diff --git "a/task1_data.csv" "b/task1_data.csv" deleted file mode 100644--- "a/task1_data.csv" +++ /dev/null @@ -1,249318 +0,0 @@ -Who,Problem,LangNorm,submit_id_1,submit_id_2,code1,code2,answer -Nael8,2049B - pspspsps,c++23 ,308551596,308547511,"#include - -using namespace std; - -#pragma GCC optimize(""Ofast"") - -#pragma GCC optimize(""unroll-loops"") - -#define int long long - -#define fi first - -#define tc int t; cin >> t; while(t--) - -#define se second - -#define pb push_back - -#define vi vector - -#define pii pair - -#define piii pair - -#define vii vector - -#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) - -#define debug cout<<""\ndebug\n""; - -typedef long long ll; - -const int mxn = 1e5+20; - -const int MOD = 1e9+7; - -const int INF = LLONG_MAX; - -int tot(int a, int b){return (a+b)%MOD;} - -// int sub(int a, int b){return (a-b)%mod;} - -// int mul(int a, int b){return (a*b)%mod;} - -// int chmx(int &a, int b){ return max(a, b);} - -// int chmn(int &a, int b){ return min(a, b);} - - - -void solve(){ - - int n, s=-1,p=-1; cin >> n; - - string ss; cin >> ss; - - if(ss[0] == 's')ss[0] = '.'; - - if(ss[n-1]=='p')ss[n-1] = '.'; - - bool foundp=0,founds=0; - - for(int i = 0; i < n; i++){ - - if(ss[i] == 'p')foundp=1; - - if(ss[i] == 's') founds=1; - - } - - cout << (foundp&&founds ? ""NO"":""YES"")<> t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}","#include - -using namespace std; - -#pragma GCC optimize(""Ofast"") - -#pragma GCC optimize(""unroll-loops"") - -#define int long long - -#define fi first - -#define tc int t; cin >> t; while(t--) - -#define se second - -#define pb push_back - -#define vi vector - -#define pii pair - -#define piii pair - -#define vii vector - -#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) - -#define debug cout<<""\ndebug\n""; - -typedef long long ll; - -const int mxn = 1e5+20; - -const int MOD = 1e9+7; - -const int INF = LLONG_MAX; - -int tot(int a, int b){return (a+b)%MOD;} - -// int sub(int a, int b){return (a-b)%mod;} - -// int mul(int a, int b){return (a*b)%mod;} - -// int chmx(int &a, int b){ return max(a, b);} - -// int chmn(int &a, int b){ return min(a, b);} - - - -void solve(){ - - int n, s=-1,p=-1; cin >> n; - - string ss; cin >> ss; - - bool ok = 0; - - for(int i = 0; i < n; i++){ - - if(ss[i]=='p' && p==-1){ - - p=i; - - } - - else if(ss[i] == 's'){ - - s = i; - - } else ok = 1; - - } - - if(s > p && p!=-1)cout<<""NO""<> t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}",1 -shivam_gupta,2049B - pspspsps,c++23 ,308240418,308241333,"#include - -using namespace std; - -#define ll long long int - -ll answer(int n){ - - string st; cin>>st; - - bool s=0,p=0; - - for(int i=1;i<=n-2;i++) { - - if(st[i]=='s' ) s=1; - - if(st[i]=='p') p=1; - - } - - if(s && p) return 0; - - if(st[0]=='p'){ - - if(s || st[n-1]=='s') return 0; - - } - - return 1; - - - -} - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; cin>>n; - - //cout< - -using namespace std; - -#define ll long long int - -ll answer(int n){ - - string st; cin>>st; - - bool s=0,p=0; - - for(int i=1;i<=n-2;i++) { - - if(st[i]=='s' ) s=1; - - if(st[i]=='p') p=1; - - } - - if(s && p|| p && st[n-1]=='s') return 0; - - if(st[0]=='p'){ - - if(s || st[n-1]=='s') return 0; - - else return 1; - - } - - return 1; - - - -} - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; cin>>n; - - //cout< - -#ifdef LOCAL - -#include ""debug.h"" - -#else - -#define dbg(x...) - -void dbgEndl() {} - -#endif - -#if __cplusplus <= 201703L || defined(LOCAL) - -#include - -namespace pbds = __gnu_pbds; - -#endif - - - -using namespace std; - -using u32 = unsigned; - -using u64 = unsigned long long; - -using i64 = long long; - -#if __cplusplus >= 202002L - -using i128 = __int128; - -#endif - -using f64 = long double; - - - -constexpr int N = 1000010; - -constexpr f64 eps = 1e-9; // !!! - -constexpr int inf32 = 1e9; - -constexpr i64 inf64 = 1e18; - - - -inline void YES(void) { cout << ""YES\n""; } - -inline void Yes(void) { cout << ""Yes\n""; } - -inline void NO(void) { cout << ""NO\n""; } - -inline void No(void) { cout << ""No\n""; } - -inline void YES_NO(bool cond) { cond ? YES() : NO(); } - -inline void Yes_No(bool cond) { cond ? Yes() : No(); } - - - -int n, m; - -inline void solve(void) { - - string s; - - cin >> n >> s; - - if (count(s.begin() + 1, s.end(), 's') == 0) { - - return YES(); - - } - - for (int i = 0; i < n; i++) { - - if (s[i] == 'p') return NO(); - - if (i > 0 && s[i] == 's') { - - for (int j = i + 1; j < n - 1; j++) { - - if (s[j] == 'p') return NO(); - - } - - return YES(); - - } - - } - - YES(); - -} - - - -inline void optimizeIO(void) { - - ios::sync_with_stdio(false); - - cin.tie(NULL), cout.tie(NULL); - -} - -int main(int argc, char const *argv[]) { - - int t = 1; - - optimizeIO(), cin >> t; - - while (t--) solve(); - - return 0; - -} - -","#include - -#ifdef LOCAL - -#include ""debug.h"" - -#else - -#define dbg(x...) - -void dbgEndl() {} - -#endif - -#if __cplusplus <= 201703L || defined(LOCAL) - -#include - -namespace pbds = __gnu_pbds; - -#endif - - - -using namespace std; - -using u32 = unsigned; - -using u64 = unsigned long long; - -using i64 = long long; - -#if __cplusplus >= 202002L - -using i128 = __int128; - -#endif - -using f64 = long double; - - - -constexpr int N = 1000010; - -constexpr f64 eps = 1e-9; // !!! - -constexpr int inf32 = 1e9; - -constexpr i64 inf64 = 1e18; - - - -inline void YES(void) { cout << ""YES\n""; } - -inline void Yes(void) { cout << ""Yes\n""; } - -inline void NO(void) { cout << ""NO\n""; } - -inline void No(void) { cout << ""No\n""; } - -inline void YES_NO(bool cond) { cond ? YES() : NO(); } - -inline void Yes_No(bool cond) { cond ? Yes() : No(); } - - - -int n, m; - -inline void solve(void) { - - string s; - - cin >> n >> s; - - if (count(s.begin(), s.end(), 's') == 0) { - - return YES(); - - } - - for (int i = 0; i < n; i++) { - - if (s[i] == 'p') return NO(); - - if (s[i] == 's') { - - for (int j = i + 1; j < n - 1; j++) { - - if (s[j] == 'p') return NO(); - - } - - return YES(); - - } - - } - - YES(); - -} - - - -inline void optimizeIO(void) { - - ios::sync_with_stdio(false); - - cin.tie(NULL), cout.tie(NULL); - -} - -int main(int argc, char const *argv[]) { - - int t = 1; - - optimizeIO(), cin >> t; - - while (t--) solve(); - - return 0; - -} - -",1 -exccc,2049B - pspspsps,c++20 ,307537589,307632605,"#include - - - -using namespace std; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - for (int i=0; i0 && i>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}","#include - - - -using namespace std; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s'){ - - s[0]='.'; - - } - - if(s[n-1]=='p'){ - - s[n-1]='.'; - - } - - int cd1=0,cd2=0; - - for (int i=0; i>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}",2 -arbaz_1712,2049B - pspspsps,c++20 ,304065791,304065506,"// Online C++ compiler to run C++ program online - -#include - -using namespace std; - - - -bool solve(string &s,int n){ - - int s1=0,p1=0,d1=0; - - for(auto &r:s){ - - if(r=='s') - - s1++; - - if(r=='p') - - p1++; - - if(r=='.') - - d1++; - - } - - if(p1==n||s1==n||d1==n||s1+d1==n||p1+d1==n) - - return 1; - - if(s[0]=='s'&&s1==1) - - return 1; - - if(s[n-1]=='p'&&p1==1) - - return 1; - - return 0; - -} - - - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(solve(s,n)) - - cout<<""YES""; - - else - - cout<<""NO""; - - cout< - -using namespace std; - - - -bool solve(string &s,int n){ - - int s1=0,p1=0,d1=0; - - for(auto &r:s){ - - if(r=='s') - - s1++; - - if(r=='p') - - p1++; - - if(r=='.') - - d1++; - - } - - if(p1==n||s1==n||d1==n) - - return 1; - - if(s[0]=='s'&&s1==1) - - return 1; - - if(s[n-1]=='p'&&p1==1) - - return 1; - - return 0; - -} - - - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(solve(s,n)) - - cout<<""YES""; - - else - - cout<<""NO""; - - cout< - -using namespace std; - -#define int long long - - - -signed main(){ - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); cout.tie(NULL); - - - - int t; cin>>t; - - while(t--){ - - int n,ss=0,si=-1,pp=0,pi=-1; cin>>n; - - string s; cin>>s; - - - - for(int i=0;i - -using namespace std; - -#define int long long - - - -signed main(){ - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); cout.tie(NULL); - - - - int t; cin>>t; - - while(t--){ - - int n,ss=0,si=-1,pp=0,pi=-1; cin>>n; - - string s; cin>>s; - - - - for(int i=0;i - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,say1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m; - - cin>>s; - - say1=0; - - say2=0; - - bool b=1; - - if(s[0]=='s') - - { - - cout<<""yes""< - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,say1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m; - - cin>>s; - - say1=0; - - say2=0; - - bool b=0,b1=0; - - if(s[0]=='s') - - { - - s[0]='.'; - - } - - if(s[m-1]=='p') - - s[m-1]='.'; - - for(int i=0;i - -#define ll long long - -#define pn cout<<""NO""< - -#define vi vector - -#define vb vector - -#define u_map unordered_map - -#define pll pair - -#define pii pair - -#define inf INT_MAX - -#define pb push_back - -#define mod 998244353 - -#define MOD 1000000007 - -#define ld long double - -#define ff first - -#define ss second - -#define all(v) v.begin(),v.end() - -#define min3(a, b, c) min(c, min(a, b)) - -#define min4(a, b, c, d) min(d, min(c, min(a, b))) - -#define loop(i,n) for(int i=0;i=0;i--) - -using namespace std; - - - -void input(vector&arr,ll n){ - -for(ll i =0;i>arr[i]; - -} - - - -void printArr(vector&arr, ll i,ll j){ - -for(ll k = i;k<=j;k++)cout<>n>>str; - - sets; - - for(auto c:str)s.insert(c); - - if(s.size()==1){ - - py; - - return; - - } - - for(int i = 0;i>test; - -while(test--){ - -find(); - -} - -return 0; - -}","// **************** MBRAHUL *************** - -#include - -#define ll long long - -#define pn cout<<""NO""< - -#define vi vector - -#define vb vector - -#define u_map unordered_map - -#define pll pair - -#define pii pair - -#define inf INT_MAX - -#define pb push_back - -#define mod 998244353 - -#define MOD 1000000007 - -#define ld long double - -#define ff first - -#define ss second - -#define all(v) v.begin(),v.end() - -#define min3(a, b, c) min(c, min(a, b)) - -#define min4(a, b, c, d) min(d, min(c, min(a, b))) - -#define loop(i,n) for(int i=0;i=0;i--) - -using namespace std; - - - -void input(vector&arr,ll n){ - -for(ll i =0;i>arr[i]; - -} - - - -void printArr(vector&arr, ll i,ll j){ - -for(ll k = i;k<=j;k++)cout<>n>>str; - - setst; - - for(auto c:str)if(c!='.')st.insert(c); - - if(st.size()<=1){ - - py; - - return; - - } - - int s=0,p=0; - - for(auto c:str){ - - if(c=='s')s++; - - else if(c=='p')p++; - - } - - if(s==1 || p==1){ - - if(s==1 && p==1){ - - if(str.back()=='p' || str[0]=='s')py; - - else pn; - - } - - else if(s==1){ - - if(str[0]=='s')py; - - else pn; - - } - - else{ - - if(str.back()=='p')py; - - else pn; - - } - - } - - else pn; - -} - - - -int main(){ - -ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); - -ll test=1; - -cin>>test; - -while(test--){ - -find(); - -} - -return 0; - -}",2 -AU25meyu251,2049B - pspspsps,c++17 ,306629529,306630053,"#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - - - string s; - - cin >> s; - - - - bool seen_s = false; - - bool seen_p = false; - - - - if(s[0] == 's'){ - - seen_s = true; - - } - - else if(s[0] == 'p'){ - - seen_p = true; - - } - - - - for(int i = 1; i < n-1; i++){ - - if(s[i] == 's'){ - - if(seen_p){ - - cout << ""no\n""; - - return; - - } - - seen_s = true; - - } - - else if(s[i] == 'p'){ - - if(seen_s){ - - cout << ""no\n""; - - return; - - } - - seen_p = true; - - } - - } - - - - cout << ""yes\n""; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - - - string s; - - cin >> s; - - - - bool seen_s = false; - - bool seen_p = false; - - - - if(s[0] == 'p'){ - - seen_p = true; - - } - - - - for(int i = 1; i < n-1; i++){ - - if(s[i] == 's'){ - - if(seen_p){ - - cout << ""no\n""; - - return; - - } - - seen_s = true; - - } - - else if(s[i] == 'p'){ - - if(seen_s){ - - cout << ""no\n""; - - return; - - } - - seen_p = true; - - } - - } - - if(s[n-1] == 's' && seen_p){ - - cout << ""no\n""; - - return; - - } - - - - cout << ""yes\n""; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}",2 -PrinceZuko,2049B - pspspsps,c++20 ,304273131,304282111,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define input(v) for(auto &it:v)cin>>it - -#define output(v) for(auto &it:v)cout< - -#define tzll(x) __builtin_ctzll(x) - -#define lzll(x) __builtin_clzll(x) - -#define lz(x) __builtin_clz(x) - -#define tz(x) __builtin_ctz(x) - -#define popc(x) __builtin_popcount(x) - -#define popcll(x) __builtin_popcountll(x) - -#define pi pair - -#define vi vector - -#define vvi vector > - -#define vpi vector > - -#define si set - -#define spi set > - -#define qi queue - -#define qpi queue > - -#define msi multiset - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define pb push_back - -#define ppb pop_back - -#define mp make_pair - -#define ff first - -#define ss second - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - - - -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;} - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - - -int gcd (int a, int b) { - - if (b == 0) return a; - - return gcd (b, a % b); - -} - -int lcm (int a, int b) { - - return a / gcd(a, b) * b; - -} - -long long binpow(long long a, long long b) { - - long long res = 1; - - while (b > 0) { - - if (b & 1) - - res = res * a; - - a = a * a; - - b >>= 1; - - } - - return res; - -} - -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; - -} - -/* - - - -*/ - - - -bool solve() - -{ - - int n; - - cin>>n; - - string s; - - cin>>s; - - for(int i=0;i> t; - - for(int i = 1; i <= t; i++){ - - // cout<<""Case #""< - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define input(v) for(auto &it:v)cin>>it - -#define output(v) for(auto &it:v)cout< - -#define tzll(x) __builtin_ctzll(x) - -#define lzll(x) __builtin_clzll(x) - -#define lz(x) __builtin_clz(x) - -#define tz(x) __builtin_ctz(x) - -#define popc(x) __builtin_popcount(x) - -#define popcll(x) __builtin_popcountll(x) - -#define pi pair - -#define vi vector - -#define vvi vector > - -#define vpi vector > - -#define si set - -#define spi set > - -#define qi queue - -#define qpi queue > - -#define msi multiset - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define pb push_back - -#define ppb pop_back - -#define mp make_pair - -#define ff first - -#define ss second - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - - - -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;} - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - - -int gcd (int a, int b) { - - if (b == 0) return a; - - return gcd (b, a % b); - -} - -int lcm (int a, int b) { - - return a / gcd(a, b) * b; - -} - -long long binpow(long long a, long long b) { - - long long res = 1; - - while (b > 0) { - - if (b & 1) - - res = res * a; - - a = a * a; - - b >>= 1; - - } - - return res; - -} - -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; - -} - -/* - - - -*/ - - - -bool solve() - -{ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int pmin=n,pmax=-1,smin=n,smax=-1; - - if(s[0]=='s') - - s[0]='.'; - - if(s[n-1]=='p') - - s[n-1]='.'; - - int sct=0,pct=0; - - for(auto it:s) - - { - - if(it=='s') - - sct++; - - if(it=='p') - - pct++; - - } - - if(sct==0 || pct==0) - - return 1; - - - - return 0; - -} - -signed main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - int t = 1; - - cin >> t; - - for(int i = 1; i <= t; i++){ - - // cout<<""Case #""< - -#include - -using namespace std; - -void solve() - -{ - - int n,jump=1; - - string s; - - cin>>n>>s; - - for(int i=1;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} ","#include - -#include - -using namespace std; - -void solve() - -{ - - int n; - - string s; - - cin>>n>>s; - - for(int i=1;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} ",1 -xigua666,2049B - pspspsps,c++23 ,307648298,307645735,"#include - -using namespace std; - -using ll=long long; - -ll n,a[1000010],q[1000010]; - -string s; - - - -void solve() - -{ - - cin>>n; - - cin>>s; - - for(int i=0;i<=n-1;i++) - - { - - for(int j=0;j<=n-1;j++) - - { - - if(s[i]=='p'&&s[j]=='s'&&i!=n-1&&j!=0) - - { - - cout<<""NO""<<'\n'; - - return; - - } - - } - - } - - cout<<""YES""<<'\n'; - - return; - -} - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -using ll=long long; - -ll n,a[1000010],q[1000010]; - -string s; - - - -void solve() - -{ - - cin>>n; - - cin>>s; - - for(int i=0;i=0;i--) - - { - - if(q[i]==2) flag=true; - - if(flag&&q[i]==1) - - { - - cout<<""NO""<<'\n'; - - return; - - } - - } - - cout<<""YES""<<'\n'; - - return; - -} - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",1 -Boom_Wuhuhu,2049B - pspspsps,c++17 ,306623854,306622221,"#include - -using namespace std; - -const int N=6000; - -char a[N]; - -int main() - -{ - - int T; - - cin>>T; - - while(T--) - - { - - int n; - - cin>>n; - - int b1=0,b2=0; - - for(int i=1;i<=n;i++) - - { - - cin>>a[i]; - - if(i==1 or i==n)continue; - - if(a[i]=='p')b1++; - - if(a[i]=='s')b2++; - - } - - if(b1>0 and b2>0)cout<<""NO""<0 and a[1]!='p')cout<<""YES""<0 and a[n]!='s')cout<<""YES""< - -using namespace std; - -const int N=6000; - -char a[N]; - -int main() - -{ - - int T; - - cin>>T; - - while(T--) - - { - - int n; - - cin>>n; - - int b1=0,b2=0; - - for(int i=1;i<=n;i++) - - { - - cin>>a[i]; - - if(a[i]=='p')b1++; - - if(a[i]=='s')b2++; - - } - - if(b1==0 or b2==0)cout<<""YES""<1 and b2>1)cout<<""NO""< - -#define all(s) s.begin(), s.end() - -using namespace std; - -using ll = long long; - -using ull = unsigned long long; - -const int _N = 1e5 + 5; - - - -void solve(){ - - ll n; - - cin>>n; - - string s; - - cin>>s; - - map mp; - - ll p=0,q=0,r=0; - - for(ll i=0; i>t; - - while(t--){ - - solve(); - - } - -}","#include - -#define all(s) s.begin(), s.end() - -using namespace std; - -using ll = long long; - -using ull = unsigned long long; - -const int _N = 1e5 + 5; - - - -void solve(){ - - ll n; - - cin>>n; - - string s; - - cin>>s; - - map mp; - - ll p=0,q=0,r=0; - - for(ll i=0; i>t; - - while(t--){ - - solve(); - - } - -}",2 -mali.avadhut7,2049B - pspspsps,java,304671702,304670614,"import java.util.*; - -import java.io.*; - - - -public class B_pspspsps { - - - - static final int MAX = 10_000_000; - - static final int MOD = 1_000_000_007; - - static boolean[] isPrime = new boolean[MAX + 1]; - - static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); - - - - public static void solve() { - - FastIO sc = new FastIO(); - - int testCases = sc.nextInt(); - - - - while (testCases-- != 0) { - - int n = sc.nextInt(); - - String s = sc.next(); - - boolean f = false; - - boolean isS=false; - - boolean isP=false; - - char arr[] = s.toCharArray(); - - if(arr[0]=='s')arr[0]='.'; - - if(arr[n-1]=='p')arr[n-1]='.'; - - for(int i=0;i list) { - - out.println(list); - - } - - - - public static long modAdd(long a, long b, int mod) { - - return (a + b) % mod; - - } - - - - public static long modMul(long a, long b, int mod) { - - return (a * b) % mod; - - } - - - - public static long modExp(long base, long exp, int mod) { - - long result = 1; - - while (exp > 0) { - - if ((exp & 1) == 1) result = (result * base) % mod; - - base = (base * base) % mod; - - exp >>= 1; - - } - - return result; - - } - - - - public static void precomputePrimes() { - - Arrays.fill(isPrime, true); - - isPrime[0] = isPrime[1] = false; - - for (int i = 2; i * i <= MAX; i++) { - - if (isPrime[i]) { - - for (int j = i * i; j <= MAX; j += i) { - - isPrime[j] = false; - - } - - } - - } - - } - - - - public static boolean isPrime(int n) { - - return n >= 0 && n <= MAX && isPrime[n]; - - } - - - - public static void bfs(int start, List[] graph, boolean[] visited) { - - Queue queue = new LinkedList<>(); - - queue.add(start); - - visited[start] = true; - - - - while (!queue.isEmpty()) { - - int node = queue.poll(); - - for (int neighbor : graph[node]) { - - if (!visited[neighbor]) { - - queue.add(neighbor); - - visited[neighbor] = true; - - } - - } - - } - - } - - - - static class DSU { - - int[] parent, rank; - - - - DSU(int n) { - - parent = new int[n]; - - rank = new int[n]; - - for (int i = 0; i < n; i++) parent[i] = i; - - } - - - - int find(int x) { - - if (x != parent[x]) parent[x] = find(parent[x]); - - return parent[x]; - - } - - - - void union(int x, int y) { - - int rootX = find(x), rootY = find(y); - - if (rootX != rootY) { - - if (rank[rootX] > rank[rootY]) parent[rootY] = rootX; - - else if (rank[rootX] < rank[rootY]) parent[rootX] = rootY; - - else { - - parent[rootY] = rootX; - - rank[rootX]++; - - } - - } - - } - - } - - - - static class FastIO { - - BufferedReader br; - - StringTokenizer st; - - - - public FastIO() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - - } - - - - public static void main(String[] args) { - - precomputePrimes(); - - solve(); - - } - -} - -","import java.util.*; - -import java.io.*; - - - -public class B_pspspsps { - - - - static final int MAX = 10_000_000; - - static final int MOD = 1_000_000_007; - - static boolean[] isPrime = new boolean[MAX + 1]; - - static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); - - - - public static void solve() { - - FastIO sc = new FastIO(); - - int testCases = sc.nextInt(); - - - - while (testCases-- != 0) { - - int n = sc.nextInt(); - - String s = sc.next(); - - boolean f = false; - - boolean isS=false; - - char arr[] = s.toCharArray(); - - for(int i=0;i list) { - - out.println(list); - - } - - - - public static long modAdd(long a, long b, int mod) { - - return (a + b) % mod; - - } - - - - public static long modMul(long a, long b, int mod) { - - return (a * b) % mod; - - } - - - - public static long modExp(long base, long exp, int mod) { - - long result = 1; - - while (exp > 0) { - - if ((exp & 1) == 1) result = (result * base) % mod; - - base = (base * base) % mod; - - exp >>= 1; - - } - - return result; - - } - - - - public static void precomputePrimes() { - - Arrays.fill(isPrime, true); - - isPrime[0] = isPrime[1] = false; - - for (int i = 2; i * i <= MAX; i++) { - - if (isPrime[i]) { - - for (int j = i * i; j <= MAX; j += i) { - - isPrime[j] = false; - - } - - } - - } - - } - - - - public static boolean isPrime(int n) { - - return n >= 0 && n <= MAX && isPrime[n]; - - } - - - - public static void bfs(int start, List[] graph, boolean[] visited) { - - Queue queue = new LinkedList<>(); - - queue.add(start); - - visited[start] = true; - - - - while (!queue.isEmpty()) { - - int node = queue.poll(); - - for (int neighbor : graph[node]) { - - if (!visited[neighbor]) { - - queue.add(neighbor); - - visited[neighbor] = true; - - } - - } - - } - - } - - - - static class DSU { - - int[] parent, rank; - - - - DSU(int n) { - - parent = new int[n]; - - rank = new int[n]; - - for (int i = 0; i < n; i++) parent[i] = i; - - } - - - - int find(int x) { - - if (x != parent[x]) parent[x] = find(parent[x]); - - return parent[x]; - - } - - - - void union(int x, int y) { - - int rootX = find(x), rootY = find(y); - - if (rootX != rootY) { - - if (rank[rootX] > rank[rootY]) parent[rootY] = rootX; - - else if (rank[rootX] < rank[rootY]) parent[rootX] = rootY; - - else { - - parent[rootY] = rootX; - - rank[rootX]++; - - } - - } - - } - - } - - - - static class FastIO { - - BufferedReader br; - - StringTokenizer st; - - - - public FastIO() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - - } - - - - public static void main(String[] args) { - - precomputePrimes(); - - solve(); - - } - -} - -",1 -L_315205,2049B - pspspsps,c++17 ,306810456,306810562,"#include - -using namespace std; - -int n; - -char s[505]; - -void solve(){ - - cin>>n; - - for(int i=1;i<=n;i++){ - - cin>>s[i]; - - } - - int a=0,b=0; - - for(int i=2;i>TTT; - - while(TTT--)solve(); - -}","#include - -using namespace std; - -int n; - -char s[505]; - -void solve(){ - - cin>>n; - - for(int i=1;i<=n;i++){ - - cin>>s[i]; - - } - - int a=0,b=0; - - for(int i=2;i>TTT; - - while(TTT--)solve(); - -}",2 -DronDron,2049B - pspspsps,c++17 ,307216339,307137962,"#pragma region usual_defs -#include -#include -#include -#include - -// this is the only reason I like C++ (sorry, java, try to be more fun next time): -#define meow cin -#define murr cout -#define lol long long -#define lmao unsigned long long -#define el '\n' -#define none \ - { \ - } -#define kaput return -#define kill break -#define nah continue -using namespace std; -#pragma endregion usual_defs -// #define SYNC -#define i_like_cats - -int n; -string str; -bool l, _s, _p; -void cat() -{ - meow >> n; - meow.ignore(); - getline(meow, str); - _s = false; - _p = false; - for (int i = 0; i < n; i++) - { - if (str[i] == 's') - _s = true; - else if (str[i] == 'p') - _p = true; - } - if (!(_s && _p)) - { - murr << ""YES\n""; - kaput; - } - - _p = true; - for (int i = 0; i < n - 1; i++) - { - if (str[i] == 'p') - { - _p = false; - kill; - } - } - if (_p) - { - murr << ""YES\n""; - kaput; - } - - _s = true; - for (int i = 1; i < n; i++) - { - if (str[i] == 's') - { - _s = false; - kill; - } - } - if (_s) - { - murr << ""YES\n""; - kaput; - } - murr << ""NO\n""; -} - -#pragma region main -#ifdef i_like_cats -int INPUT_SETS_COUNT; -#endif -int main() -{ - ios_base::sync_with_stdio(false); -#ifndef SYNC - meow.tie(NULL); -#endif -#ifdef i_like_cats - meow >> INPUT_SETS_COUNT; - meow.ignore(); - while (INPUT_SETS_COUNT--) - cat(); -#endif -#ifndef i_like_cats - cat(); -#endif -} -#pragma endregion main -","#pragma region usual_defs -#include -#include -#include -#include - -// this is the only reason I like C++ (sorry, java, try to be more fun next time): -#define meow cin -#define murr cout -#define lol long long -#define lmao unsigned long long -#define el '\n' -#define none \ - { \ - } -#define kaput return -#define kill break -#define nah continue -using namespace std; -#pragma endregion usual_defs -// #define SYNC -#define i_like_cats - -int n; -string str; -bool l, _s, _p; -void cat() -{ - meow >> n; - meow.ignore(); - getline(meow, str); - _s = false; - _p = false; - for (int i = 0; i < n; i++) - { - if (str[i] == 's') - _s = true; - else if (str[i] == 'p') - _p = true; - } - if (!(_s && _p)) - { - murr << ""YES\n""; - kaput; - } - - if (str[0] != '.' || str[n - 1] != '.') - { - l = false; - for (int i = 0; i < n; i++) - { - if (str[i] != '.') - { - if (str[i] == 's') - { - if (l) - { - murr << ""NO\n""; - kaput; - } - } - else - l = true; - } - } - murr << ""YES\n""; - } - else - murr << ""NO\n""; -} - -#pragma region main -#ifdef i_like_cats -int INPUT_SETS_COUNT; -#endif -int main() -{ - ios_base::sync_with_stdio(false); -#ifndef SYNC - meow.tie(NULL); -#endif -#ifdef i_like_cats - meow >> INPUT_SETS_COUNT; - meow.ignore(); - while (INPUT_SETS_COUNT--) - cat(); -#endif -#ifndef i_like_cats - cat(); -#endif -} -#pragma endregion main -",1 -AQIBat1,2049B - pspspsps,c++20 ,306875708,306866960,"#include""bits/stdc++.h"" -using namespace std; - -#define YES cout<<""YES\n"" -#define NO cout<<""NO\n"" -#define endl ""\n"" -#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) - -typedef long long ll; -const int MOD = 1000000007; -const int Nmax = 2e5+5; - -void akibify(){ - - int n ;cin>>n ; - string s ; - cin>>s;bool f = 1; - mapm ; - int slast = 0; - int pfirst = -1 ; - for(int i = 0 ; i < n ; i++){ - m[s[i]]++; - if(s[i] == 's'){ - slast = i ; - } - if(s[i] == 'p' && pfirst == -1){ - pfirst = i ; - } - } - if(m['p'] == 0 || m['s'] == 0){ - YES; - return; - } - if(slast == 0 || pfirst == n-1){ - YES; - return; - } - NO; - - - } - - - - - -int main(){ - fast_io; - int t ; - cin>>t ; - while(t--){ - akibify(); - - } - - - return 0; -}","#include""bits/stdc++.h"" -using namespace std; - -#define YES cout<<""YES\n"" -#define NO cout<<""NO\n"" -#define endl ""\n"" -#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) - -typedef long long ll; -const int MOD = 1000000007; -const int Nmax = 2e5+5; - -void akibify(){ - - int n ;cin>>n ; - string s ; - cin>>s;bool f = 1; - - for(int i = 1 ; i < n ; i++){ - char c1 = s[i-1]; - int l1,r1 ; - if(c1 == 'p') { - l1 = 0 ; - r1 = i-1; - } - else if(c1 == 's') { - l1 = i-1; - r1 = n-1; - } - else { - l1 = 0 ; - r1 = n-1; - } - char c2 = s[i]; - int l2,r2 ; - if(c2 == 'p') { - l2 = 0 ; - r2 = i; - } - else if(c2 == 's') { - l2 = i; - r2 = n-1; - } - else { - l2= 0 ; - r2 = n-1; - } - if(c1 == 'p' && c2 == 's' && r1 < l2 ){ - f = 0 ; - NO; - return ; - } - if(c1 == 's' && c2 == 'p' && l2 < l1 && r2 >t ; - while(t--){ - akibify(); - - } - - - return 0; -}",1 -ounailiu,2049B - pspspsps,c++17 ,304940217,304941309,"#include - - - -#define int long long - - - -const int mod = 1e9 + 7; - -const int inf = 1e18; - - - -using namespace std; - - - -void solve() - -{ - - int n; - - string a; - - cin >> n >> a; - - int cnt1=0,cnt2=0; - - for(auto &i:a){ - - if(i=='s') cnt1++; - - if(i=='p') cnt2++; - - } - - if(cnt1==0 || cnt2==0 || cnt1==1 && a[a.size()-1]=='s' || cnt2==1 && a[a.size()-1]=='p') cout << ""YES""; - - else cout << ""NO""; - -} - - - -signed main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(0); - -#ifdef Timur - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - cout << ""\n""; - - } - - return 0; - -}","#include - - - -#define int long long - - - -const int mod = 1e9 + 7; - -const int inf = 1e18; - - - -using namespace std; - - - -void solve() - -{ - - int n; - - string a; - - cin >> n >> a; - - int cnt1=0,cnt2=0; - - for(auto &i:a){ - - if(i=='s') cnt1++; - - if(i=='p') cnt2++; - - } - - if(cnt1==0 || cnt2==0 || cnt2==1 && a[a.size()-1]=='p') cout << ""YES""; - - else cout << ""NO""; - -} - - - -signed main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(0); - -#ifdef Timur - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - cout << ""\n""; - - } - - return 0; - -}",2 -pratham795,2049B - pspspsps,java,304403870,304403444,"import java.util.HashSet; - -import java.util.Scanner; - - - -public class PSPS { - - public static void main(String[] args) { - - Scanner sc=new Scanner(System.in); - - int testCase=sc.nextInt(); - - while (testCase-- >0){ - - int n=sc.nextInt(); - - String s=sc.next(); - - int pidx=s.indexOf('p'); - - int sidx=s.lastIndexOf('s'); - - HashSet hs=new HashSet<>(); - - for (int i = 1; i < n-1; i++) { - - if(s.charAt(i)!='.') hs.add(s.charAt(i)); - - } - - if(hs.size()>1 || (pidx0){ - - int n=sc.nextInt(); - - String s=sc.next(); - - int pidx=s.indexOf('p'); - - int sidx=s.lastIndexOf('s'); - - HashSet hs=new HashSet<>(); - - for (int i = 1; i < n-1; i++) { - - if(s.charAt(i)!='.') hs.add(s.charAt(i)); - - } - - if(hs.size()>1 || pidx - -using namespace std; - -const int N = 1e6+7; - -#define int long long - -#define endl '\n' - - - - - - - -void solve(){ - - - - int n; - - cin>>n; - - string s; - - cin>>s; - - s='0'+s; - - - - if(s[1]=='s'){ - - for(int i=2;i<=n;i++){ - - if(s[i]=='p'&&i!=n){ - - cout<<""NO""<>T; - - while(T--){ - - - - solve(); - - - - } - - - - - - - - return 0; - -}","#include - -using namespace std; - -const int N = 1e6+7; - -#define int long long - -#define endl '\n' - - - - - - - -void solve(){ - - - - int n; - - cin>>n; - - string s; - - cin>>s; - - s='0'+s; - - - - int l=-1,r=n+1; - - for(int i=1;i<=n;i++){ - - if(s[i]=='s') l=i; - - } - - for(int i=n;i>=0;i--){ - - if(s[i]=='p')r=i; - - } - - if(r>T; - - while(T--){ - - - - solve(); - - - - } - - - - - - - - return 0; - -}",2 -pranavbansal21,2049B - pspspsps,c++17 ,304809408,304838297,"#include - -using namespace std; - -#define int long long - -#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - map m; - - for(auto x:s){ - - m[x]++; - - } - - if(m.size()==1){ - - cout<<""YES\n""; - - } - - else if(m.size()==2){ - - if(m.find('.')!=m.end()){ - - cout<<""YES\n""; - - } - - else{ - - int k = m['p']; - - if(k>1){ - - cout<<""NO\n""; - - } - - else{ - - if(s[n-1]!='p'){ - - cout<<""NO\n""; - - } - - else{ - - cout<<""YES\n""; - - } - - } - - } - - } - - else{ - - int k = m['p']; - - if(k>1){ - - cout<<""NO\n""; - - } - - else{ - - if(s[n-1]!='p'){ - - cout<<""NO\n""; - - } - - else{ - - cout<<""YES\n""; - - } - - } - - } - -} - -signed main(){ - - pranavbansal21(); - - int t; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -#define int long long - -#define pranavbansal21() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - map m; - - if(s[0]=='s') s[0]= '.'; - - if(s[n-1]=='p') s[n-1]='.'; - - for(auto x:s){ - - m[x]++; - - } - - if(m.find('s')!=m.end()&&m.find('p')!=m.end()){ - - cout<<""NO\n""; - - } - - else{ - - cout<<""YES\n""; - - } - -} - -signed main(){ - - pranavbansal21(); - - int t; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -xrf123,2049B - pspspsps,c++17 ,308600810,308615194,"#include - -#include - -#include - - - -using namespace std; - - - -typedef long long LL; - - - -const int N = 200010, MOD = 1e9 + 7; - - - -int T; - -LL n, m; - -int a[N], b[N]; - - - -int main() { - - cin >> T; - - - - while (T--) { - - cin >> n; - - - - string s; - - cin >> s; - - - - int f = 1; - - for (int i = 1; i < n; i++) { - - if (s[i] != s[0]) f = 0; - - } - - - - if (f) puts(""YES""); - - else { - - f = 1; - - for (int i = 0; i < n; i++) { - - if (s[i] == 's') f = 0; - - } - - - - if (f) puts(""YES""); - - else{ - - if (s[0] == 'p') puts(""NO""); - - else { - - f = 1; - - for (int i = 0; i < n; i++) { - - if (s[i] == 'p' && i != n - 1) { - - f = 0; - - break; - - } - - } - - if (f) puts(""YES""); - - else puts(""NO""); - - } - - } - - } - - - - } - - - - return 0; - -} - -","#include - -#include - -#include - - - -using namespace std; - - - -typedef long long LL; - - - -const int N = 200010, MOD = 1e9 + 7; - - - -int T; - -LL n, m; - -int a[N], b[N]; - - - -int main() { - - cin >> T; - - - - while (T--) { - - cin >> n; - - - - string s; - - cin >> s; - - - - if(s[0] == 's') s[0] = '.'; - - if(s[n - 1] == 'p') s[n - 1] = '.'; - - - - int f1 = 0, f2 = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 's') f1 = 1; - - else if(s[i] == 'p') f2 = 1; - - } - - - - if(f1 && f2) puts(""NO""); - - else puts(""YES""); - - - - } - - - - return 0; - -} - -",2 -Saurabh1628,2049B - pspspsps,c++23 ,307115662,307115168,"#include - -using namespace std; - -#pragma GCC optimize(""O3,unroll-loops"") - -#pragma GCC target(""avx2,bmi,bmi2,popcnt,lzcnt"") - -#define int long long - -int mod=1e9+7; - -void sort(vector &vct){ sort(vct.begin(),vct.end());} - -void invct(vector &vct,int n){vct.resize(n);for(int i=0;i>vct[i];} - -int accumulate(vector &vct){int sum=0;for(int i=0;i vct,vct1,vct2; - - unordered_map mp; - - vector> mat; - - int a,b,c,k,l,m,n,r; - - - - // cin>>n>>m; - - cin>>n; - - cin>>str; - - // no ps is - - int flag=0; - - int flag1=0; - - for(int i=0;i>TC;while(TC--) Solve(); - - return 0; - -}","#include - -using namespace std; - -#pragma GCC optimize(""O3,unroll-loops"") - -#pragma GCC target(""avx2,bmi,bmi2,popcnt,lzcnt"") - -#define int long long - -int mod=1e9+7; - -void sort(vector &vct){ sort(vct.begin(),vct.end());} - -void invct(vector &vct,int n){vct.resize(n);for(int i=0;i>vct[i];} - -int accumulate(vector &vct){int sum=0;for(int i=0;i vct,vct1,vct2; - - unordered_map mp; - - vector> mat; - - int a,b,c,k,l,m,n,r; - - - - // cin>>n>>m; - - cin>>n; - - cin>>str; - - // no ps is - - int flag=0; - - int flag1=0; - - for(int i=0;i>TC;while(TC--) Solve(); - - return 0; - -}",1 -Krzychuo,2049B - pspspsps,c++20 ,307178755,307179427,"/************************************************************************************************************* - - ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋⠉⠈⠉⠉⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⡏⣀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿ - - ⣿⣿⣿⢏⣴⣿⣷⠀⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿ - - ⣿⣿⣟⣾⣿⡟⠁⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣷⢢⠀⠀⠀⠀⠀⠀⠀⢸⣿ - - ⣿⣿⣿⣿⣟⠀⡴⠄⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⣿ - - ⣿⣿⣿⠟⠻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⢴⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⣿ - - ⣿⣁⡀⠀⠀⢰⢠⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⡄⠀⣴⣶⣿⡄⣿ - - ⣿⡋⠀⠀⠀⠎⢸⣿⡆⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⠗⢘⣿⣟⠛⠿⣼ - - ⣿⣿⠋⢀⡌⢰⣿⡿⢿⡀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣧⢀⣼ - - ⣿⣿⣷⢻⠄⠘⠛⠋⠛⠃⠀⠀⠀⠀⠀⢿⣧⠈⠉⠙⠛⠋⠀⠀⠀⣿⣿⣿⣿⣿ - - ⣿⣿⣧⠀⠈⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠟⠀⠀⠀⠀⢀⢃⠀⠀⢸⣿⣿⣿⣿ - - ⣿⣿⡿⠀⠴⢗⣠⣤⣴⡶⠶⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡸⠀⣿⣿⣿⣿ - - ⣿⣿⣿⡀⢠⣾⣿⠏⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠉⠀⣿⣿⣿⣿ - - ⣿⣿⣿⣧⠈⢹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿ - - ⣿⣿⣿⣿⡄⠈⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣦⣄⣀⣀⣀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠙⣿⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠁⠀⠀⠹⣿⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⢐⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⠿⠛⠉⠉⠁⠀⢻⣿⡇⠀⠀⠀⠀⠀⠀⢀⠈⣿⣿⡿⠉⠛⠛⠛⠉⠉ - - ⣿⡿⠋⠁⠀⠀⢀⣀⣠⡴⣸⣿⣇⡄⠀⠀⠀⠀⢀⡿⠄⠙⠛⠀⣀⣠⣤⣤⠄ - -*************************************************************************************************************/ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -#define UwU cin.tie(0);ios_base::sync_with_stdio(0); - -#define test int test_num;cin>>test_num;while(test_num--) - -#define prec(k) cout<; - -using pll = pair; - -using point = complex; - -ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));} - -ll lcm(ll a, ll b){return a/gcd(a,b)*b;} - -const int M = 1e9 + 7; - -const int O = 998244353; - -const ld EPS = 1e-10; - -const ld PI = 3.14159265358979323846; - -const ll INF = (ll)1e18 + 5; - - - -const int N = 2e5 + 5; - - - -int n; - -string s; - - - -int main(){ - - UwU - - - - test{ - - cin >> n >> s; - - - - if(!count(s.begin(),s.end(),'p') || !count(s.begin(),s.end(),'s')){ - - cout << ""YES\n""; - - } - - else if(count(s.begin(),s.end(),'p') >= 2 && count(s.begin(),s.end(),'s') >= 2){ - - cout << ""NO\n""; - - } - - else{ - - if(count(s.begin(),s.end(),'s') >= 2){ - - reverse(s.begin(),s.end()); - - for(auto& c : s){ - - if(c == 'p' || c == 's'){ - - c = c ^ 'p' ^ 's'; - - } - - } - - } - - if(s[0] != 's'){ - - cout << ""NO\n""; - - } - - else{ - - cout << ""YES\n""; - - } - - } - - } - - - - return 0; - -} - -","/************************************************************************************************************* - - ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋⠉⠈⠉⠉⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⡏⣀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿ - - ⣿⣿⣿⢏⣴⣿⣷⠀⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿ - - ⣿⣿⣟⣾⣿⡟⠁⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣷⢢⠀⠀⠀⠀⠀⠀⠀⢸⣿ - - ⣿⣿⣿⣿⣟⠀⡴⠄⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⣿ - - ⣿⣿⣿⠟⠻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⢴⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⣿ - - ⣿⣁⡀⠀⠀⢰⢠⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⡄⠀⣴⣶⣿⡄⣿ - - ⣿⡋⠀⠀⠀⠎⢸⣿⡆⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⠗⢘⣿⣟⠛⠿⣼ - - ⣿⣿⠋⢀⡌⢰⣿⡿⢿⡀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣧⢀⣼ - - ⣿⣿⣷⢻⠄⠘⠛⠋⠛⠃⠀⠀⠀⠀⠀⢿⣧⠈⠉⠙⠛⠋⠀⠀⠀⣿⣿⣿⣿⣿ - - ⣿⣿⣧⠀⠈⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠟⠀⠀⠀⠀⢀⢃⠀⠀⢸⣿⣿⣿⣿ - - ⣿⣿⡿⠀⠴⢗⣠⣤⣴⡶⠶⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡸⠀⣿⣿⣿⣿ - - ⣿⣿⣿⡀⢠⣾⣿⠏⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠉⠀⣿⣿⣿⣿ - - ⣿⣿⣿⣧⠈⢹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿ - - ⣿⣿⣿⣿⡄⠈⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣦⣄⣀⣀⣀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠙⣿⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠁⠀⠀⠹⣿⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⢐⣿⣿⣿⣿⣿⣿⣿⣿⣿ - - ⣿⣿⣿⣿⠿⠛⠉⠉⠁⠀⢻⣿⡇⠀⠀⠀⠀⠀⠀⢀⠈⣿⣿⡿⠉⠛⠛⠛⠉⠉ - - ⣿⡿⠋⠁⠀⠀⢀⣀⣠⡴⣸⣿⣇⡄⠀⠀⠀⠀⢀⡿⠄⠙⠛⠀⣀⣠⣤⣤⠄ - -*************************************************************************************************************/ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -#define UwU cin.tie(0);ios_base::sync_with_stdio(0); - -#define test int test_num;cin>>test_num;while(test_num--) - -#define prec(k) cout<; - -using pll = pair; - -using point = complex; - -ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));} - -ll lcm(ll a, ll b){return a/gcd(a,b)*b;} - -const int M = 1e9 + 7; - -const int O = 998244353; - -const ld EPS = 1e-10; - -const ld PI = 3.14159265358979323846; - -const ll INF = (ll)1e18 + 5; - - - -const int N = 2e5 + 5; - - - -int n; - -string s; - - - -int main(){ - - UwU - - - - test{ - - cin >> n >> s; - - - - if(!count(s.begin(),s.end(),'p') || !count(s.begin(),s.end(),'s')){ - - cout << ""YES\n""; - - } // git - - else if(count(s.begin(),s.end(),'p') >= 2 && count(s.begin(),s.end(),'s') >= 2){ - - cout << ""NO\n""; - - } // - - else{ - - if(count(s.begin(),s.end(),'s') >= 2){ - - reverse(s.begin(),s.end()); - - for(auto& c : s){ - - if(c == 'p' || c == 's'){ - - c = c ^ 'p' ^ 's'; - - } - - } - - } - - if(s[0] == 's'){ - - cout << ""YES\n""; - - } - - else if(count(s.begin(),s.end(),'p') == 1 && s.back() == 'p'){ - - cout << ""YES\n""; - - } - - else{ - - cout << ""NO\n""; - - } - - } - - } - - - - return 0; - -} - -",2 -vipulgoyal776,2049B - pspspsps,c++17 ,305947978,305947115,"#include - -using namespace std; - - - -// Macros for shorthand - -#define ll long long - -#define ld long double - -#define pb push_back - -#define mp make_pair - -#define fi first - -#define se second - -#define all(v) v.begin(), v.end() - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) ((int)(x).size()) - -#define rep(i, a, b) for (int i = a; i < b; i++) - -#define rrep(i, a, b) for (int i = a; i >= b; i--) - - - -// Constants - -const ll MOD = 1e9 + 7; - -const ll INF = 1e18; - - - -// Debugging utility (comment out in contests) - -#define debug(x) cerr << #x << "" = "" << (x) << endl; - - - -// Fast IO - -void fast_io() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - -} - - - -// GCD and LCM - -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } - -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } - - - -// Modular arithmetic - -ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } - -ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } - -ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -ll mod_pow(ll a, ll b, ll m = MOD) { - - ll res = 1; - - while (b > 0) { - - if (b & 1) res = (res * a) % m; - - a = (a * a) % m; - - b >>= 1; - - } - - return res; - -} - - - -// Binary search example (can be modified) - -int binary_search(vector& v, int target) { - - int lo = 0, hi = sz(v) - 1; - - while (lo <= hi) { - - int mid = lo + (hi - lo) / 2; - - if (v[mid] == target) return mid; - - else if (v[mid] < target) lo = mid + 1; - - else hi = mid - 1; - - } - - return -1; - -} - - - -// Main function - -int main() { - - fast_io(); - - - - int t; // Number of test cases - - cin >> t; - - while (t--) { - - // Input and solve here - - int n; - - cin >> n; - - string s; - - cin>>s; - - int pidx=-1,sidx=-1; - - int flag=0; - - for(int i=0;i - -using namespace std; - - - -// Macros for shorthand - -#define ll long long - -#define ld long double - -#define pb push_back - -#define mp make_pair - -#define fi first - -#define se second - -#define all(v) v.begin(), v.end() - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) ((int)(x).size()) - -#define rep(i, a, b) for (int i = a; i < b; i++) - -#define rrep(i, a, b) for (int i = a; i >= b; i--) - - - -// Constants - -const ll MOD = 1e9 + 7; - -const ll INF = 1e18; - - - -// Debugging utility (comment out in contests) - -#define debug(x) cerr << #x << "" = "" << (x) << endl; - - - -// Fast IO - -void fast_io() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - -} - - - -// GCD and LCM - -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } - -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } - - - -// Modular arithmetic - -ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } - -ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } - -ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -ll mod_pow(ll a, ll b, ll m = MOD) { - - ll res = 1; - - while (b > 0) { - - if (b & 1) res = (res * a) % m; - - a = (a * a) % m; - - b >>= 1; - - } - - return res; - -} - - - -// Binary search example (can be modified) - -int binary_search(vector& v, int target) { - - int lo = 0, hi = sz(v) - 1; - - while (lo <= hi) { - - int mid = lo + (hi - lo) / 2; - - if (v[mid] == target) return mid; - - else if (v[mid] < target) lo = mid + 1; - - else hi = mid - 1; - - } - - return -1; - -} - - - -// Main function - -int main() { - - fast_io(); - - - - int t; // Number of test cases - - cin >> t; - - while (t--) { - - // Input and solve here - - int n; - - cin >> n; - - string s; - - cin>>s; - - int pidx=-1,sidx=-1; - - int flag=0; - - for(int i=0;i - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') - - { - - s[0]='.'; - - } - - if(s[n-1]=='p') - - { - - s[n-1]='.'; - - } - - int flag=0; - - int arr=0; - - for(int i=0;i - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='p') - - { - - s[0]='.'; - - } - - if(s[n-1]=='s') - - { - - s[n-1]='.'; - - } - - int flag=0; - - int arr=0; - - for(int i=1;i<=n;i++) - - { - - if(s[i]=='p'&&flag==0) - - { - - flag=1; - - } - - else if(s[i]=='s'&&flag) - - { - - arr=1; - - break; - - } - - } - - if(arr) - - { - - cout<<""NO""< - -// #define int long long - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using namespace chrono; - -// #define ll unsigned long long int - -#define ll long long int - -// ll mod = 1e9 + 7; - -ll mod = 998244353; - -// ll prime[1000009]; - -vector prime(100000000 + 1, true); - -ll maxpoweroftwo(ll n) - -{ - - ll x = log2(n); - - return x; - -} - -ll maxpoweroffive(ll n) - -{ - - ll x = log(n) / log(5); - - return x; - -} - -ll maxpoweroften(ll n) - -{ - - ll x = log(n) / log(10); - - return x; - -} - -static ll gcd(ll a, ll b) - -{ - - ll r, i; - - while (b != 0) - - { - - r = a % b; - - a = b; - - b = r; - - } - - return a; - -} - -ll lcm(ll a, ll b) - -{ - - return a * b / gcd(a, b); - -} - -vector decToBinary(ll n1) - -{ - - vector binaryNum(63); - - ll i = 0; - - while (n1 > 0) - - { - - binaryNum[i] = n1 % 2; - - // binaryNum.push_back(n1 % 2); - - n1 = n1 / 2; - - i++; - - } - - return binaryNum; - -} - -ll binaryToDecimal(vector v) - -{ - - ll dec_value = 0; - - - - // Initializing base value to 1, i.e 2^0 - - ll base = 1; - - - - ll i = v.size() - 1; - - while (i >= 0) - - { - - ll last_digit = v[i]; - - // temp = temp / 10; - - dec_value += last_digit * base; - - - - base = base * 2; - - i--; - - } - - - - return dec_value; - -} - -// k = upto k - -vector sieveOfEratosthenes(ll k) - -{ - - // Create a boolean vector initialized to true - - std::vector isPrime(k + 1, true); - - isPrime[0] = isPrime[1] = false; // 0 and 1 are not primes - - - - for (ll i = 2; i * i <= k; ++i) - - { - - if (isPrime[i]) - - { - - // Mark multiples of i as not prime - - for (ll j = i * i; j <= k; j += i) - - { - - isPrime[j] = false; - - } - - } - - } - - - - // Store all prime numbers in a vector - - std::vector primes; - - for (ll i = 2; i <= k; ++i) - - { - - if (isPrime[i]) - - { - - primes.push_back(i); - - } - - } - - - - return primes; - -} - -vector primeFactorization(ll n) - -{ - - vector factors; - - for (ll i = 2; i * i <= n; i++) - - { - - ll cnt = 0; - - while (n % i == 0) - - { - - cnt++; - - n /= i; - - factors.push_back(i); - - } - - } - - if (n > 1) - - factors.push_back(n); - - return factors; - -} - -bool get_bit(ll a, ll i) - -{ - - return a & (1ll << i); - -} - -ll binpow(ll a, ll b) - -{ - - ll ans = 1; - - while (b > 0) - - { - - if ((b & 1) == 1) - - ans *= a; - - a *= a; - - b = b >> 1; - - } - - return ans; - -} - - - -ll binpowmod(ll a, ll b) - -{ - - ll ans = 1; - - while (b > 0) - - { - - if ((b & 1) == 1) - - { - - ans *= a; - - ans %= mod; - - } - - a *= a; - - a %= mod; - - b = b >> 1; - - } - - return ans; - -} - -const ll MAX = 2e5 + 7; - -vector fact(MAX); - - - -ll add(ll a, ll b) - -{ - - return (a + b) % mod; - -} - - - -ll sub(ll a, ll b) - -{ - - return ((a - b) % mod + mod) % mod; - -} - - - -ll mult(ll a, ll b) - -{ - - return ((a * b) % mod); - -} - - - -ll inv(ll a) - -{ - - return binpowmod(a, mod - 2); - -} - - - -ll divide(ll a, ll b) - -{ - - return mult(a, inv(b)); - -} - - - -ll nCr(ll n, ll r) - -{ - - if (n < r) - - return 0; - - return divide(fact[n], mult(fact[r], fact[n - r])); - -} - - - -void preFactorial() - -{ - - fact[0] = 1; - - for (ll i = 1; i < MAX; i++) - - fact[i] = mult(i, fact[i - 1]); - -} - -void solve() { - - ll n;cin>>n;string s;cin>>s; - -ll counts=0; - -ll countp=0; - -ll posp=-1; - -ll poss=-1; - -for (ll i = 0; i < n; i++) - -{ - - if(s[i]=='s'){ - - poss=i; - - counts++; - - } - - else if(s[i]=='p'){ - - posp=i; - - countp++; - - } - -} - -if(counts==0 || countp==0){ - - cout<<""YES""; - -} - -else{ - - if(counts>1 && countp>1){ - - cout<<""NO""; - - } - - else{ - - if(counts==1 && countp==1){ - - if(poss==0 || posp==n-1){ - - cout<<""YES""; - - } - - else{ - - cout<<""NO""; - - } - - } - - else{ - - if(counts==1){ - - if(poss==0){ - - cout<<""YES""; - - } - - else{ - - cout<<""NO""; - - } - - } - - else{ - - if(posp==n-1){ - - cout<<""YES""; - - } - - else{ - - cout<<""NO""; - - } - - } - - } - - } - -} - -// sppp => 1234 - -// sp.p => 1234 - -// 123456 - - cout< A -> 15 MIN , B->45MIN , C->1 HR - -// BUT LOGIC TIME -> A-> 10 MIN , B-> 30MIN , C-> 30MIN - - - -// DIV3=> A-> 10 MIN , B-> 15MIN , C->45MIN , D->1HR - -// BUT LOGIC TIME -> A-> 5 MIN , B-> 10MIN , C-> 30MIN , D-> 30 MIN - - - -// DIV3=> A-> 5 MIN , B-> 10MIN , C->20MIN , D->35MIN , E->45MIN - -// BUT LOGIC TIME -> A-> 5 MIN , B-> 5MIN , C-> 15MIN , D-> 25 MIN , E->30MIN - - - -// increase speed in 'a' within 5 min - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - preFactorial(); - - int T; - - cin >> T; - - - - auto start1 = high_resolution_clock::now(); - - while (T--) - - { - - solve(); - - } - - auto stop1 = high_resolution_clock::now(); - - auto duration = duration_cast(stop1 - start1); - - cerr << ""Time: "" << duration.count() / 1000 << "" ms"" << endl; - - - - return 0; - -} - -","// #include - -// #define int long long - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using namespace chrono; - -// #define ll unsigned long long int - -#define ll long long int - -// ll mod = 1e9 + 7; - -ll mod = 998244353; - -// ll prime[1000009]; - -vector prime(100000000 + 1, true); - -ll maxpoweroftwo(ll n) - -{ - - ll x = log2(n); - - return x; - -} - -ll maxpoweroffive(ll n) - -{ - - ll x = log(n) / log(5); - - return x; - -} - -ll maxpoweroften(ll n) - -{ - - ll x = log(n) / log(10); - - return x; - -} - -static ll gcd(ll a, ll b) - -{ - - ll r, i; - - while (b != 0) - - { - - r = a % b; - - a = b; - - b = r; - - } - - return a; - -} - -ll lcm(ll a, ll b) - -{ - - return a * b / gcd(a, b); - -} - -vector decToBinary(ll n1) - -{ - - vector binaryNum(63); - - ll i = 0; - - while (n1 > 0) - - { - - binaryNum[i] = n1 % 2; - - // binaryNum.push_back(n1 % 2); - - n1 = n1 / 2; - - i++; - - } - - return binaryNum; - -} - -ll binaryToDecimal(vector v) - -{ - - ll dec_value = 0; - - - - // Initializing base value to 1, i.e 2^0 - - ll base = 1; - - - - ll i = v.size() - 1; - - while (i >= 0) - - { - - ll last_digit = v[i]; - - // temp = temp / 10; - - dec_value += last_digit * base; - - - - base = base * 2; - - i--; - - } - - - - return dec_value; - -} - -// k = upto k - -vector sieveOfEratosthenes(ll k) - -{ - - // Create a boolean vector initialized to true - - std::vector isPrime(k + 1, true); - - isPrime[0] = isPrime[1] = false; // 0 and 1 are not primes - - - - for (ll i = 2; i * i <= k; ++i) - - { - - if (isPrime[i]) - - { - - // Mark multiples of i as not prime - - for (ll j = i * i; j <= k; j += i) - - { - - isPrime[j] = false; - - } - - } - - } - - - - // Store all prime numbers in a vector - - std::vector primes; - - for (ll i = 2; i <= k; ++i) - - { - - if (isPrime[i]) - - { - - primes.push_back(i); - - } - - } - - - - return primes; - -} - -vector primeFactorization(ll n) - -{ - - vector factors; - - for (ll i = 2; i * i <= n; i++) - - { - - ll cnt = 0; - - while (n % i == 0) - - { - - cnt++; - - n /= i; - - factors.push_back(i); - - } - - } - - if (n > 1) - - factors.push_back(n); - - return factors; - -} - -bool get_bit(ll a, ll i) - -{ - - return a & (1ll << i); - -} - -ll binpow(ll a, ll b) - -{ - - ll ans = 1; - - while (b > 0) - - { - - if ((b & 1) == 1) - - ans *= a; - - a *= a; - - b = b >> 1; - - } - - return ans; - -} - - - -ll binpowmod(ll a, ll b) - -{ - - ll ans = 1; - - while (b > 0) - - { - - if ((b & 1) == 1) - - { - - ans *= a; - - ans %= mod; - - } - - a *= a; - - a %= mod; - - b = b >> 1; - - } - - return ans; - -} - -const ll MAX = 2e5 + 7; - -vector fact(MAX); - - - -ll add(ll a, ll b) - -{ - - return (a + b) % mod; - -} - - - -ll sub(ll a, ll b) - -{ - - return ((a - b) % mod + mod) % mod; - -} - - - -ll mult(ll a, ll b) - -{ - - return ((a * b) % mod); - -} - - - -ll inv(ll a) - -{ - - return binpowmod(a, mod - 2); - -} - - - -ll divide(ll a, ll b) - -{ - - return mult(a, inv(b)); - -} - - - -ll nCr(ll n, ll r) - -{ - - if (n < r) - - return 0; - - return divide(fact[n], mult(fact[r], fact[n - r])); - -} - - - -void preFactorial() - -{ - - fact[0] = 1; - - for (ll i = 1; i < MAX; i++) - - fact[i] = mult(i, fact[i - 1]); - -} - -void solve() { - - ll n;cin>>n;string s;cin>>s; - - - -// pspspsps - - - -// .sp. - -// sssssss - -// sspp - -// 1234 - -// 4213 - -// 4321 - - - -// sps no - -// spps no - -// ppps no - - - -// ssss ok - -// pppp ok - -// sssp ok - -// spp => 123 - -// .sss => 4321 ok - -// .pppp => 12345 ok - -// .spp => 1234 no - -// .ppps => 12341 no - -// .ssp => 4321 ok - - - -// ss.pp=> 4321 - - - - - -// ristricted case => - -// p ke bad s - -// s ke bad p only one time - -ll counts=0; - -ll countp=0; - -ll posp=-1; - -ll poss=-1; - -for (ll i = 0; i < n; i++) - -{ - - if(s[i]=='s'){ - - poss=i; - - counts++; - - } - - else if(s[i]=='p'){ - - posp=i; - - countp++; - - } - -} - -if(counts==0 || countp==0){ - - cout<<""YES""; - -} - -else{ - - if(countp>1){ - - cout<<""NO""; - - } - - else{ - - if(posp A -> 15 MIN , B->45MIN , C->1 HR - -// BUT LOGIC TIME -> A-> 10 MIN , B-> 30MIN , C-> 30MIN - - - -// DIV3=> A-> 10 MIN , B-> 15MIN , C->45MIN , D->1HR - -// BUT LOGIC TIME -> A-> 5 MIN , B-> 10MIN , C-> 30MIN , D-> 30 MIN - - - -// DIV3=> A-> 5 MIN , B-> 10MIN , C->20MIN , D->35MIN , E->45MIN - -// BUT LOGIC TIME -> A-> 5 MIN , B-> 5MIN , C-> 15MIN , D-> 25 MIN , E->30MIN - - - -// increase speed in 'a' within 5 min - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - preFactorial(); - - int T; - - cin >> T; - - - - auto start1 = high_resolution_clock::now(); - - while (T--) - - { - - solve(); - - } - - auto stop1 = high_resolution_clock::now(); - - auto duration = duration_cast(stop1 - start1); - - cerr << ""Time: "" << duration.count() / 1000 << "" ms"" << endl; - - - - return 0; - -} - -",1 -Haze__m,2049B - pspspsps,c++23 ,307080026,307078860,"#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define YES cout << ""YES\n""; - -#define NO cout << ""NO\n""; - - - -const int N = 1e6 + 5; - - - -signed main() // Road to red - -{ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - - int tes = 1; - - cin >> tes; - - while (tes--) - - { - - int n,res{1}; cin >> n; - - string s; cin >> s; - - bool p = 0; - - for(int i = 0; i < n; i++) - - { - - if(s[i] == 'p'){p = 1;} - - if(p && s[i] == 's'){res = 0; break;} - - } - - bool ss = 0; - - for(int i = 1; i < n; i++) - - { - - if(i < n-2 && s[i] == 's'){ss = 1;} - - if(ss && s[i] == 'p' && i < n-1){res = 0; break;} - - } - - if(res){YES} - - else{NO} - - } - - return 0; - -}","#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define YES cout << ""YES\n""; - -#define NO cout << ""NO\n""; - - - -const int N = 1e6 + 5; - - - -signed main() // Road to red - -{ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - - int tes = 1; - - cin >> tes; - - while (tes--) - - { - - int n,res{1}; cin >> n; - - string s; cin >> s; - - bool p = 0; - - for(int i = 0; i < n; i++) - - { - - if(s[i] == 'p'){p = 1;} - - if(p && s[i] == 's'){res = 0; break;} - - // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;} - - } - - bool ss = 0; - - for(int i = 1; i < n; i++) - - { - - if(i < n-2 && s[i] == 's'){ss = 1;} - - if(ss && s[i] == 'p'){res = 0; break;} - - // else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;} - - } - - if(res){YES} - - else{NO} - - } - - return 0; - -}",1 -jp5222347,2049B - pspspsps,c++20 ,304401037,304401778,"#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - stack sta; - - bool flag=false; - - for(int i=0;i st; - - for(int i=0;i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - stack sta; - - bool flag=false; - - sta.push(s[0]); - - for(int i=1;i st; - - for(int i=0;i - -using namespace std; - -typedef long long ll; - -typedef long double ld; - -#define fu(i,a,b) for(int i = a; i=0; i--) - -const int MOD = 998244353; - -const int NMAX = 200000; - - - - - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(0); - - - - - - - - int t; - - cin >> t; - - while (t--) { - - int n; - - cin >> n; - - - - string s; - - - - int t=0; - - - - cin >> s; - - - - if(s[0]== 's') - - { - - t=1; - - } - - else if(s[n-1]=='p') - - { - - t=1; - - } - - else - - { - - t=1; - - f(i,n) - - { - - if(s[i]!= '.') - - { - - t=0; - - } - - } - - } - - - - char m = '.'; - - - - - - f(i,n) - - { - - - - - - if(s[i]=='s' && m == 'p') - - { - - t=0; - - } - - - - - - - - if(s[i]=='s') - - { - - m = 's'; - - } - - if(s[i]=='p') - - { - - m = 'p'; - - } - - - - } - - - - if(t==1) - - { - - cout << ""YES"" << endl; - - } - - else - - { - - cout << ""NO"" << endl; - - } - - - - - - - - } - - - - return 0; - -} - -","#include - -using namespace std; - -typedef long long ll; - -typedef long double ld; - -#define fu(i,a,b) for(int i = a; i=0; i--) - -const int MOD = 998244353; - -const int NMAX = 200000; - - - - - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(0); - - - - - - - - int t; - - cin >> t; - - while (t--) { - - int n; - - cin >> n; - - - - string s; - - - - int t=0; - - - - cin >> s; - - - - if(s[0]=='s') - - { - - s[0] = '.'; - - } - - if(s[n-1]=='p') - - { - - s[n-1] = '.'; - - } - - - - int g=0,h=0; - - - - f(i,n) - - { - - - - if(s[i]=='p') - - { - - g =1; - - } - - if(s[i]=='s') - - { - - h =1; - - } - - - - } - - - - if(g==1 && h==1) - - { - - cout << ""NO"" << endl; - - } - - else - - { - - cout << ""YES"" << endl; - - } - - - - - - } - - - - return 0; - -} - -",2 -Harsh_Sharawat,2049B - pspspsps,c++17 ,307558344,307559077,"#include -using namespace std; - -/* clang-format off */ - -/* TYPES */ -#define ll long long -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define mii map -#define si set -#define sc set - -/* FUNCTIONS */ -#define f(a,n) for(long long int i=a;i=s;i--) -#define pb push_back -#define eb emplace_back -#define all(a) (a).begin(),(a).end() - - -/* PRINTS */ -template -void print_v(vector &v) { cout << ""{""; for (auto x : v) cout << x << "",""; cout << ""\b}""; } - -/* UTILS */ -#define M 1000000007 -#define PI 3.1415926535897932384626433832795 -#define read(type) readInt() - -ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } -ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } - -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } - -bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; } - -#define yy cout<<""Yes\n"" -#define nn cout<<""No\n"" - -/* -question intuitions: -- dp --compute next result from the previous result of the sequence - -- you have a choice at each step and each choice can lead to answer - -- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n)) -or upper/lower bound of something in a sorted sample namespac - --- where anwer space is sorted and in fixed range - --heap -- find lowest or largest of a segment -- k is given example kth largest or smallest -if k+smallest -- kth smallest--maxheap -if k+largest --kth largest-- minheap -complexity-- nlog(k) -*/ - - -#define inputv(arr,n) {for(int i=0;i>arr[i];} -#define printv(a) {for(auto u:a) cout<>n; - - string s; - cin>>s; - - - string temp = """"; - for(auto it: s) - if(it=='.')continue; - else temp+=it; - if(n==1 || temp == """") { - yy; - return; - } - for(int i = 1; i>t; - while(t--){ - - solve(); - - - - - - } - return 0; -}","#include -using namespace std; - -/* clang-format off */ - -/* TYPES */ -#define ll long long -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define mii map -#define si set -#define sc set - -/* FUNCTIONS */ -#define f(a,n) for(long long int i=a;i=s;i--) -#define pb push_back -#define eb emplace_back -#define all(a) (a).begin(),(a).end() - - -/* PRINTS */ -template -void print_v(vector &v) { cout << ""{""; for (auto x : v) cout << x << "",""; cout << ""\b}""; } - -/* UTILS */ -#define M 1000000007 -#define PI 3.1415926535897932384626433832795 -#define read(type) readInt() - -ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } -ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } - -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } - -bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; } - -#define yy cout<<""Yes\n"" -#define nn cout<<""No\n"" - -/* -question intuitions: -- dp --compute next result from the previous result of the sequence - -- you have a choice at each step and each choice can lead to answer - -- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n)) -or upper/lower bound of something in a sorted sample namespac - --- where anwer space is sorted and in fixed range - --heap -- find lowest or largest of a segment -- k is given example kth largest or smallest -if k+smallest -- kth smallest--maxheap -if k+largest --kth largest-- minheap -complexity-- nlog(k) -*/ - - -#define inputv(arr,n) {for(int i=0;i>arr[i];} -#define printv(a) {for(auto u:a) cout<>n; - - string s; - cin>>s; - - - if(n==1) { - yy; - return; - } - if(s[0]=='s') s[0] = '.'; - if(s[n-1] == 'p') s[n-1] = '.'; - - - char ch = ' '; - for(auto it: s){ - if(it!='.'){ - if(ch == ' '){ - ch = it; - }else{ - if(ch != it) { - nn; - return - ; - } - } - } - } - - yy; - - - -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - int t; cin>>t; - while(t--){ - - solve(); - - - - - - } - return 0; -}",2 -yz99,2049B - pspspsps,c++17 ,307018021,307017699,"#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - - - while(t --) - - { - - int n; - - string str; - - cin >> n >> str; - - int p = n, s = -1; - - for(int i = 0; i < n; i ++) - - { - - if(str[i] == 'p') p = min(p, i); - - if(str[i] == 's') s = max(s, i); - - } - - if(p < s) cout << ""NO"" << ""\n""; - - else if(s == 0 || s == -1 || p == n - 1 || p == n) cout << ""YES"" << ""\n""; - - else cout << ""NO"" << ""\n""; - - - - } - -}","#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - - - while(t --) - - { - - int n; - - string str; - - cin >> n >> str; - - int p = n, s = -1; - - for(int i = 0; i < n; i ++) - - { - - if(str[i] == 'p') p = min(p, i); - - if(str[i] == 's') s = max(s, i); - - } - - if(p < s) cout << ""NO"" << ""\n""; - - else if(str[0] == '.' && str[n - 1] == '.' && p != n && s != -1) cout << ""NO"" << ""\n""; - - else cout << ""YES"" << ""\n""; - - - - } - -}",1 -Torluch,2049B - pspspsps,c++23 ,304856107,304856290,"#include - -using namespace std; - -ifstream fin(""input.txt""); - -ofstream fout(""output.txt""); - - - - - - - -void solve(){ - - int n; cin >> n; - - vector v(n); - - for(auto &i: v) cin >> i; - - - - int imp = 0; - - int posSmx = -1; - - for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i; - - for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1; - - - - if(posSmx != -1){ - - for(int i = posSmx; i < n; i++){ - - if(v[i] == 'p'){ - - if(i != n - 1) imp = 1; - - } - - } - - } - - cout << ((imp == 1) ? ""NO"": ""YES"") << '\n'; - -} - - - -int32_t main() { - - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - - - int t = 1; - - cin >> t; - - while(t--) solve(); - -}","#include - -using namespace std; - -ifstream fin(""input.txt""); - -ofstream fout(""output.txt""); - - - - - - - -void solve(){ - - int n; cin >> n; - - vector v(n); - - for(auto &i: v) cin >> i; - - - - int imp = 0; - - int posSmx = -1; - - for(int i = 0; i < n; i++) if(v[i] == 's') posSmx = i; - - for(int i = 0; i < n; i++) if(v[i] == 'p' && i < posSmx) imp = 1; - - - - if(posSmx > 0){ - - for(int i = posSmx; i < n; i++){ - - if(v[i] == 'p'){ - - if(i != n - 1) imp = 1; - - } - - } - - } - - cout << ((imp == 1) ? ""NO"": ""YES"") << '\n'; - -} - - - -int32_t main() { - - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - - - int t = 1; - - cin >> t; - - while(t--) solve(); - -}",2 -Haze__m,2049B - pspspsps,c++23 ,307078318,307080026,"#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define YES cout << ""YES\n""; - -#define NO cout << ""NO\n""; - - - -const int N = 1e6 + 5; - - - -signed main() // Road to red - -{ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - - int tes = 1; - - cin >> tes; - - while (tes--) - - { - - int n,res{1}; cin >> n; - - string s; cin >> s; - - for(auto &x : s){if(x == '.'){x = 's';}} - - for(int i = 0; i < n-1; i++) - - { - - if(s[i] == 'p' && s[i+1] == 's'){res = 0; break;} - - else if(s[i] == 's' && s[i+1] == 'p' && i != 0 && i != n-2){res = 0; break;} - - } - - if(res){YES} - - else{NO} - - } - - return 0; - -}","#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define YES cout << ""YES\n""; - -#define NO cout << ""NO\n""; - - - -const int N = 1e6 + 5; - - - -signed main() // Road to red - -{ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - - int tes = 1; - - cin >> tes; - - while (tes--) - - { - - int n,res{1}; cin >> n; - - string s; cin >> s; - - bool p = 0; - - for(int i = 0; i < n; i++) - - { - - if(s[i] == 'p'){p = 1;} - - if(p && s[i] == 's'){res = 0; break;} - - } - - bool ss = 0; - - for(int i = 1; i < n; i++) - - { - - if(i < n-2 && s[i] == 's'){ss = 1;} - - if(ss && s[i] == 'p' && i < n-1){res = 0; break;} - - } - - if(res){YES} - - else{NO} - - } - - return 0; - -}",2 -curz_,2049B - pspspsps,c++17 ,306890786,306897679,"#include - -using namespace std; - -#include - -#include - - - -template - -using ordered_set = - - __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, - - __gnu_pbds::tree_order_statistics_node_update>; - -using pi = pair; - -using pl = pair; - -using vi = vector; - -using vl = vector; - -using vvi = vector>; - -using vvl = vector>; - -using vpi = vector>; - -using vpl = vector>; - -using vvpi = vector>>; - -using vvpl = vector>>; - -using vb = vector; - -using vs = vector; - -using si = set; - -using mpii = map; - - - -#define fori(i, a, b) for (int i = a; i < b; ++i) - -#define fore(i, a, b) for (int i = a; i <= b; ++i) - -#define forr(i, a, b) for (int i = a; i > b; --i) - -#define forre(i, a, b) for (int i = a; i >= b; --i) - - - -#define pb push_back - -#define sc static_cast - -#define all(v) v.begin(), v.end() - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) (int32_t)x.size() - -#define yes cout << ""YES\n""; - -#define no cout << ""NO\n""; - -#define approx(a) fixed << setprecision(a) - -#define ff first - -#define ss second - -#define INF LONG_LONG_MAX - -#define INFF LONG_LONG_MIN - -#define inf INT_MAX - -#define inff INT_MIN - -#define nl '\n' - - - -template void read(vector &v); - -template void read(pair &p); - -template void read(array &a); - -template void read(T &x) { - - cin >> x; - -} - -template void read(R &r, T &...t) { - - read(r); - - read(t...); - -}; - -template void read(vector &v) { - - for (auto &x : v) - - read(x); - -} - -template void read(pair &p) { - - read(p.ff, p.ss); - -} - -template void read(array &a) { - - for (auto &x : a) - - read(x); - -} - - - -template void pr(const pair &x); - -template void pr(const T &x) { - - cout << x; - -} - -template void pr(const R &r, const T &...t) { - - pr(r); - - pr(t...); - -} - -template void pr(const pair &x) { - - pr(""{"", x.ff, "", "", x.ss, ""}""); - -} - -void ps() { - - pr(""\n""); - -} - -template void ps(const T &x) { - - pr(x); - - ps(); - -} - -template void ps(vector &v) { - - for (auto &x : v) - - pr(x, ' '); - - ps(); - -} - -template void ps(const array &a) { - - for (auto &x : a) - - pr(x, ' '); - - ps(); - -} - -template void ps(const pair &x) { - - pr(x.ff, ' ', x.ss); - - ps(); - -} - -template void ps(const R &r, const T &...t) { - - pr(r, ' '); - - ps(t...); - -} - -#define definp() \ - - int n; \ - - read(n); \ - - vl a(n); \ - - read(a); - -#define int long long - - - -// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1}; - -#define MOD (long long)(1e9 + 7) - -void exec_once() { - -} - -bool tc = 1; - - - -void solve(int tn [[maybe_unused]]) { - - int n;read(n); - - string s; - - read(s); - - int cur = -1; - - bool p = 0; - - fori(i,0,n){ - - if(s[i] == 's'&&p)return ps(""NO""); - - if(s[i] == 's') cur=i; - - if(s[i] == 'p')p=1; - - if(s[i] == 'p' && cur!=-1){ - - if(i!=n-1) return ps(""NO""); - - } - - } - - ps(""YES""); - -} - - - -int32_t main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - exec_once(); - - int t = 1; - - if (tc) - - cin >> t; - - fore(tn, 1, t) solve(tn); - - return 0; - -} - -","#include - -using namespace std; - -#include - -#include - - - -template - -using ordered_set = - - __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, - - __gnu_pbds::tree_order_statistics_node_update>; - -using pi = pair; - -using pl = pair; - -using vi = vector; - -using vl = vector; - -using vvi = vector>; - -using vvl = vector>; - -using vpi = vector>; - -using vpl = vector>; - -using vvpi = vector>>; - -using vvpl = vector>>; - -using vb = vector; - -using vs = vector; - -using si = set; - -using mpii = map; - - - -#define fori(i, a, b) for (int i = a; i < b; ++i) - -#define fore(i, a, b) for (int i = a; i <= b; ++i) - -#define forr(i, a, b) for (int i = a; i > b; --i) - -#define forre(i, a, b) for (int i = a; i >= b; --i) - - - -#define pb push_back - -#define sc static_cast - -#define all(v) v.begin(), v.end() - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) (int32_t)x.size() - -#define yes cout << ""YES\n""; - -#define no cout << ""NO\n""; - -#define approx(a) fixed << setprecision(a) - -#define ff first - -#define ss second - -#define INF LONG_LONG_MAX - -#define INFF LONG_LONG_MIN - -#define inf INT_MAX - -#define inff INT_MIN - -#define nl '\n' - - - -template void read(vector &v); - -template void read(pair &p); - -template void read(array &a); - -template void read(T &x) { - - cin >> x; - -} - -template void read(R &r, T &...t) { - - read(r); - - read(t...); - -}; - -template void read(vector &v) { - - for (auto &x : v) - - read(x); - -} - -template void read(pair &p) { - - read(p.ff, p.ss); - -} - -template void read(array &a) { - - for (auto &x : a) - - read(x); - -} - - - -template void pr(const pair &x); - -template void pr(const T &x) { - - cout << x; - -} - -template void pr(const R &r, const T &...t) { - - pr(r); - - pr(t...); - -} - -template void pr(const pair &x) { - - pr(""{"", x.ff, "", "", x.ss, ""}""); - -} - -void ps() { - - pr(""\n""); - -} - -template void ps(const T &x) { - - pr(x); - - ps(); - -} - -template void ps(vector &v) { - - for (auto &x : v) - - pr(x, ' '); - - ps(); - -} - -template void ps(const array &a) { - - for (auto &x : a) - - pr(x, ' '); - - ps(); - -} - -template void ps(const pair &x) { - - pr(x.ff, ' ', x.ss); - - ps(); - -} - -template void ps(const R &r, const T &...t) { - - pr(r, ' '); - - ps(t...); - -} - -#define definp() \ - - int n; \ - - read(n); \ - - vl a(n); \ - - read(a); - -#define int long long - - - -// int dx[4] = {-1, 1, -1, 1}, dy[4] = {-1, -1, 1, 1}; - -#define MOD (long long)(1e9 + 7) - -void exec_once() { - -} - -bool tc = 1; - - - -void solve(int tn [[maybe_unused]]) { - - int n;read(n); - - string s; - - read(s); - - int cur = -1; - - bool p = 0; - - int cnt1 = 0, cnt2=0; - - fori(i,0,n){ - - if(s[i] == 's'&&p)return ps(""NO""); - - if(s[i] == 'p')p=1; - - if(s[i]=='s') cnt1++; - - else if(s[i]=='p')cnt2++; - - } - - if(cnt1==1 && (s[0] == 's' || s[n-1]=='s')) return ps(""YES""); - - if(cnt2==1 && (s[0] == 'p' || s[n-1]=='p')) return ps(""YES""); - - if(cnt1==0 || cnt2 == 0) return ps(""YES""); - - ps(""NO""); - -} - - - -int32_t main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - exec_once(); - - int t = 1; - - if (tc) - - cin >> t; - - fore(tn, 1, t) solve(tn); - - return 0; - -} - -",2 -yz99,2049B - pspspsps,c++17 ,307018021,307014461,"#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - - - while(t --) - - { - - int n; - - string str; - - cin >> n >> str; - - int p = n, s = -1; - - for(int i = 0; i < n; i ++) - - { - - if(str[i] == 'p') p = min(p, i); - - if(str[i] == 's') s = max(s, i); - - } - - if(p < s) cout << ""NO"" << ""\n""; - - else if(s == 0 || s == -1 || p == n - 1 || p == n) cout << ""YES"" << ""\n""; - - else cout << ""NO"" << ""\n""; - - - - } - -}","#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - - - while(t --) - - { - - int n; - - string str; - - cin >> n >> str; - - int p = 0, s = 0; - - for(int i = 0; i < n; i ++) - - { - - if(str[i] == 'p') p ++; - - if(str[i] == 's') s ++; - - } - - if(p >= 1 && s >= 1 && str[n - 1] != 'p') - - cout << ""NO"" << ""\n""; - - else cout << ""YES"" << ""\n""; - - } - -}",1 -THEarchitect,2049B - pspspsps,python,307652696,307651475,"a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - j = list(c) - - - - if j[0] == ""s"": - - j[0] = ""."" - - - - if j[-1] == ""p"": - - j[-1] = ""."" - - - - l = 0 - - if ""s"" in j and ""p"" in j: - - l = -1 - - - - - - print(""Yes"") if l == 0 else print(""No"") - - ","a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - k = 0 - - for z in range(b): - - if c[z] == ""p"" and k == 0: - - k = 1 - - - - elif k == 1 and c[z] == ""s"": - - k = -1 - - break - - - - if k != -1: - - n = c[0] - - for y in range(1,b): - - if c[y-1] != c[y]: - - n += c[y] - - - - - - if "".sp."" in n: - - print(""No"") - - - - else: - - s = 0 - - p = 0 - - l = 0 - - for y in range(b): - - if c[y] == ""."": - - if (s > 1 and p > 0) or (s > 0 and p > 1): - - l = -1 - - break - - - - s = 0 - - p = 0 - - else: - - if c[y] == ""s"": - - s += 1 - - - - else: - - p += 1 - - - - - - s = 0 - - p = 0 - - for y in range(b-1,-1,-1): - - if c[y] == ""."": - - if (s > 1 and p > 0) or (s > 0 and p > 1): - - l = -1 - - break - - - - s = 0 - - p = 0 - - - - else: - - if c[y] == ""s"": - - s += 1 - - - - else: - - p += 1 - - - - - - - - if l == -1: - - print(""No"") - - - - else: - - print(""Yes"") - - - - - - - - elif k == -1: - - print(""No"") - -",1 -chandupaambepitiya,2049B - pspspsps,c++17 ,304643445,304646393,"#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - int l1 = s.length(); - - char last = s[0]; - - bool can = true; - - - - if (last == '.') { - - bool pf = false, sf = false; - - for (int i = 0; i < l1; i++) { // Start from i = 0 to consider all characters - - if (s[i] == 'p') pf = true; - - if (s[i] == 's') sf = true; - - } - - if (sf && pf) can = false; - - } else { - - bool pf = false, sf = false; - - int countp = 0, counts = 0; - - - - for (auto x : s) { - - if (x == 'p') { - - pf = true; - - countp++; - - } - - if (x == 's') { - - sf = true; - - counts++; - - if (pf) { - - can = false; - - break; - - } - - } - - } - - if (countp > 1 && counts > 1) { - - can = false; - - } - - } - - - - if (can) { - - cout << ""yes"" << endl; - - } else { - - cout << ""no"" << endl; - - } - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -","#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - int l1 = s.length(); - - bool can = true; - - bool pf=false; - - bool sf=false; - - int s_found=-1; - - for(int i=0;i> t; - - while (t--) { - - solve(); - - } - -} - -",2 -HetB1809,2049B - pspspsps,c++23 ,307037841,307035094,"#include - -#define ll long long - -using namespace std; - -bool check(string s) - -{ - - bool did_come = false; - - ll l = s.length(); - - ll index_last_p = l; - - for (ll i = 0; i < l - 1; i++) - - { - - if (s[i] == 's' && i != 0) - - { - - did_come = true; - - } - - if (s[i] == 'p') - - { - - index_last_p = i; - - if (did_come) - - { - - return false; - - } - - } - - } - - for (ll i = index_last_p + 1; i < l; i++) - - { - - if (s[i] == 's') - - return false; - - } - - return true; - -} - -void solve() - -{ - - ll n; - - cin >> n; - - string s; - - cin >> s; - - if (check(s)) - - cout << ""YES"" << endl; - - else - - cout << ""NO"" << endl; - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -}","#include - -#define ll long long - -using namespace std; - -bool pisleft(string s) - -{ - - ll l = s.length(); - - bool start = false; - - for (ll i = 0; i < l; i++) - - { - - if (s[i] == 'p') - - { - - start = true; - - } - - if (s[i] == 's' && start) - - { - - return true; - - } - - } - - return false; - -} - -void solve() - -{ - - ll n; - - cin >> n; - - string s; - - cin >> s; - - if (pisleft(s)) - - { - - cout << ""NO"" << endl; - - return; - - } - - set perm; - - vector per_ct; - - ll ct_p = 0, ct_s = 0; - - for (ll i = 1; i < s.length() - 1; i++) - - { - - if (s[i] == 'p') - - { - - ct_p++; - - per_ct.push_back(i + 1); - - perm.insert(i + 1); - - } - - else if (s[i] == 's') - - { - - ct_s++; - - per_ct.push_back(s.length() - i); - - perm.insert(s.length() - i); - - } - - } - - if (s[0] == 'p') - - ct_p++; - - if (s[s.length() - 1] == 's') - - ct_s++; - - if (s[0] == 'p' && ct_s != 0) - - { - - cout << ""NO"" << endl; - - return; - - } - - if (s[s.length() - 1] == 's' && ct_p != 0) - - { - - cout << ""NO"" << endl; - - return; - - } - - if (per_ct.size() != perm.size()) - - { - - cout << ""NO"" << endl; - - } - - else - - { - - cout << ""YES"" << endl; - - } - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -}",1 -as_dfsdf#,2049B - pspspsps,c++17 ,306855770,306855555,"#ifdef _MSC_VER - -# include - -# define __builtin_popcount __popcnt - -#endif - -#include - -#pragma GCC optimize(""O3"") - -#pragma GCC optimize(""Ofast"") - -#pragma GCC optimize(""unroll-loops"") - -#pragma GCC target(""avx,avx2,fma"") - -using namespace std; - -typedef long long ll; - -typedef pair pii; - -typedef pair pll; - -typedef long double ld; - -#define MAX 3030 - -#define MAXS 20 - -#define BMAX 35 - -#define MOD 100'000'000 - -#define TC 1 - -#define ln '\n' - -#define bb ' ' - -int A[MAX]; - -void solve() { - - int N; - - cin >> N; - - string s; - - cin >> s; - - int pc, sc; - - pc = sc = 0; - - int i; - - for (i = 0; i < N; i++) { - - if (s[i] == 'p' && i < N - 1) pc++; - - if (s[i] == 's' && i) sc++; - - } - - if (!pc || !sc) { - - cout << ""YES"" << ln; - - return; - - } - - else cout << ""NO"" << ln; - -} - -signed main() { - - ios::sync_with_stdio(false), cin.tie(0); - - int T = 1; - - if (TC) cin >> T; - - while (T--) solve(); - -}","#ifdef _MSC_VER - -# include - -# define __builtin_popcount __popcnt - -#endif - -#include - -#pragma GCC optimize(""O3"") - -#pragma GCC optimize(""Ofast"") - -#pragma GCC optimize(""unroll-loops"") - -#pragma GCC target(""avx,avx2,fma"") - -using namespace std; - -typedef long long ll; - -typedef pair pii; - -typedef pair pll; - -typedef long double ld; - -#define MAX 3030 - -#define MAXS 20 - -#define BMAX 35 - -#define MOD 100'000'000 - -#define TC 1 - -#define ln '\n' - -#define bb ' ' - -int A[MAX]; - -void solve() { - - int N; - - cin >> N; - - string s; - - cin >> s; - - int pc, sc; - - pc = sc = 0; - - for (auto c : s) { - - if (c == 'p') pc++; - - else if (c == 's') sc++; - - } - - if (pc > 1 && sc > 1) { - - cout << ""NO"" << ln; - - return; - - } - - if (!pc || !sc) { - - cout << ""YES"" << ln; - - return; - - } - - if (pc == 1) { - - if (s[N - 1] == 'p') cout << ""YES"" << ln; - - else cout << ""NO"" << ln; - - } - - else { - - if (s[0] == 's') cout << ""YES"" << ln; - - else cout << ""NO"" << ln; - - } - -} - -signed main() { - - ios::sync_with_stdio(false), cin.tie(0); - - int T = 1; - - if (TC) cin >> T; - - while (T--) solve(); - -}",1 -HoneyGupta,2049B - pspspsps,c++23 ,306328509,306330901,"#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0; - - rep(i,0,n){ - - if(s[i]=='p') prevp=1; - - else if(prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - rep(i,1,n-2){ - - if(s[i]=='s' && s[i+1]=='p'){ - - cout<<""NO\n""; - - return; - - } - - } - - cout<<""YES\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}","#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0,prevs=0; - - rep(i,0,n){ - - if(s[i]=='p'){ - - if(prevp==0) prevp=i+1; - - } - - else if(s[i]=='s'){ - - prevs=i+1; - - if(prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - } - - if(!prevs || !prevp) cout<<""YES\n""; - - else if(prevs==1 || prevp==n) cout<<""YES\n""; - - else cout<<""NO\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}",2 -tusharb_25,2049B - pspspsps,c++17 ,308491627,308492837,"#include - -using namespace std; - -#define ll long long - -#define int long long - -const ll N=1e9+7; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int cs=count(s.begin(),s.end(),'s'); - - int cp=count(s.begin(),s.end(),'p'); - - int cd=count(s.begin(),s.end(),'.'); - - if(cs==0||cp==0) {cout<<""YES\n""; return;} - - int i=n-1; - - bool found=true; - - while(i>=0){ - - if(s[i]=='.') i--; - - else if(s[i]=='s'){ - - found=false; - - break; - - } - - else break; - - } - - if(!found) {cout<<""NO\n""; return;} - - i=0; - - while(i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -#define ll long long - -#define int long long - -const ll N=1e9+7; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') s[0]='.'; - - if(s[n-1]=='p') s[n-1]='.'; - - int cs=count(s.begin(),s.end(),'s'); - - int cp=count(s.begin(),s.end(),'p'); - - int cd=count(s.begin(),s.end(),'.'); - - if(cs==0||cp==0) {cout<<""YES\n""; return;} - - cout<<""NO\n""; - - return; - -} - - - -int32_t main() { - - ios::sync_with_stdio(0); - - cin.tie(0); - - ll t; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -chandupaambepitiya,2049B - pspspsps,c++17 ,304643309,304646393,"#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int l1=s.length(); - - char last=s[0]; - - bool can=true; - - if(last=='.'){ - - bool pf=false; - - bool sf=false; - - for(int i=1;i1 && counts>1){ - - can=false; - - } - - } - - if(can){ - - cout<<""yes""<>t; - - while(t--){ - - solve(); - - } - - } - -","#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - int l1 = s.length(); - - bool can = true; - - bool pf=false; - - bool sf=false; - - int s_found=-1; - - for(int i=0;i> t; - - while (t--) { - - solve(); - - } - -} - -",2 -fake_lebo,2049B - pspspsps,c++23 ,304549642,304542691,"#include -#define ll long long int -#define ld long double -#define mk make_pair -#define pb push_back -#define INF (ll)1e18 -#define pll pair -#define vll vector -#define vii vector -#define all(x) x.begin(), x.end() -#define allr(x) x.rbegin(), x.rend() -#define isON(n, k) (((n) >> (k)) & 1) -#define f(i, a, b) for (ll i = a; i < b; i++) -#define fb(i, a, b) for (ll i = a; i > b; i--) -#define ff first -#define ss second -#define PI 3.141592653589793238 -// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; -// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; -using namespace std; -const int N = 2e5 + 5; -const ll MOD = 1e9 + 7; -ll t = 1; - -void solve() -{ - ll n; - cin >> n; - string s; - cin >> s; - // Check if the string contains 's' or 'p' - if (s.find('s') == string::npos && s.find('p') == string::npos) - { - cout << ""YES\n""; - return; - } - if (s[0] == 's') s[0] = '.'; - if (s.back() == 'p') s.back() = '.'; - bool fp = false, fs = false; - f(i, 0, n) - { - switch (s[i]) - { - case 's': - fs = true; - break; - case 'p': - fp = true; - break; - } - } - cout << (fs && fp ? ""NO\n"" : ""YES\n""); - - return; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}","#include -#define ll long long int -#define ld long double -#define mk make_pair -#define pb push_back -#define INF (ll)1e18 -#define pll pair -#define vll vector -#define vii vector -#define all(x) x.begin(), x.end() -#define allr(x) x.rbegin(), x.rend() -#define isON(n, k) (((n) >> (k)) & 1) -#define f(i, a, b) for (ll i = a; i < b; i++) -#define fb(i, a, b) for (ll i = a; i > b; i--) -#define ff first -#define ss second -#define PI 3.141592653589793238 -// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; -// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; -using namespace std; -const int N = 2e5 + 5; -const ll MOD = 1e9 + 7; -ll t = 1; - -void solve() -{ - ll n; - cin >> n; - string s; - cin >> s; - // Check if the string contains 's' or 'p' - if (s.find('s') == string::npos && s.find('p') == string::npos) { - cout << ""YES\n""; - return; - } - int l = -1, r = -1; - f(i,0,n){ - switch (s[i]) - { - case 'p': - if (l == -1) - { - l = 1; - r = i+1; - } - else { - int ff = 1, ss = i+1; - // Check if the new range [ff, ss] can contain the range [l, r] or vice versa - if ((ff <= l && ss >= r) || (l <= ff && r >= ss)) - { - l = min(l, ff); - r = max(r, ss); - } - else - { - cout << ""NO\n""; - return; - } - } - break; - case 's': - if (l == -1) - { - l = i+1; - r = n; - } - else { - int ff = i+1, ss = n; - // Check if the new range [ff, ss] can contain the range [l, r] or vice versa - if ((ff <= l && ss >= r) || (l <= ff && r >= ss)) - { - l = min(l, ff); - r = max(r, ss); - } - else - { - cout << ""NO\n""; - return; - } - } - break; - default: - break; - } - } - cout << ""YES\n""; - - return; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}",1 -Atlas,2049B - pspspsps,c++20 ,305858067,305858935,"#include - -using namespace std; - - - -template - -ostream &operator<<(ostream &os, const pair &p) { - - return os << '(' << p.first << "", "" << p.second << ')'; - -} - - - -template ::value, - - typename T_container::value_type>::type> - -ostream &operator<<(ostream &os, const T_container &v) { - - os << '{'; - - string sep; - - for (const T &x : v) - - os << sep << x, sep = "", ""; - - return os << '}'; - -} - - - -void dbg_out() { cerr << endl; } - - - -template void dbg_out(Head H, Tail... T) { - - cerr << ' ' << H; - - dbg_out(T...); - -} - - - -#ifdef LOCAL - -#define debug(...) cerr << ""["" << #__VA_ARGS__ << ""]:"", dbg_out(__VA_ARGS__) - -#else - -#define debug(...) - -#endif - - - -int main() { - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - int N; - - cin >> N; - - string S; - - cin >> S; - - bool ok = true; - - int p = 0, s = 0; - - for (int i = 0; i < N - 1; i++) { - - if (S[i] == 's') - - s++; - - if (S[i] == 'p') { - - p++; - - int j = i + 1; - - while (j < N && S[j] == '.') - - j++; - - if (S[j] == 's') - - ok = false; - - j = i; - - } - - } - - if (!ok || (s > 0 && p > 0 && S != ""sp"" && S != "".sp"" && S != ""sp."")) { - - cout << ""NO"" << '\n'; - - } else { - - cout << ""YES"" << '\n'; - - } - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = - - std::chrono::duration_cast(end - begin); - - cerr << ""time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -} - -","#include - -using namespace std; - - - -template - -ostream &operator<<(ostream &os, const pair &p) { - - return os << '(' << p.first << "", "" << p.second << ')'; - -} - - - -template ::value, - - typename T_container::value_type>::type> - -ostream &operator<<(ostream &os, const T_container &v) { - - os << '{'; - - string sep; - - for (const T &x : v) - - os << sep << x, sep = "", ""; - - return os << '}'; - -} - - - -void dbg_out() { cerr << endl; } - - - -template void dbg_out(Head H, Tail... T) { - - cerr << ' ' << H; - - dbg_out(T...); - -} - - - -#ifdef LOCAL - -#define debug(...) cerr << ""["" << #__VA_ARGS__ << ""]:"", dbg_out(__VA_ARGS__) - -#else - -#define debug(...) - -#endif - - - -int main() { - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - int N; - - cin >> N; - - string S; - - cin >> S; - - bool ok = true; - - int p = 0, s = 0; - - if (S[0] == 's') - - S[0] = '.'; - - if (S[N - 1] == 'p') - - S[N - 1] = '.'; - - for (int i = 0; i < N - 1; i++) { - - if (S[i] == 's') - - s++; - - if (S[i] == 'p') { - - p++; - - int j = i + 1; - - while (j < N && S[j] == '.') - - j++; - - if (S[j] == 's') - - ok = false; - - j = i; - - } - - } - - if (!ok || (s > 0 && p > 0 && S != ""sp"" && S != "".sp"" && S != ""sp."")) { - - cout << ""NO"" << '\n'; - - } else { - - cout << ""YES"" << '\n'; - - } - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = - - std::chrono::duration_cast(end - begin); - - cerr << ""time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -} - -",2 -An_it,2049B - pspspsps,c++17 ,305563213,305572111,"#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n; - - cin>>n; - - string s; - - cin>>s; - - - - if(s[0]=='s' || s[n-1]=='p') - - cout<<""YES\n""; - - - - else - - { - - bool b=true; - - for(int i=0; i - -using namespace std; - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') - - s[0]='.'; - - if(s[n-1]=='p') - - s[n-1]='.'; - - bool f_s=false,f_p=false; - - - - for(char x:s) - - { - - if(x=='p') - - f_p=true; - - else if(x=='s') - - f_s=true; - - } - - cout<<((f_p && f_s)? ""NO\n"":""YES\n""); - - } - - return 0; - -}",2 -Angelina188,2049B - pspspsps,c++17 ,304263128,304264288,"#include - -using namespace std; - -int T,n; - -string s; - -int main() { - - ios::sync_with_stdio(0); - - cin.tie(0); cout.tie(0); - - cin>>T; - - while(T--){ - - cin>>n>>s; - - bool f=0; - - s=' '+s; - - for(int i=1;i<=n;i++){ - - for(int j=1;j<=n;j++){ - - if(s[i]=='s'&&s[j]=='p'&&i>0&&j!=n){ - - f=1; - - break; - - } - - } - - if(f) break; - - } - - if(f) cout<<""NO""<<""\n""; - - else cout<<""YES""<<""\n""; - - } - - return 0; - -}","#include - -using namespace std; - -int T,n; - -string s; - -int main() { - - ios::sync_with_stdio(0); - - cin.tie(0); cout.tie(0); - - cin>>T; - - while(T--){ - - cin>>n>>s; - - bool f=0; - - s=' '+s; - - for(int i=1;i<=n;i++){ - - for(int j=1;j<=n;j++){ - - if(s[i]=='s'&&s[j]=='p'&&i>1&&j!=n){ - - f=1; - - break; - - } - - } - - if(f) break; - - } - - if(f) cout<<""NO""<<""\n""; - - else cout<<""YES""<<""\n""; - - } - - return 0; - -}",2 -xorrr,2049B - pspspsps,c++17 ,307532131,307533137,"#include - -using namespace std; - - - -// Short forms - -#define rall(x) x.rbegin(), x.rend() - -#define lli long long int - -#define ll long long - -#define ull unsigned long long - -#define nl '\n' - -#define ff first - -#define ss second - -#define all(x) x.begin(), x.end() - -#define sz(x) (int)(x).size() - -#define pb push_back - -#define mp make_pair - - - -// Loops - -#define nlp(i, n) for (int i = 0; i < (int)(n); ++i) - -#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) - -#define rlp(i, a, b) for (int i = (int)(a); i > (int)(b); --i) - -#define llp(i,a,b) for (ll i= (ll)(a); i < (ll)(ll)(b); ++i) - - - -// STLs - -#define pii pair - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define vvl vector> - - - -// Outputs - -#define yes cout<<""YES""<>t; - - while(t--) - - { - - int n; - - cin>>n; - - string str; - - cin>>str; - - bool ans=true; - - for(int i=1;i0) ans=false; - - } - - if(ans) yes; - - else no; - - } - - - - return 0; - -}","#include - -using namespace std; - - - -// Short forms - -#define rall(x) x.rbegin(), x.rend() - -#define lli long long int - -#define ll long long - -#define ull unsigned long long - -#define nl '\n' - -#define ff first - -#define ss second - -#define all(x) x.begin(), x.end() - -#define sz(x) (int)(x).size() - -#define pb push_back - -#define mp make_pair - - - -// Loops - -#define nlp(i, n) for (int i = 0; i < (int)(n); ++i) - -#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) - -#define rlp(i, a, b) for (int i = (int)(a); i > (int)(b); --i) - -#define llp(i,a,b) for (ll i= (ll)(a); i < (ll)(ll)(b); ++i) - - - -// STLs - -#define pii pair - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define vvl vector> - - - -// Outputs - -#define yes cout<<""YES""<>t; - - while(t--) - - { - - int n; - - cin>>n; - - string str; - - cin>>str; - - bool ans=true; - - int s=0; - - for(int i=1;i0) ans=false; - - } - - if(ans) yes; - - else no; - - } - - - - return 0; - -}",2 -VISHVJEET,2049B - pspspsps,c++17 ,306989230,306991000,"// **************** MBRAHUL *************** - -#include - -#define ll long long - -#define pn cout<<""NO""< - -#define vi vector - -#define vb vector - -#define u_map unordered_map - -#define pll pair - -#define pii pair - -#define inf INT_MAX - -#define pb push_back - -#define mod 998244353 - -#define MOD 1000000007 - -#define ld long double - -#define ff first - -#define ss second - -#define all(v) v.begin(),v.end() - -#define min3(a, b, c) min(c, min(a, b)) - -#define min4(a, b, c, d) min(d, min(c, min(a, b))) - -#define loop(i,n) for(int i=0;i=0;i--) - -using namespace std; - - - -void input(vector&arr,ll n){ - -for(ll i =0;i>arr[i]; - -} - - - -void printArr(vector&arr, ll i,ll j){ - -for(ll k = i;k<=j;k++)cout<>n>>str; - - sets; - - for(auto c:str)if(c!='.')s.insert(c); - - if(s.size()<=1){ - - py; - - return; - - } - - for(int i = 0;i>test; - -while(test--){ - -find(); - -} - -return 0; - -}","// **************** MBRAHUL *************** - -#include - -#define ll long long - -#define pn cout<<""NO""< - -#define vi vector - -#define vb vector - -#define u_map unordered_map - -#define pll pair - -#define pii pair - -#define inf INT_MAX - -#define pb push_back - -#define mod 998244353 - -#define MOD 1000000007 - -#define ld long double - -#define ff first - -#define ss second - -#define all(v) v.begin(),v.end() - -#define min3(a, b, c) min(c, min(a, b)) - -#define min4(a, b, c, d) min(d, min(c, min(a, b))) - -#define loop(i,n) for(int i=0;i=0;i--) - -using namespace std; - - - -void input(vector&arr,ll n){ - -for(ll i =0;i>arr[i]; - -} - - - -void printArr(vector&arr, ll i,ll j){ - -for(ll k = i;k<=j;k++)cout<>n>>str; - - setst; - - for(auto c:str)if(c!='.')st.insert(c); - - if(st.size()<=1){ - - py; - - return; - - } - - int s=0,p=0; - - for(auto c:str){ - - if(c=='s')s++; - - else if(c=='p')p++; - - } - - if(s==1 || p==1){ - - if(s==1 && p==1){ - - if(str.back()=='p' || str[0]=='s')py; - - else pn; - - } - - else if(s==1){ - - if(str[0]=='s')py; - - else pn; - - } - - else{ - - if(str.back()=='p')py; - - else pn; - - } - - } - - else pn; - -} - - - -int main(){ - -ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); - -ll test=1; - -cin>>test; - -while(test--){ - -find(); - -} - -return 0; - -}",2 -prit_zalavadiya,2049B - pspspsps,c++23 ,306475620,306476412,"#include - -using namespace std; - -#include - - - -typedef long long int ll; - -typedef vector vll; - -typedef vector> vvll; - -typedef vector> vpll; - -typedef map mll; - -typedef map mcl; - -typedef unordered_map umll; - -typedef unordered_map umcl; - -typedef set sll; - -typedef pair pll; - -typedef queue qll; - -typedef deque dqll; - -typedef priority_queue pqll; - - - -#define Jay ios_base::sync_with_stdio(false); - -#define Shree cin.tie(NULL); - -#define Ram cout.tie(NULL); - -#define yes cout << ""YES"" << ""\n""; - -#define no cout << ""NO"" << ""\n""; - -#define nope cout<<-1<<""\n""; - -#define ZZ cout<<0<<""\n""; - -#define cspace cout<<""\n""; - -#define endl '\n' - -#define inarr(a,n) for(ll i=0;i>a[i]; - -#define outarr(a,n) for(ll i=0;i=0; i--) - -#define fr(e, x) for(auto &e:x) - -#define RR return; - -#define fi first - -#define se second - -#define pb push_back - -#define eb emplace_back - -#define pf push_front - - - -const ll MOD=1e9+7; - -const ll N=1e7+7; - -const ll PI=3.141592653589793238462643; - - - -bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;} - -bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n))==floor(log2(n)));} - -bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}} - -bool isInteger(double n){return floor(n)==n;} - - - -ll findMEX(const set&s){ll mex=0;while(s.find(mex)!=s.end()){mex++;}return mex;} - - - -void solve() - -{ - - ll n; - - cin>>n; - - string s; - - cin>>s; - - ll p=count(all(s), 'p'), ss=count(all(s), 's'), d = count(all(s), '.'); - - if(p+d==n || ss+d==n) yes - - else if(s[0]=='s' || s[n-1]=='p') yes - - else no - -} - - - -int main() - -{ - - Jay Shree Ram - - - - int t; - - cin >> t; - - - - while (t--) - - { - - solve(); - - } - - - - return 0; - -}","#include - -using namespace std; - -#include - - - -typedef long long int ll; - -typedef vector vll; - -typedef vector> vvll; - -typedef vector> vpll; - -typedef map mll; - -typedef map mcl; - -typedef unordered_map umll; - -typedef unordered_map umcl; - -typedef set sll; - -typedef pair pll; - -typedef queue qll; - -typedef deque dqll; - -typedef priority_queue pqll; - - - -#define Jay ios_base::sync_with_stdio(false); - -#define Shree cin.tie(NULL); - -#define Ram cout.tie(NULL); - -#define yes cout << ""YES"" << ""\n""; - -#define no cout << ""NO"" << ""\n""; - -#define nope cout<<-1<<""\n""; - -#define ZZ cout<<0<<""\n""; - -#define cspace cout<<""\n""; - -#define endl '\n' - -#define inarr(a,n) for(ll i=0;i>a[i]; - -#define outarr(a,n) for(ll i=0;i=0; i--) - -#define fr(e, x) for(auto &e:x) - -#define RR return; - -#define fi first - -#define se second - -#define pb push_back - -#define eb emplace_back - -#define pf push_front - - - -const ll MOD=1e9+7; - -const ll N=1e7+7; - -const ll PI=3.141592653589793238462643; - - - -bool isPrime(ll n){if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(ll i=5; i*i<=n; i+=6) {if(n%i==0 || n%(i+2)==0) return false;} return true;} - -bool isPowerOfTwo(ll n){if(n==0)return false;return (ceil(log2(n))==floor(log2(n)));} - -bool isPerfectSquare(ll x){if(x>=0){ll sr=sqrt(x);return (sr*sr==x);}} - -bool isInteger(double n){return floor(n)==n;} - - - -ll findMEX(const set&s){ll mex=0;while(s.find(mex)!=s.end()){mex++;}return mex;} - - - -void solve() - -{ - - ll n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') s[0]='.'; - - if(s[n-1]=='p') s[n-1]='.'; - - if(count(all(s), 'p') && count(all(s), 's')) no - - else yes - -} - - - -int main() - -{ - - Jay Shree Ram - - - - int t; - - cin >> t; - - - - while (t--) - - { - - solve(); - - } - - - - return 0; - -}",2 -Mahashri_Saini,2049B - pspspsps,c++17 ,305945883,305951572,"#include - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - int lasts = -1, lastp = -1; - - bool ans = true; - - for (int i = 0; i < n; i++) - - { - - if (s[i] == 's') - - lasts = i; - - else if (s[i] == 'p') - - lastp = i; - - - - if (lasts != -1 && lastp != -1) - - { - - if (lasts > lastp) - - { - - ans = false; - - break; - - } - - else if (lastp > lasts && lastp != n - 1) - - { - - ans = false; - - break; - - } - - } - - } - - if(ans==1) - - cout<<""YES""< - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - - - - - if (s[0] == 's') - - s[0] = '.'; - - if (s[n - 1] == 'p') - - s[n - 1] = '.'; - - bool fp=0, fs=0; - - for (int i = 0; i < n; i++) - - { - - if (s[i]=='s') - - { - - fs=1; - - } - - if(s[i] == 'p') - - { - - fp=1; - - } - - } - - if (fs==1 && fp==1) - - cout << ""NO"" << endl; - - else - - cout << ""YES"" << endl; - - } - - return 0; - -}",2 -AdityaNarayan564,2049B - pspspsps,c++20 ,306724130,306787336,"#include - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - n=s.size(); - - string ans = ""YES""; - - - - int countp = 0, counts = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p') - - countp++; - - if(s[i] == 's') - - counts++; - - if(countp>0 and (s[i]=='s')) - - ans = ""NO""; - - if(counts>1 && countp>1) - - ans = ""NO""; - - } - - if(s[0] == '.' && s[n-1]=='.' && counts>0 && countp>0) - - ans = ""NO""; - - cout< - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - string ans = ""YES""; - - - - int countp = 0, counts = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p') - - countp++; - - if(s[i] == 's') - - counts++; - - if((countp>0 and (s[i]=='s'))||(counts>1 && countp>1)) - - ans = ""NO""; - - } - - if(((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')|| - - ((counts>1 && countp>0) && s[n-1]=='.')|| - - ((countp>1 && counts>0) && s[0]=='.')) - - ans = ""NO""; - - cout< - -#define pii pair - -#define fi first - -#define se second - -#define ll long long - -#define int long long - -#define endl '\n' - -#define ull unsigned long long - -using namespace std; - -const int N=505; - -char s[N];int n; - -void work(){ - - cin>>n; - - cin>>(s+1); - - int fl=0;int cs=0,cp=0; - - for(int i=1;i<=n;i++){ - - if(s[i]=='p'){if(fl==0);cp++;} - - if(s[i]=='s'){if(fl==1)fl++;cs++;} - - } - - if(fl==2){ - - cout<<""NO""<>T; - - while(T--)work(); - - return 0; - -}","#include - -#define pii pair - -#define fi first - -#define se second - -#define ll long long - -#define int long long - -#define endl '\n' - -#define ull unsigned long long - -using namespace std; - -const int N=505; - -char s[N];int n; - -void work(){ - - cin>>n; - - cin>>(s+1); - - int fl=0;int cs=0,cp=0; - - for(int i=1;i<=n;i++){ - - if(s[i]=='p')fl++,cp++; - - if(s[i]=='s'){ - - if(fl==1)fl++; - - cs++; - - } - - } - - if(fl==2){ - - cout<<""NO""<>T; - - while(T--)work(); - - return 0; - -}",1 -exccc,2049B - pspspsps,c++20 ,307632605,307538377,"#include - - - -using namespace std; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s'){ - - s[0]='.'; - - } - - if(s[n-1]=='p'){ - - s[n-1]='.'; - - } - - int cd1=0,cd2=0; - - for (int i=0; i>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}","#include - - - -using namespace std; - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - for (int i=0; i=3 &&n-i>=3 ){ - - cout<<""NO\n""; - - return; - - } - - } - - cout<<""YES\n""; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; - - cin>>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}",1 -farzz_,2049B - pspspsps,c++23 ,308289771,308295133,"#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n,i,j,ok=1; - - cin>>n; - - string s; - - cin>>s; - - for(i=0;i0 && i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n,i,j,ok=1; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') s[0]='.'; - - if(s[n-1]=='p') s[n-1]='.'; - - for(i=0;i - -#define ll long long - -#define PII pair - -using namespace std; - - - -void solve() - -{ - - int n; - - cin>>n; - - string s; - - cin>>s; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -#define ll long long - -#define PII pair - -using namespace std; - - - -void solve() - -{ - - int n; - - cin>>n; - - string s; - - cin>>s; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -AQIBat1,2049B - pspspsps,c++20 ,306875708,306873753,"#include""bits/stdc++.h"" -using namespace std; - -#define YES cout<<""YES\n"" -#define NO cout<<""NO\n"" -#define endl ""\n"" -#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) - -typedef long long ll; -const int MOD = 1000000007; -const int Nmax = 2e5+5; - -void akibify(){ - - int n ;cin>>n ; - string s ; - cin>>s;bool f = 1; - mapm ; - int slast = 0; - int pfirst = -1 ; - for(int i = 0 ; i < n ; i++){ - m[s[i]]++; - if(s[i] == 's'){ - slast = i ; - } - if(s[i] == 'p' && pfirst == -1){ - pfirst = i ; - } - } - if(m['p'] == 0 || m['s'] == 0){ - YES; - return; - } - if(slast == 0 || pfirst == n-1){ - YES; - return; - } - NO; - - - } - - - - - -int main(){ - fast_io; - int t ; - cin>>t ; - while(t--){ - akibify(); - - } - - - return 0; -}","#include""bits/stdc++.h"" -using namespace std; - -#define YES cout<<""YES\n"" -#define NO cout<<""NO\n"" -#define endl ""\n"" -#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) - -typedef long long ll; -const int MOD = 1000000007; -const int Nmax = 2e5+5; - -void akibify(){ - - int n ;cin>>n ; - string s ; - cin>>s;bool f = 1; - mapm ; - int plast = -1; - int sfirst = -1 ; - for(int i = 0 ; i < n ; i++){ - m[s[i]]++; - if(s[i] == 's' && sfirst == -1){ - sfirst = i ; - } - if(s[i] == 'p'){ - plast = i ; - } - } - if(m['.'] == n || m['p'] == n || m['s'] == n){ - YES; - return; - } - if(sfirst == 0 || plast == n-1){ - YES; - return; - } - NO; - - - } - - - - - -int main(){ - fast_io; - int t ; - cin>>t ; - while(t--){ - akibify(); - - } - - - return 0; -}",1 -krishvamja07,2049B - pspspsps,c++17 ,307578052,307576975,"#include - -using namespace std; - -#define ll long long - -#define lc(t) ll t; cin >> t; - -#define f(i,a,n) for (ll i=a; i> a[i] - -#define fout(i,n,a) for (ll i=0; i - -#define vll vector - -#define F first - -#define S second - -#define endl ""\n"" - -#define mod 1000000007 - -#define inf 1000000000000000000 - -#define pi 3.141592653589793238462643383279502884197169399 - -#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ld long double - - - -bool isprime (ll n) - -{ - - if (n<=1) return false; - - if(n==2 || n==3) return true; - - if(n%2==0 || n%3==0) return false; - - for (ll i=5; i<=sqrt(n); i+=6) if (n%i==0 || n%(i+2)==0) return false; - - return true; - -} - - - -bool s(ll a, ll b) - -{ - - return a>b; - -} - - - -void fun() - -{ - - lc(n); - - string a; - - cin >> a; - - f(i,0,n-1) - - { - - if ( a[i]=='p' ) - - { - - f(j,i+1,n) - - { - - if ( a[j]=='s' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - } - - } - - f(i,1,n-2) - - { - - if ( a[i]=='s' ) - - { - - f(j,i+1,n-1) - - { - - if ( a[j]=='p' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - } - - } - - cout << ""YES\n""; - - return; - -} - - - -int main() - -{ - - krish; - - lc(t); - - // ll t = 1; - - while (t--) fun(); - - return 0; - -}","#include - -using namespace std; - -#define ll long long - -#define lc(t) ll t; cin >> t; - -#define f(i,a,n) for (ll i=a; i> a[i] - -#define fout(i,n,a) for (ll i=0; i - -#define vll vector - -#define F first - -#define S second - -#define endl ""\n"" - -#define mod 1000000007 - -#define inf 1000000000000000000 - -#define pi 3.141592653589793238462643383279502884197169399 - -#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ld long double - - - -bool isprime (ll n) - -{ - - if (n<=1) return false; - - if(n==2 || n==3) return true; - - if(n%2==0 || n%3==0) return false; - - for (ll i=5; i<=sqrt(n); i+=6) if (n%i==0 || n%(i+2)==0) return false; - - return true; - -} - - - -bool s(ll a, ll b) - -{ - - return a>b; - -} - - - -void fun() - -{ - - lc(n); - - string a; - - cin >> a; - - f(i,0,n-1) - - { - - if ( a[i]=='p' ) - - { - - f(j,i+1,n) - - { - - if ( a[j]=='s' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - } - - } - - f(i,1,n-2) - - { - - if ( a[i]=='s' && a[i+1]=='p' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - cout << ""YES\n""; - - return; - -} - - - -int main() - -{ - - krish; - - lc(t); - - // ll t = 1; - - while (t--) fun(); - - return 0; - -}",1 -mr_jackpots,2049B - pspspsps,c++17 ,306096492,306097988,"// DO NOT COPY AND PASTE CODE - -// Be very sure of what you are doing before submitting - -// Solve 1000+ problems of rating range 1300-1800 (400+ of 1300-1500 and 600+ for 1600-1800) before 31st December. - -// Analyze the ratings of problems you are solving here https://cfviz.netlify.app/ - -// Dont look at test cases - -#include - -using namespace std; - -#include - -#include - - - -#include - -// typedef long ; - -// #include - -// #include - -// #include - -// #include - -// #include - -// #include - - - -// // Library effective with Windows - -// #include - - - -// // Library effective with Linux - -// #include - -// const ll INF = 1e9+7; - - - - - - - - - - - -#define ll long long - -#define ull unsigned long long - -// #define MOD 1000000007 // 998244353 - -#define vi vector - -#define vb vector - -#define vvi vector > - -#define vll vector - -#define pb push_back - -#define eb emplace_back - -#define mp(a, b) make_pair(a, b) - -#define pii pair - -#define vpii vector > - -#define mk(arr, n, type) type *arr = new type[n]; - -#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) - -#define RFOR(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i)) - -#define FORALL(i, a) for (auto& (i) : (a)) - -#define printall(a) for (auto& (i) : (a)) cout << i << ' ' - -#define print(a) cout << a << '\n' - -#define rsort(a) sort((a).rbegin(), (a).rend()) - -#define w(x) int x; cin >> x; while(x--) - -#define all(c) (c).begin(), (c).end() - -#define sz(c) (int)(c).size() - -#define pqmx priority_queue - -#define pqmn priority_queue, greater > - -#define max3(a, b, c) max((a), max((b), (c))) - -#define min3(a, b, c) min((a), min((b), (c))) - -#define mx_all(c) *max_element((c).begin(), (c).end()) - -#define mn_all(c) *min_element((c).begin(), (c).end()) - -#define lwr_b(c, a) lower_bound((c).begin(), (c).end(), (a)) - ((c).begin()) - -#define upr_b(c, a) upper_bound((c).begin(), (c).end(), (a)) - ((c).begin()) - -#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - -// #define MAXN 100010 - -// int x[MAXN],y[MAXN],a[MAXN],degree[MAXN]; - -// const int MAX = 100'007; - -const long long int MOD = 1000000007; - - - -bool isprime(long long int N){ - - if(N<2 || (!(N&1) && N!=2)) - - return 0; - - for(int i=3; i*i<=N; i+=2){ - - if(!(N%i)) - - return false; - - } - - return true; - -} - - - -long long int factorial(long long int n) { - - if (n <= 1) { - - return 1; - - } else { - - return (n * factorial(n - 1)); - - } - -} - - - -void upd(int &a, int b) { - - a = (a * 1LL * b) % MOD; - -} - -// #define sz(a) int((a).size()) - -// #define forn(i, n) for (int i = 0; i < int(n); ++i) - - - -long long int gcd(long long int a, long long int b) { - - while (b != 0) { - - long long int temp = b; - - b = a % b; // Get the remainder - - a = temp; // Update a to the previous value of b - - } - - return a; - -} - - - -long long int powerMod(long long int base, long long int exponent, long long int mod) { - - long long int result = 1; - - base = base % mod; - - - - while (exponent > 0) { - - if (exponent % 2 == 1) { - - result = (result * base) % mod; - - } - - exponent = exponent >> 1; - - base = (base * base) % mod; - - } - - - - return result; - -} - - - - - -double roundToSixDecimalPlaces(double value) { - - return std::round(value * 1e6) / 1e6; - -} - -vector parent,component; - - - -ll find(ll x){ - - if(x==parent[x]) return x; - - return parent[x]=find(parent[x]); - -} - - - -void unite(ll a, ll b){ - - a=find(a); - - b=find(b); - - if(a!=b){ - - if(component[a] b) ? (a - b) : (b - a); - -} - - - -const int MAXN = 200200; - - - - - -void dfsRecursive(int vertex, vector& visited, const vector>& adjList) { - - visited[vertex] = true; - - - - for (int neighbor : adjList[vertex]) { - - if (!visited[neighbor]) { - - dfsRecursive(neighbor, visited, adjList); - - } - - } - -} - - - - - -long long power(long long a, long long b) - -{ - - long long res = 1; - - while (b > 0) { - - if (b%2==1) { - - res = (res * a); - - } - - a*=a; - - b >>= 1; - - } - - return res; - -} - - - -long long lcm(int a, int b) { - - return (1LL * a * b) / __gcd(a, b); - -} - - - -int pb, pc, ps; - -int nb, nc, ns; - -int lb, lc, ls; - -ll fb, fc, fs; - - - -ll price(ll x) - -{ - - fb = max(x*lb - nb, (ll)0); - - fc = max(x*lc - nc, (ll)0); - - fs = max(x*ls - ns, (ll)0); - - - - ll p = fb*pb + fc*pc + fs*ps; - - return p; - -} - - - -void solve() { - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(n==1){ - - cout<<""YES""; - - } - - else{ - - bool done=false; - - for(int i=1;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -} - -;","// DO NOT COPY AND PASTE CODE - -// Be very sure of what you are doing before submitting - -// Solve 1000+ problems of rating range 1300-1800 (400+ of 1300-1500 and 600+ for 1600-1800) before 31st December. - -// Analyze the ratings of problems you are solving here https://cfviz.netlify.app/ - -// Dont look at test cases - -#include - -using namespace std; - -#include - -#include - - - -#include - -// typedef long ; - -// #include - -// #include - -// #include - -// #include - -// #include - -// #include - - - -// // Library effective with Windows - -// #include - - - -// // Library effective with Linux - -// #include - -// const ll INF = 1e9+7; - - - - - - - - - - - -#define ll long long - -#define ull unsigned long long - -// #define MOD 1000000007 // 998244353 - -#define vi vector - -#define vb vector - -#define vvi vector > - -#define vll vector - -#define pb push_back - -#define eb emplace_back - -#define mp(a, b) make_pair(a, b) - -#define pii pair - -#define vpii vector > - -#define mk(arr, n, type) type *arr = new type[n]; - -#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) - -#define RFOR(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i)) - -#define FORALL(i, a) for (auto& (i) : (a)) - -#define printall(a) for (auto& (i) : (a)) cout << i << ' ' - -#define print(a) cout << a << '\n' - -#define rsort(a) sort((a).rbegin(), (a).rend()) - -#define w(x) int x; cin >> x; while(x--) - -#define all(c) (c).begin(), (c).end() - -#define sz(c) (int)(c).size() - -#define pqmx priority_queue - -#define pqmn priority_queue, greater > - -#define max3(a, b, c) max((a), max((b), (c))) - -#define min3(a, b, c) min((a), min((b), (c))) - -#define mx_all(c) *max_element((c).begin(), (c).end()) - -#define mn_all(c) *min_element((c).begin(), (c).end()) - -#define lwr_b(c, a) lower_bound((c).begin(), (c).end(), (a)) - ((c).begin()) - -#define upr_b(c, a) upper_bound((c).begin(), (c).end(), (a)) - ((c).begin()) - -#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - -// #define MAXN 100010 - -// int x[MAXN],y[MAXN],a[MAXN],degree[MAXN]; - -// const int MAX = 100'007; - -const long long int MOD = 1000000007; - - - -bool isprime(long long int N){ - - if(N<2 || (!(N&1) && N!=2)) - - return 0; - - for(int i=3; i*i<=N; i+=2){ - - if(!(N%i)) - - return false; - - } - - return true; - -} - - - -long long int factorial(long long int n) { - - if (n <= 1) { - - return 1; - - } else { - - return (n * factorial(n - 1)); - - } - -} - - - -void upd(int &a, int b) { - - a = (a * 1LL * b) % MOD; - -} - -// #define sz(a) int((a).size()) - -// #define forn(i, n) for (int i = 0; i < int(n); ++i) - - - -long long int gcd(long long int a, long long int b) { - - while (b != 0) { - - long long int temp = b; - - b = a % b; // Get the remainder - - a = temp; // Update a to the previous value of b - - } - - return a; - -} - - - -long long int powerMod(long long int base, long long int exponent, long long int mod) { - - long long int result = 1; - - base = base % mod; - - - - while (exponent > 0) { - - if (exponent % 2 == 1) { - - result = (result * base) % mod; - - } - - exponent = exponent >> 1; - - base = (base * base) % mod; - - } - - - - return result; - -} - - - - - -double roundToSixDecimalPlaces(double value) { - - return std::round(value * 1e6) / 1e6; - -} - -vector parent,component; - - - -ll find(ll x){ - - if(x==parent[x]) return x; - - return parent[x]=find(parent[x]); - -} - - - -void unite(ll a, ll b){ - - a=find(a); - - b=find(b); - - if(a!=b){ - - if(component[a] b) ? (a - b) : (b - a); - -} - - - -const int MAXN = 200200; - - - - - -void dfsRecursive(int vertex, vector& visited, const vector>& adjList) { - - visited[vertex] = true; - - - - for (int neighbor : adjList[vertex]) { - - if (!visited[neighbor]) { - - dfsRecursive(neighbor, visited, adjList); - - } - - } - -} - - - - - -long long power(long long a, long long b) - -{ - - long long res = 1; - - while (b > 0) { - - if (b%2==1) { - - res = (res * a); - - } - - a*=a; - - b >>= 1; - - } - - return res; - -} - - - -long long lcm(int a, int b) { - - return (1LL * a * b) / __gcd(a, b); - -} - - - -int pb, pc, ps; - -int nb, nc, ns; - -int lb, lc, ls; - -ll fb, fc, fs; - - - -ll price(ll x) - -{ - - fb = max(x*lb - nb, (ll)0); - - fc = max(x*lc - nc, (ll)0); - - fs = max(x*ls - ns, (ll)0); - - - - ll p = fb*pb + fc*pc + fs*ps; - - return p; - -} - - - -void solve() { - - int n; - - cin>>n; - - string s; - - cin>>s; - - if(s[0]=='s') s[0]='.'; - - if(s[s.size()-1]=='p') s[s.size()-1]='.'; - - bool found_p=false; - - bool found_s=false; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -} - -;",2 -mdael.ali,2049B - pspspsps,c++17 ,304305931,304307340,"#include - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,say1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m; - - cin>>s; - - say1=0; - - say2=0; - - if(s[0]=='s') - - { - - cout<<""yes""< - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,say1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m; - - cin>>s; - - say1=0; - - say2=0; - - bool b=0,b1=0; - - if(s[0]=='s') - - { - - s[0]='.'; - - } - - if(s[m-1]=='p') - - s[m-1]='.'; - - for(int i=0;i -#define pb push_back -#define endl (""\n"") -#define all(aa) aa.begin(), aa.end() -typedef long long ll; -using namespace std; - -void solve(){ - int n; - cin >> n; - string s; - cin >> s; - array cnt = {0, 0}; - for(int i = 0; i < n; i++){ - if(s[i] == 's') cnt[0]++; - if(s[i] == 'p') cnt[1]++; - } - if(cnt[0] >= 2 && cnt[1] >= 2){ - cout << ""No"" << endl; - return; - } - if(cnt[0] == 0 || cnt[1] == 0){ - cout << ""Yes"" << endl; - return; - } - if(cnt[0] == 1 && s[0] == 's'){ - cout << ""Yes"" << endl; - return; - } - if(cnt[1] == 1 && s[n - 1] == 'p'){ - cout << ""Yes"" << endl; - return; - } - cout << ""No"" << endl; -} - -int main(){ - int tt; - cin >> tt; - while(tt--){ - solve(); - } -} - -","#include -#define pb push_back -#define endl (""\n"") -#define all(aa) aa.begin(), aa.end() -typedef long long ll; -using namespace std; - -void solve(){ - int n; - cin >> n; - string s; - cin >> s; - vector a(n), b(n, n - 1); - for(int i = 0; i < n; i++){ - if(i) a[i] = a[i - 1]; - if(s[i] == 's') a[i] = i; - } - for(int i = n - 1; i >= 0; i--){ - if(i + 1 < n) b[i] = b[i + 1]; - if(s[i] == 'p') b[i] = i; - } - bool ok = 1; - for(int i = 0; i < n; i++){ - ok &= a[i] <= b[i]; - } - cout << (ok ? ""Yes"" : ""No"") << endl; -} - -int main(){ - int tt; - cin >> tt; - while(tt--){ - solve(); - } -} - -",1 -AnkushJainAj,2049B - pspspsps,c++20 ,307300371,307300935,"#include - -using namespace std; - - - -int main() { - - // your code goes here - - - - int T; - - cin>>T; - - - - while(T--){ - - int n; - - cin>>n; - - - - string s; - - cin>>s; - - int cntp=0; - - int cnts=0; - - - - for(int i=0; i0 && cnts>0){ - - if(cntp==1 && s[s.size()-1]=='p'){ - - cout<<""Yes""< - -using namespace std; - - - -int main() { - - // your code goes here - - - - int T; - - cin>>T; - - - - while(T--){ - - int n; - - cin>>n; - - - - string s; - - cin>>s; - - int cntp=0; - - int cnts=0; - - - - for(int i=0; i0 && cnts>0){ - - if(cntp==1 && s[s.size()-1]=='p'|| cnts==1 && s[0]=='s'){ - - cout<<""Yes""< - -#include - -using namespace std; - -void solve() - -{ - - int n,jump=1; - - string s; - - cin>>n>>s; - - for(int i=1;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} ","#include - -#include - -using namespace std; - -void solve() - -{ - - int n,jump=1; - - string s; - - cin>>n>>s; - - for(int i=1;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} ",1 -KalbiatAman,2049B - pspspsps,c++20 ,308090378,308089879,"#include - - - -using namespace std; - - - -#define ll long long - -#define ld long double - -#define mp make_pair - -#define F first - -#define S second - -#define pb push_back - -#define upb upper_bound - -#define lwb lower_bound - - - -const int maxn = 512; - -int n; - -char s[maxn]; - - - -void clear_array() { - - fill(s, s + 3 + n, 0); - - n = 0; - -} - - - -void solve() { - - cin >> n; - - for (int i = 1; i <= n; i++) { - - cin >> s[i]; - - } - - int l = -1; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - l = i; - - break; - - } - - } - - int r = -1; - - for (int i = n; i >= 1; i--) { - - if (s[i] == 's') { - - r = i; - - break; - - } - - } - - if (l == -1 || r == -1) { - - cout << ""YES\n""; - - return; - - } - - if (l < r) { - - cout << ""NO\n""; - - return; - - } - - int pos1 = (n / 2); - - int pos2 = (n + 3) / 2; - - while (pos1 > 1 && pos2 < n) { - - if (s[pos1] == 's' && s[pos2] == 'p') { - - cout << ""NO\n""; - - return; - - } - - pos1--; - - pos2++; - - } - - for (int i = n - 1; i > 1; i--) { - - for (int j = 2; j < i; j++) { - - if (s[i] == 'p' && s[j] == 's') { - - cout << ""NO\n""; - - return; - - } - - } - - } - - cout << ""YES\n""; - -} - - - -void boost() { - - cin.tie(0), cout.tie(0); - - ios_base :: sync_with_stdio(false); - -} - - - -int main() { - - boost(); - - int TT; - - cin >> TT; - - while (TT--) { - - solve(); - - } - - return 0; - -}","#include - - - -using namespace std; - - - -#define ll long long - -#define ld long double - -#define mp make_pair - -#define F first - -#define S second - -#define pb push_back - -#define upb upper_bound - -#define lwb lower_bound - - - -const int maxn = 512; - -int n; - -char s[maxn]; - - - -void clear_array() { - - fill(s, s + 3 + n, 0); - - n = 0; - -} - - - -void solve() { - - cin >> n; - - for (int i = 1; i <= n; i++) { - - cin >> s[i]; - - } - - int l = -1; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - l = i; - - break; - - } - - } - - int r = -1; - - for (int i = n; i >= 1; i--) { - - if (s[i] == 's') { - - r = i; - - break; - - } - - } - - if (l == -1 || r == -1) { - - cout << ""YES\n""; - - return; - - } - - if (l < r) { - - cout << ""NO\n""; - - return; - - } - - int pos1 = (n / 2); - - int pos2 = (n + 3) / 2; - - while (pos1 > 1 && pos2 < n) { - - if (s[pos1] == 's' && s[pos2] == 'p') { - - cout << ""NO\n""; - - return; - - } - - pos1--; - - pos2++; - - } - - cout << ""YES\n""; - -} - - - -void boost() { - - cin.tie(0), cout.tie(0); - - ios_base :: sync_with_stdio(false); - -} - - - -int main() { - - boost(); - - int TT; - - cin >> TT; - - while (TT--) { - - solve(); - - } - - return 0; - -}",1 -Ahsan612,2049B - pspspsps,python,307433499,307436479,"from collections import defaultdict, deque -from bisect import bisect_right, bisect_left -from math import inf, isqrt, sqrt, gcd, factorial, ceil -from itertools import permutations - -mod = 10**9 + 7 - -def main(): - for _ in range(int(input())): - solve() - -# solve() -def solve(): - - n = int(input()) - s = input() - p_found = False - for i in range(n): - if s[i] == ""p"": - p_found = True - if p_found and s[i] == ""s"": - print(""NO"") - return - a = 0 - while True: - try: - a = s.index(""sp"",a) - if a-1>=0 and a+2 0 and c2 > 0: - print(""NO"") - else: - print(""YES"") - - - - -main() - -",2 -THEarchitect,2049B - pspspsps,python,307652696,307651955,"a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - j = list(c) - - - - if j[0] == ""s"": - - j[0] = ""."" - - - - if j[-1] == ""p"": - - j[-1] = ""."" - - - - l = 0 - - if ""s"" in j and ""p"" in j: - - l = -1 - - - - - - print(""Yes"") if l == 0 else print(""No"") - - ","a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - k = 0 - - for z in range(b): - - if c[z] == ""p"" and k == 0: - - k = 1 - - - - elif k == 1 and c[z] == ""s"": - - k = -1 - - break - - - - if k != -1: - - n = c[0] - - for y in range(1,b): - - if c[y-1] != c[y]: - - n += c[y] - - - - - - if "".sp."" in n: - - print(""No"") - - - - else: - - s = 0 - - p = 0 - - l = 0 - - for y in range(b): - - if c[y] == ""."": - - if (s > 1 and p > 0): - - l = -1 - - break - - - - s = 0 - - p = 0 - - else: - - if c[y] == ""s"": - - s += 1 - - - - else: - - p += 1 - - - - - - s = 0 - - p = 0 - - for y in range(b-1,-1,-1): - - if c[y] == ""."": - - if (p > 1 and s > 0): - - l = -1 - - break - - - - s = 0 - - p = 0 - - - - else: - - if c[y] == ""s"": - - s += 1 - - - - else: - - p += 1 - - - - - - - - if l == -1: - - print(""No"") - - - - else: - - print(""Yes"") - - - - - - - - elif k == -1: - - print(""No"") - - - -",1 -Rantan#,2049B - pspspsps,c++23 ,306988862,306990015,"#include - - - -#define endl ""\n"" - - - -// #define int long long - - - -using namespace std; - - - -using i64 = long long; - -using u64 = unsigned long long; - - - -constexpr int N = 2e5 + 1; - -constexpr int P = 131; - -constexpr int INF = 1e9; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - s = "" "" + s; - - int r = INF; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - r = i; - - } - - } - - bool ok = true; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 's') { - - if (n > r) { - - ok = false; - - break; - - } - - } - - } - - if (ok) { - - cout << ""YES\n""; - - } else { - - cout << ""NO\n""; - - } - -} - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - -} - - - -","#include - - - -#define endl ""\n"" - - - -// #define int long long - - - -using namespace std; - - - -using i64 = long long; - -using u64 = unsigned long long; - - - -constexpr int N = 2e5 + 1; - -constexpr int P = 131; - -constexpr int INF = 1e9; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - s = "" "" + s; - - int r = INF; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - r = i; - - break; - - } - - } - - bool ok = true; - - for (int i = 2; i <= n; i++) { - - if (s[i] == 's') { - - if (n > r) { - - ok = false; - - break; - - } - - } - - } - - if (ok) { - - cout << ""YES\n""; - - } else { - - cout << ""NO\n""; - - } - -} - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - -} - - - -",2 -AdityaNarayan04,2049B - pspspsps,c++17 ,306787003,306782039,"#include - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - string ans = ""YES""; - - - - int countp = 0, counts = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p') - - countp++; - - if(s[i] == 's') - - counts++; - - if(countp>0 and (s[i]=='s')) - - ans = ""NO""; - - if(counts>1 && countp>1) - - ans = ""NO""; - - } - - if((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.') - - ans = ""NO""; - - if((counts>1 && countp>0) && s[n-1]=='.') - - ans = ""NO""; - - if((countp>1 && counts>0) && s[0]=='.') - - ans=""NO""; - - cout< - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - // cout<0 and (s[i]=='s')) - - ans = ""NO""; - - if(counts>1 && countp>1) - - ans = ""NO""; - - } - - if(s[0] == '.' && s[n-1]=='.' && counts>0 && countp>0) - - ans = ""NO""; - - cout< - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - - - string s; - - cin >> s; - - - - bool seen_s = false; - - bool seen_p = false; - - - - if(s[0] == 'p'){ - - seen_p = true; - - } - - - - for(int i = 1; i < n-1; i++){ - - if(s[i] == 's'){ - - if(seen_p){ - - cout << ""no\n""; - - return; - - } - - seen_s = true; - - } - - else if(s[i] == 'p'){ - - if(seen_s){ - - cout << ""no\n""; - - return; - - } - - seen_p = true; - - } - - } - - if(s[n-1] == 's' && seen_p){ - - cout << ""no\n""; - - return; - - } - - - - cout << ""yes\n""; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -typedef long long ll; - - - -void solve() { - - int n; - - cin >> n; - - - - string s; - - cin >> s; - - - - bool seen_s = false; - - bool seen_p = false; - - - - if(s[0] == 's'){ - - seen_s = true; - - } - - else if(s[0] == 'p'){ - - seen_p = true; - - } - - - - for(int i = 1; i < n-1; i++){ - - if(s[i] == 's'){ - - if(seen_p){ - - cout << ""no\n""; - - return; - - } - - seen_s = true; - - } - - else if(s[i] == 'p'){ - - if(seen_s){ - - cout << ""no\n""; - - return; - - } - - seen_p = true; - - } - - } - - if(s[n-1] == 's' && seen_p){ - - cout << ""no\n""; - - return; - - } - - - - cout << ""yes\n""; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}",1 -Nady_,2049B - pspspsps,c++20 ,306885694,306881516,"#include - - - -using namespace std; - - - -#define ll long long - - - -void I_Will_Give_It_a_Try() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - if (s.front() == 's') s[0] = '.'; - - if (s.back() == 'p') s[n - 1] = '.'; - - bool f1{}, f2{}; - - for (int i = 0; i < n; ++i) { - - if (s[i] == 'p') f1 = true; - - if (s[i] == 's') f2 = true; - - - - } - - cout << (f1 && f2 ? ""NO\n"" : ""YES\n""); - -} - - - -int32_t main() { - - ios::sync_with_stdio(0); - - cout.tie(0); - - cin.tie(0); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - int t{1}; - - cin >> t; - - while (t--) - - I_Will_Give_It_a_Try(); - - /* - - IT'S AN ABSOLUTE MESS UP THERE. - - */ - -}","#include - - - -using namespace std; - - - -#define ll long long - - - -void I_Will_Give_It_a_Try() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - int Ss{}, Ps{}, idxP{-1}, idxS{-1}; - - for (int i = 0; i < n; ++i) { - - if (s[i] == 's') - - Ss++, idxS = i; - - if (s[i] == 'p') { - - Ps++; - - if (idxP == -1) - - idxP = i; - - } - - } - - if (!Ss || !Ps) return void(cout << ""YES\n""); - - if (Ss > 1 && Ps > 1 || idxP < idxS) return void(cout << ""NO\n""); - - if (s.back() == s.front() && s.front() == '.') return void(cout << ""NO\n""); - - cout << ""YES\n""; - -} - - - -int32_t main() { - - ios::sync_with_stdio(0); - - cout.tie(0); - - cin.tie(0); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - int t{1}; - - cin >> t; - - while (t--) - - I_Will_Give_It_a_Try(); - - /* - - IT'S AN ABSOLUTE MESS UP THERE. - - */ - -}",1 -HoneyGupta,2049B - pspspsps,c++23 ,306330901,306329911,"#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0,prevs=0; - - rep(i,0,n){ - - if(s[i]=='p'){ - - if(prevp==0) prevp=i+1; - - } - - else if(s[i]=='s'){ - - prevs=i+1; - - if(prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - } - - if(!prevs || !prevp) cout<<""YES\n""; - - else if(prevs==1 || prevp==n) cout<<""YES\n""; - - else cout<<""NO\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}","#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0,prevs=0; - - rep(i,0,n){ - - if(s[i]=='p') prevp=1; - - else if(s[i]=='s'){ - - prevs=1; - - if(prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - } - - if(!prevs || !prevp) cout<<""YES\n""; - - else if(s[0]=='s' || s[n-1]=='p') cout<<""YES\n""; - - else cout<<""NO\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}",1 -krishvamja07,2049B - pspspsps,c++17 ,307578052,307576671,"#include - -using namespace std; - -#define ll long long - -#define lc(t) ll t; cin >> t; - -#define f(i,a,n) for (ll i=a; i> a[i] - -#define fout(i,n,a) for (ll i=0; i - -#define vll vector - -#define F first - -#define S second - -#define endl ""\n"" - -#define mod 1000000007 - -#define inf 1000000000000000000 - -#define pi 3.141592653589793238462643383279502884197169399 - -#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ld long double - - - -bool isprime (ll n) - -{ - - if (n<=1) return false; - - if(n==2 || n==3) return true; - - if(n%2==0 || n%3==0) return false; - - for (ll i=5; i<=sqrt(n); i+=6) if (n%i==0 || n%(i+2)==0) return false; - - return true; - -} - - - -bool s(ll a, ll b) - -{ - - return a>b; - -} - - - -void fun() - -{ - - lc(n); - - string a; - - cin >> a; - - f(i,0,n-1) - - { - - if ( a[i]=='p' ) - - { - - f(j,i+1,n) - - { - - if ( a[j]=='s' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - } - - } - - f(i,1,n-2) - - { - - if ( a[i]=='s' ) - - { - - f(j,i+1,n-1) - - { - - if ( a[j]=='p' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - } - - } - - cout << ""YES\n""; - - return; - -} - - - -int main() - -{ - - krish; - - lc(t); - - // ll t = 1; - - while (t--) fun(); - - return 0; - -}","#include - -using namespace std; - -#define ll long long - -#define lc(t) ll t; cin >> t; - -#define f(i,a,n) for (ll i=a; i> a[i] - -#define fout(i,n,a) for (ll i=0; i - -#define vll vector - -#define F first - -#define S second - -#define endl ""\n"" - -#define mod 1000000007 - -#define inf 1000000000000000000 - -#define pi 3.141592653589793238462643383279502884197169399 - -#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ld long double - - - -bool isprime (ll n) - -{ - - if (n<=1) return false; - - if(n==2 || n==3) return true; - - if(n%2==0 || n%3==0) return false; - - for (ll i=5; i<=sqrt(n); i+=6) if (n%i==0 || n%(i+2)==0) return false; - - return true; - -} - - - -bool s(ll a, ll b) - -{ - - return a>b; - -} - - - -void fun() - -{ - - lc(n); - - string a; - - cin >> a; - - f(i,0,n-1) - - { - - if ( a[i]=='p' && a[i+1]=='s' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - f(i,1,n-2) - - { - - if ( a[i]=='s' && a[i+1]=='p' ) - - { - - cout << ""NO\n""; - - return; - - } - - } - - cout << ""YES\n""; - - return; - -} - - - -int main() - -{ - - krish; - - lc(t); - - // ll t = 1; - - while (t--) fun(); - - return 0; - -}",1 -Chxxxx,2049B - pspspsps,c++23 ,307507213,307505307,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define ll long long - -#define ull unsigned long long - -using namespace std; - - - -void solve() - -{ - - ll n; - - bool fs = false, fp = false; - - string s; - - cin >> n >> s; - - if(s[0] == 's') s[0] = '.'; - - if(s[n-1] == 'p') s[n-1] = '.'; - - for(int i = 0; i < n; i++) { - - if(s[i] == 's') fs = true; - - if(s[i] == 'p') fp = true; - - } - - if(fs && fp) cout << ""NO"" << endl; - - else cout << ""YES"" << endl; - - return; - -} - -int main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t=1; - - cin>>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define ll long long - -#define ull unsigned long long - -using namespace std; - - - -void solve() - -{ - - ll n; - - string s; - - cin >> n >> s; - - ll ns = 0, np = 0; - - for(int i = 0; i < n; i++) { - - if(s[i] == 's') { - - ns++; - - if(np > 0) { - - cout << "" NO"" << endl; - - return; - - } - - } - - if(s[i] == 'p') np++; - - } - - if(ns == n || np == n) { - - cout << ""YES"" << endl; - - return; - - } - - if(ns == 0 && np == 0) { - - cout << ""YES"" << endl; - - return; - - } - - s = ' ' + s; - - map mp; - - for(int i = 2; i < n; i++) { - - if(s[i] == 's') { - - mp[n-i+1]++; - - } - - if(s[i] == 'p') { - - mp[i]++; - - } - - } - - for(auto x : mp) { - - if(x.second > 1) { - - cout << "" NO"" << endl; - - return; - - } - - } - - cout << ""YES"" << endl; - - return; - -} - -int main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t=1; - - cin>>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",1 -AdityaNarayan564,2049B - pspspsps,c++20 ,306787336,306671748,"#include - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - string ans = ""YES""; - - - - int countp = 0, counts = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p') - - countp++; - - if(s[i] == 's') - - counts++; - - if((countp>0 and (s[i]=='s'))||(counts>1 && countp>1)) - - ans = ""NO""; - - } - - if(((counts>0 && countp>0) && s[0] == '.' && s[n-1]=='.')|| - - ((counts>1 && countp>0) && s[n-1]=='.')|| - - ((countp>1 && counts>0) && s[0]=='.')) - - ans = ""NO""; - - cout< - -using namespace std; - - - -#define int long long - -using pii = pair; - - - -signed main(void) - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - - - int T = 1; - - cin >> T; - - while(T--) - - { - - int n; - - cin >> n; - - string s; - - cin >> s; - - string ans = ""YES""; - - bool pflag = false; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p') - - pflag = true; - - if(pflag and (s[i]=='s'||s[i]=='.')) - - ans = ""NO""; - - } - - cout< - -using namespace std; - -void solve(void) - -{ - - int n;cin>>n; - - string s;cin>>s; - - int snum=0,pnum=0; - - bool pj=1;int posp,poss; - - for(int i=0;i1&&pnum>1) - - { - - cout<<""NO\n""; - - return; - - } - - if(snum==1&&pnum==1&&(s[0]=='s'||s[n-1]=='p')) - - { - - cout<<""YES\n""; - - return; - - } - - if(snum==1&&pnum!=0&&s[0]!='s') - - { - - cout<<""NO\n""; - - return; - - } - - if(pnum==1&&snum!=0&&s[n-1]!='p') - - { - - cout<<""NO\n""; - - return; - - } - -// cout<>t; - - while(t--) - - { - - solve(); - - } - -}","#include - -using namespace std; - -void solve(void) - -{ - - int n;cin>>n; - - string s;cin>>s; - - int snum=0,pnum=0; - - bool pj=1;int posp,poss; - - for(int i=0;i1&&pnum>1) - - { - - cout<<""NO\n""; - - return; - - } - - if(snum!=0&&pnum!=0&&s[0]!='s'&&s[n-1]!='p') - - { - - cout<<""NO\n""; - - return; - - } - -// cout<>t; - - while(t--) - - { - - solve(); - - } - -}",1 -akshayjadhavkrishnaholic,2049B - pspspsps,c++17 ,307373390,307373143,"// #include - -// using namespace std; - - - -// int main(){ - -// int t; - -// cin>>t; - -// while (t--){ - -// int n; - -// cin>>n; - -// vector v; - -// map mp; - -// int x,y; - -// for(int i = 0;i>x>>y; - -// mp[x] = y; - -// v.push_back(y); - -// } - -// sort(v.begin(),v.end()); - -// long total = 0; - -// for(auto &j : mp){ - -// auto p = lower_bound(v.begin(),v.end(),j.second); - -// total+=p-v.begin(); - -// v.erase(p); - -// } - -// cout< - -using namespace std; - - - -int main(){ - - int t; - - cin>>t; - - while (t--) - - { - - int n; - - string s; - - cin>>n>>s; - - bool is_poss=true,is_p=false,is_s=false; - - if (s[0]=='s') s[0]='.'; - - if (s[n-1]=='p') s[n-1]='.'; - - for(int i = 0;i - -// using namespace std; - - - -// int main(){ - -// int t; - -// cin>>t; - -// while (t--){ - -// int n; - -// cin>>n; - -// vector v; - -// map mp; - -// int x,y; - -// for(int i = 0;i>x>>y; - -// mp[x] = y; - -// v.push_back(y); - -// } - -// sort(v.begin(),v.end()); - -// long total = 0; - -// for(auto &j : mp){ - -// auto p = lower_bound(v.begin(),v.end(),j.second); - -// total+=p-v.begin(); - -// v.erase(p); - -// } - -// cout< - -using namespace std; - - - -int main(){ - - int t; - - cin>>t; - - while (t--) - - { - - int n; - - string s; - - cin>>n>>s; - - bool is_poss=true,is_p=false,is_s=false; - - if (s[0]=='s') s[0]=='.'; - - if (s[n-1]=='p') s[n-1]=='.'; - - for(int i = 0;i - -#include - -#include - - - -#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr); - -using ll = long long; - - - - - -void solve() - -{ - - int n; - - std::cin >> n; - - - - std::string str; - - std::cin >> str; - - - - // sp.... -> possible - - // ....sp -> possible - - // ps impossible in any case - - - - // basically p should be leading and only one p is allowed - - std::unordered_map map; - - for (char e : str) map[e]++; - - bool p = false, s = false, oneP = false, oneS = false; - - for (const auto& [first, second] : map) - - { - - if (first == 'p' && second > 1) p = true; - - if (first == 's' && second > 1) s = true; - - if (first == 's' && second == 1) oneS = true; - - if (first == 'p' && second == 1) oneP = true; - - } - - - - if ((p && s) || (oneS && p)) {std::cout << ""NO\n""; return;} - - if (str[0] == 's') str[0] = '.'; if (str[n-1] == 'p') str[n-1] = '.'; - - - - p = false; s = false; - - for (char e : str) - - { - - if (e == 'p') p = true; - - if (e == 's') s = true; - - } - - (p && s) ? std::cout << ""NO\n"" : std::cout << ""YES\n""; - -} - - - -int main() - -{ - - inout; - - int t = 1; - - std::cin >> t; - - - - while (t--) solve(); - -} - -","#include - -#include - -#include - - - -#define inout std::ios::sync_with_stdio(false); std::cin.tie(nullptr); - -using ll = long long; - - - - - -void solve() - -{ - - int n; - - std::cin >> n; - - - - std::string str; - - std::cin >> str; - - - - // sp.... -> possible - - // ....sp -> possible - - // ps impossible in any case - - - - // basically p should be leading and only one p is allowed - - bool p = false, s = false; - - if (str[0] == 's') str[0] = '.'; if (str[n-1] == 'p') str[n-1] = '.'; - - - - for (char e : str) - - { - - if (e == 'p') p = true; - - if (e == 's') s = true; - - } - - (p && s) ? std::cout << ""NO\n"" : std::cout << ""YES\n""; - -} - - - -int main() - -{ - - inout; - - int t = 1; - - std::cin >> t; - - - - while (t--) solve(); - -} - -",2 -HoneyGupta,2049B - pspspsps,c++23 ,306328693,306330901,"#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0; - - rep(i,0,n){ - - if(s[i]=='p') prevp=1; - - else if(s[i]=='s' && prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - rep(i,1,n-2){ - - if(s[i]=='s' && s[i+1]=='p'){ - - cout<<""NO\n""; - - return; - - } - - } - - cout<<""YES\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}","#include - -#include - -#include - -using namespace std; - - - -#define int long long - -#define rep(i, x, n) for (int i = x; i < n; i++) - -#define rrep(i, x, n) for (int i = n; i >= x; i--) - -#define all(x) (x).begin(), (x).end() - -#define fi first - -#define se second - -#define endl ""\n"" - -#define pb push_back - -#define pii pair - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define inf (int)1e18 - - - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - -const int M=1e9+7; - - - -// Binary Exponentiation - -int binExp(int a, int b) { int x = 1; while (b) { if (b & 1) x = (x * 1ll * a) % M; a = (a * 1ll * a) % M; b >>= 1; } return x; } - - - -void Solve() - -{ - - int n,m,k,q; - - string s; - - cin>>n>>s; - - int prevp=0,prevs=0; - - rep(i,0,n){ - - if(s[i]=='p'){ - - if(prevp==0) prevp=i+1; - - } - - else if(s[i]=='s'){ - - prevs=i+1; - - if(prevp){ - - cout<<""NO\n""; - - return; - - } - - } - - } - - if(!prevs || !prevp) cout<<""YES\n""; - - else if(prevs==1 || prevp==n) cout<<""YES\n""; - - else cout<<""NO\n""; - -} - - - -int32_t main() - -{ - - auto begin = std::chrono::high_resolution_clock::now(); - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - int t = 1; - - // freopen(""in"", ""r"", stdin); - - // freopen(""out"", ""w"", stdout); - - - - cin >> t; - - while(t--) - - { - - //cout << ""Case #"" << i << "": ""; - - Solve(); - - } - - auto end = std::chrono::high_resolution_clock::now(); - - auto elapsed = std::chrono::duration_cast(end - begin); - - // cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - - return 0; - -}",2 -lry_342#,2049B - pspspsps,c++17 ,307396625,307392892,"#include - - - -using namespace std; - - - -int n; - -string s; - -void solve() { - - cin >> n >> s; - - - - int l = n - 1, r = 0; - - while(l >= 0 && s[l] != 's') l--; - - while(r < n && s[r] != 'p') r++; - - if(l > r) { - - cout << ""No"" << '\n'; - - return; - - } - - - - if(l < 1 || n - r < 2) { - - cout << ""Yes"" << '\n'; - - } else { - - // cout << l << ' ' << r << '\n'; - - cout << ""No"" << '\n'; - - } - -} - - - -int main() { - - int t; cin >> t; - - while(t--) { - - solve(); - - } - - return 0; - -} - - - -/* - -sspp - -4312 - -*/","#include - - - -using namespace std; - - - -int n; - -string s; - -void solve() { - - cin >> n >> s; - - - - bool f1 = false, f2 = false; - - for(char c : s) { - - if(c == 'p') f1 = true; - - else if(c == 's') f2 = true; - - } - - if(!f1 || !f2) { - - cout << ""Yes"" << ""\n""; - - return; - - } - - - - if(s[0] == 's' && s[n - 1] == 'p') { - - cout << ""Yes"" << ""\n""; - - } - - else cout << ""No"" << ""\n""; - -} - - - -int main() { - - int t; cin >> t; - - while(t--) { - - solve(); - - } - - return 0; - -}",1 -Yashasva,2049B - pspspsps,c++17 ,306479611,306479801,"#include - -using namespace std; - - - -int main(){ - - int t; - - cin >> t; - - while(t--){ - - int n; - - cin >> n; - - string h; - - cin >> h; - - int i = 0; - - int j = n - 1; - - if(h[0] == h[n - 1]){ - - i++; - - j--; - - goto abc; - - } - - if(h[0] == 's' || h[0] == '.'){ - - i++; - - } - - if(h[n - 1] == 'p' || h[n - 1] == '.'){ - - j--; - - } - - abc : //skip statement - - bool flag1 = 0; - - bool flag2 = 0; - - for(int p = i; p <= j; p++){ - - if(h[p] == '.') continue; - - if(h[p] == 's') flag1 = 1; - - if(h[p] == 'p') flag2 = 1; - - } - - if(flag1 && flag2){ - - cout << ""NO"" << endl; - - } else { - - cout << ""YES"" << endl; - - } - - } - -}","#include - -using namespace std; - - - -int main(){ - - int t; - - cin >> t; - - while(t--){ - - int n; - - cin >> n; - - string h; - - cin >> h; - - int i = 0; - - int j = n - 1; - - if(h[0] == 's' || h[0] == '.'){ - - i++; - - } - - if(h[n - 1] == 'p' || h[n - 1] == '.'){ - - j--; - - } - - bool flag1 = 0; - - bool flag2 = 0; - - for(int p = i; p <= j; p++){ - - if(h[p] == '.') continue; - - if(h[p] == 's') flag1 = 1; - - if(h[p] == 'p') flag2 = 1; - - } - - if(flag1 && flag2){ - - cout << ""NO"" << endl; - - } else { - - cout << ""YES"" << endl; - - } - - } - -}",2 -a_e_kasem,2049B - pspspsps,c++23 ,306958746,306958608," /***> @author : a_e_kasem <***/ - - - -// ﷽ - -// { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى } - - - -// {***} - - - -// فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ - -// - -// وَما نَيلُ المَطالِبِ بِالتَمَنّي - -// وَلَكِن تُؤخَذُ الدُنيا غِلابا - -// *** - -// وَما اِستَعصى عَلى قَومٍ مَنالٌ - -// إِذا الإِقدامُ كانَ لَهُم رِكا - -// - -#include - -using namespace std; - - - -#define int long long - -#define ld long double - -#define ull unsigned long long - -#define w(x) int x; cin >> x; while(x--) - -#define vi vector - -#define vvi vector > - -#define fi first - -#define se second - -#define pii pair - -#define vpii vector > - -#define FOR(i, a, b) for (int(i) = (a); (i) <= (b); ++(i)) - -#define RFOR(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i)) - -#define FORALL(i, a) for (auto& (i) : (a)) - -#define printall(a) for (auto& (i) : (a)) cout << i << ' ' - -#define cinall(a) for (auto& (i) : (a)) cin >> i - -#define cin_1all(a, n) for (int (i) = 1; (i) <= (n) ; i++) cin >> a[i] - -#define rsort(a) sort((a).rbegin(), (a).rend()) - -#define all(c) (c).begin(), (c).end() - -#define pqmn priority_queue, greater > - -#define mx_all(c) *max_element((c).begin(), (c).end()) - -#define mn_all(c) *min_element((c).begin(), (c).end()) - -#define FIO ios::sync_with_stdio(false); cin.tie(nullptr); - -#define in freopen(""input.txt"", ""r"", stdin); - -#define el cout << ""\n"" - -#define no cout << ""No"" << endl - -#define yes cout << ""Yes"" << endl - -#define NO cout << ""NO"" << endl - -#define YES cout << ""YES"" << endl - - - -const int INF = (long long)2e9; - -const int MOD = (long long) 7+1e9; - -const ld PI = 3.1415926535897932384626; - - - -void FASTIO(); - -void solve(); - -int32_t main() { - - FASTIO(); - - - - w(t) - - { - - solve(); - - } - - - - - - // solve(); - -} - - - -/*===================================================================// - - - - ██╗ ██╗ █████╗ ███████╗ ███████╗ ███╗ ███╗ - - ██║ ██╔╝ ██╔══██╗ ██╔════╝ ██╔════╝ ████╗ ████║ - - █████╔╝ ███████║ ███████╗ █████╗ ██╔████╔██║ - - ██╔═██╗ ██╔══██║ ╚════██║ ██╔══╝ ██║╚██╔╝██║ - - ██║ ██╗ ██║ ██║ ███████║ ███████╗ ██║ ╚═╝ ██║ - - ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ ╚═╝ - - - -//====================================================================*/ - - - -void FASTIO() - -{ - - FIO - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -int ctoi(char c) { - - return (c - '0'); - -} - -int sum_of_digits(int n) { - - string s = to_string(n); - - return s.size(); - -} - - - -void solve() { - - int n; cin >> n; - - vector a(n); - - int p = 0, s = 0; - - - - for (int i = 0; i < n; i++) - - { - - cin >> a[i]; - - if (a[i] == 'p') p++; - - if (a[i] == 's') s++; - - } - - - - if (!s || !p) YES; - - else if (p == 1 && a.back() == 'p') YES; - - else if (s == 1 && a.front() == 's') YES; - - else NO; - -} - -"," /***> @author : a_e_kasem <***/ - - - -// ﷽ - -// { وَأَنْ لَيْسَ لِلْإِنْسَانِ إِلَّا مَا سَعَى } - - - -// {***} - - - -// فَالجُهدُ يُثمِرُ إنْ تَضافَرَ صَفوُهُ، والعَزمُ يَرفعُ صَرحَ كُلِّ بُنيانِ - -// - -// وَما نَيلُ المَطالِبِ بِالتَمَنّي - -// وَلَكِن تُؤخَذُ الدُنيا غِلابا - -// *** - -// وَما اِستَعصى عَلى قَومٍ مَنالٌ - -// إِذا الإِقدامُ كانَ لَهُم رِكا - -// - -#include - -using namespace std; - - - -#define int long long - -#define ld long double - -#define ull unsigned long long - -#define w(x) int x; cin >> x; while(x--) - -#define vi vector - -#define vvi vector > - -#define fi first - -#define se second - -#define pii pair - -#define vpii vector > - -#define FOR(i, a, b) for (int(i) = (a); (i) <= (b); ++(i)) - -#define RFOR(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i)) - -#define FORALL(i, a) for (auto& (i) : (a)) - -#define printall(a) for (auto& (i) : (a)) cout << i << ' ' - -#define cinall(a) for (auto& (i) : (a)) cin >> i - -#define cin_1all(a, n) for (int (i) = 1; (i) <= (n) ; i++) cin >> a[i] - -#define rsort(a) sort((a).rbegin(), (a).rend()) - -#define all(c) (c).begin(), (c).end() - -#define pqmn priority_queue, greater > - -#define mx_all(c) *max_element((c).begin(), (c).end()) - -#define mn_all(c) *min_element((c).begin(), (c).end()) - -#define FIO ios::sync_with_stdio(false); cin.tie(nullptr); - -#define in freopen(""input.txt"", ""r"", stdin); - -#define el cout << ""\n"" - -#define no cout << ""No"" << endl - -#define yes cout << ""Yes"" << endl - -#define NO cout << ""NO"" << endl - -#define YES cout << ""YES"" << endl - - - -const int INF = (long long)2e9; - -const int MOD = (long long) 7+1e9; - -const ld PI = 3.1415926535897932384626; - - - -void FASTIO(); - -void solve(); - -int32_t main() { - - FASTIO(); - - - - w(t) - - { - - solve(); - - } - - - - - - // solve(); - -} - - - -/*===================================================================// - - - - ██╗ ██╗ █████╗ ███████╗ ███████╗ ███╗ ███╗ - - ██║ ██╔╝ ██╔══██╗ ██╔════╝ ██╔════╝ ████╗ ████║ - - █████╔╝ ███████║ ███████╗ █████╗ ██╔████╔██║ - - ██╔═██╗ ██╔══██║ ╚════██║ ██╔══╝ ██║╚██╔╝██║ - - ██║ ██╗ ██║ ██║ ███████║ ███████╗ ██║ ╚═╝ ██║ - - ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ ╚═╝ - - - -//====================================================================*/ - - - -void FASTIO() - -{ - - FIO - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -int ctoi(char c) { - - return (c - '0'); - -} - -int sum_of_digits(int n) { - - string s = to_string(n); - - return s.size(); - -} - - - -void solve() { - - int n; cin >> n; - - vector a(n); - - int p = 0, s = 0; - - - - for (int i = 0; i < n; i++) - - { - - cin >> a[i]; - - if (a[i] == 'p') p++; - - if (a[i] == 's') s++; - - } - - - - if (!s || !p) YES; - - else if (s == 1 && a.back() == 'p') YES; - - else if (p == 1 && a.front() == 's') YES; - - else NO; - -} - -",1 -THEarchitect,2049B - pspspsps,python,307644778,307652696,"a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - k = 0 - - for z in range(b): - - if c[z] == ""p"" and k == 0: - - k = 1 - - - - elif k == 1 and c[z] == ""s"": - - k = -1 - - break - - - - - - - - if ""s"" in c and ""p"" in c: - - if c[-1] != ""p"": - - print(""No"") - - - - elif k == -1: - - print(""No"") - - - - else: - - print(""Yes"") - - - - elif k == -1: - - print(""No"") - - - - else: - - print(""Yes"")","a = int(input()) - -for y in range(a): - - b = int(input()) - - c = input() - - j = list(c) - - - - if j[0] == ""s"": - - j[0] = ""."" - - - - if j[-1] == ""p"": - - j[-1] = ""."" - - - - l = 0 - - if ""s"" in j and ""p"" in j: - - l = -1 - - - - - - print(""Yes"") if l == 0 else print(""No"") - - ",2 -krishrb2517_,2049B - pspspsps,c++20 ,307350605,307350761,"#include - -using namespace std; - - - -#define int long long int - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - bool f = false; - - int cnts = 0; - - int cntp = 0; - - for(int i=0;i>tt; - - - - while(tt--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - - - -#define int long long int - - - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - bool f = false; - - int cnts = 0; - - int cntp = 0; - - for(int i=0;i>tt; - - - - while(tt--){ - - solve(); - - } - - return 0; - -}",2 -bidaglas,2049B - pspspsps,c++23 ,307136719,307209507,"#include - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(0) , cout.tie(0); - - int t; - - cin >> t; - - while(t --){ - - int n; - - cin >> n; - - string s; - - cin >> s; - - int s_cnt = 0 , p_cnt = 0 , wzs = -1 , wzp = -1 , cs = -1; - - for(int i = 0 ; i < n ; i ++){ - - if(s[i] == 's') - - s_cnt ++; - - else if(s[i] == 'p') - - p_cnt ++; - - if(s[i] == 's') - - wzs = i; - - else if(s[i] == 'p' && wzp == -1) - - wzp = i; - - if(s[i] == 's' && cs == -1) - - cs = i; - - } - - if(s_cnt && p_cnt){ - - if(wzs > wzp || cs != 0) - - cout << ""NO"" << '\n'; - - else - - cout << ""YES"" << '\n'; - - }else - - cout << ""YES"" << '\n'; - - } - - return 0; - -}","#include - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(0) , cout.tie(0); - - int t; - - cin >> t; - - while(t --){ - - int n; - - cin >> n; - - string s; - - cin >> s; - - int wzs = -1 , wzp = -1; - - for(int i = 0 ; i < n ; i ++){ - - if(s[i] == 's') - - wzs = i; - - else if(s[i] == 'p' && wzp == -1) - - wzp = i; - - } - - if((wzs >= -1 && (wzp == n - 1 || wzp == -1)) || (wzs == -1 || wzs == 0) && wzp >= -1) - - cout << ""YES"" << '\n'; - - else - - cout << ""NO"" << '\n'; - - } - - return 0; - -}",2 -AdityaxBhatt,2049B - pspspsps,c++23 ,307593890,307593327,"#include - -#define ll long long - -#define MAXN 100001 - -using namespace std; - -vector spf(MAXN + 1, 1); - - - -void sieve() - -{ - - spf[0] = 0; - - for (int i = 2; i <= MAXN; i++) { - - if (spf[i] == 1) { - - for (int j = i; j <= MAXN; j += i) { - - if (spf[j]== 1) - - spf[j] = i; - - } - - } - - } - -} - - - -map getFactorization(int x) - -{ - - map ret; - - while (x != 1) { - - ret[spf[x]]++; - - x = x / spf[x]; - - } - - return ret; - -} - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int f=0; - - int x=0; - - int z=0; - - int y=0; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -#define ll long long - -#define MAXN 100001 - -using namespace std; - -vector spf(MAXN + 1, 1); - - - -void sieve() - -{ - - spf[0] = 0; - - for (int i = 2; i <= MAXN; i++) { - - if (spf[i] == 1) { - - for (int j = i; j <= MAXN; j += i) { - - if (spf[j]== 1) - - spf[j] = i; - - } - - } - - } - -} - - - -map getFactorization(int x) - -{ - - map ret; - - while (x != 1) { - - ret[spf[x]]++; - - x = x / spf[x]; - - } - - return ret; - -} - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int f=0; - - int x=0; - - int z=0; - - int y=0; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",1 -saumya77022,2049B - pspspsps,c++17 ,307453823,307451111,"# include - -using namespace std; - - - - - - void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int pp=0; - - int ss=0; - - - - for(int i=0;i>t; - - - - while(t--){ - - solve(); - - - - } - - - -return 0; - -}","# include - -using namespace std; - - - - - - void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - int pp=0; - - int ss=0; - - int dot=0; - - for(int i=0;i>t; - - - - while(t--){ - - solve(); - - - - } - - - -return 0; - -}",1 -Noob_er_Bacca,2049B - pspspsps,c++17 ,306435344,306416510," #include - - using namespace std; - - #define ll long long - - #define test cout<<""ok""< is_prime(MX+ 1, true); - - /*is_prime[0] = false; - - is_prime[1] = true; - - for(int i = 2; i<= MX; i++){ - - if(is_prime[i] == true && i * i <= MX) - - { - - for(int j = i * i ; j <= MX ;j+= i) - - { - - is_prime[j] = false; - - } - - } - - - - }*/ - - - - void solve(){ - - ll n; cin >> n; - - string s; - - cin >> s; - - if(s[0] =='s') - - s[0] = '.'; - - if(s[n-1] == 'p') - - s[n-1] = '.'; - - - - bool flag1= false, flag2 = false; - - for(int i =0; i < n; i++){ - - if(s[i] == 's') - - flag1 = true; - - if(s[i] == 'p') - - flag2 = true; - - } - - if(flag1 & flag2) - - cout << ""NO"" << endl; - - else - - cout <<""YES"" << endl; - - - - } - - - - int main(){ - - Faster; - - int t; cin >> t; - - - - while(t --){ - - solve(); - - } - - }"," #include - - using namespace std; - - #define ll long long - - #define test cout<<""ok""< is_prime(MX+ 1, true); - - /*is_prime[0] = false; - - is_prime[1] = true; - - for(int i = 2; i<= MX; i++){ - - if(is_prime[i] == true && i * i <= MX) - - { - - for(int j = i * i ; j <= MX ;j+= i) - - { - - is_prime[j] = false; - - } - - } - - - - }*/ - - - - void solve(){ - - ll n; cin >> n; - - string s; - - cin >> s; - - int ppos = 0, spos = 0; - - - - for(int i = 0; i < n; i++){ - - if(s[i] == 's') - - spos = i; - - } - - - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p'){ - - ppos = i; - - break; - - } - - } - - - - if(ppos < spos) - - cout <<""NO"" << endl; - - else { - - - - bool flag1 = false; - - bool flag2 = false; - - - - for(int i = spos-1; i >=0; i--){ - - if(s[i] == '.') - - flag1 = true; - - } - - - - for(int i = ppos+1; i > t; - - - - while(t --){ - - solve(); - - } - - }",1 -muzammil-1008,2049B - pspspsps,c++20 ,307559537,307560559,"#include -using namespace std; -int main(){ -int t; -cin>>t; -while(t--){ -int n; -cin>>n; -string s; -cin>>s; -mapbe,af; -int i=0; -while(i0 && i==n-1){ - cout<<""YES""<0 && i>1 && i0){ - cout<<""NO""< -using namespace std; -int main(){ -int t; -cin>>t; -while(t--){ -int n; -cin>>n; -string s; -cin>>s; -if(s[0]=='s')s[0]='.'; -if(s[n-1]=='p')s[n-1]='.'; -bool x=false,y=false; -int i=0; -while(i - - - -#define endl ""\n"" - - - -// #define int long long - - - -using namespace std; - - - -using i64 = long long; - -using u64 = unsigned long long; - - - -constexpr int N = 2e5 + 1; - -constexpr int P = 131; - -constexpr int INF = 1e9; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - s = "" "" + s; - - int r = INF; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - r = i; - - break; - - } - - } - - bool ok = true; - - for (int i = 2; i <= n; i++) { - - if (s[i] == 's') { - - if (n > r) { - - ok = false; - - break; - - } - - } - - } - - if (ok) { - - cout << ""YES\n""; - - } else { - - cout << ""NO\n""; - - } - -} - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - -} - - - -","#include - - - -#define endl ""\n"" - - - -// #define int long long - - - -using namespace std; - - - -using i64 = long long; - -using u64 = unsigned long long; - - - -constexpr int N = 2e5 + 1; - -constexpr int P = 131; - -constexpr int INF = 1e9; - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - s = "" "" + s; - - int mnp = INF, mxs = 0; - - for (int i = 1; i <= n; i++) { - - if (s[i] == 'p') { - - mnp = min(mnp, i); - - } else { - - mxs = max(mxs, i); - - } - - } - - if (mnp < mxs) { - - cout << ""NO\n""; - - } else { - - cout << ""YES\n""; - - } - -} - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - -} - - - -",1 -SD125#,2049B - pspspsps,java,305960799,305963970,"import static java.lang.Math.max; - -import static java.lang.Math.min; - -import static java.lang.Math.abs; - - - -import java.util.*; - -import java.io.*; - -import java.math.*; - - - -public final class Main { - - - - static PrintWriter out = new PrintWriter(System.out); - - static FastReader in = new FastReader(); - - static final int MOD1 = (int) (1e9 + 7); - - static final int MOD2 = 998244353; - - - - static final int inf = Integer.MAX_VALUE; - - static final int minf = Integer.MIN_VALUE; - - static final long linf = 1L << 62; - - - - public static void main(String[] args){ - - int tt = i(); - - while (tt-- > 0) { - - solve(); - - } - - out.flush(); - - } - - - - public static void solve(){ - - - - // int MIN = -1*(int) 1e9; - - // int MAX = (int) 1e9; - - // PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); - - - - int n = i(); - - String s = s(); - - // int ar[]=input(n); - - // int ar[] = new int[n]; - - int id1=-1,id2=-1,id3=-1,id4=-1; - - for(int i=0;i= k) { - - ans = mid; - - hi = mid - 1; - - } else { - - lo = mid + 1; - - } - - } - - return ans; - - } - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // -------------BINARYSEARCH-----------// - - - - // UPPERBOUND find lowest i which satisfy a[i]>=x - - static int upperbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - // LOWERBOUND find highest i which satisfy a[i]<=x - - static int lowerbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - // -------------BINARYSEARCH-----------// - - - - // ---------------MATH-----------------// - - - - public static long fact(int n, int mod) { - - long res = 1; - - for (int i = 2; i <= n; i++) { - - res = (res * i) % mod; - - } - - return res; - - } - - - - static int GCD(int a, int b) { - - int dividend = a > b ? a : b; - - int divisor = a < b ? a : b; - - - - while (divisor > 0) { - - int reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long GCD(long a, long b) { - - long dividend = a > b ? a : b; - - long divisor = a < b ? a : b; - - - - while (divisor > 0) { - - long reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long LCM(int a, int b) { - - return (long) a / GCD(a, b) * b; - - } - - - - static long LCM(long a, long b) { - - return a / GCD(a, b) * b; - - } - - - - static long pow(long a, long b, int mod) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow = (pow * x) % mod; - - } - - x = (x * x) % mod; - - b /= 2; - - } - - return pow; - - } - - - - static long pow(long a, long b) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow *= x; - - } - - x = x * x; - - b /= 2; - - } - - return pow; - - } - - - - static long modInverse(long x, int mod) { - - return pow(x, mod - 2, mod); - - } - - - - static boolean isPrime(long N) { - - if (N <= 1) { - - return false; - - } - - if (N <= 3) { - - return true; - - } - - if (N % 2 == 0 || N % 3 == 0) { - - return false; - - } - - for (int i = 5; i * i <= N; i = i + 6) { - - if (N % i == 0 || N % (i + 2) == 0) { - - return false; - - } - - } - - return true; - - } - - - - static long log(long a) { - - return (long) (Math.log(a)); - - } - - - - static long log2(long a) { - - return (long) (Math.log(a) / Math.log(2)); - - } - - - - static long sqrt(long x) { - - long start = 0, end = (long) 3e9, ans = 1; - - while (start <= end) { - - long mid = (start + end) / 2; - - if (mid * mid <= x) { - - ans = mid; - - start = mid + 1; - - } else - - end = mid - 1; - - } - - return ans; - - } - - - - static long ceil(long a, long b) { - - return (a / b) + ((a % b == 0) ? 0 : 1); - - } - - - - static boolean isPerfectSquare(double number) { - - double sqrt = Math.sqrt(number); - - return ((sqrt - Math.floor(sqrt)) == 0); - - } - - - - // ---------------MATH-----------------// - - // ---------------CALCS-----------------// - - - - static long sum(List a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(int[] a) { - - long sum = 0; - - for (int ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(long[] a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static int maxArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int maxArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - // ---------------CALCS-----------------// - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// - - - - static void shuffle(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - } - - - - static void shuffleAndSort(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void shuffleAndSort(long[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - long temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void swap(int A[], int a, int b) { - - int t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(long A[], int a, int b) { - - long t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(char A[], int a, int b) { - - char t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - public static String reverse(String str) { - - if (str == null) { - - return null; - - } - - return new StringBuilder(str).reverse().toString(); - - } - - - - public static void reverse(int[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static void reverse(long[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static String repeat(char ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = repeat - 1; i >= 0; i--) { - - buf[i] = ch; - - } - - return new String(buf); - - } - - - - public static String repeat(char ch[], int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch[i % ch.length]; - - } - - return new String(buf); - - } - - - - public static String repeat(String ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch.charAt(i % ch.length()); - - } - - return new String(buf); - - } - - - - static void fillFrequency(Map map, long a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, long val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void fillFrequency(Map map, int a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, int val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void remove(Map map, long val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - static void remove(Map map, int val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // --------------BITS-----------------// - - static int[][] PrefixBitsCount(int n, int[] a) { - - int pref[][] = new int[n + 1][32]; - - // Builds the prefix sums for each bit - - for (int i = 0; i < n; i++) { - - for (int j = 0; j < 32; j++) { - - if ((a[i] & (1 << j)) != 0) { - - pref[i + 1][j] = pref[i][j] + 1; - - } else { - - pref[i + 1][j] = pref[i][j]; - - } - - } - - } - - return pref; - - } - - - - static int[] prefixAnd(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] & a[i]; - - } - - return pre; - - } - - - - static int[] prefixOr(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] | a[i]; - - } - - return pre; - - } - - - - static int[] prefixXor(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] ^ a[i]; - - } - - return pre; - - } - - // --------------BITS-----------------// - - - - // --------------ARRAYS-----------------// - - - - static int[] getPrefMax(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = max(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getPrefMin(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = min(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getSuffMin(int arr[]) { - - int n = arr.length; - - int suff[] = new int[n]; - - suff[n - 1] = arr[n - 1]; - - for (int i = n - 2; i >= 0; i--) { - - suff[i] = min(suff[i + 1], arr[i]); - - } - - return suff; - - } - - - - static long[] prefix(int[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static List prefix(List a) { - - List pre = new ArrayList<>(); - - pre.add(0l); - - for (int i = 0; i < a.size(); i++) { - - pre.add(pre.get(i) + a.get(i)); - - } - - return pre; - - } - - - - static long[] prefix(long[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static long[] suffix(int[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - - - static long[] suffix(long[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - // --------------ARRAYS-----------------// - - - - // --------------Sieve&Factors-----------------// - - - - static List sieveOfEratosthenes(int n) { - - List primeList = new ArrayList<>(); - - boolean prime[] = new boolean[n + 1]; - - for (int i = 0; i <= n; i++) - - prime[i] = true; - - - - for (int p = 2; p * p <= n; p++) { - - - - if (prime[p] == true) { - - - - for (int i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - - - for (int i = 2; i <= n; i++) { - - if (prime[i] == true) - - primeList.add(i); - - // System.out.print(i + "" ""); - - } - - return primeList; - - } - - - - static List allDivisors(int n) { - - List divisoers = new ArrayList<>(); - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - divisoers.add(i); - - if (i != n / i) { - - divisoers.add(n / i); - - } - - } - - } - - return divisoers; - - } - - - - // --------------Sieve&Factors-----------------// - - - - // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - - static int i() { - - return in.nextInt(); - - } - - - - static long l() { - - return in.nextLong(); - - } - - - - static double d() { - - return in.nextDouble(); - - } - - - - static String s() { - - return in.nextLine(); - - } - - - - static ArrayList inputList(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(i()); - - return a; - - } - - - - static ArrayList inputListLong(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(l()); - - return a; - - } - - - - static int[][] inputWithIdx(int N) { - - int A[][] = new int[N][2]; - - for (int i = 0; i < N; i++) { - - A[i] = new int[] { in.nextInt(), i }; - - } - - return A; - - } - - - - static int[][] inputMatrix(int N, int M) { - - int A[][] = new int[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static long[][] inputMatrixLong(int N, int M) { - - long A[][] = new long[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static int[] input(int N) { - - int A[] = new int[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static Integer[] inputWrapper(int N) { - - Integer A[] = new Integer[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static long[] inputLong(int N) { - - long A[] = new long[N]; - - for (int i = 0; i < A.length; i++) { - - A[i] = in.nextLong(); - - } - - return A; - - } - - - - static void p(String s) { - - out.print(s); - - } - - - - static void p(int s) { - - out.print(s); - - } - - - - static void p(long s) { - - out.print(s); - - } - - - - static void p(double s) { - - out.print(s); - - } - - - - static void p(char s) { - - out.print(s); - - } - - - - static void pl(String s) { - - out.println(s); - - } - - - - static void pl(int s) { - - out.println(s); - - } - - - - static void pl(long s) { - - out.println(s); - - } - - - - static void pl(double s) { - - out.println(s); - - } - - - - static void pl(char c) { - - out.println(c); - - } - - - - static void pl() { - - out.println(); - - } - - - - static void pl(int[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(long[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(T[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(List A) { - - for (T a : A) { - - out.print(a + "" ""); - - } - - out.println(); - - } - - - - static void pl(Object o) { - - out.println(o); - - } - - - - static void ps(int s) { - - out.print(s + "" ""); - - } - - - - static void ps(long s) { - - out.print(s + "" ""); - - } - - - - static void ps(double s) { - - out.print(s + "" ""); - - } - - - - static void ps(char c) { - - out.print(c + "" ""); - - } - - - - static void yes() { - - pl(""YES""); - - } - - - - static void no() { - - pl(""NO""); - - } - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - -} - - - - class FastReader { - - - - BufferedReader br; - - StringTokenizer st; - - - - public FastReader() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - char nextChar() { - - return next().charAt(0); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - -} - - - -","import static java.lang.Math.max; - -import static java.lang.Math.min; - -import static java.lang.Math.abs; - - - -import java.util.*; - -import java.io.*; - -import java.math.*; - - - -public final class Main { - - - - static PrintWriter out = new PrintWriter(System.out); - - static FastReader in = new FastReader(); - - static final int MOD1 = (int) (1e9 + 7); - - static final int MOD2 = 998244353; - - - - static final int inf = Integer.MAX_VALUE; - - static final int minf = Integer.MIN_VALUE; - - static final long linf = 1L << 62; - - - - public static void main(String[] args){ - - int tt = i(); - - while (tt-- > 0) { - - solve(); - - } - - out.flush(); - - } - - - - public static void solve(){ - - - - // int MIN = -1*(int) 1e9; - - // int MAX = (int) 1e9; - - // PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); - - - - int n = i(); - - String s = s(); - - // int ar[]=input(n); - - // int ar[] = new int[n]; - - int id1=-1,id2=-1,id3=-1,id4=-1; - - int c1=0,c2=0; - - for(int i=0;i1&&c2>1){ - - pl(""NO""); - - return; - - - - } - - - - if(c1>1){ - - if(id2==0)yes(); - - else no(); - - return; - - }else if(c2>1){ - - if(id1==n-1)yes(); - - else no(); - - return; - - - - }else{ - - if(id2==0||id1==n-1)yes(); - - else no(); - - } - - - - // pl(); - - } - - - - static int BinarySearch(long ar[], int k) { - - int lo = 0; - - int hi = ar.length - 1; - - int mid; - - int ans = -1; - - while (lo <= hi) { - - mid = lo + ((hi - lo) / 2); - - if (ar[mid] >= k) { - - ans = mid; - - hi = mid - 1; - - } else { - - lo = mid + 1; - - } - - } - - return ans; - - } - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // -------------BINARYSEARCH-----------// - - - - // UPPERBOUND find lowest i which satisfy a[i]>=x - - static int upperbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - // LOWERBOUND find highest i which satisfy a[i]<=x - - static int lowerbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - // -------------BINARYSEARCH-----------// - - - - // ---------------MATH-----------------// - - - - public static long fact(int n, int mod) { - - long res = 1; - - for (int i = 2; i <= n; i++) { - - res = (res * i) % mod; - - } - - return res; - - } - - - - static int GCD(int a, int b) { - - int dividend = a > b ? a : b; - - int divisor = a < b ? a : b; - - - - while (divisor > 0) { - - int reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long GCD(long a, long b) { - - long dividend = a > b ? a : b; - - long divisor = a < b ? a : b; - - - - while (divisor > 0) { - - long reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long LCM(int a, int b) { - - return (long) a / GCD(a, b) * b; - - } - - - - static long LCM(long a, long b) { - - return a / GCD(a, b) * b; - - } - - - - static long pow(long a, long b, int mod) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow = (pow * x) % mod; - - } - - x = (x * x) % mod; - - b /= 2; - - } - - return pow; - - } - - - - static long pow(long a, long b) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow *= x; - - } - - x = x * x; - - b /= 2; - - } - - return pow; - - } - - - - static long modInverse(long x, int mod) { - - return pow(x, mod - 2, mod); - - } - - - - static boolean isPrime(long N) { - - if (N <= 1) { - - return false; - - } - - if (N <= 3) { - - return true; - - } - - if (N % 2 == 0 || N % 3 == 0) { - - return false; - - } - - for (int i = 5; i * i <= N; i = i + 6) { - - if (N % i == 0 || N % (i + 2) == 0) { - - return false; - - } - - } - - return true; - - } - - - - static long log(long a) { - - return (long) (Math.log(a)); - - } - - - - static long log2(long a) { - - return (long) (Math.log(a) / Math.log(2)); - - } - - - - static long sqrt(long x) { - - long start = 0, end = (long) 3e9, ans = 1; - - while (start <= end) { - - long mid = (start + end) / 2; - - if (mid * mid <= x) { - - ans = mid; - - start = mid + 1; - - } else - - end = mid - 1; - - } - - return ans; - - } - - - - static long ceil(long a, long b) { - - return (a / b) + ((a % b == 0) ? 0 : 1); - - } - - - - static boolean isPerfectSquare(double number) { - - double sqrt = Math.sqrt(number); - - return ((sqrt - Math.floor(sqrt)) == 0); - - } - - - - // ---------------MATH-----------------// - - // ---------------CALCS-----------------// - - - - static long sum(List a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(int[] a) { - - long sum = 0; - - for (int ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(long[] a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static int maxArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int maxArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - // ---------------CALCS-----------------// - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// - - - - static void shuffle(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - } - - - - static void shuffleAndSort(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void shuffleAndSort(long[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - long temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void swap(int A[], int a, int b) { - - int t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(long A[], int a, int b) { - - long t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(char A[], int a, int b) { - - char t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - public static String reverse(String str) { - - if (str == null) { - - return null; - - } - - return new StringBuilder(str).reverse().toString(); - - } - - - - public static void reverse(int[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static void reverse(long[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static String repeat(char ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = repeat - 1; i >= 0; i--) { - - buf[i] = ch; - - } - - return new String(buf); - - } - - - - public static String repeat(char ch[], int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch[i % ch.length]; - - } - - return new String(buf); - - } - - - - public static String repeat(String ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch.charAt(i % ch.length()); - - } - - return new String(buf); - - } - - - - static void fillFrequency(Map map, long a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, long val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void fillFrequency(Map map, int a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, int val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void remove(Map map, long val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - static void remove(Map map, int val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // --------------BITS-----------------// - - static int[][] PrefixBitsCount(int n, int[] a) { - - int pref[][] = new int[n + 1][32]; - - // Builds the prefix sums for each bit - - for (int i = 0; i < n; i++) { - - for (int j = 0; j < 32; j++) { - - if ((a[i] & (1 << j)) != 0) { - - pref[i + 1][j] = pref[i][j] + 1; - - } else { - - pref[i + 1][j] = pref[i][j]; - - } - - } - - } - - return pref; - - } - - - - static int[] prefixAnd(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] & a[i]; - - } - - return pre; - - } - - - - static int[] prefixOr(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] | a[i]; - - } - - return pre; - - } - - - - static int[] prefixXor(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] ^ a[i]; - - } - - return pre; - - } - - // --------------BITS-----------------// - - - - // --------------ARRAYS-----------------// - - - - static int[] getPrefMax(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = max(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getPrefMin(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = min(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getSuffMin(int arr[]) { - - int n = arr.length; - - int suff[] = new int[n]; - - suff[n - 1] = arr[n - 1]; - - for (int i = n - 2; i >= 0; i--) { - - suff[i] = min(suff[i + 1], arr[i]); - - } - - return suff; - - } - - - - static long[] prefix(int[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static List prefix(List a) { - - List pre = new ArrayList<>(); - - pre.add(0l); - - for (int i = 0; i < a.size(); i++) { - - pre.add(pre.get(i) + a.get(i)); - - } - - return pre; - - } - - - - static long[] prefix(long[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static long[] suffix(int[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - - - static long[] suffix(long[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - // --------------ARRAYS-----------------// - - - - // --------------Sieve&Factors-----------------// - - - - static List sieveOfEratosthenes(int n) { - - List primeList = new ArrayList<>(); - - boolean prime[] = new boolean[n + 1]; - - for (int i = 0; i <= n; i++) - - prime[i] = true; - - - - for (int p = 2; p * p <= n; p++) { - - - - if (prime[p] == true) { - - - - for (int i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - - - for (int i = 2; i <= n; i++) { - - if (prime[i] == true) - - primeList.add(i); - - // System.out.print(i + "" ""); - - } - - return primeList; - - } - - - - static List allDivisors(int n) { - - List divisoers = new ArrayList<>(); - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - divisoers.add(i); - - if (i != n / i) { - - divisoers.add(n / i); - - } - - } - - } - - return divisoers; - - } - - - - // --------------Sieve&Factors-----------------// - - - - // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - - static int i() { - - return in.nextInt(); - - } - - - - static long l() { - - return in.nextLong(); - - } - - - - static double d() { - - return in.nextDouble(); - - } - - - - static String s() { - - return in.nextLine(); - - } - - - - static ArrayList inputList(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(i()); - - return a; - - } - - - - static ArrayList inputListLong(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(l()); - - return a; - - } - - - - static int[][] inputWithIdx(int N) { - - int A[][] = new int[N][2]; - - for (int i = 0; i < N; i++) { - - A[i] = new int[] { in.nextInt(), i }; - - } - - return A; - - } - - - - static int[][] inputMatrix(int N, int M) { - - int A[][] = new int[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static long[][] inputMatrixLong(int N, int M) { - - long A[][] = new long[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static int[] input(int N) { - - int A[] = new int[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static Integer[] inputWrapper(int N) { - - Integer A[] = new Integer[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static long[] inputLong(int N) { - - long A[] = new long[N]; - - for (int i = 0; i < A.length; i++) { - - A[i] = in.nextLong(); - - } - - return A; - - } - - - - static void p(String s) { - - out.print(s); - - } - - - - static void p(int s) { - - out.print(s); - - } - - - - static void p(long s) { - - out.print(s); - - } - - - - static void p(double s) { - - out.print(s); - - } - - - - static void p(char s) { - - out.print(s); - - } - - - - static void pl(String s) { - - out.println(s); - - } - - - - static void pl(int s) { - - out.println(s); - - } - - - - static void pl(long s) { - - out.println(s); - - } - - - - static void pl(double s) { - - out.println(s); - - } - - - - static void pl(char c) { - - out.println(c); - - } - - - - static void pl() { - - out.println(); - - } - - - - static void pl(int[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(long[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(T[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(List A) { - - for (T a : A) { - - out.print(a + "" ""); - - } - - out.println(); - - } - - - - static void pl(Object o) { - - out.println(o); - - } - - - - static void ps(int s) { - - out.print(s + "" ""); - - } - - - - static void ps(long s) { - - out.print(s + "" ""); - - } - - - - static void ps(double s) { - - out.print(s + "" ""); - - } - - - - static void ps(char c) { - - out.print(c + "" ""); - - } - - - - static void yes() { - - pl(""YES""); - - } - - - - static void no() { - - pl(""NO""); - - } - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - -} - - - - class FastReader { - - - - BufferedReader br; - - StringTokenizer st; - - - - public FastReader() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - char nextChar() { - - return next().charAt(0); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - -} - - - -",2 -Shubham-V#,2049B - pspspsps,c++20 ,306053580,306053258,"#include - -using namespace std; - - - -typedef long long ll; - -typedef unsigned long long ull; - -typedef pair pii; - -typedef pair pdd; - -typedef pair pll; - -typedef vector vi; - -typedef vector vll; - -typedef map mii; - -typedef vector> vvi; - -typedef vector> vvll; - -#define f(i, a, b, j) for(int i = int(a); i < int(b); i = i + int(j)) - -#define M map - -#define V vector - -#define P pair - -#define all(a) a.begin(), a.end() - -#define rall(a) a.rbegin(), a.rend() - -#define nl ""\n"" - -#define pb push_back - -#define mp make_pair - -#define reset(a, b) memset(a, int(b), sizeof(a)) - -#define MOD1 (ll)1000000007 - -#define MOD2 (ll)998244353 - - - -ll mod = MOD1; - -ll power(ll a,ll b){ - - ll res = 1; - - while(b){ - - if(b & 1){ - - res *= a; - - res %= mod; - - } - - a *= a; - - a %= mod; - - b >>= 1; - - } - - return res; - -} - -ll inverse(ll a){ - - return power(a,mod - 2); - -} - - - -void solve(){ - - ll n; - - cin >> n; - - string s; - - cin >> s; - - // p before s (not possible) - - ll r_s = n; - - for(int i = n - 1; i >= 0; i--){ - - if(s[i] == 's'){ - - r_s = i; - - break; - - } - - } - - if(r_s == n){ - - cout << ""YES"" << nl; - - return; - - } - - ll l_p = -1; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p'){ - - l_p = i; - - break; - - } - - } - - if(l_p == -1){ - - cout << ""YES"" << nl; - - return; - - } - - if(l_p < r_s){ - - cout << ""NO"" << nl; - - return; - - } - - ll count_s = 0; - - ll count_p = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 's'){ - - count_s++; - - } - - if(s[i] == 'p'){ - - count_p++; - - } - - } - - if(count_s > 1 and count_p > 1){ - - cout << ""NO"" << nl; - - return; - - } - - if(count_s == 1 and count_p == 1){ - - if(s[0] != 's' and s[n - 1] != 'p'){ - - cout << ""NO"" << nl; - - return; - - } - - cout << ""YES"" << nl; - - return; - - } - - if(count_s == 1){ - - // more than one p - - if(s[0] != 's'){ - - cout << ""NO"" << nl; - - return; - - } - - cout << ""YES"" << nl; - - return; - - } - - // count_p == 1 - - if(s[n - 1] != 'p'){ - - cout << ""NO"" << nl; - - return; - - } - - cout << ""YES"" << nl; - - return; - -} - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - ll t; - - cin >> t; - - for(int i = 0; i < t; i++){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - - - -typedef long long ll; - -typedef unsigned long long ull; - -typedef pair pii; - -typedef pair pdd; - -typedef pair pll; - -typedef vector vi; - -typedef vector vll; - -typedef map mii; - -typedef vector> vvi; - -typedef vector> vvll; - -#define f(i, a, b, j) for(int i = int(a); i < int(b); i = i + int(j)) - -#define M map - -#define V vector - -#define P pair - -#define all(a) a.begin(), a.end() - -#define rall(a) a.rbegin(), a.rend() - -#define nl ""\n"" - -#define pb push_back - -#define mp make_pair - -#define reset(a, b) memset(a, int(b), sizeof(a)) - -#define MOD1 (ll)1000000007 - -#define MOD2 (ll)998244353 - - - -ll mod = MOD1; - -ll power(ll a,ll b){ - - ll res = 1; - - while(b){ - - if(b & 1){ - - res *= a; - - res %= mod; - - } - - a *= a; - - a %= mod; - - b >>= 1; - - } - - return res; - -} - -ll inverse(ll a){ - - return power(a,mod - 2); - -} - - - -void solve(){ - - ll n; - - cin >> n; - - string s; - - cin >> s; - - // p before s (not possible) - - ll r_s = n; - - for(int i = n - 1; i >= 0; i--){ - - if(s[i] == 's'){ - - r_s = i; - - break; - - } - - } - - if(r_s == n){ - - cout << ""YES"" << nl; - - return; - - } - - ll l_p = -1; - - for(int i = 0; i < n; i++){ - - if(s[i] == 'p'){ - - l_p = i; - - break; - - } - - } - - if(l_p == -1){ - - cout << ""YES"" << nl; - - return; - - } - - if(l_p < r_s){ - - cout << ""NO"" << nl; - - return; - - } - - ll count_s = 0; - - ll count_p = 0; - - for(int i = 0; i < n; i++){ - - if(s[i] == 's'){ - - count_s++; - - } - - if(s[i] == 'p'){ - - count_p++; - - } - - } - - if(count_s > 1 and count_p > 1){ - - cout << ""NO"" << nl; - - return; - - } - - if(count_s == 1){ - - // more than one p - - if(s[0] != 's'){ - - cout << ""NO"" << nl; - - return; - - } - - cout << ""YES"" << nl; - - return; - - } - - // count_p == 1 - - if(s[n - 1] != 'p'){ - - cout << ""NO"" << nl; - - return; - - } - - cout << ""YES"" << nl; - - return; - -} - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - ll t; - - cin >> t; - - for(int i = 0; i < t; i++){ - - solve(); - - } - - return 0; - -}",1 -menglao,2049B - pspspsps,c++20 ,306989243,306987038," #include - -#define int long long //二维数组可能会爆 - -#define pll pair - -#define INF 0x3f3f3f3f3f3f3f3f - -using namespace std; - -#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0); - -const int N=1e6+7; - -const int mod=1e9+7; - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - bool ok=1; - - for(int i=0;i>_; - - while(_--){ - - solve(); - - } - - return 0; - -} - -/* - - - -*/"," #include - -#define int long long //二维数组可能会爆 - -#define pll pair - -#define INF 0x3f3f3f3f3f3f3f3f - -using namespace std; - -#define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0); - -const int N=1e6+7; - -const int mod=1e9+7; - -void solve(){ - - int n; - - cin>>n; - - string s; - - cin>>s; - - bool ok=0; - - int cnts=0,cntp=0,cntd=0; - - for(int i=0;i>_; - - while(_--){ - - solve(); - - } - - return 0; - -} - -/* - - - -*/",1 -Harsh_Sharawat,2049B - pspspsps,c++17 ,307559077,307557597,"#include -using namespace std; - -/* clang-format off */ - -/* TYPES */ -#define ll long long -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define mii map -#define si set -#define sc set - -/* FUNCTIONS */ -#define f(a,n) for(long long int i=a;i=s;i--) -#define pb push_back -#define eb emplace_back -#define all(a) (a).begin(),(a).end() - - -/* PRINTS */ -template -void print_v(vector &v) { cout << ""{""; for (auto x : v) cout << x << "",""; cout << ""\b}""; } - -/* UTILS */ -#define M 1000000007 -#define PI 3.1415926535897932384626433832795 -#define read(type) readInt() - -ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } -ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } - -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } - -bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; } - -#define yy cout<<""Yes\n"" -#define nn cout<<""No\n"" - -/* -question intuitions: -- dp --compute next result from the previous result of the sequence - -- you have a choice at each step and each choice can lead to answer - -- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n)) -or upper/lower bound of something in a sorted sample namespac - --- where anwer space is sorted and in fixed range - --heap -- find lowest or largest of a segment -- k is given example kth largest or smallest -if k+smallest -- kth smallest--maxheap -if k+largest --kth largest-- minheap -complexity-- nlog(k) -*/ - - -#define inputv(arr,n) {for(int i=0;i>arr[i];} -#define printv(a) {for(auto u:a) cout<>n; - - string s; - cin>>s; - - - if(n==1) { - yy; - return; - } - if(s[0]=='s') s[0] = '.'; - if(s[n-1] == 'p') s[n-1] = '.'; - - - char ch = ' '; - for(auto it: s){ - if(it!='.'){ - if(ch == ' '){ - ch = it; - }else{ - if(ch != it) { - nn; - return - ; - } - } - } - } - - yy; - - - -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - int t; cin>>t; - while(t--){ - - solve(); - - - - - - } - return 0; -}","#include -using namespace std; - -/* clang-format off */ - -/* TYPES */ -#define ll long long -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define mii map -#define si set -#define sc set - -/* FUNCTIONS */ -#define f(a,n) for(long long int i=a;i=s;i--) -#define pb push_back -#define eb emplace_back -#define all(a) (a).begin(),(a).end() - - -/* PRINTS */ -template -void print_v(vector &v) { cout << ""{""; for (auto x : v) cout << x << "",""; cout << ""\b}""; } - -/* UTILS */ -#define M 1000000007 -#define PI 3.1415926535897932384626433832795 -#define read(type) readInt() - -ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } -ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } - -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } - -bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) if (a%i==0) return 0; return 1; } - -#define yy cout<<""Yes\n"" -#define nn cout<<""No\n"" - -/* -question intuitions: -- dp --compute next result from the previous result of the sequence - -- you have a choice at each step and each choice can lead to answer - -- binary search -- can sort the array or sort the answer--- find minimum or maximum from the answer sample space ->binary search on answer n(long(n)) -or upper/lower bound of something in a sorted sample namespac - --- where anwer space is sorted and in fixed range - --heap -- find lowest or largest of a segment -- k is given example kth largest or smallest -if k+smallest -- kth smallest--maxheap -if k+largest --kth largest-- minheap -complexity-- nlog(k) -*/ - - -#define inputv(arr,n) {for(int i=0;i>arr[i];} -#define printv(a) {for(auto u:a) cout<>n; - - string s; - cin>>s; - - - if(n==1){ - yy; - return; - } - - - - int i=0;int j = 0 ; - while(i>t; - while(t--){ - - solve(); - - - - - - } - return 0; -}",1 -garry_cp,2049B - pspspsps,c++23 ,306267724,306264914,"#include - -using namespace std; - - - -#define fastIO() \ - - do { \ - - ios::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL); \ - - } while (0) - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - map m; - - for(int i=0;i> tc; - - while (tc--) { - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - - - -#define fastIO() \ - - do { \ - - ios::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL); \ - - } while (0) - - - -void solve() { - - int n; - - cin >> n; - - string s; - - cin >> s; - - if(s[0]=='s' || s[n-1]=='p'){ - - cout << ""YES"" << endl; - - return; - - } - - for(int i=0;i> tc; - - while (tc--) { - - solve(); - - } - - return 0; - -} - -",1 -vpanfilov,2049B - pspspsps,c++23 ,307173784,307172361,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -#pragma GCC target(""avx2"") - - - -using ll = long long; - -using ii = pair; - -using vi = int; - -using vl = vector; - -using pll = pair; - -using dd = pair; - -using db = double; - - - -#define int long long - -#define all(x) x.begin(), x.end() - -#define X first - -#define Y second - -#define endl ""\n"" - -#define mod 998244353 - - - -void solve() { - - int n; - - cin>>n; - - string s; - - cin>>s; - - vector a,b; - - for (int i=0;i1){ - - cout<<""NO""<> tt; - - while (tt--) - - solve(); - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -#pragma GCC target(""avx2"") - - - -using ll = long long; - -using ii = pair; - -using vi = int; - -using vl = vector; - -using pll = pair; - -using dd = pair; - -using db = double; - - - -#define int long long - -#define all(x) x.begin(), x.end() - -#define X first - -#define Y second - -#define endl ""\n"" - -#define mod 998244353 - - - -void solve() { - - int n; - - cin>>n; - - string s; - - cin>>s; - - vector a={-1},b; - - cin>>s; - - for (int i=0;i> tt; - - while (tt--) - - solve(); - -}",1 -CoMpIlAtIoN_mIsTaKeEe08,2049B - pspspsps,c++17 ,306213262,306211915,"#include - -using namespace std; - -#define ll long long - -#define pb push_back - -#define int long long - -#define sv(v) sort(v.begin(),v.end()) - -#define all(v) (v).begin(), (v).end() - -#define mp make_pair - -const int N=1e7+10; - -const int M=1e5+10; - -//int pf[N]; - -long long binpow(long long a, long long b) { - - if(b==0) - - return 1; - - long long res = binpow(a,b/2); - - if(b%2) - - return res*res*a; - - else - - return res*res; - -} - -int mex(vector &arr, int N){ - - sort(arr.begin(), arr.end()); - - int mex = 0; - - for (int idx = 0; idx < N; idx++){ - - if (arr[idx] == mex){ - - mex += 1; - - } - - } - - return mex; - -} - -signed main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - int t; - - cin>>t; - - while(t--) - - { - - int n;cin>>n; - - string s;cin>>s; - - if(s[0]=='s') s[0]='.'; - - if(s[n-1]=='p') s[n-1]='.'; - - int flagp=0,flags=0; - - for(int i=0;i - -using namespace std; - -#define ll long long - -#define pb push_back - -#define int long long - -#define sv(v) sort(v.begin(),v.end()) - -#define all(v) (v).begin(), (v).end() - -#define mp make_pair - -const int N=1e7+10; - -const int M=1e5+10; - -//int pf[N]; - -long long binpow(long long a, long long b) { - - if(b==0) - - return 1; - - long long res = binpow(a,b/2); - - if(b%2) - - return res*res*a; - - else - - return res*res; - -} - -int mex(vector &arr, int N){ - - sort(arr.begin(), arr.end()); - - int mex = 0; - - for (int idx = 0; idx < N; idx++){ - - if (arr[idx] == mex){ - - mex += 1; - - } - - } - - return mex; - -} - -signed main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - int t; - - cin>>t; - - while(t--) - - { - - int n;cin>>n; - - string s;cin>>s; - - int flag=0,fllag=0; - - for(int i=0;i -#define ll long long int -#define ld long double -#define mk make_pair -#define pb push_back -#define INF (ll)1e18 -#define pll pair -#define vll vector -#define vii vector -#define all(x) x.begin(), x.end() -#define allr(x) x.rbegin(), x.rend() -#define isON(n, k) (((n) >> (k)) & 1) -#define f(i, a, b) for (ll i = a; i < b; i++) -#define fb(i, a, b) for (ll i = a; i > b; i--) -#define ff first -#define ss second -#define PI 3.141592653589793238 -// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; -// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; -using namespace std; -const int N = 2e5 + 5; -const ll MOD = 1e9 + 7; -ll t = 1; - -void solve() -{ - ll n; - cin >> n; - string s; - cin >> s; - // Check if the string contains 's' or 'p' - if (s.find('s') == string::npos && s.find('p') == string::npos) - { - cout << ""YES\n""; - return; - } - if (s[0] == 's') s[0] = '.'; - if (s.back() == 'p') s.back() = '.'; - bool fp = false, fs = false; - f(i, 0, n) - { - switch (s[i]) - { - case 's': - fs = true; - break; - case 'p': - fp = true; - break; - } - } - cout << (fs && fp ? ""NO\n"" : ""YES\n""); - - return; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}","#include -#define ll long long int -#define ld long double -#define mk make_pair -#define pb push_back -#define INF (ll)1e18 -#define pll pair -#define vll vector -#define vii vector -#define all(x) x.begin(), x.end() -#define allr(x) x.rbegin(), x.rend() -#define isON(n, k) (((n) >> (k)) & 1) -#define f(i, a, b) for (ll i = a; i < b; i++) -#define fb(i, a, b) for (ll i = a; i > b; i--) -#define ff first -#define ss second -#define PI 3.141592653589793238 -// int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; -// int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; -using namespace std; -const int N = 2e5 + 5; -const ll MOD = 1e9 + 7; -ll t = 1; - -void solve() -{ - ll n; - cin >> n; - string s; - cin >> s; - ll count_p = count(s.begin(), s.end(), 'p'); - ll count_s = count(s.begin(), s.end(), 's'); - if (count_p == 0 || count_s == 0){ - cout << ""YES\n""; - } - else { - if (s[0] == 's' || s[n - 1] == 'p'){ - cout << ""YES\n""; - } - else { - cout << ""NO\n""; - } - } - return; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}",1 -sunset1231,2049C - MEX Cycle,c++20 ,305776956,305777747,"#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) { - - ans[max(x, y)] = 2; - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - } - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -","#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) { - - ans[max(x, y)] = 2; - - if(y == n - 2 && ans[n - 1] == 2) {ans[n - 1] = 1;} - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - } - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -",2 -Chetan_21,2049C - MEX Cycle,c++23 ,304396656,304308441,"#include - -using namespace std; - - - -typedef long long ll; - -typedef vector vi; - -typedef vector vvi; - -typedef vector vll; - -typedef pair pii; - -typedef pair pll; - -typedef vector vpii; - - - -// #define rep(i,x,y) for(int i=x; true; i=(i+1)%n) - -#define rrep(i,x,y) for(int i=x; i>=y; i--) - -#define inp(arr) for(auto &x: arr) cin >>x; - -#define ninp(arr,n) int n; cin >>n; vector arr(n); for(auto &x: arr) cin >>x; - -#define kinp(arr,n,k) int n,k; cin >>n >>k; vector arr(n); for(auto &x: arr) cin >>x; - -#define out(arr) for(auto &x: arr){ cout <>t; - - while(t--){ - - int n,x,y; cin >>n >>x >>y; - - x--, y--; - - - - // if((x+1)%n == y || (y+1)%n == x){} - - - - vi ans(n,0); - - ans[x]=0, ans[y]=1; - - - - int i=x, op = 0; - - while(1){ - - // cout < - -using namespace std; - - - -typedef long long ll; - -typedef vector vi; - -typedef vector vvi; - -typedef vector vll; - -typedef pair pii; - -typedef pair pll; - -typedef vector vpii; - - - -#define rep(i,x,y) for(int i=x; i=y; i--) - -#define inp(arr) for(auto &x: arr) cin >>x; - -#define ninp(arr,n) int n; cin >>n; vector arr(n); for(auto &x: arr) cin >>x; - -#define kinp(arr,n,k) int n,k; cin >>n >>k; vector arr(n); for(auto &x: arr) cin >>x; - -#define out(arr) for(auto &x: arr){ cout <>t; - - while(t--){ - - int n,x,y; cin >>n >>x >>y; - - x--, y--; - - - - vi ans(n,0); - - ans[x]=0, ans[y]=1; - - - - rep(i,x+1,y){ - - if(i==y-1){ - - if(i%2 != x%2) ans[i]=2; - - else ans[i]=0; - - continue; - - } - - if(i%2 == x%2) ans[i]=0; - - else ans[i]=1; - - } - - - - rep(i,y+1,x){ - - if(i==x-1){ - - if(i%2 != y%2) ans[i]=2; - - else ans[i]=1; - - continue; - - } - - if(i%2 == y%2) ans[i]=1; - - else ans[i]=0; - - } - - - - out(ans); - - } - - return 0; - -}",1 -Abuseini,2049C - MEX Cycle,c++20 ,307927576,307929930,"/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/ - -#include - -#include - -#include - -// #pragma GCC optimize(""Ofast"") - -// #pragma GCC target(""avx,avx2,fma"") - -// #pragma GCC optimization (""unroint-loops"") - -// #include ""robin_hood.h"" - -using namespace __gnu_pbds; - -using namespace std; - -typedef long long ll; - -typedef unsigned long long ul; - -typedef tree, null_type, greater>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#define endl ""\n"" - -const int mod = 998244353; - -const int dx[] = {1, -1, 0, 0}; - -const int dy[] = {0, 0, 1, -1}; - -void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int N = 2e5 + 5; - - - -void Solve() { - - int n, x, y; cin >> n >> x >> y; - - vector ans(n + 1); - - ans[x] = 2; - - ans[y] = 1; - - for (int i = 1; i < x; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = x + 1; i < y; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = y + 1; i < n + 1; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = 1; i <= n; i++) cout << ans[i] << "" ""; - - cout << endl; - -} - - - -signed main() { - - fast(); - - int t = 1; cin >> t; - - while (t--) Solve(); - -} - -/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/","/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/ - -#include - -#include - -#include - -// #pragma GCC optimize(""Ofast"") - -// #pragma GCC target(""avx,avx2,fma"") - -// #pragma GCC optimization (""unroint-loops"") - -// #include ""robin_hood.h"" - -using namespace __gnu_pbds; - -using namespace std; - -typedef long long ll; - -typedef unsigned long long ul; - -typedef tree, null_type, greater>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#define endl ""\n"" - -const int mod = 998244353; - -const int dx[] = {1, -1, 0, 0}; - -const int dy[] = {0, 0, 1, -1}; - -void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int N = 2e5 + 5; - - - -void Solve() { - - int n, x, y; cin >> n >> x >> y; - - vector ans(n + 1); - - ans[x] = (n - y + x - 1) % 2 || (y - x - 1) % 2 ? 2 : 0; - - ans[y] = 1; - - for (int i = y + 1; i <= n; i++) ans[i] = ans[i - 1] == 0 ? 1 : 0; - - for (int i = 1; i < x; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = y - 1; i > x; i--) ans[i] = ans[i + 1] == 0 ? 1 : 0; - - for (int i = 1; i <= n; i++) cout << ans[i] << "" ""; - - cout << endl; - -} - - - -signed main() { - - fast(); - - int t = 1; cin >> t; - - while (t--) Solve(); - -} - -/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/",2 -vasu_boda_,2049C - MEX Cycle,c++20 ,308056150,308055294," - -/*<------------------------------------------------------------------------------------ - ---------------------------------------------------------------------------------------- - -----------------------MADE--BY--VB----------------------------------------------------- - ---------------------------------------------------------------------------------------- - ------------------------------------------------------------------------------------->*/ - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -// ifstream i_data(""mixmilk.in""); - -// ofstream o_data(""mixmilk.out""); - - - -// #define cin i_data - -// #define cout o_data - - - -/*<--------------------------------DATA--STRUCTURES----------------------------------->*/ - -#define ll long long - -#define pii pair - -#define pll pair - -#define vi vector - -#define vll vector - -#define mii map - -#define mll map - -#define si set - -#define sc set - -#define moj_karvani \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -// only less behave as set - -// less_equal as multiset - -// we can replace less with greater for descending order - -/*<--------------------------------FUNCTIONS------------------------------------------->*/ - -string itob(int num) - -{ - - if (num == 0) - - return ""0""; - - string binaryString; - - while (num > 0) - - { - - binaryString = (num % 2 == 0 ? ""0"" : ""1"") + binaryString; - - num /= 2; - - } - - return binaryString; - -} - -int btoi(const string &binaryString) { return stoi(binaryString, nullptr, 2); } - -void print_binary(int num) - -{ - - for (int i = 10; i >= 0; i--) - - { - - cout << ((num >> i) & 1); - - } - - cout << endl; - -} - -string to_upper(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'a' && a[i] <= 'z') - - a[i] -= 'a' - 'A'; - - return a; - -} - -string to_lower(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'A' && a[i] <= 'Z') - - a[i] += 'a' - 'A'; - - return a; - -} - -bool comp(const pair &a, const pair &b) - -{ - - if (a.first == b.first) - - { - - return a.second < b.second; - - } - - return a.first < b.first; - -}; - -vector find_intersection(int a, int b, int c, int d, int p, int q, int r, int s) - -{ - - vector v; - - int l = max(a, p); - - int m = max(b, q); - - int n = min(c, r); - - int o = min(d, s); - - int x = n - l; - - int y = o - m; - - if (x < 0 || y < 0) - - { - - return v; - - } - - v.push_back(l); - - v.push_back(m); - - v.push_back(n); - - v.push_back(o); - - return v; - -} - -/*<-----------------------------BASIC--MATH----------------------------------------->*/ - -const ll M = 1e9 + 7, N = 1e5 + 5; - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, a % b); - -} - -ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } - -// ll power(ll a,ll b){if(b==0) return 1;ll res=power(a,b/2);if(b&1){return a*res*res;}else{return res*res;}} - -ll power(ll a, ll b) - -{ - - ll ans = 1; - - while (b) - - { - - if (b & 1) - - { - - ans = ans * a; - - } - - a = a * a; - - b >>= 1; - - } - - return ans; - -} - -// ll isPrime(ll a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(ll i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -bool isPrime(int number) - -{ - - if (number <= 1) - - return false; - - if (number == 2) - - return true; - - if (number % 2 == 0) - - return false; - - int boundary = (int)floor(sqrt(number)); - - for (int i = 3; i <= boundary; i += 2) - - if (number % i == 0) - - return false; - - return true; - -} - - - -/*<---------------------------------Solve--here-------------------------------------------->*/ - - - -void solve() - -{ - - ll n, x, y; - - cin >> n >> x >> y; - - vector ans(n + 1); - - int b = 0; - - int f=0; - - for (int i = x; i <= y; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - if ((abs(x - y) + 1) & 1) - - { - - f=1; - - ans[y] = 2; - - }; - - - - ll p = n - y + 1LL + x; - - - - if (p & 1) - - { - - b = 1; - - } - - else - - { - - b = 0; - - } - - if(f==0 && p&1){ - - b=0; - - } - - for (int i = y + 1; i <= n; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - for (int i = 1; i < x; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - if(x==1){ - - x=n; - - } - - else{ - - x--; - - } - - if(f==0 && p&1){ - - ans[x]=2; - - } - - for(int i=1;i<=n;i++){ - - cout<*/ - -int main() - -{ - - moj_karvani; - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -} - - - -/*<-------------------------------Thank--You----------------------------------------------->*/ - -"," - -/*<------------------------------------------------------------------------------------ - ---------------------------------------------------------------------------------------- - -----------------------MADE--BY--VB----------------------------------------------------- - ---------------------------------------------------------------------------------------- - ------------------------------------------------------------------------------------->*/ - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -// ifstream i_data(""mixmilk.in""); - -// ofstream o_data(""mixmilk.out""); - - - -// #define cin i_data - -// #define cout o_data - - - -/*<--------------------------------DATA--STRUCTURES----------------------------------->*/ - -#define ll long long - -#define pii pair - -#define pll pair - -#define vi vector - -#define vll vector - -#define mii map - -#define mll map - -#define si set - -#define sc set - -#define moj_karvani \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -// only less behave as set - -// less_equal as multiset - -// we can replace less with greater for descending order - -/*<--------------------------------FUNCTIONS------------------------------------------->*/ - -string itob(int num) - -{ - - if (num == 0) - - return ""0""; - - string binaryString; - - while (num > 0) - - { - - binaryString = (num % 2 == 0 ? ""0"" : ""1"") + binaryString; - - num /= 2; - - } - - return binaryString; - -} - -int btoi(const string &binaryString) { return stoi(binaryString, nullptr, 2); } - -void print_binary(int num) - -{ - - for (int i = 10; i >= 0; i--) - - { - - cout << ((num >> i) & 1); - - } - - cout << endl; - -} - -string to_upper(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'a' && a[i] <= 'z') - - a[i] -= 'a' - 'A'; - - return a; - -} - -string to_lower(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'A' && a[i] <= 'Z') - - a[i] += 'a' - 'A'; - - return a; - -} - -bool comp(const pair &a, const pair &b) - -{ - - if (a.first == b.first) - - { - - return a.second < b.second; - - } - - return a.first < b.first; - -}; - -vector find_intersection(int a, int b, int c, int d, int p, int q, int r, int s) - -{ - - vector v; - - int l = max(a, p); - - int m = max(b, q); - - int n = min(c, r); - - int o = min(d, s); - - int x = n - l; - - int y = o - m; - - if (x < 0 || y < 0) - - { - - return v; - - } - - v.push_back(l); - - v.push_back(m); - - v.push_back(n); - - v.push_back(o); - - return v; - -} - -/*<-----------------------------BASIC--MATH----------------------------------------->*/ - -const ll M = 1e9 + 7, N = 1e5 + 5; - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, a % b); - -} - -ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } - -// ll power(ll a,ll b){if(b==0) return 1;ll res=power(a,b/2);if(b&1){return a*res*res;}else{return res*res;}} - -ll power(ll a, ll b) - -{ - - ll ans = 1; - - while (b) - - { - - if (b & 1) - - { - - ans = ans * a; - - } - - a = a * a; - - b >>= 1; - - } - - return ans; - -} - -// ll isPrime(ll a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(ll i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -bool isPrime(int number) - -{ - - if (number <= 1) - - return false; - - if (number == 2) - - return true; - - if (number % 2 == 0) - - return false; - - int boundary = (int)floor(sqrt(number)); - - for (int i = 3; i <= boundary; i += 2) - - if (number % i == 0) - - return false; - - return true; - -} - - - -/*<---------------------------------Solve--here-------------------------------------------->*/ - - - -void solve() - -{ - - ll n, x, y; - - cin >> n >> x >> y; - - vector ans(n + 1); - - int b = 0; - - for (int i = x; i <= y; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - if ((abs(x - y) + 1) & 1) - - { - - ans[y] = 2; - - }; - - ll p = n - y + 1LL + x; - - - - if (p & 1) - - { - - b = 1; - - } - - else - - { - - b = 0; - - } - - for (int i = y + 1; i <= n; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - for (int i = 1; i < x; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - for(int i=1;i<=n;i++){ - - cout<*/ - -int main() - -{ - - moj_karvani; - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -} - - - -/*<-------------------------------Thank--You----------------------------------------------->*/ - -",1 -Hacked_89,2049C - MEX Cycle,c++17 ,303743156,303740864,"#include - -using namespace std; - - - -int main() { - - long long input; - - cin >> input; - - for(long long i=0 ; i> n >> k >> m; - - int minx=INT_MAX; - - vector que(n,0); - - for(int j=0 ; j - -using namespace std; - - - -int main() { - - long long input; - - cin >> input; - - for(long long i=0 ; i> n >> k >> m; - - int minx=INT_MAX; - - vector que(n,0); - - for(int j=0 ; j - - - -using namespace std; - -using ll = long long; - -using ull = unsigned long long; - -using ld = long double; - - - -#define double ld - -#define int ll - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define pb push_back - -#define ppb pop_back - -#define mp make_pair - -#define fi first - -#define se second - -#define vl vector - -#define vvl vector - -#define vb vector - -#define vvb vector - -#define vc vector - -#define vvc vector - -#define vs vector - -#define pll pair - -#define vpll vector> - -#define vvpll vector>> - -#define umll unordered_map - -#define umcl unordered_map - -#define umlc unordered_map - -#define fr(i, a, n) for (ll i = (a); i < (n); i++) - -#define rfr(i, n, a) for (ll i = n; i >= a; i--) - -#define all(v) v.begin(), v.end() - -#define allr(v) v.rbegin(), v.rend() - -#define srt(v) sort(all(v)) // sort - -#define mxe(v) *max_element(all(v)) // find max element in vector - -#define mne(v) *min_element(all(v)) // find min element in vector - -#define rev(v) reverse(all(v)) - -#define sum_arr(v) accumulate(all(v), 0LL) - -#define pq_max priority_queue - -#define pq_min priority_queue, greater> - -#define yes cout << ""YES"" << ""\n"" - -#define no cout << ""NO"" << ""\n"" - - - -// function - - - -ll gcd(ll a, ll b) - -{ - - if (a == 0) - - return b; - - return gcd(b % a, a); - -} - - - -ll ncr(ll n, ll r) - -{ - - ll res = 1; - - fr(i, 0, r) - - { - - res = res * (n - i); - - res = res / (i + 1); - - } - - return res; - -} - - - -int lcm(int a, int b) - -{ - - return (a * b) / gcd(a, b); - -} - - - -vector simpleSieve(int limit) - -{ - - vector is_prime(limit + 1, true); - - vector primes; - - for (int p = 2; p <= limit; ++p) - - { - - if (is_prime[p]) - - { - - primes.push_back(p); - - for (int multiple = p * p; multiple <= limit; multiple += p) - - { - - is_prime[multiple] = false; - - } - - } - - } - - return primes; - -} - - - -int primeinrange(int L, int R) - -{ - - int limit = sqrt(R); - - vector primes = simpleSieve(limit); - - vector is_prime(R - L + 1, true); - - for (int prime : primes) - - { - - int start = max(prime * prime, (L + prime - 1) / prime * prime); - - for (int j = start; j <= R; j += prime) - - { - - is_prime[j - L] = false; - - } - - } - - if (L == 1) - - is_prime[0] = false; - - int c = 0; - - for (int i = 0; i <= R - L; ++i) - - { - - if (is_prime[i]) - - { - - c++; - - } - - } - - return c; - -} - - - -int mod_exp(int base, int exp, int mod) - -{ - - int result = 1; - - while (exp > 0) - - { - - if (exp % 2 == 1) - - { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - - - -// Code by harshsingh9222 - - - -int exp(int k,int c) - -{ - - return pow(k,c); - -} - - - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - x--,y--; - - vl a(n); - - for(int i=0;i> t; - - - - while (t--) - - { - - solve(); - - } - - return 0; - -}","#include - - - -using namespace std; - -using ll = long long; - -using ull = unsigned long long; - -using ld = long double; - - - -#define double ld - -#define int ll - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define pb push_back - -#define ppb pop_back - -#define mp make_pair - -#define fi first - -#define se second - -#define vl vector - -#define vvl vector - -#define vb vector - -#define vvb vector - -#define vc vector - -#define vvc vector - -#define vs vector - -#define pll pair - -#define vpll vector> - -#define vvpll vector>> - -#define umll unordered_map - -#define umcl unordered_map - -#define umlc unordered_map - -#define fr(i, a, n) for (ll i = (a); i < (n); i++) - -#define rfr(i, n, a) for (ll i = n; i >= a; i--) - -#define all(v) v.begin(), v.end() - -#define allr(v) v.rbegin(), v.rend() - -#define srt(v) sort(all(v)) // sort - -#define mxe(v) *max_element(all(v)) // find max element in vector - -#define mne(v) *min_element(all(v)) // find min element in vector - -#define rev(v) reverse(all(v)) - -#define sum_arr(v) accumulate(all(v), 0LL) - -#define pq_max priority_queue - -#define pq_min priority_queue, greater> - -#define yes cout << ""YES"" << ""\n"" - -#define no cout << ""NO"" << ""\n"" - - - -// function - - - -ll gcd(ll a, ll b) - -{ - - if (a == 0) - - return b; - - return gcd(b % a, a); - -} - - - -ll ncr(ll n, ll r) - -{ - - ll res = 1; - - fr(i, 0, r) - - { - - res = res * (n - i); - - res = res / (i + 1); - - } - - return res; - -} - - - -int lcm(int a, int b) - -{ - - return (a * b) / gcd(a, b); - -} - - - -vector simpleSieve(int limit) - -{ - - vector is_prime(limit + 1, true); - - vector primes; - - for (int p = 2; p <= limit; ++p) - - { - - if (is_prime[p]) - - { - - primes.push_back(p); - - for (int multiple = p * p; multiple <= limit; multiple += p) - - { - - is_prime[multiple] = false; - - } - - } - - } - - return primes; - -} - - - -int primeinrange(int L, int R) - -{ - - int limit = sqrt(R); - - vector primes = simpleSieve(limit); - - vector is_prime(R - L + 1, true); - - for (int prime : primes) - - { - - int start = max(prime * prime, (L + prime - 1) / prime * prime); - - for (int j = start; j <= R; j += prime) - - { - - is_prime[j - L] = false; - - } - - } - - if (L == 1) - - is_prime[0] = false; - - int c = 0; - - for (int i = 0; i <= R - L; ++i) - - { - - if (is_prime[i]) - - { - - c++; - - } - - } - - return c; - -} - - - -int mod_exp(int base, int exp, int mod) - -{ - - int result = 1; - - while (exp > 0) - - { - - if (exp % 2 == 1) - - { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - - - -// Code by harshsingh9222 - - - -int exp(int k,int c) - -{ - - return pow(k,c); - -} - - - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - vl a(n); - - for(int i=0;i> t; - - - - while (t--) - - { - - solve(); - - } - - return 0; - -}",1 -KaiwalyaJoshi,2049C - MEX Cycle,c++17 ,303756045,303756436,"#include - -typedef long long ll; - -#define MII map - -#define UMII unordered_map - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define vi vector - -#define vvi vector - -#define qi queue - -#define si stack - -#define rep(i, a, b) for(int i = a; i < b; i++) - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while(t--){ - - int n, x, y; - - cin >> n >> x >> y; - - if(x > y) swap(x, y); - - x--; - - y--; - - vector arr(n); - - for(int i = 0; i < n; i++){ - - arr[(x+i) % n] = i % 2; - - } - - if((y - x) % 2 || (x+n-y) % 2) arr[x] = 2; - - - - for(int i = 0; i < n; i++){ - - cout << arr[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -}","#include - -typedef long long ll; - -#define MII map - -#define UMII unordered_map - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define vi vector - -#define vvi vector - -#define qi queue - -#define si stack - -#define rep(i, a, b) for(int i = a; i < b; i++) - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while(t--){ - - int n, x, y; - - cin >> n >> x >> y; - - if(x > y) swap(x, y); - - x--; - - y--; - - vector arr(n); - - for(int i = 0; i < n; i++){ - - arr[(x+i) % n] = i % 2; - - } - - if((y - x) % 2 == 0 || (x+n-y) % 2 == 0) arr[x] = 2; - - - - for(int i = 0; i < n; i++){ - - cout << arr[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -}",2 -Qaiser-,2049C - MEX Cycle,c++23 ,304523038,304522048,"#include - -#include - -#include - - - -using namespace std; - -#define ull unsigned long long - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define new cout << endl - -#define ll long long - -#define pb push_back - -#define vll vector - -#define INF (long long)1e9 - -#define MOD 1000000007 - -#define mp make_pair - -#define F first - -#define S second - -#define f(i, a, b) for(long long i = a; i < b; i++) // Loop from a to b - -long long gcd(long long a, long long b) { - - while (b != 0) { - - long long temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -long long lcm(long long a, long long b) { - - return (a * b) /gcd(a, b); - -} - -long long factorial(int n) { - - long long result = 1; - - for (int i = 1; i <= n; ++i) { - - result *= i; - - } - - return result; - -} - - - -long long combination(int n, int r) { - - if (r > n) return 0; - - if (r == 0 || r == n) return 1; - - - - - - if (r > n - r) r = n - r; - - - - long long result = 1; - - - - for (int i = 0; i < r; ++i) { - - result *= (n - i); - - result /= (i + 1); - - } - - - - return result; - -} - - - -bool damn(const pair& a, const pair& b) { - - if (floor(log2(a.first)) != floor(log2(b.first))) { - - return floor(log2(a.first)) b.first; - -}; - - - - - - - - - -vector sieve_of_eratosthenes(long long limit) { - - vector prime(limit + 1, true); - - prime[0] = prime[1] = false; - - - - for (long long num = 2; num * num <= limit; ++num) { - - if (prime[num]) { - - for (long long multiple = num * num; multiple <= limit; multiple += num) { - - prime[multiple] = false; - - } - - } - - } - - - - vector primes; - - for (long long i = 2; i <= limit; ++i) { - - if (prime[i]) { - - primes.push_back(i); - - } - - } - - - - return primes; - -}; - -void merge(int arr[], int left, int right) { - - if (left >= right) return; - - int mid = left + (right - left) / 2; - - merge(arr, left, mid); - - merge(arr, mid + 1, right); - - - - int n1 = mid - left + 1; - - int n2 = right - mid; - - - - int L[n1], R[n2]; - - for (int i = 0; i < n1; i++) L[i] = arr[left + i]; - - for (int i = 0; i < n2; i++) R[i] = arr[mid + 1 + i]; - - - - int i = 0, j = 0, k = left; - - while (i < n1 && j < n2) { - - if (L[i] <= R[j]) arr[k++] = L[i++]; - - else arr[k++] = R[j++]; - - } - - - - while (i < n1) arr[k++] = L[i++]; - - while (j < n2) arr[k++] = R[j++]; - -}; - - - -void mergeSort(int arr[], int left, int right) { - - if (left < right) { - - int mid = left + (right - left) / 2; - - mergeSort(arr, left, mid); - - mergeSort(arr, mid + 1, right); - - merge(arr, left, right); - - } - -}; - -struct item{ - - ll m,c; - -}; - -int count_trailing_zeros(ll n) { - - int count = 0; - - - - - - while ((n & 1) == 0 && n != 0) { - - count++; - - n >>= 1; - - } - - - - return count; - -} - - - - - -int popcount(ll n) { - - int count = 0; - - - - - - while (n) { - - - - n = n & (n - 1); - - count++; - - } - - - - return count; - -} - - - - - - - -struct segTree { - - ll size; - - vll sums; - - - - void init(int n) { - - size = 1; - - while (size < n) { - - size *= 2; - - } - - sums.assign(2 * size, 0LL); - - } - - - - void set(ll i, ll v, ll x, ll lx, ll rx) { - - if (rx - lx == 1) { - - sums[x] = v; - - return; - - } - - ll m = (lx + rx) / 2; - - if (i < m) { - - set(i, v, 2 * x + 1, lx, m); - - } - - else { - - set(i, v, 2 * x + 2, m, rx); - - } - - sums[x] = gcd(sums[2 * x + 1] , sums[2 * x + 2]); - - } - - - - void set(ll i, ll v) { - - set(i, v, 0, 0, size); - - } - - - - ll sum(ll l, ll r, ll x, ll lx, ll rx) { - - if (lx >= r || l >= rx) return 1e9; - - if (lx >= l && rx <= r) return sums[x]; - - ll m = (lx + rx) / 2; - - ll s1 = sum(l, r, 2 * x + 1, lx, m); - - ll s2 = sum(l, r, 2 * x + 2, m, rx); - - return gcd(s1 , s2); - - } - - - - ll sum(ll l, ll r) { - - return sum(l, r, 0, 0, size); - - } - -}; - -bool isPerfectPowerOf3(int n) { - - if (n <= 0) { - - return false; - - } - - while (n % 3 == 0) { - - n /= 3; - - } - - - - return n == 1; - -} - - - - - -int main() { - - - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - ll test_cases; - - cin>>test_cases; - - auto start = chrono::high_resolution_clock::now(); - - - - f(j,0,test_cases){ - - ll m,y,x,r1,maxi=0,k;bool change=true; bool sorted=false;ll sum=0;ll sum1=0;ll mini=1e9; - - long long n,d; - - cin>>n>>d>>k; - - vll vec_1(n); - - if(n%2==0){ - - - - f(i,0,n){ - - vec_1[i]=i%2; - - } - - if(vec_1[d-1]==vec_1[k-1]){ - - if(d-1==0){ - - set i; - - i.insert(vec_1[n-1]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else if(d-1!=n-1){ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else{ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[0]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - } - - } - - else{ - - f(i,0,n-1){ - - vec_1[i]=i%2; - - } - - vec_1[n-1]=2; - - if(vec_1[d-1]==vec_1[k-1]){ - - if(d-1==0){ - - set i; - - i.insert(vec_1[n-1]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else{ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - } - - } - - if(d!=n && k!=n){ - - set t; - - t.insert(vec_1[n-2]); - - t.insert(vec_1[0]); - - f(z,0,4){ - - if(t.find(z)==t.end()){ - - vec_1[n-1]=z; - - break; - - } - - } - - } - - else if(d==n){ - - set t; - - t.insert(vec_1[n-2]); - - t.insert(vec_1[0]); - - t.insert(vec_1[k-1]); - - f(z,0,4){ - - if(t.find(z)==t.end()){ - - vec_1[n-1]=z; - - break; - - } - - } - - } - - else{ - - set t; - - t.insert(vec_1[n-2]); - - t.insert(vec_1[0]); - - t.insert(vec_1[d-1]); - - f(z,0,4){ - - if(t.find(z)==t.end()){ - - vec_1[n-1]=z; - - break; - - } - - } - - } - - if(d-1==0){ - - set i; - - i.insert(vec_1[n-1]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else{ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - - - f(i,0,n){ - - cout< duration = end - start; - - //cout << ""Time taken: "" << duration.count() << "" seconds"" << endl; - - - - return 0; - -}","#include - -#include - -#include - - - -using namespace std; - -#define ull unsigned long long - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define new cout << endl - -#define ll long long - -#define pb push_back - -#define vll vector - -#define INF (long long)1e9 - -#define MOD 1000000007 - -#define mp make_pair - -#define F first - -#define S second - -#define f(i, a, b) for(long long i = a; i < b; i++) // Loop from a to b - -long long gcd(long long a, long long b) { - - while (b != 0) { - - long long temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -long long lcm(long long a, long long b) { - - return (a * b) /gcd(a, b); - -} - -long long factorial(int n) { - - long long result = 1; - - for (int i = 1; i <= n; ++i) { - - result *= i; - - } - - return result; - -} - - - -long long combination(int n, int r) { - - if (r > n) return 0; - - if (r == 0 || r == n) return 1; - - - - - - if (r > n - r) r = n - r; - - - - long long result = 1; - - - - for (int i = 0; i < r; ++i) { - - result *= (n - i); - - result /= (i + 1); - - } - - - - return result; - -} - - - -bool damn(const pair& a, const pair& b) { - - if (floor(log2(a.first)) != floor(log2(b.first))) { - - return floor(log2(a.first)) b.first; - -}; - - - - - - - - - -vector sieve_of_eratosthenes(long long limit) { - - vector prime(limit + 1, true); - - prime[0] = prime[1] = false; - - - - for (long long num = 2; num * num <= limit; ++num) { - - if (prime[num]) { - - for (long long multiple = num * num; multiple <= limit; multiple += num) { - - prime[multiple] = false; - - } - - } - - } - - - - vector primes; - - for (long long i = 2; i <= limit; ++i) { - - if (prime[i]) { - - primes.push_back(i); - - } - - } - - - - return primes; - -}; - -void merge(int arr[], int left, int right) { - - if (left >= right) return; - - int mid = left + (right - left) / 2; - - merge(arr, left, mid); - - merge(arr, mid + 1, right); - - - - int n1 = mid - left + 1; - - int n2 = right - mid; - - - - int L[n1], R[n2]; - - for (int i = 0; i < n1; i++) L[i] = arr[left + i]; - - for (int i = 0; i < n2; i++) R[i] = arr[mid + 1 + i]; - - - - int i = 0, j = 0, k = left; - - while (i < n1 && j < n2) { - - if (L[i] <= R[j]) arr[k++] = L[i++]; - - else arr[k++] = R[j++]; - - } - - - - while (i < n1) arr[k++] = L[i++]; - - while (j < n2) arr[k++] = R[j++]; - -}; - - - -void mergeSort(int arr[], int left, int right) { - - if (left < right) { - - int mid = left + (right - left) / 2; - - mergeSort(arr, left, mid); - - mergeSort(arr, mid + 1, right); - - merge(arr, left, right); - - } - -}; - -struct item{ - - ll m,c; - -}; - -int count_trailing_zeros(ll n) { - - int count = 0; - - - - - - while ((n & 1) == 0 && n != 0) { - - count++; - - n >>= 1; - - } - - - - return count; - -} - - - - - -int popcount(ll n) { - - int count = 0; - - - - - - while (n) { - - - - n = n & (n - 1); - - count++; - - } - - - - return count; - -} - - - - - - - -struct segTree { - - ll size; - - vll sums; - - - - void init(int n) { - - size = 1; - - while (size < n) { - - size *= 2; - - } - - sums.assign(2 * size, 0LL); - - } - - - - void set(ll i, ll v, ll x, ll lx, ll rx) { - - if (rx - lx == 1) { - - sums[x] = v; - - return; - - } - - ll m = (lx + rx) / 2; - - if (i < m) { - - set(i, v, 2 * x + 1, lx, m); - - } - - else { - - set(i, v, 2 * x + 2, m, rx); - - } - - sums[x] = gcd(sums[2 * x + 1] , sums[2 * x + 2]); - - } - - - - void set(ll i, ll v) { - - set(i, v, 0, 0, size); - - } - - - - ll sum(ll l, ll r, ll x, ll lx, ll rx) { - - if (lx >= r || l >= rx) return 1e9; - - if (lx >= l && rx <= r) return sums[x]; - - ll m = (lx + rx) / 2; - - ll s1 = sum(l, r, 2 * x + 1, lx, m); - - ll s2 = sum(l, r, 2 * x + 2, m, rx); - - return gcd(s1 , s2); - - } - - - - ll sum(ll l, ll r) { - - return sum(l, r, 0, 0, size); - - } - -}; - -bool isPerfectPowerOf3(int n) { - - if (n <= 0) { - - return false; - - } - - while (n % 3 == 0) { - - n /= 3; - - } - - - - return n == 1; - -} - - - - - -int main() { - - - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - ll test_cases; - - cin>>test_cases; - - auto start = chrono::high_resolution_clock::now(); - - - - f(j,0,test_cases){ - - ll m,y,x,r1,maxi=0,k;bool change=true; bool sorted=false;ll sum=0;ll sum1=0;ll mini=1e9; - - long long n,d; - - cin>>n>>d>>k; - - vll vec_1(n); - - if(n%2==0){ - - - - f(i,0,n){ - - vec_1[i]=i%2; - - } - - if(vec_1[d-1]==vec_1[k-1]){ - - if(d-1==0){ - - set i; - - i.insert(vec_1[n-1]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else if(d-1!=n-1){ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - else{ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[0]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - } - - } - - else{ - - f(i,0,n-1){ - - vec_1[i]=i%2; - - } - - vec_1[n-1]=2; - - if(vec_1[d-1]==vec_1[k-1]){ - - if(d-1==0){ - - vec_1[d-1]=3; - - } - - else{ - - set i; - - i.insert(vec_1[d-2]); - - i.insert(vec_1[d]); - - i.insert(vec_1[k-1]); - - f(z,0,4){ - - if(i.find(z)==i.end()){ - - vec_1[d-1]=z; - - break; - - } - - } - - } - - } - - } - - f(i,0,n){ - - cout< duration = end - start; - - //cout << ""Time taken: "" << duration.count() << "" seconds"" << endl; - - - - return 0; - -}",1 -prodigy12,2049C - MEX Cycle,c++17 ,304067413,304074094,"#include - -using namespace std; - - - -int main() { - - int t; - - cin >> t; - - - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - - - vector groups(n + 1); - - - - // Start with filling most positions with alternating 0s and 1s - - int curr_val = 0; - - for (int i = 1; i <= n; i++) { - - if (i == y) { - - groups[i] = 2; - - } else { - - groups[i] = curr_val; - - curr_val = 1 - curr_val; - - } - - } - - - - // Then adjust values working backwards from y to ensure MEX property holds - - int curr = y; - - while (curr != x) { - - curr = (curr == 1) ? n : curr - 1; - - if (curr == x) break; - - - - // Get next value (considering circular array) - - int next = (curr == n) ? 1 : curr + 1; - - - - // If next is y, get the value after y - - if (next == y) { - - next = (next == n) ? 1 : next + 1; - - } - - - - // Adjust current position to maintain MEX property - - groups[curr] = (groups[next] + 1) % 2; - - } - - - - // Ensure x position has value 0 - - groups[x] = 0; - - - - // Print result - - for (int i = 1; i <= n; i++) { - - cout << groups[i] << "" ""; - - } - - cout << ""\n""; - - } - - return 0; - -}","#include - -using namespace std; - - - -int main() { - - int t; - - cin >> t; - - - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - --x; - - --y; - - - - vector groups(n); - - - - groups[x] = 0; - - - - for (int i = (x + 1 + n) % n; i != y; i = (i + 1 + n) % n){ - - groups[i] = (groups[(i-1) % n] + 1) % 2; - - - - } - - - - for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n){ - - groups[i] = (groups[(i+1) % n] + 1) % 2; - - - - } - - - - if (groups[(y - 1) % n] == 1 || groups[(y+1) % n] == 1) groups[y] = 2; - - else{ - - groups[y] = 1; - - } - - for (auto g : groups){ - - cout << g << "" ""; - - } - - cout << '\n'; - - } - -}",2 -"SENSODYNE: s.seraj.shafie, AA_Surely#",2049C - MEX Cycle,c++23 ,308530433,308530961,"#include - -#include - - - -#define FOR(i, x, n) for(int i = x; i < n; i++) - -#define F0R(i, n) FOR(i, 0, n) - -#define ROF(i, x, n) for(int i = n - 1; i >= x; i--) - -#define R0F(i, n) ROF(i, 0, n) - - - -#define WTF cout << ""WTF"" << endl - - - -#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#define F first - -#define S second - -#define PB push_back - -#define EP emplace_back - - - -#define ALL(x) x.begin(), x.end() - -#define RALL(x) x.rbegin(), x.rend() - - - -using namespace std; - - - -typedef long long LL; - -typedef long double LD; - - - -typedef pair PII; - -typedef pair PLL; - - - -typedef vector VI; - -typedef vector VLL; - -typedef vector VPII; - -typedef vector VPLL; - - - -typedef complex Point; - - - -const int N = 2e5 + 7; - -const int INF = 1e9 + 7; - -const int LOG = 22; - -const int A = 26; - -const int SQ = 320; - -const int MOD = 1e9 + 7; - - - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - - - -int n, x, y; - -int ans[N]; - - - -void solve() { - - cin >> n >> x >> y; - - x--; y--; - - - - - - if (n & 1) { - - ans[x] = 2; - - FOR(i, x + 1, n) ans[i] = ((x - i) % 2 == 0 ? 1 : 0); - - R0F(i, x) ans[i] = ((x - i) % 2 == 0 ? 0 : 1); - - } - - - - else { - - if (abs(x - y) % 2 == 0) { - - F0R(i, n) ans[i] = (i & 1); - - } - - else { - - F0R(i, n) ans[i] = (abs(x - i) % 2 == 0 ? 0 : 1); - - ans[x] = 2; - - } - - } - - - - F0R(i, n) cout << ans[i] << ' '; - - cout << endl; - -} - - - -int main() { - - IOS; - - int t; cin >> t; - - while(t--) solve(); - -} - -","#include - -#include - - - -#define FOR(i, x, n) for(int i = x; i < n; i++) - -#define F0R(i, n) FOR(i, 0, n) - -#define ROF(i, x, n) for(int i = n - 1; i >= x; i--) - -#define R0F(i, n) ROF(i, 0, n) - - - -#define WTF cout << ""WTF"" << endl - - - -#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#define F first - -#define S second - -#define PB push_back - -#define EP emplace_back - - - -#define ALL(x) x.begin(), x.end() - -#define RALL(x) x.rbegin(), x.rend() - - - -using namespace std; - - - -typedef long long LL; - -typedef long double LD; - - - -typedef pair PII; - -typedef pair PLL; - - - -typedef vector VI; - -typedef vector VLL; - -typedef vector VPII; - -typedef vector VPLL; - - - -typedef complex Point; - - - -const int N = 2e5 + 7; - -const int INF = 1e9 + 7; - -const int LOG = 22; - -const int A = 26; - -const int SQ = 320; - -const int MOD = 1e9 + 7; - - - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - - - -int n, x, y; - -int ans[N]; - - - -void solve() { - - cin >> n >> x >> y; - - x--; y--; - - - - - - if (n & 1) { - - ans[x] = 2; - - FOR(i, x + 1, n) ans[i] = ((x - i) % 2 == 0 ? 1 : 0); - - R0F(i, x) ans[i] = ((x - i) % 2 == 0 ? 0 : 1); - - } - - - - else { - - if (abs(x - y) % 2 == 0) { - - F0R(i, n) ans[i] = (i & 1); - - ans[x] = 2; - - } - - else { - - F0R(i, n) ans[i] = (abs(x - i) % 2 == 0 ? 0 : 1); - - } - - } - - - - F0R(i, n) cout << ans[i] << ' '; - - cout << endl; - -} - - - -int main() { - - IOS; - - int t; cin >> t; - - while(t--) solve(); - -} - -",2 -glowbigger,2049C - MEX Cycle,c++23 ,307068054,307068038,"#include - -int main() { - - for (int _ = (std::cin.tie(0), not std::ios::sync_with_stdio(0)); _ or std::cin >> _, _; _--) { - - int n, x, y; - - std::cin >> n >> x >> y; - - x--, y--; - - std::vector a(n); - - if (n % 2 == 1) { - - a[x] = 2; - - int digit = 0; - - for (int i = (x + 1) % n; i != x; (++i) %= n) a[i] = digit, digit = not digit; - - } else { - - for (int i = 0; i < n; i++) a[i] = i % 2 ? 0 : 1; - - if (a[x] == 1 and a[y] == 1) a[x] = 2; - - if (a[x] == 0 and a[y] == 0) a[x] = 2; - - } - - for (int val : a) std::cout << val << "" ""; - - std::cout << ""\n""; - - } - -} - -","#include - -int main() { - - for (int _ = (std::cin.tie(0), not std::ios::sync_with_stdio(0)); _ or std::cin >> _, _; _--) { - - int n, x, y; - - std::cin >> n >> x >> y; - - x--, y--; - - std::vector a(n); - - if (n % 2 == 1) { - - a[x] = 2; - - int digit = 0; - - for (int i = (x + 1) % n; i != x; (++i) %= n) a[i] = digit, digit = not digit; - - } else { - - for (int i = 0; i < n; i++) a[i] = i % 2 ? 0 : 1; - - if (a[x] == 1 and a[y] == 1) a[x] = 2; - - if (a[x] == 0 and a[y] == 0) a[x] = 2; - - } - - DEBUG(a); - - } - -} - -",1 -Dalle2,2049C - MEX Cycle,c++17 ,303544648,303545098,"#include - -#define ll long long - -#define all(x) (x).begin(), (x).end() - -#define rall(x) (x).rbegin(), (x).rend() - -#define int long long - -#define inf LONG_MAX - -#define loop(i, n) for (int i = 0; i < n; i++) - -#define rep(i, a, n) for (int i = a; i < n; i++) - -#define vec vector - -#define no cout << ""NO"" << '\n'; - -#define yes cout << ""YES"" << '\n'; - -#define nl cout << '\n'; - -#define MOD 1000000007 - -#define fs fflush(stdout); - -#define pb push_back - -#define vp vector> - -#define ump unordered_map - -#define vs vector - -#define vv vector> - -#define vb vector - -using namespace std; - - - -void solve(); - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t = 1; - - cin >> t; - - while (t--) - - solve(); - - return 0; - -} - - - - - -void solve() { - - int n,m,k; - - cin>>n>>m>>k; - - vec a(n,-1); - - a[m-1]=0; - - a[k-1]=1; - - m--,k--; - - for(int i=m+1;i - -#define ll long long - -#define all(x) (x).begin(), (x).end() - -#define rall(x) (x).rbegin(), (x).rend() - -#define int long long - -#define inf LONG_MAX - -#define loop(i, n) for (int i = 0; i < n; i++) - -#define rep(i, a, n) for (int i = a; i < n; i++) - -#define vec vector - -#define no cout << ""NO"" << '\n'; - -#define yes cout << ""YES"" << '\n'; - -#define nl cout << '\n'; - -#define MOD 1000000007 - -#define fs fflush(stdout); - -#define pb push_back - -#define vp vector> - -#define ump unordered_map - -#define vs vector - -#define vv vector> - -#define vb vector - -using namespace std; - - - -void solve(); - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t = 1; - - cin >> t; - - while (t--) - - solve(); - - return 0; - -} - - - - - -void solve() { - - int n,m,k; - - cin>>n>>m>>k; - - vec a(n,-1); - - a[m-1]=0; - - a[k-1]=1; - - m--,k--; - - for(int i=m+1;i - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define ull unsigned long long - -#define ll long long - -#define max_ll 9223372036854775807 - -#define max_int 2147483647 - -#define elif else if - -#define rep(i, l, r) for(register ll i = l; i <= r; ++i) - -#define nep(i, r, l) for(register ll i = r; i >= l; --i) - -#define YES puts(""Yes""); - -#define NO puts(""No""); - -using namespace std; - -templateinline void read(T &x) - -{ - - x=0;char c=getchar();bool f=0; - - while(!isdigit(c))f^=c=='-',c=getchar(); - - while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar(); - - if(f)x=-x; - -} - -templateinline void print(T x) - -{ - - if(x<0)putchar('-'),x=-x; - - if(x>9)print(x/10); - - putchar('0'+x%10); - -} - -int t; - -int n; - -int x,y; - -int ans[200005]; - -void sol(){ - - read(n);read(x);read(y); - - ans[x]=0; - - ans[y]=1; - - int len=y-x-1; - - if(len%2==0){ - - for(int i=x+1;i=1;i--){ - - ans[i]=k; - - k^=1; - - } - - for(int i=n;i>y;i--){ - - ans[i]=k; - - k^=1; - - } - - }else{ - - for(int i=x-1;i>=1;i--){ - - ans[i]=k; - - k^=1; - - } - - for(int i=n;i>y;i--){ - - ans[i]=k; - - k^=1; - - } - - ans[y%n+1]=2; - - } - - for(int i=1;i<=n;++i) - - printf(""%d "",ans[i]); - - puts(""""); - -} - -int main(){ - - read(t); - - while(t--){ - - sol(); - - } - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define ull unsigned long long - -#define ll long long - -#define max_ll 9223372036854775807 - -#define max_int 2147483647 - -#define elif else if - -#define rep(i, l, r) for(register ll i = l; i <= r; ++i) - -#define nep(i, r, l) for(register ll i = r; i >= l; --i) - -#define YES puts(""Yes""); - -#define NO puts(""No""); - -using namespace std; - -templateinline void read(T &x) - -{ - - x=0;char c=getchar();bool f=0; - - while(!isdigit(c))f^=c=='-',c=getchar(); - - while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar(); - - if(f)x=-x; - -} - -templateinline void print(T x) - -{ - - if(x<0)putchar('-'),x=-x; - - if(x>9)print(x/10); - - putchar('0'+x%10); - -} - -int t; - -int n; - -int x,y; - -int ans[200005]; - -void sol(){ - - read(n);read(x);read(y); - - ans[x]=0; - - ans[y]=1; - - int len=y-x-1; - - if(len%2==0){ - - for(int i=x+1;i=1;i--){ - - ans[i]=k; - - k^=1; - - } - - for(int i=n;i>y;i--){ - - ans[i]=k; - - k^=1; - - } - - }else{ - - for(int i=x-1;i>=1;i--){ - - ans[i]=k; - - k^=1; - - } - - for(int i=n;i>y;i--){ - - ans[i]=k; - - k^=1; - - } - - ans[y+1]=2; - - } - - for(int i=1;i<=n;++i) - - printf(""%d "",ans[i]); - - puts(""""); - -} - -int main(){ - - read(t); - - while(t--){ - - sol(); - - } - - return 0; - -}",1 -Greninja_007,2049C - MEX Cycle,c++23 ,304606006,304605828,"#include - -using namespace std; - -const int MOD = 998244353; - -#define int long long - -#define loop(i, n, x) for (int i = 0; i < n; i += x) - - - -void solve() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - x--; - - y--; - - vector ans(n); - - loop(i, n, 1) - - { - - ans[(x + i) % n] = i % 2; - - } - - if (n & 1 || !((y - x) & 1)) - - { - - ans[x] = 2; - - } - - loop(i, n, 1) - - { - - cout << ans[i] << "" ""; - - } - - cout << endl; - -} - - - -int32_t main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0), cout.tie(0); - - - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - -const int MOD = 998244353; - -#define int long long - -#define loop(i, n, x) for (int i = 0; i < n; i += x) - - - -void solve() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - x--; - - y--; - - vector ans(n); - - loop(i, n, 1) - - { - - ans[(x + i) % n] = i % 2; - - } - - if (n & 1 || !(y - x) & 1) - - { - - ans[x] = 2; - - } - - loop(i, n, 1) - - { - - cout << ans[i] << "" ""; - - } - - cout << endl; - -} - - - -int32_t main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0), cout.tie(0); - - - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -} - -",1 -ZarifSWE,2049C - MEX Cycle,c++20 ,303981058,303982024,"#include - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long int; - -int main() - -{ - - ll i, j, n, k, t, d, m, l, v, x, y; - - cin >> t; - - while (t--) - - { - - cin>>n>>x>>y; - - int arr[n+1]; - - for(i=1;i - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long int; - -int main() - -{ - - ll i, j, n, k, t, d, m, l, v, x, y; - - cin >> t; - - while (t--) - - { - - cin >> n >> x >> y; - - int arr[n + 1]; - - for (i = 1; i < n; i++) - - { - - if (i % 2 == 0) - - { - - arr[i] = 1; - - } - - else - - { - - arr[i] = 0; - - } - - } - - if (n % 2 == 0) - - { - - arr[n] = 1; - - } - - else - - { - - arr[n] = 2; - - } - - if (arr[x] == arr[y]) - - { - - if (y == n - 1) - - { - - arr[x] = 2; - - } - - else - - { - - arr[y] = 2; - - if (y != n && arr[y + 2] == 2) - - { - - arr[y + 1] = 0; - - arr[n] = 1; - - } - - } - - } - - for (i = 1; i <= n; i++) - - { - - cout << arr[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -} - -",2 -maksim.banin,2049C - MEX Cycle,c++17 ,305906368,305913338,"#include - -using namespace std; - -void solve(int n, int x, int y) { - - vector> adj(n + 1, vector()); - - for (int i = 0; i < n; ++i) { - - int prev = (i - 1 + n) % n; - - int next = (i + 1) % n; - - adj[i].push_back(prev); - - adj[i].push_back(next); - - } - - auto is_adjacent = [&](int u, int v) -> bool { - - return (u == v - 1) || (u == v + 1) || (u == 1 && v == n) || (u == n && v == 1); - - }; - - if (!is_adjacent(x, y)) { - - adj[x].push_back(y); - - adj[y].push_back(x); - - } - - vector labels(n + 1, 0); - - queue q; - - for (int i = 0; i < n; ++i) { - - q.push(i); - - } - - vector in_queue(n + 1, true); - - while (!q.empty()) { - - int u = q.front(); - - q.pop(); - - in_queue[u] = false; - - int mask = 0; - - for (const auto &v : adj[u]) { - - if (labels[v] < 32) { - - mask |= (1 << labels[v]); - - } - - } - - int mex = 0; - - while (mask & (1 << mex)) { - - ++mex; - - } - - if (labels[u] != mex) { - - labels[u] = mex; - - for (const auto &v : adj[u]) { - - if (!in_queue[v]) { - - q.push(v); - - in_queue[v] = true; - - } - - } - - } - - } - - for (int i = 0; i < n; ++i) { - - cout << labels[i] << "" ""; - - } - - cout << ""\n""; - -} - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; - - cin >> t; - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - solve(n, x, y); - - } - - return 0; - -} - -","#include - -using namespace std; - -void solve(int n, int x, int y) { - - vector> adj(n + 1, vector()); - - for (int i = 1; i <= n; ++i) { - - int prev = i - 1; - - if (prev == 0) { - - prev = n; - - } - - int next = i + 1; - - if (next > n) { - - next = 1; - - } - - adj[i].push_back(prev); - - adj[i].push_back(next); - - } - - auto is_adjacent = [&](int u, int v) -> bool { - - return (u == v - 1) || (u == v + 1) || (u == 1 && v == n) || (u == n && v == 1); - - }; - - if (!is_adjacent(x, y)) { - - adj[x].push_back(y); - - adj[y].push_back(x); - - } - - vector labels(n + 1, 0); - - queue q; - - for (int i = 1; i <= n; ++i) { - - q.push(i); - - } - - vector in_queue_flag(n + 1, true); - - while (!q.empty()) { - - int u = q.front(); - - q.pop(); - - in_queue_flag[u] = false; - - int mask = 0; - - for (auto &v : adj[u]) { - - if (labels[v] < 32) { - - mask |= (1 << labels[v]); - - } - - } - - int mex = 0; - - while (mask & (1 << mex)) { - - ++mex; - - } - - if (labels[u] != mex) { - - labels[u] = mex; - - for (auto &v : adj[u]) { - - if (!in_queue_flag[v]) { - - q.push(v); - - in_queue_flag[v] = true; - - } - - } - - } - - } - - for (int i = 1; i <= n; ++i) { - - cout << labels[i] << (i < n ? "" "" : ""\n""); - - } - -} - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; - - cin >> t; - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - solve(n, x, y); - - } - -} - -",2 --200,2049C - MEX Cycle,c++20 ,306631417,306630678,"#include - -using namespace std; - - - -#define ll long long - -#define ull unsigned long long - -#define int long long int - - - -#define init ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define no cout << ""NO\n"" - -#define yes cout << ""YES\n"" - -#define mod 1000000007 - -#define endd cout << ""\n"" - -#define endl ""\n"" - -#define came cout<<""came\n""; - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; __print(x); cerr << endl; - -#define start_T auto start = std::chrono::high_resolution_clock::now(); - -#define end_T auto end = std::chrono::high_resolution_clock::now(); \ - -chrono::duration duration = end - start; \ - -cout << ""Time taken: ""< - -void __print(T t){cerr< - -void in(T a[],int n){for(int i=0;i>a[i];} - -template - -void out(T a[], int x){for(int i = 0; i < x; i++){cout << a[i] << "" ""; } cout << endl;} - -template - -void in(vector& a, int n){for(int i = 0; i < n; i++){ T x; cin >> x; a.push_back(x);}} - -template - -void in(vector>& a,int n,int m){vector tp;for(int i=0;i - -void out(vector a){for(auto i : a)cout << i << "" "";cout << endl;} - -struct pair_hash{ - -template - -std::size_t operator()(const pair& pair) const {return std::hash()(pair.first) ^ (std::hash()(pair.second) << 1);}}; - -class DSU{ - - public: - - vector parent,rank,size; - - DSU(int n){ - - // rank.resize(n+1,0); - - parent.resize(n+1); - - size.resize(n+1,1); - - iota(parent.begin(),parent.end(),0); - - } - - //finding ultimate parent() - - int fup(int node){ - - if(node == parent[node]) return node; - - // path compression - - return parent[node] = fup(parent[node]); - - } - - // union by rank() - - void joinr(int u,int v){ - - int p1 = fup(u), p2 = fup(v); - - if(p1==p2) return; - - else if(rank[p1]>rank[p2]){ - - parent[p2]=p1; - - } - - else if(rank[p2]>rank[p1]){ - - parent[p1]=p2; - - } - - else{ - - parent[p1]=p2; - - //we ar attaching component p1 to p2 - - rank[p2]++; - - } - - } - - // union by size() - - void joins(int u,int v){ - - int p1 = fup(u); - - int p2 = fup(v); - - if(p1==p2) return; - - else if(size[p1]>size[p2]) size[p1]+=size[p2],parent[p2]=p1; - - else size[p2]+=size[p1],parent[p1]=p2; - -}}; - -class SEG{ - - public: - - vector seg; - - vector arr; - - vector lazy; - - SEG(int n){ - - this->seg = vector(n*4+1,0); - - this->lazy = vector(n*4+1,0); - - this->arr.clear(); - - } - - void build(){ - - if(this->arr.size()==0) return; - - this->build(0,0,this->arr.size()-1); - - } - - int query(int l,int r){ - - return this->query(0,0,arr.size()-1,l,r); - - } - - // Builds a Seg Tree - - int build(int ind,int lo,int hi){ - - if(lo==hi){ - - return this->seg[ind] = this->arr[lo]; - - } - - int mid = (lo+hi)/2; - - return this->seg[ind] = __gcd(build(2*ind+1,lo,mid),build(2*ind+2,mid+1,hi)); - - } - - int query(int ind,int lo,int hi,int l,int r){ - - //complete lying - - // l --- low -- high --- r - - if(lo>=l && hi<=r) return this->seg[ind]; - - //Not overlap - - // lo -- hi -- l -- r [or] l -- r -- lo -- hi - - if(hir) return 0; - - //Semi Overlap - - int mid = (lo+hi)/2; - - return __gcd(query(ind*2+1,lo,mid,l,r),query(ind*2+2,mid+1,hi,l,r)); - - } - - // Updates the I'th ind value - - void update(int segind,int lo,int hi,int val,int ind){ - - if(lo==hi && lo==ind){ - - this->seg[segind] = val; - - return; - - } - - int mid = (lo+hi)/2; - - if(lo<=ind&&mid>=ind) update(2*segind+1,lo,mid,val,ind); - - else update(2*segind+2,mid+1,hi,val,ind); - - this->seg[segind] = max(this->seg[segind*2+1],this->seg[segind*2+2]); - - } - - //update Lazy - - void updatel(int ind,int lo,int hi,int l,int r,int val){ - - // updating the pendings - - if(this->lazy[ind]!=0){ - - this->seg[ind] = (hi-lo+1)*this->lazy[ind]; - - if(hi!=lo){ - - this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind]; - - } - - this->lazy[ind]=0; - - } - - - - if(lo>r || hihi) return; - - // l -- lo -- hi -- r - - if(lo>=l && hi<=r){ - - this->seg[ind] += (hi-lo+1) * val; - - if(lo!=hi){ - - this->lazy[2*ind+1]+= val; - - this->lazy[2*ind+2]+= val; - - } - - } - - - - int mid = (lo+hi)/2; - - updatel(ind*2+1,lo,mid,l,r,val); - - updatel(ind*2+2,mid+1,hi,l,r,val); - - this->seg[ind] = this->seg[ind*2+1] + this->seg[ind*2+2]; - - } - - int queryl(int ind,int lo,int hi,int l,int r){ - - // updating the pendings - - if(this->lazy[ind]!=0){ - - this->seg[ind] = (hi-lo+1)*this->lazy[ind]; - - if(hi!=lo){ - - this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind]; - - } - - this->lazy[ind]=0; - - } - - - - if(lo>r || hihi) return 0; - - // l -- lo -- hi -- r - - if(lo>=l && hi<=r){ - - return this->seg[ind]; - - } - - int mid = (lo+hi)/2; - - return queryl(ind*2+1,lo,mid,l,r)+queryl(ind*2+2,mid+1,hi,l,r); - - }}; - -inline int fib(int n) {const double phi = (1 + sqrt(5)) / 2;const double psi = (1 - sqrt(5)) / 2;return round((pow(phi, n) - pow(psi, n)) / sqrt(5));} - -inline int gcd(int A, int B){while(A>0&&B>0){if(A>B) A%=B;else B%=A;}return ((A==0)?B:A);} - -inline int lcm(int A, int B) {return ((A * B) / (gcd(A, B)));} - -inline bool isprime(int X) {if(X==1) return 0;if (X == 2) return true;for (int i = 2; i <= sqrt(X); i++) {if ((X % i) == 0)return false;}return true;} - -// int Mod(string &a,int k){int rem=0;for(int i=0;i is_prime; - - vector primes; - - sieve(int n){ - - this->n=n; - - is_prime.resize(n+1,true); - - is_prime[0] = is_prime[1] = false; - - for(int i=2;i<=n;i++){ - - if(is_prime[i]){ - - primes.push_back(i); - - for(int j=i*i;j<=n;j+=i) - - is_prime[j] = false; - - } - - } - - } - - bool fun(int ind){ - - return is_prime[ind]; - - } }; - -int pow(int a,int b){if(b==0) return 1;int res=pow(a,b/2);if(b%2) return ((((res*res)%mod)*a)%mod);else return ((res*res)%mod);} - -int modInverse(int a,int p){int res=1,exp=p-2;while(exp){if(exp%2)res=(1LL*res*a)%p;a=(1LL*a*a)%p; exp/=2;}return res;} - -//-------------------------------------------------UDF------------------------------------------------ - -signed main(){ - - init;start_T; - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - - #endif - - ll _=1; - - cin>>_; - - while(_--){ - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - memset(a,-1,sizeof(a)); - - bool f=0; - - if(max(x,y)-min(x,y)==1||(max(x,y)==n&&min(x,y)==1)){ - - if(n%2) cout<<""0 1 2 ""; - - bool f=0; - - for(int i=(n&1)?3:0;i - -using namespace std; - - - -#define ll long long - -#define ull unsigned long long - -#define int long long int - - - -#define init ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define no cout << ""NO\n"" - -#define yes cout << ""YES\n"" - -#define mod 1000000007 - -#define endd cout << ""\n"" - -#define endl ""\n"" - -#define came cout<<""came\n""; - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; __print(x); cerr << endl; - -#define start_T auto start = std::chrono::high_resolution_clock::now(); - -#define end_T auto end = std::chrono::high_resolution_clock::now(); \ - -chrono::duration duration = end - start; \ - -cout << ""Time taken: ""< - -void __print(T t){cerr< - -void in(T a[],int n){for(int i=0;i>a[i];} - -template - -void out(T a[], int x){for(int i = 0; i < x; i++){cout << a[i] << "" ""; } cout << endl;} - -template - -void in(vector& a, int n){for(int i = 0; i < n; i++){ T x; cin >> x; a.push_back(x);}} - -template - -void in(vector>& a,int n,int m){vector tp;for(int i=0;i - -void out(vector a){for(auto i : a)cout << i << "" "";cout << endl;} - -struct pair_hash{ - -template - -std::size_t operator()(const pair& pair) const {return std::hash()(pair.first) ^ (std::hash()(pair.second) << 1);}}; - -class DSU{ - - public: - - vector parent,rank,size; - - DSU(int n){ - - // rank.resize(n+1,0); - - parent.resize(n+1); - - size.resize(n+1,1); - - iota(parent.begin(),parent.end(),0); - - } - - //finding ultimate parent() - - int fup(int node){ - - if(node == parent[node]) return node; - - // path compression - - return parent[node] = fup(parent[node]); - - } - - // union by rank() - - void joinr(int u,int v){ - - int p1 = fup(u), p2 = fup(v); - - if(p1==p2) return; - - else if(rank[p1]>rank[p2]){ - - parent[p2]=p1; - - } - - else if(rank[p2]>rank[p1]){ - - parent[p1]=p2; - - } - - else{ - - parent[p1]=p2; - - //we ar attaching component p1 to p2 - - rank[p2]++; - - } - - } - - // union by size() - - void joins(int u,int v){ - - int p1 = fup(u); - - int p2 = fup(v); - - if(p1==p2) return; - - else if(size[p1]>size[p2]) size[p1]+=size[p2],parent[p2]=p1; - - else size[p2]+=size[p1],parent[p1]=p2; - -}}; - -class SEG{ - - public: - - vector seg; - - vector arr; - - vector lazy; - - SEG(int n){ - - this->seg = vector(n*4+1,0); - - this->lazy = vector(n*4+1,0); - - this->arr.clear(); - - } - - void build(){ - - if(this->arr.size()==0) return; - - this->build(0,0,this->arr.size()-1); - - } - - int query(int l,int r){ - - return this->query(0,0,arr.size()-1,l,r); - - } - - // Builds a Seg Tree - - int build(int ind,int lo,int hi){ - - if(lo==hi){ - - return this->seg[ind] = this->arr[lo]; - - } - - int mid = (lo+hi)/2; - - return this->seg[ind] = __gcd(build(2*ind+1,lo,mid),build(2*ind+2,mid+1,hi)); - - } - - int query(int ind,int lo,int hi,int l,int r){ - - //complete lying - - // l --- low -- high --- r - - if(lo>=l && hi<=r) return this->seg[ind]; - - //Not overlap - - // lo -- hi -- l -- r [or] l -- r -- lo -- hi - - if(hir) return 0; - - //Semi Overlap - - int mid = (lo+hi)/2; - - return __gcd(query(ind*2+1,lo,mid,l,r),query(ind*2+2,mid+1,hi,l,r)); - - } - - // Updates the I'th ind value - - void update(int segind,int lo,int hi,int val,int ind){ - - if(lo==hi && lo==ind){ - - this->seg[segind] = val; - - return; - - } - - int mid = (lo+hi)/2; - - if(lo<=ind&&mid>=ind) update(2*segind+1,lo,mid,val,ind); - - else update(2*segind+2,mid+1,hi,val,ind); - - this->seg[segind] = max(this->seg[segind*2+1],this->seg[segind*2+2]); - - } - - //update Lazy - - void updatel(int ind,int lo,int hi,int l,int r,int val){ - - // updating the pendings - - if(this->lazy[ind]!=0){ - - this->seg[ind] = (hi-lo+1)*this->lazy[ind]; - - if(hi!=lo){ - - this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind]; - - } - - this->lazy[ind]=0; - - } - - - - if(lo>r || hihi) return; - - // l -- lo -- hi -- r - - if(lo>=l && hi<=r){ - - this->seg[ind] += (hi-lo+1) * val; - - if(lo!=hi){ - - this->lazy[2*ind+1]+= val; - - this->lazy[2*ind+2]+= val; - - } - - } - - - - int mid = (lo+hi)/2; - - updatel(ind*2+1,lo,mid,l,r,val); - - updatel(ind*2+2,mid+1,hi,l,r,val); - - this->seg[ind] = this->seg[ind*2+1] + this->seg[ind*2+2]; - - } - - int queryl(int ind,int lo,int hi,int l,int r){ - - // updating the pendings - - if(this->lazy[ind]!=0){ - - this->seg[ind] = (hi-lo+1)*this->lazy[ind]; - - if(hi!=lo){ - - this->lazy[2*ind+1]=this->lazy[2*ind+2]=this->lazy[ind]; - - } - - this->lazy[ind]=0; - - } - - - - if(lo>r || hihi) return 0; - - // l -- lo -- hi -- r - - if(lo>=l && hi<=r){ - - return this->seg[ind]; - - } - - int mid = (lo+hi)/2; - - return queryl(ind*2+1,lo,mid,l,r)+queryl(ind*2+2,mid+1,hi,l,r); - - }}; - -inline int fib(int n) {const double phi = (1 + sqrt(5)) / 2;const double psi = (1 - sqrt(5)) / 2;return round((pow(phi, n) - pow(psi, n)) / sqrt(5));} - -inline int gcd(int A, int B){while(A>0&&B>0){if(A>B) A%=B;else B%=A;}return ((A==0)?B:A);} - -inline int lcm(int A, int B) {return ((A * B) / (gcd(A, B)));} - -inline bool isprime(int X) {if(X==1) return 0;if (X == 2) return true;for (int i = 2; i <= sqrt(X); i++) {if ((X % i) == 0)return false;}return true;} - -// int Mod(string &a,int k){int rem=0;for(int i=0;i is_prime; - - vector primes; - - sieve(int n){ - - this->n=n; - - is_prime.resize(n+1,true); - - is_prime[0] = is_prime[1] = false; - - for(int i=2;i<=n;i++){ - - if(is_prime[i]){ - - primes.push_back(i); - - for(int j=i*i;j<=n;j+=i) - - is_prime[j] = false; - - } - - } - - } - - bool fun(int ind){ - - return is_prime[ind]; - - } }; - -int pow(int a,int b){if(b==0) return 1;int res=pow(a,b/2);if(b%2) return ((((res*res)%mod)*a)%mod);else return ((res*res)%mod);} - -int modInverse(int a,int p){int res=1,exp=p-2;while(exp){if(exp%2)res=(1LL*res*a)%p;a=(1LL*a*a)%p; exp/=2;}return res;} - -//-------------------------------------------------UDF------------------------------------------------ - -signed main(){ - - init;start_T; - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - - #endif - - ll _=1; - - cin>>_; - - while(_--){ - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - memset(a,-1,sizeof(a)); - - bool f=0; - - if(max(x,y)-min(x,y)==1||(max(x,y)==n&&min(x,y)==1)){ - - if(n%2) cout<<""0 1 2 ""; - - bool f=0; - - for(int i=(n&1)?3:0;i - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -typedef vectorVI; typedef vectorVVI; - -typedef vectorVS; - -typedef pairPII; - -#define FOR(i,n) for((i)=0;(i)<(n);(i)++) - -#define FORN(i,n) for((i)=(n)-1;(i)>=0;(i)--) - -#define FOR1(i,n) for((i)=1;(i)<=(n);(i)++) - -#define BE(a) ((a).begin()),((a).end()) - -#define SI(a) ((int)(a).size()) - -#define CLR(a) memset(a,0,sizeof(a)) - -#define PB push_back - -#define MP make_pair - - - -int n, x, y; - -int a[200005]; - - - -void Solve() - -{ - - int i; - - FOR(i, n) a[i] = i % 2; - - if (n % 2) a[n - 1] = 2; - - if ((x + 1) % n == y || (y + 1) % n == x) return; - - if (n % 2) - - { - - FOR(i, n) a[(x + i) % n] = i % 2; - - a[x] = 2; - - } - - else a[x] = 2; - -} - - - -void WriteAnswer() - -{ - - int i; - - FOR(i, n) - - { - - if (i) cout << "" ""; - - cout << a[i]; - - } - - cout << endl; - -} - - - -void ReadInput() - -{ - - cin >> n >> x >> y; - - x--, y--; - -} - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0), cout.tie(0); - -#if !ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - -#endif - - int t; - - for (cin >> t; t > 0; t--) - - { - - ReadInput(); - - Solve(); - - WriteAnswer(); - - } - - return 0; - -} - -","#pragma comment(linker, ""/STACK:40000000"") - -#define _CRT_SECURE_NO_WARNINGS - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -typedef vectorVI; typedef vectorVVI; - -typedef vectorVS; - -typedef pairPII; - -#define FOR(i,n) for((i)=0;(i)<(n);(i)++) - -#define FORN(i,n) for((i)=(n)-1;(i)>=0;(i)--) - -#define FOR1(i,n) for((i)=1;(i)<=(n);(i)++) - -#define BE(a) ((a).begin()),((a).end()) - -#define SI(a) ((int)(a).size()) - -#define CLR(a) memset(a,0,sizeof(a)) - -#define PB push_back - -#define MP make_pair - - - -int n, x, y; - -int a[200005]; - - - -void Solve() - -{ - - int i, j; - - FOR(i, n) a[i] = i % 2; - - if (n % 2) a[n - 1] = 2; - - if ((x + 1) % n != y && (y + 1) % n != x && a[x] == a[y]) - - { - - if (n % 2) FOR(i, n) a[(x + i) % n] = i % 2; - - a[x] = 2; - - } - - /*FOR(i, n) - - { - - set b; - - for (j = -1; j <= 1; j++) b.insert(a[(n + i + j) % n]); - - if (i == x) b.insert(a[y]); - - else if (i == y) b.insert(a[x]); - - for (j = 0; ; j++) if (!b.count(j)) break; - - if (a[i] != j) - - { - - ; - - } - - }*/ - -} - - - -void WriteAnswer() - -{ - - int i; - - FOR(i, n) - - { - - if (i) cout << "" ""; - - cout << a[i]; - - } - - cout << endl; - -} - - - -void ReadInput() - -{ - - cin >> n >> x >> y; - - x--, y--; - -} - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0), cout.tie(0); - -#if !ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - -#endif - - int t; - - for (cin >> t; t > 0; t--) - - { - - ReadInput(); - - Solve(); - - WriteAnswer(); - - } - - return 0; - -} - -",2 -theworstperson,2049C - MEX Cycle,c++20 ,304578915,304577393,"#include - -using namespace std; - -int main(){ - - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int t; cin>>t; - - while(t--){ - - int n,x,y; cin>>n>>x>>y; x--; y--; vector a(n); - - for(int i=0;i - -using namespace std; - -int main(){ - - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int t; cin>>t; - - while(t--){ - - int n,x,y; cin>>n>>x>>y; int a[n+1]; - - for(int i=1;i<=n;i++) a[(x+i)%n]=i%2; - - if(n%2||(y-x)%2==0) a[x]=2; - - for(int i=1;i<=n;i++) cout< - -using namespace std; - -using ll = long long; - -const ll inf = 4e18; - -const int N = 2e5 + 5; - -int n, x, y; - -int a[N]; - -void solve(){ - - cin >> n >> x >> y; - - for(int i = 1;i <= n; ++ i){ - - a[i] = (i - 1) % 2; - - } - - if(n % 2 == 1)a[1] = 2; - - - - if(a[x] == a[y]){ - - if(n % 2 == 0)a[x] = 2; - - else{ - - if(x == 2)swap(a[x], a[1]); - - else if(y == n)swap(a[y], a[1]); - - else a[x] = 2; - - } - - } - - for(int i = 1;i <= n; ++ i)cout << a[i] << ' '; - - cout << '\n'; - - - -} - - - -int main(){ - - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int _ = 1;cin >> _; - - while(_ --){ - - solve(); - - } - - return 0; - -} - -/* - - - -*/","#include - -using namespace std; - -using ll = long long; - -const ll inf = 4e18; - -const int N = 2e5 + 5; - -int n, x, y; - -int a[N]; - -void solve(){ - - cin >> n >> x >> y; - - for(int i = 1;i <= n; ++ i){ - - a[i] = (i - 1) % 2; - - } - - if(n % 2 == 1)a[1] = 2; - - - - if(a[x] == a[y]){ - - if(n % 2 == 0)a[x] = 2; - - else{ - - if(x == 2)swap(a[x], a[1]); - - else if(y == n)swap(a[y], a[1]); - - else a[y] = 2; - - } - - } - - for(int i = 1;i <= n; ++ i)cout << a[i] << ' '; - - cout << '\n'; - - - -} - - - -int main(){ - - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int _ = 1;cin >> _; - - while(_ --){ - - solve(); - - } - - return 0; - -} - -/* - - - -*/",2 -7oDA_ERROR,2049C - MEX Cycle,c++23 ,307342135,307342263,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -#define ll long long - -#define mod 998244353 - -const int N = 1e6 + 5; - -ll oo = 0x3f3f3f3f3f3f3f3f; - -int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; - -int dy[] = {1, -1, 0, 0, -1, 1, -1, 1}; - -char ch[] = {'R', 'L', 'U', 'D'}; - - - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - - - if (fopen(""input.txt"", ""r"")) - - { - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - } - - - - int t = 1; - - cin >> t; - - - - while (t--) - - { - - int n, m, k; - - cin >> n >> m >> k; - - vector v(n + 1); - - v[k] = 1e9; - - if (m == 1) - - v[n] = 1; - - else - - v[m - 1] = 1; - - if (m == n) - - v[1] = 1; - - else - - v[m + 1] = 1; - - - - for (int i = 1; i <= n; i++) - - { - - if (i == m) - - continue; - - if (i == k) - - { - - int j = 0; - - vector a; - - if (i == 1) - - { - - a.push_back(v[n]); - - } - - else - - a.push_back(v[i - 1]); - - - - if (i == n) - - a.push_back(v[1]); - - - - else - - a.push_back(v[i + 1]); - - if ((i + 1) % n != m % n && (i - 1 != m || (i == 1 && m != n))) - - a.push_back(v[m]); - - sort(a.begin(), a.end()); - - for (auto it : a) - - { - - if (it == j) - - j++; - - } - - v[i] = j; - - } - - else - - { - - int j = 0; - - vector a; - - if (i == 1) - - { - - a.push_back(v[n]); - - } - - else - - a.push_back(v[i - 1]); - - - - if (i == n) - - a.push_back(v[1]); - - else - - a.push_back(v[i + 1]); - - sort(a.begin(), a.end()); - - for (auto it : a) - - { - - if (it == j) - - j++; - - } - - v[i] = j; - - } - - } - - for (int i = 1; i <= n; i++) - - cout << v[i] << "" ""; - - cout << '\n'; - - } - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -#define ll long long - -#define mod 998244353 - -const int N = 1e6 + 5; - -ll oo = 0x3f3f3f3f3f3f3f3f; - -int dx[] = {0, 0, -1, 1, -1, -1, 1, 1}; - -int dy[] = {1, -1, 0, 0, -1, 1, -1, 1}; - -char ch[] = {'R', 'L', 'U', 'D'}; - - - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - - - - if (fopen(""input.txt"", ""r"")) - - { - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - } - - - - int t = 1; - - cin >> t; - - - - while (t--) - - { - - int n, m, k; - - cin >> n >> m >> k; - - vector v(n + 1); - - v[k] = 1e9; - - if (m == 1) - - v[n] = 1; - - else - - v[m - 1] = 1; - - if (m == n) - - v[1] = 1; - - else - - v[m + 1] = 1; - - int q = 10; - - while (q--) - - { - - for (int i = 1; i <= n; i++) - - { - - if (i == m) - - continue; - - if (i == k) - - { - - int j = 0; - - vector a; - - if (i == 1) - - { - - a.push_back(v[n]); - - } - - else - - a.push_back(v[i - 1]); - - - - if (i == n) - - a.push_back(v[1]); - - - - else - - a.push_back(v[i + 1]); - - if ((i + 1) % n != m % n && (i - 1 != m || (i == 1 && m != n))) - - a.push_back(v[m]); - - sort(a.begin(), a.end()); - - for (auto it : a) - - { - - if (it == j) - - j++; - - } - - v[i] = j; - - } - - else - - { - - int j = 0; - - vector a; - - if (i == 1) - - { - - a.push_back(v[n]); - - } - - else - - a.push_back(v[i - 1]); - - - - if (i == n) - - a.push_back(v[1]); - - else - - a.push_back(v[i + 1]); - - sort(a.begin(), a.end()); - - for (auto it : a) - - { - - if (it == j) - - j++; - - } - - v[i] = j; - - } - - } - - } - - for (int i = 1; i <= n; i++) - - cout << v[i] << "" ""; - - cout << '\n'; - - } - - return 0; - -}",2 -anurag_shukla_,2049C - MEX Cycle,c++20 ,304028425,304027249,"#include - -// #include - -// #include - -using namespace std; - -//using namespace __gnu_pbds; - -//typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -#define int long long - -#define pb push_back - -#define endl '\n' - -#define vi vector - -const int Mod=1e9+7; - -const int N=1e6; - -#define ld long double - -#define vpi vector> - -const int MOD = 1e9 + 7; - - - -#define mii map - -#define vvi vector - -#define rep(i,x,y) for(int i=x; i prime(n+1,1); - - prime[0]=0; - - prime[1]=0; - - for(int i =2;i*i<=n;i++){ - - if(prime[i]){ - - for(int j =i*i;j<=n;j=j+i){ - - prime[j]=0; - - }}} - - return prime[n]; - - } - - - - int power(int x,int n){ - - // calculating the power by binary exponentiation - - int ans=1; - - if(n==0){ - - return 1; - - } - - if(n%2 == 0){ - - // even power case - - ans=power(x*x,n/2); - - } - - else { - - //odd power case - - ans=x*power(x*x,n/2); - - } - - return ans; - - } - - - -int ncr(int n,int r){ - - if(r==0 || r==n) return 1; - - if(r==1) return n; - - int res=1; - - for(int i=1;i<=r;i++){ - - res*=(n-i+1); - - res/=(i); - - } - - return res; - -} - - - -// factorial - -unsigned int factorial(unsigned int n) - -{ - - if (n == 0 || n == 1) - - return 1; - - return n * factorial(n - 1); - -} - - - - - -// sort the vactor pair based on second element - - bool comp(pair& a, pair& b){ - - return a.second < b.second; - - } - -// Function to calculate (base^exponent) % mod - -int modExp(int base, int exponent, int mod) { - - int result = 1; - - while (exponent > 0) { - - if (exponent % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exponent /= 2; - - } - - return result; - -} - - - -// Function to calculate (P * Q^-1) % MOD - -int calculateModInverse(int P, int Q) { - - int Q_inv = modExp(Q, MOD - 2, MOD); - - return (P * Q_inv) % MOD; - -} - - - -int gcd(int a, int b) { - - while (b != 0) { - - int temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -void FASTIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - - - -int32_t main(){ - - FASTIO(); - - cout<>t; - - while(t--){ - - int n,x,y; - - cin>>n>>x>>y; - - vi ans(n,-1); - - x--; - - y--; - - for(int i=0;i - -// #include - -// #include - -using namespace std; - -//using namespace __gnu_pbds; - -//typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -#define int long long - -#define pb push_back - -#define endl '\n' - -#define vi vector - -const int Mod=1e9+7; - -const int N=1e6; - -#define ld long double - -#define vpi vector> - -const int MOD = 1e9 + 7; - - - -#define mii map - -#define vvi vector - -#define rep(i,x,y) for(int i=x; i prime(n+1,1); - - prime[0]=0; - - prime[1]=0; - - for(int i =2;i*i<=n;i++){ - - if(prime[i]){ - - for(int j =i*i;j<=n;j=j+i){ - - prime[j]=0; - - }}} - - return prime[n]; - - } - - - - int power(int x,int n){ - - // calculating the power by binary exponentiation - - int ans=1; - - if(n==0){ - - return 1; - - } - - if(n%2 == 0){ - - // even power case - - ans=power(x*x,n/2); - - } - - else { - - //odd power case - - ans=x*power(x*x,n/2); - - } - - return ans; - - } - - - -int ncr(int n,int r){ - - if(r==0 || r==n) return 1; - - if(r==1) return n; - - int res=1; - - for(int i=1;i<=r;i++){ - - res*=(n-i+1); - - res/=(i); - - } - - return res; - -} - - - -// factorial - -unsigned int factorial(unsigned int n) - -{ - - if (n == 0 || n == 1) - - return 1; - - return n * factorial(n - 1); - -} - - - - - -// sort the vactor pair based on second element - - bool comp(pair& a, pair& b){ - - return a.second < b.second; - - } - -// Function to calculate (base^exponent) % mod - -int modExp(int base, int exponent, int mod) { - - int result = 1; - - while (exponent > 0) { - - if (exponent % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exponent /= 2; - - } - - return result; - -} - - - -// Function to calculate (P * Q^-1) % MOD - -int calculateModInverse(int P, int Q) { - - int Q_inv = modExp(Q, MOD - 2, MOD); - - return (P * Q_inv) % MOD; - -} - - - -int gcd(int a, int b) { - - while (b != 0) { - - int temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -void FASTIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - - - -int32_t main(){ - - FASTIO(); - - cout<>t; - - while(t--){ - - int n,x,y; - - cin>>n>>x>>y; - - vi ans(n,-1); - - ans[x-1]=0; - - ans[y-1]=1; - - - - if(ans[x%n]==-1)ans[x]=2; - - if(ans[(x-2) %n]==-1)ans[(x-2) %n]=2; - - if(ans[(y-2) %n] ==-1)ans[(y-2) %n]=0; - - if(ans[y%n]==-1)ans[y]=0; - - for(int i=0;i - - - -using namespace std; - -#define lli long long int - - - -void solve(){ - - lli n, x, y; - - cin >> n >> x >> y; - - vector a1(n), a2(n); - - lli st = 1; - - for(int i = 0; i < n; i++){ - - a1[i] = st; - - st = 1-st; - - } - - st = 0; - - for(int i = 0; i < n; i++){ - - a2[i] = st; - - st = 1 -st; - - } - - if(n&1){ - - a1[n-1] = 2; - - a2[n-1] = 2; - - } - - bool yes1 = false, yes2 = false; - - if(((y-x) == 1) || ((y == n) && (n&1))){ - - yes1 = true; - - goto label; - - } - - x--; y--; - - if(a1[x] == 1){ - - a1[x] = 2; - - yes1 = true; - - } - - else if((a1[y] == 1)){ - - a1[y] = 2; - - yes1 = true; - - } - - else if(a2[x] == 1){ - - a2[x] = 2; - - yes2 = true; - - } - - else if(a2[y] == 1){ - - a2[y] = 2; - - yes2 = true; - - } - - label: - - if(yes1){ - - for(int i = 0; i < n; i++){ - - cout << a1[i] << "" ""; - - } - - cout << endl; - - } - - else{ - - for(int i = 0; i < n; i++){ - - cout << a2[i] << "" ""; - - } - - cout << endl; - - } - - - -} - - - -#define lli long long int - -int main(){ - - ios_base::sync_with_stdio(false); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - lli t; - - cin >> t; - - // t = 1; - - while(t--){ - - solve(); - - } - - - -#ifndef ONLINE_JUDGE - - cerr << ""Time elapsed: "" << 1.0 * clock() / CLOCKS_PER_SEC << "" s.\n""; - -#endif - - return 0; - -}","#include - - - -using namespace std; - -#define lli long long int - - - -void solve(){ - - lli n, x, y; - - cin >> n >> x >> y; - - vector a1(n), a2(n); - - lli st = 1; - - for(int i = 0; i < n; i++){ - - a1[i] = st; - - st = 1-st; - - } - - st = 0; - - for(int i = 0; i < n; i++){ - - a2[i] = st; - - st = 1 -st; - - } - - if(n&1){ - - a1[n-1] = 2; - - a2[n-1] = 2; - - } - - bool yes1 = false, yes2 = false; - - if(((y-x) == 1) || ((y == n) && (n&1)) || ((y+x)&1)){ - - yes1 = true; - - goto label; - - } - - x--; y--; - - if(a1[x] == 1 && !((n&1) && (x == 0))){ - - a1[x] = 2; - - yes1 = true; - - } - - else if((a1[y] == 1) && !((n&1) && (y == (n-2)))){ - - a1[y] = 2; - - yes1 = true; - - } - - else if(a2[x] == 1 && !((n&1) && (x == 0))){ - - a2[x] = 2; - - yes2 = true; - - } - - else if((a2[y] == 1) && !((n&1) && (y == (n-2)))){ - - a2[y] = 2; - - yes2 = true; - - } - - label: - - if(yes1){ - - for(int i = 0; i < n; i++){ - - cout << a1[i] << "" ""; - - } - - cout << endl; - - } - - else{ - - for(int i = 0; i < n; i++){ - - cout << a2[i] << "" ""; - - } - - cout << endl; - - } - - - -} - - - -#define lli long long int - -int main(){ - - ios_base::sync_with_stdio(false); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - lli t; - - cin >> t; - - // t = 1; - - while(t--){ - - solve(); - - } - - - -#ifndef ONLINE_JUDGE - - cerr << ""Time elapsed: "" << 1.0 * clock() / CLOCKS_PER_SEC << "" s.\n""; - -#endif - - return 0; - -}",2 -killah9,2049C - MEX Cycle,c++17 ,308592167,308592031,"#include - -using namespace std; - - - -#define int long long - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - - - if (n == 3){ - - cout << 0 << "" "" << 1 << "" "" << 2; - - return; - - } - - if (n == 4){ - - if (abs(x - y) == 2){ - - for (int i = 1; i <= 4; i++){ - - if (i == x) cout << 0; - - else if (i == y) cout << 2; - - else cout << 1; - - cout << "" ""; - - } - - } - - else { - - cout << 0 << "" "" << 1 << "" "" << 0 << "" "" << 1; - - } - - return; - - } - - - - vector a(n+1, -1); - - - - queue q; - - q.push(x); - - - - while (!q.empty()){ - - int cur = q.front(); - - q.pop(); - - - - int prv = (cur == 1 ? n : cur-1); - - int nxt = (cur == n ? 1 : cur+1); - - - - int third = -1; - - if (cur == x) third = y; - - if (cur == y) third = x; - - - - int ans = 0; - - if (third == -1){ - - while (ans == a[prv] || ans == a[nxt]){ - - ans++; - - } - - } - - else { - - while (ans == a[prv] || ans == a[nxt] || ans == a[third]){ - - ans++; - - } - - } - - - - a[cur] = ans; - - if (a[prv] == -1) q.push(prv); - - if (a[nxt] == -1) q.push(nxt); - - if (third != -1 && a[third] == -1) q.push(third); - - } - - - - for (int i = 1; i <= n; i++) cout << a[i] << "" ""; - -} - - - -signed main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - int t = 1; - - cin >> t; - - while (t--){ - - solve(); - - cout << '\n'; - - } - -}","#include - -using namespace std; - - - -#define int long long - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - - - if (n == 3){ - - cout << 0 << "" "" << 1 << "" "" << 2; - - return; - - } - - if (n == 4){ - - if (abs(x - y) == 2){ - - for (int i = 1; i <= 4; i++){ - - if (i == x) cout << 0; - - else if (i == y) cout << 2; - - else cout << 1; - - cout << "" ""; - - } - - } - - else { - - for (int i = 1; i <= 4; i++){ - - if (i == x || i == y) cout << 0; - - else cout << 1; - - cout << "" ""; - - } - - } - - return; - - } - - - - vector a(n+1, -1); - - - - queue q; - - q.push(x); - - - - while (!q.empty()){ - - int cur = q.front(); - - q.pop(); - - - - int prv = (cur == 1 ? n : cur-1); - - int nxt = (cur == n ? 1 : cur+1); - - - - int third = -1; - - if (cur == x) third = y; - - if (cur == y) third = x; - - - - int ans = 0; - - if (third == -1){ - - while (ans == a[prv] || ans == a[nxt]){ - - ans++; - - } - - } - - else { - - while (ans == a[prv] || ans == a[nxt] || ans == a[third]){ - - ans++; - - } - - } - - - - a[cur] = ans; - - if (a[prv] == -1) q.push(prv); - - if (a[nxt] == -1) q.push(nxt); - - if (third != -1 && a[third] == -1) q.push(third); - - } - - - - for (int i = 1; i <= n; i++) cout << a[i] << "" ""; - -} - - - -signed main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - int t = 1; - - cin >> t; - - while (t--){ - - solve(); - - cout << '\n'; - - } - -}",1 -TLEphage#,2049C - MEX Cycle,c++20 ,307298165,307301728,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -#define int long long - - - -using namespace std; - - - -const int N = 1e6 + 100; - -const int MOD = 998244353; - -const int INF = 1e18 + 7; - - - -int gi() - -{ - - int s=0,f=1;char ch=getchar(); - - while(!(ch>='0'&&ch<='9')) f=(ch=='-'?-1:1),ch=getchar(); - - while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); - - return s*f; - -} - - - -int PRINT[333]; - -void print(int x) - -{ - - if(!x) - - { - - putchar('0'); - - return; - - } - - if(x<0) putchar('-'),x=-x; - - int ppp=0; - - while(x) PRINT[++ppp]=x%10,x/=10; - - for(int i=ppp;i>=1;--i) putchar(PRINT[i]+'0'); - -} - - - -int T; - -int n,m; - -int A[N],B[N]; - -char ch[N]; - - - -signed main() - -{ - - T=gi(); - - while(T--) - - { - - n=gi(); - - int x=gi(),y=gi(); - - if(n&1) - - { - - for(int i=1;i - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -#define int long long - - - -using namespace std; - - - -const int N = 1e6 + 100; - -const int MOD = 998244353; - -const int INF = 1e18 + 7; - - - -int gi() - -{ - - int s=0,f=1;char ch=getchar(); - - while(!(ch>='0'&&ch<='9')) f=(ch=='-'?-1:1),ch=getchar(); - - while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); - - return s*f; - -} - - - -int PRINT[333]; - -void print(int x) - -{ - - if(!x) - - { - - putchar('0'); - - return; - - } - - if(x<0) putchar('-'),x=-x; - - int ppp=0; - - while(x) PRINT[++ppp]=x%10,x/=10; - - for(int i=ppp;i>=1;--i) putchar(PRINT[i]+'0'); - -} - - - -int T; - -int n,m; - -int A[N],B[N]; - -char ch[N]; - - - -signed main() - -{ - - T=gi(); - - while(T--) - - { - - n=gi(); - - int x=gi(),y=gi(); - - if(n&1) - - { - - for(int i=1;i - -using namespace std; - -int arr[200005]; - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - if(n&1){ - - for(int i=2;i<=n;i+=2){ - - arr[i-1]=0; - - arr[i]=1; - - } - - arr[n]=2; - - if(arr[x]==0&&arr[y]==0){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - if(arr[x]==1&&arr[y]==1){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - }else{ - - for(int i=1;i<=n;i+=2){ - - arr[i-1]=0; - - arr[i]=1; - - } - - if(arr[x]==0&&arr[y]==0){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - if(arr[x]==1&&arr[y]==1){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - } - - for(int i = 1; i <= n; i ++) cout << arr[i] << "" ""; - - cout << ""\n""; - -} - - - -int main(){ - - int t; - - cin>>t; - - while(t--)solve(); - -}","#include - -using namespace std; - -int arr[200005]; - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - if(n&1){ - - for(int i=2;i<=n;i+=2){ - - arr[i-1]=0; - - arr[i]=1; - - } - - arr[n]=2; - - if(arr[x]==0&&arr[y]==0){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - if(arr[x]==1&&arr[y]==1){ - - if(x==n-1||x==1)swap(arr[x],arr[n]); - - else arr[x]=2; - - } - - }else{ - - for(int i=2;i<=n;i+=2){ - - arr[i-1]=0; - - arr[i]=1; - - } - - if(arr[x]==0&&arr[y]==0){ - - arr[x]=2; - - } - - if(arr[x]==1&&arr[y]==1){ - - arr[x]=2; - - } - - } - - for(int i = 1; i <= n; i ++) cout << arr[i] << "" ""; - - cout << ""\n""; - -} - - - -int main(){ - - int t; - - cin>>t; - - while(t--)solve(); - -}",2 -chandupaambepitiya,2049C - MEX Cycle,c++17 ,304504135,304503559,"#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - -int findMex(int a, int b, int c) { - - set s = {a, b, c}; // Store unique numbers - - - - for (int i = 0; ; i++) { // Check from 0 upwards - - if (s.find(i) == s.end()) return i; - - } - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -","#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - -int findMex(int a, int b, int c) { - - set s = {a, b, c}; // Store unique numbers - - - - for (int i = 0; ; i++) { // Check from 0 upwards - - if (s.find(i) == s.end()) return i; - - } - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -",1 -chandupaambepitiya,2049C - MEX Cycle,c++17 ,304504135,304502727,"#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - -int findMex(int a, int b, int c) { - - set s = {a, b, c}; // Store unique numbers - - - - for (int i = 0; ; i++) { // Check from 0 upwards - - if (s.find(i) == s.end()) return i; - - } - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -","#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -",1 -ziggy,2049C - MEX Cycle,other,304004012,304004238,"// https://codeforces.com/contest/2049/problem/C - - - -#[allow(unused_imports)] - -use alg::io::read; - - - -fn main() { - - for _ in 0..read() { - - solve(); - - } - -} - - - -fn solve() { - - input! { - - n: usize, - - x: usize, - - y: usize, - - } - - let a = ring(n, x, y); - - for i in 0..n { - - print!(""{} "", a[i]); - - } - - println!(); - -} - - - -fn ring(n: usize, x: usize, y: usize) -> Vec { - - let x = x - 1; - - let y = y - 1; - - assert!(x < y); - - let mut a = vec![3; n]; - - if x + 1 == y || (y + 1) % n == x { - - a[0] = n % 2 + 1; - - for i in 1..n { - - a[i] = (a[i - 1] + 1) % 2; - - } - - return a; - - } - - let l1 = y - x + 1; - - let l2 = x + n - y + 1; - - if n == 4 { - - a[(x + n - 1) % n] = 1; - - a[x] = 2; - - a[x + 1] = 1; - - a[y] = 0; - - } else { - - a[(x + n - 1) % n] = l2 % 2 + 1; - - a[x] = 0; - - a[x + 1] = l1 % 2 + 1; - - a[y] = 0; - - } - - for i in (x + 2)..y { - - a[i] = (a[i - 1] + 1) % 2; - - } - - for i in (y + 1)..(n + x - 1) { - - a[i % n] = (a[(i - 1) % n] + 1) % 2; - - } - - a - -} - - - -#[cfg(test)] - -mod tests { - - use super::*; - - - - fn mex(a: &[usize]) -> usize { - - for i in 0.. { - - if !a.iter().any(|&e| e == i) { - - return i; - - } - - } - - unreachable!() - - } - - - - fn check(n: usize, x: usize, y: usize) { - - let a = ring(n, x, y); - - let x = x - 1; - - let y = y - 1; - - for i in 0..n { - - let mut tmp = vec![a[(i + 1) % n], a[(i + n - 1) % n]]; - - if i == x { - - tmp.push(a[y]); - - } else if i == y { - - tmp.push(a[x]); - - } - - assert_eq!(a[i], mex(&tmp), ""{i} {a:?}""); - - } - - } - - - - #[test] - - fn test1() { - - check(4, 2, 4); - - check(4, 1, 4); - - } - - - - #[test] - - fn test2() { - - for n in 3..10 { - - for x in 1..n { - - for y in x + 1..=n { - - check(n, x, y); - - } - - } - - } - - } - -} - - - -mod alg { - -pub mod io { - -#[macro_export] - -macro_rules! input { - - (mut $var:ident: $kind:tt, $($rest:tt)*) => { - - let mut $var = $crate::_input_kind!($kind); - - input!($($rest)*) - - }; - - ($var:ident: $kind:tt, $($rest:tt)*) => { - - let $var = $crate::_input_kind!($kind); - - input!($($rest)*) - - }; - - (mut $var:ident: $kind:tt) => { let mut $var = $crate::_input_kind!($kind); }; - - ($var:ident: $kind:tt) => { let $var = $crate::_input_kind!($kind); }; - - () => {}; - -} - - - -#[doc(hidden)] - -#[macro_export] - -macro_rules! _input_kind { - - ([$t:tt; $n:expr]) => { - - (0..$n).map(|_| $crate::_input_kind!($t)).collect::>() - - }; - - ([$t:tt]) => {{ - - let n = $crate::_input_kind!(usize); - - (0..n).map(|_| $crate::_input_kind!($t)).collect::>() - - }}; - - (($a:tt, $b:tt)) => {{ - - let a = $crate::_input_kind!($a); - - let b = $crate::_input_kind!($b); - - (a, b) - - }}; - - (bytes) => { - - $crate::_input_kind!(String).into_bytes() - - }; - - (usize1) => { - - $crate::_input_kind!(usize) - 1 - - }; - - ($t:ty) => { - - $crate::alg::io::read::<$t>() - - }; - -} - - - -pub fn read() -> T - -where - - T: std::str::FromStr, - - T::Err: std::fmt::Debug, - -{ - - use std::cell::RefCell; - - use std::io::{stdin, BufRead, StdinLock}; - - thread_local! { - - pub static STDIN: RefCell> = RefCell::new(stdin().lock()); - - } - - STDIN.with(|r| { - - let mut r = r.borrow_mut(); - - let mut s = vec![]; - - loop { - - let buf = r.fill_buf().unwrap(); - - if buf.is_empty() { - - break; - - } - - if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) { - - s.extend_from_slice(&buf[..i]); - - r.consume(i + 1); - - if !s.is_empty() { - - break; - - } - - } else { - - s.extend_from_slice(buf); - - let n = buf.len(); - - r.consume(n); - - } - - } - - std::str::from_utf8(&s).unwrap().parse().unwrap() - - }) - -} - - - -#[macro_export] - -macro_rules! println { - - ($($arg:tt)*) => { - - $crate::alg::io::_with_stdout(|w| { - - use std::io::Write; - - std::writeln!(w, $($arg)*).unwrap() - - }) - - }; - - } - - - -#[macro_export] - -macro_rules! print { - - ($($arg:tt)*) => { - - $crate::alg::io::_with_stdout(|w| { - - use std::io::Write; - - std::write!(w, $($arg)*).unwrap() - - }) - - }; - - } - - - -#[doc(hidden)] - -pub fn _with_stdout(f: F) - -where - - F: FnOnce(&mut std::io::BufWriter), - -{ - - use std::cell::RefCell; - - use std::io::{stdout, BufWriter, StdoutLock}; - - thread_local! { - - pub static STDOUT: RefCell>> = - - RefCell::new(BufWriter::new(stdout().lock())); - - } - - STDOUT.with(|w| f(&mut w.borrow_mut())) - -} - -} - -} - -","// https://codeforces.com/contest/2049/problem/C - - - -#[allow(unused_imports)] - -use alg::io::read; - - - -fn main() { - - for _ in 0..read() { - - solve(); - - } - -} - - - -fn solve() { - - input! { - - n: usize, - - x: usize, - - y: usize, - - } - - let a = ring(n, x, y); - - for i in 0..n { - - print!(""{} "", a[i]); - - } - - println!(); - -} - - - -fn ring(n: usize, x: usize, y: usize) -> Vec { - - let x = x - 1; - - let y = y - 1; - - assert!(x < y); - - let mut a = vec![3; n]; - - if x + 1 == y || (y + 1) % n == x { - - a[0] = n % 2 + 1; - - for i in 1..n { - - a[i] = (a[i - 1] + 1) % 2; - - } - - return a; - - } - - let l1 = y - x + 1; - - let l2 = x + n - y + 1; - - if n == 4 { - - a[(x + n - 1) % n] = 1; - - a[x] = 2; - - a[x + 1] = 1; - - a[y] = 0; - - } else { - - a[(x + n - 1) % n] = l2 % 2 + 1; - - a[x] = 0; - - a[x + 1] = l1 % 2 + 1; - - a[y] = 1; - - } - - for i in (x + 2)..y { - - a[i] = (a[i - 1] + 1) % 2; - - } - - for i in (y + 1)..(n + x - 1) { - - a[i % n] = (a[(i - 1) % n] + 1) % 2; - - } - - a - -} - - - -#[cfg(test)] - -mod tests { - - use super::*; - - - - fn mex(a: &[usize]) -> usize { - - for i in 0.. { - - if !a.iter().any(|&e| e == i) { - - return i; - - } - - } - - unreachable!() - - } - - - - fn check(n: usize, x: usize, y: usize) { - - let a = ring(n, x, y); - - let x = x - 1; - - let y = y - 1; - - for i in 0..n { - - let mut tmp = vec![a[(i + 1) % n], a[(i + n - 1) % n]]; - - if i == x { - - tmp.push(a[y]); - - } else if i == y { - - tmp.push(a[x]); - - } - - assert_eq!(a[i], mex(&tmp), ""{i} {a:?}""); - - } - - } - - - - #[test] - - fn test1() { - - check(5, 1, 3); - - check(4, 2, 4); - - } - - - - #[test] - - fn test2() { - - for n in 3..10 { - - for x in 1..n { - - for y in x + 1..=n { - - check(n, x, y); - - } - - } - - } - - } - -} - - - -mod alg { - -pub mod io { - -#[macro_export] - -macro_rules! input { - - (mut $var:ident: $kind:tt, $($rest:tt)*) => { - - let mut $var = $crate::_input_kind!($kind); - - input!($($rest)*) - - }; - - ($var:ident: $kind:tt, $($rest:tt)*) => { - - let $var = $crate::_input_kind!($kind); - - input!($($rest)*) - - }; - - (mut $var:ident: $kind:tt) => { let mut $var = $crate::_input_kind!($kind); }; - - ($var:ident: $kind:tt) => { let $var = $crate::_input_kind!($kind); }; - - () => {}; - -} - - - -#[doc(hidden)] - -#[macro_export] - -macro_rules! _input_kind { - - ([$t:tt; $n:expr]) => { - - (0..$n).map(|_| $crate::_input_kind!($t)).collect::>() - - }; - - ([$t:tt]) => {{ - - let n = $crate::_input_kind!(usize); - - (0..n).map(|_| $crate::_input_kind!($t)).collect::>() - - }}; - - (($a:tt, $b:tt)) => {{ - - let a = $crate::_input_kind!($a); - - let b = $crate::_input_kind!($b); - - (a, b) - - }}; - - (bytes) => { - - $crate::_input_kind!(String).into_bytes() - - }; - - (usize1) => { - - $crate::_input_kind!(usize) - 1 - - }; - - ($t:ty) => { - - $crate::alg::io::read::<$t>() - - }; - -} - - - -pub fn read() -> T - -where - - T: std::str::FromStr, - - T::Err: std::fmt::Debug, - -{ - - use std::cell::RefCell; - - use std::io::{stdin, BufRead, StdinLock}; - - thread_local! { - - pub static STDIN: RefCell> = RefCell::new(stdin().lock()); - - } - - STDIN.with(|r| { - - let mut r = r.borrow_mut(); - - let mut s = vec![]; - - loop { - - let buf = r.fill_buf().unwrap(); - - if buf.is_empty() { - - break; - - } - - if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) { - - s.extend_from_slice(&buf[..i]); - - r.consume(i + 1); - - if !s.is_empty() { - - break; - - } - - } else { - - s.extend_from_slice(buf); - - let n = buf.len(); - - r.consume(n); - - } - - } - - std::str::from_utf8(&s).unwrap().parse().unwrap() - - }) - -} - - - -#[macro_export] - -macro_rules! println { - - ($($arg:tt)*) => { - - $crate::alg::io::_with_stdout(|w| { - - use std::io::Write; - - std::writeln!(w, $($arg)*).unwrap() - - }) - - }; - - } - - - -#[macro_export] - -macro_rules! print { - - ($($arg:tt)*) => { - - $crate::alg::io::_with_stdout(|w| { - - use std::io::Write; - - std::write!(w, $($arg)*).unwrap() - - }) - - }; - - } - - - -#[doc(hidden)] - -pub fn _with_stdout(f: F) - -where - - F: FnOnce(&mut std::io::BufWriter), - -{ - - use std::cell::RefCell; - - use std::io::{stdout, BufWriter, StdoutLock}; - - thread_local! { - - pub static STDOUT: RefCell>> = - - RefCell::new(BufWriter::new(stdout().lock())); - - } - - STDOUT.with(|w| f(&mut w.borrow_mut())) - -} - -} - -} - -",2 -AustinWang#,2049C - MEX Cycle,c++20 ,304782853,304782763,"#include - -using namespace std; - -const int N=505; - -int t,n,x,y; - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - if (n%2==1){ - - for (int i=1;i<=n-1;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}","#include - -using namespace std; - -const int N=505; - -int t,n,x,y; - -int cha(int a,int b){ - - if (a>b) swap(a,b); - - return min(b-a,a+n-b); - -} - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - if (n%2==1){ - - for (int i=1;i<=n-1;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}",1 -PanzerCrowd#,2049C - MEX Cycle,c++20 ,306266732,306267206,"#include - -using namespace std; - -using ll = long long; - - - - - - - -void solve() { - - int n, x, y; - - cin>>n>>x>>y; - - - - vector> adj(n+1); - - for(int i=1; i<=n; i++){ - - int a = i+1>n?1:i+1; - - adj[i].push_back(a); - - - - int b = i-1<1?5:i-1; - - adj[i].push_back(b); - - - - if(i==x) adj[i].push_back(y); - - else if(i == y) adj[i].push_back(x); - - - - } - - - - vector visited(n+1, -1); - - - - queue q; - - q.push(1); - - visited[1] = 0; - - - - bool m = false; - - while(!q.empty()){ - - int node = q.front(); - - q.pop(); - - - - m = !m; - - for(auto nnode: adj[node]){ - - if(visited[nnode] == -1) { - - visited[nnode] = m; - - q.push(nnode); - - } - - - - } - - } - - - - - - for(int i=1; i<=n; i++){ - - bool found2 = false; - - bool same = false; - - for(auto nnode: adj[i]){ - - if(visited[i] == visited[nnode]) same = true; - - else if(visited[nnode] == 2) found2 = true; - - } - - - - if(!found2 and same) visited[i] = 2; - - - - cout<> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -} - -","#include - -using namespace std; - -using ll = long long; - - - - - - - -void solve() { - - int n, x, y; - - cin>>n>>x>>y; - - - - vector> adj(n+1); - - for(int i=1; i<=n; i++){ - - int a = i+1>n?1:i+1; - - adj[i].push_back(a); - - - - int b = i-1<1?5:i-1; - - adj[i].push_back(b); - - - - if(i==x) adj[i].push_back(y); - - else if(i == y) adj[i].push_back(x); - - - - } - - - - vector visited(n+1, -1); - - - - queue q; - - q.push(1); - - visited[1] = 0; - - - - bool m = false; - - while(!q.empty()){ - - - - int t = q.size(); - - - - m = !m; - - while(t--){ - - int node = q.front(); - - q.pop(); - - - - - - for(auto nnode: adj[node]){ - - if(visited[nnode] == -1) { - - visited[nnode] = m; - - q.push(nnode); - - } - - - - } - - } - - } - - - - - - for(int i=1; i<=n; i++){ - - bool found2 = false; - - bool same = false; - - for(auto nnode: adj[i]){ - - if(visited[i] == visited[nnode]) same = true; - - else if(visited[nnode] == 2) found2 = true; - - } - - - - if(!found2 and same) visited[i] = 2; - - - - cout<> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -} - -",2 -DeathPrince,2049C - MEX Cycle,c++17 ,307316002,307292661,"#include - -#include - -#include - - - -using namespace std; - - - -int main() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - - - int t; - - cin >> t; - - - - while(t--) { - - int n, x, y; - - cin >> n >> x >> y; - - --x; - - --y; - - std::vector a(2 * n, 0); - - - - int value = 0; - - for (int i = x; i < x + n; ++i) { - - a[i] = value; - - value = (value + 1) % 2; - - } - - - - if (n % 2 == 1 || (y - x) % 2 == 0) { - - a[x] = 2; - - } - - - - std::vector result(n); - - for (int i = x; i < x + n; ++i) { - - result[i % n] = a[i]; - - } - - - - for (int i = 0; i < n; ++i) { - - cout << result[i] << "" ""; - - } - - cout << ""\n""; - - } - -}","#include - -#include - -#include - - - -using namespace std; - - - -int main() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - - - int t; - - cin >> t; - - - - while(t--) { - - int n, x, y; - - cin >> n >> x >> y; - - --x; - - --y; - - std::vector a(2 * n, 0); - - - - int value = 0; - - for (int i = x; i < x + n; ++i) { - - if (i == y && (i - x) % 3 == 0) { - - value++; - - a[i - 1] = 0; - - } - - a[i] = value; - - value = (value + 1) % 3; - - } - - - - if (a[x + n - 1] == 0) { - - a[x + n - 1] = 1; - - if (a[x + n - 2] == 2) { - - a[x + n - 2] = 0; - - } - - } - - - - std::vector result(n); - - for (int i = x; i < x + n; ++i) { - - result[i % n] = a[i]; - - } - - - - for (int i = 0; i < n; ++i) { - - cout << result[i] << "" ""; - - } - - cout << ""\n""; - - } - -}",1 -yassinearfaoui131,2049C - MEX Cycle,python,305920981,305916494,"for _ in range(int(input())): - - n,x,y=map(int,input().split()) - - t=[0]*n - - x=x-1 - - y=y-1 - - x1=min(x,y) - - x2=max(x,y) - - cluster1=x2-x1-1 - - cluster2=n-(x2-x1-1) - - pos1=-1 - - pos2=-1 - - if cluster1%2==1 : - - pos1=(x2+x1)//2 - - if cluster2%2==1: - - pos2=((x1+x2+n)//2)%n - - hattan=0 - - for i in range(n): - - if i!=pos1 and i!=pos2: - - t[i]=str(hattan) - - hattan=(hattan+1)%2 - - else: - - t[i]=""2"" - - print("" "".join(t))"," - -for _ in range(int(input())): - - n,x,y=map(int,input().split()) - - t=[0]*n - - x1=min(x,y) - - x2=max(x,y) - - cluster1=x2-x1-1 - - cluster2=n-(x2-x1-1) - - pos1=-1 - - pos2=-1 - - if cluster1%2==1 : - - pos1=(x2+x1)//2 - - if cluster2%2==1: - - pos2=((x1+x2+n)//2)%n - - hattan=0 - - for i in range(n): - - if i!=pos1 and i!=pos2: - - t[i]=str(hattan) - - hattan=(hattan+1)%2 - - else: - - t[i]=""2"" - - print("" "".join(t)) - - - - - -",1 -mohamedhesham,2049C - MEX Cycle,c++20 ,303719307,303719150,"// بسم الله الرحمن الرحيم - - - -#include - -//#include - -//#include - -#define Hesham ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -//#define ordered_set tree,rb_tree_tag,tree_order_statistics_node_update> - -#define fll(i,a,b) for(long long i=a;i=b;i--) - -#define f(b,a) cout << fixed << setprecision(b) << a << endl; - -#define rall(x) x.rbegin(),x.rend() - -#define MOD 1000000007 - -#define sub_mod(a,b,m) ((((a)%m)-((b)%m)+m)%m) - -#define add_mod(a,b,m) ((((a)%m)+((b)%m))%m) - -#define mult_mod(a,b,m) ((((a)%m)*((b)%m))%m) - -#define pi 3.14159265358979323846 - -#define all(x) x.begin(),x.end() - -#define ull unsigned long long - -#define ld long double - -#define ll long long - -#define sz(s) s.size() - -#define yes cout << ""YES"" << nl - -#define no cout << ""NO"" << nl - -#define F first - -#define S second - -#define nl '\n' - - - -using namespace std; - -//using namespace __gnu_pbds; - -const int m=998244353; - -const int maxn=200000; - -vectorfact(maxn,1),inv(maxn,1); - -vectorsieve(20+1,1); - -vectorspf(20); - - - -ll dx[] = {0, -1, 1, 0}; - -ll dy[] = {1, 0, 0, -1}; - - - -bool isPrime(ll n) - -{ - - if(n==1||(n%2==0&&n!=2)) return false; - - for(ll j=2;j*j<=n;j++) - - { - - if(n%j==0) - - { - - return false; - - } - - } - - return true; - -} - - - -void sev() - -{ - - for(ll i=2;i*i<=maxn;i++) - - { - - if(sieve[i]) - - { - - for(ll j=i*i;j<=maxn;j+=i) - - { - - sieve[j]=0; - - } - - } - - } - - sieve[1]=0,sieve[0]=0; - -} - - - -void smallestpf() - -{ - - spf[1]=1; - - fll(i,2,maxn) spf[i]=i; - - for(ll i=4;igetf(ll n) - -{ - - vectorret; - - while(n!=1) - - { - - ret.push_back(spf[n]); - - n=n/spf[n]; - - } - - return ret; - -} - - - -bool comp(pairp1,pairp2) - -{ - - return p1.S0) - - { - - if(n%2!=0) res=(res%m*x%m)%m,n--; - - else x=(x%m*x%m)%m,n/=2; - - } - - return res; - -} - - - -vectorpresum(vector &v) - -{ - - vectorp(v.size()); - - fll(i,0,v.size()) - - { - - if(i==0) p[i]=v[i]; - - else p[i]=v[i]+p[i-1]; - - } - - return p; - -} - - - -vectorprimefactor(ll n) - -{ - - ll cn=0; vectorv; - - while(n%2==0) - - { - - v.push_back(2); n/=2; - - } - - for(ll j=3;j*j<=n;j+=2) - - { - - while(n%j==0) - - { - - v.push_back(j); - - n/=j; - - } - - } - - if(n>2) v.push_back(n); - - - - return v; - -} - - - -vectordivisors(ll n) - -{ - - vectorc; - - for(ll i=1;i*i<=n;i++) - - { - - if(n%i==0) - - { - - c.push_back(i); - - if(n/i!=i) c.push_back(n/i); - - } - - } - - return c; - -} - - - -ll lcm(ll a,ll b) - -{ - - ll k=(a*b)/__gcd(a,b); - - return k; - -} - - - -ll arteq(ll l,ll r,ll p) - -{ - - ll k=((r-l)/p)+1; - - ll h=k*(l*2+(k-1)*p); h/=2; - - return h; - -} - - - -ll binpow(ll a,ll b,ll p=m) - -{ - - ll res=1; - - while(b>0) - - { - - if(b&1) res*=a,res%=p; - - a*=a,a%=p; - - b>>=1; - - } - - return res; - -} - - - -void solve() - -{ - - ll n,x,y,cn=0; cin >> n >> x >> y; x--,y--; vectorv(n); - - fll(i,0,n) - - { - - if(i==n-1) v[i]=2; - - else v[i]=i%2; - - } - - if(v[x]==v[y]) v[y]=2; - - fll(i,0,n) - - { - - ll a=i-1,b=i+1; - - if(b==n) b=0; - - if(a==-1) a=n-1; - - ll mn,mx,c=0; vectorcx; - - if(i==x) cx={v[a],v[b],v[y]}; - - else if(i==y) cx={v[a],v[b],v[x]}; - - else cx={v[a],v[b]}; - - sort(all(cx)); - - fll(j,0,sz(cx)) if(c==cx[j]) c++; - - v[i]=c; - - } - - fll(i,0,n) - - { - - ll a=i-1,b=i+1; - - if(b==n) b=0; - - if(a==-1) a=n-1; - - ll mn,mx,c=0; vectorcx; - - if(i==x) cx={v[a],v[b],v[y]}; - - else if(i==y) cx={v[a],v[b],v[x]}; - - else cx={v[a],v[b]}; - - sort(all(cx)); - - fll(j,0,sz(cx)) if(c==cx[j]) c++; - - v[i]=c; - - } - - fll(i,0,n) cout << v[i] << "" ""; cout << nl; - - - -} - - - -int main() - -{ - - Hesham; - - // freopen(""army.in"",""r"",stdin); - - // freopen(""output.out"",""w"",stdout); - - ll t=1; - - cin >> t; - - while(t--) solve(); - - - - return 0; - -}","// بسم الله الرحمن الرحيم - - - -#include - -//#include - -//#include - -#define Hesham ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -//#define ordered_set tree,rb_tree_tag,tree_order_statistics_node_update> - -#define fll(i,a,b) for(long long i=a;i=b;i--) - -#define f(b,a) cout << fixed << setprecision(b) << a << endl; - -#define rall(x) x.rbegin(),x.rend() - -#define MOD 1000000007 - -#define sub_mod(a,b,m) ((((a)%m)-((b)%m)+m)%m) - -#define add_mod(a,b,m) ((((a)%m)+((b)%m))%m) - -#define mult_mod(a,b,m) ((((a)%m)*((b)%m))%m) - -#define pi 3.14159265358979323846 - -#define all(x) x.begin(),x.end() - -#define ull unsigned long long - -#define ld long double - -#define ll long long - -#define sz(s) s.size() - -#define yes cout << ""YES"" << nl - -#define no cout << ""NO"" << nl - -#define F first - -#define S second - -#define nl '\n' - - - -using namespace std; - -//using namespace __gnu_pbds; - -const int m=998244353; - -const int maxn=200000; - -vectorfact(maxn,1),inv(maxn,1); - -vectorsieve(20+1,1); - -vectorspf(20); - - - -ll dx[] = {0, -1, 1, 0}; - -ll dy[] = {1, 0, 0, -1}; - - - -bool isPrime(ll n) - -{ - - if(n==1||(n%2==0&&n!=2)) return false; - - for(ll j=2;j*j<=n;j++) - - { - - if(n%j==0) - - { - - return false; - - } - - } - - return true; - -} - - - -void sev() - -{ - - for(ll i=2;i*i<=maxn;i++) - - { - - if(sieve[i]) - - { - - for(ll j=i*i;j<=maxn;j+=i) - - { - - sieve[j]=0; - - } - - } - - } - - sieve[1]=0,sieve[0]=0; - -} - - - -void smallestpf() - -{ - - spf[1]=1; - - fll(i,2,maxn) spf[i]=i; - - for(ll i=4;igetf(ll n) - -{ - - vectorret; - - while(n!=1) - - { - - ret.push_back(spf[n]); - - n=n/spf[n]; - - } - - return ret; - -} - - - -bool comp(pairp1,pairp2) - -{ - - return p1.S0) - - { - - if(n%2!=0) res=(res%m*x%m)%m,n--; - - else x=(x%m*x%m)%m,n/=2; - - } - - return res; - -} - - - -vectorpresum(vector &v) - -{ - - vectorp(v.size()); - - fll(i,0,v.size()) - - { - - if(i==0) p[i]=v[i]; - - else p[i]=v[i]+p[i-1]; - - } - - return p; - -} - - - -vectorprimefactor(ll n) - -{ - - ll cn=0; vectorv; - - while(n%2==0) - - { - - v.push_back(2); n/=2; - - } - - for(ll j=3;j*j<=n;j+=2) - - { - - while(n%j==0) - - { - - v.push_back(j); - - n/=j; - - } - - } - - if(n>2) v.push_back(n); - - - - return v; - -} - - - -vectordivisors(ll n) - -{ - - vectorc; - - for(ll i=1;i*i<=n;i++) - - { - - if(n%i==0) - - { - - c.push_back(i); - - if(n/i!=i) c.push_back(n/i); - - } - - } - - return c; - -} - - - -ll lcm(ll a,ll b) - -{ - - ll k=(a*b)/__gcd(a,b); - - return k; - -} - - - -ll arteq(ll l,ll r,ll p) - -{ - - ll k=((r-l)/p)+1; - - ll h=k*(l*2+(k-1)*p); h/=2; - - return h; - -} - - - -ll binpow(ll a,ll b,ll p=m) - -{ - - ll res=1; - - while(b>0) - - { - - if(b&1) res*=a,res%=p; - - a*=a,a%=p; - - b>>=1; - - } - - return res; - -} - - - -void solve() - -{ - - ll n,x,y,cn=0; cin >> n >> x >> y; x--,y--; vectorv(n); - - fll(i,0,n) - - { - - if(i==n-1) v[i]=2; - - else v[i]=i%2; - - } - - if(v[x]==v[y]) v[y]=2; - - fll(i,0,n) - - { - - ll a=i-1,b=i+1; - - if(b==n) b=0; - - if(a==-1) a=n-1; - - ll mn,mx,c=0; vectorcx; - - if(i==x) cx={v[a],v[b],v[y]}; - - else if(i==y) cx={v[a],v[b],v[x]}; - - else cx={v[a],v[b]}; - - sort(all(cx)); - - fll(j,0,sz(cx)) if(c==cx[j]) c++; - - v[i]=c; - - } - - fll(i,0,n) cout << v[i] << "" ""; cout << nl; - - - -} - - - -int main() - -{ - - Hesham; - - // freopen(""army.in"",""r"",stdin); - - // freopen(""output.out"",""w"",stdout); - - ll t=1; - - cin >> t; - - while(t--) solve(); - - - - return 0; - -}",1 -PraveenK_2024,2049C - MEX Cycle,c++20 ,304410487,304411620,"#include - -using namespace std; - - - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - x--; y--; - - - - vector a(n, -1); - - a[x] = 0, a[y] = 1; - - - - for (int i = (x + 1) % n; i != y; i = (i + 1) % n) { - - a[i] = (i - x + n) % 2; - - } - - for (int i = (x - 1 + n) % n; i != y; i = (i - 1 + n) % n) { - - a[i] = (x - i + n) % 2; - - } - - - - for (int i = 0; i < n; i++) - - cout << a[i] << "" \n""[i == n - 1]; - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) solve(); - - - - return 0; - -} - -","#include - -using namespace std; - - - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - x--; y--; - - - - vector a(n); - - a[x] = 0; - - a[y] = 1; - - for (int i = x; i != y; i = (i + 1) % n) { - - a[i] = (i - x + n) % n % 2; - - if ((i + 1) % n == y && a[i] == 1) { - - a[i] = 2; - - } - - } - - for (int i = x; i != y; i = (i - 1 + n) % n) { - - a[i] = (x - i + n) % n % 2; - - if ((i - 1 + n) % n == y && a[i] == 1) { - - a[i] = 2; - - } - - } - - for (int i = 0; i < n; i++) { - - cout << a[i] << "" \n""[i == n - 1]; - - } - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) solve(); - - - - return 0; - -} - -",2 -Hi_Hi_Hi,2049C - MEX Cycle,c++20 ,306882101,306881014,"#include - - - -using namespace std; - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t;cin>>t; - - while(t--) - - { - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - for(int i=x;i - - - -using namespace std; - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t;cin>>t; - - while(t--) - - { - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - for(int i=0;i - -using namespace std; - -const int N=505; - -int t,n,x,y; - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - if (n%2==1){ - - for (int i=1;i<=n-1;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}","#include - -using namespace std; - -const int N=505; - -int t,n,x,y; - -int cha(int a,int b){ - - if (a>b) swap(a,b); - - return min(b-a,a+n-b); - -} - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - for (int i=1;i<=n;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}",1 -WintersBlizzard,2049C - MEX Cycle,c++17 ,304918825,304918597,"#include - -// g++-14 -o main [file].cpp; - -//./main < input.txt > output.txt - -using namespace std; - - - -#pragma region - -#define ll long long - -template - -void print(T v[], int n, int i = 0){ - - for(; i < n; ++i){ - - cout << v[i] << "" ""; - - } - - cout << endl; - -} - -template - -void print(vector v){ - - for(int i =0 ; i < v.size(); ++i){ - - cout << v[i] << "" ""; - - } - - cout << endl; - -} - -ll inv_mod_prime(ll a, ll MOD) { - - return a <= 1 ? a : MOD - (MOD/a) * inv_mod_prime(MOD % a, MOD) % MOD; - -} - -// count number of bits - -// only for int64 and int32 - -//__builtin_popcount - - - -// bool is_prime[4'00'001]; - -// void sieve(int n){ - -// memset(is_prime, true, sizeof(is_prime)); - -// is_prime[0] = is_prime[1] = false; - -// for(int i = 4; i <= n; i += 2){ - -// is_prime[i] = false; - -// } - -// for(int i = 9; i <= n; i += 6){ - -// is_prime[i] = false; - -// } - -// for(int i = 15; i <= n; i += 10){ - -// is_prime[i] = false; - -// } - -// int num = 7; - -// while(num <= n){ - -// if(is_prime[num]){ - -// for(int i = num+num; i <= n; i += num){ - -// is_prime[i] = false; - -// } - -// } - -// num += 2; - -// } - -// } - -#pragma endregion - - - - - -int a[2'00'001]; - -int n, x, y; - - - -int convert_ind(int i){ - - if(i == 0) return n; - - if(i == n+1) return 1; - - return i; - - - -} - - - -void solve(){ - - cin >> n >> x >> y; - - int start = x; - - int diff = y-x; - - int rev_diff = n-diff; - - - - int val = 0; - - for(int i = x; i <= y; i++){ - - a[i] = val; - - val ^= 1; - - } - - if(diff%2 == 0){ - - a[convert_ind(y-1)] = 2; - - a[y] = 1; - - } - - int ind = x; - - val = 0; - - while(ind != y){ - - a[ind] = val; - - val ^= 1; - - ind--; - - ind = convert_ind(ind); - - } - - if(rev_diff%2 == 0){ - - a[convert_ind(y+1)] = 2; - - a[y] = 1; - - } - - - - for(int i = 1; i <= n; i++){ - - cout << a[i] << "" ""; - - } - - cout << endl; - - - - - - - - - - - - - - - - - - - - - - - - - -} - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; - - cin >> t; - - while(t--){ - - - - solve(); - - } - - return 0; - -}","#include - -// g++-14 -o main [file].cpp; - -//./main < input.txt > output.txt - -using namespace std; - - - -#pragma region - -#define ll long long - -template - -void print(T v[], int n, int i = 0){ - - for(; i < n; ++i){ - - cout << v[i] << "" ""; - - } - - cout << endl; - -} - -template - -void print(vector v){ - - for(int i =0 ; i < v.size(); ++i){ - - cout << v[i] << "" ""; - - } - - cout << endl; - -} - -ll inv_mod_prime(ll a, ll MOD) { - - return a <= 1 ? a : MOD - (MOD/a) * inv_mod_prime(MOD % a, MOD) % MOD; - -} - -// count number of bits - -// only for int64 and int32 - -//__builtin_popcount - - - -// bool is_prime[4'00'001]; - -// void sieve(int n){ - -// memset(is_prime, true, sizeof(is_prime)); - -// is_prime[0] = is_prime[1] = false; - -// for(int i = 4; i <= n; i += 2){ - -// is_prime[i] = false; - -// } - -// for(int i = 9; i <= n; i += 6){ - -// is_prime[i] = false; - -// } - -// for(int i = 15; i <= n; i += 10){ - -// is_prime[i] = false; - -// } - -// int num = 7; - -// while(num <= n){ - -// if(is_prime[num]){ - -// for(int i = num+num; i <= n; i += num){ - -// is_prime[i] = false; - -// } - -// } - -// num += 2; - -// } - -// } - -#pragma endregion - - - - - -int a[2'00'001]; - -int n, x, y; - - - -int convert_ind(int i){ - - if(i == 0) return n; - - if(i == n+1) return 1; - - return i; - - - -} - - - -void solve(){ - - cin >> n >> x >> y; - - int start = x; - - int diff = y-x; - - int rev_diff = n-diff; - - - - int val = 0; - - for(int i = x; i < y; i++){ - - a[i] = val; - - val ^= 1; - - } - - if(diff%2 == 0){ - - a[convert_ind(y-1)] = 2; - - a[y] = 1; - - } - - int ind = x; - - val = 0; - - while(ind != y){ - - a[ind] = val; - - val ^= 1; - - ind--; - - ind = convert_ind(ind); - - } - - if(rev_diff%2 == 0){ - - a[convert_ind(y+1)] = 2; - - a[y] = 1; - - } - - - - for(int i = 1; i <= n; i++){ - - cout << a[i] << "" ""; - - } - - cout << endl; - - - - - - - - - - - - - - - - - - - - - - - - - -} - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; - - cin >> t; - - while(t--){ - - - - solve(); - - } - - return 0; - -}",1 -anshu_kumar_123,2049C - MEX Cycle,c++17 ,304038724,304039626," #include - -#define ll long long int - -using namespace std; - -int main(){ - - ll t; - - cin>>t; - - while(t--){ - - ll n,x,y; - - cin>>n>>x>>y; - - vectorv(n,0); - - for(int i=0;i<=n-1;i++){ - - if(i%2!=0) v[i]=1; - - } - - if(n%2==0 || (y-x)%2==0) v[x]=2; - - for(int i=0;i<=n-1;i++) cout< - -#define ll long long int - -using namespace std; - -int main(){ - - ll t; - - cin>>t; - - while(t--){ - - ll n,x,y; - - cin>>n>>x>>y; - - vectorv(n,0); - - --x; - - --y; - - for(int i=0;i<=n-1;i++){ - - v[(x+i)%n] = i%2; - - } - - if(n%2 || (y-x) % 2==0) v[x]=2; - - for(int i=0;i<=n-1;i++) cout< - - - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define pii pair - -#define vpii vector> - -#define pb push_back - -#define f first - -#define s second - - - -const ll MOD = 1e9+7; - - - -ll gcd(ll a, ll b) { - - if (a == 0) return b; - - return gcd(b % a, a); - -} - - - - - -ll pow(ll x, ll n) { - - if (n == 0) return 1; - - if (n % 2 == 0) return pow((x * x) % MOD, n / 2); - - return (x * pow((x * x) % MOD, (n - 1) / 2) % MOD); - -} - - - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - - - int p[n+2]={0}; - - if(x == y -1 || (x==1 && y==n)) { - - for(int i=1; i<=n-1; i++) p[i]=(i%2); - - if(n%2) p[n]=2; - - } - - else { - - // x --> y ==> (y-x-1) - - // both side even => 0 - 1 => 1 0 1 0 - - // else => odd side => 1 0 1 1 0 10 0 - - int curr = 1; - - p[x]=0; - - p[y]=2; - - for(int i=x+1; iy - - for(int i=x-1; i>=1; i--) p[i] = p[i+1]^1; // 1 -> x-1 - - for(int i=n; i>y; i--) p[i] = p[(i+1)%n ==0 ? n : (i+1)%n]^1;// y+1 -> n - - - - if((y-x -1 )%2 == 0 && (n-y+x-1)%2 == 0) p[y]=1; - - } - - for(int i=1; i<=n; i++) cout<>t; - - - - for(int i=01;i<=t;i++) { - - // cout<<""Case #""< - - - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define pii pair - -#define vpii vector> - -#define pb push_back - -#define f first - -#define s second - - - -const ll MOD = 1e9+7; - - - -ll gcd(ll a, ll b) { - - if (a == 0) return b; - - return gcd(b % a, a); - -} - - - - - -ll pow(ll x, ll n) { - - if (n == 0) return 1; - - if (n % 2 == 0) return pow((x * x) % MOD, n / 2); - - return (x * pow((x * x) % MOD, (n - 1) / 2) % MOD); - -} - - - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - - - if(x == y -1 || (x==1 && y==n)) { - - int dem = 2 + n%2; - - for(int i=0; i y ==> (y-x-1) - - // both side even => 0 - 1 => 1 0 1 0 - - // else => odd side => 1 0 1 1 0 10 0 - - int p[n+2]={0}; - - int curr = 1; - - p[x]=0; - - p[y]=2; - - for(int i=x+1; iy - - for(int i=x-1; i>=1; i--) p[i] = p[i+1]^1; // 1 -> x-1 - - for(int i=n; i>y; i--) p[i] = p[(i+1)%n ==0 ? n : (i+1)%n]^1;// y+1 -> n - - - - if((y-x -1 )%2 == 0 && (n-y+x-1)%2 == 0) p[y]=1; - - for(int i=1; i<=n; i++) cout<>t; - - - - for(int i=01;i<=t;i++) { - - // cout<<""Case #""< - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - - - -using namespace std; - -#define NDEBUG - -#define endl ""\n"" - -#define ff first - -#define ss second - -#define vi vector - -#define pii pair - -#define sz(x) (int)x.size() - -//#define int long long - -constexpr int MAX_N = 100'005; - -constexpr int INF = 1E9; - - - - - -int32_t main() { - - // ifstream cin(""MEXcycle.txt""); - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - int t; cin>>t; - - - - while(t--) { - - int n, x, y; - - cin>>n>>x>>y; - - --x, --y; - - - - vector ans(n); - - - - for (int i = 0; i < n; i++) { - - ans[(x + i) % n] = i % 2; - - } - - if (n % 2 || (x - y) % 2 == 0) { - - ans[x] = 2; - - } - - - - for (auto& i : ans) cout< - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - - - -using namespace std; - -#define NDEBUG - -#define endl ""\n"" - -#define ff first - -#define ss second - -#define vi vector - -#define pii pair - -#define sz(x) (int)x.size() - -//#define int long long - -constexpr int MAX_N = 100'005; - -constexpr int INF = 1E9; - - - - - -int32_t main() { - - // ifstream cin(""MEXcycle.txt""); - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - int t; cin>>t; - - - - while(t--) { - - int n, x, y; - - cin>>n>>x>>y; - - - - vector ans; - - - - for (int i = 0; i < n; i++) { - - if (i % 2) ans.push_back(0); - - else ans.push_back(1); - - } - - if (n % 2 == 0 && (x - y) % 2 == 0) { - - ans[x - 1] = 2; - - } - - else if (n % 2) { - - ans[0] = 2; - - } - - for (auto& i : ans) cout< - - - -const int N = 200100; - - - -int n, x, y; - -int a[N]; - - - -int calc(std::vector element) { - - for (int mex = 0;; mex ++) { - - bool flag = 0; - - for (int x : element) - - if (x == mex) { - - flag = 1; - - break; - - } - - - - if (!flag) - - return mex; - - } - -} - - - -void work() { - - std::cin >> n >> x >> y; - - - - a[x] = a[y] = -1; - - - - int state = 1; - - for (int i = x + 1; i <= y - 1; i ++) - - a[i] = (state ^= 1); - - - - state = 1; - - for (int i = y + 1; i <= n; i ++) - - a[i] = (state ^= 1); - - for (int i = 1; i <= x - 1; i ++) - - a[i] = (state ^= 1); - - - - a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]}); - - a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]}); - - - - for (int i = 1; i <= n; i ++) - - std::cout << a[i] << ' '; - - std::cout << '\n'; - -} - - - -int main() { - - std::ios::sync_with_stdio(0); - - std::cin.tie(0); - - - - int T; - - std::cin >> T; - - - - while (T --) - - work(); - - - - return 0; - -} - - - -/* - - * 心中无女人 - - * 比赛自然神 - - * 模板第一页 - - * 忘掉心上人 - -**/","#include - - - -const int N = 200100; - - - -int n, x, y; - -int a[N]; - - - -int calc(std::vector element) { - - for (int mex = 0;; mex ++) { - - bool flag = 0; - - for (int x : element) - - if (x == mex) { - - flag = 1; - - break; - - } - - - - if (!flag) - - return mex; - - } - -} - - - -void work() { - - std::cin >> n >> x >> y; - - - - a[x] = a[y] = -1; - - - - int state = 0; - - - - for (int i = x + 1; i <= y - 1; i ++) - - a[i] = (state ^= 1); - - - - for (int i = y + 1; i <= n; i ++) - - a[i] = (state ^= 1); - - - - for (int i = 1; i <= x - 1; i ++) - - a[i] = (state ^= 1); - - - - a[x] = calc({a[x == 1 ? n : x - 1], a[x == n ? 1 : x + 1]}); - - a[y] = calc({a[y == 1 ? n : y - 1], a[y == n ? 1 : y + 1], a[x]}); - - - - for (int i = 1; i <= n; i ++) - - std::cout << a[i] << ' '; - - std::cout << '\n'; - -} - - - -int main() { - - std::ios::sync_with_stdio(0); - - std::cin.tie(0); - - - - int T; - - std::cin >> T; - - - - while (T --) - - work(); - - - - return 0; - -} - - - -/* - - * 心中无女人 - - * 比赛自然神 - - * 模板第一页 - - * 忘掉心上人 - -**/",1 -exccc,2049C - MEX Cycle,c++20 ,307643869,307634573,"#include - - - -using namespace std; - - - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - x--,y--; - - vectora(n); - - for (int i=0; i>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}","#include - - - -using namespace std; - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - vectora(n+1); - - a[1]=0; - - for (int i=2; i<=n; i++) { - - a[i]=(a[i-1]+1)%3; - - } - - - - if(a[x]==a[y]){ - - a[y]=3-a[x]-a[y-1]; - - } - - int z=(y+1)%n; - - if(a[z]==a[y]||a[z]==a[z+1]){ - - a[z]=3-a[y]-a[z+1]; - - } - - for (int i=1; i<=n; i++) { - - cout<>t; - - while(t--){ - - solve(); - - }; - - return 0; - -}",1 -Parth1510,2049C - MEX Cycle,c++17 ,304247363,304246551,"#include - -#include - -#include - -using namespace std; - -#pragma GCC optimize(""Ofast"") - -#pragma GCC target(""avx,avx2,fma"") - -#pragma GCC optimization(""unroll-loops"") - - - -#define nl '\n' - -#define sp ' ' - -#define pi 2 * acos(0.0) - - - -// Types of declarations ///////////////////////////////// - -#define ui unsigned int - -#define us unsigned short - -#define all(x) x.begin(), x.end() - -#define ull unsigned long long - -#define ll long long - -#define ld long double - -#define vstr vector - -#define vll vector - -#define vi vector - -#define vvi vector> - -#define vii vector> - -#define pii pair - - - -// Odd Even ///////////////////////////////////////////// - -bool odd(ll num) { return ((num & 1) == 1); } - -bool even(ll num) { return ((num & 1) == 0); } - - - -//////////////////////////////////////////////////////// Prime - - - -bool isPrime(int n) - -{ - - for (int i = 2; i * i <= n; i++) - - { - - if (n % i == 0) - - return false; - - } - - return true; - -} - - - -///////////////////////////////////////////////////////// LCM GCD - -long long gcd(long long a, long long b) - -{ - - while (b != 0) - - { - - long long temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -long long lcm(long long a, long long b) - -{ - - return (a / gcd(a, b)) * b; - -} - -////////////////////////////////////////////////////////// SQR ROOT - - - -long long sqrt(long long x) - -{ - - long long s = 0, e = 2e9, res = s; - - while (s <= e) - - { - - long long m = (s + e) / 2; - - if (m * m <= x) - - res = m, s = m + 1; - - else - - e = m - 1; - - } - - return res; - -} - -/* - - vi arr(n); - - for(int i=0; i>arr[i]; - -*/ - - - -/* - -check all edge cases - -check for integer overflow - -check for corner cases - -check for constraints - -check for time complexity - -check for array bounds - -check for negative values - -*/ - - - -/*----------------------------------------------------------------------------*/ - -void solve() - -{ - - // Read input: n = number of dragons, x and y are the special dragons - - int n, x, y; - - cin >> n >> x >> y; - - // Convert x and y from 1-indexed to 0-indexed for array usage - - x--, y--; - - - - vector a(n); // Array to store the assigned numbers for dragons - - - - if (n % 2 == 0) - - { - - // For even n, assign alternating values: 0, 1, 0, 1, ... - - for (int i = 0; i < n; i++) - - { - - a[i] = i % 2; - - } - - // If dragons x and y (friends) have the same number, break the tie by changing one of them - - if (a[x] == a[y]) - - { - - a[x] = 2; // New value to ensure mex condition holds on the cycle - - } - - } - - else - - { - - // For odd n, fix the value for dragon x to 2 first - - a[x] = 2; - - // For positions after x, use alternating pattern (0 and 1) - - for (int i = x + 1; i < n; i++) - - { - - a[i] = i % 2; - - } - - // For positions before x, adjust pattern with (n + i) % 2 to maintain cyclic order - - for (int i = 0; i < x; i++) - - { - - a[i] = (n + i) % 2; - - } - - } - - // Output the array where each entry represents dragon's assigned number - - for (int i = 0; i < n; i++) - - { - - cout << a[i] << ' '; - - } - - cout << '\n'; - -} - - - -/* - -Evirir the dragon has many friends. They have 3 friends! That is one more than the average dragon. - - - -You are given integers n - -, x - -, and y - -. There are n - - dragons sitting in a circle. The dragons are numbered 1,2,…,n - -. For each i - - (1≤i≤n - -), dragon i - - is friends with dragon i−1 - - and i+1 - -, where dragon 0 - - is defined to be dragon n - - and dragon n+1 - - is defined to be dragon 1 - -. Additionally, dragons x - - and y - - are friends with each other (if they are already friends, this changes nothing). Note that all friendships are mutual. - - - -Output n - - non-negative integers a1,a2,…,an - - such that for each dragon i - - (1≤i≤n - -), the following holds: - - - -Let f1,f2,…,fk - - be the friends of dragon i - -. Then ai=mex(af1,af2,…,afk) - -.∗ - -∗ - -The minimum excluded (MEX) of a collection of integers c1,c2,…,cm - - is defined as the smallest non-negative integer t - - which does not occur in the collection c - -. - - - -Input - -Each test contains multiple test cases. The first line contains the number of test cases t - - (1≤t≤104 - -). The description of the test cases follows. - - - -The first and only line of each test case contains three integers n - -, x - -, y - - (3≤n≤2⋅105 - -, 1≤x> t; - - while (t--) - - solve(); - -} - -","#include - -#include - -#include - -using namespace std; - -#pragma GCC optimize(""Ofast"") - -#pragma GCC target(""avx,avx2,fma"") - -#pragma GCC optimization(""unroll-loops"") - - - -#define nl '\n' - -#define sp ' ' - -#define pi 2 * acos(0.0) - - - -// Types of declarations ///////////////////////////////// - -#define ui unsigned int - -#define us unsigned short - -#define all(x) x.begin(), x.end() - -#define ull unsigned long long - -#define ll long long - -#define ld long double - -#define vstr vector - -#define vll vector - -#define vi vector - -#define vvi vector> - -#define vii vector> - -#define pii pair - - - -// Odd Even ///////////////////////////////////////////// - -bool odd(ll num) { return ((num & 1) == 1); } - -bool even(ll num) { return ((num & 1) == 0); } - - - -//////////////////////////////////////////////////////// Prime - - - -bool isPrime(int n) - -{ - - for (int i = 2; i * i <= n; i++) - - { - - if (n % i == 0) - - return false; - - } - - return true; - -} - - - -///////////////////////////////////////////////////////// LCM GCD - -long long gcd(long long a, long long b) - -{ - - while (b != 0) - - { - - long long temp = b; - - b = a % b; - - a = temp; - - } - - return a; - -} - -long long lcm(long long a, long long b) - -{ - - return (a / gcd(a, b)) * b; - -} - -////////////////////////////////////////////////////////// SQR ROOT - - - -long long sqrt(long long x) - -{ - - long long s = 0, e = 2e9, res = s; - - while (s <= e) - - { - - long long m = (s + e) / 2; - - if (m * m <= x) - - res = m, s = m + 1; - - else - - e = m - 1; - - } - - return res; - -} - -/* - - vi arr(n); - - for(int i=0; i>arr[i]; - -*/ - - - -/* - -check all edge cases - -check for integer overflow - -check for corner cases - -check for constraints - -check for time complexity - -check for array bounds - -check for negative values - -*/ - - - -/*----------------------------------------------------------------------------*/ - -void solve() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - - - vector a(n); - - for (int i = 0; i < n; i++) - - a[i] = i % 3; - - - - for (int i = 0; i < n; i++) - - cout << a[i] << (i + 1 < n ? ' ' : '\n'); - -} - - - -/* - -Evirir the dragon has many friends. They have 3 friends! That is one more than the average dragon. - - - -You are given integers n - -, x - -, and y - -. There are n - - dragons sitting in a circle. The dragons are numbered 1,2,…,n - -. For each i - - (1≤i≤n - -), dragon i - - is friends with dragon i−1 - - and i+1 - -, where dragon 0 - - is defined to be dragon n - - and dragon n+1 - - is defined to be dragon 1 - -. Additionally, dragons x - - and y - - are friends with each other (if they are already friends, this changes nothing). Note that all friendships are mutual. - - - -Output n - - non-negative integers a1,a2,…,an - - such that for each dragon i - - (1≤i≤n - -), the following holds: - - - -Let f1,f2,…,fk - - be the friends of dragon i - -. Then ai=mex(af1,af2,…,afk) - -.∗ - -∗ - -The minimum excluded (MEX) of a collection of integers c1,c2,…,cm - - is defined as the smallest non-negative integer t - - which does not occur in the collection c - -. - - - -Input - -Each test contains multiple test cases. The first line contains the number of test cases t - - (1≤t≤104 - -). The description of the test cases follows. - - - -The first and only line of each test case contains three integers n - -, x - -, y - - (3≤n≤2⋅105 - -, 1≤x> t; - - while (t--) - - solve(); - -} - -",1 -SD125#,2049C - MEX Cycle,java,305958276,305959259,"import static java.lang.Math.max; - -import static java.lang.Math.min; - -import static java.lang.Math.abs; - - - -import java.util.*; - -import java.io.*; - -import java.math.*; - - - -public final class Main { - - - - static PrintWriter out = new PrintWriter(System.out); - - static FastReader in = new FastReader(); - - static final int MOD1 = (int) (1e9 + 7); - - static final int MOD2 = 998244353; - - - - static final int inf = Integer.MAX_VALUE; - - static final int minf = Integer.MIN_VALUE; - - static final long linf = 1L << 62; - - - - public static void main(String[] args){ - - int tt = i(); - - while (tt-- > 0) { - - solve(); - - } - - out.flush(); - - } - - - - public static void solve(){ - - - - // int MIN = -1*(int) 1e9; - - // int MAX = (int) 1e9; - - // PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); - - - - int n = i(); - - int x = i(); - - int y = i(); - - // String s = s(); - - // int ar[]=input(n); - - int ar[]=new int[n]; - - for(int i=0;i= k) { - - ans = mid; - - hi = mid - 1; - - } else { - - lo = mid + 1; - - } - - } - - return ans; - - } - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // -------------BINARYSEARCH-----------// - - - - // UPPERBOUND find lowest i which satisfy a[i]>=x - - static int upperbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - // LOWERBOUND find highest i which satisfy a[i]<=x - - static int lowerbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - // -------------BINARYSEARCH-----------// - - - - // ---------------MATH-----------------// - - - - public static long fact(int n, int mod) { - - long res = 1; - - for (int i = 2; i <= n; i++) { - - res = (res * i) % mod; - - } - - return res; - - } - - - - static int GCD(int a, int b) { - - int dividend = a > b ? a : b; - - int divisor = a < b ? a : b; - - - - while (divisor > 0) { - - int reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long GCD(long a, long b) { - - long dividend = a > b ? a : b; - - long divisor = a < b ? a : b; - - - - while (divisor > 0) { - - long reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long LCM(int a, int b) { - - return (long) a / GCD(a, b) * b; - - } - - - - static long LCM(long a, long b) { - - return a / GCD(a, b) * b; - - } - - - - static long pow(long a, long b, int mod) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow = (pow * x) % mod; - - } - - x = (x * x) % mod; - - b /= 2; - - } - - return pow; - - } - - - - static long pow(long a, long b) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow *= x; - - } - - x = x * x; - - b /= 2; - - } - - return pow; - - } - - - - static long modInverse(long x, int mod) { - - return pow(x, mod - 2, mod); - - } - - - - static boolean isPrime(long N) { - - if (N <= 1) { - - return false; - - } - - if (N <= 3) { - - return true; - - } - - if (N % 2 == 0 || N % 3 == 0) { - - return false; - - } - - for (int i = 5; i * i <= N; i = i + 6) { - - if (N % i == 0 || N % (i + 2) == 0) { - - return false; - - } - - } - - return true; - - } - - - - static long log(long a) { - - return (long) (Math.log(a)); - - } - - - - static long log2(long a) { - - return (long) (Math.log(a) / Math.log(2)); - - } - - - - static long sqrt(long x) { - - long start = 0, end = (long) 3e9, ans = 1; - - while (start <= end) { - - long mid = (start + end) / 2; - - if (mid * mid <= x) { - - ans = mid; - - start = mid + 1; - - } else - - end = mid - 1; - - } - - return ans; - - } - - - - static long ceil(long a, long b) { - - return (a / b) + ((a % b == 0) ? 0 : 1); - - } - - - - static boolean isPerfectSquare(double number) { - - double sqrt = Math.sqrt(number); - - return ((sqrt - Math.floor(sqrt)) == 0); - - } - - - - // ---------------MATH-----------------// - - // ---------------CALCS-----------------// - - - - static long sum(List a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(int[] a) { - - long sum = 0; - - for (int ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(long[] a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static int maxArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int maxArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - // ---------------CALCS-----------------// - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// - - - - static void shuffle(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - } - - - - static void shuffleAndSort(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void shuffleAndSort(long[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - long temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void swap(int A[], int a, int b) { - - int t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(long A[], int a, int b) { - - long t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(char A[], int a, int b) { - - char t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - public static String reverse(String str) { - - if (str == null) { - - return null; - - } - - return new StringBuilder(str).reverse().toString(); - - } - - - - public static void reverse(int[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static void reverse(long[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static String repeat(char ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = repeat - 1; i >= 0; i--) { - - buf[i] = ch; - - } - - return new String(buf); - - } - - - - public static String repeat(char ch[], int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch[i % ch.length]; - - } - - return new String(buf); - - } - - - - public static String repeat(String ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch.charAt(i % ch.length()); - - } - - return new String(buf); - - } - - - - static void fillFrequency(Map map, long a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, long val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void fillFrequency(Map map, int a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, int val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void remove(Map map, long val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - static void remove(Map map, int val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // --------------BITS-----------------// - - static int[][] PrefixBitsCount(int n, int[] a) { - - int pref[][] = new int[n + 1][32]; - - // Builds the prefix sums for each bit - - for (int i = 0; i < n; i++) { - - for (int j = 0; j < 32; j++) { - - if ((a[i] & (1 << j)) != 0) { - - pref[i + 1][j] = pref[i][j] + 1; - - } else { - - pref[i + 1][j] = pref[i][j]; - - } - - } - - } - - return pref; - - } - - - - static int[] prefixAnd(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] & a[i]; - - } - - return pre; - - } - - - - static int[] prefixOr(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] | a[i]; - - } - - return pre; - - } - - - - static int[] prefixXor(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] ^ a[i]; - - } - - return pre; - - } - - // --------------BITS-----------------// - - - - // --------------ARRAYS-----------------// - - - - static int[] getPrefMax(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = max(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getPrefMin(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = min(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getSuffMin(int arr[]) { - - int n = arr.length; - - int suff[] = new int[n]; - - suff[n - 1] = arr[n - 1]; - - for (int i = n - 2; i >= 0; i--) { - - suff[i] = min(suff[i + 1], arr[i]); - - } - - return suff; - - } - - - - static long[] prefix(int[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static List prefix(List a) { - - List pre = new ArrayList<>(); - - pre.add(0l); - - for (int i = 0; i < a.size(); i++) { - - pre.add(pre.get(i) + a.get(i)); - - } - - return pre; - - } - - - - static long[] prefix(long[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static long[] suffix(int[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - - - static long[] suffix(long[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - // --------------ARRAYS-----------------// - - - - // --------------Sieve&Factors-----------------// - - - - static List sieveOfEratosthenes(int n) { - - List primeList = new ArrayList<>(); - - boolean prime[] = new boolean[n + 1]; - - for (int i = 0; i <= n; i++) - - prime[i] = true; - - - - for (int p = 2; p * p <= n; p++) { - - - - if (prime[p] == true) { - - - - for (int i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - - - for (int i = 2; i <= n; i++) { - - if (prime[i] == true) - - primeList.add(i); - - // System.out.print(i + "" ""); - - } - - return primeList; - - } - - - - static List allDivisors(int n) { - - List divisoers = new ArrayList<>(); - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - divisoers.add(i); - - if (i != n / i) { - - divisoers.add(n / i); - - } - - } - - } - - return divisoers; - - } - - - - // --------------Sieve&Factors-----------------// - - - - // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - - static int i() { - - return in.nextInt(); - - } - - - - static long l() { - - return in.nextLong(); - - } - - - - static double d() { - - return in.nextDouble(); - - } - - - - static String s() { - - return in.nextLine(); - - } - - - - static ArrayList inputList(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(i()); - - return a; - - } - - - - static ArrayList inputListLong(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(l()); - - return a; - - } - - - - static int[][] inputWithIdx(int N) { - - int A[][] = new int[N][2]; - - for (int i = 0; i < N; i++) { - - A[i] = new int[] { in.nextInt(), i }; - - } - - return A; - - } - - - - static int[][] inputMatrix(int N, int M) { - - int A[][] = new int[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static long[][] inputMatrixLong(int N, int M) { - - long A[][] = new long[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static int[] input(int N) { - - int A[] = new int[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static Integer[] inputWrapper(int N) { - - Integer A[] = new Integer[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static long[] inputLong(int N) { - - long A[] = new long[N]; - - for (int i = 0; i < A.length; i++) { - - A[i] = in.nextLong(); - - } - - return A; - - } - - - - static void p(String s) { - - out.print(s); - - } - - - - static void p(int s) { - - out.print(s); - - } - - - - static void p(long s) { - - out.print(s); - - } - - - - static void p(double s) { - - out.print(s); - - } - - - - static void p(char s) { - - out.print(s); - - } - - - - static void pl(String s) { - - out.println(s); - - } - - - - static void pl(int s) { - - out.println(s); - - } - - - - static void pl(long s) { - - out.println(s); - - } - - - - static void pl(double s) { - - out.println(s); - - } - - - - static void pl(char c) { - - out.println(c); - - } - - - - static void pl() { - - out.println(); - - } - - - - static void pl(int[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(long[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(T[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(List A) { - - for (T a : A) { - - out.print(a + "" ""); - - } - - out.println(); - - } - - - - static void pl(Object o) { - - out.println(o); - - } - - - - static void ps(int s) { - - out.print(s + "" ""); - - } - - - - static void ps(long s) { - - out.print(s + "" ""); - - } - - - - static void ps(double s) { - - out.print(s + "" ""); - - } - - - - static void ps(char c) { - - out.print(c + "" ""); - - } - - - - static void yes() { - - pl(""YES""); - - } - - - - static void no() { - - pl(""NO""); - - } - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - -} - - - - class FastReader { - - - - BufferedReader br; - - StringTokenizer st; - - - - public FastReader() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - char nextChar() { - - return next().charAt(0); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - -} - - - -","import static java.lang.Math.max; - -import static java.lang.Math.min; - -import static java.lang.Math.abs; - - - -import java.util.*; - -import java.io.*; - -import java.math.*; - - - -public final class Main { - - - - static PrintWriter out = new PrintWriter(System.out); - - static FastReader in = new FastReader(); - - static final int MOD1 = (int) (1e9 + 7); - - static final int MOD2 = 998244353; - - - - static final int inf = Integer.MAX_VALUE; - - static final int minf = Integer.MIN_VALUE; - - static final long linf = 1L << 62; - - - - public static void main(String[] args){ - - int tt = i(); - - while (tt-- > 0) { - - solve(); - - } - - out.flush(); - - } - - - - public static void solve(){ - - - - // int MIN = -1*(int) 1e9; - - // int MAX = (int) 1e9; - - // PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); - - - - int n = i(); - - int x = i(); - - int y = i(); - - // String s = s(); - - // int ar[]=input(n); - - int ar[]=new int[n]; - - for(int i=0;i= k) { - - ans = mid; - - hi = mid - 1; - - } else { - - lo = mid + 1; - - } - - } - - return ans; - - } - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // -------------BINARYSEARCH-----------// - - - - // UPPERBOUND find lowest i which satisfy a[i]>=x - - static int upperbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a.get(m) >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - static int upperbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = l + (r - l) / 2; - - if (a[m] >= x) { - - r = m; - - } else { - - l = m + 1; - - } - - - - } - - return r; - - } - - - - // LOWERBOUND find highest i which satisfy a[i]<=x - - static int lowerbound(List a, long x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(List a, int x) { - - int l = 0; - - int r = a.size() - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a.get(m) <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(int[] a, int x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - static int lowerbound(long[] a, long x) { - - int l = 0; - - int r = a.length - 1; - - while (l < r) { - - int m = (l + r + 1) / 2; - - if (a[m] <= x) { - - l = m; - - } else { - - r = m - 1; - - } - - } - - return l; - - } - - - - // -------------BINARYSEARCH-----------// - - - - // ---------------MATH-----------------// - - - - public static long fact(int n, int mod) { - - long res = 1; - - for (int i = 2; i <= n; i++) { - - res = (res * i) % mod; - - } - - return res; - - } - - - - static int GCD(int a, int b) { - - int dividend = a > b ? a : b; - - int divisor = a < b ? a : b; - - - - while (divisor > 0) { - - int reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long GCD(long a, long b) { - - long dividend = a > b ? a : b; - - long divisor = a < b ? a : b; - - - - while (divisor > 0) { - - long reminder = dividend % divisor; - - dividend = divisor; - - divisor = reminder; - - } - - return dividend; - - } - - - - static long LCM(int a, int b) { - - return (long) a / GCD(a, b) * b; - - } - - - - static long LCM(long a, long b) { - - return a / GCD(a, b) * b; - - } - - - - static long pow(long a, long b, int mod) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow = (pow * x) % mod; - - } - - x = (x * x) % mod; - - b /= 2; - - } - - return pow; - - } - - - - static long pow(long a, long b) { - - long pow = 1; - - long x = a; - - while (b != 0) { - - if ((b & 1) != 0) { - - pow *= x; - - } - - x = x * x; - - b /= 2; - - } - - return pow; - - } - - - - static long modInverse(long x, int mod) { - - return pow(x, mod - 2, mod); - - } - - - - static boolean isPrime(long N) { - - if (N <= 1) { - - return false; - - } - - if (N <= 3) { - - return true; - - } - - if (N % 2 == 0 || N % 3 == 0) { - - return false; - - } - - for (int i = 5; i * i <= N; i = i + 6) { - - if (N % i == 0 || N % (i + 2) == 0) { - - return false; - - } - - } - - return true; - - } - - - - static long log(long a) { - - return (long) (Math.log(a)); - - } - - - - static long log2(long a) { - - return (long) (Math.log(a) / Math.log(2)); - - } - - - - static long sqrt(long x) { - - long start = 0, end = (long) 3e9, ans = 1; - - while (start <= end) { - - long mid = (start + end) / 2; - - if (mid * mid <= x) { - - ans = mid; - - start = mid + 1; - - } else - - end = mid - 1; - - } - - return ans; - - } - - - - static long ceil(long a, long b) { - - return (a / b) + ((a % b == 0) ? 0 : 1); - - } - - - - static boolean isPerfectSquare(double number) { - - double sqrt = Math.sqrt(number); - - return ((sqrt - Math.floor(sqrt)) == 0); - - } - - - - // ---------------MATH-----------------// - - // ---------------CALCS-----------------// - - - - static long sum(List a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(int[] a) { - - long sum = 0; - - for (int ele : a) - - sum += ele; - - return sum; - - } - - - - static long sum(long[] a) { - - long sum = 0; - - for (long ele : a) - - sum += ele; - - return sum; - - } - - - - static int maxArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int maxArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] > m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(long a[]) { - - int in = 0; - - long m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - static int minArray(int a[]) { - - int in = 0; - - int m = a[0]; - - for (int i = 1; i < a.length; i++) { - - if (a[i] < m) { - - m = a[i]; - - in = i; - - } - - } - - return in; - - } - - - - // ---------------CALCS-----------------// - - - - // ------------------------------------------COMMON|FUNCTIONS--------------------------------------------------// - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// - - - - static void shuffle(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - } - - - - static void shuffleAndSort(int[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - int temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void shuffleAndSort(long[] arr) { - - for (int i = 0; i < arr.length; i++) { - - int rand = (int) (Math.random() * arr.length); - - long temp = arr[rand]; - - arr[rand] = arr[i]; - - arr[i] = temp; - - } - - Arrays.sort(arr); - - } - - - - static void swap(int A[], int a, int b) { - - int t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(long A[], int a, int b) { - - long t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - static void swap(char A[], int a, int b) { - - char t = A[a]; - - A[a] = A[b]; - - A[b] = t; - - } - - - - public static String reverse(String str) { - - if (str == null) { - - return null; - - } - - return new StringBuilder(str).reverse().toString(); - - } - - - - public static void reverse(int[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static void reverse(long[] arr) { - - int l = 0; - - int r = arr.length - 1; - - while (l < r) { - - swap(arr, l, r); - - l++; - - r--; - - } - - } - - - - public static String repeat(char ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = repeat - 1; i >= 0; i--) { - - buf[i] = ch; - - } - - return new String(buf); - - } - - - - public static String repeat(char ch[], int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch[i % ch.length]; - - } - - return new String(buf); - - } - - - - public static String repeat(String ch, int repeat) { - - if (repeat <= 0) { - - return """"; - - } - - final char[] buf = new char[repeat]; - - for (int i = 0; i < repeat; i++) { - - buf[i] = ch.charAt(i % ch.length()); - - } - - return new String(buf); - - } - - - - static void fillFrequency(Map map, long a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, long val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void fillFrequency(Map map, int a[]) { - - for (int i = 0; i < a.length; i++) { - - fill(map, a[i]); - - } - - } - - - - static void fill(Map map, int val) { - - if (map.containsKey(val)) - - map.put(val, map.get(val) + 1); - - else - - map.put(val, 1); - - } - - - - static void remove(Map map, long val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - static void remove(Map map, int val) { - - if (map.get(val) == 1) - - map.remove(val); - - else - - map.replace(val, map.get(val) - 1); - - } - - - - // ------------------------------------------MODIFICATIONS--------------------------------------------------// // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // --------------BITS-----------------// - - static int[][] PrefixBitsCount(int n, int[] a) { - - int pref[][] = new int[n + 1][32]; - - // Builds the prefix sums for each bit - - for (int i = 0; i < n; i++) { - - for (int j = 0; j < 32; j++) { - - if ((a[i] & (1 << j)) != 0) { - - pref[i + 1][j] = pref[i][j] + 1; - - } else { - - pref[i + 1][j] = pref[i][j]; - - } - - } - - } - - return pref; - - } - - - - static int[] prefixAnd(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] & a[i]; - - } - - return pre; - - } - - - - static int[] prefixOr(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] | a[i]; - - } - - return pre; - - } - - - - static int[] prefixXor(int[] a) { - - int[] pre = new int[a.length]; - - pre[0] = a[0]; - - for (int i = 1; i < a.length; i++) { - - pre[i] = pre[i - 1] ^ a[i]; - - } - - return pre; - - } - - // --------------BITS-----------------// - - - - // --------------ARRAYS-----------------// - - - - static int[] getPrefMax(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = max(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getPrefMin(int arr[]) { - - int n = arr.length; - - int pref[] = new int[n]; - - pref[0] = arr[0]; - - for (int i = 1; i < n; i++) { - - pref[i] = min(arr[i], pref[i - 1]); - - } - - return pref; - - } - - - - static int[] getSuffMin(int arr[]) { - - int n = arr.length; - - int suff[] = new int[n]; - - suff[n - 1] = arr[n - 1]; - - for (int i = n - 2; i >= 0; i--) { - - suff[i] = min(suff[i + 1], arr[i]); - - } - - return suff; - - } - - - - static long[] prefix(int[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static List prefix(List a) { - - List pre = new ArrayList<>(); - - pre.add(0l); - - for (int i = 0; i < a.size(); i++) { - - pre.add(pre.get(i) + a.get(i)); - - } - - return pre; - - } - - - - static long[] prefix(long[] a) { - - long[] pre = new long[a.length + 1]; - - pre[0] = 0; - - for (int i = 0; i < a.length; i++) { - - pre[i + 1] = pre[i] + a[i]; - - } - - return pre; - - } - - - - static long[] suffix(int[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - - - static long[] suffix(long[] a) { - - long[] post = new long[a.length + 1]; - - post[a.length] = 0; - - for (int i = a.length - 1; i >= 0; i++) { - - post[i] = post[i + 1] + a[i]; - - } - - return post; - - } - - // --------------ARRAYS-----------------// - - - - // --------------Sieve&Factors-----------------// - - - - static List sieveOfEratosthenes(int n) { - - List primeList = new ArrayList<>(); - - boolean prime[] = new boolean[n + 1]; - - for (int i = 0; i <= n; i++) - - prime[i] = true; - - - - for (int p = 2; p * p <= n; p++) { - - - - if (prime[p] == true) { - - - - for (int i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - - - for (int i = 2; i <= n; i++) { - - if (prime[i] == true) - - primeList.add(i); - - // System.out.print(i + "" ""); - - } - - return primeList; - - } - - - - static List allDivisors(int n) { - - List divisoers = new ArrayList<>(); - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - divisoers.add(i); - - if (i != n / i) { - - divisoers.add(n / i); - - } - - } - - } - - return divisoers; - - } - - - - // --------------Sieve&Factors-----------------// - - - - // -----------------------------------------------PRECOMPUTE--------------------------------------------------// - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - - static int i() { - - return in.nextInt(); - - } - - - - static long l() { - - return in.nextLong(); - - } - - - - static double d() { - - return in.nextDouble(); - - } - - - - static String s() { - - return in.nextLine(); - - } - - - - static ArrayList inputList(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(i()); - - return a; - - } - - - - static ArrayList inputListLong(int n) { - - ArrayList a = new ArrayList(n); - - for (int i = 0; i < n; i++) - - a.add(l()); - - return a; - - } - - - - static int[][] inputWithIdx(int N) { - - int A[][] = new int[N][2]; - - for (int i = 0; i < N; i++) { - - A[i] = new int[] { in.nextInt(), i }; - - } - - return A; - - } - - - - static int[][] inputMatrix(int N, int M) { - - int A[][] = new int[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static long[][] inputMatrixLong(int N, int M) { - - long A[][] = new long[N][M]; - - for (int i = 0; i < N; i++) { - - for (int j = 0; j < M; j++) { - - A[i][j] = i(); - - } - - } - - return A; - - } - - - - static int[] input(int N) { - - int A[] = new int[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static Integer[] inputWrapper(int N) { - - Integer A[] = new Integer[N]; - - for (int i = 0; i < N; i++) { - - A[i] = in.nextInt(); - - } - - return A; - - } - - - - static long[] inputLong(int N) { - - long A[] = new long[N]; - - for (int i = 0; i < A.length; i++) { - - A[i] = in.nextLong(); - - } - - return A; - - } - - - - static void p(String s) { - - out.print(s); - - } - - - - static void p(int s) { - - out.print(s); - - } - - - - static void p(long s) { - - out.print(s); - - } - - - - static void p(double s) { - - out.print(s); - - } - - - - static void p(char s) { - - out.print(s); - - } - - - - static void pl(String s) { - - out.println(s); - - } - - - - static void pl(int s) { - - out.println(s); - - } - - - - static void pl(long s) { - - out.println(s); - - } - - - - static void pl(double s) { - - out.println(s); - - } - - - - static void pl(char c) { - - out.println(c); - - } - - - - static void pl() { - - out.println(); - - } - - - - static void pl(int[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(long[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(T[] o) { - - for (int i = 0; i < o.length; i++) { - - out.print(o[i] + "" ""); - - } - - out.println(); - - } - - - - static void pl(List A) { - - for (T a : A) { - - out.print(a + "" ""); - - } - - out.println(); - - } - - - - static void pl(Object o) { - - out.println(o); - - } - - - - static void ps(int s) { - - out.print(s + "" ""); - - } - - - - static void ps(long s) { - - out.print(s + "" ""); - - } - - - - static void ps(double s) { - - out.print(s + "" ""); - - } - - - - static void ps(char c) { - - out.print(c + "" ""); - - } - - - - static void yes() { - - pl(""YES""); - - } - - - - static void no() { - - pl(""NO""); - - } - - - - // ---------------------------------------------INPUT&OUTPUT--------------------------------------------------// - - - -} - - - - class FastReader { - - - - BufferedReader br; - - StringTokenizer st; - - - - public FastReader() { - - br = new BufferedReader(new InputStreamReader(System.in)); - - } - - - - String next() { - - while (st == null || !st.hasMoreElements()) { - - try { - - st = new StringTokenizer(br.readLine()); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - } - - return st.nextToken(); - - } - - - - char nextChar() { - - return next().charAt(0); - - } - - - - int nextInt() { - - return Integer.parseInt(next()); - - } - - - - long nextLong() { - - return Long.parseLong(next()); - - } - - - - double nextDouble() { - - return Double.parseDouble(next()); - - } - - - - String nextLine() { - - String str = """"; - - try { - - str = br.readLine(); - - } catch (IOException e) { - - e.printStackTrace(); - - } - - return str; - - } - -} - - - -",2 -LumosSpark,2049C - MEX Cycle,c++23 ,308596188,308595792,"#include - -using namespace std; - -const int N = 2e5+7; - -int a[N]; - -int main(){ - - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int T; - - cin>>T; - - while(T--){ - - int n,x,y; - - cin>>n>>x>>y; - - int m=y-x,flag=0; - - if (n%2==0){ - - if (m%2){ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - } - - else{ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - a[y]=2; - - } - - } - - else{ - - if (m%2){ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - a[x]=2; - - } - - else{ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - a[x]=2; - - } - - } - - for (int i=1;i<=n;i++) - - cout< - -using namespace std; - -const int N = 2e5+7; - -int a[N]; - -int main(){ - - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int T; - - cin>>T; - - while(T--){ - - int n,x,y; - - cin>>n>>x>>y; - - int m=y-x,flag=0; - - if (n%2==0){ - - if (m%2){ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - } - - else{ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - a[y]=2; - - } - - } - - else{ - - if (m%2){ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - if (x-1==0) a[n]=2; - - else a[x-1]=2; - - } - - else{ - - for (int i=x;i<=n;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - for (int i=1;i<=x-1;i++){ - - a[i]=flag; - - if (flag==0) flag=1; - - else flag=0; - - } - - if (x-1==0) a[n]=2; - - else a[x-1]=2; - - a[y]=2; - - } - - } - - for (int i=1;i<=n;i++) - - cout< - -using namespace std; - -#define ll long long - -#define N 100000000+1; - -#define all(v) v.begin(),v.end() - -#define fin(v) for(auto &it:v) cin>>it - -#define mll map - -#define vl vector - -#define srt(v) sort(v.begin(),v.end()) - -#define cnt(a,v) count(a.begin(),a.end(),v) - -#define sm(v) accumulate(all(v), 0LL) - -#define ln ""\n"" - -#define Griffith ios_base::sync_with_stdio(0); - -#define The cin.tie(0); - -#define Hawk cout.tie(0); - -#define Solve ll tt; cin>>tt; while (tt--){solve(); } - - - - - -void solve() { - - ll n; cin>>n; - - ll x,y; cin>>x>>y; x--; y--; - - vl ans(n); - - if(n%2 == 0 && abs(x-y)&1){ - - for (ll i = 0; i < n; i++) - - { - - ans[i] = 1&i; - - } - - } - - else{ - - for (ll i = 0; i < n; i++) - - { - - if(i == x) ans[i] = 2; - - else ans[i] = ((i-x+n)%n)&1; - - } - - - - } - - for (ll i = 0; i < n; i++) - - { - - cout< - -using namespace std; - -#define ll long long - -#define N 100000000+1; - -#define all(v) v.begin(),v.end() - -#define fin(v) for(auto &it:v) cin>>it - -#define mll map - -#define vl vector - -#define srt(v) sort(v.begin(),v.end()) - -#define cnt(a,v) count(a.begin(),a.end(),v) - -#define sm(v) accumulate(all(v), 0LL) - -#define ln ""\n"" - -#define Griffith ios_base::sync_with_stdio(0); - -#define The cin.tie(0); - -#define Hawk cout.tie(0); - -#define Solve ll tt; cin>>tt; while (tt--){solve(); } - - - - - -void solve() { - - ll n; cin>>n; - - ll x,y; cin>>x>>y; - - vl ans(n); - - if(n%2 == 0 && abs(x-y)&1){ - - for (ll i = 0; i < n; i++) - - { - - ans[i] = 1&i; - - } - - } - - else{ - - for (ll i = 0; i < n; i++) - - { - - if(i == x) ans[i] = 2; - - else ans[i] = ((i-x+n)%n)&1; - - } - - - - } - - for (ll i = 0; i < n; i++) - - { - - cout< - -#define int long long - -#define endl ""\n""; - -#define all(a) a.begin(), a.end() - -#define ONLINE_JUDGE - -using namespace std; - -long long mod_exp(long long base, long long exp, long long mod) { - - long long result = 1; - - while (exp > 0) { - - if (exp % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - -int m(set arr){ - - int st = 0; - - for(auto i : arr){ - - if(i == st){ - - // then do nothing - - }else{ - - return st; - - } - - st++; - - } - - return st; - -} - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - // vector> f(n + 1); - - vector ans(n + 1); - - for(int i = 1; i <= n; i++){ - - if(i & 1)ans[i] = 0; - - else ans[i] = 1; - - } - - if((x + y) & 1){ - - // i think it does not matter in case of even n is even only - - if(n % 2 == 0){ - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - }else{ - - for(int i = 1; i < n; i++){ - - cout << ans[i] << "" ""; - - } - - ans[n] = 2; - - cout << 2; - - cout << endl; - - } - - }else{ - - // same number having people are friends - - // so one among them need to have 2 as ans[] - - if(n % 2 == 0){ - - for(int i = 1 ; i <= n; i++){ - - if(i == x){ - - cout << 2 << "" ""; - - ans[i] = 2; - - }else { - - cout << ans[i] << "" ""; - - } - - } - - cout << endl; - - }else{ - - ans[x] = 2; - - int idx = x - 1; - - if(idx == 0) idx = n; - - int cnt = 1; - - int val = 0; - - while(cnt < n){ - - ans[idx] = val; - - val = !val; - - cnt++; - - idx--; - - if(idx == 0) idx = n; - - } - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - } - - } - - //validation - - vector> f(n + 1); - - for(int i = 1; i <= n; i++){ - - int nxt = i + 1; - - int prev = i - 1; - - if(nxt == n + 1) nxt = 1; - - if(prev == 0) prev = n; - - f[i].insert(nxt); - - f[i].insert(prev); - - } - - f[x].insert(y); - - f[y].insert(x); - - - - // for(int i = 1; i <= n; i++) - - // cout << ans[i] << "" ""; - - // cout << endl; - - for(int i = 1; i <=n; i++){ - - set friendsMx; - - // cout << ""friends of "" << i << "" : "" ; - - for(auto j : f[i]){ - - // cout << j << "" , "" << ans[j] << "" ; ""; - - friendsMx.insert(ans[j]); - - } - - // cout << endl; - - // cout << ""M value for "" << i << "" is "" << m(friendsMx) << endl; - - // cout << ""Ans value for "" << i << "" is "" << ans[i] << endl; - - int m_val = m(friendsMx); - - if(m_val != ans[i]){ - - cout << ""wrong for "" << i << endl; - - } - - } - - - - - - - -} - - - - - -signed main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - int t; - - cin >> t; - - while(t--) - - solve(); - - - -} - - - -/* - -void solve() { - - int n, k; - - cin >> n >> k; - - int r = n, l =1; - - stack> st; - - st.push({l, r}); - - int ans =0LL; - - while(st.size()){ - - auto p = st.top(); - - st.pop(); - - int curL = p.first; - - int curR = p.second; - - if(curR - curL + 1 < k){ - - // do nothing - - }else{ - - int sz = curR - curL + 1; - - if(sz & 1){ - - int m = (curL + curR) / 2LL; - - ans += m; - - cout << ""{"" << curL << "" , "" << curR << ""} : "" << m << endl; - - st.push({curL, m - 1LL}); - - st.push({m + 1LL , curR}); - - }else{ - - int m = (curL + curR) / 2LL; - - st.push({curL, m}); - - st.push({m + 1LL , curR}); - - } - - } - - } - - cout << ans << endl; - -} - - */","// || =================================================================== || - -// || || - -// || Reach Expert by May 2025 || - -// || || - -// || =================================================================== || - -#include - -#define int long long - -#define endl ""\n""; - -#define all(a) a.begin(), a.end() - -#define ONLINE_JUDGE - -using namespace std; - -long long mod_exp(long long base, long long exp, long long mod) { - - long long result = 1; - - while (exp > 0) { - - if (exp % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - -int m(set arr){ - - int st = 0; - - for(auto i : arr){ - - if(i == st){ - - // then do nothing - - }else{ - - return st; - - } - - st++; - - } - - return st; - -} - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - // vector> f(n + 1); - - vector ans(n + 1); - - for(int i = 1; i <= n; i++){ - - if(i & 1)ans[i] = 0; - - else ans[i] = 1; - - } - - if((x + y) & 1){ - - // i think it does not matter in case of even n is even only - - if(n % 2 == 0){ - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - }else{ - - for(int i = 1; i < n; i++){ - - cout << ans[i] << "" ""; - - } - - ans[n] = 2; - - cout << 2; - - cout << endl; - - } - - }else{ - - // same number having people are friends - - // so one among them need to have 2 as ans[] - - for(int i = 1 ; i <= n; i++){ - - if(i == x){ - - cout << 2 << "" ""; - - ans[i] = 2; - - }else { - - cout << ans[i] << "" ""; - - } - - } - - cout << endl; - - } - - //validation - - vector> f(n + 1); - - for(int i = 1; i <= n; i++){ - - int nxt = i + 1; - - int prev = i - 1; - - if(nxt == n + 1) nxt = 1; - - if(prev == 0) prev = n; - - f[i].insert(nxt); - - f[i].insert(prev); - - } - - f[x].insert(y); - - f[y].insert(x); - - - - // for(int i = 1; i <= n; i++) - - // cout << ans[i] << "" ""; - - // cout << endl; - - for(int i = 1; i <=n; i++){ - - set friendsMx; - - // cout << ""friends of "" << i << "" : "" ; - - for(auto j : f[i]){ - - // cout << j << "" , "" << ans[j] << "" ; ""; - - friendsMx.insert(ans[j]); - - } - - // cout << endl; - - // cout << ""M value for "" << i << "" is "" << m(friendsMx) << endl; - - // cout << ""Ans value for "" << i << "" is "" << ans[i] << endl; - - int m_val = m(friendsMx); - - if(m_val != ans[i]){ - - cout << ""wrong for "" << i << endl; - - } - - } - - - - - - - -} - - - - - -signed main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - int t; - - cin >> t; - - while(t--) - - solve(); - - - -} - - - -/* - -void solve() { - - int n, k; - - cin >> n >> k; - - int r = n, l =1; - - stack> st; - - st.push({l, r}); - - int ans =0LL; - - while(st.size()){ - - auto p = st.top(); - - st.pop(); - - int curL = p.first; - - int curR = p.second; - - if(curR - curL + 1 < k){ - - // do nothing - - }else{ - - int sz = curR - curL + 1; - - if(sz & 1){ - - int m = (curL + curR) / 2LL; - - ans += m; - - cout << ""{"" << curL << "" , "" << curR << ""} : "" << m << endl; - - st.push({curL, m - 1LL}); - - st.push({m + 1LL , curR}); - - }else{ - - int m = (curL + curR) / 2LL; - - st.push({curL, m}); - - st.push({m + 1LL , curR}); - - } - - } - - } - - cout << ans << endl; - -} - - */",1 -Domzi1,2049C - MEX Cycle,c++23 ,306913515,306912286,"#include - -#include - -#define max(a, b) (a < b ? b : a) - -#define min(a, b) ((a > b) ? b : a) - -#define SZ(X) ((int)(X).size()) - -#define ALL(X) (X).begin(), (X).end() - -#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) - -typedef long long int ll; - -typedef std::vector vi; - -typedef std::pair pi; - -#define clr(arr,value) memset(arr,value,sizeof(arr)) - -#define F first - -#define S second - -//#define int long long - -#define el '\n' - -#define OO 100000000000000 - -const ll MOD = 1e9 +7; - -const int N = 2e5+5; - -using namespace std; - -typedef unordered_map> HASHSET ; - - - - - - - - - -int dx []= {0,0,1,-1,-1,1,-1,1}; - -int dy []= {1,-1,0,0,-1,1,1,-1}; - - - - - - - -void PLAY(){ - - int n , x, y; - - cin >> n >> x>> y; - - --x;--y; - - vi ans(n); - - bool f = x&1?1:0; - - for (int i = 0; i < n; ++i) { - - ans[i] = (i&1?f:!f); - - } - - if (n&1)ans[n-1]=2; - - if (!(abs(x-y)==1 || ans[x] != ans[y] || y-x == n-1)){ - - x = (x == 0)?y:x; - - ans[x] = 2; - - } - - for (int i = 0; i < n; ++i) { - - cout << ans[i] << ' '; - - } - - cout << el; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - -// freopen(""input.txt"",""r"",stdin); - -// freopen(""output.txt"", ""w"", stdout); - - int T = 1 ; - - cin >> T; - - - - while (T--){ - - PLAY(); - - } - - - - return 0; - - - -}","#include - -#include - -#define max(a, b) (a < b ? b : a) - -#define min(a, b) ((a > b) ? b : a) - -#define SZ(X) ((int)(X).size()) - -#define ALL(X) (X).begin(), (X).end() - -#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) - -typedef long long int ll; - -typedef std::vector vi; - -typedef std::pair pi; - -#define clr(arr,value) memset(arr,value,sizeof(arr)) - -#define F first - -#define S second - -//#define int long long - -#define el '\n' - -#define OO 100000000000000 - -const ll MOD = 1e9 +7; - -const int N = 2e5+5; - -using namespace std; - -typedef unordered_map> HASHSET ; - - - - - - - - - -int dx []= {0,0,1,-1,-1,1,-1,1}; - -int dy []= {1,-1,0,0,-1,1,1,-1}; - - - - - - - -void PLAY(){ - - int n , x, y; - - cin >> n >> x>> y; - - --x;--y; - - vi ans(n); - - for (int i = 0; i < n; ++i) { - - ans[i] = (i&1?0:1); - - } - - if (n&1)ans[n-1]=2; - - if (!(abs(x-y)==1 || ans[x] != ans[y] || y-x == n-1)){ - - x = (x == 0)?y:x; - - ans[x] = 2; - - } - - for (int i = 0; i < n; ++i) { - - cout << ans[i] << ' '; - - } - - cout << el; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - -// freopen(""input.txt"",""r"",stdin); - -// freopen(""output.txt"", ""w"", stdout); - - int T = 1 ; - - cin >> T; - - - - while (T--){ - - PLAY(); - - } - - - - return 0; - - - -}",1 -uannai,2049C - MEX Cycle,c++17 ,308259049,308259377,"#include - -using namespace std; - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - vector res(n + 1); - - if (n % 2) { - - bool ok = false; - - for (int i = 1; i <= n; i++) { - - if (i == y && (y - x) % 2 == 0) ok = true; - - res[i] = (i + ok) % 2; - - } - - res[y] = 2; - - } - - else { - - for (int i = 1; i <= n; i++) { - - res[i] = i % 2; - - } - - if (res[x] == res[y]) res[y] = 2; - - } - - for (int i = 1; i <= n; i++) cout << res[i] << "" \n""[i == n]; - -} - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - vector res(n + 1); - - if (n % 2) { - - bool ok = false; - - for (int i = 1; i <= n; i++) { - - if (i == y) ok = true; - - res[i] = (i + ok) % 2; - - } - - res[y] = 2; - - } - - else { - - for (int i = 1; i <= n; i++) { - - res[i] = i % 2; - - } - - if (res[x] == res[y]) res[y] = 2; - - } - - for (int i = 1; i <= n; i++) cout << res[i] << "" \n""[i == n]; - -} - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int T; - - cin >> T; - - while (T--) { - - solve(); - - } - - return 0; - -}",2 -TurboChemtank#,2049C - MEX Cycle,c++20 ,308031357,308033039,"#pragma GCC optimize(""Ofast"") - -#include - -#define int long long - -#define ok cout<<""ok\n"" - -using namespace std; - -typedef pair PII; - -#define ft first - -#define sd second - -const int N=1e6+10; - -const int mod=998244353; - -//const int inf=0x3f3f3f3f; - -const int inf=0x3f3f3f3f3f3f3f3f; - -int n,m; - -int a[N]; - -void solve(){ - - int x,y;cin>>n>>x>>y; - - for(int i=1;i>Case; - - while(Case--)solve(); - -}","#pragma GCC optimize(""Ofast"") - -#include - -#define int long long - -#define ok cout<<""ok\n"" - -using namespace std; - -typedef pair PII; - -#define ft first - -#define sd second - -const int N=1e6+10; - -const int mod=998244353; - -//const int inf=0x3f3f3f3f; - -const int inf=0x3f3f3f3f3f3f3f3f; - -int n,m; - -int a[N]; - -void solve(){ - - int x,y;cin>>n>>x>>y; - - for(int i=1;i=1;i-=2)a[i]=1,a[i-1]=0; - - } - - for(int i=1;i<=n;i++)cout<>Case; - - while(Case--)solve(); - -}",2 -memaygay,2049C - MEX Cycle,c++23 ,307938530,307937421,"#include - -using namespace std; - -typedef long long ll; - -const int N=100000; - -vector v; - -int CALMEX(vector sex){ - - int m[10]={}; - - for(auto k:sex){ - - m[k]++; - - } - - if(m[0]==0){ - - return 0; - - } - - if(m[1]==0){ - - return 1; - - } - - if(m[2]==0){ - - return 2; - - } - - if(m[3]==0){ - - return 3; - - } - - return 4; - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - int a[n+2]={},b[n+2]={}; - - vector> g(n+2); - - g[x].push_back(y); - - g[y].push_back(x); - - for(int i=2;i<=n-1;i++){ - - g[i].push_back(i-1); - - g[i].push_back(i+1); - - } - - g[1].push_back(n); - - g[1].push_back(2); - - g[n].push_back(1); - - g[n].push_back(n-1); - - int thu=10; - - while(thu--){ - - for(int i=1;i<=n;i++){ - - for(auto x:g[i]){ - - // cout<>t; - - while(t--){ - - solve(); - - } - -} - -","#include - -using namespace std; - -typedef long long ll; - -const int N=100000; - -vector v; - -int CALMEX(vector sex){ - - int m[10]={}; - - for(auto k:sex){ - - m[k]++; - - } - - if(m[0]==0){ - - return 0; - - } - - if(m[1]==0){ - - return 1; - - } - - if(m[2]==0){ - - return 2; - - } - - if(m[3]==0){ - - return 3; - - } - - return 4; - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - int a[n+2]={}; - - vector> g(n+2); - - g[x].push_back(y); - - g[y].push_back(x); - - for(int i=2;i<=n-1;i++){ - - g[i].push_back(i-1); - - g[i].push_back(i+1); - - } - - g[1].push_back(n); - - g[1].push_back(2); - - g[n].push_back(1); - - g[n].push_back(n-1); - - for(int i=1;i<=n;i++){ - - for(auto x:g[i]){ - - // cout<>t; - - while(t--){ - - solve(); - - } - -} - -",1 -emersonjr02,2049C - MEX Cycle,c++20 ,308422528,308422467,"#include - -using namespace std; - - - -#define sws std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - -#define int long long int - -#define float long double - -#define ld long double - -#define ll long long - -#define pb push_back - -#define ff first - -#define ss second - -#define vi vector - -#define vpii vector> - -#define vvi vector> - -#define pii pair - -#define all(x) x.begin(), x.end() - -#define rall(x) x.rbegin(), x.rend() - -#define in(v) for(auto & x : v) cin >> x; - -#define out(v) for(auto x : v) cout << x << ' '; - -#define tiii tuple - -#define tam(x) ((int)x.size()) - - - -const int MAX = 3e5+1; - -const int INF = INT32_MAX; - -int MOD = 1e9+7; - -const int LOG = 31; - -const ld PI = acos(-1); - -const int MINF = INT32_MIN; - -vpii dirs = {{1, 0}, {-1, 0}}; - -vpii dirs1 = {{0, 1}, {0, -1}}; - - - -// Contest patrocinado por Summer - -// meu primeiro amor santos queridooooooo - - - -void solve() { - - - - int n, x, y; cin >> n >> x >> y; - - - - x--; y--; - - - - vi ans(n, -1); - - - - if(n % 2){ - - - - ans[x] = 2; - - - - int start = 1; - - - - for(int i = (x + 1) % n; ans[i] == -1; (i+=1)%=n){ - - - - ans[i] = start; - - - - start = !(start == 1); - - } - - - - cout << '\n'; - - out(ans); - - cout << '\n'; - - return; - - } - - - - if(x % 2 == y % 2) {ans[x] = 2;} - - - - int start = 1, iniPoint = x; - - - - for(int i = (iniPoint + 1) % n; ans[i] > 2 || ans[i] == -1; (i+=1)%=n){ - - - - if(ans[i] != -1) continue; - - ans[i] = start; - - - - start = !(start == 1); - - } - - - - cout << '\n'; - - - - out(ans); - - cout << '\n'; - -} - - - -int32_t main() { - - sws; - - int t = 1; - - cin >> t; - - - - while(t--) - - solve(); - - - -return 0; - -}","#include - -using namespace std; - - - -#define sws std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - -#define int long long int - -#define float long double - -#define ld long double - -#define ll long long - -#define pb push_back - -#define ff first - -#define ss second - -#define vi vector - -#define vpii vector> - -#define vvi vector> - -#define pii pair - -#define all(x) x.begin(), x.end() - -#define rall(x) x.rbegin(), x.rend() - -#define in(v) for(auto & x : v) cin >> x; - -#define out(v) for(auto x : v) cout << x << ' '; - -#define tiii tuple - -#define tam(x) ((int)x.size()) - - - -const int MAX = 3e5+1; - -const int INF = INT32_MAX; - -int MOD = 1e9+7; - -const int LOG = 31; - -const ld PI = acos(-1); - -const int MINF = INT32_MIN; - -vpii dirs = {{1, 0}, {-1, 0}}; - -vpii dirs1 = {{0, 1}, {0, -1}}; - - - -// Contest patrocinado por Summer - -// meu primeiro amor santos queridooooooo - - - -void solve() { - - - - int n, x, y; cin >> n >> x >> y; - - - - x--; y--; - - - - vi ans(n, -1); - - - - - - ans[x] = 2; - - - - int start = 1; - - - - for(int i = (x + 1) % n; ans[i] == -1; (i+=1)%=n){ - - - - ans[i] = start; - - - - start = !(start == 1); - - } - - - - cout << '\n'; - - out(ans); - - cout << '\n'; - - return; - - - - - - if(x % 2 == y % 2) {ans[x] = 2; ans[y] = 3;} - - - - start = 1; - - int iniPoint = x; - - - - if(y - x - 1 == 1){ - - - - ans[x + 1] = 0; - - iniPoint = y; - - } - - - - for(int i = (iniPoint + 1) % n; ans[i] > 2 || ans[i] == -1; (i+=1)%=n){ - - - - if(ans[i] != -1) continue; - - ans[i] = start; - - - - start = !(start == 1); - - } - - - - cout << '\n'; - - - - out(ans); - - cout << '\n'; - -} - - - -int32_t main() { - - sws; - - int t = 1; - - cin >> t; - - - - while(t--) - - solve(); - - - -return 0; - -}",1 -intend,2049C - MEX Cycle,c++20 ,306853983,306850214,"#include - -using namespace std; - -const int N = 2e5+5; - -int n,x,y; - -int ans[N]; - - - -void solve() - -{ - - cin>>n>>x>>y; - - if((y-x)%2==1){ - - if(n&1){ - - for(int i = 1;i < n; i++){ - - if(i&1) cout <<1<<"" ""; - - else cout <<0<<"" ""; - - } - - cout <<2<<'\n'; - - }else{ - - for(int i = 1;i <= n; i++){ - - if(i&1) cout <<1<<"" ""; - - else cout <<0<<"" ""; - - } - - cout <<'\n'; - - } - - }else{ - - if(n&1){ - - for(int i = 1,cnt = 0;i <= n; i++){ - - if(i == x){ - - cout <<2<<"" ""; - - }else{ - - if(cnt&1) cout <<0<<"" ""; - - else cout <<1<<"" ""; - - cnt++; - - } - - } - - cout <<'\n'; - - }else{ - - for(int i = 1;i <= n; i++){ - - if(i&1) ans[i] = 1; - - else ans[i] = 0; - - } - - ans[x] = 2; - - for(int i = 1;i <= n; i++){ - - cout <>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -const int N = 2e5+5; - -int n,x,y; - -int ans[N]; - - - -void solve() - -{ - - cin>>n>>x>>y; - - if(x == 1 || (y-x)%2==1){ - - cout <<2<<"" ""; - - for(int i = 2;i <= n; i++){ - - if(i&1) cout <<0<<"" ""; - - else cout <<1<<"" ""; - - } - - cout <<'\n'; - - }else if((y-x)%2==0){ - - ans[x] = 2; - - for(int i = x+1,cnt = 0;i<=n;i++,cnt++){ - - if(cnt&1) ans[i] = 0; - - else ans[i] = 1; - - } - - for(int i = x-1,cnt = 0;i>=1;i--,cnt++){ - - if(cnt&1) ans[i] = 1; - - else ans[i] = 0; - - } - - for(int i = 1;i <= n ;i++) cout <>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",1 -turneja,2049C - MEX Cycle,c++20 ,304448721,304449098,"#include - -#include - - - -using namespace std; - -using namespace __gnu_pbds; - - - -#define endl ""\n"" - -#define ll long long - -#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); - - - -const int N = 2e5 + 5; - - - -int ans[N]; - - - - - -int main() { - - IOS; - - int t; - - cin >> t; - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - x--, y--; - - if (x > y) { - - swap(x, y); - - } - - for (int i = 0; i < n; i++) { - - ans[i] = -1; - - } - - int i; - - if (y - x == 1 || (x == 0 && y == n - 1)) { - - ans[0] = 0; - - i = 1; - - x = 0; - - } else { - - ans[x] = 0; - - ans[y] = 1; - - int xa = (x + 1) % n, xb = (x - 1 + n) % n; - - int ya = (y + 1) % n, yb = (y - 1 + n) % n; - - ans[xa] = 1; - - ans[xb] = 1; - - ans[ya] = 0; - - ans[yb] = 0; - - if (xa == ya || xa == yb) { - - ans[xa] = 2; - - } - - if (xb == ya || xb == yb) { - - ans[xb] = 2; - - } - - } - - while (i != x) { - - if (ans[i] == -1) { - - set st; - - if (ans[(i - 1 + n) % n] != -1) { - - st.insert(ans[(i - 1 + n) % n]); - - } - - if (ans[(i + 1) % n] != -1) { - - st.insert(ans[(i + 1) % n]); - - } - - if (*st.begin() == 1) { - - ans[i] = 0; - - } else if (*st.rbegin() == 0 || st.size() == 1) { - - ans[i] = 1; - - } else { - - ans[i] = 2; - - } - - } - - i = (i + 1) % n; - - } - - i = x; - - while (i != y) { - - if (ans[i] == -1) { - - set st; - - if (ans[(i - 1 + n) % n] != -1) { - - st.insert(ans[(i - 1 + n) % n]); - - } - - if (ans[(i + 1) % n] != -1) { - - st.insert(ans[(i + 1) % n]); - - } - - if (*st.begin() == 1) { - - ans[i] = 0; - - } else if (*st.rbegin() == 0 || st.size() == 1) { - - ans[i] = 1; - - } else { - - ans[i] = 2; - - } - - } - - i++; - - } - - for (int i = 0; i < n; i++) { - - cout << ans[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -} - -","#include - -#include - - - -using namespace std; - -using namespace __gnu_pbds; - - - -#define endl ""\n"" - -#define ll long long - -#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); - - - -const int N = 2e5 + 5; - - - -int ans[N]; - -int main() { - - IOS; - - int t; - - cin >> t; - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - x--, y--; - - if (x > y) { - - swap(x, y); - - } - - for (int i = 0; i < n; i++) { - - ans[i] = -1; - - } - - int i; - - if (y - x == 1 || (x == 0 && y == n - 1)) { - - ans[0] = 0; - - i = 1; - - x = 0; - - } else { - - ans[x] = 0; - - ans[y] = 1; - - int xa = (x + 1) % n, xb = (x - 1 + n) % n; - - int ya = (y + 1) % n, yb = (y - 1 + n) % n; - - ans[xa] = 1; - - ans[xb] = 1; - - ans[ya] = 0; - - ans[yb] = 0; - - if (xa == ya || xa == yb) { - - ans[xa] = 2; - - } - - if (xb == ya || xb == yb) { - - ans[xb] = 2; - - } - - i = y; - - } - - while (i != x) { - - if (ans[i] == -1) { - - set st; - - if (ans[(i - 1 + n) % n] != -1) { - - st.insert(ans[(i - 1 + n) % n]); - - } - - if (ans[(i + 1) % n] != -1) { - - st.insert(ans[(i + 1) % n]); - - } - - if (*st.begin() == 1) { - - ans[i] = 0; - - } else if (*st.rbegin() == 0 || st.size() == 1) { - - ans[i] = 1; - - } else { - - ans[i] = 2; - - } - - } - - i = (i + 1) % n; - - } - - i = x; - - while (i != y) { - - if (ans[i] == -1) { - - set st; - - if (ans[(i - 1 + n) % n] != -1) { - - st.insert(ans[(i - 1 + n) % n]); - - } - - if (ans[(i + 1) % n] != -1) { - - st.insert(ans[(i + 1) % n]); - - } - - if (*st.begin() == 1) { - - ans[i] = 0; - - } else if (*st.rbegin() == 0 || st.size() == 1) { - - ans[i] = 1; - - } else { - - ans[i] = 2; - - } - - } - - i++; - - } - - for (int i = 0; i < n; i++) { - - cout << ans[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -} - -",2 -Millenialkiid,2049C - MEX Cycle,c++20 ,304734167,304728463,"#include - -using namespace std; - - - -typedef long long ll; - -typedef long long ll; - -typedef vector vi; - -typedef vector vc; - -typedef vector vll; - -typedef unsigned long long ull; - -typedef vector> vpii; - -typedef vector> vpic; - - - -#define for1(i, n1, n2) for(ll i = n1; i < n2; i++) - -#define for2(i, n2, n1) for(ll i = n2; i > n1; i--) - -#define vecMAX(v) *max_element(v.begin(), v.end()) - -#define vecMIN(v) *min_element(v.begin(), v.end()) - -#define srt(v) sort(v.begin(), v.end()) - -#define rev(v) reverse(v.begin(), v.end()) - -#define pb push_back - -#define inx ll p[0]; cin >> p[0]; - -#define vin(v) for(auto &it : v) cin >> it; - -#define mp make_pair - -#define ff first - -#define ss second - -#define v_erase(i) v.erase(v.begin() + i); - -#define sum(v) accumulate(v.begin(), v.end(), 0) - -#define INF 1e9 - -#define MOD 1000000007 - -#define sz(v) ((ll)(v).size()) - -#define Code_by_Millenialkiid ios::sync_with_stdio(0); cin.tie(0); - -#ifndef ONLINE_JUDGE - - - - #include ""Jatt_don't_Care.h"" - -#else - - #define see(...) 42 - -#endif - -void solve() { - -ll n,x,y; - -cin>>n>>x>>y; - -x--,y--; - -if(n%2==0&&abs(x-y)%2){ - - for1(i,0,n)cout<> t; - - - - for (ll i = 0; i < t; i++) { - - #ifndef ONLINE_JUDGE - - - - cout << ""-----------------"" << i + 1 << endl; - - #endif - - - - solve(); - - } - - - - return 0; - -}","#include - -using namespace std; - - - -typedef long long ll; - -typedef long long ll; - -typedef vector vi; - -typedef vector vc; - -typedef vector vll; - -typedef unsigned long long ull; - -typedef vector> vpii; - -typedef vector> vpic; - - - -#define for1(i, n1, n2) for(ll i = n1; i < n2; i++) - -#define for2(i, n2, n1) for(ll i = n2; i > n1; i--) - -#define vecMAX(v) *max_element(v.begin(), v.end()) - -#define vecMIN(v) *min_element(v.begin(), v.end()) - -#define srt(v) sort(v.begin(), v.end()) - -#define rev(v) reverse(v.begin(), v.end()) - -#define pb push_back - -#define inx ll p[0]; cin >> p[0]; - -#define vin(v) for(auto &it : v) cin >> it; - -#define mp make_pair - -#define ff first - -#define ss second - -#define v_erase(i) v.erase(v.begin() + i); - -#define sum(v) accumulate(v.begin(), v.end(), 0) - -#define INF 1e9 - -#define MOD 1000000007 - -#define sz(v) ((ll)(v).size()) - -#define Code_by_Millenialkiid ios::sync_with_stdio(0); cin.tie(0); - -#ifndef ONLINE_JUDGE - - - - #include ""Jatt_don't_Care.h"" - -#else - - #define see(...) 42 - -#endif - -void solve() { - -ll n,x,y; - -cin>>n>>x>>y; - -x--,y--; - -vll ans(n,0); - -for1(i,0,n){ - - if(i%2==1){ - - ans[i]=1; - - } - -} - -if(n%2==1||(x-y)%2==0){ - - ans[x]=2; - -} - -for1(i,0,n){ - - cout<> t; - - - - for (ll i = 0; i < t; i++) { - - #ifndef ONLINE_JUDGE - - - - cout << ""-----------------"" << i + 1 << endl; - - #endif - - - - solve(); - - } - - - - return 0; - -}",1 -2111sahil,2049C - MEX Cycle,c++20 ,305014876,305074920,"// || =================================================================== || - -// || || - -// || Reach Expert by May 2025 || - -// || || - -// || =================================================================== || - -#include - -#define int long long - -#define endl ""\n""; - -#define all(a) a.begin(), a.end() - -#define ONLINE_JUDGE - -using namespace std; - -long long mod_exp(long long base, long long exp, long long mod) { - - long long result = 1; - - while (exp > 0) { - - if (exp % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - vector ans(n + 1); - - for(int i = 1 ; i <= n; i++){ - - if(i & 1){ - - ans[i] = 1; - - }else ans[i] = 0; - - } - - if((x == 1 && y == n) || (x == n && y == 1) || min(x, y) + 1 == max(x, y)){ - - //nothing happens - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - return; - - } - - if(((x % 2 == 0) && (y % 2 == 0)) || ((x % 2 == 1) && (y % 2 == 1))){ - - // // here also nothing happens - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - return; - - } - - ans[(int)max(x, y)] = 2; - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - -} - - - - - -signed main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - int t; - - cin >> t; - - while(t--) - - solve(); - - - -} - - - -/* - -void solve() { - - int n, k; - - cin >> n >> k; - - int r = n, l =1; - - stack> st; - - st.push({l, r}); - - int ans =0LL; - - while(st.size()){ - - auto p = st.top(); - - st.pop(); - - int curL = p.first; - - int curR = p.second; - - if(curR - curL + 1 < k){ - - // do nothing - - }else{ - - int sz = curR - curL + 1; - - if(sz & 1){ - - int m = (curL + curR) / 2LL; - - ans += m; - - cout << ""{"" << curL << "" , "" << curR << ""} : "" << m << endl; - - st.push({curL, m - 1LL}); - - st.push({m + 1LL , curR}); - - }else{ - - int m = (curL + curR) / 2LL; - - st.push({curL, m}); - - st.push({m + 1LL , curR}); - - } - - } - - } - - cout << ans << endl; - -} - - */","// || =================================================================== || - -// || || - -// || Reach Expert by May 2025 || - -// || || - -// || =================================================================== || - -#include - -#define int long long - -#define endl ""\n""; - -#define all(a) a.begin(), a.end() - -#define ONLINE_JUDGE - -using namespace std; - -long long mod_exp(long long base, long long exp, long long mod) { - - long long result = 1; - - while (exp > 0) { - - if (exp % 2 == 1) { - - result = (result * base) % mod; - - } - - base = (base * base) % mod; - - exp /= 2; - - } - - return result; - -} - -int m(set arr){ - - int st = 0; - - for(auto i : arr){ - - if(i == st){ - - // then do nothing - - }else{ - - return st; - - } - - st++; - - } - - return st; - -} - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - // vector> f(n + 1); - - vector ans(n + 1); - - for(int i = 1; i <= n; i++){ - - if(i & 1)ans[i] = 0; - - else ans[i] = 1; - - } - - if((x + y) & 1){ - - // i think it does not matter in case of even n is even only - - if(n % 2 == 0){ - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - }else{ - - for(int i = 1; i < n; i++){ - - cout << ans[i] << "" ""; - - } - - ans[n] = 2; - - cout << 2; - - cout << endl; - - } - - }else{ - - // same number having people are friends - - // so one among them need to have 2 as ans[] - - if(n % 2 == 0){ - - for(int i = 1 ; i <= n; i++){ - - if(i == x){ - - cout << 2 << "" ""; - - ans[i] = 2; - - }else { - - cout << ans[i] << "" ""; - - } - - } - - cout << endl; - - }else{ - - ans[x] = 2; - - int idx = x - 1; - - if(idx == 0) idx = n; - - int cnt = 1; - - int val = 0; - - while(cnt < n){ - - ans[idx] = val; - - val = !val; - - cnt++; - - idx--; - - if(idx == 0) idx = n; - - } - - for(int i = 1; i <= n; i++){ - - cout << ans[i] << "" ""; - - } - - cout << endl; - - } - - } - - //validation - - vector> f(n + 1); - - for(int i = 1; i <= n; i++){ - - int nxt = i + 1; - - int prev = i - 1; - - if(nxt == n + 1) nxt = 1; - - if(prev == 0) prev = n; - - f[i].insert(nxt); - - f[i].insert(prev); - - } - - f[x].insert(y); - - f[y].insert(x); - - - - // for(int i = 1; i <= n; i++) - - // cout << ans[i] << "" ""; - - // cout << endl; - - for(int i = 1; i <=n; i++){ - - set friendsMx; - - // cout << ""friends of "" << i << "" : "" ; - - for(auto j : f[i]){ - - // cout << j << "" , "" << ans[j] << "" ; ""; - - friendsMx.insert(ans[j]); - - } - - // cout << endl; - - // cout << ""M value for "" << i << "" is "" << m(friendsMx) << endl; - - // cout << ""Ans value for "" << i << "" is "" << ans[i] << endl; - - int m_val = m(friendsMx); - - if(m_val != ans[i]){ - - cout << ""wrong for "" << i << endl; - - } - - } - - - - - - - -} - - - - - -signed main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - int t; - - cin >> t; - - while(t--) - - solve(); - - - -} - - - -/* - -void solve() { - - int n, k; - - cin >> n >> k; - - int r = n, l =1; - - stack> st; - - st.push({l, r}); - - int ans =0LL; - - while(st.size()){ - - auto p = st.top(); - - st.pop(); - - int curL = p.first; - - int curR = p.second; - - if(curR - curL + 1 < k){ - - // do nothing - - }else{ - - int sz = curR - curL + 1; - - if(sz & 1){ - - int m = (curL + curR) / 2LL; - - ans += m; - - cout << ""{"" << curL << "" , "" << curR << ""} : "" << m << endl; - - st.push({curL, m - 1LL}); - - st.push({m + 1LL , curR}); - - }else{ - - int m = (curL + curR) / 2LL; - - st.push({curL, m}); - - st.push({m + 1LL , curR}); - - } - - } - - } - - cout << ans << endl; - -} - - */",2 -zihaojf,2049C - MEX Cycle,c++23 ,307537938,307537794,"#include - -using namespace std; - -#define endl '\n' - -#define int long long - -const int inf = 0x7f7f7f7f; - -const int mod = 1e9+7; - - - -long long ksm(long long a,long long b){ - - if(b==0) return 1; - - long long ans = 1; - - while(b>0){ - - if(b & 1){ - - ans= ans * a % mod; - - } - - a = a * a % mod; - - b>>=1; - - } - - return ans; - -} - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - y--;x--; - - vector ans(n); - - for(int i = 0;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}","#include - -using namespace std; - -#define endl '\n' - -#define int long long - -const int inf = 0x7f7f7f7f; - -const int mod = 1e9+7; - - - -long long ksm(long long a,long long b){ - - if(b==0) return 1; - - long long ans = 1; - - while(b>0){ - - if(b & 1){ - - ans= ans * a % mod; - - } - - a = a * a % mod; - - b>>=1; - - } - - return ans; - -} - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - vector ans(n); - - for(int i = 0;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}",1 -Laoqiang--wiLLAC,2049C - MEX Cycle,c++23 ,308281044,308284797,"#include - -using namespace std; - - - -#define endl '\n' - -#define int long long - -#define PII std::pair - -#define all(a) (a).begin(),(a).end() - - - -using i64 = long long; - -using i128 = __int128; - -using u64 = unsigned long long; - - - -constexpr int N = 2e6 + 5; - -constexpr i64 INF = LLONG_MAX; - -constexpr double eps = 1e-10; - -constexpr int mod = 998244353; - -constexpr int MOD = 1e9 + 7; - - - -void Main() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - if (abs(x - y) == 1) { - - int flag = 0, be = 1 + n % 2; - - cout << be << "" \n""[n == 1]; - - for (int i = 2; i <= n; i++) { - - cout << flag << "" \n""[i == n]; - - flag ^= 1; - - } - - return; - - } - - vector ans(n + 1); - - int flag = 0; - - for (int i = 1; i <= n; i++) { - - ans[i] = flag++; - - flag %= 3; - - } - - if (n % 3 == 1) { - - swap(ans[n], ans[n - 1]); - - } - - if (ans[x] == ans[y]) { - - ans[y] = 3; - - } - - for (int i = 1; i <= n; i++) { - - cout << ans[i] << "" \n""[i == n]; - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(0), std::cout.tie(0); - - int T = 1; - - std::cin >> T; - - while (T--) { - - Main(); - - } - - return 0; - -}","#include - -using namespace std; - - - -#define endl '\n' - -#define int long long - -#define PII std::pair - -#define all(a) (a).begin(),(a).end() - - - -using i64 = long long; - -using i128 = __int128; - -using u64 = unsigned long long; - - - -constexpr int N = 2e6 + 5; - -constexpr i64 INF = LLONG_MAX; - -constexpr double eps = 1e-10; - -constexpr int mod = 998244353; - -constexpr int MOD = 1e9 + 7; - - - -void Main() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - x--, y--; - - vector ans(n); - - for (int i = 0; i < n; i++) { - - ans[(x + i) % n] = i % 2; - - } - - if (n % 2 || !((x - y) & 1)) { - - ans[x] = 2; - - } - - - - for (int i = 0; i < n; i++) { - - cout << ans[i] << "" \n""[i == n - 1]; - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(0), std::cout.tie(0); - - int T = 1; - - std::cin >> T; - - while (T--) { - - Main(); - - } - - return 0; - -}",2 -Saurav_576,2049C - MEX Cycle,c++17 ,304965259,304965382,"#include - -using namespace std; - - - -void solve(){ - - int n,x,y; - -cin>>n>>x>>y; - - - -int a[n]; - -for(int i=0;i>t; - - while(t--) - - { - - solve(); - -} - -} - - - - - - - -","#include - -using namespace std; - - - -void solve(){ - - int n,x,y; - -cin>>n>>x>>y; - - --x;--y; - -int a[n]; - -for(int i=0;i>t; - - while(t--) - - { - - solve(); - -} - -}",2 -qwerty1236,2049C - MEX Cycle,python,308029544,308029345,"def main(): - - - - for _ in range(int(input())): - - - - n,x,y = map(int,input().split()) - - - - x -= 1 - - y -=1 - - - - ans = [0] * n - - - - - - for i in range(n): - - - - ans[(x + i) %n] = i % 2 - - - - - - if n % 2 != 0 or (x - y) % 2 == 0: - - ans[x] = 2 - - - - - - print(*ans) - - - - - - - -if __name__ == ""__main__"": - - main()","def main(): - - - - for _ in range(int(input())): - - - - n,x,y = map(int,input().split()) - - - - - - - - ans = [0] * n - - - - - - for i in range(n): - - - - ans[(x + i) %n] = i % 2 - - - - - - if n % 2 != 0 or (x - y) % 2 == 0: - - ans[x] = 2 - - - - - - print(*ans) - - - - - - - -if __name__ == ""__main__"": - - main()",1 -Laoqiang--wiLLAC,2049C - MEX Cycle,c++23 ,308281454,308284797,"#include - -using namespace std; - - - -#define endl '\n' - -#define int long long - -#define PII std::pair - -#define all(a) (a).begin(),(a).end() - - - -using i64 = long long; - -using i128 = __int128; - -using u64 = unsigned long long; - - - -constexpr int N = 2e6 + 5; - -constexpr i64 INF = LLONG_MAX; - -constexpr double eps = 1e-10; - -constexpr int mod = 998244353; - -constexpr int MOD = 1e9 + 7; - - - -void Main() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - if (abs(x - y) == 1) { - - int flag = 0, be = 1 + n % 2; - - cout << be << "" \n""[n == 1]; - - for (int i = 2; i <= n; i++) { - - cout << flag << "" \n""[i == n]; - - flag ^= 1; - - } - - return; - - } - - vector ans(n + 1); - - int flag = 0; - - for (int i = 1; i <= n; i++) { - - ans[i] = flag; - - flag ^= 1; - - } - - if (n % 2 == 1) { - - ans[n] = 2; - - } - - if (ans[x] == ans[y]) { - - ans[y] = 2; - - } - - for (int i = 1; i <= n; i++) { - - cout << ans[i] << "" \n""[i == n]; - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(0), std::cout.tie(0); - - int T = 1; - - std::cin >> T; - - while (T--) { - - Main(); - - } - - return 0; - -}","#include - -using namespace std; - - - -#define endl '\n' - -#define int long long - -#define PII std::pair - -#define all(a) (a).begin(),(a).end() - - - -using i64 = long long; - -using i128 = __int128; - -using u64 = unsigned long long; - - - -constexpr int N = 2e6 + 5; - -constexpr i64 INF = LLONG_MAX; - -constexpr double eps = 1e-10; - -constexpr int mod = 998244353; - -constexpr int MOD = 1e9 + 7; - - - -void Main() - -{ - - int n, x, y; - - cin >> n >> x >> y; - - x--, y--; - - vector ans(n); - - for (int i = 0; i < n; i++) { - - ans[(x + i) % n] = i % 2; - - } - - if (n % 2 || !((x - y) & 1)) { - - ans[x] = 2; - - } - - - - for (int i = 0; i < n; i++) { - - cout << ans[i] << "" \n""[i == n - 1]; - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(0), std::cout.tie(0); - - int T = 1; - - std::cin >> T; - - while (T--) { - - Main(); - - } - - return 0; - -}",2 -Domzi1,2049C - MEX Cycle,c++23 ,306913515,306912570,"#include - -#include - -#define max(a, b) (a < b ? b : a) - -#define min(a, b) ((a > b) ? b : a) - -#define SZ(X) ((int)(X).size()) - -#define ALL(X) (X).begin(), (X).end() - -#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) - -typedef long long int ll; - -typedef std::vector vi; - -typedef std::pair pi; - -#define clr(arr,value) memset(arr,value,sizeof(arr)) - -#define F first - -#define S second - -//#define int long long - -#define el '\n' - -#define OO 100000000000000 - -const ll MOD = 1e9 +7; - -const int N = 2e5+5; - -using namespace std; - -typedef unordered_map> HASHSET ; - - - - - - - - - -int dx []= {0,0,1,-1,-1,1,-1,1}; - -int dy []= {1,-1,0,0,-1,1,1,-1}; - - - - - - - -void PLAY(){ - - int n , x, y; - - cin >> n >> x>> y; - - --x;--y; - - vi ans(n); - - bool f = x&1?1:0; - - for (int i = 0; i < n; ++i) { - - ans[i] = (i&1?f:!f); - - } - - if (n&1)ans[n-1]=2; - - if (!(abs(x-y)==1 || ans[x] != ans[y] || y-x == n-1)){ - - x = (x == 0)?y:x; - - ans[x] = 2; - - } - - for (int i = 0; i < n; ++i) { - - cout << ans[i] << ' '; - - } - - cout << el; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - -// freopen(""input.txt"",""r"",stdin); - -// freopen(""output.txt"", ""w"", stdout); - - int T = 1 ; - - cin >> T; - - - - while (T--){ - - PLAY(); - - } - - - - return 0; - - - -}","#include - -#include - -#define max(a, b) (a < b ? b : a) - -#define min(a, b) ((a > b) ? b : a) - -#define SZ(X) ((int)(X).size()) - -#define ALL(X) (X).begin(), (X).end() - -#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) - -typedef long long int ll; - -typedef std::vector vi; - -typedef std::pair pi; - -#define clr(arr,value) memset(arr,value,sizeof(arr)) - -#define F first - -#define S second - -//#define int long long - -#define el '\n' - -#define OO 100000000000000 - -const ll MOD = 1e9 +7; - -const int N = 2e5+5; - -using namespace std; - -typedef unordered_map> HASHSET ; - - - - - - - - - -int dx []= {0,0,1,-1,-1,1,-1,1}; - -int dy []= {1,-1,0,0,-1,1,1,-1}; - - - - - - - -void PLAY(){ - - int n , x, y; - - cin >> n >> x>> y; - - --x;--y; - - vi ans(n); - - for (int i = 0; i < n; ++i) { - - ans[i] = (i&1?1:0); - - } - - if (n&1)ans[n-1]=2; - - if (!(abs(x-y)==1 || ans[x] != ans[y] || y-x == n-1)){ - - x = (x == 0)?y:x; - - ans[x] = 2; - - } - - for (int i = 0; i < n; ++i) { - - cout << ans[i] << ' '; - - } - - cout << el; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - -// freopen(""input.txt"",""r"",stdin); - -// freopen(""output.txt"", ""w"", stdout); - - int T = 1 ; - - cin >> T; - - - - while (T--){ - - PLAY(); - - } - - - - return 0; - - - -}",1 -falcZhang#,2049C - MEX Cycle,c++20 ,306159881,306161844,"#include - -using namespace std; - -long long n,m,t,k1,k2; - -long long zs,zp,ys,yp; - -string s1; - - - -int main() - -{ - - cin>>t; - - for(int o=1;o<=t;++o){ - - cin>>n>>k1>>k2; - - for(int i=1;i<=n;++i){ - - if(i%3==1)cout<<0<<"" ""; - - else if(i%3==2)cout<<1<<"" ""; - - else if(i%3==0)cout<<2<<"" ""; - - } - - cout< - -using namespace std; - -long long n,m,t,k1,k2; - -long long zs,zp,ys,yp; - -vector a; - -string s1; - - - -int main() - -{ - - cin>>t; - - for(int o=1;o<=t;++o){ - - cin>>n>>k1>>k2; - - a.clear(); - - for(int i=1;i - -using namespace std; - -#define int long long - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - vectora(n+1,0); - - for(int i=1;i<=n;i++){ - - if(i%2){ - - a[i]=0; - - }else{ - - a[i]=1; - - } - - } - - if(n%2==1) a[1]=2; - - if(a[x]==a[y]){ - - if(y==n&&a[1]==2) a[y]=2,a[1]=0; - - else a[y]=2; - - } - - for(int i=1;i<=n;i++){ - - cout<> t; - - - - while (t--) { - - solve(); - - } - -}","#include - -using namespace std; - -#define int long long - -void solve() { - - int n,x,y; - - cin>>n>>x>>y; - - vectora(n+1,0); - - for(int i=1;i<=n;i++){ - - if(i%2){ - - a[i]=0; - - }else{ - - a[i]=1; - - } - - } - - if(n%2==1) a[1]=2; - - if(a[x]==a[y]){ - - a[y]=2; - - } - - for(int i=1;i<=n;i++){ - - cout<> t; - - - - while (t--) { - - solve(); - - } - -}",1 -gauravbro17,2049C - MEX Cycle,c++17 ,303907864,303908277,"#include - -using namespace std; - -#define int long long - -#define pb push_back - -#define ff first - -#define ss second - -#define pii pair - -#define vi vector - -#define vii vector> - - - -void solve() - -{ - - int n,x,y; - - cin >> n>>x>>y; - - vi v(n); - - if(x>y)swap(x,y); - - for(int i=0; i> tcs; - - while (tcs--) - - { - - solve(); - - } - -}","#include - -using namespace std; - -#define int long long - -#define pb push_back - -#define ff first - -#define ss second - -#define pii pair - -#define vi vector - -#define vii vector> - - - -void solve() - -{ - - int n,x,y; - - cin >> n>>x>>y; - - vi v(n); - - x--,y--; - - for(int i=0; i> tcs; - - while (tcs--) - - { - - solve(); - - } - -}",2 -sunset1231,2049C - MEX Cycle,c++20 ,305776766,305777747,"#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) ans[max(x, y)] = 2; - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -","#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) { - - ans[max(x, y)] = 2; - - if(y == n - 2 && ans[n - 1] == 2) {ans[n - 1] = 1;} - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - } - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -",2 -destructor_89,2049C - MEX Cycle,c++20 ,303706526,303704957,"/*⣿⣿⣿⣿⣿⣿⣿⣻⠿⣝⡿⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⢫⡿⣽⢣⡒⡄⠲⡐⢄⠢⠀⠀⢀⠠⣽ - - ⣿⣿⣿⣿⣿⣿⣿⣻⣿⠙⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢫⢿⡽⣣⠕⡨⢁⠉⢂⠁⠠⠐⣤⣿⣿ - - ⣿⣿⣿⣿⣿⣻⣿⣟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠫⣗⢇⢢⠐⠌⡰⠀⣌⣶⣿⡟⠓⢉ - - ⣟⠬⡛⠽⠻⠿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣾⠡⢎⠢⣱⣿⡿⣟⠚⣌⢡⢆ - - ⣿⢻⡶⣍⡀⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢫⠘⢂⣴⣿⠏⠉⠄⠉⠀⡁⠈ - - ⡛⢷⣶⣍⡛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀���⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⡿⢋⡰⢌⡑⢀⠂⠡⣄⢣ - - ⣭⠒⣌⡉⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⢦⣑⠣⠐⢂⠌⡳⢬⣷ - - ⢇⠏⡴⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠄⡀⠄⠀⢂⠨⣴⣻⣿ - - ⣜⡸⡠⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡠⢀⡜⠠⢄⣧⣿⣿⣿ - - ⣎⢵⣛⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣗⣨⣴⠾⠛⣩⣵⡾⠿ - - ⣿⣾⣽⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⠀⢽⣆⠀⠀⠀⠀⠀⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣻⣭⡴⠶⢛⠫⠑⠂⠁ - - ⡝⣜⠳⡃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⡏⠀⢺⣿⠀⠀⠀⠀⠀⣿⣇⡀⠆⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠄⠀⠀⠀⠀⠀⠀⠀ - - ⡼⢶⣟⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⡆⣿⣿⣿⣿⠁⣀⢸⣿⠀⠀⠀⠀⢰⣿⣿⠡⠘⠄⣠⡀⠀⠀⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠘⣎⠳⠌⠂⠄⠀⠀⠄ - - ⣿⡭⢪⠅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⢸⣷⠸⣿⣿⣿⣷⢹⡌⣿⣸⢠⣴⣶⣿⣿⣿⣼⡦⠟⠛⠛⠃⠐⠥⠠⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣳⣮⣳⡌⣤⢤⣰⣤⣶ - - ⢧⡈⠳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⡄⠿⠘⠛⠂⠙⠛⠻⣿⣏⢿⣼⣿⣿⣿⣿⣿⣿⢋⣠⣤⠶⠶⢶⣶⣷⣶⣶⣶⣴⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡷⣷⣷⣾⣤⣿⣿⣿⠭ - - ⣶⡜⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⢘⣩⣤⣶⣶⣶⣿⣿⣯⣭⡝⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢁⠟⠍⠁⠀⡀⠈⡉⢻⣿⣿⠂⠀⠀⠀⠀⢀⣠⠀⠀⠀⠀⠀⣤⡾⠛⢉⣀⣤⣴ - - ⣿⣿⣳⡂⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⠟⠉⠉⠀⠠⠀⠉⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣼⡀⠀⠀⠀⠀⣿⠀⢿⣿⡄⠓⠦⢄⢀⠞⠁⠀⠀⢲⣷⠿⠛⠓⠛⠉⠍⠉⠀ - - ⣿⡷⣯⢿⡄⠔⡀⠀⠀⠀⠀⣧⡘⣾⣿⠄⢰⣇⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⡻⠶⠤⠴⠞⢋⣼⣿⣿⠀⠀⠀⣠⠟⢤⡀⠀⠀⠈⠍⠂⠀⠀⠈⠁⠈⠀⠀ - - ⣿⣿⡿⣯⢿⡼⢷⠀⡀⠀⠀⠠⢹⣿⣿⣶⣀⠙⠷⠶⠶⣛⣥⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢠⠞⠉⠀⠀⠁⠀⠀⠀⡀⢀⠀⠀⢀⣀⣤⠴⠞ - - ⣟⣯⢿⡝⠉⠀⡘⣄⠐⠀⠐⢤⡀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⣯⣽⢾⣛⣫⡽⠶⠛⢋ - - ⠿⣚⣳⠌⡐⠠⠑⠨⠁⠠⠀⠀⠙⠒⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⠷⣚⢫⢛⠲⣜⠢⡁⢆ - - ⣿⣿⣿⣟⣷⣶⣷⣶⣶⣶⠗⠀⠀⠀⠐⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⢠⣄⡡⠀⠢⠌⡱⡌⡄⢑⠪ - - ⣿⣿⡿⣿⢿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⡟⣧⢃⠂⠤⢡⣙⠘⡄⠂ - - ⣿⡷⣿⢿⢿⡛⣡⢶⡒⠆⠀⠀⠀⠀⠀⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠲⠜⡁⠊⠐⠈⠂⠙⠮⠐⡀ - - ⣿⣽⠋⠁⢠⠘⣵⢫⡝⣤⠀⠀⠀⠀⠀⠀⠀⠀⠈⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣭⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⠐⡆⠂⡄⠀⠀⠀⠀⠀⠀⠀⠀ - - ⠉⠠⣌⠰⢀⠱⣌⠷⢣⠅⠀⣀⡀⠢⢀⠔⡠⠂⠀⠀⣄⠙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣫⣤⠀⣀⠠⡖⡁⠀⠀⠀⠀⠸⣁⠣⢘⠐⠠⠀⠀⠀⠀⠀⠀⠀⠀ - - ⣴⡿⡎⠔⠠⡁⢆⡋⢇⠊⢰⠽⡁⢀⠂⠆⠠⠁⠀⢠⡟⢸⣿⠆⣽⣻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠈⠜⡠⢀⠁⠀⠀⠀⠀⡳⣔⡢⢄⠊⡄⢠⠀⡀⠀⡀⢀⠀⣀ - - ⣿⡝⣡⠋⡐⡐⠢⠙⡌⢢⢉⠒⠀⠂⠌⠠⢁⠂⢠⡿⢠⣿⡿⢀⣿⣿⣿⣾⣟⣛⣿⣿⣿⣛⣯⣿⣿⣿⣿⣿⣿⣿⡇⢨⣷⣒⠀⠀⠀⠀⢀⡳⣜⢿⢯⡷⣼⣥⣙⠶⣽⣜⣣⢻⡴ - - ⠣⠈⡄⢣⠐⠁⢡⠚⠬⡁⢂⡱⢈⡐⢈⠐⡠⠂⣼⠇⣾⣿⢃⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢻⡆⠀⠀⠀⠀⡼⢑⢮⡏⡟⠽⢣⠙⢋⠎⠱⠋⠖⢣⠙ - - ⠀⠐⡈⢄⠰⠈⠠⣉⠦⣑⢦⡕⣣⠐⡂⠐⠀⣼⣻⡼⠟⣡⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠁⠀⠀⠀⢸⣝⡞⢦⡙⢬⢃⠂⠁⠀⠀⠀⠀⠈⠀⠀ - - ⠀⢆⡸⢌⢆⠡⣧⢷⡺⣝⡾⣽⢧⣛⠴⠉⠞⣋⣥⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⣏⢾⡹⣧⠞⣄⠂⠌⠀⠀⠀⠀⡀⠀⠀⠀ - - ⡜⣢⢝⡲⣎⡷⠽⠳⢛⣙⣉⣉⣡⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⣤⣈⠒⠽⣳⡟⣬⢋⠄⠀⠀⠀⠀⠀⠀⠐⠀ - - ⠸⡁⢎⣡⣷⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⢸⣿⣿⣿⣶⣤⣌⣀⠉⠂ */ - - - -#include - -#include - -#include - -#include - -using namespace __gnu_pbds; - -using namespace std; - - - -#define ct(v) for(auto i:v){cout<>i;} - -#define all(a) a.begin(),a.end() - -#define rall(a) a.rbegin(),a.rend() - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -#define sv(v) sort(v.begin(),v.end()) - -#define en ""\n"" - -#define pb push_back - -#define ppb pop_back - -#define mpr make_pair - -#define ff first - -#define ss second - - - -#define atulmultiset tree, rb_tree_tag,tree_order_statistics_node_update> - -#define atulset tree, rb_tree_tag,tree_order_statistics_node_update> //atulset ss; - -//ss.*find_by_order(index); - -//ss.order_of_key(element) index; - - - - - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - -#define int ll - - - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define PI 3.141592653589793238462 - - - -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;} - - - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(unordered_set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(unordered_set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - - - - -int binExp(int a , int b ){ // O(log(b)) - - int ans = 1; // if a is very large then ---->>a%=M; - - while(b){ - - if(b&1){ - - ans=(ans*a)%MOD; // ans = (ans*1ll*a)%M use binMultiply if M is big (M->1e18) - - } - - a=(a*a)%MOD; // a = (a*1ll*a)%M; use binMultiply if M=1e18 - - b>>=1; - - } - - return ans ; - -} - - - -void atulmultiseterase(atulmultiset &t, int v){ - - int rank = t.order_of_key(v); - - atulmultiset::iterator it = t.find_by_order(rank); - - t.erase(it); - -} - -void atulseterase(atulset &t, int v){ - - int rank = t.order_of_key(v); - - atulset::iterator it = t.find_by_order(rank); - - t.erase(it); - -} - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - - - -int fact(int y) - -{ - - if (y==0) return 1; - - else return y*fact(y-1); - -} - - - -void solve() - -{ - - int n,a,b;cin>>n>>a>>b;vectorv(n); - - for (int i=0; i>ts; - - while(ts--) - - { - - solve(); - - } - -} - -","/*⣿⣿⣿⣿⣿⣿⣿⣻⠿⣝⡿⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⢫⡿⣽⢣⡒⡄⠲⡐⢄⠢⠀⠀⢀⠠⣽ - - ⣿⣿⣿⣿⣿⣿⣿⣻⣿⠙⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢫⢿⡽⣣⠕⡨⢁⠉⢂⠁⠠⠐⣤⣿⣿ - - ⣿⣿⣿⣿⣿⣻⣿⣟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠫���⢇⢢⠐⠌⡰⠀⣌⣶⣿⡟⠓⢉ - - ⣟⠬⡛⠽⠻⠿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣾⠡⢎⠢⣱⣿⡿⣟⠚⣌⢡⢆ - - ⣿⢻⡶⣍⡀⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢫⠘⢂⣴⣿⠏⠉⠄⠉⠀⡁⠈ - - ⡛⢷⣶⣍⡛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⡿⢋⡰⢌⡑⢀⠂⠡⣄⢣ - - ⣭⠒⣌⡉⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⢦⣑⠣⠐⢂⠌⡳⢬⣷ - - ⢇⠏⡴⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠄⡀⠄⠀⢂⠨⣴⣻⣿ - - ⣜⡸⡠⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡠⢀⡜⠠⢄⣧⣿⣿⣿ - - ⣎⢵⣛⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣗⣨⣴⠾⠛⣩⣵⡾⠿ - - ⣿⣾⣽⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⠀⢽⣆⠀⠀⠀⠀⠀⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣻⣭⡴⠶⢛⠫⠑⠂⠁ - - ⡝⣜⠳⡃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⡏⠀⢺⣿⠀⠀⠀⠀⠀⣿⣇⡀⠆⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠄⠀⠀⠀⠀⠀⠀⠀ - - ⡼⢶⣟⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⡆⣿⣿⣿⣿⠁⣀⢸⣿⠀⠀⠀⠀⢰⣿⣿⠡⠘⠄⣠⡀⠀⠀⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠘⣎⠳⠌⠂⠄⠀⠀⠄ - - ⣿⡭⢪⠅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⢸⣷⠸⣿⣿⣿⣷⢹⡌⣿⣸⢠⣴⣶⣿⣿⣿⣼⡦⠟⠛⠛⠃⠐⠥⠠⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣳⣮⣳⡌⣤⢤⣰⣤⣶ - - ⢧⡈⠳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⡄⠿⠘⠛⠂⠙⠛⠻⣿⣏⢿⣼⣿⣿⣿⣿⣿⣿⢋⣠⣤⠶⠶⢶⣶⣷⣶⣶⣶⣴⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⡷⣷⣷⣾⣤⣿⣿⣿⠭ - - ⣶⡜⢤⠀⠀⠀⠀⠀⠀⠀⠀⠀⢘⣩⣤⣶⣶⣶⣿⣿⣯⣭⡝⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢁⠟⠍⠁⠀⡀⠈⡉⢻⣿⣿⠂⠀⠀⠀⠀⢀⣠⠀⠀⠀⠀⠀⣤⡾⠛⢉⣀⣤⣴ - - ⣿⣿⣳⡂⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⠟⠉⠉⠀⠠⠀⠉⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣼⡀⠀⠀⠀⠀⣿⠀⢿⣿⡄⠓⠦⢄⢀⠞⠁⠀⠀⢲⣷⠿⠛⠓⠛⠉⠍⠉⠀ - - ⣿⡷⣯⢿⡄⠔⡀⠀⠀⠀⠀⣧⡘⣾⣿⠄⢰⣇⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⡻⠶⠤⠴⠞⢋⣼⣿⣿⠀⠀⠀⣠⠟⢤⡀⠀⠀⠈⠍⠂⠀⠀⠈⠁⠈⠀⠀ - - ⣿⣿⡿⣯⢿⡼⢷⠀⡀⠀⠀⠠⢹⣿⣿⣶⣀⠙⠷⠶⠶⣛⣥⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢠⠞⠉⠀⠀⠁⠀⠀⠀⡀⢀⠀⠀⢀⣀⣤⠴⠞ - - ⣟⣯⢿⡝⠉⠀⡘⣄⠐⠀⠐⢤⡀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧⣯⣽⢾⣛⣫⡽⠶⠛⢋ - - ⠿⣚⣳⠌⡐⠠⠑⠨⠁⠠⠀⠀⠙⠒⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⠷⣚⢫⢛⠲⣜⠢⡁⢆ - - ⣿⣿⣿⣟⣷⣶⣷⣶⣶⣶⠗⠀⠀⠀⠐⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⢠⣄⡡⠀⠢⠌⡱⡌⡄⢑⠪ - - ⣿⣿⡿⣿⢿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⡟⣧⢃⠂⠤⢡⣙⠘⡄⠂ - - ⣿⡷⣿⢿⢿⡛⣡⢶⡒⠆⠀⠀⠀⠀⠀⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠲⠜⡁⠊⠐⠈⠂⠙⠮⠐⡀ - - ⣿⣽⠋⠁⢠⠘⣵⢫⡝⣤⠀⠀⠀⠀⠀⠀⠀⠀⠈⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣭⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⠐⡆⠂⡄⠀⠀⠀⠀⠀⠀⠀⠀ - - ⠉⠠⣌⠰⢀⠱⣌⠷⢣⠅⠀⣀⡀⠢⢀⠔⡠⠂⠀⠀⣄⠙⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣫⣤⠀⣀⠠⡖⡁⠀⠀⠀⠀⠸⣁⠣⢘⠐⠠⠀⠀⠀⠀⠀⠀⠀⠀ - - ⣴⡿⡎⠔⠠⡁⢆⡋⢇⠊⢰⠽⡁⢀⠂⠆⠠⠁⠀⢠⡟⢸⣿⠆⣽⣻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠈⠜⡠⢀⠁⠀⠀⠀⠀⡳⣔⡢⢄⠊⡄⢠⠀⡀⠀⡀⢀⠀⣀ - - ⣿⡝⣡⠋⡐⡐⠢⠙⡌⢢⢉⠒⠀⠂⠌⠠⢁⠂⢠⡿⢠⣿⡿⢀⣿⣿⣿⣾⣟⣛⣿⣿⣿⣛⣯⣿⣿⣿⣿⣿⣿⣿⡇⢨⣷⣒⠀⠀⠀⠀⢀⡳⣜⢿⢯⡷⣼⣥⣙⠶⣽⣜⣣⢻⡴ - - ⠣⠈⡄⢣⠐⠁⢡⠚⠬⡁⢂⡱⢈⡐⢈⠐⡠⠂⣼⠇⣾⣿⢃⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢻⡆⠀⠀⠀⠀⡼⢑⢮⡏⡟⠽⢣⠙⢋⠎⠱⠋⠖⢣⠙ - - ⠀⠐⡈⢄⠰⠈⠠⣉⠦⣑⢦⡕⣣⠐⡂⠐⠀⣼⣻⡼⠟⣡⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠁⠀⠀⠀⢸⣝⡞⢦⡙⢬⢃⠂⠁⠀⠀⠀⠀⠈⠀⠀ - - ⠀⢆⡸⢌⢆⠡⣧⢷⡺⣝⡾⣽⢧⣛⠴⠉⠞⣋⣥⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⣏⢾⡹⣧⠞⣄⠂⠌⠀⠀⠀⠀⡀⠀⠀⠀ - - ⡜⣢⢝⡲⣎⡷⠽⠳⢛⣙⣉⣉⣡⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠀⠀⣤⣈⠒⠽⣳⡟⣬⢋⠄⠀⠀⠀⠀⠀⠀⠐⠀ - - ⠸⡁⢎⣡⣷⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⢸⣿⣿⣿⣶⣤⣌⣀⠉⠂ */ - - - -#include - -#include - -#include - -#include - -using namespace __gnu_pbds; - -using namespace std; - - - -#define ct(v) for(auto i:v){cout<>i;} - -#define all(a) a.begin(),a.end() - -#define rall(a) a.rbegin(),a.rend() - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -#define sv(v) sort(v.begin(),v.end()) - -#define en ""\n"" - -#define pb push_back - -#define ppb pop_back - -#define mpr make_pair - -#define ff first - -#define ss second - - - -#define atulmultiset tree, rb_tree_tag,tree_order_statistics_node_update> - -#define atulset tree, rb_tree_tag,tree_order_statistics_node_update> //atulset ss; - -//ss.*find_by_order(index); - -//ss.order_of_key(element) index; - - - - - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - -#define int ll - - - -#define MOD 1000000007 - -#define MOD1 998244353 - -#define INF 1e18 - -#define PI 3.141592653589793238462 - - - -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;} - - - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(unordered_set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(unordered_set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - - - - -int binExp(int a , int b ){ // O(log(b)) - - int ans = 1; // if a is very large then ---->>a%=M; - - while(b){ - - if(b&1){ - - ans=(ans*a)%MOD; // ans = (ans*1ll*a)%M use binMultiply if M is big (M->1e18) - - } - - a=(a*a)%MOD; // a = (a*1ll*a)%M; use binMultiply if M=1e18 - - b>>=1; - - } - - return ans ; - -} - - - -void atulmultiseterase(atulmultiset &t, int v){ - - int rank = t.order_of_key(v); - - atulmultiset::iterator it = t.find_by_order(rank); - - t.erase(it); - -} - -void atulseterase(atulset &t, int v){ - - int rank = t.order_of_key(v); - - atulset::iterator it = t.find_by_order(rank); - - t.erase(it); - -} - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - - - -int fact(int y) - -{ - - if (y==0) return 1; - - else return y*fact(y-1); - -} - - - -void solve() - -{ - - int n,a,b;cin>>n>>a>>b;vectorv(n); - - for (int i=0; i>ts; - - while(ts--) - - { - - solve(); - - } - -} - -",1 -Linly.,2049C - MEX Cycle,c++20 ,303957715,303957968,"#pragma GCC optimize(2) - -#include - -using namespace std; - -#define ll long long - -const int INF=0x3f3f3f3f; - -const int mod=1e9+7; - -const int N=200005; - - - -int a[N]; - -void solve(){ - - int n,x,y;cin>>n>>x>>y; - - for(int i=1;i<=n;i++)a[i]=i%2; - - if(n%2)a[n]=2; - - if(a[x]==a[y]){ - - if(a[n]==2){ - - for(int i=1;i>_; - - while(_--){ - - solve(); - - } - - return 0; - -}","#pragma GCC optimize(2) - -#include - -using namespace std; - -#define ll long long - -const int INF=0x3f3f3f3f; - -const int mod=1e9+7; - -const int N=200005; - - - -int a[N]; - -void solve(){ - - int n,x,y;cin>>n>>x>>y; - - for(int i=1;i<=n;i++)a[i]=i%2; - - if(n%2)a[n]=2; - - if(a[x]==a[y]){ - - if(a[n]==2){ - - for(int i=1;i>_; - - while(_--){ - - solve(); - - } - - return 0; - -}",2 -Millenialkiid,2049C - MEX Cycle,c++20 ,304731273,304734167,"#include - -using namespace std; - - - -typedef long long ll; - -typedef long long ll; - -typedef vector vi; - -typedef vector vc; - -typedef vector vll; - -typedef unsigned long long ull; - -typedef vector> vpii; - -typedef vector> vpic; - - - -#define for1(i, n1, n2) for(ll i = n1; i < n2; i++) - -#define for2(i, n2, n1) for(ll i = n2; i > n1; i--) - -#define vecMAX(v) *max_element(v.begin(), v.end()) - -#define vecMIN(v) *min_element(v.begin(), v.end()) - -#define srt(v) sort(v.begin(), v.end()) - -#define rev(v) reverse(v.begin(), v.end()) - -#define pb push_back - -#define inx ll p[0]; cin >> p[0]; - -#define vin(v) for(auto &it : v) cin >> it; - -#define mp make_pair - -#define ff first - -#define ss second - -#define v_erase(i) v.erase(v.begin() + i); - -#define sum(v) accumulate(v.begin(), v.end(), 0) - -#define INF 1e9 - -#define MOD 1000000007 - -#define sz(v) ((ll)(v).size()) - -#define Code_by_Millenialkiid ios::sync_with_stdio(0); cin.tie(0); - -#ifndef ONLINE_JUDGE - - - - #include ""Jatt_don't_Care.h"" - -#else - - #define see(...) 42 - -#endif - -void solve() { - -ll n,x,y; - -cin>>n>>x>>y; - -x--,y--; - -if(n%2==0&&abs(x-y)%2){ - - for1(i,0,n)cout<> t; - - - - for (ll i = 0; i < t; i++) { - - #ifndef ONLINE_JUDGE - - - - cout << ""-----------------"" << i + 1 << endl; - - #endif - - - - solve(); - - } - - - - return 0; - -}","#include - -using namespace std; - - - -typedef long long ll; - -typedef long long ll; - -typedef vector vi; - -typedef vector vc; - -typedef vector vll; - -typedef unsigned long long ull; - -typedef vector> vpii; - -typedef vector> vpic; - - - -#define for1(i, n1, n2) for(ll i = n1; i < n2; i++) - -#define for2(i, n2, n1) for(ll i = n2; i > n1; i--) - -#define vecMAX(v) *max_element(v.begin(), v.end()) - -#define vecMIN(v) *min_element(v.begin(), v.end()) - -#define srt(v) sort(v.begin(), v.end()) - -#define rev(v) reverse(v.begin(), v.end()) - -#define pb push_back - -#define inx ll p[0]; cin >> p[0]; - -#define vin(v) for(auto &it : v) cin >> it; - -#define mp make_pair - -#define ff first - -#define ss second - -#define v_erase(i) v.erase(v.begin() + i); - -#define sum(v) accumulate(v.begin(), v.end(), 0) - -#define INF 1e9 - -#define MOD 1000000007 - -#define sz(v) ((ll)(v).size()) - -#define Code_by_Millenialkiid ios::sync_with_stdio(0); cin.tie(0); - -#ifndef ONLINE_JUDGE - - - - #include ""Jatt_don't_Care.h"" - -#else - - #define see(...) 42 - -#endif - -void solve() { - -ll n,x,y; - -cin>>n>>x>>y; - -x--,y--; - -if(n%2==0&&abs(x-y)%2){ - - for1(i,0,n)cout<> t; - - - - for (ll i = 0; i < t; i++) { - - #ifndef ONLINE_JUDGE - - - - cout << ""-----------------"" << i + 1 << endl; - - #endif - - - - solve(); - - } - - - - return 0; - -}",2 -chandupaambepitiya,2049C - MEX Cycle,c++17 ,304504062,304504135,"#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - -int findMex(int a, int b, int c) { - - set s = {a, b, c}; // Store unique numbers - - - - for (int i = 0; ; i++) { // Check from 0 upwards - - if (s.find(i) == s.end()) return i; - - } - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -","#include - -using namespace std; - -typedef long long ll; - -bool compareByFirst(const pair& a, const pair& b) { - - return a.first < b.first; - -} - -int findMex(int a, int b, int c) { - - set s = {a, b, c}; // Store unique numbers - - - - for (int i = 0; ; i++) { // Check from 0 upwards - - if (s.find(i) == s.end()) return i; - - } - -} - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - - - vectora(n); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - } - -",2 -random221,2049C - MEX Cycle,c++23 ,305042229,305041811," - -#include - -#include - -#include - -#define FASTIO() \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); - -using namespace std; - - - -//<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> - -// DEBUG TEMPLATE - -void __print(int x) {cerr << x;} - -void __print(long x) {cerr << x;} - -void __print(long long x) {cerr << x;} - -void __print(unsigned x) {cerr << x;} - -void __print(unsigned long x) {cerr << x;} - -void __print(unsigned long long x) {cerr << x;} - -void __print(float x) {cerr << x;} - -void __print(double x) {cerr << x;} - -void __print(long double x) {cerr << x;} - -void __print(char x) {cerr << '\'' << x << '\'';} - -void __print(const char *x) {cerr << '\""' << x << '\""';} - -void __print(const string &x) {cerr << '\""' << x << '\""';} - -void __print(bool x) {cerr << (x ? ""true"" : ""false"");} - - - -template - -void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} - -template - -void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "","" : """"), __print(i); cerr << ""}"";} - -void _print() {cerr << ""]\n"";} - -template - -void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << "", ""; _print(v...);} - - - -#ifndef ONLINE_JUDGE - -#define debug(x...) cerr << ""["" << #x << ""] = [""; _print(x) - -#else - -#define debug(x...) - -#endif - - - -// ordered set - -// find_by_order, order_of_key - -// order_of_key (k) : Number of items strictly smaller than k. - -// find_by_order(k) : K-th element in a set (counting from zero) - -using namespace __gnu_pbds; - -template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update> ; - -template using ordered_multiset = tree, rb_tree_tag,tree_order_statistics_node_update>; - -template> using ordered_map = tree; - -struct pair_hash { - - template - - size_t operator()(const std::pair& p) const { - - auto h1 = std::hash{}(p.first); - - auto h2 = std::hash{}(p.second); - - return h1 ^ (h2 << 1); - - } - -}; - -class DSU{ - - public: - - vector Rank, parent; - - void make(int n) { - - Rank.resize(n+1,0); - - parent.resize(n+1); - - for (int i = 0; i <= n; i++) { - - parent[i] = i; - - } - - } - - int get(int node) { - - if (node == parent[node]) - - return node; - - return parent[node] = get(parent[node]); - - } - - void unite(int u, int v) { - - int ulp_u = get(u); - - int ulp_v = get(v); - - if (ulp_u == ulp_v) return; - - if (Rank[ulp_u] < Rank[ulp_v]) { - - parent[ulp_u] = ulp_v; - - } - - else if (Rank[ulp_v] < Rank[ulp_u]) { - - parent[ulp_v] = ulp_u; - - } - - else { - - parent[ulp_v] = ulp_u; - - Rank[ulp_u]++; - - } - - } - -}; - -//<-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------> - - - - - -void getpath(int n, unordered_map>&mp, vector&path, vector&visited){ - - queue>q; // node, parent - - q.push({path[0], -1}); - - visited[path[0]] = 1; - - while(!q.empty()){ - - auto [node, parent] = q.front(); - - q.pop(); - - for(auto &neigh: mp[node]){ - - if(!visited[neigh]){ - - visited[neigh] = 1; - - q.push({neigh, node}); - - path.push_back(neigh); - - break; - - } - - else{ - - if(neigh == parent) continue; - - return; - - } - - } - - } - -} - - - -void solve(){ - - unordered_map>mp; - - int n, x, y; - - cin >> n >> x >> y; - - for(int i = 1; i <= n; ++i){ - - int f1 = i + 1, f2 = i - 1; - - if(f1 == n + 1) f1 = 1; - - if(f2 == 0) f2 = n; - - mp[i].insert(f1); - - mp[i].insert(f2); - - } - - mp[x].insert(y);mp[y].insert(x); - - bool exist = false; - - vectorpath1, path2; - - for(int i = 1; i <= n; ++i){ - - if(mp[i].size() == 3){ - - path1.push_back(i); - - path2.push_back(i); - - exist = true; - - break; - - } - - } - - if(!exist){ - - if(n % 2 == 0){ - - for(int i = 1; i <= n; ++i){ - - cout << (i % 2 == 1 ? 0 : 1) << "" ""; - - } - - } - - else{ - - for(int i = 1; i <= 3; ++i){ - - cout << i - 1 << "" ""; - - } - - for(int i = 4; i <= n; ++i){ - - cout << (i % 2 == 1) << "" ""; - - } - - } - - cout << ""\n""; - - return; - - } - - //debug(path1, path2); - - vectorvisited(n + 1, 0); - - int endnode = -1; - - getpath(n, mp, path1, visited); - - int nc1 = path2[0] + 1, nc2 = path2[0] - 1; - - if(nc1 == n + 1) nc1 = 1; - - if(nc2 == 0) nc2 = n; - - if(!visited[nc2]){ - - for(int i = n; i >= 1; --i){ - - if(visited[i]) continue; - - else{ - - path2.push_back(i); - - } - - } - - } - - else{ - - for(int i = 1; i <= n; ++i){ - - if(visited[i]) continue; - - else{ - - path2.push_back(i); - - } - - } - - } - - //debug(path1); - - path2.push_back(path1.back()); - - //debug(path2); - - vectorans(n + 1, -1); - - if(path1.size() % 2 == 1 and path2.size() % 2 == 1){ - - ans[path1[0]] = 2; - - int i = 1; - - while(i < path1.size() or i < path2.size()){ - - if(i < path1.size()){ - - ans[path1[i]] = i % 2; - - } - - if(i < path2.size()){ - - ans[path2[i]] = i % 2; - - } - - ++i; - - } - - } - - - - else if(path1.size() % 2 == 1){ - - ans[path1[0]] = 0; - - ans[path1[1]] = 2; - - ans[path1[2]] = 1; - - for(int i = 3; i < path1.size(); ++i){ - - if(i & 1) ans[path1[i]] = 0; - - else ans[path1[i]] = 1; - - } - - for(int i = 0; i < path2.size(); ++i){ - - if(ans[path2[i]] != -1) continue; - - //debug(path2[i]); - - ans[path2[i]] = i % 2; - - } - - } - - else if(path2.size() % 2 == 1){ - - ans[path2[0]] = 0; - - ans[path2[1]] = 2; - - ans[path2[2]] = 1; - - for(int i = 3; i < path2.size(); ++i){ - - if(i & 1) ans[path2[i]] = 0; - - else ans[path2[i]] = 1; - - } - - for(int i = 0; i < path1.size(); ++i){ - - if(ans[path1[i]] != -1) continue; - - ans[path1[i]] = i % 2; - - } - - } - - else{ - - for(int i = 1; i <= n; ++i){ - - ans[i] = (i % 2 == 0); - - } - - } - - for(int i = 1; i <= n; ++i){ - - cout << ans[i] << "" ""; - - } - - cout << ""\n""; - - - - - -} - - - -int main() { - - FASTIO(); - - int t; t = 1; - - cin >> t; - - while(t--){ - - solve(); - - } - - - -} - -"," - -#include - -#include - -#include - -#define FASTIO() \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); - -using namespace std; - - - -//<------------------------------------------------------------------------------------------------------------------------------------------------------------------------------> - -// DEBUG TEMPLATE - -void __print(int x) {cerr << x;} - -void __print(long x) {cerr << x;} - -void __print(long long x) {cerr << x;} - -void __print(unsigned x) {cerr << x;} - -void __print(unsigned long x) {cerr << x;} - -void __print(unsigned long long x) {cerr << x;} - -void __print(float x) {cerr << x;} - -void __print(double x) {cerr << x;} - -void __print(long double x) {cerr << x;} - -void __print(char x) {cerr << '\'' << x << '\'';} - -void __print(const char *x) {cerr << '\""' << x << '\""';} - -void __print(const string &x) {cerr << '\""' << x << '\""';} - -void __print(bool x) {cerr << (x ? ""true"" : ""false"");} - - - -template - -void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} - -template - -void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "","" : """"), __print(i); cerr << ""}"";} - -void _print() {cerr << ""]\n"";} - -template - -void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << "", ""; _print(v...);} - - - -#ifndef ONLINE_JUDGE - -#define debug(x...) cerr << ""["" << #x << ""] = [""; _print(x) - -#else - -#define debug(x...) - -#endif - - - -// ordered set - -// find_by_order, order_of_key - -// order_of_key (k) : Number of items strictly smaller than k. - -// find_by_order(k) : K-th element in a set (counting from zero) - -using namespace __gnu_pbds; - -template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update> ; - -template using ordered_multiset = tree, rb_tree_tag,tree_order_statistics_node_update>; - -template> using ordered_map = tree; - -struct pair_hash { - - template - - size_t operator()(const std::pair& p) const { - - auto h1 = std::hash{}(p.first); - - auto h2 = std::hash{}(p.second); - - return h1 ^ (h2 << 1); - - } - -}; - -class DSU{ - - public: - - vector Rank, parent; - - void make(int n) { - - Rank.resize(n+1,0); - - parent.resize(n+1); - - for (int i = 0; i <= n; i++) { - - parent[i] = i; - - } - - } - - int get(int node) { - - if (node == parent[node]) - - return node; - - return parent[node] = get(parent[node]); - - } - - void unite(int u, int v) { - - int ulp_u = get(u); - - int ulp_v = get(v); - - if (ulp_u == ulp_v) return; - - if (Rank[ulp_u] < Rank[ulp_v]) { - - parent[ulp_u] = ulp_v; - - } - - else if (Rank[ulp_v] < Rank[ulp_u]) { - - parent[ulp_v] = ulp_u; - - } - - else { - - parent[ulp_v] = ulp_u; - - Rank[ulp_u]++; - - } - - } - -}; - -//<-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------> - - - - - -void getpath(int n, unordered_map>&mp, vector&path, vector&visited){ - - queue>q; // node, parent - - q.push({path[0], -1}); - - visited[path[0]] = 1; - - while(!q.empty()){ - - auto [node, parent] = q.front(); - - q.pop(); - - for(auto &neigh: mp[node]){ - - if(!visited[neigh]){ - - visited[neigh] = 1; - - q.push({neigh, node}); - - path.push_back(neigh); - - break; - - } - - else{ - - if(neigh == parent) continue; - - return; - - } - - } - - } - -} - - - -void solve(){ - - unordered_map>mp; - - int n, x, y; - - cin >> n >> x >> y; - - for(int i = 1; i <= n; ++i){ - - int f1 = i + 1, f2 = i - 1; - - if(f1 == n + 1) f1 = 1; - - if(f2 == 0) f2 = n; - - mp[i].insert(f1); - - mp[i].insert(f2); - - } - - mp[x].insert(y);mp[y].insert(x); - - bool exist = false; - - vectorpath1, path2; - - for(int i = 1; i <= n; ++i){ - - if(mp[i].size() == 3){ - - path1.push_back(i); - - path2.push_back(i); - - exist = true; - - break; - - } - - } - - if(!exist){ - - if(n % 2 == 0){ - - for(int i = 1; i <= n; ++i){ - - cout << (i % 2 == 1 ? 0 : 1); - - } - - } - - else{ - - for(int i = 1; i <= 3; ++i){ - - cout << i - 1 << "" ""; - - } - - for(int i = 4; i <= n; ++i){ - - cout << (i % 2 == 0) << "" ""; - - } - - } - - cout << ""\n""; - - return; - - } - - //debug(path1, path2); - - vectorvisited(n + 1, 0); - - int endnode = -1; - - getpath(n, mp, path1, visited); - - int nc1 = path2[0] + 1, nc2 = path2[0] - 1; - - if(nc1 == n + 1) nc1 = 1; - - if(nc2 == 0) nc2 = n; - - if(!visited[nc2]){ - - for(int i = n; i >= 1; --i){ - - if(visited[i]) continue; - - else{ - - path2.push_back(i); - - } - - } - - } - - else{ - - for(int i = 1; i <= n; ++i){ - - if(visited[i]) continue; - - else{ - - path2.push_back(i); - - } - - } - - } - - //debug(path1); - - path2.push_back(path1.back()); - - //debug(path2); - - vectorans(n + 1, -1); - - if(path1.size() % 2 == 1 and path2.size() % 2 == 1){ - - ans[path1[0]] = 2; - - int i = 1; - - while(i < path1.size() or i < path2.size()){ - - if(i < path1.size()){ - - ans[path1[i]] = i % 2; - - } - - if(i < path2.size()){ - - ans[path2[i]] = i % 2; - - } - - ++i; - - } - - } - - - - else if(path1.size() % 2 == 1){ - - ans[path1[0]] = 0; - - ans[path1[1]] = 2; - - ans[path1[2]] = 1; - - for(int i = 3; i < path1.size(); ++i){ - - if(i & 1) ans[path1[i]] = 0; - - else ans[path1[i]] = 1; - - } - - for(int i = 0; i < path2.size(); ++i){ - - if(ans[path2[i]] != -1) continue; - - //debug(path2[i]); - - ans[path2[i]] = i % 2; - - } - - } - - else if(path2.size() % 2 == 1){ - - ans[path2[0]] = 0; - - ans[path2[1]] = 2; - - ans[path2[2]] = 1; - - for(int i = 3; i < path2.size(); ++i){ - - if(i & 1) ans[path2[i]] = 0; - - else ans[path2[i]] = 1; - - } - - for(int i = 0; i < path1.size(); ++i){ - - if(ans[path1[i]] != -1) continue; - - ans[path1[i]] = i % 2; - - } - - } - - else{ - - for(int i = 1; i <= n; ++i){ - - ans[i] = (i % 2 == 0); - - } - - } - - for(int i = 1; i <= n; ++i){ - - cout << ans[i] << "" ""; - - } - - cout << ""\n""; - - - - - -} - - - -int main() { - - FASTIO(); - - int t; t = 1; - - cin >> t; - - while(t--){ - - solve(); - - } - - - -} - -",1 -noobie_hunter,2049C - MEX Cycle,c++23 ,308249987,308249207,"#include - -using namespace std; - -#define int long long - -#define pi 3.1415926 - -#define pb(e) push_back(e) - -#define all(x) x.begin(),x.end() - -#define cin(v) for(auto &i:v){cin>>i;} - -#define sv(a) sort(a.begin(),a.end()) - -#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL)); - -#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++) - -#define vi vector - -#define vii vector> - -#define vc vector - -#define vcc vector> - -void print(vector v) { - -for (auto i : v) cout << i << ' '; - -cout << endl;} - - - - - -int binpow(int a,int b){ - -int res=1; - -while(b>0){ - -if(b&1) - -res*=a; - -a*=a; - -b>>=1;} - -return res;} - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - x--;y--; - - vi ans(n); - - forn(i,n) ans[(x+i)%n]=i%2; - - if(n%2||(x-y)%2==0) - - ans[x]=2; - - print(ans); - -} - - - - - -signed main(){ - -int t; cin>>t; while(t--) solve(); - -}","#include - -using namespace std; - -#define int long long - -#define pi 3.1415926 - -#define pb(e) push_back(e) - -#define all(x) x.begin(),x.end() - -#define cin(v) for(auto &i:v){cin>>i;} - -#define sv(a) sort(a.begin(),a.end()) - -#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL)); - -#define forn(a, c) for (int (a) = 0; (a) < (c); (a)++) - -#define vi vector - -#define vii vector> - -#define vc vector - -#define vcc vector> - -void print(vector v) { - -for (auto i : v) cout << i << ' '; - -cout << endl;} - - - - - -int binpow(int a,int b){ - -int res=1; - -while(b>0){ - -if(b&1) - -res*=a; - -a*=a; - -b>>=1;} - -return res;} - - - -int mex(vi f,vi ans) { - - set v; - - forn(i,f.size()) { - - v.insert(ans[f[i]]); - - } - - int mex=0; - - for(auto i:v) if(i==mex) mex++; - - return mex; - -} - - - -void solve(){ - - int n,x,y; - - cin>>n>>x>>y; - - vi ans(n,1e9); - - vii f(n); - - forn(i,n) { - - f[i].pb((i==0)?n-1:i-1); - - f[i].pb((i==n-1)?0:i+1); - - } - - x--;y--; - - f[x].pb(y); - - f[y].pb(x); - - forn(i,n) { - - ans[i]=mex(f[i],ans); - - } - - print(ans); - -} - - - - - -signed main(){ - -int t; cin>>t; while(t--) solve(); - -}",1 -vasu_boda_,2049C - MEX Cycle,c++20 ,308056150,308052152," - -/*<------------------------------------------------------------------------------------ - ---------------------------------------------------------------------------------------- - -----------------------MADE--BY--VB----------------------------------------------------- - ---------------------------------------------------------------------------------------- - ------------------------------------------------------------------------------------->*/ - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -// ifstream i_data(""mixmilk.in""); - -// ofstream o_data(""mixmilk.out""); - - - -// #define cin i_data - -// #define cout o_data - - - -/*<--------------------------------DATA--STRUCTURES----------------------------------->*/ - -#define ll long long - -#define pii pair - -#define pll pair - -#define vi vector - -#define vll vector - -#define mii map - -#define mll map - -#define si set - -#define sc set - -#define moj_karvani \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -// only less behave as set - -// less_equal as multiset - -// we can replace less with greater for descending order - -/*<--------------------------------FUNCTIONS------------------------------------------->*/ - -string itob(int num) - -{ - - if (num == 0) - - return ""0""; - - string binaryString; - - while (num > 0) - - { - - binaryString = (num % 2 == 0 ? ""0"" : ""1"") + binaryString; - - num /= 2; - - } - - return binaryString; - -} - -int btoi(const string &binaryString) { return stoi(binaryString, nullptr, 2); } - -void print_binary(int num) - -{ - - for (int i = 10; i >= 0; i--) - - { - - cout << ((num >> i) & 1); - - } - - cout << endl; - -} - -string to_upper(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'a' && a[i] <= 'z') - - a[i] -= 'a' - 'A'; - - return a; - -} - -string to_lower(string a) - -{ - - for (int i = 0; i < (int)a.size(); ++i) - - if (a[i] >= 'A' && a[i] <= 'Z') - - a[i] += 'a' - 'A'; - - return a; - -} - -bool comp(const pair &a, const pair &b) - -{ - - if (a.first == b.first) - - { - - return a.second < b.second; - - } - - return a.first < b.first; - -}; - -vector find_intersection(int a, int b, int c, int d, int p, int q, int r, int s) - -{ - - vector v; - - int l = max(a, p); - - int m = max(b, q); - - int n = min(c, r); - - int o = min(d, s); - - int x = n - l; - - int y = o - m; - - if (x < 0 || y < 0) - - { - - return v; - - } - - v.push_back(l); - - v.push_back(m); - - v.push_back(n); - - v.push_back(o); - - return v; - -} - -/*<-----------------------------BASIC--MATH----------------------------------------->*/ - -const ll M = 1e9 + 7, N = 1e5 + 5; - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, a % b); - -} - -ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } - -// ll power(ll a,ll b){if(b==0) return 1;ll res=power(a,b/2);if(b&1){return a*res*res;}else{return res*res;}} - -ll power(ll a, ll b) - -{ - - ll ans = 1; - - while (b) - - { - - if (b & 1) - - { - - ans = ans * a; - - } - - a = a * a; - - b >>= 1; - - } - - return ans; - -} - -// ll isPrime(ll a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(ll i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -bool isPrime(int number) - -{ - - if (number <= 1) - - return false; - - if (number == 2) - - return true; - - if (number % 2 == 0) - - return false; - - int boundary = (int)floor(sqrt(number)); - - for (int i = 3; i <= boundary; i += 2) - - if (number % i == 0) - - return false; - - return true; - -} - - - -/*<---------------------------------Solve--here-------------------------------------------->*/ - - - -void solve() - -{ - - ll n, x, y; - - cin >> n >> x >> y; - - vector ans(n + 1); - - int b = 0; - - int f=0; - - for (int i = x; i <= y; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - if ((abs(x - y) + 1) & 1) - - { - - f=1; - - ans[y] = 2; - - }; - - - - ll p = n - y + 1LL + x; - - - - if (p & 1) - - { - - b = 1; - - } - - else - - { - - b = 0; - - } - - if(f==0 && p&1){ - - b=0; - - } - - for (int i = y + 1; i <= n; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - for (int i = 1; i < x; i++) - - { - - if (b == 0) - - { - - ans[i] = 0; - - b = 1; - - } - - else - - { - - ans[i] = 1; - - b = 0; - - } - - } - - if(x==1){ - - x=n; - - } - - else{ - - x--; - - } - - if(f==0 && p&1){ - - ans[x]=2; - - } - - for(int i=1;i<=n;i++){ - - cout<*/ - -int main() - -{ - - moj_karvani; - - int t = 1; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - return 0; - -} - - - -/*<-------------------------------Thank--You----------------------------------------------->*/ - -"," - -/*<------------------------------------------------------------------------------------ - ---------------------------------------------------------------------------------------- - -----------------------MADE--BY--VB----------------------------------------------------- - ---------------------------------------------------------------------------------------- - ------------------------------------------------------------------------------------->*/ - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -// ifstream i_data(""mixmilk.in""); - -// ofstream o_data(""mixmilk.out""); - - - -// #define cin i_data - -// #define cout o_data - - - -/*<--------------------------------DATA--STRUCTURES----------------------------------->*/ - -#define ll long long - -#define pii pair - -#define pll pair - -#define vi vector - -#define vll vector - -#define mii map - -#define mll map - -#define si set - -#define sc set - -#define moj_karvani ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -// only less behave as set - -//less_equal as multiset - -//we can replace less with greater for descending order - -/*<--------------------------------FUNCTIONS------------------------------------------->*/ - -string itob(int num) {if (num == 0) return ""0"";string binaryString;while (num > 0) {binaryString = (num % 2 == 0 ? ""0"" : ""1"") + binaryString;num /= 2;}return binaryString;} - -int btoi(const string& binaryString) {return stoi(binaryString, nullptr, 2);} - -void print_binary(int num){for(int i=10;i>=0;i--){cout<<((num>>i) & 1);}cout<='a' && a[i]<='z') a[i]-='a'-'A'; return a; } - -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } - -bool comp(const pair& a, const pair& b) {if (a.first == b.first) {return a.second < b.second; }return a.first find_intersection(int a,int b,int c,int d,int p,int q,int r ,int s){vectorv;int l=max(a,p);int m=max(b,q);int n=min(c,r);int o=min(d,s);int x=n-l;int y=o-m;if(x<0 || y<0){return v;}v.push_back(l);v.push_back(m);v.push_back(n);v.push_back(o);return v;} - -/*<-----------------------------BASIC--MATH----------------------------------------->*/ - -const ll M=1e9+7,N=1e5+5; - -ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } - -ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } - -//ll power(ll a,ll b){if(b==0) return 1;ll res=power(a,b/2);if(b&1){return a*res*res;}else{return res*res;}} - -ll power(ll a, ll b){ll ans=1;while(b){if(b&1){ans=ans*a;}a=a*a;b>>=1;}return ans;} - -//ll isPrime(ll a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(ll i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -bool isPrime(int number){if (number <= 1)return false;if (number == 2)return true;if (number % 2 == 0) return false;int boundary = (int)floor(sqrt(number));for (int i = 3; i <= boundary; i += 2)if (number % i == 0)return false;return true;} - - - -/*<---------------------------------Solve--here-------------------------------------------->*/ - - - -void solve(){ - - ll n,x,y; - - cin>>n>>x>>y; - - vector ans; - - for(int i=0;i*/ - -int main(){ - - moj_karvani; - - int t=1; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -} - - - -/*<-------------------------------Thank--You----------------------------------------------->*/ - - - -",1 -champignondayo#,2049C - MEX Cycle,c++23 ,305776122,305776371,"#include - -using namespace std; - -#define rep(i, l, n) for(int i = (int)(l); i < (int)(n); i++) - -#define ll long long - - - -vector solve() { - - int n; cin >> n; - - int x, y; cin >> x >> y; - - x--; y--; - - vector ans(n, 0); - - rep(i, 0, n) ans[i] = i % 2; - - if(n % 2) ans[n - 1] = 2; - - int start = -1; - - rep(i, 0, n) { - - if(ans[i] != ans[(i + y - x) % n]) start = i; - - } - - if(start == -1) { - - ans[0] = 2; - - } - - start = (start - x + n) % n; - - vector real_ans(n); - - rep(i, 0, n) real_ans[i] = ans[(i + start) % n]; - - return real_ans; - -} - - - -int main() { - - int t; cin >> t; - - while(t--) { - - auto v = solve(); - - for(int u : v) cout << u << "" ""; - - cout << endl; - - } - -}","#include - -using namespace std; - -#define rep(i, l, n) for(int i = (int)(l); i < (int)(n); i++) - -#define ll long long - - - -vector solve() { - - int n; cin >> n; - - int x, y; cin >> x >> y; - - x--; y--; - - vector ans(n, 0); - - rep(i, 0, n) ans[i] = i % 2; - - if(n % 2) ans[n - 1] = 2; - - int start = -1; - - rep(i, 0, n) { - - if(ans[i] != ans[(i + y - x) % n]) start = i; - - } - - if(start == -1) { - - ans[0] = 2; - - start = 0; - - } - - start = (start - x + n) % n; - - vector real_ans(n); - - rep(i, 0, n) real_ans[i] = ans[(i + start) % n]; - - return real_ans; - -} - - - -int main() { - - int t; cin >> t; - - while(t--) { - - auto v = solve(); - - for(int u : v) cout << u << "" ""; - - cout << endl; - - } - -}",2 -KaiwalyaJoshi,2049C - MEX Cycle,c++17 ,303749736,303756436,"#include - -typedef long long ll; - -#define MII map - -#define UMII unordered_map - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define vi vector - -#define vvi vector - -#define qi queue - -#define si stack - -#define rep(i, a, b) for(int i = a; i < b; i++) - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while(t--){ - - int n, x, y; - - cin >> n >> x >> y; - - if(x > y) swap(x, y); - - x--; - - y--; - - vector arr(n); - - for(int i = 0; i < n; i++){ - - arr[(x+i) % n] = i % 2; - - } - - if((y - x) % 2 == 0) arr[x] = 2; - - - - for(int i = 0; i < n; i++){ - - cout << arr[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -}","#include - -typedef long long ll; - -#define MII map - -#define UMII unordered_map - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define vi vector - -#define vvi vector - -#define qi queue - -#define si stack - -#define rep(i, a, b) for(int i = a; i < b; i++) - -using namespace std; - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while(t--){ - - int n, x, y; - - cin >> n >> x >> y; - - if(x > y) swap(x, y); - - x--; - - y--; - - vector arr(n); - - for(int i = 0; i < n; i++){ - - arr[(x+i) % n] = i % 2; - - } - - if((y - x) % 2 == 0 || (x+n-y) % 2 == 0) arr[x] = 2; - - - - for(int i = 0; i < n; i++){ - - cout << arr[i] << "" ""; - - } - - cout << endl; - - } - - return 0; - -}",2 -Linxon,2049C - MEX Cycle,c++20 ,304834292,304834115,"#include - -using namespace std; - -typedef long long ll; - -#define endl ""\n""; - -const int N = 2e5 + 5; - - - -int main() { - - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - - ll _; cin >> _; - - while (_--) { - - ll n, x, y; cin >> n >> x >> y; - - --x, --y; - - vector a(n); - - if (n & 1) { - - a[x] = 2; - - for (int i = 1; i < n; ++i) a[(x + i) % n] = i & 1; - - } - - else { - - if ((x ^ y) & 1) for (int i = 0; i < n; ++i) a[i] = i & 1; - - else { - - a[x] = 2; - - for (int i = 1; i < n; ++i) a[(x + i) % n] = i & 1; - - } - - } - - for (int i = 0; i < n; ++i) cout << a[i] << "" ""; - - cout << endl; - - } - - return 0; - -} - - - -","#include - -using namespace std; - -typedef long long ll; - -#define endl ""\n""; - -const int N = 2e5 + 5; - - - -int main() { - - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - - ll _; cin >> _; - - while (_--) { - - ll n, x, y; cin >> n >> x >> y; - - --x, --y; - - vector a(n); - - if (n & 1) { - - a[x] = 2; - - for (int i = 1; i < n; ++i) a[(x + i) % n] = i & 1; - - } - - else { - - if (x != y) for (int i = 0; i < n; ++i) a[i] = i & 1; - - else { - - a[x] = 2; - - for (int i = 1; i < n; ++i) a[(x + i) % n] = i & 1; - - } - - } - - for (int i = 0; i < n; ++i) cout << a[i] << "" ""; - - cout << endl; - - } - - return 0; - -} - - - -",1 -ye..,2049C - MEX Cycle,c++20 ,303740702,303736176,"#include ""bits/stdc++.h"" - -using namespace std; - -typedef long long ll; - -#define int long long - -#define endl '\n' - -#define IOS ios::sync_with_stdio(0),cin.tie(0); - -#define all(x) x.begin(),x.end() - -#define all2(x) x.begin()+1,x.end() - -#define pi pair - -#define vi vector - -#define vc vector - -#define si set - -#define mi map - -#define mc map - -#define YES cout<<""Yes""<bool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n>>x>>y; - - x--,y--; - - vi a(n); - - for (int i=0,j=0;i>t; - -// t=1; - - while(t--){ - - solve(); - - } - -} - - - -","#include ""bits/stdc++.h"" - -using namespace std; - -typedef long long ll; - -#define int long long - -#define endl '\n' - -#define IOS ios::sync_with_stdio(0),cin.tie(0); - -#define all(x) x.begin(),x.end() - -#define all2(x) x.begin()+1,x.end() - -#define pi pair - -#define vi vector - -#define vc vector - -#define si set - -#define mi map - -#define mc map - -#define YES cout<<""Yes""<bool chmin(T &a, const T &b) { if (bbool chmax(T &a, const T &b) { if (a>n>>x>>y; - - vi a(n+1); - - if(n%2==0){ - - for(int i=1,j=0;i<=n;i++){ - - a[i]=j; - - j=1-j; - - } - - } - - else { - - for (int i=1,j=0;i>t; - -// t=1; - - while(t--){ - - solve(); - - } - -} - - - -",1 -Abuseini,2049C - MEX Cycle,c++20 ,307929930,307928486,"/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/ - -#include - -#include - -#include - -// #pragma GCC optimize(""Ofast"") - -// #pragma GCC target(""avx,avx2,fma"") - -// #pragma GCC optimization (""unroint-loops"") - -// #include ""robin_hood.h"" - -using namespace __gnu_pbds; - -using namespace std; - -typedef long long ll; - -typedef unsigned long long ul; - -typedef tree, null_type, greater>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#define endl ""\n"" - -const int mod = 998244353; - -const int dx[] = {1, -1, 0, 0}; - -const int dy[] = {0, 0, 1, -1}; - -void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int N = 2e5 + 5; - - - -void Solve() { - - int n, x, y; cin >> n >> x >> y; - - vector ans(n + 1); - - ans[x] = (n - y + x - 1) % 2 || (y - x - 1) % 2 ? 2 : 0; - - ans[y] = 1; - - for (int i = y + 1; i <= n; i++) ans[i] = ans[i - 1] == 0 ? 1 : 0; - - for (int i = 1; i < x; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = y - 1; i > x; i--) ans[i] = ans[i + 1] == 0 ? 1 : 0; - - for (int i = 1; i <= n; i++) cout << ans[i] << "" ""; - - cout << endl; - -} - - - -signed main() { - - fast(); - - int t = 1; cin >> t; - - while (t--) Solve(); - -} - -/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/","/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/ - -#include - -#include - -#include - -// #pragma GCC optimize(""Ofast"") - -// #pragma GCC target(""avx,avx2,fma"") - -// #pragma GCC optimization (""unroint-loops"") - -// #include ""robin_hood.h"" - -using namespace __gnu_pbds; - -using namespace std; - -typedef long long ll; - -typedef unsigned long long ul; - -typedef tree, null_type, greater>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#define endl ""\n"" - -const int mod = 998244353; - -const int dx[] = {1, -1, 0, 0}; - -const int dy[] = {0, 0, 1, -1}; - -void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int N = 2e5 + 5; - - - -void Solve() { - - int n, x, y; cin >> n >> x >> y; - - vector ans(n + 1); - - ans[x] = 2; - - ans[y] = 1; - - for (int i = y + 1; i <= n; i++) ans[i] = ans[i - 1] == 0 ? 1 : 0; - - for (int i = 1; i < x; i++) ans[i] = ans[i > 1 ? i - 1 : n] == 0 ? 1 : 0; - - for (int i = y - 1; i > x; i--) ans[i] = ans[i + 1] == 0 ? 1 : 0; - - for (int i = 1; i <= n; i++) cout << ans[i] << "" ""; - - cout << endl; - -} - - - -signed main() { - - fast(); - - int t = 1; cin >> t; - - while (t--) Solve(); - -} - -/** - -you can ^_^ (•‿•) - -( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما ) - -**/",1 -Hi_Hi_Hi,2049C - MEX Cycle,c++20 ,306881822,306882101,"#include - - - -using namespace std; - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t;cin>>t; - - while(t--) - - { - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - for(int i=x;i - - - -using namespace std; - - - -int main() - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t;cin>>t; - - while(t--) - - { - - int n,x,y;cin>>n>>x>>y; - - int a[n]; - - for(int i=x;i - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,x,y,say1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m>>x>>y; - - x--; y--; - - vectorv(m); - - for(int i=0;i - -using namespace std; - -#define ll long long - -#define pair pair - -ll n,m,x,ysay1,say2,cem=0; - -int main() - -{ - - cin>>n; - - string s; - - while(n--) - - { - - cin>>m>>x>>y; - - x--; y--; - - vectorv(m); - - for(int i=0;i - -using namespace std; - -typedef long long ll; - -const int N = 2e6 + 7; - -ll r[N]; - -int h[N], e[N], ne[N], idx; - -void add(int a, int b) - -{ - - e[idx] = b, ne[idx] = h[a], h[a] = idx++; - -} - -void dfs(int x) - -{ - - if (r[x] >= 0) - - { - - return; - - } - - set s; - - for (int i = h[x]; i != -1; i = ne[i]) - - { - - int to = e[i]; - - if (r[to] >= 0) - - { - - s.insert(r[to]); - - } - - } - - for (int i = 0; i <= 10; i++) - - { - - if (s.count(i) == 0) - - { - - r[x] = i; - - break; - - } - - } - - for (int i = h[x]; i != -1; i = ne[i]) - - { - - int to = e[i]; - - dfs(to); - - } - -} - -void solve() - -{ - - ll n, x, y; - - cin >> n >> x >> y; - - idx = 0; - - for (int i = 1; i <= n; i++) - - { - - r[i] = -1; - - h[i] = -1; - - } - - for (int i = 2; i <= n; i++) - - { - - add(i - 1, i); - - add(i, i - 1); - - } - - add(1, n); - - add(n, 1); - - add(x, y); - - add(y, x); - - r[y] = 1; - - dfs(x); - - for (int i = 1; i <= n; i++) - - { - - cout << r[i] << ' '; - - } - - cout << '\n'; - -} - -int main() - -{ - - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - - int T; - - cin >> T; - - while (T--) - - { - - solve(); - - } - -}","#include - -using namespace std; - -typedef long long ll; - -const int N = 2e5 + 7; - -ll r[N]; - -int h[N], e[N], ne[N], idx; - -void add(int a, int b) - -{ - - e[idx] = b, ne[idx] = h[a], h[a] = idx++; - -} - -void dfs(int x) - -{ - - if (r[x] >= 0) - - { - - return; - - } - - set s; - - for (int i = h[x]; i != -1; i = ne[i]) - - { - - int to = e[i]; - - if (r[to] >= 0) - - { - - s.insert(r[to]); - - } - - } - - for (int i = 0; i <= 10; i++) - - { - - if (s.count(i) == 0) - - { - - r[x] = i; - - break; - - } - - } - - for (int i = h[x]; i != -1; i = ne[i]) - - { - - int to = e[i]; - - dfs(to); - - } - -} - -void solve() - -{ - - ll n, x, y; - - cin >> n >> x >> y; - - idx = 0; - - for (int i = 1; i <= n; i++) - - { - - r[i] = -1; - - h[i] = -1; - - } - - for (int i = 2; i <= n; i++) - - { - - add(i - 1, i); - - add(i, i - 1); - - } - - add(1, n); - - add(n, 1); - - add(x, y); - - add(y, x); - - r[y] = 1; - - dfs(x); - - for (int i = 1; i <= n; i++) - - { - - cout << r[i] << ' '; - - } - - cout << '\n'; - -} - -int main() - -{ - - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - - int T; - - cin >> T; - - while (T--) - - { - - solve(); - - } - -}",1 -PrachiJha_23,2049C - MEX Cycle,c++20 ,304515816,304516389,"#include - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - while(t--){ - - int n,x,y; - - cin>>n>>x>>y; - - vectorans(n); - - for(int i=0; i - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - while(t--){ - - int n,x,y; - - cin>>n>>x>>y; - - x--;y--; - - vectorans(n); - - for(int i=0; i - -using namespace std; - - - -int main() { - - int t ;cin>>t; // You can modify t for multiple test cases - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - - - vector a(n, 0); // Initialize with 0 - - - - if (y==n) { - - for (int i = 0; i < n; i++) { - - a[i] = (i % 2 == 0) ? 0 : 1; - - } - - if (n % 2) { - - a[0] = 2; - - - - if (a[x - 1] == a[y - 1]) { - - if (a[x - 1] == 0) { - - a[x - 1] = 2; - - if (x == 3) { - - a[x - 2] = 0; - - a[0] = 1; - - } - - } else if (a[x - 1] == 1) { - - a[y - 1] = 2; - - } - - } - - } - - else{ - - if (a[x - 1] == a[y - 1]) { - - a[x-1] = 2; - - } - - } - - } else { - - for (int i = 0; i < n; i++) { - - a[i] = (i % 2 == 0) ? 0 : 1; - - } - - if (n % 2) { - - a[n - 1] = 2; - - - - if (a[x - 1] == a[y - 1]) { - - if (a[x - 1] == 0) { - - a[y - 1] = 2; - - if (y + 1 < n && a[y + 1] == 2) { // Avoid out-of-bounds access - - a[y] = 0; - - a[y+1] = 1; - - } - - } else if (a[x - 1] == 1) { - - a[x - 1] = 2; - - } - - } - - }else{ - - if (a[x - 1] == a[y - 1]) { - - a[x-1] = 2; - - } - - } - - } - - - - for (int i = 0; i < n; i++) { - - cout << a[i] << "" ""; - - } - - cout << endl; - - } - - - - return 0; - -} - -","#include - -using namespace std; - - - -int main() { - - int t ;cin>>t; // You can modify t for multiple test cases - - while (t--) { - - int n, x, y; - - cin >> n >> x >> y; - - - - vector a(n, 0); // Initialize with 0 - - - - if (y==n) { - - for (int i = 0; i < n; i++) { - - a[i] = (i % 2 == 0) ? 0 : 1; - - } - - if (n % 2) { - - a[0] = 2; - - - - if (a[x - 1] == a[y - 1]) { - - if (a[x - 1] == 0) { - - a[x - 1] = 2; - - if (x == 3) { - - a[x - 2] = 0; - - } - - } else if (a[x - 1] == 1) { - - a[y - 1] = 2; - - } - - } - - } - - else{ - - a[x-1] = 2; - - } - - } else { - - for (int i = 0; i < n; i++) { - - a[i] = (i % 2 == 0) ? 0 : 1; - - } - - if (n % 2) { - - a[n - 1] = 2; - - - - if (a[x - 1] == a[y - 1]) { - - if (a[x - 1] == 0) { - - a[y - 1] = 2; - - if (y + 1 < n && a[y + 1] == 2) { // Avoid out-of-bounds access - - a[y] = 0; - - } - - } else if (a[x - 1] == 1) { - - a[x - 1] = 2; - - } - - } - - }else{ - - a[x-1] = 2; - - } - - } - - - - for (int i = 0; i < n; i++) { - - cout << a[i] << "" ""; - - } - - cout << endl; - - } - - - - return 0; - -} - -",1 -sunset1231,2049C - MEX Cycle,c++20 ,305777747,305777504,"#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) { - - ans[max(x, y)] = 2; - - if(y == n - 2 && ans[n - 1] == 2) {ans[n - 1] = 1;} - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - } - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -","#include - -//#include - -using namespace std; - -//using namespace atcoder; - -//using mint = modint998244353; - -//long long型=int64_tという認識で大丈夫です。 - -#define ll long long - -#define ull unsigned long long - -#define vec vector - -#define vi vector - -#define vll vector - -#define pq priority_queue - -#define pb push_back - -#define rep(i, l, r) for(int i=(int)(l); i<(int)(r); i++) - -#define ld long double - - - -const ll INF = 1e9; - -const ll inf = 9e18; - - - -struct Edge { - - int to; - - ll cost; - -}; - - - -struct SEdge { - - int to; - - pair cost; - -}; - - - -template - -using spq = priority_queue, greater>; - - - -const vector di = {-1, 0, 1, 1, 0, -1}, dj = {0, 1, 1, 0, -1, -1}; - - - -template - -bool chmin(T& a, T b) { - - if (a > b) { - - a = b; - - return true; - - } - - return false; - -} - - - -template - -bool chmax(T& a, T b) { - - if(a < b) { - - a = b; - - return true; - - } - - return false; - -} - - - -using S = ll; - - - -S op(S a, S b) {return a + b;} - -S e() {return 0;} - - - -int main() { - - int t; cin >> t; - - rep(i, 0, t) { - - int n, x, y; cin >> n >> x >> y; x--; y--; - - vi ans(n, 0); - - rep(j, 0, n) { - - ans[j] = j % 2; - - } - - if(n % 2 == 1) ans[n - 1] = 2; - - if(ans[x] == ans[y]) { - - ans[max(x, y)] = 2; - - if(y == n - 2 && ans[n - 1] == 2) {ans[n - 2] = 3;} - - if(y == n - 3 && ans[n - 1] == 2) {ans[n - 2] = 0; ans[n - 1] = 1;} - - } - - rep(j, 0, n) cout << ans[j] << "" ""; - - cout << endl; - - } - -} - -",1 -souvenir_vayne#,2049C - MEX Cycle,c++17 ,306007091,306008498,"#pragma GCC optimize(""Ofast"") - - - -#include - -#include - -#include - -#include - -#define pb push_back - -#define INF 0x3f3f3f3f - -#define LINF 0x3f3f3f3f3f3f3f3f - -#define endl '\n' - -#define ll long long - -#define f first - -#define fin cin - -#define fout cout - -#define s second - -#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) - -#define debug(x) cout << ""DEBUG "" << x << endl - -#define debug2(x, y) cout << ""DEBUG "" << x << "" "" << y << endl - -#define debug3(x, y, z) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< endl - -#define debug4(x, y, z, o) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< "" "" << o << endl - -#define all(x) x.begin(), x.end() - -#define left esquerda - -#define lb lower_bound - -#define right direita - -using namespace std; - -using namespace __gnu_pbds; - - - -void setIO(string s) { - -ios_base::sync_with_stdio(0); cin.tie(0); - -freopen((s+"".in"").c_str(),""r"",stdin); - -freopen((s+"".out"").c_str( ),""w"",stdout); - -} - -typedef pair pii; - -typedef vector> mat; - -typedef pair pis; - -const ll mod = 1e9 + 7, MAXN = 2e5 + 5; - -typedef vector vi; - -typedef pair> piii; - -const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); - -struct chash { - - int operator()(int x) const { return x ^ RANDOM; } - -}; - - - - - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - - - x--, y--; - - - - vector v(n); - - v[n - 1] = 1; - - v[1] = 1; - - - - - - if(!x && y != 1 && y != n - 1) - - v[y] = 1; - - - - for(int i = 1; i < n; i++) { - - if(v[i] == v[i + 1]) - - v[i + 1]++; - - if(x == i && v[x] == v[y]) - - v[y]++; - - } - - - - for(int &i : v) - - cout << i << "" ""; - - cout << endl; - -} - - - - - -int32_t main() { - - int ct = 1; - - cin >> ct; - - while(ct--) - - solve(); - -}","#pragma GCC optimize(""Ofast"") - - - -#include - -#include - -#include - -#include - -#define pb push_back - -#define INF 0x3f3f3f3f - -#define LINF 0x3f3f3f3f3f3f3f3f - -#define endl '\n' - -#define ll long long - -#define f first - -#define fin cin - -#define fout cout - -#define s second - -#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) - -#define debug(x) cout << ""DEBUG "" << x << endl - -#define debug2(x, y) cout << ""DEBUG "" << x << "" "" << y << endl - -#define debug3(x, y, z) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< endl - -#define debug4(x, y, z, o) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< "" "" << o << endl - -#define all(x) x.begin(), x.end() - -#define left esquerda - -#define lb lower_bound - -#define right direita - -using namespace std; - -using namespace __gnu_pbds; - - - -void setIO(string s) { - -ios_base::sync_with_stdio(0); cin.tie(0); - -freopen((s+"".in"").c_str(),""r"",stdin); - -freopen((s+"".out"").c_str( ),""w"",stdout); - -} - -typedef pair pii; - -typedef vector> mat; - -typedef pair pis; - -const ll mod = 1e9 + 7, MAXN = 2e5 + 5; - -typedef vector vi; - -typedef pair> piii; - -const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); - -struct chash { - - int operator()(int x) const { return x ^ RANDOM; } - -}; - - - - - -void solve() { - - int n, x, y; - - cin >> n >> x >> y; - - - - x--, y--; - - - - vector v(n); - - - - priority_queue, greater> fila; - - for(int i = 0; i < n; i++) - - fila.push({0, i}); - - - - while(!fila.empty()) { - - pii aux = fila.top(); - - fila.pop(); - - - - if(v[aux.s] != aux.f) - - continue; - - - - int viz = (aux.s ? aux.s - 1 : n - 1); - - int viz2 = (aux.s + 1 < n ? aux.s + 1 : 0); - - - - vector vl = {viz, viz2}; - - if(aux.s == x) - - vl.pb(y); - - if(aux.s == y) - - vl.pb(x); - - - - for(int &i : vl) - - if(aux.f == v[i]) { - - fila.push({aux.f + 1, i}); - - v[i] = aux.f + 1; - - } - - - - - - - - } - - - - for(int &i : v) - - cout << i << "" ""; - - cout << endl; - -} - - - - - -int32_t main() { - - int ct = 1; - - cin >> ct; - - while(ct--) - - solve(); - -}",2 -losXxh#,2049C - MEX Cycle,c++17 ,308479745,308479009,"#include - -#define pii pair - -#define fi first - -#define se second - -#define ll long long - -#define int long long - -#define endl '\n' - -#define ull unsigned long long - -using namespace std; - -const int N=2e5+5; - -int a[N],n,x,y; - -void work(){ - - cin>>n>>x>>y; - - if(n&1){ - - a[x]=2; - - for(int i=1;i<=n-1;i++){ - - x++;if(x==n+1)x=1; - - a[x]=(i&1); - - } - - for(int i=1;i<=n;i++)cout<=2)a[x]=(fl-1)&1; - - fl++; - - } - - fl=0;x=xx; - - while(1){ - - x--;if(x==0)x=n; - - if(x==y)break; - - a[x]=(fl-1)&1; - - fl++; - - } - - a[y]=1; - - for(int i=1;i<=n;i++)cout<>T; - - while(T--)work(); - - return 0; - -}","#include - -#define pii pair - -#define fi first - -#define se second - -#define ll long long - -#define int long long - -#define endl '\n' - -#define ull unsigned long long - -using namespace std; - -const int N=2e5+5; - -int a[N],n,x,y; - -void work(){ - - cin>>n>>x>>y; - - if(n&1){ - - a[x]=2; - - for(int i=1;i<=n-1;i++){ - - x++;if(x==n+1)x=1; - - a[x]=(i&1); - - } - - for(int i=1;i<=n;i++)cout<=2)a[x]=(fl-1)&1; - - fl++; - - } - - fl=0;x=xx; - - while(1){ - - x--;if(x==0)x=n; - - if(x==y)break; - - a[x]=(fl-1)&1; - - fl++; - - } - - for(int i=1;i<=n;i++)cout<>T; - - while(T--)work(); - - return 0; - -}",1 -aditya.chauhan15,2049C - MEX Cycle,c++20 ,305111861,305112268,"#include - -using namespace std; - -#define int long long - - - -void build(vector &segtree, vector &arr, int v, int l, int r) { - - if (l == r) { - - segtree[v]=arr[l]; - - } else { - - int mid = (l + r) / 2; - - build(segtree, arr, 2 * v, l, mid); - - build(segtree, arr, 2 * v + 1, mid + 1, r); - - segtree[v] = gcd(segtree[2 * v], segtree[2 * v + 1]); - - } - -} - - - - - - - -int query(vector &segtree, vector &arr, int v, int l, int r, int l1, int r1) { - - if (r1 < l || r < l1) { - - return 0; - - } else if (l >= l1 && r <= r1) { - - return segtree[v]; - - } else { - - int mid = (l + r) / 2; - - int a = query(segtree, arr, 2 * v, l, mid, l1, r1); - - int b = query(segtree, arr, 2 * v + 1, mid + 1, r, l1, r1); - - return gcd(a, b); - - } - -} - - - -int32_t main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - int n,x,y; - - cin>>n>>x>>y; - - x--; y--; - - vector arr(n); - - - - for(int i=0;i - -using namespace std; - -#define int long long - - - -void build(vector &segtree, vector &arr, int v, int l, int r) { - - if (l == r) { - - segtree[v]=arr[l]; - - } else { - - int mid = (l + r) / 2; - - build(segtree, arr, 2 * v, l, mid); - - build(segtree, arr, 2 * v + 1, mid + 1, r); - - segtree[v] = gcd(segtree[2 * v], segtree[2 * v + 1]); - - } - -} - - - - - - - -int query(vector &segtree, vector &arr, int v, int l, int r, int l1, int r1) { - - if (r1 < l || r < l1) { - - return 0; - - } else if (l >= l1 && r <= r1) { - - return segtree[v]; - - } else { - - int mid = (l + r) / 2; - - int a = query(segtree, arr, 2 * v, l, mid, l1, r1); - - int b = query(segtree, arr, 2 * v + 1, mid + 1, r, l1, r1); - - return gcd(a, b); - - } - -} - - - -int32_t main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - int n,x,y; - - cin>>n>>x>>y; - - x--; y--; - - vector arr(n); - - - - for(int i=0;i - -using namespace std; - -typedef long long int ll; - - - - - -int mex(int a,int b){ - - int less = min(a,b); - - int more = max(a,b); - - for(int i=0;i<=3;i++){ - - if(i!=less && i!=more){ - - return i; - - } - - } - -} - -int main(){ - - int tests; - - cin>>tests; - - for(int test=0;test>n>>x>>y; - - vector a; - - if(n%2==0){ - - for(int i=0;i - -using namespace std; - -typedef long long int ll; - - - - - -int mex(int a,int b){ - - int less = min(a,b); - - int more = max(a,b); - - for(int i=0;i<=3;i++){ - - if(i!=less && i!=more){ - - return i; - - } - - } - -} - -int main(){ - - int tests; - - cin>>tests; - - for(int test=0;test>n>>x>>y; - - vector a; - - if(n%2==0){ - - for(int i=0;i - -#define int long long - -#define all(x,y) x.begin()+y,x.end() - -using namespace std; - -typedef pair pii; - -typedef array arr2; - -const int inf = 1e18 + 30; - -const int N=1e5+15; - -const int mod=1e9+7; - -void smin(int&x,int y){x=min(x,y);} - -void smax(int&x,int y){x=max(x,y);} - -void help(){ - - int n,x,y;cin>>n>>x>>y; - - vector vec(n+1); - - for(int i=1;i<=n;i++) - - vec[i]=(i&1?0:1); - - if(n&1) - - for(int i=n;i>=1;i-=2){ - - vec[i]=1; - - // if(i-1!=x&&i-1!=y){ - - vec[i-1]=2; - - break; - - // } - - } - - set st; - - st.insert(vec[(x-1)<1?n:(x-1)]); - - st.insert(vec[(x+1)>n?1:(x+1)]); - - st.insert(vec[y]); - - int mex=0; - - while(st.count(mex)) mex++; - - vec[x]=mex; - - for(int i=1;i<=n;i++) - - cout<>t; - - while(t--){ - - help(); - - // cout< - -#define int long long - -#define all(x,y) x.begin()+y,x.end() - -using namespace std; - -typedef pair pii; - -typedef array arr2; - -const int inf = 1e18 + 30; - -const int N=1e5+15; - -const int mod=1e9+7; - -void smin(int&x,int y){x=min(x,y);} - -void smax(int&x,int y){x=max(x,y);} - -void help(){ - - int n,x,y;cin>>n>>x>>y; - - vector vec(n+1); - - if(n&1){ - - vec[x]=2; vec[x-1]=1,vec[x+1]=0; - - for(int i=x+2;i<=n;i++) - - vec[i]=vec[i-1]^1; - - for(int i=x-2;i>=1;i--) - - vec[i]=vec[i+1]^1; - - } - - else{ - - if(abs(x-y)&1) - - for(int i=1;i<=n;i++) - - vec[i]=vec[i-1]^1; - - else{ - - for(int i=x+1;i<=n;i++) - - vec[i]=vec[i-1]^1; - - for(int i=x-1;i>=1;i--) - - vec[i]=vec[i+1]^1; - - vec[y]=2; - - } - - } - - for(int i=1;i<=n;i++) - - cout<>t; - - while(t--){ - - help(); - - // cout< - -using namespace std; - -#define print_b(ans) cout<<(ans?""YES"":""NO"")<>x;while(x--) - -#define debug(x) cout<<#x<<"": ""<>n>>x>>y; - - if(x ans(n); - - ans[x-1]=1; - - ans[y-1]=0; - - int left=(x-y-1); - - int right=n-(x-y+1); - - if(left%2==0){ - - bool test=1; - - for(int i=y;i - -using namespace std; - -#define print_b(ans) cout<<(ans?""YES"":""NO"")<>x;while(x--) - -#define debug(x) cout<<#x<<"": ""<>n>>x>>y; - - if(x ans(n); - - ans[x-1]=1; - - ans[y-1]=0; - - int left=(x-y-1); - - int right=n-(x-y+1); - - if(left%2==0){ - - bool test=1; - - for(int i=y;i - -#define endl '\n' - -// #define int long long - -#define lowbit(x) x & -x - -using i64 = long long; - -using u64 = unsigned long long; - -using ld = long double; - -const int maxn = 2e5 + 5; - -const int inf = 0x7f7f7f7f; - -const int mod = 1e9 + 7; - - - -struct custom_hash - -{ - - static uint64_t splitmix64(uint64_t x) - - { - - x ^= x << 13; - - x ^= x >> 7; - - x ^= x << 17; - - return x; - - } - - size_t operator () (uint64_t x) const - - { - - static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳 - - return splitmix64(x + FIXED_RANDOM); - - } - -}; - -void solve() - -{ - - int n = 0, x = 0, y = 0; - - std::cin >> n >> x >> y; - - if (n & 1) - - { - - if (abs(x - y) & 1) - - { - - std::cout << 2 << "" ""; - - for (int i = 1; i <= n - 1; i++) - - { - - std::cout << (i % 2) << "" ""; - - } - - std::cout << endl; - - return; - - } - - else - - { - - for (int i = 1; i <= n; i++) - - { - - if (i == x) - - { - - std::cout << 2 << "" ""; - - } - - else - - { - - if(abs(x - i) & 1) - - { - - std::cout << 1 << "" ""; - - } - - else - - { - - std::cout << 0 << "" ""; - - } - - } - - } - - std::cout << endl; - - return; - - } - - } - - else - - { - - if (abs(x - y) & 1) - - { - - for (int i = 1; i <= n; i++) - - { - - std::cout << (i + 1) % 2 << "" ""; - - } - - std::cout << endl; - - return; - - } - - else - - { - - for (int i = 1; i <= n; i++) - - { - - if (i == x) - - { - - std::cout << 2 << "" ""; - - } - - else if (abs(x - i) & 1) - - { - - std::cout << 1 << "" ""; - - } - - else - - { - - std::cout << 0 << "" ""; - - } - - } - - std::cout << endl; - - return; - - } - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(nullptr); std::cout.tie(nullptr); - - //freopen(""out.txt"", ""w"", stdout); - - int t = 1; - - std::cin >> t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","#pragma optimize GCC(2) - -#pragma optimize GCC(3) - -#pragma optimize GCC(""Ofast"") - -#include - -#define endl '\n' - -// #define int long long - -#define lowbit(x) x & -x - -using i64 = long long; - -using u64 = unsigned long long; - -using ld = long double; - -const int maxn = 2e5 + 5; - -const int inf = 0x7f7f7f7f; - -const int mod = 1e9 + 7; - - - -struct custom_hash - -{ - - static uint64_t splitmix64(uint64_t x) - - { - - x ^= x << 13; - - x ^= x >> 7; - - x ^= x << 17; - - return x; - - } - - size_t operator () (uint64_t x) const - - { - - static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳 - - return splitmix64(x + FIXED_RANDOM); - - } - -}; - -void solve() - -{ - - int n = 0, x = 0, y = 0; - - std::cin >> n >> x >> y; - - if (n & 1) - - { - - for (int i = 1; i <= n; i++) - - { - - if (i == x) - - { - - std::cout << 2 << "" ""; - - } - - else if (i < x) - - { - - if ((x - i) & 1) std::cout << 0 << "" ""; - - if ((x - i) % 2 == 0) std::cout << 1 << "" ""; - - } - - else - - { - - if((i - x) & 1) std::cout << 1 << "" ""; - - if ((i - x) % 2 == 0) std::cout << 0 << "" ""; - - } - - } - - std::cout << endl; - - return; - - } - - else - - { - - if((abs(x - y) & 1) || (x == n && y == 1) || (x == 1 && y == n)) - - { - - for (int i = 1; i <= n; i++) - - { - - std::cout << (i + 1) % 2 << "" ""; - - } - - std::cout << endl; - - return; - - } - - for (int i = 1; i <= n; i++) - - { - - if (i == x) - - { - - std::cout << 2 << "" ""; - - } - - else if (abs(i - x) & 1) - - { - - std::cout << 0 << "" ""; - - } - - else - - { - - std::cout << 1 << "" ""; - - } - - } - - std::cout << endl; - - return; - - } - -} - - - -signed main() - -{ - - std::ios::sync_with_stdio(false); - - std::cin.tie(nullptr); std::cout.tie(nullptr); - - //freopen(""out.txt"", ""w"", stdout); - - int t = 1; - - std::cin >> t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",2 -shiqiDqi,2049C - MEX Cycle,c++17 ,304229421,304231002,"#include - -#define x first - -#define y second - -using namespace std; - -#define int long long - -typedef pair PII; - -typedef long long LL; - -const int N = 2e5+10; - -const int mod = 998244353; - -const int p = 1e9 + 7; - -int a[N]; - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - a[x] = 1, a[y] = 0; - - int t1 = abs(x-y)-1, t2 = n - 2 - t1; - - if(x > y)swap(x, y); - - int st = x+1; - - - - for(int i = 1; i <= t1/2; i ++) { - - a[st] = 0; - - a[st+1] = 1; - - st+=2; - - } - - if(t1%2)a[st] = 2; - - st = y+1; - - if(st > n)st-=n; - - for(int i = 1; i <= t2/ 2; i ++){ - - a[st] = 1; - - a[st+1] = 0; - - st+=2; - - if(st > n)st-=n; - - } - - if(t2%2)a[st] = 2; - - for(int i = 1; i <= n; i++)cout << a[i] <<' '; - - cout <> t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -#define x first - -#define y second - -using namespace std; - -#define int long long - -typedef pair PII; - -typedef long long LL; - -const int N = 2e5+10; - -const int mod = 998244353; - -const int p = 1e9 + 7; - -int a[N]; - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - a[x] = 1, a[y] = 0; - - int t1 = abs(x-y)-1, t2 = n - 2 - t1; - - if(x > y)swap(x, y); - - int st = x+1; - - - - for(int i = 1; i <= t1/2; i ++) { - - a[st] = 0; - - a[st+1] = 1; - - st+=2; - - } - - if(t1%2)a[st] = 2; - - st = y+1; - - if(st > n)st-=n; - - for(int i = 1; i <= t2/ 2; i ++){ - - if(st > n)st-=n; - - a[st] = 1; - - if(st+1 > n)st-=n; - - a[st+1] = 0; - - st+=2; - - } - - if(st > n)st-=n; - - if(t2%2)a[st] = 2; - - for(int i = 1; i <= n; i++)cout << a[i] <<' '; - - cout <> t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -freebie,2049C - MEX Cycle,c++23 ,307483975,307484594,"/*-----AUTHOR-------- - --------FREEBIE------- - -https://codeforces.com/profile/freebie - -*/ - - - -# include - -using namespace std; - - - -# define ll long long - -# define pb push_back - -# define mp make_pair - -# define f first - -# define s second - -# define mod 1000000007 - -# define py cout << ""YES"" << endl - -# define pn cout << ""NO"" << endl - -# define INF 1e18 - -# define vi vector - -# define vc vector - -# define vll vector - -# define pii pair - -# define pll pair - -# define vvi vector - -# define vvc vector - -# define vpii vector - -# define vpll vector - -# define all(x) x.begin(), x.end() - -# define endl ""\n"" - -# define forn(i, n) for(int i = 0; i < n; i++) - -# define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - - -int gcd(int a, int b){ - - if(b == 0){ - - return a; - - } - - return gcd(b, a%b); - -} - - - -int lcm(int a, int b){ - - return (a*b)/gcd(a, b); - -} - - - -bool isPrime(int n){ - - if(n == 1){ - - return false; - - } - - for(int i = 2; i*i <= n; i++){ - - if(n%i == 0){ - - return false; - - } - - } - - return true; - -} - - - -void sieve(int n){ - - bool prime[n+1]; - - memset(prime, true, sizeof(prime)); - - for(int p = 2; p*p <= n; p++){ - - if(prime[p] == true){ - - for(int i = p*p; i <= n; i += p){ - - prime[i] = false; - - } - - } - - } - -} - - - -ll binpow(ll a, ll b){ - - if(b == 0) return 1; - - if(b%2){ - - return (a * binpow(a, b-1)) % mod; - - } - - return binpow((a*a) % mod, b/2); - -} - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - // vi v(n+1); - - if(x == 1 && y == n){ - - // simply alternate between 0 and 1 if n is even - - if(n%2 == 0){ - - for(ll i=0 ; i> TCS; - - // TCS = 1; - - for (int TC = 1; TC <= TCS; ++TC) - - { - - solve(); - - } - -}","/*-----AUTHOR-------- - --------FREEBIE------- - -https://codeforces.com/profile/freebie - -*/ - - - -# include - -using namespace std; - - - -# define ll long long - -# define pb push_back - -# define mp make_pair - -# define f first - -# define s second - -# define mod 1000000007 - -# define py cout << ""YES"" << endl - -# define pn cout << ""NO"" << endl - -# define INF 1e18 - -# define vi vector - -# define vc vector - -# define vll vector - -# define pii pair - -# define pll pair - -# define vvi vector - -# define vvc vector - -# define vpii vector - -# define vpll vector - -# define all(x) x.begin(), x.end() - -# define endl ""\n"" - -# define forn(i, n) for(int i = 0; i < n; i++) - -# define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - - -int gcd(int a, int b){ - - if(b == 0){ - - return a; - - } - - return gcd(b, a%b); - -} - - - -int lcm(int a, int b){ - - return (a*b)/gcd(a, b); - -} - - - -bool isPrime(int n){ - - if(n == 1){ - - return false; - - } - - for(int i = 2; i*i <= n; i++){ - - if(n%i == 0){ - - return false; - - } - - } - - return true; - -} - - - -void sieve(int n){ - - bool prime[n+1]; - - memset(prime, true, sizeof(prime)); - - for(int p = 2; p*p <= n; p++){ - - if(prime[p] == true){ - - for(int i = p*p; i <= n; i += p){ - - prime[i] = false; - - } - - } - - } - -} - - - -ll binpow(ll a, ll b){ - - if(b == 0) return 1; - - if(b%2){ - - return (a * binpow(a, b-1)) % mod; - - } - - return binpow((a*a) % mod, b/2); - -} - - - -void solve(){ - - int n, x, y; - - cin >> n >> x >> y; - - // vi v(n+1); - - // if(x == 1 && y == n){ - - // // simply alternate between 0 and 1 if n is even - - // if(n%2 == 0){ - - // for(ll i=0 ; i> TCS; - - // TCS = 1; - - for (int TC = 1; TC <= TCS; ++TC) - - { - - solve(); - - } - -}",2 -gauravbro17,2049C - MEX Cycle,c++17 ,303908277,303905843,"#include - -using namespace std; - -#define int long long - -#define pb push_back - -#define ff first - -#define ss second - -#define pii pair - -#define vi vector - -#define vii vector> - - - -void solve() - -{ - - int n,x,y; - - cin >> n>>x>>y; - - vi v(n); - - x--,y--; - - for(int i=0; i> tcs; - - while (tcs--) - - { - - solve(); - - } - -}","#include - -using namespace std; - -#define int long long - -#define pb push_back - -#define ff first - -#define ss second - -#define pii pair - -#define vi vector - -#define vii vector> - - - -void solve() - -{ - - int n,x,y; - - cin >> n>>x>>y; - - vi v(n); - - - - if(x&1 && y&1){ - - v[x-1]=0; - - v[y-1]=2; - - }else{ - - v[x-1]=1; - - v[y-1]=2; - - } - - int i=x-2; - - while(i>=0){ - - if(v[i+1]==0){ - - v[i]=1; - - }else{ - - v[i]=0; - - } - - i--; - - } - - i=x; - - while(i> tcs; - - while (tcs--) - - { - - solve(); - - } - -}",1 -Tamas,2049C - MEX Cycle,c++23 ,304931251,304935460,"#include - - - -using namespace std; - - - -template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << "", "" << p.second << ')'; } - -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = "", ""; return os << '}'; } - -void dbg_out() { cerr << endl; } - -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } - -#ifdef LOCAL - -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) - -#else - -#define dbg(...) - -#endif - - - -#define ar array - -#define ll long long - -#define ld long double - -#define sza(x) ((int)x.size()) - -#define all(a) (a).begin(), (a).end() - - - -const int MAX_N = 1e5 + 5; - -const ll MOD = 1e9 + 7; - -const ll INF = 1e9; - -const ld EPS = 1e-9; - - - - - - - -void solve() { - - ll n,x,y; - - cin>>n>>x>>y; - - if(n%2==0){ - - - - for(int i=1;i<=n;i++){ - - if(i==x && (y-x)%2==0)cout<<2<<"" ""; - - else if(i%2==0)cout<<1<<"" ""; - - else cout<<0<<"" ""; - - } - - cout<<'\n'; - - - - - - - - } - - else{ - - - - for(int i=1;i<=x-1;i++){ - - if(i%2==0)cout<<0<<"" ""; - - else cout<<1<<"" ""; - - } - - cout<<2<<"" ""; - - if(x%2==0){ - - for(int i=x+1;i<=n;i++){ - - if(i%2==0)cout<<1<<"" ""; - - else cout<<0<<"" ""; - - } - - - - } - - else{ - - for(int i=x+1;i<=n;i++){ - - if(i%2==0)cout<<0<<"" ""; - - else cout<<1<<"" ""; - - } - - - - } - - cout<<'\n'; - - - - - - - - } - - - -} - - - -int main() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); cout.tie(0); - - int tc = 1; - - cin >> tc; - - for (int t = 1; t <= tc; t++) { - - // cout << ""Case #"" << t << "": ""; - - solve(); - - } - - - -}","#include - - - -using namespace std; - - - -template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << "", "" << p.second << ')'; } - -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = "", ""; return os << '}'; } - -void dbg_out() { cerr << endl; } - -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } - -#ifdef LOCAL - -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) - -#else - -#define dbg(...) - -#endif - - - -#define ar array - -#define ll long long - -#define ld long double - -#define sza(x) ((int)x.size()) - -#define all(a) (a).begin(), (a).end() - - - -const int MAX_N = 1e5 + 5; - -const ll MOD = 1e9 + 7; - -const ll INF = 1e9; - -const ld EPS = 1e-9; - - - - - - - -void solve() { - - ll n,x,y; - - cin>>n>>x>>y; - - if(n%2==0){ - - - - for(int i=1;i<=n;i++){ - - if(i==x && (y-x)%2==0)cout<<2<<"" ""; - - else if(i%2==0)cout<<1<<"" ""; - - else cout<<0<<"" ""; - - } - - cout<<'\n'; - - - - - - - - } - - else{ - - - - for(int i=1;i<=x-1;i++){ - - if(i%2==0)cout<<0<<"" ""; - - else cout<<1<<"" ""; - - } - - cout<<2<<"" ""; - - - - for(int i=x+1;i<=n;i++){ - - if(i%2==0)cout<<1<<"" ""; - - else cout<<0<<"" ""; - - } - - - - - - - - cout<<'\n'; - - - - - - - - } - - - -} - - - -int main() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); cout.tie(0); - - int tc = 1; - - cin >> tc; - - for (int t = 1; t <= tc; t++) { - - // cout << ""Case #"" << t << "": ""; - - solve(); - - } - - - -}",2 -AceTaffy258,2049C - MEX Cycle,c++20 ,304413578,304268211,"#include - -#define ll long long - -#define hachimi cat - -#define oukinkin milktea - -#define bacon maozedong - -#define my_son dengxiaoping - -#define winnie xijinping - -#define N 200005 - -using namespace std; - - - -int n,x,y; - -int a[N]; - -int main(){ - - std::ios::sync_with_stdio(0); - - cin.tie(0),cout.tie(0); - - int T;cin>>T; - - while(T--){ - - cin>>n>>x>>y; - - for(int i=1;i<=n;i++){ - - a[(x+i-1)%n+1]=i%2; - - } - - if(n%2||abs(x-y)%2==0){ - - a[x]=2; - - } - - for(int i=1;i<=n;i++){ - - cout< - -#define ll long long - -#define hachimi cat - -#define oukinkin milktea - -#define bacon maozedong - -#define my_son dengxiaoping - -#define winnie xijinping - -#define N 200005 - -using namespace std; - - - -int n; - -ll a[305][305],b[305]; - -int main(){ - - std::ios::sync_with_stdio(0); - - cin.tie(0),cout.tie(0); - - int T;cin>>T; - - while(T--){ - - cin>>n; - - for(int i=1;i<=n;i++){ - - a[i][n+1]=1;b[i]=0; - - for(int j=1;j<=n;j++){ - - cin>>a[i][j]; - - } - - } - - for(int i=1;i<=n;i++){ - - for(int j=n-1;j>=1;j--){ - - a[i][j]+=a[i][j+1]; - - } - - } - - priority_queue,greater > q; - - for(int i=1;i<=n;i++){ - - for(int j=1;j<=n;j++){ - - if(a[i][j]==n-j+1){ - - q.push(n-j+1);break; - - } - - } - - } - - //cout<<""ans=""; - - int ans=0; - - while(!q.empty()){ - - int x=q.top();q.pop(); - - if(x>=ans){ - - ans++; - - } - - cout< - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -typedef long long ll; - -template - -using ordered_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - -#define pb push_back - -#define pp pop_back - -#define endl '\n' - -#define dbg(x) cerr << #x << "" = "" << x << endl - -const int mod = 1e9 + 7; - -const double e = 1e-6; - - - -void solve() { - - ll n, x, y; - - cin >> n >> x >> y; - - vector a(n+1); - - if(y < x) swap(x, y); - - if((y-x)%2 || (n+y-x)%2) { - - for(ll i = 0; x+i < y; ++i){ - - if(i%2) a[i+x] = 1; - - else a[i+x] = 0; - - } - - a[y] = 2; - - for(ll i = 0; (n+x-i) > y ; i++){ - - if((x-i)%2){ - - if((n+x-i)%n == 0) a[n] = 1; - - else a[(n+x-i)%n] = 1; - - } - - else{ - - if((n+x-i)%n == 0) a[n] = 0; - - else a[(n+x-i)%n] = 0; - - } - - } - - } - - else{ - - for(ll i = 0; i < n; ++i){ - - if(i%2){ - - if((x+i)%n == 0) a[n] = 1; - - else a[(x+i)%n] = 1; - - } - - else{ - - if((x+i)%n == 0) a[n] = 0; - - else a[(x+i)%n] = 0; - - } - - } - - } - - for(ll i = 1; i <= n; ++i) cout << a[i] << "" ""; - - cout << endl; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; cin >> t; while(t--) - - solve(); - -} - -","#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -typedef long long ll; - -template - -using ordered_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - -#define pb push_back - -#define pp pop_back - -#define endl '\n' - -#define dbg(x) cerr << #x << "" = "" << x << endl - -const int mod = 1e9 + 7; - -const double e = 1e-6; - - - -void solve() { - - ll n, x, y; - - cin >> n >> x >> y; - - vector a(n+1); - - if(y < x) swap(x, y); - - if((y-x)%2 == 0 || (n+y-x)%2 == 0){ - - for(ll i = 0; x+i < y; ++i){ - - if(i%2) a[i+x] = 1; - - else a[i+x] = 0; - - } - - a[y] = 2; - - for(ll i = 0; (n+x-i) > y ; i++){ - - if(i%2){ - - if((n+x-i)%n == 0) a[n] = 1; - - else a[(n+x-i)%n] = 1; - - } - - else{ - - if((n+x-i)%n == 0) a[n] = 0; - - else a[(n+x-i)%n] = 0; - - } - - } - - } - - else{ - - for(ll i = 0; i < n; ++i){ - - if(i%2){ - - if((x+i)%n == 0) a[n] = 1; - - else a[(x+i)%n] = 1; - - } - - else{ - - if((x+i)%n == 0) a[n] = 0; - - else a[(x+i)%n] = 0; - - } - - } - - } - - for(ll i = 1; i <= n; ++i) cout << a[i] << "" ""; - - cout << endl; - -} - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - int t; cin >> t; while(t--) - - solve(); - -} - -",2 -AustinWang#,2049C - MEX Cycle,c++20 ,304782265,304782853,"#include - -using namespace std; - -const int N=505; - -int t,n,x,y; - -int cha(int a,int b){ - - if (a>b) swap(a,b); - - return min(b-a,a+n-b); - -} - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - if (n%2==1){ - - for (int i=1;i<=n-1;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}","#include - -using namespace std; - -const int N=505; - -int t,n,x,y; - -void solve(){ - - cin>>n>>x>>y; - - if (x>y) swap(x,y); - - int a=y-x,b=x+n-y; - - if (a>b) swap(a,b); - - if (a==1){ - - if (n%2==1){ - - for (int i=1;i<=n-1;i++) cout<>t; - - while (t--) solve(); - - return 0; - -}",2 -Golam_Rabbany,2050B - Transfusion,c++20 ,308229680,308229248,"#include - -#include - -#include - - - -using namespace std; - -using namespace __gnu_pbds; - - - -template - -#define ll long long int - -#define endl ""\n"" - -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -using ordered_multiset = tree , rb_tree_tag, tree_order_statistics_node_update>; - -#define vsort sort(v.begin(),v.end()) - -#define yes cout << ""Yes\n"" - -#define no cout << ""No\n"" - - - -ll lcm(ll x, ll y) - -{ - - return (x * y) / __gcd(x, y); - -} - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - while(t--) - - { - - - - ll n; - - cin>>n; - - ll odd=0,even=0,sum=0; - - ll oo,ee; - - vectorv; - - for(int i=0;i>x; - - if((i+1)%2!=0)odd+=x; - - else even+=x; - - sum+=x; - - v.push_back(x); - - } - - oo=(n+1)/2; - - ee=n/2; - - ll k=sum/n; - - //cout< - -#include - -#include - - - -using namespace std; - -using namespace __gnu_pbds; - - - -template - -#define ll long long int - -#define endl ""\n"" - -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -using ordered_multiset = tree , rb_tree_tag, tree_order_statistics_node_update>; - -#define vsort sort(v.begin(),v.end()) - -#define yes cout << ""Yes\n"" - -#define no cout << ""No\n"" - - - -ll lcm(ll x, ll y) - -{ - - return (x * y) / __gcd(x, y); - -} - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - while(t--) - - { - - int n; - - cin>>n; - - int odd=0,even=0,sum=0; - - int oo,ee; - - vectorv; - - for(int i=0;i>x; - - if((i+1)%2!=0)odd+=x; - - else even+=x; - - sum+=x; - - v.push_back(x); - - } - - oo=(n+1)/2; - - ee=n/2; - - int k=sum/n; - - //cout< -using namespace std; -#define int long long - - -void solv() { - int n; - cin>>n; - vectorv(n); - for(auto &i:v) cin>>i; - int odd=0, even=0, sum = 0; - for(int i=0;i> t; - while (t--) { - solv(); - } - return 0; -} -","#include -using namespace std; - - - -void solv() { - int n; - cin>>n; - vectorv(n); - for(auto &i:v) cin>>i; - int odd=0, even=0, sum = 0; - for(int i=0;i> t; - while (t--) { - solv(); - } - return 0; -} -",1 -mostafa_abdalshafy1,2050B - Transfusion,c++17 ,306264255,306262472,"// بسم الله الرحمن الرحيم // - - - -// ███╗ ███╗ █████╗ ██████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗ - -// ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗ - -// ██╔████╔██║███████║╚█████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗██║██║ ██║ - -// ██║╚██╔╝██║██╔══██║ ╚═══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚████║██║ ██║ - -// ██║ ╚═╝ ██║██║ ██║██████╔╝ ██║ ███████╗██║ ██║██ ╚═╝ ██║██║██║ ╚███║██████╔╝ - -// ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚══╝╚═════╝ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define MOD 1000000007 - -#define PI 3.14159265 - -// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0)) - -#define nl '\n' - -#define pb push_back - -#define tc \ - - int t; \ - - cin >> t; - -#define fast std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define sz size() - -#define all(v) v.begin(), v.end() - -void Mastermind() - -{ - - ios::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -bool checkBit(int x, int idx) - -{ - - return x & (1 << idx); - -} - -bool checkBit2(int x, int idx) - -{ - - return (x >> idx) & 1; - -} - -bool setBitToOne(int x, int idx) - -{ - - return x | (1 << idx); - -} - -bool setBitToZero(int x, int idx) - -{ - - return x & ~(1 << idx); - -} - -bool flipIdx(int x, int idx) - -{ - - // bit ^ 1 - - // 0^1 (bit= 1) - - // 1^1 (bit= 0) - - return x ^ (1 << idx); - -} - -int countOns(int x) // or bult in function -> __builtin_popcount(x) - -{ - - int cnt = 0; - - for (int i = 0; i <= 31; i++) - - cnt += checkBit(x, i); - -} - -// ll gcd(ll a, ll b) - -// { - -// if(b==0)return a; - -// return gcd(b,b%a); - -// } - -// ll lcm(ll a, ll b) - -// { - -// return a / gcd(a, b) * b; - -// } - - - -// // <------------------------------------------------> - - - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, b % a); - -} - -ll lcm(ll a, ll b) - -{ - - return a / gcd(a, b) * b; - -} - - - -// <------------------------------------------------> - - - -int FAST_POWER(int x, int n) - -{ - - int result = 1; - - while (n > 0) - - { - - if (n % 2 == 1) - - result = result * x; - - x = x * x; - - n = n / 2; - - } - - return result; - -} - - - -// fast power { time : log {n}} - -// <------------------------------------------------> - - - -bool isPerfectSquare(int x) - -{ - - if (x < 0) - - return false; - - int s = sqrt(x); - - return (s * s == x); - -} - - - -// <------------------------------------------------> - - - -vector prime_factorization(int n) - -{ - - vector v; - - for (int i = 2; i * i <= n; i++) - - { - - while (n % i == 0) - - { - - v.push_back(i); - - n /= i; - - } - - } - - if (n > 1) - - v.push_back(n); - - return v; - -} - - - -bool comp(const pair &a, const pair &b) - -{ - - if (a.second == b.second) - - { - - return a.first > b.first; - - } - - else - - { - - return a.second > b.second; - - } - -} - -// _____________________________________ Solve. ______________________________________________________ - -int Ones(vector v) - -{ - - int c = 0; - - for (auto &i : v) - - { - - if (i == 1) - - c++; - - } - - return c; - -} - -int main() - -{ - - // Mastermind(); - - fast; - - - - tc; - - while (t--) - - { - - int n; - - cin >> n; - - vector v(n); - - ll sum = 0; - - for (auto &i : v) - - { - - cin >> i; - - sum += i; - - } - - ll sum_odd = 0, sum_even = 0, c_odd = 0; - - - - for (int i = 0; i < n; i++) - - { - - if (i & 1) - - { - - sum_odd += v[i]; - - c_odd++; - - } - - else - - sum_even += v[i]; - - } - - if (!(sum % n) && sum_odd / c_odd == sum_even / (n - c_odd)) - - { - - cy; - - } - - else - - cn; - - } - - - - return 0; - -}","// بسم الله الرحمن الرحيم // - - - -// ███╗ ███╗ █████╗ ██████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗ - -// ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗ - -// ██╔████╔██║███████║╚█████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗██║██║ ██║ - -// ██║╚██╔╝██║██╔══██║ ╚═══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚████║██║ ██║ - -// ██║ ╚═╝ ██║██║ ██║██████╔╝ ██║ ███████╗██║ ██║██ ╚═╝ ██║██║██║ ╚███║██████╔╝ - -// ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚══╝╚═════╝ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define MOD 1000000007 - -#define PI 3.14159265 - -// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0)) - -#define nl '\n' - -#define pb push_back - -#define tc \ - - int t; \ - - cin >> t; - -#define fast std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define sz size() - -#define all(v) v.begin(), v.end() - -void Mastermind() - -{ - - ios::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -bool checkBit(int x, int idx) - -{ - - return x & (1 << idx); - -} - -bool checkBit2(int x, int idx) - -{ - - return (x >> idx) & 1; - -} - -bool setBitToOne(int x, int idx) - -{ - - return x | (1 << idx); - -} - -bool setBitToZero(int x, int idx) - -{ - - return x & ~(1 << idx); - -} - -bool flipIdx(int x, int idx) - -{ - - // bit ^ 1 - - // 0^1 (bit= 1) - - // 1^1 (bit= 0) - - return x ^ (1 << idx); - -} - -int countOns(int x) // or bult in function -> __builtin_popcount(x) - -{ - - int cnt = 0; - - for (int i = 0; i <= 31; i++) - - cnt += checkBit(x, i); - -} - -// ll gcd(ll a, ll b) - -// { - -// if(b==0)return a; - -// return gcd(b,b%a); - -// } - -// ll lcm(ll a, ll b) - -// { - -// return a / gcd(a, b) * b; - -// } - - - -// // <------------------------------------------------> - - - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, b % a); - -} - -ll lcm(ll a, ll b) - -{ - - return a / gcd(a, b) * b; - -} - - - -// <------------------------------------------------> - - - -int FAST_POWER(int x, int n) - -{ - - int result = 1; - - while (n > 0) - - { - - if (n % 2 == 1) - - result = result * x; - - x = x * x; - - n = n / 2; - - } - - return result; - -} - - - -// fast power { time : log {n}} - -// <------------------------------------------------> - - - -bool isPerfectSquare(int x) - -{ - - if (x < 0) - - return false; - - int s = sqrt(x); - - return (s * s == x); - -} - - - -// <------------------------------------------------> - - - -vector prime_factorization(int n) - -{ - - vector v; - - for (int i = 2; i * i <= n; i++) - - { - - while (n % i == 0) - - { - - v.push_back(i); - - n /= i; - - } - - } - - if (n > 1) - - v.push_back(n); - - return v; - -} - - - -bool comp(const pair &a, const pair &b) - -{ - - if (a.second == b.second) - - { - - return a.first > b.first; - - } - - else - - { - - return a.second > b.second; - - } - -} - -// _____________________________________ Solve. ______________________________________________________ - -int Ones(vector v) - -{ - - int c = 0; - - for (auto &i : v) - - { - - if (i == 1) - - c++; - - } - - return c; - -} - -int main() - -{ - - // Mastermind(); - - fast; - - - - tc; - - while (t--) - - { - - int n; - - cin >> n; - - vector v(n); - - ll sum = 0; - - for (auto &i : v) - - { - - cin >> i; - - sum += i; - - } - - // cerr << Ones(v) << "" ""; - - if (!(sum % n) && Ones(v) < 2) - - { - - cy; - - } - - else - - cn; - - } - - - - return 0; - -}",1 -YuRC,2050B - Transfusion,c++17 ,299436460,299436414,"#include -using namespace std; - -#define ll long long - -void solve() -{ - int n; - cin >> n; - ll a[2] = {0}; - for (int i = 0, tt; i < n; ++i) - { - cin >> tt; - a[i % 2] += tt; - } - if (a[0] % (n + 1 >> 1) == 0 && a[1] % (n >> 1) == 0 && a[0] / (n + 1 >> 1) == a[1] / (n >> 1)) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}","#include -using namespace std; - -void solve() -{ - int n; - cin >> n; - ll a[2] = {0}; - for (int i = 0, tt; i < n; ++i) - { - cin >> tt; - a[i % 2] += tt; - } - if (a[0] % (n + 1 >> 1) == 0 && a[1] % (n >> 1) == 0 && a[0] / (n + 1 >> 1) == a[1] / (n >> 1)) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}",1 -hgopani,2050B - Transfusion,c++23 ,306071961,306072244,"#include - -using namespace std; - -typedef long long w; - - - -int main(){ - -int t; - -cin>>t; - -while(t--){ - - w n; - - cin>>n; w a[n];w sum=0; - - for(int i=0;i>a[i]; - - sum+=a[i]; - - } - - int b=sum/n; - - if(sum%n==0){ - - int r=1; - - for(int i=1;ib){ - - w c=a[i-1]-b; - - a[i-1]=b; - - a[i+1]=a[i+1]+c; - - } - - else if(a[i-1] - -using namespace std; - -typedef long long w; - - - -int main(){ - -int t; - -cin>>t; - -while(t--){ - - w n; - - cin>>n; vector a(n);w sum=0; - - for(int i=0;i>a[i]; - - sum+=a[i]; - - } - - int b=sum/n; - - if(sum%n==0){ - - int r=1; - - for(int i=1;ib){ - - w c=a[i-1]-b; - - a[i-1]=b; - - a[i+1]=a[i+1]+c; - - } - - else if(a[i-1] a){ - return -1; - } - else if(((Pair)o).a < a){ - return 1; - } - else{ - if(((Pair)o).b > b){ - return 1; - } - else if(((Pair)o).b < b){ - return -1; - } - else{ - return 0; - } - - } - } - public String toString(){ - return a + "" "" + b; - } -}"," import java.io.*; -import java.math.BigInteger; -import java.util.*; -public class Main{ - public static void main(String[] args) throws IOException{ - Scanner sc= new Scanner(System.in); - int t = sc.nextInt(); - for(int i=0;i a){ - return -1; - } - else if(((Pair)o).a < a){ - return 1; - } - else{ - if(((Pair)o).b > b){ - return 1; - } - else if(((Pair)o).b < b){ - return -1; - } - else{ - return 0; - } - - } - } - public String toString(){ - return a + "" "" + b; - } -}",1 -prashants18488,2050B - Transfusion,python,299660397,299616415,"t = int(input()) -for _ in range(t): - n = int(input()) - a = list(map(int, input().split())) - b = [a[i] for i in range(n) if i % 2 == 0] - c=[a[i] for i in range(n) if i % 2 != 0] - - if sum(b)%len(b)==0: - if sum(c)%len(c)==0 and sum(b)//len(b)==sum(c)//len(c): - print(""YES"") - else: - print(""NO"") - else: - print(""NO"")","t=int(input()) -for i in range(t): - n=int(input()) - a=list(map(int,input().split())) - b=[] - c=[0*t for m in range(t)] - count=0 - count2=0 - mean=2*sum(a)//n - if sum(a)%n!=0: - print(""NO"") - else: - for j in range(n-2): - b.append(abs(a[j]+a[j+2])) - for k in range(n-2): - if b[k]%2==0: - count+=2 - else: - c[i]+=1 - if mean in b: - if (count+c[i])%2==0: - print(""YES"") - else: - print(""NO"") - else: - print(""NO"")",1 -akgoyal2111,2050B - Transfusion,c++17 ,299556510,299564001,"#include -using namespace std; -#define int long long -#define forr(i,x,n) for(int i = x; i < n ; i ++ ) - -int32_t main() { - int t; - cin>>t; - while(t--){ - int n ; - cin >> n; - int a[n] ; - int s=0; - forr(i,0, n){ - cin >> a[i] ; - s+=a[i]; - } - bool ok = false ; - if(s%n==0){ok = true ;} - else { ok = false ;} - - if(ok) { - int x = s/n; - forr(i,1,n-1) { - - if(a[i-1] >= x && a[i+1] > x ) { - ok = false ; - } - else if(a[i-1] > x && a[i+1] >= x) ok = false ; - else if(a[i-1] <= x && a[i+1] < x ) { - ok = false; - } - - else if(a[i-1] < x && a[i+1] <= x) ok = false ; - else { - if(a[i-1] > x && a[i+1] < x) { - a[i+1]+= a[i-1] - x ; - } - else if(a[i-1] < x && a[i+1] > x ){ - a[i-1]+= a[i+1] - x ; - a[i+1] = x ; } - } - } - } - - - if(ok) cout<< ""YES"" << endl ; - else cout << ""NO"" << endl ; - - } - -} -","#include -using namespace std; -#define int long long -#define forr(i,x,n) for(int i = x; i < n ; i ++ ) - -int32_t main() { - int t; - cin>>t; - while(t--){ - int n ; - cin >> n; - int a[n] ; - int s=0; - int pe=0 , le = 0 ; - int po=0 , lo = 0 ; - forr(i,0, n){ - cin >> a[i] ; - s+=a[i]; - } - bool ok = false ; - if(s%n==0){ok = true ;} - else { ok = false ;} - - if(ok) { - int x = s/n; - forr(i,0,n) { - - if(i%2==0) { - if (a[i] > x) { - pe+= a[i] - x; - } - else le+= x - a[i]; - } - else { - if(a[i]>x) po+= a[i] - x; - else lo+= x - a[i]; - } - - } - } - if(ok && po == lo && pe == le ) cout << ""YES"" << endl ; - else cout<< ""NO"" << endl ; - - - - - // if(ok) cout<< ""YES"" << endl ; - // else cout << ""NO"" << endl ; - - } - -} -",2 -Ahish_Ragav,2050B - Transfusion,c++17 ,308932210,308932483,"#include - -using namespace std; - -void solve(){ - - int n;cin>>n; - - vector vec(n+1); - - vec[0]=0; - - for(int i=1;i<=n;i++){ - - cin>>vec[i]; - - } - - - - int odd=0,even=0; - - for(int i=1;i<=n;i++){ - - if(i&1) odd+=vec[i]; - - else even+=vec[i]; - - } - - if(n%2==0){ - - if(even==odd && even%(n/2)==0){ - - cout<<""YES""<>t; - - while(t--){ - - solve(); - - }; - -}","#include - -using namespace std; - -void solve(){ - - int n;cin>>n; - - vector vec(n+1); - - vec[0]=0; - - for(int i=1;i<=n;i++){ - - cin>>vec[i]; - - } - - - - long long int odd=0,even=0; - - for(int i=1;i<=n;i++){ - - if(i&1) odd+=vec[i]; - - else even+=vec[i]; - - } - - if(n%2==0){ - - if(even==odd && even%(n/2)==0){ - - cout<<""YES""<>t; - - while(t--){ - - solve(); - - }; - -}",2 -wuhu_,2050B - Transfusion,c++23 ,295999630,296000165,"#include -using namespace std; -int main(){ - int t,num; - cin>>t; - while(t--){ - int n; - cin>>n; - int a[2]{}; - for(int i=0;i>num; - a[i&1]+=num; - } - if((a[0]+a[1])%n==0&&(a[0]%(n/2))==0&&(a[1]%(n/2-(n%2)))==0&&(a[0]/(n/2))==(a[1]/(n/2-(n%2)))){ - cout<<""yes""< -using namespace std; -int main(){ - int t,num; - cin>>t; - while(t--){ - int n; - cin>>n; - long long a[2]{}; - for(int i=0;i>num; - a[i&1]+=num; - } - if((a[0]+a[1])%n==0&&(a[0]%((n+1)/2))==0&&(a[1]%(n/2))==0&&(a[0]/((n+1)/2))==((a[0]+a[1])/n)){ - cout<<""yes""< -using namespace std; -#define int long long - -void solve(){ - int n; - cin>>n; - int sum_odd = 0; - int sum_even = 0; - int cnt_odd = 0; - int cnt_even = 0; - for(int i=1;i<=n;i++){ - int x; - cin>>x; - if(i%2==0){ - sum_even+=x; - cnt_even++; - }else{ - sum_odd+=x; - cnt_odd++; - } - } - - if(sum_even%cnt_even==0 && sum_odd%cnt_odd==0 && sum_even/cnt_even == sum_odd/cnt_odd){ - cout<<""YES""<> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; -#define int long long - -void solve(){ - int n; - cin>>n; - int sum_odd = 0; - int sum_even = 0; - int cnt_odd = 0; - int cnt_even = 0; - for(int i=1;i<=n;i++){ - int x; - cin>>x; - if(i%2==0){ - sum_even+=x; - cnt_even++; - }else{ - sum_odd+=x; - cnt_odd++; - } - } - - if(sum_even%cnt_even==0 && sum_odd%cnt_odd==0 && sum_even/cnt_even == sum_odd/cnt_odd){ - cout<<""YES""<> t; - while (t--) { - solve(); - } - return 0; -}",2 -satvik08,2050B - Transfusion,python,299493441,299494396,"def process_array(): - _size = int(input()) - a =list(map(int, input().split())) - sum1 = 0 - odd= (_size+1)/2 - sum2 = 0 - even = _size-odd - for i in range(_size): - if i%2==0 : - sum1+=a[i] - else : - sum2+=a[i] - if (sum1+sum2)%_size==0 : - if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size): - print(""YES"") - return - else: - print(""NO"") - return - else: - print(""NO"") - -t = int(input()) -for _ in range(t): - process_array() -","def process_array(): - _size = int(input()) - a =list(map(int, input().split())) - sum1 = 0 - odd= (_size+1)//2 - sum2 = 0 - even = _size-odd - for i in range(_size): - if i%2==0 : - sum1+=a[i] - - else : - sum2+=a[i] - # print(sum1, sum2, odd ,even) - if (sum1+sum2)%_size==0 : - if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size): - print(""YES"") - return - else: - print(""NO"") - return - else: - print(""NO"") - -t = int(input()) -for _ in range(t): - process_array() -",2 -xGONZOx,2050B - Transfusion,c++20 ,306668463,306668554,"#include - -using namespace std; - -int main () { - - ios_base::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t; cin >> t; - - while(t--) { - - int n; cin >> n; - - long long x, suma = 0, sumb=0; - - for(int i = 1; i < n+1; ++i) { - - cin >> x; - - if(i%2==0) { - - sumb += x; - - } else { - - suma += x; - - } - - } - - - - if(n%2==0) { - - int f = n/2; - - if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f+1)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } else { - - int f = n/2; - - if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } - - - - } - -}","#include - -using namespace std; - -int main () { - - ios_base::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t; cin >> t; - - while(t--) { - - int n; cin >> n; - - long long x, suma = 0, sumb=0; - - for(int i = 1; i < n+1; ++i) { - - cin >> x; - - if(i%2==0) { - - sumb += x; - - } else { - - suma += x; - - } - - } - - - - if(n%2==0) { - - int f = n/2; - - if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } else { - - int f = n/2; - - if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } - - - - } - -}",2 -menqian1#,2050B - Transfusion,c++17 ,306279200,306278745,"// Problem: B. Transfusion - -// Contest: Codeforces - Codeforces Round 991 (Div. 3) - -// URL: https://codeforces.com/contest/2050/problem/B - -// Memory Limit: 256 MB - -// Time Limit: 2000 ms - -// - -// Powered by CP Editor (https://cpeditor.org) - - - -//#pragma GCC optimize(""O3"") - -//#pragma GCC optimize(""Ofast"") - - - -#include - -#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) - -#define pii pair - -#define pdd pair - -#define lowbit(x) (x & -x) - -#define all(x) x.begin(), x.end() - - - -#define Rep(i, x) for(auto &i : x) - -#define L(i, x, y) for(int i = x; i <= y; ++ i) - -#define R(i, x, y) for(int i = x; i >= y; -- i) - -#define rd(x) scanf(""%lld"", &(x)) - -#define p_b push_back - -#define ft first - -#define sd second - -using namespace std; - -template using vc = vector; - -template using _pq = priority_queue, greater>; - -using i64 = long long; - -using u64 = unsigned long long; - -using u32 = unsigned; - -const int N = 2e5 + 10; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void solve() { - - int n; cin >> n; - - vc a(n); - - L(i, 0, n - 1) cin >> a[i]; - - i64 sum = reduce(a.begin(), a.end()); - - if(sum % n) { - - cout << ""NO\n""; - - return; - - } - - int sd = sum / n; - - //cout << sd << ""\n""; - - L(i, 0, n - 1) { - - //cout << i << "" "" << a[i] << ""\n""; - - if(i >= n - 2 && a[i] != sd) { - - cout << ""NO\n""; - - return; - - } - - if(a[i] == sd) continue; - - else { - - if((a[i] + a[i + 2]) / 2 != sd || (a[i] + a[i + 2]) % 2) { - - if(a[i] < sd) { - - int dif = sd - a[i]; - - a[i] = sd; - - if(a[i + 2] >= dif) a[i + 2] -= dif; - - else { - - cout << ""NO\n""; - - return; - - } - - } - - else { - - int dif = a[i] - sd; - - a[i] = sd; - - a[i + 2] += dif; - - } - - - - } - - else { - - a[i] = (a[i] + a[i + 2]) / 2; - - a[i + 2] = a[i]; - - } - - - - } - - } - - //L() - - cout << ""YES\n""; - -} - - - - - -int main() { - - Begin; - - int _; _ = 1; - - cin >> _; - - while(_--) solve(); - - return 0; - -}","// Problem: B. Transfusion - -// Contest: Codeforces - Codeforces Round 991 (Div. 3) - -// URL: https://codeforces.com/contest/2050/problem/B - -// Memory Limit: 256 MB - -// Time Limit: 2000 ms - -// - -// Powered by CP Editor (https://cpeditor.org) - - - -//#pragma GCC optimize(""O3"") - -//#pragma GCC optimize(""Ofast"") - - - -#include - -#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) - -#define pii pair - -#define pdd pair - -#define lowbit(x) (x & -x) - -#define all(x) x.begin(), x.end() - - - -#define Rep(i, x) for(auto &i : x) - -#define L(i, x, y) for(int i = x; i <= y; ++ i) - -#define R(i, x, y) for(int i = x; i >= y; -- i) - -#define rd(x) scanf(""%lld"", &(x)) - -#define p_b push_back - -#define ft first - -#define sd second - -using namespace std; - -template using vc = vector; - -template using _pq = priority_queue, greater>; - -using i64 = long long; - -using u64 = unsigned long long; - -using u32 = unsigned; - -const int N = 2e5 + 10; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void solve() { - - int n; cin >> n; - - vc a(n); - - L(i, 0, n - 1) cin >> a[i]; - - i64 sum = reduce(a.begin(), a.end()); - - if(sum % n) { - - cout << ""NO\n""; - - return; - - } - - int sd = sum / n; - - //cout << sd << ""\n""; - - L(i, 0, n - 1) { - - //cout << i << "" "" << a[i] << ""\n""; - - if(i >= n - 2 && a[i] != sd) { - - cout << ""NO\n""; - - return; - - } - - if(a[i] == sd) continue; - - else { - - if((a[i] + a[i + 2]) / 2 != sd || (a[i] + a[i + 2]) % 2) { - - int dif = a[i] - sd; - - a[i + 2] += dif; - - continue; - - } - - else { - - a[i] = (a[i] + a[i + 2]) / 2; - - a[i + 2] = a[i]; - - } - - - - } - - } - - cout << ""YES\n""; - -} - - - - - -int main() { - - Begin; - - int _; _ = 1; - - cin >> _; - - while(_--) solve(); - - return 0; - -}",1 -Sakamoto_11,2050B - Transfusion,c++17 ,308912805,308912689,"#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - long long int n; - - cin>>n; - - vectorritik(n); - - for(int i=0;i>ritik[i]; - - long long int sum_o=0,sum_e=0; - - long long int c1=0,c2=0; - - for(int i=0;i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vectorritik(n); - - for(int i=0;i>ritik[i]; - - int sum_o=0,sum_e=0; - - int c1=0,c2=0; - - for(int i=0;i -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int a[n]; - for(int i=0;i>a[i]; - } - int even= (n+1)/2; - int odd= n/2; - int x,y; - x=0; - y=0; - for(int i=0;i -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int a[n]; - for(int i=0;i>a[i]; - } - int even= (n+1)/2; - int odd= n/2; - long long x,y; - x=0; - y=0; - for(int i=0;i - -using namespace std; -#define int long long - -void helper() -{ - int n; - cin >> n; - - int odd = 0, even = 0; - for(int i =0; i>x; - if(i%2) odd += x; - else even += x; - } - int odc = n/2 , evc = n/2 ; - if(n&1) evc +=1 ; - - if(odd%odc != 0 || even%evc != 0 || odd/odc != even/evc){ - cout<<""NO""<> t; - while (t--) - { - helper(); - } -} -","#include -#include -#include - -using namespace std; -#define int long long - -void helper() -{ - int n; - cin >> n; - vector v(n); - - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - - for (int i = 1; i < n-1; i += 1) - { - long long sum = v[i - 1]; - sum += v[i + 1]; - long long div = sum /2 ; - if(sum%2 == 0){ - v[i - 1] = div; - v[i + 1] = div; - }else { - v[i - 1] = div; - v[i + 1] = div+1; - } - } - - for (int i = 1; i < n; i++) - { - - if (v[i - 1] != v[i]) - { - cout << ""NO"" << endl; - return; - } - } - cout << ""YES"" << endl; -} - -signed main() -{ - if (1) - { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - } - int t; - cin >> t; - while (t--) - { - helper(); - } -}",1 -Bandon,2050B - Transfusion,c++20 ,305824127,305823995,"#include - -using namespace std; - -const int N = 2e5 + 5; - -typedef long long ll; - -vector num(N); - -void solve() - -{ - - int n; - - cin >> n; - - ll sum = 0; - - for (int i = 1; i <= n; i++) - - { - - cin >> num[i]; - - sum += num[i]; - - } - - if ((sum % n) != 0) - - { - - cout << ""NO"" << endl; - - return; - - } - - ll p = sum / n; - - for (int i = 1; i <= n - 2; i++) - - { - - if (num[i] < p) - - { - - num[i + 2] -= (p - num[i]); - - } - - else - - { - - num[i + 2] += (num[i] - p); - - } - - num[i] = p; - - } - - if (num[n] == p && num[n - 1] == p) - - cout << ""YES"" << endl; - - else - - cout << ""NO"" << endl; - -} - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - solve(); - - } - -} - -","#include - -using namespace std; - -const int N = 2e5 + 5; - -typedef long long ll; - -vector num(N); - -void solve() - -{ - - int n; - - cin >> n; - - ll sum = 0; - - for (int i = 1; i <= n; i++) - - { - - cin >> num[i]; - - sum += num[i]; - - } - - if ((sum % n) != 0) - - { - - cout << ""NO"" << endl; - - return; - - } - - ll p = sum / n; - - for (int i = 1; i <= n - 2; i++) - - { - - if (num[i] < p) - - { - - num[i + 2] -= (p - num[i]); - - } - - else - - { - - num[i + 2] += (num[i] - p); - - } - - if(num[i+2] < 0) - - { - - cout << ""NO"" << endl; - - return; - - } - - } - - if (num[n] == p && num[n - 1] == p) - - cout << ""YES"" << endl; - - else - - cout << ""NO"" << endl; - -} - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - solve(); - - } - -} - -",1 -mostafa_abdalshafy1,2050B - Transfusion,c++17 ,306262529,306264255,"// بسم الله الرحمن الرحيم // - - - -// ███╗ ███╗ █████╗ ██████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗ - -// ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗ - -// ██╔████╔██║███████║╚█████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗██║██║ ██║ - -// ██║╚██╔╝██║██╔══██║ ╚═══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚████║██║ ██║ - -// ██║ ╚═╝ ██║██║ ██║██████╔╝ ██║ ███████╗██║ ██║██ ╚═╝ ██║██║██║ ╚███║██████╔╝ - -// ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚══╝╚═════╝ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define MOD 1000000007 - -#define PI 3.14159265 - -// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0)) - -#define nl '\n' - -#define pb push_back - -#define tc \ - - int t; \ - - cin >> t; - -#define fast std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define sz size() - -#define all(v) v.begin(), v.end() - -void Mastermind() - -{ - - ios::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -bool checkBit(int x, int idx) - -{ - - return x & (1 << idx); - -} - -bool checkBit2(int x, int idx) - -{ - - return (x >> idx) & 1; - -} - -bool setBitToOne(int x, int idx) - -{ - - return x | (1 << idx); - -} - -bool setBitToZero(int x, int idx) - -{ - - return x & ~(1 << idx); - -} - -bool flipIdx(int x, int idx) - -{ - - // bit ^ 1 - - // 0^1 (bit= 1) - - // 1^1 (bit= 0) - - return x ^ (1 << idx); - -} - -int countOns(int x) // or bult in function -> __builtin_popcount(x) - -{ - - int cnt = 0; - - for (int i = 0; i <= 31; i++) - - cnt += checkBit(x, i); - -} - -// ll gcd(ll a, ll b) - -// { - -// if(b==0)return a; - -// return gcd(b,b%a); - -// } - -// ll lcm(ll a, ll b) - -// { - -// return a / gcd(a, b) * b; - -// } - - - -// // <------------------------------------------------> - - - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, b % a); - -} - -ll lcm(ll a, ll b) - -{ - - return a / gcd(a, b) * b; - -} - - - -// <------------------------------------------------> - - - -int FAST_POWER(int x, int n) - -{ - - int result = 1; - - while (n > 0) - - { - - if (n % 2 == 1) - - result = result * x; - - x = x * x; - - n = n / 2; - - } - - return result; - -} - - - -// fast power { time : log {n}} - -// <------------------------------------------------> - - - -bool isPerfectSquare(int x) - -{ - - if (x < 0) - - return false; - - int s = sqrt(x); - - return (s * s == x); - -} - - - -// <------------------------------------------------> - - - -vector prime_factorization(int n) - -{ - - vector v; - - for (int i = 2; i * i <= n; i++) - - { - - while (n % i == 0) - - { - - v.push_back(i); - - n /= i; - - } - - } - - if (n > 1) - - v.push_back(n); - - return v; - -} - - - -bool comp(const pair &a, const pair &b) - -{ - - if (a.second == b.second) - - { - - return a.first > b.first; - - } - - else - - { - - return a.second > b.second; - - } - -} - -// _____________________________________ Solve. ______________________________________________________ - -int Ones(vector v) - -{ - - int c = 0; - - for (auto &i : v) - - { - - if (i == 1) - - c++; - - } - - return c; - -} - -int main() - -{ - - // Mastermind(); - - fast; - - - - tc; - - while (t--) - - { - - int n; - - cin >> n; - - vector v(n); - - ll sum = 0; - - for (auto &i : v) - - { - - cin >> i; - - sum += i; - - } - - // cerr << Ones(v) << "" ""; - - if (!(sum % n) && Ones(v) % 2 != 0) - - { - - cy; - - } - - else - - cn; - - } - - - - return 0; - -}","// بسم الله الرحمن الرحيم // - - - -// ███╗ ███╗ █████╗ ██████╗████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗██████╗ - -// ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗ - -// ██╔████╔██║███████║╚█████╗ ██║ █████╗ ██████╔╝██╔████╔██║██║██╔██╗██║██║ ██║ - -// ██║╚██╔╝██║██╔══██║ ╚═══██╗ ██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║██║╚████║██║ ██║ - -// ██║ ╚═╝ ██║██║ ██║██████╔╝ ██║ ███████╗██║ ██║██ ╚═╝ ██║██║██║ ╚███║██████╔╝ - -// ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚══╝╚═════╝ - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define MOD 1000000007 - -#define PI 3.14159265 - -// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0)) - -#define nl '\n' - -#define pb push_back - -#define tc \ - - int t; \ - - cin >> t; - -#define fast std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); - -#define cy cout << ""YES\n"" - -#define cn cout << ""NO\n"" - -#define sz size() - -#define all(v) v.begin(), v.end() - -void Mastermind() - -{ - - ios::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - freopen(""error.txt"", ""w"", stderr); - -#endif - -} - -bool checkBit(int x, int idx) - -{ - - return x & (1 << idx); - -} - -bool checkBit2(int x, int idx) - -{ - - return (x >> idx) & 1; - -} - -bool setBitToOne(int x, int idx) - -{ - - return x | (1 << idx); - -} - -bool setBitToZero(int x, int idx) - -{ - - return x & ~(1 << idx); - -} - -bool flipIdx(int x, int idx) - -{ - - // bit ^ 1 - - // 0^1 (bit= 1) - - // 1^1 (bit= 0) - - return x ^ (1 << idx); - -} - -int countOns(int x) // or bult in function -> __builtin_popcount(x) - -{ - - int cnt = 0; - - for (int i = 0; i <= 31; i++) - - cnt += checkBit(x, i); - -} - -// ll gcd(ll a, ll b) - -// { - -// if(b==0)return a; - -// return gcd(b,b%a); - -// } - -// ll lcm(ll a, ll b) - -// { - -// return a / gcd(a, b) * b; - -// } - - - -// // <------------------------------------------------> - - - -ll gcd(ll a, ll b) - -{ - - if (b == 0) - - return a; - - return gcd(b, b % a); - -} - -ll lcm(ll a, ll b) - -{ - - return a / gcd(a, b) * b; - -} - - - -// <------------------------------------------------> - - - -int FAST_POWER(int x, int n) - -{ - - int result = 1; - - while (n > 0) - - { - - if (n % 2 == 1) - - result = result * x; - - x = x * x; - - n = n / 2; - - } - - return result; - -} - - - -// fast power { time : log {n}} - -// <------------------------------------------------> - - - -bool isPerfectSquare(int x) - -{ - - if (x < 0) - - return false; - - int s = sqrt(x); - - return (s * s == x); - -} - - - -// <------------------------------------------------> - - - -vector prime_factorization(int n) - -{ - - vector v; - - for (int i = 2; i * i <= n; i++) - - { - - while (n % i == 0) - - { - - v.push_back(i); - - n /= i; - - } - - } - - if (n > 1) - - v.push_back(n); - - return v; - -} - - - -bool comp(const pair &a, const pair &b) - -{ - - if (a.second == b.second) - - { - - return a.first > b.first; - - } - - else - - { - - return a.second > b.second; - - } - -} - -// _____________________________________ Solve. ______________________________________________________ - -int Ones(vector v) - -{ - - int c = 0; - - for (auto &i : v) - - { - - if (i == 1) - - c++; - - } - - return c; - -} - -int main() - -{ - - // Mastermind(); - - fast; - - - - tc; - - while (t--) - - { - - int n; - - cin >> n; - - vector v(n); - - ll sum = 0; - - for (auto &i : v) - - { - - cin >> i; - - sum += i; - - } - - ll sum_odd = 0, sum_even = 0, c_odd = 0; - - - - for (int i = 0; i < n; i++) - - { - - if (i & 1) - - { - - sum_odd += v[i]; - - c_odd++; - - } - - else - - sum_even += v[i]; - - } - - if (!(sum % n) && sum_odd / c_odd == sum_even / (n - c_odd)) - - { - - cy; - - } - - else - - cn; - - } - - - - return 0; - -}",2 -Coder_Devdas,2050B - Transfusion,c++17 ,308608934,308608683,"#include - -using namespace std; - - - -int main() { - - int t; - - cin>>t; - - - - while(t--) - - { - - long long int n; - - cin>>n; - - - - long long int a[n]; - - - - for(long long int i=0;i>a[i]; - - } - - - - long long int sum=0; - - - - for(long long int i=0;i - -using namespace std; - - - -int main() { - - int t; - - cin>>t; - - - - while(t--) - - { - - int n; - - cin>>n; - - - - int a[n]; - - - - for(int i=0;i>a[i]; - - } - - - - int sum=0; - - - - for(int i=0;i { - inputString += inputStdin; -}); - -process.stdin.on('end', _ => { - inputStrings = inputString.trim().split('\n').map(string => { - return string.trim(); - }); - - main(); -}); - -function readline() { - return inputStrings[currentLine++]; -} - -function main() { - const runs = readline(); - for (var j = 0; j < runs; ++j) { - const len = parseInt(readline()); - const arr = readline().split(' ').map(x => parseInt(x)); - let odds = 0; - let evens = 0; - let count_odd_idx = Math.floor(arr.length / 2) + arr.length % 2; - let count_even_idx = Math.floor(arr.length / 2); - for (var i = 0; i < arr.length; ++i) { - odds += i % 2 == 0 ? arr[i] : 0; - evens += i % 2 == 1 ? arr[i] : 0; - } - - if (odds % count_odd_idx != 0 - || evens % count_even_idx != 0) { - console.log(""NO""); - continue; - } - - if (Math.floor(odds / count_odd_idx) !== Math.floor(evens / count_even_idx)) { - console.log(""NO""); - continue; - } - - console.log(""YES""); - continue; - } - - return; -} -","'use strict'; - -process.stdin.resume(); -process.stdin.setEncoding('utf-8'); - -let inputString = ''; -let inputStrings; -let currentLine = 0; - -process.stdin.on('data', inputStdin => { - inputString += inputStdin; -}); - -process.stdin.on('end', _ => { - inputStrings = inputString.trim().split('\n').map(string => { - return string.trim(); - }); - - main(); -}); - -function readline() { - return inputStrings[currentLine++]; -} - -function main() { - const runs = readline(); - for (var i = 0; i < runs; ++i) { - const len = parseInt(readline()); - const arr = readline().split(' ').map(x => parseInt(x)); - let odds = 0; - let evens = 0; - let count_odd_idx = arr.length / 2 + arr.length % 2; - let count_even_idx = arr.length / 2; - for (var i = 0; i < arr.length; ++i) { - odds += i % 0 == 0 ? arr[i] : 0; - evens += i % 0 == 1 ? arr[i] : 0; - } - - if (odds % count_odd_idx != 0 - || evens % count_even_idx != 0) { - console.log(""NO""); - break; - } - - if (odds / count_odd_idx !== evens / count_even_idx) { - console.log(""NO""); - break; - } - - console.log(""YES""); - break - } - - return; -} -",1 -Bogys,2050B - Transfusion,java,299719432,299719316,"import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; - -public class Main { - public static void main(String[] args) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - List inputs = new ArrayList<>(); - String line; - - int t = Integer.parseInt(reader.readLine()); - - while((line = reader.readLine()) != null) { - inputs.add(line); - } - - String[] result = new String[t]; - - int j = 0; - - for(int i = 0; i < t; i++){ - int n = Integer.parseInt(inputs.get(j)); - String[] strings = inputs.get(j+1).split("" ""); - j += 2; - - int[] data = new int[n]; - - for(int k = 0; k < n; k++){ - data[k] = Integer.parseInt(strings[k]); - } - - result[i] = solution(data); - } - - for(String r: result){ - System.out.println(r); - } - } - - public static String solution(int[] nums){ - double oddT = 0; - int o = 0; - - double evenT = 0; - int e = 0; - - for(int i = 0; i < nums.length; i++){ - if(i%2 == 0){ - evenT += nums[i]; - e += 1; - } - else{ - oddT += nums[i]; - o += 1; - } - } - - if((oddT+evenT) % nums.length != 0){ - return ""NO""; - } - - boolean ans = oddT/o == evenT/e; - - - if(ans){ - return ""YES""; - } - return ""NO""; - - - } - - -} -","import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; - -public class Main { - public static void main(String[] args) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - List inputs = new ArrayList<>(); - String line; - - int t = Integer.parseInt(reader.readLine()); - - while((line = reader.readLine()) != null) { - inputs.add(line); - } - - String[] result = new String[t]; - - int j = 0; - - for(int i = 0; i < t; i++){ - int n = Integer.parseInt(inputs.get(j)); - String[] strings = inputs.get(j+1).split("" ""); - j += 2; - - int[] data = new int[n]; - - for(int k = 0; k < n; k++){ - data[k] = Integer.parseInt(strings[k]); - } - - result[i] = solution(data); - } - - for(String r: result){ - System.out.println(r); - } - } - - public static String solution(int[] nums){ - int oddT = 0; - int o = 0; - - int evenT = 0; - int e = 0; - - for(int i = 0; i < nums.length; i++){ - if(i%2 == 0){ - evenT += nums[i]; - e += 1; - } - else{ - oddT += nums[i]; - o += 1; - } - } - - if((oddT+evenT) % nums.length != 0){ - return ""NO""; - } - - boolean ans = oddT/o == evenT/e; - - - if(ans){ - return ""YES""; - } - return ""NO""; - - - } - - -} -",1 -bipindehariya05,2050B - Transfusion,c++20 ,296002142,296002701,"#include -#include - -using namespace std; - -int main() -{ - int t; cin >> t; - while(t) - { - int n; cin >> n; - int a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - int sum = 0; - for(int i = 0; i < n; i++) sum += a[i]; - if(sum % n != 0) - { - cout << ""NO"" << endl; - continue; - } - - int unit = sum / n; - int req_sum = 0; int test_sum = 0; - for(int i = 0; i < n; i += 2) - { - req_sum += unit; - test_sum += a[i]; - } - if(test_sum != req_sum) - { - cout << ""NO"" << endl; - continue; - } - cout << ""YES"" << endl; - t--; - } -}","#include - -using namespace std; - -int main() -{ - int t; cin >> t; - while(t) - { - int n; cin >> n; - int a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - unsigned long long sum = 0; - for(int i = 0; i < n; i++) sum += a[i]; - if(sum % n != 0) - { - cout << ""NO"" << endl; - t--; - continue; - } - - unsigned long long unit = sum / n; - unsigned long long req_sum = 0, test_sum = 0; - for(int i = 0; i < n; i += 2) - { - req_sum += unit; - test_sum += a[i]; - } - if(test_sum != req_sum) - { - cout << ""NO"" << endl; - t--; - continue; - } - cout << ""YES"" << endl; - t--; - } -}",2 -Scipo,2050B - Transfusion,c++20 ,306100844,306100567,"import java.util.*; - -public class transfusion { - - public static void main(String[] args) { - - Scanner sc = new Scanner(System.in); - - int t = sc.nextInt(); - - while (t-->0) { - - int n = sc.nextInt(); - - long a[] = new long[n]; - - long avg = 0; - - for(int i = 0; i < n; i++) { - - a[i] = sc.nextLong(); - - avg+=a[i]; - - } - - avg/=n; - - long odd = a[0]-avg, even = a[1]-avg; - - for(int i = 1; i < n-1; i++) { - - if(i%2!=0) { - - odd+=a[i+1]-avg; - - }else { - - even+=a[i+1]-avg; - - } - - } - - if(odd==0 && even==0) { - - System.out.println(""YES""); - - }else { - - System.out.println(""NO""); - - } - - } - - - - sc.close(); - - } - -}","import java.util.*; - -public class transfusion { - - public static void main(String[] args) { - - Scanner sc = new Scanner(System.in); - - int t = sc.nextInt(); - - while (t-->0) { - - int n = sc.nextInt(); - - int a[] = new int[n]; - - int avg = 0; - - for(int i = 0; i < n; i++) { - - a[i] = sc.nextInt(); - - avg+=a[i]; - - } - - avg/=n; - - int odd = a[0]-avg, even = a[1]-avg; - - for(int i = 1; i < n-1; i++) { - - if(i%2!=0) { - - odd+=a[i+1]-avg; - - }else { - - even+=a[i+1]-avg; - - } - - } - - if(odd==0 && even==0) { - - System.out.println(""YES""); - - }else { - - System.out.println(""NO""); - - } - - } - - - - sc.close(); - - } - -}",1 -sjain1131,2050B - Transfusion,c++17 ,299507322,299505035,"#include -using namespace std; - -int main(){ - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector arr(n); - for(auto &it : arr){ - cin >> it; - } - - long long sum_odd = 0, sum_even = 0; - int n_odd = (n%2 == 0)? n/2 : n/2 + 1, n_even = n/2; - - for(int i = 0; i < n; i += 2){ - sum_odd += arr[i]; - } - for(int j = 1; j < n; j += 2){ - sum_even += arr[j]; - } - - if(sum_odd % n_odd == 0 && sum_even % n_even == 0 && (sum_odd/n_odd) == (sum_even/n_even)){ - cout << ""YES"" << endl; - }else{ - cout << ""NO"" << endl; - } - } -}","#include -using namespace std; - -int main(){ - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector arr(n); - for(auto &it : arr){ - cin >> it; - } - int diff; - for(int i = 1; i < n-1; i++){ - diff = arr[i-1] - arr[i+1]; - if(diff == 0){continue;} - if(diff % 2 == 0){ - arr[i+1] += diff/2; - arr[i-1] -= diff/2; - }else{ - arr[i-1] -= (diff+1)/2; - arr[i+1] += (diff+1)/2; - } - } - - int num = arr[0]; - bool flag = true; - for(int i = 1; i < n; i++){ - if(arr[i] != num){ - flag = false; - break; - } - } - if(flag){ - cout << ""YES"" << endl; - }else{ - cout << ""NO"" << endl; - } - } -}",1 -hpf1024,2050B - Transfusion,c++20 ,305913147,305913393,"#include - -using namespace std; - -#define int long long - -int num[200010]; - -#include - -void solve() { - - int n = 0; - - cin >> n; - - int sum = 0; - - for (int i = 1; i <= n; i++) { - - cin >> num[i]; - - sum += num[i]; - - } - - int t = sum / n; - - if (sum % n != 0){ - - cout<<""NO""<<""\n""; - - return; - - } - - else { - - for (int i = 2; i <= n - 1; i++) { - - if (num[i - 1] > t) { - - num[i + 1] += num[i - 1] - t; - - num[i - 1] = t; - - } - - else if (num[i + 1] > t) { - - num[i - 1] += num[i + 1] - t; - - num[i + 1] = t; - - } - - } - - for (int i = 1; i <= n; i++) { - - if (num[i] != t) { - - cout << ""NO"" << ""\n""; - - return; - - } - - } - - cout << ""YES"" << ""\n""; - - return; - - } - - - -} - -signed main() { - - int t = 0; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -#define int long long - -int num[200010]; - -#include - -void solve() { - - int n = 0; - - cin >> n; - - int sum = 0; - - for (int i = 1; i <= n; i++) { - - cin >> num[i]; - - sum += num[i]; - - } - - int t = sum / n; - - if (sum % n != 0){ - - cout<<""NO""<<""\n""; - - return; - - } - - else { - - for (int i = 2; i <= n - 1; i++) { - - if (num[i - 1] > t) { - - num[i + 1] += num[i - 1] - t; - - num[i - 1] = t; - - } - - else { - - num[i + 1] -= t - num[i - 1]; - - num[i - 1] = t; - - } - - } - - for (int i = 1; i <= n; i++) { - - if (num[i] != t) { - - cout << ""NO"" << ""\n""; - - return; - - } - - } - - cout << ""YES"" << ""\n""; - - return; - - } - - - -} - -signed main() { - - int t = 0; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}",2 -progger-serg,2050B - Transfusion,c++17 ,308470055,308467398,"#include - - - -using namespace std; - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - for(int gt=0;gt>n; - - for(int i=1;i<=n;i++){ - - int a; - - cin>>a; - - if(i%2==1){k1++;s1+=a;} - - else{k2++;s2+=a;} - - } - - if(s1%k1!=0 || s2%k2!=0){cout<<""NO""<<'\n';} - - else if(s1/k1==s2/k2){cout<<""YES""<<'\n';} - - else{cout<<""NO""<<'\n';} - - } - - return 0; - -} - -","#include - - - -using namespace std; - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - for(int gt=0;gt>n; - - for(int i=0;i>a; - - s+=a; - - } - - if(s%2){cout<<""NO""<<'\n';} - - else{cout<<""YES""<<'\n';} - - } - - return 0; - -} - -",1 -Aisha_Ramadan,2050B - Transfusion,c++17 ,307602620,307602652,"#include - -#include - -using namespace std; - - - - - - - -int main() - - - -{ - - int t; - - cin >> t; - - while(t--){ - - int n; - - cin >> n; - - vector arr(n); - - for (int i = 0; i> arr[i]; - - - - int od = 0; - - int ev = 0; - - int od_sum = 0; - - int ev_sum = 0; - - - - for (int i = 0; i - -#include - -using namespace std; - - - - - - - -int main() - - - -{ - - int t; - - cin >> t; - - while(t--){ - - int n; - - cin >> n; - - vector arr(n); - - for (int i = 0; i> arr[i]; - - - - int od = 0; - - int ev = 0; - - long long int od_sum = 0; - - long long int ev_sum = 0; - - - - for (int i = 0; i - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -#define x27pert \ - - ios::sync_with_stdio(0); \ - - cin.tie(0); \ - - cout.tie(0); \ - - cout << setiosflags(ios::fixed) << setprecision(15); - -using ll = long long; - -using ld = long double; - -// Define the PBDS type with pairs (value, frequency) - -typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> pbds; - -#define all(a) (a).begin(), (a).end() - -#define allr(a) (a).rbegin(), (a).rend() - -#define mp make_pair - -#define pb push_back - -#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++) - -#define rrep(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--) - -#define no cout << ""NO"" << ""\n""; - -#define yes cout << ""YES"" << ""\n""; - -const ll MOD = 1e9 + 7; - -const ld pi = 3.1415926535897932384626433832795; - -using gint = greater; - -vector>d={{-1,0},{0,1},{1,0},{0,-1}}; - -bool isvalid(int n, int m,int i ,int j,vector>&v,vector>&visited) - -{ - - return i=0 && j=0 && v[i][j]!='*' && !visited[i][j] ; - -} - -void solve() { - - int n; - - cin>>n; - - vectorv(n); - - int sum=0; - - int ans=0; - - for(int i=0;i>v[i]; - - if(i%2==0) - - { - - sum+=v[i]; - - } - - else{ - - ans+=v[i]; - - } - - } - - int m=n/2; - - int l=m; - - if(n%2==1) - - { - - l++; - - } - - if(sum/l == ans/m && sum%l==0 && ans%l==0) - - { - - yes; - - } - - else{ - - no; - - } - -} - -signed main() - -{ - - x27pert; - - int _; - - _ = 1; - - cin >> _; - - - - while (_--) - - { - - solve(); - - } - - return 0; - -} - -// ll exp(ll x, ll n) - -// { - -// assert(n >= 0); - -// // note: m * m must be less than 2^63 to avoid ll overflow - -// ll res = 1; - -// while (n > 0) - -// { - -// if (n % 2 == 1) - -// { - -// res = res * x ; - -// } - -// x = x * x ; - -// n /= 2; - -// } - -// return res; - -// } - -// - -// bool isvalid(int i ,int j , vector>&v,vector>&visited) - -// { - -// return i>=0 && i=0 && j0; - -// } - -// vector>dx={{-1,0},{0,-1},{1,0},{0,1}};"," #include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -#define x27pert \ - - ios::sync_with_stdio(0); \ - - cin.tie(0); \ - - cout.tie(0); \ - - cout << setiosflags(ios::fixed) << setprecision(15); - -using ll = long long; - -using ld = long double; - -// Define the PBDS type with pairs (value, frequency) - -typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> pbds; - -#define all(a) (a).begin(), (a).end() - -#define allr(a) (a).rbegin(), (a).rend() - -#define mp make_pair - -#define pb push_back - -#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++) - -#define rrep(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--) - -#define no cout << ""NO"" << ""\n""; - -#define yes cout << ""YES"" << ""\n""; - -# define int long long - -const ll MOD = 1e9 + 7; - -const ld pi = 3.1415926535897932384626433832795; - -using gint = greater; - -vector>d={{-1,0},{0,1},{1,0},{0,-1}}; - -bool isvalid(int n, int m,int i ,int j,vector>&v,vector>&visited) - -{ - - return i=0 && j=0 && v[i][j]!='*' && !visited[i][j] ; - -} - -void solve() { - - int n; - - cin>>n; - - vectorv(n); - - int sum=0; - - int ans=0; - - for(int i=0;i>v[i]; - - if(i%2==0) - - { - - sum+=v[i]; - - } - - else{ - - ans+=v[i]; - - } - - } - - int m=n/2; - - int l=m; - - if(n%2==1) - - { - - l++; - - } - - if(sum/l == ans/m && sum%l==0 && ans%m==0) - - { - - yes; - - } - - else{ - - no; - - } - -} - -signed main() - -{ - - x27pert; - - int _; - - _ = 1; - - cin >> _; - - - - while (_--) - - { - - solve(); - - } - - return 0; - -} - -// ll exp(ll x, ll n) - -// { - -// assert(n >= 0); - -// // note: m * m must be less than 2^63 to avoid ll overflow - -// ll res = 1; - -// while (n > 0) - -// { - -// if (n % 2 == 1) - -// { - -// res = res * x ; - -// } - -// x = x * x ; - -// n /= 2; - -// } - -// return res; - -// } - -// - -// bool isvalid(int i ,int j , vector>&v,vector>&visited) - -// { - -// return i>=0 && i=0 && j0; - -// } - -// vector>dx={{-1,0},{0,-1},{1,0},{0,1}};",2 -aayushkuloor,2050B - Transfusion,c++20 ,299454875,299453561,"#include -#pragma GCC optimize(""Ofast"") -#pragma GCC target(""avx,avx2,fma"") - -using namespace std; - -#define int long long -#define rep(i,a,b) for(int i=a; i<=b; i++) -#define read(x,a,b) rep(i, a, b) cin>>x[i]; -#define vi vector -#define all(l) l.begin(), l.end() - -typedef long long ll; -constexpr int N=1e6, mod=1e9+7, INF=1e18+5; - -void solve() -{ - int n; cin >> n; - vi a(n); read(a,0,n-1) - int sum{0},even{0},odd{0}; - rep(i,0,n-1) - { - if (i&1) odd+=a[i]; - else even+=a[i]; - } - int e{n/2},o{n/2}; - if (n&1) e++; - if (odd%o || even%e || odd/o!=even/e) cout << ""NO\n""; - else cout << ""YES\n""; -} - -signed main() -{ - ios::sync_with_stdio(false); cin.tie(nullptr); - int t{1}; - cin >> t; - while (t--) solve(); -}","#include -#pragma GCC optimize(""Ofast"") -#pragma GCC target(""avx,avx2,fma"") - -using namespace std; - -#define int long long -#define rep(i,a,b) for(int i=a; i<=b; i++) -#define read(x,a,b) rep(i, a, b) cin>>x[i]; -#define vi vector -#define all(l) l.begin(), l.end() - -typedef long long ll; -constexpr int N=1e6, mod=1e9+7, INF=1e18+5; - -void solve() -{ - int n; cin >> n; - vi a(n); read(a,0,n-1) - int sum{accumulate(all(a),0)}; - if (sum/n!=(sum+n-1)/n) {cout << ""NO\n""; return;} - int target{sum/n}; - rep(i,1,n-2) - { - int diff{target-a[i-1]}; - a[i-1]+=diff,a[i+1]-=diff; - } - rep(i,0,n-1) - { - if (a[i]!=target) {cout << ""NO\n""; return;} - } - cout << ""YES\n""; -} - -signed main() -{ - ios::sync_with_stdio(false); cin.tie(nullptr); - int t{1}; - cin >> t; - while (t--) solve(); -}",1 -satvik08,2050B - Transfusion,python,299494396,299493693,"def process_array(): - _size = int(input()) - a =list(map(int, input().split())) - sum1 = 0 - odd= (_size+1)//2 - sum2 = 0 - even = _size-odd - for i in range(_size): - if i%2==0 : - sum1+=a[i] - - else : - sum2+=a[i] - # print(sum1, sum2, odd ,even) - if (sum1+sum2)%_size==0 : - if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size): - print(""YES"") - return - else: - print(""NO"") - return - else: - print(""NO"") - -t = int(input()) -for _ in range(t): - process_array() -","def process_array(): - _size = int(input()) - a =list(map(int, input().split())) - sum1 = 0 - odd= (_size+1)/2 - sum2 = 0 - even = _size-odd - for i in range(_size): - if i%2==0 : - sum1+=a[i] - else : - sum2+=a[i] - if (sum1+sum2)%_size==0 : - if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size): - print(""YES"") - return - else: - print(""NO"") - return - else: - print(""NO"") - -t = int(input()) -for _ in range(t): - process_array() -",1 -yassinearfaoui131,2050B - Transfusion,python,299562279,299562608," - -OUT=[] -for i in range(int(input())): - n=int(input()) - L=list(map(int,input().split())) - s=sum(L) - if s%n==0 : - p=s//n - k=1 - b=True - while k -using namespace std; -#define print(x) cout<=b; i--) -#define all(v) v.begin(),v.end() -#define pb(x) push_back(x) -#define w(t) int t; cin>>t; while(t--) -#define ll long long - - -int main(){ -w(t){ - int n ; cin>>n; - vector arr(n); - long long even=0,odd=0; - f(i,0,n) { - int x; cin>>x; - if(i%2) odd+=x; - else even+=x; - } - bool z=false; - if(n%2 ) { - if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2)))) z=true; - } - - else { - if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2)))) z=true; - } - if(z) print(""YES"") - else print(""NO"") - -} - -}","// #include -// using namespace std; -// #define print(x) cout<=b; i--) -// #define all(v) v.begin(),v.end() -// #define pb(x) push_back(x) -// #define w(t) int t; cin>>t; while(t--) -// #define ll long long - - -// int main(){ -// w(t){ -// int n ; cin>>n; -// vector arr(n); -// long long even=0,odd=0; -// f(i,0,n) { -// int x; cin>>x; -// if(i%2) odd+=x; -// else even+=x; -// } -// bool z=false; -// if(n%2 ) { -// if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true; -// } - -// else { -// if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2)))) -// z=true; -// } -// if(z) print(""YES"") -// else print(""NO"") - -// } - -// } -#include - -using namespace std; - -void solve() { - int n; cin >> n; - vector a(n); - for (int &x : a) cin >> x; - - long long ods = 0, evs = 0; - for (int i = 0; i < n; i++) { - if (i & 1) ods += a[i]; - else evs += a[i]; - } - int odc = n / 2, evc = n / 2; - if (n & 1) evc++; - - if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) { - cout << ""NO""; - return; - } - cout << ""YES""; -} - -int main() { - int TESTS; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}",2 -DarkMody,2050B - Transfusion,c++17 ,308948261,308948911,"#include - -using namespace std; - -int main() - -{ - - double t, n, a; - - cin >> t; - - while (t--) - - { - - cin >> n; - - double sum = 0, sum1 = 0, sum2 = 0; - - for (int i = 0; i < n; i++) - - { - - cin >> a; - - sum += a; - - if (i % 2 == 0) - - sum1 += a; - - else - - sum2 += a; - - } - - double test = sum / (float)n; - - if ((int)sum % (int)n == 0 && sum1 == test * ceil(n / 2) && sum2 == test * int(n / 2)) - - cout << ""YES\n""; - - else - - cout << ""NO\n""; - - } - -}","#include - -using namespace std; - -int main() - -{ - - long long t, n, a, b; - - cin >> t; - - while (t--) - - { - - cin >> n; - - long long sum = 0, sum1 = 0, sum2 = 0; - - for (int i = 0; i < n; i++) - - { - - cin >> a; - - sum += a; - - if (i % 2 == 0) - - sum1 += a; - - else - - sum2 += a; - - } - - if (n % 2 == 0) - - { - - a = n / 2; - - b = n / 2; - - } - - else - - { - - a = n / 2 + 1; - - b = n / 2; - - } - - if (sum % n == 0 && sum1 == a * sum / n && sum2 == b * sum / n) - - cout << ""YES\n""; - - else - - cout << ""NO\n""; - - } - -}",2 -yuktaaa,2050B - Transfusion,c++17 ,299598256,299598859,"#include -#include -using namespace std; -#define _test int _TEST; cin >> _TEST; while (_TEST--) -#define ll long long -#define all(a) (a).begin(), (a).end() - - - -void solve() { - int n; - cin>>n; - vectora(n); - for(int i = 0; i < n; i++) - { - cin>>a[i]; - } - int even=0,odd=0; - int n1=0,n2=0; - for(int i = 0; i < n; i++) - { - if(i&1){ - even+=a[i]; - n1++; - }else{ - odd+=a[i]; - n2++; - } - } - if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<""YES\n""; - else cout<<""NO\n""; -} -int main() { - _test { -solve(); - } - return 0; -}","#include -#include -using namespace std; -#define _test int _TEST; cin >> _TEST; while (_TEST--) -#define ll long long -#define all(a) (a).begin(), (a).end() - - - -void solve() { - ll n; - cin>>n; - vectora(n); - for(int i = 0; i < n; i++) - { - cin>>a[i]; - } - ll even=0,odd=0; - ll n1=0,n2=0; - for(int i = 0; i < n; i++) - { - if(i&1){ - even+=a[i]; - n1++; - }else{ - odd+=a[i]; - n2++; - } - } - if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<""YES\n""; - else cout<<""NO\n""; -} -int main() { - _test { -solve(); - } - return 0; -}",2 -Bogys,2050B - Transfusion,java,299718842,299719432,"import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; - -public class Main { - public static void main(String[] args) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - List inputs = new ArrayList<>(); - String line; - - int t = Integer.parseInt(reader.readLine()); - - while((line = reader.readLine()) != null) { - inputs.add(line); - } - - String[] result = new String[t]; - - int j = 0; - - for(int i = 0; i < t; i++){ - int n = Integer.parseInt(inputs.get(j)); - String[] strings = inputs.get(j+1).split("" ""); - j += 2; - - int[] data = new int[n]; - - for(int k = 0; k < n; k++){ - data[k] = Integer.parseInt(strings[k]); - } - - result[i] = solution(data); - } - - for(String r: result){ - System.out.println(r); - } - } - - public static String solution(int[] nums){ - int oddT = 0; - int o = 0; - - int evenT = 0; - int e = 0; - - for(int i = 0; i < nums.length; i++){ - if(i%2 == 0){ - evenT += nums[i]; - e += 1; - } - else{ - oddT += nums[i]; - o += 1; - } - } - - - - - if((oddT+evenT) % nums.length != 0){ - return ""NO""; - } - - - - int target = (oddT+evenT)/nums.length; - boolean ans = oddT/o == target && evenT/e == target; - - - if(ans){ - return ""YES""; - } - return ""NO""; - - - } - - -} -","import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; - -public class Main { - public static void main(String[] args) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - List inputs = new ArrayList<>(); - String line; - - int t = Integer.parseInt(reader.readLine()); - - while((line = reader.readLine()) != null) { - inputs.add(line); - } - - String[] result = new String[t]; - - int j = 0; - - for(int i = 0; i < t; i++){ - int n = Integer.parseInt(inputs.get(j)); - String[] strings = inputs.get(j+1).split("" ""); - j += 2; - - int[] data = new int[n]; - - for(int k = 0; k < n; k++){ - data[k] = Integer.parseInt(strings[k]); - } - - result[i] = solution(data); - } - - for(String r: result){ - System.out.println(r); - } - } - - public static String solution(int[] nums){ - double oddT = 0; - int o = 0; - - double evenT = 0; - int e = 0; - - for(int i = 0; i < nums.length; i++){ - if(i%2 == 0){ - evenT += nums[i]; - e += 1; - } - else{ - oddT += nums[i]; - o += 1; - } - } - - if((oddT+evenT) % nums.length != 0){ - return ""NO""; - } - - boolean ans = oddT/o == evenT/e; - - - if(ans){ - return ""YES""; - } - return ""NO""; - - - } - - -} -",2 -competativepreparation7,2050B - Transfusion,c++17 ,308950842,308949917,"#include - -using namespace std; - -void gotoo(){ - - long long n; - - cin>>n; - - long long a[n],i,sum=0; - - for(i=0;i>a[i]; - - sum+=a[i]; - - } - - if(sum%n!=0){ - - cout<<""NO""<ch){ - - long long ne1=a[i-1]-ch; - - a[i-1]=a[i-1]-ne1; - - a[i+1]=a[i+1]+ne1; - - } - - else if(a[i-1]>t; - - while(t--){ - - gotoo(); - - } - -}","#include - -using namespace std; - -void gotoo(){ - - int n; - - cin>>n; - - int a[n],i,sum=0; - - for(i=0;i>a[i]; - - sum+=a[i]; - - } - - if(sum%n!=0){ - - cout<<""NO""<ch){ - - int ne1=a[i-1]-ch; - - a[i-1]=a[i-1]-ne1; - - a[i+1]=a[i+1]+ne1; - - } - - else if(a[i-1]>t; - - while(t--){ - - gotoo(); - - } - -}",1 -priyav,2050B - Transfusion,c++17 ,299708309,299708250,"#include -using namespace std; -void solve(vector finder, long long n){ - long long sum_even = 0; - long long count_even = 0; - long long sum_odd = 0; - long long count_odd = 0; - for(long long i = 0; i>t; - while(t--){ - long long n; - cin>>n; - vector finder(n); - for(long long i = 0; i>finder[i]; - } - solve(finder,n); - } -} -","#include -using namespace std; -void solve(vectorfinder, int n){ - int sum_even = 0; - int count_even = 0; - int sum_odd = 0; - int count_odd = 0; - for(int i = 0; i>t; - while(t--){ - int n; - cin>>n; - vectorfinder(n); - for(int i = 0; i>finder[i]; - } - solve(finder,n); - } - -} -",1 -Nazmul99,2050B - Transfusion,c++17 ,308605699,308609587,"#include - -#define fast \ - - ios::sync_with_stdio(false); \ - - cin.tie(nullptr) - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int k, d, n, sum = 0; - - bool flag = true; - - cin >> n; - - vector A(n); - - for (int i = 0; i < n; i++) - - cin >> A[i]; - - - - for (int i = 0; i < n; i++) - - sum += A[i]; - - - - if (sum % n != 0) - - flag = false; - - else - - { - - d = sum / n; - - for (int i = 1; i < n - 1; i++) - - { - - if (A[i - 1] > d && A[i - 1] > 0) - - { - - k = A[i - 1] - d; - - A[i + 1] = A[i + 1] + k; - - A[i - 1] = d; - - } - - else - - { - - k = d - A[i - 1]; - - A[i + 1] = A[i + 1] - k; - - A[i - 1] = d; - - } - - } - - } - - for (int j = 0; j < n; j++) - - if (A[j] != d) - - flag = false; - - cout << (flag ? ""YES"" : ""NO"") << endl; - - } - - - - return 0; - -}","#include - -#define fast \ - - ios::sync_with_stdio(false); \ - - cin.tie(nullptr) - -#define ll long long - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - ll k = 0, d, n, sum = 0; - - bool flag = true; - - cin >> n; - - vector A(n); - - for (int i = 0; i < n; i++) - - cin >> A[i]; - - for (int i = 0; i < n; i++) - - sum += A[i]; - - - - if (sum % n != 0) - - flag = false; - - else - - { - - d = sum / n; - - for (int i = 1; i < n - 1; i++) - - { - - if (A[i - 1] < d && A[i - 1] > 0) - - { - - k = d - A[i - 1]; - - A[i + 1] = A[i + 1] - k; - - A[i - 1] = d; - - } - - else - - { - - k = A[i - 1] - d; - - A[i + 1] = A[i + 1] + k; - - A[i - 1] = d; - - } - - } - - } - - for (int j = 0; j < n; j++) - - if (A[j] != d) - - flag = false; - - cout << (flag ? ""YES"" : ""NO"") << endl; - - } - - - - return 0; - -}",2 -Mariam12Gamal,2050B - Transfusion,c++17 ,308415964,308417658,"#include - -using namespace std; - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n,oddsm=0,evensm=0,oddcnt=0,evencnt=0; - - cin>>n; - - int arr[n]; - - for(int i=0; i>arr[i]; - - if(i%2==0){ - - evensm+=arr[i]; - - evencnt++; - - } - - else{ - - oddsm+=arr[i]; - - oddcnt++; - - } - - } - - if(evensm%evencnt!=0 || oddsm%oddcnt !=0 || evensm/evencnt!=oddsm/oddcnt) - - cout<<""NO\n""; - - else cout<<""YES\n""; - - } - - return 0; - -}","#include - -using namespace std; - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - int arr[n]; - - for(int i=0; i>arr[i]; - - } - - long long oddsm=0,evensm=0,oddcnt=0,evencnt=0; - - for(int i=0; i -using namespace std; -#define ll long long -#define pll pair -#define nl ""\n"" -#define INF 1e18 - -void mainCode(){ - ll n=0,k; - cin >> n ; - vector v(n); - ll sum=0; - for(ll i=0;i> v[i]; - sum+=v[i]; - } - if(sum%3==0) cout << ""YES\n""; - else cout << ""NO\n""; - -} - -int main() -{ - int tc=0; - cin >> tc; - while(tc--) - { - mainCode(); - } - return 0; -} -","#include -using namespace std; -#define ll long long -#define pll pair -#define nl ""\n"" -#define INF 1e18 - -void mainCode(){ - ll n=0,k; - cin >> n ; - vector v(n); - ll odd=0,even=0; - for(ll i=0;i> v[i]; - if(i &1) odd+=v[i]; - else even+=v[i]; - } - ll nodd=n/2,neven=n/2; - if(n&1) neven++; - - if(odd % nodd != 0 || even % neven != 0 || odd / nodd != even / neven){ - cout << ""NO\n""; - } - else cout << ""YES\n""; - -} - -int main() -{ - int tc=0; - cin >> tc; - while(tc--) - { - mainCode(); - } - return 0; -} -",2 -behruz10,2050B - Transfusion,python,299475354,299475179,"a=int(input()) -for _ in range(a): - b=int(input()) - c=list(map(int,input().split())) - if sum(c)%b!=0: - print('NO') - else: - t=sum(c)//b - w=[] - l=[] - for i in range(b): - if i%2==0: - w.append(c[i]) - else: - l.append(c[i]) - if sum(l)//len(l)==t==sum(w)//len(w): - print('YES') - else: - print('NO')","a=int(input()) -for _ in range(a): - b=int(input()) - c=list(map(int,input().split())) - if sum(c)%b!=0: - print('NO') - exit() - t=sum(c)//b - w=[] - l=[] - for i in range(b): - if i%2==0: - w.append(c[i]) - else: - l.append(c[i]) - if sum(l)//len(l)==t==sum(w)//len(w): - print('YES') - else: - print('NO')",1 -NotMyCupOfTea,2050B - Transfusion,c++17 ,296006306,296006859,"#include -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector v(n); - set st; - for (int i=0; i> v[i]; - st.insert(v[i]); - } - if (st.size() == 1) { - cout << ""yes\n""; - continue; - } - ll mn = INT_MAX; - int pos = -1; - for (int i=2; i 0 && diff % 2 == 0 && diff < mn) { - mn = diff; - pos = i; - } - } - if (pos == -1) { - cout << ""no\n""; - continue; - } - //cout << pos << "" ""; - ll target; - if (v[pos] > v[pos - 2]) target = v[pos] - mn/2; - else target = v[pos] + mn/2; - ll tot = 0; - for (ll num: v) { - tot += num - target; - } - if (tot == 0) cout << ""yes\n""; - else cout << ""no\n""; - } -}","#include -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - ll od = 0, ev = 0; - for (int i=0; i> x; - if (i%2 == 0) ev += x; - else od += x; - } - ll eve = n / 2, ode = n / 2; - if (n%2 != 0) eve ++; - if (ev % eve == 0 && od % ode == 0 && ev / eve == od / ode) cout << ""yes\n""; - else cout << ""no\n""; - } -}",2 -muzammil-1008,2050B - Transfusion,c++20 ,307538595,307540335,"#include - -using namespace std; - -#define int long long int - -const int N = 2 * 100010; - -#define M 1000000007 - - - -void print_vect(vector &v) { - - for (auto i : v) { - - cout << i << "" ""; - - } - - cout << endl; - -} - - - -vector seg; - - - -void build_seg(int ind, int low, int high, vector &a) { - - if (low == high) { - - seg[ind] = a[low]; - - return; - - } - - int mid = (low + high) / 2; - - build_seg(2 * ind + 1, low, mid, a); - - build_seg(2 * ind + 2, mid + 1, high, a); - - seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]); - -} - - - -int seg_queries(int ind, int low, int high, int l, int r) { - - if (low >= l && high <= r) - - return seg[ind]; - - if (high < l || low > r) - - return 0; - - int mid = (low + high) / 2; - - int left = seg_queries(2 * ind + 1, low, mid, l, r); - - int right = seg_queries(2 * ind + 2, mid + 1, high, l, r); - - return __gcd(left, right); - -} - - - -void point_update(int ind, int low, int high, int node, int val) { - - if (low == high && low == node) { - - seg[ind] = val; - - return; - - } - - int mid = (low + high) / 2; - - if (node <= mid && node >= low) { - - point_update(2 * ind + 1, low, mid, node, val); - - } else { - - point_update(2 * ind + 2, mid + 1, high, node, val); - - } - - seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]); - -} - - - -int binexp(int a, int b, int m) { - - int ans = 1; - - while (b) { - - if (b & 1) { - - ans *= a; - - ans = ans % m; - - } - - a = a * a; - - a = a % m; - - b = b / 2; - - } - - return ans % m; - -} - - - -int mod_inverse(int a, int b) { - - return binexp(a, b - 2, b); - -} - - - -int sol(int a, int b, int c) { - - int gcd = __gcd(a, b); - - int k1 = a / gcd; - - int k2 = b / gcd; - - return (mod_inverse(k1, k2) * (c / gcd)) % k2; - -} - - - -void dfs(vector> &graph, int node, vector &par, vector &vis) { - - if (vis[node] == 1) { - - return; - - } - - vis[node] = 1; - - for (auto child : graph[node]) { - - if (vis[child] == 1) { - - continue; - - } - - par[child] = node; - - dfs(graph, child, par, vis); - - } - -} - - - -int32_t main() { - - int t; - - cin >> t; - - while (t--) { - - int n; - - cin>>n; - - vectorv; - - int sum = 0; - - for(int i = 0;i>x; - - v.push_back(x); - - sum += x; - - } - - if(sum%n!= 0 ){ - - cout<<""NO""<=k){ - - v[i+1] += l; - - } - - else{ - - v[i+1]-=l; - - if(v[i+1]<0){ - - fl = 1; - - break; - - } - - } - - v[i-1] = k; - - } - - //print_vect(v); - - for(int i = 0;i - -using namespace std; - -#define int long long int - -const int N = 2 * 100010; - -#define M 1000000007 - - - -void print_vect(vector &v) { - - for (auto i : v) { - - cout << i << "" ""; - - } - - cout << endl; - -} - - - -vector seg; - - - -void build_seg(int ind, int low, int high, vector &a) { - - if (low == high) { - - seg[ind] = a[low]; - - return; - - } - - int mid = (low + high) / 2; - - build_seg(2 * ind + 1, low, mid, a); - - build_seg(2 * ind + 2, mid + 1, high, a); - - seg[ind] = __gcd(seg[2 * ind + 1], seg[2 * ind + 2]); - -} - - - -int seg_queries(int ind, int low, int high, int l, int r) { - - if (low >= l && high <= r) - - return seg[ind]; - - if (high < l || low > r) - - return 0; - - int mid = (low + high) / 2; - - int left = seg_queries(2 * ind + 1, low, mid, l, r); - - int right = seg_queries(2 * ind + 2, mid + 1, high, l, r); - - return __gcd(left, right); - -} - - - -void point_update(int ind, int low, int high, int node, int val) { - - if (low == high && low == node) { - - seg[ind] = val; - - return; - - } - - int mid = (low + high) / 2; - - if (node <= mid && node >= low) { - - point_update(2 * ind + 1, low, mid, node, val); - - } else { - - point_update(2 * ind + 2, mid + 1, high, node, val); - - } - - seg[ind] = min(seg[2 * ind + 1], seg[2 * ind + 2]); - -} - - - -int binexp(int a, int b, int m) { - - int ans = 1; - - while (b) { - - if (b & 1) { - - ans *= a; - - ans = ans % m; - - } - - a = a * a; - - a = a % m; - - b = b / 2; - - } - - return ans % m; - -} - - - -int mod_inverse(int a, int b) { - - return binexp(a, b - 2, b); - -} - - - -int sol(int a, int b, int c) { - - int gcd = __gcd(a, b); - - int k1 = a / gcd; - - int k2 = b / gcd; - - return (mod_inverse(k1, k2) * (c / gcd)) % k2; - -} - - - -void dfs(vector> &graph, int node, vector &par, vector &vis) { - - if (vis[node] == 1) { - - return; - - } - - vis[node] = 1; - - for (auto child : graph[node]) { - - if (vis[child] == 1) { - - continue; - - } - - par[child] = node; - - dfs(graph, child, par, vis); - - } - -} - - - -int32_t main() { - - int t; - - cin >> t; - - while (t--) { - - int n; - - cin>>n; - - vectorv; - - int sum = 0; - - for(int i = 0;i>x; - - v.push_back(x); - - sum += x; - - } - - if(sum%n!= 0 ){ - - cout<<""NO""<=k){ - - v[i+1] += l; - - } - - else{ - - v[i+1]-=l; - - - - } - - v[i-1] = k; - - } - - //print_vect(v); - - for(int i = 0;i> t; while(t--){ - cin >> n; - for(int i=1;i<=n;i++){ - cin >> a[i]; - d[i] = a[i] - a[i-1]; -// printf(""%d "",d[i]); - } -// cout << endl; - for(int i=2;i> t; while(t--){ - cin >> n; - long long dan=0,dann=0,shuang=0,shuangn=0; - for(int i=1;i<=n;i++){ - cin >> a; - if(i%2){ - dan += a; - dann++; - }else{ - shuang += a; - shuangn++; - } - } - if(dan%dann==0 and shuang%shuangn==0 and dan/dann == shuang/shuangn) cout<<""yes\n""; - else cout<<""no\n""; - - } - -}",2 -blargz,2050B - Transfusion,other,299438654,299439351,"'use strict'; - -process.stdin.resume(); -process.stdin.setEncoding('utf-8'); - -let inputString = ''; -let inputStrings; -let currentLine = 0; - -process.stdin.on('data', inputStdin => { - inputString += inputStdin; -}); - -process.stdin.on('end', _ => { - inputStrings = inputString.trim().split('\n').map(string => { - return string.trim(); - }); - - main(); -}); - -function readline() { - return inputStrings[currentLine++]; -} - -function main() { - const arr = readline().split(' ').map(x => parseInt(x)); - let odds = 0; - let evens = 0; - let count_odd_idx = arr.length / 2 + arr.length % 2; - let count_even_idx = arr.length / 2; - for (var i = 0; i < arr.length; ++i) { - odds += i % 0 === 0 ? arr[i] : 0; - evens += i % 0 === 1 ? arr[i] : 0; - } - - if (odds % count_odd_idx !== 0 - || evens % count_even_idx !== 0) { - console.log(""NO""); - return; - } - - if (odds / count_odd_idx !== evens / count_even_idx) { - console.log(""NO""); - return; - } - - console.log(""YES""); - return -} -","'use strict'; - -process.stdin.resume(); -process.stdin.setEncoding('utf-8'); - -let inputString = ''; -let inputStrings; -let currentLine = 0; - -process.stdin.on('data', inputStdin => { - inputString += inputStdin; -}); - -process.stdin.on('end', _ => { - inputStrings = inputString.trim().split('\n').map(string => { - return string.trim(); - }); - - main(); -}); - -function readline() { - return inputStrings[currentLine++]; -} - -function main() { - const runs = readline(); - for (var j = 0; j < runs; ++j) { - const len = parseInt(readline()); - const arr = readline().split(' ').map(x => parseInt(x)); - let odds = 0; - let evens = 0; - let count_odd_idx = Math.floor(arr.length / 2) + arr.length % 2; - let count_even_idx = Math.floor(arr.length / 2); - for (var i = 0; i < arr.length; ++i) { - odds += i % 2 == 0 ? arr[i] : 0; - evens += i % 2 == 1 ? arr[i] : 0; - } - - if (odds % count_odd_idx != 0 - || evens % count_even_idx != 0) { - console.log(""NO""); - continue; - } - - if (Math.floor(odds / count_odd_idx) !== Math.floor(evens / count_even_idx)) { - console.log(""NO""); - continue; - } - - console.log(""YES""); - continue; - } - - return; -} -",2 -ShubhamMate,2050B - Transfusion,c++17 ,307092941,307092804,"#include -#include -#include - -using namespace std; - - - -int main () { - int t, n; - - cin >> t; - while (t--) { - cin >> n; - unsigned long long even_sum=0, odd_sum=0, even_count=0, odd_count=0; - for (int i=0; i> a; - if (i%2==0) { even_sum += a; even_count++; } - else { odd_sum += a; odd_count++; } - } - if (even_sum%even_count==0 && odd_sum%odd_count==0 && even_sum/even_count==odd_sum/odd_count) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } -}","#include -#include -#include - -using namespace std; - - - -int main () { - int t, n; - - cin >> t; - while (t--) { - cin >> n; - int even_sum=0, odd_sum=0, even_count=0, odd_count=0; - for (int i=0; i> a; - if (i%2==0) { even_sum += a; even_count++; } - else { odd_sum += a; odd_count++; } - } - if (even_sum%even_count==0 && odd_sum%odd_count==0 && even_sum/even_count==odd_sum/odd_count) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } -}",1 -loser_s,2050B - Transfusion,c++20 ,299490045,299490240,"#include -using namespace std; - -void solve(){ - int n ; cin >> n; - vectorv; - v.push_back(0); - for(int i=1 ; i> a; - v.push_back(a); - } - // for(auto u : v) cout<> tc; - while(tc--){ - solve(); - } -}","#include -using namespace std; -#define ll long long - -void solve(){ - int n ; cin >> n; - vectorv; - v.push_back(0); - for(int i=1 ; i> a; - v.push_back(a); - } - // for(auto u : v) cout<> tc; - while(tc--){ - solve(); - } -}",2 -Jenish007,2050B - Transfusion,c++17 ,299674970,299679088,"#include -using namespace std; - -#define Code ios_base::sync_with_stdio(false); -#define By cin.tie(NULL); -#define Rikie cout.tie(NULL); -#define ll long long - -void solve(){ - ll n; - cin >> n; - ll arr[n]; - for(int i = 0 ; i < n; i++){ - cin >> arr[i]; - } - int cEven , cOdd; - if(n%2==0){ - cOdd = n/2; - cEven = n/2; - } - else{ - cEven = (n/2) + 1; - cOdd = n/2; - } - int sumOdd = 0 , sumEven = 0 ; - for(int i = 0;i < n; i ++){ - if (i%2==0){ - sumEven+=arr[i]; - } - else{ - sumOdd+=arr[i]; - } - } - - if( sumEven%cEven==0 && sumOdd%cOdd==0&&sumEven/cEven == sumOdd/cOdd ){ - cout << ""YES"" << endl; - }else{ - cout << ""NO"" << endl; - } - -} - -int main(){ - - Code By Rikie - - int t; - cin >> t; - while(t--){ - - solve(); - - } - - return 0; -}","#include - -using namespace std; - -void solve() { - int n; cin >> n; - vector a(n); - for (int &x : a) cin >> x; - - long long ods = 0, evs = 0; - for (int i = 0; i < n; i++) { - if (i & 1) ods += a[i]; - else evs += a[i]; - } - int odc = n / 2, evc = n / 2; - if (n & 1) evc++; - - if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) { - cout << ""NO""; - return; - } - cout << ""YES""; -} - -int main() { - int TESTS; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}",2 -zakI98#,2050B - Transfusion,c++20 ,308403257,308403008,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -typedef long long ll; - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define LOO(i,a,b) for (int i = a; i <= b; i++) - -using namespace std; - -ll MAX = 1e9 + 7; - -void iO() { - - freopen(""output.txt"",""w"",stdout); - - freopen(""input.txt"",""r"",stdin); - -} - -vector make_sorted_index(vector const& values) { - - vector index(values.size()); - - iota(index.begin(), index.end(), 0); - - stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } ); - - return index; - -} - - - -ll iSqrt(ll n) { - - ll lo = 1, hi = min((ll)3037000500, n); // long long - - ll res = 1; - - while(lo <= hi) { - - ll mid = lo + (hi - lo)/2; - - if(mid*mid <= n) { - - res = mid; - - lo = mid + 1; - - } - - else { - - hi = mid - 1; - - } - - } - - return res; - -} - - - -int solve() { - - ll n; - - cin >> n; - - ll alter = 0; - - ll alter2 = 0; - - ll size1 = 0; - - ll size2 = 0; - - LOO(i, 0, n -1 ) { - - ll temp; - - cin >> temp; - - if (i%2==0) { - - size1++; - - alter += temp; - - } - - else { - - size2++; - - alter2 += temp; - - } - - } - - if (alter%size1==0 && alter2%size2==0 && alter/size1==alter2/size2) { - - cout << ""YES"" << endl; - - } - - else { - - cout << ""NO"" << endl; - - } - - return 0; - -} - - - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - //iO(); - - //pre_process(); - - int t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -typedef long long ll; - -#define F first - -#define S second - -#define PB push_back - -#define MP make_pair - -#define LOO(i,a,b) for (int i = a; i <= b; i++) - -using namespace std; - -ll MAX = 1e9 + 7; - -void iO() { - - freopen(""output.txt"",""w"",stdout); - - freopen(""input.txt"",""r"",stdin); - -} - -vector make_sorted_index(vector const& values) { - - vector index(values.size()); - - iota(index.begin(), index.end(), 0); - - stable_sort(index.begin(), index.end(), [&values](int a, int b) { return values[a] < values[b]; } ); - - return index; - -} - - - -ll iSqrt(ll n) { - - ll lo = 1, hi = min((ll)3037000500, n); // long long - - ll res = 1; - - while(lo <= hi) { - - ll mid = lo + (hi - lo)/2; - - if(mid*mid <= n) { - - res = mid; - - lo = mid + 1; - - } - - else { - - hi = mid - 1; - - } - - } - - return res; - -} - - - -int solve() { - - ll n; - - cin >> n; - - ll alter = 0; - - LOO(i, 0, n -1 ) { - - ll temp; - - cin >> temp; - - if (i%2==0) { - - alter += temp; - - } - - else { - - alter -= temp; - - } - - } - - if (alter == 0) { - - cout << ""YES"" << endl; - - } - - else { - - cout << ""NO"" << endl; - - } - - return 0; - -} - - - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - //iO(); - - //pre_process(); - - int t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -}",1 -hello_world0421,2050B - Transfusion,c++23 ,299564528,299565151,"#include - -void solve() { - int n; std::cin >> n; - std::vector odd, even; - for (int i = 0, x; i < n; i++) { - std::cin >> x; - if (i & 1) odd.push_back(x); - else even.push_back(x); - } - int oddSum = 0, evenSum = 0; - for (auto x : odd) oddSum += x; - for (auto x : even) evenSum += x; - bool oddPart = oddSum % odd.size() == 0; - bool evenPart = evenSum % even.size() == 0; - if (oddPart && evenPart && oddSum / odd.size() == evenSum / even.size()) { - std::cout << ""YES\n""; - } else { - std::cout << ""NO\n""; - } -} - -int main() { - std::cin.tie(nullptr)->sync_with_stdio(false); - - int tt; std::cin >> tt; - while (tt--) solve(); - - return 0; -}","#include -using i64 = long long; - -void solve() { - int n; std::cin >> n; - i64 oddSum = 0, evenSum = 0, oddCnt = 0, evenCnt = 0; - for (int i = 0, x; i < n; i++) { - std::cin >> x; - if (i & 1) { - oddSum += x; oddCnt++; - } else { - evenSum += x; evenCnt++; - } - } - bool oddPart = oddSum % oddCnt == 0; - bool evenPart = evenSum % evenCnt == 0; - bool connected = oddSum / oddCnt == evenSum / evenCnt; - std::cout << (oddPart && evenPart && connected ? ""YES\n"" : ""NO\n""); -} - -int main() { - std::cin.tie(nullptr)->sync_with_stdio(false); - - int tt; std::cin >> tt; - while (tt--) solve(); - - return 0; -}",2 -xGONZOx,2050B - Transfusion,c++20 ,306668554,306666479,"#include - -using namespace std; - -int main () { - - ios_base::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t; cin >> t; - - while(t--) { - - int n; cin >> n; - - long long x, suma = 0, sumb=0; - - for(int i = 1; i < n+1; ++i) { - - cin >> x; - - if(i%2==0) { - - sumb += x; - - } else { - - suma += x; - - } - - } - - - - if(n%2==0) { - - int f = n/2; - - if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } else { - - int f = n/2; - - if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } - - - - } - -}","#include - -using namespace std; - -int main () { - - ios_base::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t; cin >> t; - - while(t--) { - - int n; cin >> n; - - int x, suma = 0, sumb=0; - - for(int i = 1; i < n+1; ++i) { - - cin >> x; - - if(i%2==0) { - - sumb += x; - - } else { - - suma += x; - - } - - } - - - - if(n%2==0) { - - int f = n/2; - - if(sumb%f==0 and suma%f==0 and sumb/f==suma/(f)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } else { - - int f = n/2; - - if(sumb%(f)==0 and suma%(f+1)==0 and sumb/f==suma/(f+1)) { - - cout << ""YES"" << '\n'; - - } else { - - cout << ""NO"" << '\n'; - - } - - } - - - - } - -}",1 -bit.by.bit,2050B - Transfusion,c++23 ,299458074,299457606,"// #include -// using namespace std; -// #define print(x) cout<=b; i--) -// #define all(v) v.begin(),v.end() -// #define pb(x) push_back(x) -// #define w(t) int t; cin>>t; while(t--) -// #define ll long long - - -// int main(){ -// w(t){ -// int n ; cin>>n; -// vector arr(n); -// long long even=0,odd=0; -// f(i,0,n) { -// int x; cin>>x; -// if(i%2) odd+=x; -// else even+=x; -// } -// bool z=false; -// if(n%2 ) { -// if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true; -// } - -// else { -// if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2)))) -// z=true; -// } -// if(z) print(""YES"") -// else print(""NO"") - -// } - -// } -#include - -using namespace std; - -void solve() { - int n; cin >> n; - vector a(n); - for (int &x : a) cin >> x; - - long long ods = 0, evs = 0; - for (int i = 0; i < n; i++) { - if (i & 1) ods += a[i]; - else evs += a[i]; - } - int odc = n / 2, evc = n / 2; - if (n & 1) evc++; - - if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) { - cout << ""NO""; - return; - } - cout << ""YES""; -} - -int main() { - int TESTS; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}","#include -using namespace std; -#define print(x) cout<=b; i--) -#define all(v) v.begin(),v.end() -#define pb(x) push_back(x) -#define w(t) int t; cin>>t; while(t--) -#define ll long long - - -int main(){ -w(t){ - int n ; cin>>n; - vector arr(n); - long long even=0,odd=0; - f(i,0,n) { - int x; cin>>x; - if(i%2) odd+=x; - else even+=x; - } - bool z=false; - if(n%2 ) { - if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true; - } - - else { - if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2)))) - z=true; - } - if(z) print(""YES"") - else print(""NO"") - -} - -}",1 -prashants18488,2050B - Transfusion,python,299660397,299621211,"t = int(input()) -for _ in range(t): - n = int(input()) - a = list(map(int, input().split())) - b = [a[i] for i in range(n) if i % 2 == 0] - c=[a[i] for i in range(n) if i % 2 != 0] - - if sum(b)%len(b)==0: - if sum(c)%len(c)==0 and sum(b)//len(b)==sum(c)//len(c): - print(""YES"") - else: - print(""NO"") - else: - print(""NO"")","t = int(input()) -for _ in range(t): - n = int(input()) - a = list(map(int, input().split())) - b = [] - count = 0 - mean = 2 * sum(a) // n - - if sum(a) % n != 0: - print(""NO"") - else: - for j in range(n - 2): - b.append(a[j] + a[j + 2]) - - for value in b: - if value % 2 == 0: - count += 2 - - if mean in b and count % 2 == 0: - print(""YES"") - else: - print(""NO"") -",1 -yanami_anna_ovo,2050B - Transfusion,c++23 ,299758155,299757730,"#include -using namespace std; -using ll = long long; -using vi = vector; -using vll = vector; -using vpll = vector>; -using vpii = vector>; -using vvll = vector>; -using vbl = vector; -using pll = pair; - -#define max3(a, b, c) max(max(a, b), c) -#define max4(a, b, c, d) max(max(a, b), max(c, d)) -#define min3(a, b, c) min(min(a, b), c) -#define min4(a, b, c, d) min(min(a, b), min(c, d)) -#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) -#define F first -#define S second -#define pb push_back -#define endl '\n' -//------------------------------------ -int ar[1001000]; -void solve(){ - int n; - cin>>n; - ll sum = 0; - ll sum1 = 0; - int ct1 = 0; - int ct2 = 0; - ll sum2 = 0; - for(int i = 0;i>ar[i]; - if(i%2==0){ - sum1+=ar[i]; - ct1++; - } - else{ - sum2+=ar[i]; - ct2++; - } - sum+=ar[i]; - } - if(sum%n!=0){ - cout<<""NO""<>T; - while(T--){ - solve(); - } - - return 0; -}","#include -using namespace std; -using ll = long long; -using vi = vector; -using vll = vector; -using vpll = vector>; -using vpii = vector>; -using vvll = vector>; -using vbl = vector; -using pll = pair; - -#define max3(a, b, c) max(max(a, b), c) -#define max4(a, b, c, d) max(max(a, b), max(c, d)) -#define min3(a, b, c) min(min(a, b), c) -#define min4(a, b, c, d) min(min(a, b), min(c, d)) -#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) -#define F first -#define S second -#define pb push_back -#define endl '\n' -//------------------------------------ -int ar[100100]; -void solve(){ - int n; - cin>>n; - int sum = 0; - int sum1 = 0; - int ct1 = 0; - int ct2 = 0; - int sum2 = 0; - for(int i = 0;i>ar[i]; - if(i%2==0){ - sum1+=ar[i]; - ct1++; - } - else{ - sum2+=ar[i]; - ct2++; - } - sum+=ar[i]; - } - if(sum%n!=0){ - cout<<""NO""<>T; - while(T--){ - solve(); - } - - return 0; -}",1 -VISHVJEET,2050B - Transfusion,c++17 ,299692038,299698211,"// **************** MBRAHUL *************** -#include -#define ll long long -#define pn cout<<""NO""< -#define vi vector -#define vb vector -#define u_map unordered_map -#define pll pair -#define pii pair -#define inf INT_MAX -#define pb push_back -#define mod 998244353 -#define MOD 1000000007 -#define ld long double -#define ff first -#define ss second -#define all(v) v.begin(),v.end() -#define min3(a, b, c) min(c, min(a, b)) -#define min4(a, b, c, d) min(d, min(c, min(a, b))) -#define loop(i,n) for(int i=0;i=0;i--) -using namespace std; - -void input(vector&arr,ll n){ -for(ll i =0;i>arr[i]; -} - -void printArr(vector&arr, ll i,ll j){ -for(ll k = i;k<=j;k++)cout<>n; - vll arr(n); - ll sum = 0; - loop(i,n){ - cin>>arr[i]; - sum+=arr[i]; - } - if(sum%n){ - pn; - return; - } - ll target = sum/n; - for(int i = 0;i>test; -while(test--){ -find(); -} -return 0; -}","// **************** MBRAHUL *************** -#include -#define ll long long -#define pn cout<<""NO""< -#define vi vector -#define vb vector -#define u_map unordered_map -#define pll pair -#define pii pair -#define inf INT_MAX -#define pb push_back -#define mod 998244353 -#define MOD 1000000007 -#define ld long double -#define ff first -#define ss second -#define all(v) v.begin(),v.end() -#define min3(a, b, c) min(c, min(a, b)) -#define min4(a, b, c, d) min(d, min(c, min(a, b))) -#define loop(i,n) for(int i=0;i=0;i--) -using namespace std; - -void input(vector&arr,ll n){ -for(ll i =0;i>arr[i]; -} - -void printArr(vector&arr, ll i,ll j){ -for(ll k = i;k<=j;k++)cout<>n; - vll arr(n); - ll sum = 0; - loop(i,n){ - cin>>arr[i]; - sum+=arr[i]; - } - if(sum%n){ - pn; - return; - } - ll target = sum/n; - for(int i = 0;i>test; -while(test--){ -find(); -} -return 0; -}",2 -ha203811,2050B - Transfusion,c++17 ,308836945,308833901,"#include - -using namespace std; - -int main() { - - int t;cin >> t; - - while (t--) { - - long long n;cin >> n; - - vectorv(n); - - vectorv2(n); - - long long count = 0; - - for (int i = 0;i < n;i++){cin >> v[i];count += v[i];} - - for (int i = 0;i < v.size();i++)v2[i] = v[i]; - - if (count % n){cout << ""NO"" << endl;continue;} - - long long sum = count / n; - - for (int i = 1;i < v.size() - 1;i++) { - - long long j1,j2; - - if (v[i - 1] < sum && v[i + 1] > sum) { - - j1 = sum - v[i - 1]; - - v[i - 1] += j1; - - v[i + 1] -= j1; - - }else if (v[i - 1] > sum && v[i + 1] < sum){ - - j1 = v[i - 1] - sum; - - v[i - 1] -= j1; - - v[i + 1] += j1; - - } - - else { - - j1 = v[i - 1] - sum; - - v[i - 1] -= j1; - - v[i + 1] += j1; - - } - - } - - bool f = true; - - for (int i = 0;i < v.size();i++) { - - if (v[i] != sum){f = false;break;} - - } - - for (int i = 1;i < v.size() - 1;i++) { - - int j1,j2; - - if (v[i - 1] < sum && v[i + 1] > sum) { - - j1 = sum - v[i - 1]; - - v[i - 1] += j1; - - v[i + 1] -= j1; - - }else if (v[i - 1] > sum && v[i + 1] < sum){ - - j1 = v[i - 1] - sum; - - v[i - 1] -= j1; - - v[i + 1] += j1; - - } - - else { - - j1 = sum - v[i - 1]; - - v[i - 1] += j1; - - v[i + 1] -= j1; - - } - - } - - bool t = true; - - for (int i = 0;i < v2.size();i++) { - - if (v2[i] != sum){t = false;break;} - - } - - if (f || t)cout << ""YES"" << endl;else cout << ""NO"" << endl; - - v.clear();v2.clear(); - - } - -}","#include - -using namespace std; - -int main() { - - int t;cin >> t; - - while (t--) { - - int n;cin >> n; - - vectorv(n); - - int count = 0; - - for (int i = 0;i < n;i++){cin >> v[i];count += v[i];} - - if (count % n){cout << ""NO"" << endl;continue;} - - int sum = count / n; - - for (int i = 1;i < v.size() - 1;i++) { - - while (v[i - 1] != sum) { - - if (v[i - 1] < sum) { - - v[i - 1]++;v[i + 1]--; - - }else { - - v[i - 1]--;v[i + 1]++; - - } - - } - - } - - bool f = true; - - for (int i = 0;i < v.size();i++) { - - if (v[i] != sum){f = false;break;} - - } - - if (f)cout << ""YES"" << endl;else cout << ""NO"" << endl; - - v.clear(); - - } - -}",1 -kevat_patel,2050B - Transfusion,c++23 ,308227584,308227489,"#include - -#define kevat ios::sync_with_stdio(false); - -#define patel cin.tie(0); - -using namespace std; - -#define ll long long - -#define pb push_back - -#define F for(int i=2;i= 0; i--) - - cout << str[i]; - -} - -//------------------------------------------------------------- - -string lowercase(string s1) - -{ - - for(int i=0; i='A'&&s1[i]<='Z') - - s1[i]=s1[i]-'A'+97; - - } - - return s1; - -} - -//------------------------------------------------------------- - -void uppercase(string s1) - -{ - - for(int i=0; i='a'&&s1[i]<='z') - - cout << char(s1[i] & '_'); - - } - -} - -//------------------------------------------------------------- - -void pb(int num) - -{ - - for(int i=10;i>=0;i--) - - { - - cout<<((num>>i) & 1); - - } - - cout<=0) - - { - - ll sr=sqrt(x); - - return(sr*sr==x); - - } - - return false; - -} - -//------------------------------------------------------------- - -void solve() - -{ - - ll n; - - cin >> n; - - ll sum1 = 0, cnt1 = 0; - - ll sum2 = 0, cnt2 = 0; - - for(int i = 0; i < n; i++){ - - int x; - - cin >> x; - - if(i & 1){ - - sum1 += x; - - cnt1++; - - }else{ - - sum2 += x; - - cnt2++; - - } - - } - - bool flg = (sum2 % cnt2 == 0 && sum1 % cnt1 == 0 && sum1 / cnt1 == sum2 / cnt2); - - cout << (flg ? ""YES\n"" : ""NO\n""); - -} - -int32_t main() - -{ - - kevat; - - patel; - - int t; - - cin>>t; - - while(t--) - - { - - solve(); - - } - -}","#include - -#define kevat ios::sync_with_stdio(false); - -#define patel cin.tie(0); - -using namespace std; - -#define ll long long - -#define pb push_back - -#define F for(int i=2;i= 0; i--) - - cout << str[i]; - -} - -//------------------------------------------------------------- - -string lowercase(string s1) - -{ - - for(int i=0; i='A'&&s1[i]<='Z') - - s1[i]=s1[i]-'A'+97; - - } - - return s1; - -} - -//------------------------------------------------------------- - -void uppercase(string s1) - -{ - - for(int i=0; i='a'&&s1[i]<='z') - - cout << char(s1[i] & '_'); - - } - -} - -//------------------------------------------------------------- - -void pb(int num) - -{ - - for(int i=10;i>=0;i--) - - { - - cout<<((num>>i) & 1); - - } - - cout<=0) - - { - - ll sr=sqrt(x); - - return(sr*sr==x); - - } - - return false; - -} - -//------------------------------------------------------------- - -void solve() - -{ - - int n; - - cin >> n; - - int sum1 = 0, cnt1 = 0; - - int sum2 = 0, cnt2 = 0; - - for(int i = 0; i < n; i++){ - - int x; - - cin >> x; - - if(i & 1){ - - sum1 += x; - - cnt1++; - - }else{ - - sum2 += x; - - cnt2++; - - } - - } - - bool flg = (sum2 % cnt2 == 0 && sum1 % cnt1 == 0 && sum1 / cnt1 == sum2 / cnt2); - - cout << (flg ? ""YES\n"" : ""NO\n""); - -} - -int32_t main() - -{ - - kevat; - - patel; - - int t; - - cin>>t; - - while(t--) - - { - - solve(); - - } - -}",1 -abenezer_m54,2050B - Transfusion,c++20 ,307327350,307327268,"#include - -using namespace std; - -typedef long long ll; - - - -int - -main(void) - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - ll t; cin >> t; - - for (ll i = 0; i < t; i++) { - - ll n; cin >> n; - - ll arr[n]; - - ll flag = 0; - - for (ll j = 0; j < n; j++) - - cin >> arr[j]; - - - - ll target = (arr[0] + arr[2]) / 2; - - - - for (ll j = 1; j < n - 1; j++) { - - ll *m1 = &arr[j - 1], *m2 = &arr[j + 1]; - - - - while (*m1 < target) { - - *m1 += 1; - - *m2 -= 1; - - } - - while (*m1 > target) { - - *m1 -= 1; - - *m2 += 1; - - } - - } - - - - if (arr[n - 2] != arr[n - 1] || arr[n - 3] != arr[n - 1]) - - flag = 1; - - - - if (flag) - - cout << ""NO"" << endl; - - else - - cout << ""YES"" << endl; - - } - - - - return 0; - -} - - - -","#include - -using namespace std; - -typedef long long ll; - - - -int - -main(void) - -{ - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - ll t; cin >> t; - - for (ll i = 0; i < t; i++) { - - ll n; cin >> n; - - ll arr[n]; - - ll flag = 0; - - for (ll j = 0; j < n; j++) - - cin >> arr[j]; - - - - ll target = (arr[0] + arr[2]) / 2; - - - - for (ll j = 1; j < n - 1; j++) { - - ll *m1 = &arr[j - 1], *m2 = &arr[j + 1]; - - - - while (*m1 < target) { - - *m1 += 1; - - *m2 -= 1; - - } - - while (*m1 > target) { - - *m1 -= 1; - - *m2 += 1; - - } - - - - if (*m1 < 0 || *m2 < 0) { - - flag = 1; - - break; - - } - - - - } - - - - if (arr[n - 2] != arr[n - 1] || arr[n - 3] != arr[n - 1]) - - flag = 1; - - - - if (flag) - - cout << ""NO"" << endl; - - else - - cout << ""YES"" << endl; - - } - - - - return 0; - -} - - - -",1 -harshitahl2006,2050B - Transfusion,python,308737116,308739650,"t = int(input()) - -for i in range(t): - - n = int(input()) - - inputs = list(map(int, input().split())) - - even_sum = 0 - - odd_sum = 0 - - for i in range(n): - - if i%2 == 0: - - even_sum += inputs[i] - - else: - - odd_sum += inputs[i] - - if n%2 == 1: - - if even_sum/(n//2+1) == odd_sum*(n-n//2-1): - - print(""YES"") - - else: - - print(""NO"") - - else: - - if even_sum == odd_sum: - - print(""YES"") - - else: - - print(""NO"")","t = int(input()) - -for i in range(t): - - n = int(input()) - - inputs = list(map(int, input().split())) - - even_sum = 0 - - odd_sum = 0 - - for i in range(n): - - if i%2 == 0: - - even_sum += inputs[i] - - else: - - odd_sum += inputs[i] - - if n%2 == 0: - - even = odd = n/2 - - else: - - even = n//2+1 - - odd = n - even - - if even_sum/even == int(even_sum/even) and odd_sum/odd == int(odd_sum/odd): - - if even_sum/even == odd_sum/odd: - - print(""YES"") - - else: - - print(""NO"") - - else: - - print(""NO"") - - ",2 -Spencer1s#,2050B - Transfusion,java,308699590,308700183,"import java.io.BufferedReader; - -import java.io.InputStreamReader; - -import java.util.*; - - - -public class Main { - - public static void main(String[] args) throws Exception { - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - int t = Integer.parseInt(br.readLine()); - - - - while (t-->0) - - { - - - - int n=Integer.parseInt(br.readLine()); - - StringTokenizer st=new StringTokenizer(br.readLine()); - - int k=0; - - int[] a=new int[n]; - - // Set set=new HashSet<>(); - - long evensum=0,oddsum=0; - - while(st.hasMoreTokens()) - - { - - a[k]=Integer.parseInt(st.nextToken()); - - - - if(k%2==0) - - evensum+=a[k]; - - else - - oddsum+=a[k]; - - k++; - - } - - - - if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || (evensum+oddsum)%n!=0) - - System.out.println(""No""); - - else - - System.out.println(""Yes""); - - - - - - - - - - } - - } - -} - - - -// class ListComparator implements Comparator> - -// { - -// int index=0; - -// public ListComparator(int i) - -// { - -// index=i; - -// } - - - -// @Override - -// public int compare(List o1,List o2) - -// { - -// return Integer.compare(o1.get(index), o2.get(index)); - -// } - - - -// }","import java.io.BufferedReader; - -import java.io.InputStreamReader; - -import java.util.*; - - - -public class Main { - - public static void main(String[] args) throws Exception { - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - - int t = Integer.parseInt(br.readLine()); - - - - while (t-->0) - - { - - - - int n=Integer.parseInt(br.readLine()); - - StringTokenizer st=new StringTokenizer(br.readLine()); - - int k=0; - - int[] a=new int[n]; - - // Set set=new HashSet<>(); - - long evensum=0,oddsum=0; - - while(st.hasMoreTokens()) - - { - - a[k]=Integer.parseInt(st.nextToken()); - - - - if(k%2==0) - - evensum+=a[k]; - - else - - oddsum+=a[k]; - - k++; - - } - - - - if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || evensum/((n+1)/2)!=oddsum/(n/2)) - - System.out.println(""No""); - - else - - System.out.println(""Yes""); - - - - - - - - - - } - - } - -} - - - -// class ListComparator implements Comparator> - -// { - -// int index=0; - -// public ListComparator(int i) - -// { - -// index=i; - -// } - - - -// @Override - -// public int compare(List o1,List o2) - -// { - -// return Integer.compare(o1.get(index), o2.get(index)); - -// } - - - -// }",2 -Yash_Savalkar,2050B - Transfusion,c++20 ,299598163,299597676,"#include -using namespace std; - -#define ll long long - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while(t--) - { - ll n; - cin>>n; - vector v(n); - - ll s0=0,s1=0,c1=0,c0=0; - for(ll i = 0; i < n; i++){ - cin>>v[i]; - if(i%2==0){ - s0+=v[i]; - c0++; - } - else { - s1+=v[i]; - c1++; - } - } - - if(s0*c1== s1*c0 && (s1+s0)%(c0+c1)==0){ - cout<<""YES""< -using namespace std; - -#define ll long long - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while(t--) - { - ll n; - cin>>n; - vector v(n); - - int s0=0,s1=0,c1=0,c0=0; - for(int i = 0; i < n; i++){ - cin>>v[i]; - if(i%2==0){ - s0+=v[i]; - c0++; - } - else { - s1+=v[i]; - c1++; - } - } - - if(s0*c1== s1*c0 && (s1+s0)%n==0){ - cout<<""YES""< - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -template - -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -#define ll long long - -typedef vector vi; - -typedef vector vll; - -#define REP(i, a, b) for(int i=a; i> n; - - vll a(n); - - for (ll &x : a) cin >> x; - - vll even, odd; - - ll sumEven = 0, sumOdd = 0; - - for (ll i = 0; i < n; i++) { - - if (i % 2 == 0) { - - even.push_back(a[i]); - - sumEven += a[i]; - - } else { - - odd.push_back(a[i]); - - sumOdd += a[i]; - - } - - } - - bool one = ceil(double(sumEven) / double(even.size())) == floor(double(sumEven) / double(even.size())); - - bool two = ceil(double(sumOdd) / double(odd.size())) == floor(double(sumOdd) / double(odd.size())); - - if (one == true && two == true && sumEven / even.size() == sumOdd / odd.size()) { - - cout << ""YES"" << endl; - - } else cout << ""NO"" << endl; - -} - - - -int main() { - -#ifndef ONLINE_JUDGE - - //for getting input from input1.txt - - freopen(""input1.txt"", ""r"", stdin); - - //for writing output to output1.txt - - freopen(""output1.txt"", ""w"", stdout); - -#endif - - - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -}","#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -template - -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -#define ll long long - -typedef vector vi; - -typedef vector vll; - -#define REP(i, a, b) for(int i=a; i> n; - - vll a(n); - - for (ll &x : a) cin >> x; - - vll even, odd; - - ll sumEven = 0, sumOdd = 0; - - for (ll i = 0; i < n; i++) { - - if (i % 2 == 0) { - - even.push_back(a[i]); - - sumEven += a[i]; - - } else { - - odd.push_back(a[i]); - - sumOdd += a[i]; - - } - - } - - bool one = ceil(float(sumEven) / float(even.size())) == floor(float(sumEven) / float(even.size())); - - bool two = ceil(float(sumOdd) / float(odd.size())) == floor(float(sumOdd) / float(odd.size())); - - if (one == true && two == true && sumEven / even.size() == sumOdd / odd.size()) { - - cout << ""YES"" << endl; - - } else cout << ""NO"" << endl; - -} - - - -int main() { - -#ifndef ONLINE_JUDGE - - //for getting input from input1.txt - - freopen(""input1.txt"", ""r"", stdin); - - //for writing output to output1.txt - - freopen(""output1.txt"", ""w"", stdout); - -#endif - - - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -}",1 -priyanshusharma8126,2050B - Transfusion,c++20 ,306577016,306576739,"#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - - - long long a[n]; - - int sumodd=0; - - int sumeve=0; - - for(int i=0;i>a[i]; - - if(i%2)sumodd+=a[i]; - - else sumeve+=a[i]; - - } - - int eve=n/2,odd=n/2; - - if(n%2)eve++; - - if(sumodd%odd!=0 || sumeve%eve!=0 || sumodd/odd!=sumeve/eve){ - - cout<<""NO""< - -using namespace std; - - - -int main() - -{ - - int tt; - - cin >> tt; - - while (tt--) - - { - - int n; - - cin >> n; - - vector nums(n); - - long long sum=0; - - for (int i = 0; i < n; i++) - - { - - cin >> nums[i]; - - sum+=nums[i]; - - } - - if (n >= 3) - - { - - if(n==3) - - { - - long long num=nums[1]; - - long long diff1=num-nums[0]; - - long long diff2=num-nums[2]; - - if((diff1>0&&diff2>0)||(diff1<0&&diff2<0)||abs(diff1)!=abs(diff2))cout<<""NO""< -#include -using namespace std; - -void solve(){ - int n;;cin>>n;int arr[n]; - for(int i=0;i>arr[i]; - } - int check=0; - for(int i=0;i>t; -while(t-->0){ -solve(); -} -return 0; -} -","#include -#include -using namespace std; - -void solve(){ - long long int n;;cin>>n;int arr[n]; - for(long long int i=0;i>arr[i]; - } - long long int check=0; - for(long long int i=0;i>t; -while(t-->0){ -solve(); -} -return 0; -} -",2 -Shubhamdhingra9896,2050B - Transfusion,c++17 ,299431150,299431293,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -template class y_combinator_result { - Fun fun_; -public: - template explicit y_combinator_result(T &&fun): fun_(std::forward(fun)) {} - template decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward(args)...); } -}; -template decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result>(std::forward(fun)); } - - -template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << "", "" << p.second << ')'; } -template ostream& operator<<(ostream& os, const tuple& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? "", "" : """")), ...); }, t); return os << ')'; } -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = "", ""; return os << '}'; } - -void dbg_out() { cerr << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#ifdef NEAL_DEBUG -#define dbg(...) cerr << '[' << __FILE__ << ':' << __LINE__ << ""] ("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) -#else -#define dbg(...) -#endif - - -void run_case() { - int N; - cin >> N; - array sums = {}; - - for (int i = 0; i < N; i++) { - int a; - cin >> a; - sums[i % 2] += a; - } - - bool ans = (sums[0] + sums[1]) % N == 0; - int64_t avg = (sums[0] + sums[1]) / N; - ans &= sums[0] == avg * ((N + 1) / 2); - cout << (ans ? ""YES"" : ""NO"") << '\n'; -} - -int main() { - ios::sync_with_stdio(false); -#ifndef NEAL_DEBUG - cin.tie(nullptr); -#endif - - int tests; - cin >> tests; - - while (tests-- > 0) - run_case(); -} -","#include - -using namespace std; - -#ifdef LOCAL -#include ""algo/debug.h"" -#else -#define debug(...) 42 -#endif - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int tt; - cin >> tt; - while (tt--) { - int n; - cin >> n; - vector a(n); - array sum = {0, 0}; - array cnt = {0, 0}; - for (int i = 0; i < n; i++) { - cin >> a[i]; - sum[i % 2] += a[i]; - cnt[i % 2] += 1; - } - if (sum[0] % cnt[0] == 0 && sum[1] % cnt[1] == 0 && sum[0] / cnt[0] == sum[1] / cnt[1]) { - cout << ""YES"" << '\n'; - } else { - cout << ""NO"" << '\n'; - } - } - return 0; -} -",2 -progger-serg,2050B - Transfusion,c++17 ,308469640,308470055,"#include - - - -using namespace std; - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - for(int gt=0;gt>n; - - for(int i=1;i<=n;i++){ - - int a; - - cin>>a; - - if(i%2==1){k1++;s1+=a;} - - else{k2++;s2+=a;} - - } - - if(s1%k1!=0 || s2%k2!=0){cout<<""NO""<<'\n';} - - else if(s1/k1==s2/k2){cout<<""YES""<<'\n';} - - else{cout<<""NO""<<'\n';} - - } - - return 0; - -} - -","#include - - - -using namespace std; - - - -int main() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin>>t; - - for(int gt=0;gt>n; - - for(int i=1;i<=n;i++){ - - int a; - - cin>>a; - - if(i%2==1){k1++;s1+=a;} - - else{k2++;s2+=a;} - - } - - if(s1%k1!=0 || s2%k2!=0){cout<<""NO""<<'\n';} - - else if(s1/k1==s2/k2){cout<<""YES""<<'\n';} - - else{cout<<""NO""<<'\n';} - - } - - return 0; - -} - -",2 -coderiam,2050B - Transfusion,c++17 ,299507922,299508607,"#include -using namespace std; - - - - -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); - - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int arr[n]; - for(int i =0;i>arr[i]; - } - int od_,ev_; - if(n%2 == 0){ - od_ = n/2; - ev_ = n/2; - } - else{ - od_ = n/2 + 1; - ev_ = n/2; - } - int od =0; - int ev =0; - for(int i =0;i -using namespace std; - - - - -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); - - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int arr[n]; - for(int i =0;i>arr[i]; - } - int od_,ev_; - if(n%2 == 0){ - od_ = n/2; - ev_ = n/2; - } - else{ - od_ = n/2 + 1; - ev_ = n/2; - } - long long int od =0; - long long int ev =0; - for(int i =0;i - -using namespace std; - -int main() -{ - int t; - cin >> t; - - - while(t--) - { - int n; - cin >> n; - vector a(n); - int sum = 0; - for(int i = 0; i < n; i++) - { - cin >> a[i]; - sum += a[i]; - } - - if(sum % 3 == 0) - cout << ""YES\n""; - else - cout << ""NO\n""; - } - return 0; -}","#include -using namespace std; - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n; - cin >> n; - vector a(n); - - long long sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0; - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - if (i % 2 == 0) - { - sum1 += a[i]; - ctr1++; - } - else - { - sum2 += a[i]; - ctr2++; - } - } - - if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % (ctr1 + ctr2) == 0) - { - cout << ""YES\n""; - } - else - { - cout << ""NO\n""; - } - } - - return 0; -} -",2 -pp031608,2050B - Transfusion,c++17 ,299557825,299123393,"#include -#define int long long -using namespace std; -int t; -int n; -const int maxn=2e5+5; -int a[maxn]; -signed main(){ - cin>>t; - while(t--){ - cin>>n; - for(int i=1;i<=n;i++) cin>>a[i]; - int ans=0,sum=0; - for(int i=1;i<=n;i+=2) - ans+=a[i]; - for(int i=2;i<=n;i+=2) - sum+=a[i]; - if(n%2==0){ - if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<""NO""< - - 3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects. - -Want to change languages? Try the search bar up the top. -*/ - -#include - -using namespace std; - -#define ll long long - -int main() { - int tc; cin>>tc; - while(tc--){ - ll n; cin>>n; - ll arr[n]; - ll sum=0; - for(int i=0;i>arr[i]; - sum += arr[i]; - } - if(sum%n !=0 ){ - cout<<""NO""<=val){ - arr[i-1] = val; - arr[i+1] += diff; - }else{ - arr[i-1] = val; - if(arr[i+1] - diff <=0){ - cout<<""NO""< - -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - int n, c = 0, l = 0, cc=0, cl=0; - - cin >> n; - for (int i = 0; i < n; i++) { - int p; - cin >> p; - if (i % 2 == 0) { - l += p; - cl++; - } - else { - c += p; - cc++; - } - - } - if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) { - cout << ""YES""; - } - else { - cout << ""NO""; - } - cout << endl; - } - return 0; -}","#include - -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - long long n, c = 0, l = 0, cc=0, cl=0; - - cin >> n; - for (int i = 0; i < n; i++) { - int p; - cin >> p; - if (i % 2 == 0) { - l += p; - cl++; - } - else { - c += p; - cc++; - } - - } - if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) { - cout << ""YES""; - } - else { - cout << ""NO""; - } - cout << endl; - } - return 0; -}",2 -bipindehariya05,2050B - Transfusion,c++20 ,296002483,296002701,"#include - -using namespace std; - -int main() -{ - int t; cin >> t; - while(t) - { - int n; cin >> n; - int a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - int sum = 0; - for(int i = 0; i < n; i++) sum += a[i]; - if(sum % n != 0) - { - cout << ""NO"" << endl; - t--; - continue; - } - - int unit = sum / n; - int req_sum = 0; int test_sum = 0; - for(int i = 0; i < n; i += 2) - { - req_sum += unit; - test_sum += a[i]; - } - if(test_sum != req_sum) - { - cout << ""NO"" << endl; - t--; - continue; - } - cout << ""YES"" << endl; - t--; - } -}","#include - -using namespace std; - -int main() -{ - int t; cin >> t; - while(t) - { - int n; cin >> n; - int a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - unsigned long long sum = 0; - for(int i = 0; i < n; i++) sum += a[i]; - if(sum % n != 0) - { - cout << ""NO"" << endl; - t--; - continue; - } - - unsigned long long unit = sum / n; - unsigned long long req_sum = 0, test_sum = 0; - for(int i = 0; i < n; i += 2) - { - req_sum += unit; - test_sum += a[i]; - } - if(test_sum != req_sum) - { - cout << ""NO"" << endl; - t--; - continue; - } - cout << ""YES"" << endl; - t--; - } -}",2 -Sn0wflame,2050B - Transfusion,c++20 ,306631100,306631552,"#include - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define pb push_back - -#define all(x) begin(x), end(x) - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) (int)(x).size() - -#define ull unsigned long long - -#define fr(i, a, b) for (long long i = a; i < b; i++) - -#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) - - - -// Debugging function - -template - -void __f(const char *name, Arg1 &&arg1) { cout << name << "" : "" << arg1 << endl; } - -template - -void __f(const char *names, Arg1 &&arg1, Args &&...args) { - - const char *comma = strchr(names + 1, ','); - - cout.write(names, comma - names) << "" : "" << arg1 << "" | ""; - - __f(comma + 1, args...); - -} - - - -// Input and Output Overloads for Vectors - -template - -istream &operator>>(istream &istream, vector &vec) { - - for (auto &a : vec) cin >> a; - - return istream; - -} - -template - -ostream &operator<<(ostream &ostream, const vector &vec) { - - for (auto &a : vec) cout << a << "" ""; - - return ostream; - -} - - - - - -void to_lower(string &s) { transform(all(s), s.begin(), ::tolower); } - - - - - -void to_upper(string &s) { transform(all(s), s.begin(), ::toupper); } - - - - - -string helper(string a, string b) { - - if (a + b != b + a) return """"; - - int Gcd_len = __gcd(a.size(), b.size()); - - return a.substr(0, Gcd_len); - -} - -//----------------------------------------------------------------- - - - - - -vi factors(int n) { - - vi ans; - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - ans.pb(i); - - if (i != n / i) ans.pb(n / i); - - } - - } - - return ans; - -} - - - - bool bit(int mask, int pos){ - - return (mask >> pos ) &1; - - } - - - - bool check(int k , vi &v ,int h){ - - vi tmp; - - fr(i,0,k){ - - tmp.pb(v[i]); - - } - - sort(all(tmp)); - - reverse(all(tmp)); - - - - int t = 0; - - for(int i = 0 ; i < k ;i+=2) t += tmp[i]; - - return t <= h; - - } - - - - - - - - - - void solve() { - - int n; - - cin >> n; - - vi v(n); - - for (int &x : v) cin >> x; - - - - - - int Odd_sum = 0, Even_sum = 0; - - - - - - fr(i,0,n){ - - - - if(i &1) Odd_sum += v[i]; - - else Even_sum += v[i]; - - } - - - - int odd = n/2, eve = n/2; - - if( n&1) eve++; - - - - if( (Odd_sum % odd != 0 || Even_sum % eve != 0 ) || Odd_sum/odd != Even_sum/eve ){ - - cout << ""NO"" << endl; - - return; - - } - - - - cout << ""YES"" << endl; - - - - - - - - - - } - - - - - - - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int tc; cin >> tc; - - while(tc--){ - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define pb push_back - -#define all(x) begin(x), end(x) - -#define rall(v) v.rbegin(), v.rend() - -#define sz(x) (int)(x).size() - -#define ull unsigned long long - -#define fr(i, a, b) for (long long i = a; i < b; i++) - -#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) - - - -// Debugging function - -template - -void __f(const char *name, Arg1 &&arg1) { cout << name << "" : "" << arg1 << endl; } - -template - -void __f(const char *names, Arg1 &&arg1, Args &&...args) { - - const char *comma = strchr(names + 1, ','); - - cout.write(names, comma - names) << "" : "" << arg1 << "" | ""; - - __f(comma + 1, args...); - -} - - - -// Input and Output Overloads for Vectors - -template - -istream &operator>>(istream &istream, vector &vec) { - - for (auto &a : vec) cin >> a; - - return istream; - -} - -template - -ostream &operator<<(ostream &ostream, const vector &vec) { - - for (auto &a : vec) cout << a << "" ""; - - return ostream; - -} - - - - - -void to_lower(string &s) { transform(all(s), s.begin(), ::tolower); } - - - - - -void to_upper(string &s) { transform(all(s), s.begin(), ::toupper); } - - - - - -string helper(string a, string b) { - - if (a + b != b + a) return """"; - - int Gcd_len = __gcd(a.size(), b.size()); - - return a.substr(0, Gcd_len); - -} - -//----------------------------------------------------------------- - - - - - -vi factors(int n) { - - vi ans; - - for (int i = 1; i * i <= n; i++) { - - if (n % i == 0) { - - ans.pb(i); - - if (i != n / i) ans.pb(n / i); - - } - - } - - return ans; - -} - - - - bool bit(int mask, int pos){ - - return (mask >> pos ) &1; - - } - - - - bool check(int k , vi &v ,int h){ - - vi tmp; - - fr(i,0,k){ - - tmp.pb(v[i]); - - } - - sort(all(tmp)); - - reverse(all(tmp)); - - - - int t = 0; - - for(int i = 0 ; i < k ;i+=2) t += tmp[i]; - - return t <= h; - - } - - - - - - - - - - void solve() { - - int n; - - cin >> n; - - vi a(n); - - for (int &x : a) cin >> x; - - - - - - long long ods = 0, evs = 0; - - for (int i = 0; i < n; i++) { - - if (i & 1) ods += a[i]; - - else evs += a[i]; - - } - - int odc = n / 2, evc = n / 2; - - if (n & 1) evc++; - - - - if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) { - - cout << ""NO"" << endl; - - return; - - } - - cout << ""YES"" << endl; - - - - - - } - - - - - - - - - -signed main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - int tc; cin >> tc; - - while(tc--){ - - solve(); - - } - - return 0; - -} - -",2 -dingchilling,2050B - Transfusion,c++17 ,307391787,307392006,"#include - -using namespace std; - -using ll = long long; - -using ld = long double; - -using vi = vector; - -using vll = vector; - -using pii = pair; - -using pll = pair; - -using vpii = vector; - -void fast_io() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - -} - - - -int main() { - - fast_io(); - - - - int tc; - - cin>>tc; - - while(tc--){ - - int n; - - cin>>n; - - vi a(n,0); - - int total = 0; - - for(int i=0;i>a[i]; - - total += a[i]; - - } - - - - ll esum=0,osum=0; - - ll epos=n/2,opos=(n+1)/2; - - - - for(int i=0;i - -using namespace std; - -using ll = long long; - -using ld = long double; - -using vi = vector; - -using vll = vector; - -using pii = pair; - -using pll = pair; - -using vpii = vector; - -void fast_io() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - -} - - - -int main() { - - fast_io(); - - - - int tc; - - cin>>tc; - - while(tc--){ - - int n; - - cin>>n; - - vi a(n,0); - - ll total = 0; - - for(int i=0;i>a[i]; - - total += a[i]; - - } - - - - ll esum=0,osum=0; - - ll epos=n/2,opos=(n+1)/2; - - - - for(int i=0;i - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - -ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} - -ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} - -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} - -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} - -ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m - -#define fr(i,n) for (ll i=0;i::iterator - -#define sz(x) x.size() - -#define ff first - -#define ss second - -#define all(v) v.begin(), v.end() - -#define fv(x,v) for(auto &x:v) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - -#define mod (ll)(1e9+7) - -void _print(ll t) {cerr << t;} - -void _print(int 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;} - - - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(unordered_map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -#pragma GCC optimize(""unroll-loops,O3,Ofast"") //even 10^8+ also works with this - -//#pragma GCC target(""avx2,avx,fma,bmi,bmi2,lzcnt,popcnt"") - - - -int knightx[8]={-1,-2,-2,-1,1,2,2,1}; - -int knighty[8]={-2,-1,1,2,2,1,-1,-2}; - - - -//............................................................................................................................................... - - - -// lambda dfs-------------> - -// function dfs = [&](int node,int par){ - - - -// }; - -// dfs(0,-1); - -// --------------------------------------------------------------------------------------- - -// //__builtin_popcount(a) number of set bits for int - -// //__builtin_popcountll(a) number of set bits for long long - -// //<>Right shift /2 - -// //char a='A'|(1<<5); in uppercase 5th bit is not set and in lower case 5th bit is set - -// //char a='A'|' '; - -// //char A='a'&(~(1<<5)); unset the 5th bit - -// //char A='a'& '_'; - -// //if(n&(n-1)==0) then number is power of two - -//.................................................................................................. - -//0xAAAAAAAA - -//0x55555555 - -//if (x.find(s) != string::npos) - -//auto lastElement = *--mySet.end(); - -//mySet.erase(--mySet.end()); - -//else if (b % a == 0 && c % a == 0 && (b / a - 1) + (c / a - 1) <= 3) - -//if rope have to be divide by equal; - -//maxSum = *max_element(all(v)); - -// when modulo comes check for same number - -// when we do difference check if its is negative - -//__int128 cal = (__int128)n * mid * mid + (__int128)k * mid; - -// most number of divisor less than equal to n in vector - -// for(int i = 1; i <= n; ++i) { - -// for(int j = i; j <= n; j += i) mx[j] += cnt[i]; - -// } - -// if(a= 1; i--) { - -// while (b.size() < a[i]) { - -// b.push_back(i); - -// } - -// for(int i=(s[0]=='0');i=p?'0':s[i]); - -// upper bound give just greater than - -// lower bound give equal or greater - -// // Need to handle re-insertion since multimap does not support direct modification. - - //mp.erase(it); - - //mp.emplace(it->first, 'A'); - -// sum of 1+2+3+4+5.... odd time is exactly divisible by n; - -//cout << (char)(digits[i] < 4 ? (digits[i] + '0') : (digits[i] + '1')); - -// auto getSum = [&](int l, int r) -> int { - -// return (r * (r + 1) / 2) - (l * (l - 1) / 2); - -// }; - -// result.insert(result.end(), levelNodes.begin(), levelNodes.end()); - - - -// leftToRight = !leftToRight; - -// do { - -// string concatenated = """"; - -// for (const string& bin : perm) { - -// concatenated += bin; - -// } - -// maxValue = max(maxValue, binaryToDecimal(concatenated)); - -// } while (next_permutation(perm.begin(), perm.end())); - -#define vin(v) for(auto &x : v) cin >> x; - -int binaryToDecimal(const string& binary) { - - return stoi(binary, nullptr, 2); - - } - -string toBinary(int n) { - - string binary = """"; - - while (n > 0) { - - binary = to_string(n % 2) + binary; - - n /= 2; - - } - - return binary.empty() ? ""0"" : binary; - - } - -class DisjointSet { - - vector rank, parent, size; - - - -public: - - DisjointSet(int n) { - - rank.resize(n+1, 0); - - parent.resize(n+1); - - size.resize(n+1); - - for(int i = 0; i <= n; i++) { - - parent[i] = i; - - size[i] = 1; - - } - - } - - - - int findUPar(int node) { - - if(node == parent[node]) - - return node; - - return parent[node] = findUPar(parent[node]); // Path compression - - } - - - - void unionByRank(int u, int v) { - - int ulp_u = findUPar(u); - - int ulp_v = findUPar(v); - - if(ulp_u == ulp_v) return; - - if(rank[ulp_u] < rank[ulp_v]) { - - parent[ulp_u] = ulp_v; - - } - - else if(rank[ulp_v] < rank[ulp_u]) { - - parent[ulp_v] = ulp_u; - - } - - else { - - parent[ulp_v] = ulp_u; - - rank[ulp_u]++; - - } - - } - - - - void unionBySize(int u, int v) { - - int ulp_u = findUPar(u); - - int ulp_v = findUPar(v); - - if(ulp_u == ulp_v) return; - - if(size[ulp_u] < size[ulp_v]) { - - parent[ulp_u] = ulp_v; - - size[ulp_v] += size[ulp_u]; - - } - - else { - - parent[ulp_v] = ulp_u; - - size[ulp_u] += size[ulp_v]; - - } - - } - - vector> groups() { - - int n = parent.size(); - - vector leader_buf(n), group_size(n); - - - - // Find leaders for each node - - for (int i = 0; i < n; i++) { - - leader_buf[i] = findUPar(i); - - group_size[leader_buf[i]]++; - - } - - - - // Create groups - - vector> result(n); - - for (int i = 0; i < n; i++) { - - result[i].reserve(group_size[i]); - - } - - - - for (int i = 0; i < n; i++) { - - result[leader_buf[i]].push_back(i); - - } - - - - // Remove empty groups - - result.erase( - - remove_if(result.begin(), result.end(), - - [](const vector& v) { return v.empty(); }), - - result.end() - - ); - - - - return result; - - } - -}; - -class Solution - -{ - -public: - - //Function to find sum of weights of edges of the Minimum Spanning Tree. - - int spanningTree(int V, vector> adj[]) - - { - - // 1 - 2 wt = 5 - - /// 1 - > (2, 5) - - // 2 -> (1, 5) - - - - // 5, 1, 2 - - // 5, 2, 1 - - vector>> edges; - - for (int i = 0; i < V; i++) { - - for (auto it : adj[i]) { - - int adjNode = it[0]; - - int wt = it[1]; - - int node = i; - - - - edges.push_back({wt, {node, adjNode}}); - - } - - } - - DisjointSet ds(V); - - sort(edges.begin(), edges.end()); - - int mstWt = 0; - - for (auto it : edges) { - - int wt = it.first; - - int u = it.second.first; - - int v = it.second.second; - - - - if (ds.findUPar(u) != ds.findUPar(v)) { - - mstWt += wt; - - ds.unionBySize(u, v); - - } - - } - - - - return mstWt; - - } - -}; - -void solve() { - - int n; cin >> n; - - vector v(n); - - for (int i = 0; i < n; i++) cin >> v[i]; - - - - ll sum = accumulate(v.begin(), v.end(), 0LL); - - if (sum % n != 0) { - - cout << ""NO"" << endl; - - return; - - } - - - - ll p = sum / n; - - for (int i = 1; i < n - 1; i++) { - - if (v[i - 1] < p) { - - int diff = p - v[i - 1]; - - v[i + 1] -= diff; - - v[i - 1] = p; - - } else if (v[i - 1] > p) { - - int diff = v[i - 1] - p; - - v[i + 1] += diff; - - v[i - 1] = p; - - } - - } - - for (int i = 0; i < n; i++) { - - if (v[i] != p) { - - cout << ""NO"" << endl; - - return; - - } - - } - - - - cout << ""YES"" << endl; - -} - -int main(){ - -#ifndef ONLINE_JUDGE - - freopen(""Error.txt"",""w"",stderr); - -#endif - - - - int t=1; - - cin>>t; - - while(t--){ - - solve(); - - } - -} ","#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -typedef long long ll; - -typedef unsigned long long ull; - -typedef long double lld; - -ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} - -ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} - -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} - -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} - -ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m - -#define fr(i,n) for (ll i=0;i::iterator - -#define sz(x) x.size() - -#define ff first - -#define ss second - -#define all(v) v.begin(), v.end() - -#define fv(x,v) for(auto &x:v) - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -#else - -#define debug(x) - -#endif - -#define mod (ll)(1e9+7) - -void _print(ll t) {cerr << t;} - -void _print(int 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;} - - - -template void _print(pair p); - -template void _print(vector v); - -template void _print(set v); - -template void _print(map v); - -template void _print(multiset v); - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} - -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -template void _print(unordered_map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -#pragma GCC optimize(""unroll-loops,O3,Ofast"") //even 10^8+ also works with this - -//#pragma GCC target(""avx2,avx,fma,bmi,bmi2,lzcnt,popcnt"") - - - -int knightx[8]={-1,-2,-2,-1,1,2,2,1}; - -int knighty[8]={-2,-1,1,2,2,1,-1,-2}; - - - -//............................................................................................................................................... - - - -// lambda dfs-------------> - -// function dfs = [&](int node,int par){ - - - -// }; - -// dfs(0,-1); - -// --------------------------------------------------------------------------------------- - -// //__builtin_popcount(a) number of set bits for int - -// //__builtin_popcountll(a) number of set bits for long long - -// //<>Right shift /2 - -// //char a='A'|(1<<5); in uppercase 5th bit is not set and in lower case 5th bit is set - -// //char a='A'|' '; - -// //char A='a'&(~(1<<5)); unset the 5th bit - -// //char A='a'& '_'; - -// //if(n&(n-1)==0) then number is power of two - -//.................................................................................................. - -//0xAAAAAAAA - -//0x55555555 - -//if (x.find(s) != string::npos) - -//auto lastElement = *--mySet.end(); - -//mySet.erase(--mySet.end()); - -//else if (b % a == 0 && c % a == 0 && (b / a - 1) + (c / a - 1) <= 3) - -//if rope have to be divide by equal; - -//maxSum = *max_element(all(v)); - -// when modulo comes check for same number - -// when we do difference check if its is negative - -//__int128 cal = (__int128)n * mid * mid + (__int128)k * mid; - -// most number of divisor less than equal to n in vector - -// for(int i = 1; i <= n; ++i) { - -// for(int j = i; j <= n; j += i) mx[j] += cnt[i]; - -// } - -// if(a= 1; i--) { - -// while (b.size() < a[i]) { - -// b.push_back(i); - -// } - -// for(int i=(s[0]=='0');i=p?'0':s[i]); - -// upper bound give just greater than - -// lower bound give equal or greater - -// // Need to handle re-insertion since multimap does not support direct modification. - - //mp.erase(it); - - //mp.emplace(it->first, 'A'); - -// sum of 1+2+3+4+5.... odd time is exactly divisible by n; - -//cout << (char)(digits[i] < 4 ? (digits[i] + '0') : (digits[i] + '1')); - -// auto getSum = [&](int l, int r) -> int { - -// return (r * (r + 1) / 2) - (l * (l - 1) / 2); - -// }; - -// result.insert(result.end(), levelNodes.begin(), levelNodes.end()); - - - -// leftToRight = !leftToRight; - -// do { - -// string concatenated = """"; - -// for (const string& bin : perm) { - -// concatenated += bin; - -// } - -// maxValue = max(maxValue, binaryToDecimal(concatenated)); - -// } while (next_permutation(perm.begin(), perm.end())); - -#define vin(v) for(auto &x : v) cin >> x; - -int binaryToDecimal(const string& binary) { - - return stoi(binary, nullptr, 2); - - } - -string toBinary(int n) { - - string binary = """"; - - while (n > 0) { - - binary = to_string(n % 2) + binary; - - n /= 2; - - } - - return binary.empty() ? ""0"" : binary; - - } - -class DisjointSet { - - vector rank, parent, size; - - - -public: - - DisjointSet(int n) { - - rank.resize(n+1, 0); - - parent.resize(n+1); - - size.resize(n+1); - - for(int i = 0; i <= n; i++) { - - parent[i] = i; - - size[i] = 1; - - } - - } - - - - int findUPar(int node) { - - if(node == parent[node]) - - return node; - - return parent[node] = findUPar(parent[node]); // Path compression - - } - - - - void unionByRank(int u, int v) { - - int ulp_u = findUPar(u); - - int ulp_v = findUPar(v); - - if(ulp_u == ulp_v) return; - - if(rank[ulp_u] < rank[ulp_v]) { - - parent[ulp_u] = ulp_v; - - } - - else if(rank[ulp_v] < rank[ulp_u]) { - - parent[ulp_v] = ulp_u; - - } - - else { - - parent[ulp_v] = ulp_u; - - rank[ulp_u]++; - - } - - } - - - - void unionBySize(int u, int v) { - - int ulp_u = findUPar(u); - - int ulp_v = findUPar(v); - - if(ulp_u == ulp_v) return; - - if(size[ulp_u] < size[ulp_v]) { - - parent[ulp_u] = ulp_v; - - size[ulp_v] += size[ulp_u]; - - } - - else { - - parent[ulp_v] = ulp_u; - - size[ulp_u] += size[ulp_v]; - - } - - } - - vector> groups() { - - int n = parent.size(); - - vector leader_buf(n), group_size(n); - - - - // Find leaders for each node - - for (int i = 0; i < n; i++) { - - leader_buf[i] = findUPar(i); - - group_size[leader_buf[i]]++; - - } - - - - // Create groups - - vector> result(n); - - for (int i = 0; i < n; i++) { - - result[i].reserve(group_size[i]); - - } - - - - for (int i = 0; i < n; i++) { - - result[leader_buf[i]].push_back(i); - - } - - - - // Remove empty groups - - result.erase( - - remove_if(result.begin(), result.end(), - - [](const vector& v) { return v.empty(); }), - - result.end() - - ); - - - - return result; - - } - -}; - -class Solution - -{ - -public: - - //Function to find sum of weights of edges of the Minimum Spanning Tree. - - int spanningTree(int V, vector> adj[]) - - { - - // 1 - 2 wt = 5 - - /// 1 - > (2, 5) - - // 2 -> (1, 5) - - - - // 5, 1, 2 - - // 5, 2, 1 - - vector>> edges; - - for (int i = 0; i < V; i++) { - - for (auto it : adj[i]) { - - int adjNode = it[0]; - - int wt = it[1]; - - int node = i; - - - - edges.push_back({wt, {node, adjNode}}); - - } - - } - - DisjointSet ds(V); - - sort(edges.begin(), edges.end()); - - int mstWt = 0; - - for (auto it : edges) { - - int wt = it.first; - - int u = it.second.first; - - int v = it.second.second; - - - - if (ds.findUPar(u) != ds.findUPar(v)) { - - mstWt += wt; - - ds.unionBySize(u, v); - - } - - } - - - - return mstWt; - - } - -}; - -void solve(){ - - int n;cin>>n; - - vectorv(n); - - vin(v); - - ll sum=accumulate(v.begin(),v.end(),0); - - sets; - - if(sum%n) - - { - - cout<<""NO""<1) - - { - - debug(v) - - cout<<""NO""<>t; - - while(t--){ - - solve(); - - } - -} ",1 -codecaster,2050B - Transfusion,c++17 ,307567947,307568781,"#include - -#include - -using namespace std; - - - -int ceiling(int a, int b){ - - if (a%b==0) - - return a/b; - - else - - return a/b+1; - -} - - - -void transfusion(vector&arr, int n){ - - for (int i = 1; i arr, int n){ - - for (int i = 1; i> t; - - while(t--){ - - int n; - - cin >> n; - - vector arr(n); - - for (int i = 0; i> arr[i]; - - - - transfusion(arr,n); - - if (!check(arr,n)) - - cout << ""NO"" << endl; - - else - - cout << ""YES"" < - -#include - -using namespace std; - - - -int ceiling(int a, int b){ - - if (a%b==0) - - return a/b; - - else - - return a/b+1; - -} - - - -void transfusion(vector&arr, int n){ - - for (int i = 1; i arr, int n){ - - for (int i = 1; i> t; - - while(t--){ - - int n; - - cin >> n; - - vector arr(n); - - for (int i = 0; i> arr[i]; - - - - transfusion(arr,n); - - if (!check(arr,n)) - - cout << ""NO"" << endl; - - else - - cout << ""YES"" < -using namespace std; - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n; - cin >> n; - vector a(n); - - int sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0; - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - if (i % 2 == 0) - { - sum1 += a[i]; - ctr1++; - } - else - { - sum2 += a[i]; - ctr2++; - } - } - - if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % n == 0) - { - cout << ""YES\n""; - } - else - { - cout << ""NO\n""; - } - } - - return 0; -} -","#include -using namespace std; - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n; - cin >> n; - vector a(n); - - long long sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0; - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - if (i % 2 == 0) - { - sum1 += a[i]; - ctr1++; - } - else - { - sum2 += a[i]; - ctr2++; - } - } - - if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % (ctr1 + ctr2) == 0) - { - cout << ""YES\n""; - } - else - { - cout << ""NO\n""; - } - } - - return 0; -} -",2 -Yeasar,2050B - Transfusion,c++17 ,299592407,299592656,"#include -#define ll long long -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - - ll t; - cin >> t; - while (t--) { - ll n; - cin >> n; - - vector a(n); - for (ll i = 0; i < n; i++) { - cin >> a[i]; - } - - ll odd_sum = 0, even_sum = 0; - - for (ll i = 0; i < n; ++i) { - if (i % 2 == 0) { - even_sum += a[i]; - } else { - odd_sum += a[i]; - } - } - - ll odd_count = n / 2; - ll even_count = (n + 1) / 2; - - if (odd_sum * even_count != even_sum * odd_count) { - cout << ""NO\n""; - } else { - cout << ""YES\n""; - } - } - - return 0; -} -","#include -#define ll long long -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - - ll t; - cin >> t; - while (t--) - { - ll n; - cin >> n; - - vector a(n); - for (ll i = 0; i < n; i++) - { - cin >> a[i]; - } - - ll odd_sum = 0, even_sum = 0; - - for (ll i = 0; i < n; ++i) - { - if (i % 2 == 0) - { - even_sum += a[i]; - } - else - { - odd_sum += a[i]; - } - } - - ll odd_count = n / 2; - ll even_count = (n + 1) / 2; - - if ((odd_sum % odd_count != 0) || (even_sum % even_count != 0) || - (odd_sum / odd_count != even_sum / even_count)) - { - cout << ""NO\n""; - } - else - { - cout << ""YES\n""; - } - } - - return 0; -} -",2 -4Rt801:38,2050B - Transfusion,c++23 ,296003001,296003659,"#include -using namespace std; -#define pb push_back -#define mk make_pair -#define ll long long -#define f first -#define s second -const ll N = 1e5 + 5; -int X[4] = {0, 0, 1, -1}; -int Y[4] = {1, -1, 0, 0}; -#define inf 9223372036854775807 -void solve() -{ - int n; - cin >> n; - vector v; - int sum = 0; - for (int i = 0; i < n; i++) - { - int x; - cin >> x; - v.pb(x); - sum += x; - } - if (sum % n) - { - cout << ""NO"" << endl; - return; - } - sum = sum / n; - for (int i = 1; i < n - 1; i++) - { - if (v[i - 1] > sum) - { - int temp = v[i - 1] - sum; - v[i - 1] -= temp; - v[i + 1] += temp; - } - else - { - int temp = sum - v[i - 1]; - v[i - 1] += temp; - v[i + 1] -= temp; - } - } - if(v[n-1]==sum){ - cout<<""YES""<> t; - while (t--) - { - solve(); - } - return 0; -}","#include -using namespace std; -#define pb push_back -#define mk make_pair -#define ll long long -#define f first -#define s second -const ll N = 1e5 + 5; -int X[4] = {0, 0, 1, -1}; -int Y[4] = {1, -1, 0, 0}; -#define inf 9223372036854775807 -void solve() -{ - ll n; - cin >> n; - vector v; - ll sum = 0; - for (int i = 0; i < n; i++) - { - ll x; - cin >> x; - v.pb(x); - sum += x; - } - if (sum % n) - { - cout << ""NO"" << endl; - return; - } - sum = sum / n; - for (int i = 1; i < n - 1; i++) - { - if (v[i - 1] > sum) - { - ll temp = v[i - 1] - sum; - v[i - 1] -= temp; - v[i + 1] += temp; - } - else - { - ll temp = sum - v[i - 1]; - v[i - 1] += temp; - v[i + 1] -= temp; - } - } - if(v[n-1]==sum){ - cout<<""YES""<> t; - while (t--) - { - solve(); - } - return 0; -}",2 -Nazmul99,2050B - Transfusion,c++17 ,308609587,308606051,"#include - -#define fast \ - - ios::sync_with_stdio(false); \ - - cin.tie(nullptr) - -#define ll long long - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - ll k = 0, d, n, sum = 0; - - bool flag = true; - - cin >> n; - - vector A(n); - - for (int i = 0; i < n; i++) - - cin >> A[i]; - - for (int i = 0; i < n; i++) - - sum += A[i]; - - - - if (sum % n != 0) - - flag = false; - - else - - { - - d = sum / n; - - for (int i = 1; i < n - 1; i++) - - { - - if (A[i - 1] < d && A[i - 1] > 0) - - { - - k = d - A[i - 1]; - - A[i + 1] = A[i + 1] - k; - - A[i - 1] = d; - - } - - else - - { - - k = A[i - 1] - d; - - A[i + 1] = A[i + 1] + k; - - A[i - 1] = d; - - } - - } - - } - - for (int j = 0; j < n; j++) - - if (A[j] != d) - - flag = false; - - cout << (flag ? ""YES"" : ""NO"") << endl; - - } - - - - return 0; - -}","#include - -#define fast \ - - ios::sync_with_stdio(false); \ - - cin.tie(nullptr) - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int k = 0, d, n, sum = 0; - - bool flag = true; - - cin >> n; - - vector A(n); - - for (int i = 0; i < n; i++) - - cin >> A[i]; - - for (int i = 0; i < n; i++) - - sum += A[i]; - - - - if (sum % n != 0) - - flag = false; - - else - - { - - d = sum / n; - - for (int i = 1; i < n - 1; i++) - - { - - if (A[i - 1] < d && A[i - 1] > 0) - - { - - k = d - A[i - 1]; - - A[i + 1] = A[i + 1] - k; - - A[i - 1] = d; - - } - - else - - { - - k = A[i - 1] - d; - - A[i + 1] = A[i + 1] + k; - - A[i - 1] = d; - - } - - } - - } - - for (int j = 0; j < n; j++) - - if (A[j] != d) - - flag = false; - - cout << (flag ? ""YES"" : ""NO"") << endl; - - } - - - - return 0; - -}",1 -floatingmemories,2050B - Transfusion,c++23 ,308936272,308936548,"#include - -using namespace std; - -const int N = 2e5+10; - -//const int N = 100; - -long long l[N]; - -int main(){ - - long long ec, iec, n, i, dist; - - bool flag; - - long long sum; - - scanf(""%lld"", &ec); - - for(iec=0; iec - -using namespace std; - -const int N = 2e5+10; - -//const int N = 100; - -long long l[N]; - -int main(){ - - long long ec, iec, n, i, dist; - - bool flag; - - long long sum; - - scanf(""%lld"", &ec); - - for(iec=0; iec -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int n; - cin >> n; - - for (int i = 0; i < n; i++) { - int seq_len; cin >> seq_len; - int odd_sum = 0; - int even_sum = 0; - int odd_seq_len = (seq_len / 2) + (seq_len % 2); - int even_seq_len = (seq_len / 2); - for (int j = 0; j < seq_len; j++) { - int val; - cin >> val; - if (j % 2 == 0) { - odd_sum += val; - } - else even_sum += val; - } - int desired = (odd_sum + even_sum) / seq_len; - if (odd_sum / odd_seq_len == desired && even_sum / even_seq_len == desired && odd_sum % odd_seq_len == 0 && even_sum % even_seq_len == 0) { - cout << ""YES\n""; - } - else cout << ""NO\n""; - } -} - -","#include -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int n; - cin >> n; - - for (int i = 0; i < n; i++) { - int seq_len; cin >> seq_len; - long long odd_sum = 0; - long long even_sum = 0; - int odd_seq_len = (seq_len / 2) + (seq_len % 2); - int even_seq_len = (seq_len / 2); - for (int j = 0; j < seq_len; j++) { - int val; - cin >> val; - if (j % 2 == 0) { - odd_sum += val; - } - else even_sum += val; - } - long long desired = (odd_sum + even_sum) / seq_len; - if (odd_sum / odd_seq_len == desired && even_sum / even_seq_len == desired && odd_sum % odd_seq_len == 0 && even_sum % even_seq_len == 0) { - cout << ""YES\n""; - } - else cout << ""NO\n""; - } -} - -",2 -harshitahl2006,2050B - Transfusion,python,308736994,308739650,"t = int(input()) - -for i in range(t): - - n = int(input()) - - inputs = list(map(int, input().split())) - - even_sum = 0 - - odd_sum = 0 - - for i in range(n): - - if i%2 == 0: - - even_sum += inputs[i] - - else: - - odd_sum += inputs[i] - - if n%2 == 1: - - if even_sum/(n//2+1) == odd_sum*(n-n//2-1): - - print(""YES"") - - else: - - print(""NO"") - - else: - - if even_sum/(n//2) == odd_sum*(n-n//2): - - print(""YES"") - - else: - - print(""NO"")","t = int(input()) - -for i in range(t): - - n = int(input()) - - inputs = list(map(int, input().split())) - - even_sum = 0 - - odd_sum = 0 - - for i in range(n): - - if i%2 == 0: - - even_sum += inputs[i] - - else: - - odd_sum += inputs[i] - - if n%2 == 0: - - even = odd = n/2 - - else: - - even = n//2+1 - - odd = n - even - - if even_sum/even == int(even_sum/even) and odd_sum/odd == int(odd_sum/odd): - - if even_sum/even == odd_sum/odd: - - print(""YES"") - - else: - - print(""NO"") - - else: - - print(""NO"") - - ",2 -Sakamoto_11,2050B - Transfusion,c++17 ,308912805,308912068,"#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - long long int n; - - cin>>n; - - vectorritik(n); - - for(int i=0;i>ritik[i]; - - long long int sum_o=0,sum_e=0; - - long long int c1=0,c2=0; - - for(int i=0;i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vectorritik(n); - - for(int i=0;i>ritik[i]; - - int sum_o=0,sum_e=0; - - int c1=0,c2=0; - - for(int i=0;i - -using namespace std; - -#define ll long long - -signed solve() - -{ - - ll n; - - cin>>n; - - vector arr(n); - - ll sum=0; - - ll odd_sum=0,odd_cnt=0; - - ll eve_sum=0,eve_cnt=0; - - for(int i=0;i>arr[i]; - - sum+=arr[i]; - - if(i%2==0) - - { - - eve_sum+=arr[i]; - - eve_cnt++; - - } - - else - - { - - odd_sum+=arr[i]; - - odd_cnt++; - - } - - } - - if(sum%n==0) - - { - - ll eve_avg=eve_sum/eve_cnt; - - ll odd_avg=odd_sum/odd_cnt; - - if(eve_avg==odd_avg) - - { - - cout<<""YES""<>t; - - //t=1; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -#define ll long long - -signed solve() - -{ - - ll n; - - cin>>n; - - vector arr(n); - - ll sum=0; - - for(int i=0;i>arr[i]; - - sum+=arr[i]; - - } - - if(sum%n==0) - - { - - ll ans=sum/n; - - for(int i=0;i>t; - - //t=1; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",1 -cosmicbust,2050B - Transfusion,c++17 ,308826778,308826945,"#include - -using namespace std; - - - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vector vec(n); - - int sum = 0; - - for (int i = 0; i < n; i++) - - { - - cin>>vec[i]; - - sum += vec[i]; - - } - - if(sum%n != 0){cout<<""NO""< - -using namespace std; - - - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vector vec(n); - - long long sum = 0; - - for (int i = 0; i < n; i++) - - { - - cin>>vec[i]; - - sum += vec[i]; - - } - - if(sum%n != 0){cout<<""NO""< - -using namespace std; - -#define all(v) v.begin(), v.end() -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define ll long long -#define ld long double -#define fr(i, n) for (int i = 0; i < n; i++) -#define vi vector -#define pii pair -#define mii map -#define pb push_back -#define int long long -#define endl ""\n"" - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vi a(n); - fr(i, n) cin >> a[i]; - int x = 0; - int b = 0; - int y = 0; - int z = 0; - for (int i = 0; i < n; i++) - { - if (i % 2 == 0) - { - x += a[i]; - y++; - } - else - { - b += a[i]; - z++; - } - } - if (x / y == b / z && x % y == 0 && b % z == 0) - { - cout << ""YES"" << endl; - } - else - { - cout << ""NO"" << endl; - } - } - return 0; -}","#include - -using namespace std; - -#define all(v) v.begin(), v.end() -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define ll long long -#define ld long double -#define fr(i, n) for (int i = 0; i < n; i++) -#define vi vector -#define pii pair -#define mii map -#define pb push_back -#define int long long -#define endl ""\n"" - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vi a(n); - fr(i, n) cin >> a[i]; - if (a[0] < a[1] && a[1] < a[2]) - { - cout << ""yes"" << endl; - } - else if (a[0] > a[1] && a[1] > a[2]) - { - cout << ""yes"" << endl; - } - else - { - cout << ""no"" << endl; - } - } - return 0; -}",1 -garvahuja15,2050B - Transfusion,c++17 ,308289194,308289642,"#include - -#include - -using namespace std; - - - -void Solve(){ - - int n; - - cin>>n; - - vector vec(n); - - int sodd=0,seven=0,countodd=0,counteven=0; - - for(int i=0;i>vec[i]; - - if(i%2==0){ - - sodd+=vec[i]; - - countodd+=1; - - } - - else{ - - seven+=vec[i]; - - counteven+=1; - - } - - } - - if(seven*countodd==sodd*counteven && (seven+sodd)%(countodd+counteven)==0){ - - cout<<""YES""<>t; - - while(t--){ - - Solve(); - - } - - return 0; - -}","#include - -#include - -using namespace std; - - - -void Solve(){ - - int n; - - cin>>n; - - vector vec(n); - - long long sodd=0,seven=0,countodd=0,counteven=0; - - for(int i=0;i>vec[i]; - - if(i%2==0){ - - sodd+=vec[i]; - - countodd++; - - } - - else{ - - seven+=vec[i]; - - counteven++; - - } - - } - - if((seven*countodd)==(sodd*counteven) && ((seven+sodd)%(countodd+counteven))==0){ - - cout<<""YES""<>t; - - while(t--){ - - Solve(); - - } - - return 0; - -}",2 -ForestPrefix,2050B - Transfusion,c++17 ,307389538,307389648,"#include - -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--){ - int n; - cin >> n; - int a[n]; - int s = 0; - for (int i=0; i> a[i]; - s += a[i]; - } - if (s%n){ - cout << ""NO"" << endl; - continue; - } - s /= n; - string ans = ""YES""; - for (int i=1; i - -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--){ - int n; - cin >> n; - long long int a[n]; - long long int s = 0; - for (int i=0; i> a[i]; - s += a[i]; - } - if (s%n){ - cout << ""NO"" << endl; - continue; - } - s /= n; - string ans = ""YES""; - for (int i=1; i - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int n; - - cin >> n; - - double ji = 0; - - int cnt_ji = 0; - - double ou = 0; - - int cnt_ou = 0; - - for (int i = 0; i < n; i++) - - { - - int now; - - cin >> now; - - if (i % 2 == 0) - - { - - ji += now; - - cnt_ji++; - - } - - else - - { - - ou += now; - - cnt_ou++; - - } - - } - - double a = ou / cnt_ou; - - double b = ji / cnt_ji; - - int A = a; - - int B = b; - - if (a == b&&a-A==0&&b-B==0) - - { - - cout << ""YES"" << endl; - - } - - else - - { - - cout << ""NO"" << endl; - - } - - - - } - - - -}","#include - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - int n; - - cin >> n; - - double ji = 0; - - int cnt_ji = 0; - - double ou = 0; - - int cnt_ou = 0; - - for (int i = 0; i < n; i++) - - { - - int now; - - cin >> now; - - if (i % 2 == 0) - - { - - ji += now; - - - - } - - else - - { - - ou += now; - - - - } - - } - - - - if (n % 2 == 0) - - { - - cnt_ou = n / 2; - - cnt_ji = n / 2; - - } - - else - - { - - cnt_ou = n / 2; - - cnt_ji = n / 2+1; - - } - - - - double a = ou / cnt_ou; - - double b = ji / cnt_ji; - - int A = a; - - int B = b; - - if (a == b&&a-A==0&&b-B==0) - - { - - cout << ""YES"" << endl; - - } - - else - - { - - cout << ""NO"" << endl; - - } - - - - } - - - -}",2 -Harshuu_007,2050B - Transfusion,c++17 ,305944821,305944920,"#include - -using namespace std; - - - -void solve() { - - int n; cin>> n; - - int sumodd =0, sumeven = 0; - - - - for(int i =0;i< n;i++){ - - int u; cin>> u; - - - - if(i&1){ - - sumodd += u; - - } - - else sumeven += u; - - } - - - - int oddsize = n/2 + (n&1); - - int evensize = n/2; - - - - if((sumodd%evensize) != 0 || (sumeven% oddsize) != 0 ) { - - cout<< ""NO""<< endl; - - return; - - - - } - - if((sumodd/evensize) == (sumeven/oddsize)){ - - cout<<""YES""<< endl; - - } - - else cout<<""NO""<< endl; - - - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - - - -void solve() { - - int n; cin>> n; - - long long int sumodd =0, sumeven = 0; - - - - for(int i =0;i< n;i++){ - - int u; cin>> u; - - - - if(i&1){ - - sumodd += u; - - } - - else sumeven += u; - - } - - - - int oddsize = n/2 + (n&1); - - int evensize = n/2; - - - - if((sumodd%evensize) != 0 || (sumeven% oddsize) != 0 ) { - - cout<< ""NO""<< endl; - - return; - - - - } - - if((sumodd/evensize) == (sumeven/oddsize)){ - - cout<<""YES""<< endl; - - } - - else cout<<""NO""<< endl; - - - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -} - -",2 -EmmanuelRojas,2050B - Transfusion,c++20 ,307610675,307611765,"#include - -using namespace std; - -void solve(){ - - int n; - - cin>>n; - - vectora(n); - - for(int i=0;i>a[i]; - - } - - bool flag=true; - - for(int i=1;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -void solve(){ - - int n; - - cin>>n; - - vectora(n); - - - - for(int i=0;i>a[i]; - - - - } - - bool flag=true; - - if(a[0]==a[n-1]){ - - flag=false; - - - - } - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -L_U_N_A,2050B - Transfusion,c++23 ,299550289,299550527,"#include -typedef long long ll; -using namespace std; -int main() -{ - int t; - cin>>t; - while(t--) - { - int n; - cin>>n; - vectorvec(n); - ll sum=0,d,b; - - for(int i=0; i>vec[i]; - sum+=vec[i]; - } - if(sum%n!=0) - cout<<""NO""<=0; --a) - { - if(vec[a+1]>d) - { - b=vec[a+1]-d; - vec[a+1]=d; - vec[a-1]+=b; - } - else if(vec[a+1] -typedef long long ll; -using namespace std; -int main() -{ - int t; - cin>>t; - while(t--) - { - int n; - cin>>n; - vectorvec(n); - ll sum=0,d,b; - - for(int i=0; i>vec[i]; - sum+=vec[i]; - } - if(sum%n!=0) - cout<<""NO""<0; --a) - { - if(vec[a+1]>d) - { - b=vec[a+1]-d; - vec[a+1]=d; - vec[a-1]+=b; - } - else if(vec[a+1] - -#include - -using namespace std; - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vector arr(n); - - int seven=0; - - int sodd=0; - - for(int i=0;i>arr[i]; - - if(i%2){ - - sodd+=arr[i]; - - } - - else{ - - seven+=arr[i]; - - } - - } - - if(seven% (n-n/2) !=0 && sodd%n/2!=0){ - - cout<<""NO""< - -#include - -using namespace std; - -int main() { - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - vector arr(n); - - long long seven=0; - - long long sodd=0; - - for(int i=0;i>arr[i]; - - if((i+1)%2==1){ - - sodd+=arr[i]; - - } - - else{ - - seven+=arr[i]; - - } - - } - - if(seven% (n/2) != 0 || sodd%(n-n/2)!=0){ - - cout<<""NO""< - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - long long n; - - cin>>n; - - long long arr[n]; - - for(int i = 0 ; i>arr[i];} - - long long sum1 = 0, sum2 =0 ,odd = 0,even = 0; - - for(long long i =0; i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - int n; - - cin>>n; - - int arr[n]; - - for(int i = 0 ; i>arr[i];} - - int sum1 = 0, sum2 =0 ,odd = 0,even = 0; - - for(int i =0; i - -int main(){ - int t; - std::cin>>t; - while(t--){ - int n; - std::cin>>n; - int arr[n]; - for(int j=0;j>arr[j]; - } - long long odd=0; - long long even=0; - for(int i=0;i - -int main(){ - int t; - std::cin>>t; - while(t--){ - int n; - std::cin>>n; - int arr[n]; - for(int j=0;j>arr[j]; - } - int odd=0; - int even=0; - for(int i=0;i -#define int long long -using namespace std; -int t; -int n; -const int maxn=2e5+5; -int a[maxn]; -signed main(){ - cin>>t; - while(t--){ - cin>>n; - for(int i=1;i<=n;i++) cin>>a[i]; - int ans=0,sum=0; - for(int i=1;i<=n;i+=2) - ans+=a[i]; - for(int i=2;i<=n;i+=2) - sum+=a[i]; - if(n%2==0){ - if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<""NO""< -using namespace std; -int main() { - int N; - cin >> N; - for (int i = 0; i < N; i++) { - int n; - cin >> n; - int a[n + 2]={}; - int sum[n + 2]={}; - int sum1[n + 2]={}; - int sum2[n + 2]={}; - for (int j = 0; j < n; j++) { - cin >> a[j]; - } - sum[0] = a[0]; - sum1[0] = a[0]; - sum2[1] = a[1]; - for (int j = 1; j < n; j++) { - sum[j] += sum[j - 1] + a[j]; - cout< check if the element is present in the array or not - findInd => finds index from the array. - - */ - -// class name should be changed as required -public class Main { - private static final int MOD = (int)(1e9 + 7); - private static final int INF = (int)(1e9); - private static int[] seive; - // private static List> setSeive; - // if testcases are set to 1 then only one test will be dont else testcases will be taken as input - private static int TOTAL_TESTCASES = -1; - - static void solve(Reader r,PrintWriter out,int testcase) throws IOException { - int n = r.nextInt(); - int[] arr = r.readArr(n); - - int sumo = 0; - int sume = 0; - int poso = 0; - int pose = 0; - - for(int i = 0;i Long.compare(b, a)); - return Arrays.stream(boxedArray).mapToLong(Long::longValue).toArray(); - } - public static int[] sortDesc(int[] array) { - Integer[] boxedArray = Arrays.stream(array).boxed().toArray(Integer[]::new); - Arrays.sort(boxedArray, (a, b) -> b - a); - return Arrays.stream(boxedArray).mapToInt(Integer::intValue).toArray(); - } - - // sorts treemap by values - public static > LinkedHashMap sortByValues(Map map) { - List> entryList = new ArrayList<>(map.entrySet()); - entryList.sort(Map.Entry.comparingByValue()); - LinkedHashMap sortedMap = new LinkedHashMap<>(); - for (Map.Entry entry : entryList) { - sortedMap.put(entry.getKey(), entry.getValue()); - } - return sortedMap; - } - - static int binarySearch(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - // here in if we have the monotonic function this should be designed such that we get the first one as ans in a monotonic array represetation - if(arr[mid] == ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - - // gives first value >= x - static int lowerBound(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - if(arr[mid] >= ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - // gives first element > x - static int uppperBound(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - if(arr[mid] > ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - static int toInt(char c){ - return Integer.parseInt(Character.toString(c)); - } - - // join list of items - static String joinList(List list, String delimiter) { - if (list == null || list.isEmpty()) { - return """"; - } - - return list.stream() - .map(String::valueOf) - .collect(Collectors.joining(delimiter)); - } - - // is the number prime - static boolean isPrime(int n){ - if(n == 1) return false; - if(n == 2 || n == 3) return true; - if((n % 2) == 0 || (n % 3) == 0) return false; - - for(int i = 5;i*i<=n;i=i+6){ - if((n%i) == 0 || (n%(i+2)) == 0) return false; - } - return true; - } - - // gcd of the number - static long gcd(long a, long b){ - if(a==0) return b; - else return gcd(b%a,a); - } - - //extended gcd (gets a solution for ax + by = c ) - - public static int exGcd(int a, int b, int[] result) { - if (b == 0) { - result[0] = 1; // x - result[1] = 0; // y - return a; // gcd(a, 0) = a - } - - int[] tempResult = new int[2]; - int gcd = exGcd(b, a % b, tempResult); - // Update x and y using results of recursion - result[0] = tempResult[1]; - result[1] = tempResult[0] - (a / b) * tempResult[1]; - - return gcd; - } - static long facc(int n){ - if(n <= 2){ - return 2; - } - int[] arr = new int[n+1]; - arr[1] = 1; - arr[2] = 2; - for(int i = 3;i<=n;i++){ - arr[i] = arr[i-1]*i; - } - - return arr[n]; - } - - - // Fast power using binary exponiantian - static int power(int a,int b){ - if(b == 0){ - return 1; - } - int half_pow = power(a , b/2); - if(a % 2 == 0){ - return half_pow * half_pow; - }else return half_pow * half_pow + a; - } - - // calculates the lcm of the given number - static long lcm(long a, long b){ - return (a*b)/gcd(a,b); - } - - //TC - n logx - static void calcSeive(int n){ - seive = new int[n+1]; - for(int i = 2;i<=n;i++){ - if(seive[i] != 0) continue; // skipping non prime numbers - for(int j = 2*i;j<=n;j+=i){ - seive[j]++; - } - } - } - - // till permutations are possible it permutes the passed list else return false; - private static boolean nextPermutation(List perm) { - int n = perm.size(); - int i = n - 2; - while (i >= 0 && perm.get(i) >= perm.get(i + 1)) { - i--; - } - if (i < 0) - return false; - - int j = n - 1; - while (perm.get(j) <= perm.get(i)) { - j--; - } - Collections.swap(perm, i, j); - Collections.reverse(perm.subList(i + 1, n)); - return true; - } - - public static List getFactors(long number) { - if (number <= 0) { - return Collections.emptyList(); - } - - List factors = new ArrayList<>(); - - for(long i = 2; (long) i *i <= number; i++){ - while(number % i == 0){ - factors.add(i); - number /= i; - } - } - if(number != 1){ - factors.add(number); - } - return factors; - } - - static void debug(int[] a,String... identifier){ - PrintWriter out = new PrintWriter(System.out); - out.println( (""debug : "") + Arrays.toString(a)); - out.flush(); - } - - // is the number palindrome - public static boolean isPal(String str1){ - int i = 0; - int j = str1.length()-1; - - while(i<=j){ - if(str1.charAt(i) != str1.charAt(j)){ - return false; - } - i++; - j--; - } - - return true; - } - - static String sort(String str){ - char[] arr = str.toCharArray(); - Arrays.sort(arr); - return new String(arr); - } - - static void print(List ls ) throws IOException{ - PrintWriter out = new PrintWriter(System.out); - for(int i : ls){ - out.print(i + "" ""); - } - out.println(); - out.flush(); - - } - - static void print(T[] arr ) throws IOException{ - PrintWriter out = new PrintWriter(System.out); - - for(T i : arr){ - out.print(i + "" ""); - } - out.println(); - out.flush(); - } - - static String revStr(String str){ - StringBuilder sb = new StringBuilder(""""); - - for(int i = str.length()-1;i>=0;i--){ - sb.append(str.charAt(i)); - } - - return sb.toString(); - } - - static class Reader { - BufferedReader in; StringTokenizer st; - public Reader() throws IOException { - in = new BufferedReader(new InputStreamReader(System.in)); - st = new StringTokenizer(""""); - } - public boolean hasNextLine() throws IOException { - return in.ready(); - } - public String nextLine() throws IOException { - st = new StringTokenizer(""""); - return in.readLine(); - } - public String next() throws IOException { - while (!st.hasMoreTokens()) - st = new StringTokenizer(in.readLine()); - return st.nextToken(); - } - public int nextInt() throws IOException { - return Integer.parseInt(next()); - } - public long nextLong() throws IOException { - return Long.parseLong(next()); - } - public double nextDouble() throws IOException { - return Double.parseDouble(next()); - } - - public int[] readArr(int n) throws IOException{ - int[] arr = new int[n]; - int i = 0; - while(i list = new ArrayList<>(); - for (int i : arr) list.add(i); - Collections.sort(list); - for (int i = 0; i < arr.length; i++) - arr[i] = list.get(i); - } - - public static class Pair{ - public K key; - public V val; - public Pair(K _key,V _val){ - this.key = _key; - this.val = _val; - } - - @Override - public String toString() { - return ""{"" + - key + - "","" + val + - '}'; - } - } -} -","import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.*; -import java.util.Collections.*; -import java.util.logging.Logger; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.lang.Math.*; - - -// can use min max abs directly - -// my code -// methods -/* - - min - max - abs - findEle => check if the element is present in the array or not - findInd => finds index from the array. - - */ - -// class name should be changed as required -public class Main { - private static final int MOD = (int)(1e9 + 7); - private static final int INF = (int)(1e9); - private static int[] seive; - // private static List> setSeive; - // if testcases are set to 1 then only one test will be dont else testcases will be taken as input - private static int TOTAL_TESTCASES = -1; - - static void solve(Reader r,PrintWriter out,int testcase) throws IOException { - int n = r.nextInt(); - int[] arr = r.readArr(n); - - long sumo = 0; - long sume = 0; - int poso = 0; - int pose = 0; - - for(int i = 0;i Long.compare(b, a)); - return Arrays.stream(boxedArray).mapToLong(Long::longValue).toArray(); - } - public static int[] sortDesc(int[] array) { - Integer[] boxedArray = Arrays.stream(array).boxed().toArray(Integer[]::new); - Arrays.sort(boxedArray, (a, b) -> b - a); - return Arrays.stream(boxedArray).mapToInt(Integer::intValue).toArray(); - } - - // sorts treemap by values - public static > LinkedHashMap sortByValues(Map map) { - List> entryList = new ArrayList<>(map.entrySet()); - entryList.sort(Map.Entry.comparingByValue()); - LinkedHashMap sortedMap = new LinkedHashMap<>(); - for (Map.Entry entry : entryList) { - sortedMap.put(entry.getKey(), entry.getValue()); - } - return sortedMap; - } - - static int binarySearch(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - // here in if we have the monotonic function this should be designed such that we get the first one as ans in a monotonic array represetation - if(arr[mid] == ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - - // gives first value >= x - static int lowerBound(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - if(arr[mid] >= ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - // gives first element > x - static int uppperBound(int[] arr,int ele){ - int n = arr.length; - int l = 0; - int r = n-1; - - int ans = -1; - - while(l <= r){ - int mid = l + (r-l)/2; - - if(arr[mid] > ele){ - ans = mid; - r = mid-1; - }else{ - l = mid+1; - } - } - return ans; - } - - static int toInt(char c){ - return Integer.parseInt(Character.toString(c)); - } - - // join list of items - static String joinList(List list, String delimiter) { - if (list == null || list.isEmpty()) { - return """"; - } - - return list.stream() - .map(String::valueOf) - .collect(Collectors.joining(delimiter)); - } - - // is the number prime - static boolean isPrime(int n){ - if(n == 1) return false; - if(n == 2 || n == 3) return true; - if((n % 2) == 0 || (n % 3) == 0) return false; - - for(int i = 5;i*i<=n;i=i+6){ - if((n%i) == 0 || (n%(i+2)) == 0) return false; - } - return true; - } - - // gcd of the number - static long gcd(long a, long b){ - if(a==0) return b; - else return gcd(b%a,a); - } - - //extended gcd (gets a solution for ax + by = c ) - - public static int exGcd(int a, int b, int[] result) { - if (b == 0) { - result[0] = 1; // x - result[1] = 0; // y - return a; // gcd(a, 0) = a - } - - int[] tempResult = new int[2]; - int gcd = exGcd(b, a % b, tempResult); - // Update x and y using results of recursion - result[0] = tempResult[1]; - result[1] = tempResult[0] - (a / b) * tempResult[1]; - - return gcd; - } - static long facc(int n){ - if(n <= 2){ - return 2; - } - int[] arr = new int[n+1]; - arr[1] = 1; - arr[2] = 2; - for(int i = 3;i<=n;i++){ - arr[i] = arr[i-1]*i; - } - - return arr[n]; - } - - - // Fast power using binary exponiantian - static int power(int a,int b){ - if(b == 0){ - return 1; - } - int half_pow = power(a , b/2); - if(a % 2 == 0){ - return half_pow * half_pow; - }else return half_pow * half_pow + a; - } - - // calculates the lcm of the given number - static long lcm(long a, long b){ - return (a*b)/gcd(a,b); - } - - //TC - n logx - static void calcSeive(int n){ - seive = new int[n+1]; - for(int i = 2;i<=n;i++){ - if(seive[i] != 0) continue; // skipping non prime numbers - for(int j = 2*i;j<=n;j+=i){ - seive[j]++; - } - } - } - - // till permutations are possible it permutes the passed list else return false; - private static boolean nextPermutation(List perm) { - int n = perm.size(); - int i = n - 2; - while (i >= 0 && perm.get(i) >= perm.get(i + 1)) { - i--; - } - if (i < 0) - return false; - - int j = n - 1; - while (perm.get(j) <= perm.get(i)) { - j--; - } - Collections.swap(perm, i, j); - Collections.reverse(perm.subList(i + 1, n)); - return true; - } - - public static List getFactors(long number) { - if (number <= 0) { - return Collections.emptyList(); - } - - List factors = new ArrayList<>(); - - for(long i = 2; (long) i *i <= number; i++){ - while(number % i == 0){ - factors.add(i); - number /= i; - } - } - if(number != 1){ - factors.add(number); - } - return factors; - } - - static void debug(int[] a,String... identifier){ - PrintWriter out = new PrintWriter(System.out); - out.println( (""debug : "") + Arrays.toString(a)); - out.flush(); - } - - // is the number palindrome - public static boolean isPal(String str1){ - int i = 0; - int j = str1.length()-1; - - while(i<=j){ - if(str1.charAt(i) != str1.charAt(j)){ - return false; - } - i++; - j--; - } - - return true; - } - - static String sort(String str){ - char[] arr = str.toCharArray(); - Arrays.sort(arr); - return new String(arr); - } - - static void print(List ls ) throws IOException{ - PrintWriter out = new PrintWriter(System.out); - for(int i : ls){ - out.print(i + "" ""); - } - out.println(); - out.flush(); - - } - - static void print(T[] arr ) throws IOException{ - PrintWriter out = new PrintWriter(System.out); - - for(T i : arr){ - out.print(i + "" ""); - } - out.println(); - out.flush(); - } - - static String revStr(String str){ - StringBuilder sb = new StringBuilder(""""); - - for(int i = str.length()-1;i>=0;i--){ - sb.append(str.charAt(i)); - } - - return sb.toString(); - } - - static class Reader { - BufferedReader in; StringTokenizer st; - public Reader() throws IOException { - in = new BufferedReader(new InputStreamReader(System.in)); - st = new StringTokenizer(""""); - } - public boolean hasNextLine() throws IOException { - return in.ready(); - } - public String nextLine() throws IOException { - st = new StringTokenizer(""""); - return in.readLine(); - } - public String next() throws IOException { - while (!st.hasMoreTokens()) - st = new StringTokenizer(in.readLine()); - return st.nextToken(); - } - public int nextInt() throws IOException { - return Integer.parseInt(next()); - } - public long nextLong() throws IOException { - return Long.parseLong(next()); - } - public double nextDouble() throws IOException { - return Double.parseDouble(next()); - } - - public int[] readArr(int n) throws IOException{ - int[] arr = new int[n]; - int i = 0; - while(i list = new ArrayList<>(); - for (int i : arr) list.add(i); - Collections.sort(list); - for (int i = 0; i < arr.length; i++) - arr[i] = list.get(i); - } - - public static class Pair{ - public K key; - public V val; - public Pair(K _key,V _val){ - this.key = _key; - this.val = _val; - } - - @Override - public String toString() { - return ""{"" + - key + - "","" + val + - '}'; - } - } -} -",2 -NUSUR,2050B - Transfusion,c++23 ,295999139,299544855,"#include -using namespace std; - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n; - cin >> n; - vector a(n); - float sum_even = 0, sum_odd = 0, count_even = 0, count_odd = 0; - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - if (i % 2 == 0) - { - sum_even += a[i]; - count_even++; - } - else - { - sum_odd += a[i]; - count_odd++; - } - } - - float avg_even = sum_even / count_even; - float avg_odd = sum_odd / count_odd; - - if (fmod(avg_even, 2) != 0 || fmod(avg_odd, 2) != 0) - { - cout << ""NO"" << endl; - } - else if (count_even == 0 || count_odd == 0 || avg_even != avg_odd) - { - cout << ""NO"" << endl; - } - else - { - cout << ""YES"" << endl; - } - } - - return 0; -} -","#include -using namespace std; - -void solve(int t) { - while (t--) { - int n; - cin >> n; - vector v(n); - long long oddSum = 0, evenSum = 0, oddCount = 0, evenCount = 0; - - for (int i = 0; i < n; i++) { - cin >> v[i]; - if (i % 2 == 0) { - oddSum += v[i]; - oddCount++; - } else { - evenSum += v[i]; - evenCount++; - } - } - - bool isValid = false; - - if (oddSum % oddCount == 0 && evenSum % evenCount == 0) { - if (oddSum / oddCount == evenSum / evenCount) { - isValid = true; - } - } - - cout << (isValid ? ""YES"" : ""NO"") << endl; - } -} - -int main() { - int t; - cin >> t; - solve(t); - return 0; -} -",2 -aakarsh-2004,2050B - Transfusion,c++23 ,308606187,308608624,"#include - - - -using namespace std; - - - -typedef vector vi; - -typedef vector vll; - -typedef vector> vpair; - -typedef long long ll; - -typedef long double lld; - -typedef pair pll; - -typedef vector> vvi; - -typedef vector> vvl; - - - - - -#define f(i, n) for(int i=0; i> n; - - - - vll a(n); - - f(i, n) cin >> a[i]; - - - - for(int i=1; i0) { - - a[i-1]+=diff/2; - - a[i+1]-=diff/2; - - } - - else { - - a[i-1]-=(abs(diff)+1)/2; - - a[i+1]+=(abs(diff)+1)/2; - - } - - } - - - - for(int i=0; i>t; - - while(t--) { - - solve(); - - } - - - - return 0; - -}","#include - - - -using namespace std; - - - -typedef vector vi; - -typedef vector vll; - -typedef vector> vpair; - -typedef long long ll; - -typedef long double lld; - -typedef pair pll; - -typedef vector> vvi; - -typedef vector> vvl; - - - - - -#define f(i, n) for(int i=0; i> n; - - - - ll odds=0, evens=0, oddSum=0, evenSum=0; - - f(i, n) { - - ll x; - - cin >> x; - - if(i&1) { - - odds++; - - oddSum+=x; - - } - - else { - - evens++; - - evenSum+=x; - - } - - } - - - - if(oddSum%odds==0 && evenSum%evens==0 && oddSum/odds==evenSum/evens) { - - cout << ""Yes\n""; - - } - - else { - - cout << ""No\n""; - - } - -} - - - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(NULL); - - - - ll t=1; - - cin>>t; - - while(t--) { - - solve(); - - } - - - - return 0; - -}",2 -Aakash19971,2050C - Uninteresting Number,c++23 ,298637060,298634430,"#include - #include - #include - #include - using namespace std; - typedef long long ll; - typedef vector vi; - typedef vector vll; - #define cy() cout << ""YES"" << '\n' - #define cn() cout << ""NO"" << '\n' - const double pi= 3.14159265358979323846; - - // Function to check if an integer is prime or not - bool isprime(ll n){ - if(n<2){ - return false; - } - for(ll i = 2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; - } - bool pointscompare(pair &a ,pair &b){ - return a.second>b.second; - } - bool goaldiffcompare(pair &a , pair &b){ - return a.second>b.second; - } - bool cmp(pair& a, - pair& b) - { - return a.second < b.second; - } - bool isSorted(const std::vector& arr) { - for (size_t i = 1; i < arr.size(); ++i) { - if (arr[i] < arr[i - 1]) { - return false; - } - } - return true; - } - - void solve(){ - // ............................... - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - string s; - cin >> s; - int sum = 0; - int two = 0; - int three = 0; - - for(int i = 0;i v; - if(sum%9!=0){ - - - for(int i = 0;i<=min(8,two);i++){ - for(int j = 0;j<=min(8,three);j++){ - v.insert(2*i + 6*j); - } - } - for(auto x : v){ - // cout << x.first.first << "" "" << x.first.second << "" "" << x.second << ' ' << sum%9 << '\n'; - } - bool p = false; - for(auto x : v){ - if((sum+x)%9==0){ - cout << ""YES"" << '\n'; - p = true; - break; - } - } - if(!p){ - cout << ""NO"" << '\n'; - } - }else{ - cout << ""YES"" << '\n'; - } - } - int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - std::cout.tie(0); - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - int tt; - cin >> tt; - while(tt--){ - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - auto t1 = high_resolution_clock::now(); - solve(); - auto t2 = high_resolution_clock::now(); - auto ms_int = duration_cast(t2 - t1); - duration ms_double = t2 - t1; - // std::cout << ms_double.count() << ""ms\n""; - } - return 0; - } ","#include - #include - #include - #include - using namespace std; - typedef long long ll; - typedef vector vi; - typedef vector vll; - #define cy() cout << ""YES"" << '\n' - #define cn() cout << ""NO"" << '\n' - const double pi= 3.14159265358979323846; - - // Function to check if an integer is prime or not - bool isprime(ll n){ - if(n<2){ - return false; - } - for(ll i = 2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; - } - bool pointscompare(pair &a ,pair &b){ - return a.second>b.second; - } - bool goaldiffcompare(pair &a , pair &b){ - return a.second>b.second; - } - bool cmp(pair& a, - pair& b) - { - return a.second < b.second; - } - bool isSorted(const std::vector& arr) { - for (size_t i = 1; i < arr.size(); ++i) { - if (arr[i] < arr[i - 1]) { - return false; - } - } - return true; - } - - void solve(){ - // ............................... - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - string s; - cin >> s; - int sum = 0; - int two = 0; - int three = 0; - - for(int i = 0;i v; - for(int i = 0;i<=two;i++){ - for(int j = 0;j<=three;j++){ - v.insert(2*i + 6*j); - } - } - for(auto x : v){ - // cout << x.first.first << "" "" << x.first.second << "" "" << x.second << ' ' << sum%9 << '\n'; - } - bool p = false; - for(auto x : v){ - if((sum+x)%9==0){ - cout << ""YES"" << '\n'; - p = true; - break; - } - } - if(!p){ - cout << ""NO"" << '\n'; - } - - } - int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - std::cout.tie(0); - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - int tt; - cin >> tt; - while(tt--){ - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - auto t1 = high_resolution_clock::now(); - solve(); - auto t2 = high_resolution_clock::now(); - auto ms_int = duration_cast(t2 - t1); - duration ms_double = t2 - t1; - // std::cout << ms_double.count() << ""ms\n""; - } - return 0; - } ",1 -Christopher_Rdz,2050C - Uninteresting Number,c++17 ,299532339,299532096,"#include -using namespace std; - -#define fr(x) for (int i = 1; i <= x; i++) -#define debug(x) cout << x << ""\n"" -#define MAXN 300006 -#define MOD 998244353 -typedef long long int ll; - -int arr[MAXN]; - -ll gcdExtended(ll a, ll b, ll *x, ll *y) -{ - if (a == 0) - { - *x = 0, *y = 1; - return b; - } - - ll x1, y1; - ll gcd = gcdExtended(b%a, a, &x1, &y1); - *x = y1 - (b/a) * x1; - *y = x1; - - return gcd; -} - -ll modInverse(ll b, ll m) -{ - ll x, y; - ll g = gcdExtended(b, m, &x, &y); - return (x%m + m) % m; -} - -ll divisionModular(ll a, ll b, ll m) -{ - a = a % m; - ll inv = modInverse(b, m); - ll resp = (inv * a) % m; - return resp; -} - -int main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); - int t; - cin >> t; - - while(t--){ - string n; - int sum = 0, dos = 0, seis = 0; - cin >> n; - for (char num: n ){ - sum += (num - '0'); - if(num == '2') dos++; - if(num == '3') seis++; - } - - bool pudo = false; - if(sum % 9 == 0) pudo = true; - - for (int i = 1; i <= 100000; i++){ - int posible = sum + (2 * i); - if(posible % 9 == 0){ - int seisNeed = i / 3; - int dosNeed = i - (seisNeed * 3); - if(seisNeed > seis){ - seisNeed -= seis; - dosNeed = dosNeed + (seisNeed * 3); - } - if(dos >= dosNeed){ - pudo = true; - break; - } - } - } - - if(pudo) cout << ""YES""; - else cout << ""NO""; - - cout << ""\n""; - } - - return 0; -} - -/* -1 -6 8 -1 4 2 7 3 5 -7 6 5 6 3 3 -2 5 -1 6 -1 5 -1 5 -1 5 -2 3 -2 3 -1 6 - - - -2 3 3 3 4 4 4 4 4 4 5 6 7 7 7 7 9 -*/ -","#include -using namespace std; - -#define fr(x) for (int i = 1; i <= x; i++) -#define debug(x) cout << x << ""\n"" -#define MAXN 300006 -#define MOD 998244353 -typedef long long int ll; - -int arr[MAXN]; - -ll gcdExtended(ll a, ll b, ll *x, ll *y) -{ - if (a == 0) - { - *x = 0, *y = 1; - return b; - } - - ll x1, y1; - ll gcd = gcdExtended(b%a, a, &x1, &y1); - *x = y1 - (b/a) * x1; - *y = x1; - - return gcd; -} - -ll modInverse(ll b, ll m) -{ - ll x, y; - ll g = gcdExtended(b, m, &x, &y); - return (x%m + m) % m; -} - -ll divisionModular(ll a, ll b, ll m) -{ - a = a % m; - ll inv = modInverse(b, m); - ll resp = (inv * a) % m; - return resp; -} - -int main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); - int t; - cin >> t; - - while(t--){ - string n; - int sum = 0, dos = 0, seis = 0; - cin >> n; - for (char num: n ){ - sum += (num - '0'); - if(num == '2') dos++; - if(num == '3') seis++; - } - - if(sum % 9 == 0){ - cout << ""YES""; - }else{ - int falta = 9 - (sum % 9); - bool pudo = false; - while(dos >= 1 || seis >= 1){ - if(dos == 0){ - while(seis >= 1){ - sum += 6; - seis--; - if(sum % 9 == 0){ - seis = 0; - pudo = true; - break; - } - } - }else if(seis == 0){ - while(dos >= 1){ - sum += 2; - dos--; - if(sum % 9 == 0){ - pudo = true; - dos = 0; - break; - } - } - }else{ - if(falta >= 6){ - sum += 6; - falta -= 6; - seis--; - } - else{ - sum += 2; - falta -= 2; - dos--; - } - if(falta == 0){ - pudo = true; - break; - }else{ - falta = 9 - (sum % 9); - } - } - - } - if(pudo) cout << ""YES""; - else cout << ""NO""; - } - - cout << ""\n""; - } - - return 0; -} - -/* -1 -6 8 -1 4 2 7 3 5 -7 6 5 6 3 3 -2 5 -1 6 -1 5 -1 5 -1 5 -2 3 -2 3 -1 6 - - - -2 3 3 3 4 4 4 4 4 4 5 6 7 7 7 7 9 -*/ -",1 -Dibz,2050C - Uninteresting Number,c++17 ,299381903,299383148,"#include - -using namespace std; - -long long get_sum(long long sum){ - while(sum > 9){ - long long n = sum; - sum = 0; - while(n > 0){ - sum += n%10; - n /= 10; - } - } - return sum; -} - -void solve(string s){ - long long arr[s.size()]; - long long sum = 0,two = 0,three = 0; - for(int i = 0;i < s.size();i++){ - arr[i] = s[i] - '0'; - sum += arr[i]; - if(arr[i] == 2)two++; - else if(arr[i] == 3)three++; - } - sum = get_sum(sum); - for(int i = 0;i < min(10,two + 1);i++){ - for(int j = 0;j < min(10,three + 1);j++){ - if((sum + i*2 + j*3)%9 == 0){ - cout << ""YES\n""; - return; - } - } - } - cout << ""NO\n""; - return; -} - - -int main(){ - int t; - cin >> t; - while(t--){ - string s; - cin >> s; - solve(s); - } - return 0; -}","#include - -using namespace std; - -long long get_sum(long long sum){ - while(sum > 9){ - long long n = sum; - sum = 0; - while(n > 0){ - sum += n%10; - n /= 10; - } - } - return sum; -} - -void solve(string s){ - long long arr[s.size()]; - long long sum = 0; - int two = 0,three = 0; - for(int i = 0;i < s.size();i++){ - arr[i] = s[i] - '0'; - sum += arr[i]; - if(arr[i] == 2)two++; - else if(arr[i] == 3)three++; - } - sum = get_sum(sum); - for(int i = 0;i < min(10,two + 1);i++){ - for(int j = 0;j < min(10,three + 1);j++){ - if((sum + i*2 + j*6)%9 == 0){ - cout << ""YES\n""; - return; - } - } - } - cout << ""NO\n""; - return; -} - - -int main(){ - int t; - cin >> t; - while(t--){ - string s; - cin >> s; - solve(s); - } - return 0; -}",2 -BREAD11,2050C - Uninteresting Number,python,299516020,299517010,"testCases = int(input()) -for i in range(testCases): - two = 0 - three = 0 - total = 0 - number = input() - for j in number: - - if j == ""2"": - two += 1 - elif j == ""3"": - three += 1 - total += int(j) - total = total % 9 - if total == 0: - print(""YES"") - elif total == 3 and three >= 1 or total == 6 and three >= 2: - print(""YES"") - elif (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - elif three >= 2: - total += 3 - total = total % 9 - if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - else: - print(""NO"") - elif three >= 1: - total += 6 - total = total % 9 - if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - else: - print(""NO"") - else: - print(""NO"") - -","testCases = int(input()) -for i in range(testCases): - two = 0 - three = 0 - total = 0 - number = input() - for j in number: - - if j == ""2"": - two += 1 - elif j == ""3"": - three += 1 - total += int(j) - total = total % 9 - if total == 0: - print(""YES"") - elif total == 3 and three >= 1 or total == 6 and three >= 2: - print(""YES"") - elif (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - elif three >= 2: - total += 3 - total = total % 9 - if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - else: - total += 3 - total = total % 9 - if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - else: - print(""NO"") - elif three >= 1: - total += 6 - total = total % 9 - if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two: - print(""YES"") - else: - print(""NO"") - else: - print(""NO"") - -",2 -sminix,2050C - Uninteresting Number,c++20 ,307638486,307638588,"#include - - - -using namespace std; - - - -int main(){ - - int t; - - cin >> t; - - while(t--){ - - string s; - - cin >> s; - - int n = s.length(), r = 0, c2 = 0, c3 = 0; - - for(int i = 0; i < n; i++){ - - c2 += s[i] == '2'; - - c3 += s[i] == '3'; - - r = (r + s[i] - '0') % 9; - - } - - cout << r << "" "" << c2 << "" "" << c3 << endl; - - bool flag = false; - - for(int i = 0; i <= min(c2, 8); i++){ - - for(int j = 0; j <= min(2, c3); j++) if((r + i + i + j + j + j) % 9 == 0){ - - flag = true; - - break; - - } - - if(flag) break; - - } - - cout << (flag? ""YES"": ""NO"") << endl; - - } - - return 0; - -}","#include - - - -using namespace std; - - - -int main(){ - - int t; - - cin >> t; - - while(t--){ - - string s; - - cin >> s; - - int n = s.length(), r = 0, c2 = 0, c3 = 0; - - for(int i = 0; i < n; i++){ - - c2 += s[i] == '2'; - - c3 += s[i] == '3'; - - r = (r + s[i] - '0') % 9; - - } - - bool flag = false; - - for(int i = 0; i <= min(c2, 8); i++){ - - for(int j = 0; j <= min(2, c3); j++) if((r + i + i + j * 6) % 9 == 0){ - - flag = true; - - break; - - } - - if(flag) break; - - } - - cout << (flag? ""YES"": ""NO"") << endl; - - } - - return 0; - -}",2 -zhoyanov,2050C - Uninteresting Number,c++23 ,298393001,298393917,"#include -#define int long long -#define pb push_back -#define F first -#define S second -#define M ""MUHA"" -#define all(x) x.begin(),x.end() -#define ssd ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -using namespace std; -const int maxn = 1e5+5,N=20,mod = 1e9+7; -void solve(){ - int n; - cin >>n; - int cal2=0,cal3=0; - int cal=0; - string s = to_string(n); - for(int i=0;i>t; - for(int i=1;i<=t;i++){ - //cout<<""Case ""< -#define int long long -#define pb push_back -#define F first -#define S second -#define M ""MUHA"" -#define all(x) x.begin(),x.end() -#define ssd ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -using namespace std; -const int maxn = 1e5+5,N=20,mod = 1e9+7; -void solve(){ - string s; - cin >>s; - int cal2=0,cal3=0; - int cal=0; - for(int i=0;i>t; - for(int i=1;i<=t;i++){ - //cout<<""Case ""< - - - -using namespace std; - - - -#define ll long long - - - -void solve(){ - - string s; - - cin>>s; - - int c2 = 0, c3 = 0, sum = 0; - - for(int i=0; i check = [&]() -> bool { - - int r = (9-sum%9)%9; - - c3 %= 3; - - c2 %= 9; - - if(c2 >= (r*5)%9)return true; - - if(c3 > 0 && c2 >= ((r+3)*5)%9)return true; - - if(c3 > 1 && c2 >= ((r+6)*5)%9)return true; - - return false; - - }; - - cout<<(check() ? ""YES"" : ""NO"")<<""\n""; - -} - - - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - solve(); - - } - -}","#include - - - -using namespace std; - - - -#define ll long long - - - -void solve(){ - - string s; - - cin>>s; - - int c2 = 0, c3 = 0, sum = 0; - - for(int i=0; i check = [&]() -> bool { - - for(int i=0; i<=min(c2, 9); i++){ - - for(int j=0; j<=min(c3, 9); j++){ - - if((sum+2*i+6*j) % 9 == 0)return true; - - } - - } - - return false; - - }; - - cout<<(check() ? ""YES"" : ""NO"")<<""\n""; - -} - - - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - solve(); - - } - -}",2 -ProElectro07,2050C - Uninteresting Number,c++17 ,298639735,298640179,"#include -using namespace std; -#define int long long - -bool fn(int num_2, int num_6, int sum){ - - vector dp(9,false); - dp[sum] = true; - - for(int i=0;i<=num_2;i++){ - for(int j=0;j<=num_6;j++){ - if(i==0 && j==0){ - continue; - } - int num = sum + 2*i + 6*j; - num%=9; - dp[num] = true; - } - } - - return dp[0]; -} - - -main(){ - - cin.tie(0); - ios::sync_with_stdio(0); - - int t; - - cin>>t; - - while(t--){ - string s; - - cin>>s; - - int n = s.size(); - int num_2 = 0; - int num_6 = 0; - - int sum = 0; - - for(int i=0;i -using namespace std; -#define int long long - -bool fn(int num_2, int num_6, int sum){ - - vector dp(9,false); - dp[sum] = true; - - for(int i=0;i<=min((int)18,num_2);i++){ - for(int j=0;j<=min(num_6,(int)3);j++){ - if(i==0 && j==0){ - continue; - } - int num = sum + 2*i + 6*j; - num%=9; - dp[num] = true; - } - } - - return dp[0]; -} - - -main(){ - - cin.tie(0); - ios::sync_with_stdio(0); - - int t; - - cin>>t; - - while(t--){ - string s; - - cin>>s; - - int n = s.size(); - int num_2 = 0; - int num_6 = 0; - - int sum = 0; - - for(int i=0;i -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - string n; - cin >> n; - vector digits; - int sum = 0; - for (char c : n) { - int digit = c - '0'; - digits.push_back(digit); - sum += digit; - } - if (sum % 9 == 0) { - cout << ""YES"" << endl; - continue; - } - int count2 = 0, count3 = 0; - for (int digit : digits) { - if (digit == 2) count2++; - if (digit == 3) count3++; - } - bool possible = false; - for (int i = 0; i <= count2 && !possible; i++) { - for (int j = 0; j <= count3 && !possible; j++) { - int newSum = sum + i * 2 + j * 6; - if (newSum % 9 == 0) { - possible = true; - break; - } - } - } - if (possible) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } - return 0; -} -","#include -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - ll n; - cin >> n; - - vector digits; - ll sum = 0; - - while (n > 0) { - ll temp = n % 10; - digits.push_back(temp); - sum += temp; - n /= 10; - } - - if (sum % 9 == 0) { - cout << ""YES"" << endl; - continue; - } - - ll count2 = 0, count3 = 0; - for (int digit : digits) { - if (digit == 2) count2++; - if (digit == 3) count3++; - } - bool possible = false; - for (ll i = 0; i <= count2 && !possible; i++) { - for (ll j = 0; j <= count3 && !possible; j++) { - ll newSum = sum + i * 2 + j * 6; - if (newSum % 9 == 0) { - possible = true; - break; - } - } - if(possible){break;} - } - - if (possible) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } - return 0; -} -",1 -apex,2050C - Uninteresting Number,python,299104375,299104304,"'''⣿⣿⣿⣿⣿⣿⣿⣿⡿⡫⣁⡴⣈⡼⣟⣭⣷⣿⡿⠿⡽⡟⠍⡙⢕⣢⣿⡟⣱⣿⣿⣿⣿⣿⠟⠋⡕⢼⣣⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⢿⣩⣾⣿⡿⣿⣿⢿⣿⣿⣿⣿⡿⠛⣙⢄⣽⣿⣿⣿⡃⢹⣿⣿⣾⢫⢿⢇⣿⡟⣼⣿⡇⠯⠈⠰⣶⣾⣶⡄⢻⣿⣿⢎⣮⡹⠗⣠⣵⣶⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⡿⡫⣪⡾⣫⣾⣯⠾⠛⣋⣥⣶⡿⠟⣩⢔⣼⣾⣿⣿⠏⣼⣿⣿⢟⣿⡟⣡⢊⣼⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⡿⣫⣷⣿⣿⣿⣫⢏⡼⣫⣾⣿⣿⣿⣃⢔⠟⣱⣿⣿⡿⣛⣿⣿⣿⣿⣿⣿⣏⡾⣼⡿⣸⣿⣿⠃⣴⠠⢹⣸⡿⣿⣇⡱⡊⣿⣎⣎⢷⡘⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⠟⢞⣾⡟⠾⠿⢋⢥⣺⣯⣷⡿⢋⣴⣯⣾⡿⢟⢛⣻⠏⣼⣿⣿⠏⣾⣿⠟⣵⣿⣿⣿⣿⡿⠿⠟⠛⣛⣉⣥⣴⣶⡿⢟⣿⣿⣿⣿⡟⠑⣡⠯⣺⣿⣿⣿⣿⡿⢋⣴⣾⠿⠟⣫⣾⣿⣿⡟⣼⣿⣿⣿⡙⣽⡟⣵⣿⣿⣥⣦⡏⡇⠈⡏⣷⡹⣿⣦⠑⡜⣿⣯⢫⢭⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⡟⣠⠟⣩⣴⡾⣥⣼⠿⣫⣥⢈⣶⠶⢛⢍⡒⣡⡶⣼⠏⣰⣿⣿⢋⠶⢿⢥⣾⣮⣭⣿⢤⣤⡶⡾⣻⣿⠟⣨⣿⡿⢋⣴⣿⡿⣛⡟⡁⣴⡞⣡⣾⣿⢟⣭⣿⡿⠱⠟⡡⡊⣠⣾⣿⡿⣫⣟⣼⣿⢫⢯⣿⢸⣿⣾⣿⣿⣿⣿⢼⣷⣿⠀⣷⢿⢸⣜⢿⣷⡘⣞⢿⣷⡵⡣⠘⢿⣿⣿⣿⣿⣿⣿⣿⠿⢟⡛⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⡇⡉⣼⣿⡿⣼⡟⢡⣾⡿⢃⢈⡴⠚⠑⣋⣾⢟⠊⡄⢠⣿⡿⢃⡴⡵⣳⣿⢟⣵⡿⣵⡿⠿⠹⣼⣿⠏⣼⡿⢋⣴⣿⡿⣫⣪⢞⣡⠟⣢⣾⣿⠟⣵⡿⠛⣩⠞⣡⠪⢞⣾⣿⠟⢡⢞⠉⢊⣿⠇⡜⣸⡇⢠⣿⣿⣿⢿⣿⡟⣾⢹⣿⢈⣿⢸⠰⢻⡄⣻⣿⣎⢈⠻⣿⣞⢆⢸⣿⡿⢿⣻⣭⣷⣾⣿⣿⣿⣿⣶⣬⡛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣷⣦⣿⣿⢱⡟⣴⣿⠟⢑⣫⣷⠖⣡⣾⡿⡵⢁⡞⢻⣾⡟⢁⣞⣞⡽⣟⣵⡿⣫⠿⢋⡴⢰⣱⣿⠇⣼⠏⣠⣾⣿⢯⣾⢞⢵⣫⣷⢾⡯⠫⢠⡞⣡⢮⠞⣱⠞⣡⣢⣿⡿⠑⡠⣵⢇⣆⣾⡏⣼⠃⣿⠀⣽⡏⣿⡏⣼⣿⢳⡏⢨⡏⢘⣿⡔⢈⣸⣿⠱⡹⣿⢸⣰⡌⢛⣣⣬⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣬⡻⢿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣮⠀⠩⢁⣴⣿⢟⣵⣾⡟⠩⠊⢒⢽⣾⣧⣻⡌⣾⢉⣬⠞⠏⠩⢚⣡⣾⠿⡃⡎⣿⠏⡼⢃⣼⣿⡟⢕⠕⣡⣴⢿⡫⠟⣙⣤⣶⠟⢌⡵⢋⡜⣡⡾⣵⣿⠟⢀⣤⡾⣱⡟⢌⡞⣰⡇⣠⡟⡠⣿⡇⣿⡇⣾⣿⡾⢀⣾⡟⣸⣿⣧⢸⣧⣿⢹⠁⣟⣬⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣙⢿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⢿⣢⣤⣿⢟⡵⠟⣁⣨⢁⣾⡌⣿⠂⢻⣿⡧⣁⠵⣋⡴⢊⡔⠈⠼⡿⣫⣾⠀⣹⣿⣿⢡⡾⣿⣋⣤⣧⠿⠫⢓⡩⣴⣾⡿⣫⠉⢠⣞⡷⢪⣤⣟⣽⣿⠏⣴⣿⢏⣾⡿⠘⡞⢱⡿⣠⣿⠇⡆⣿⡇⣿⢇⣿⣿⠁⣾⣿⢳⣿⠿⢇⣦⠻⣉⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣙⢿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⠏⠕⣩⣴⣿⡿⣣⡿⡳⣣⢹⠀⣃⠅⡨⠠⠞⢱⡞⣼⠛⣆⣧⣝⢛⡻⠤⢯⣟⣃⣲⣯⣿⠿⢛⢡⣶⣾⠛⣴⡿⣫⣾⠃⣰⣯⡟⣱⣯⣏⣼⣿⢃⣾⣿⢣⣿⢏⠄⡼⢡⣿⠇⣼⡿⢠⡏⣿⡇⣿⠈⣿⠇⣾⣿⢧⣿⠃⢀⣾⡟⡰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡱⠇⣼⣿⣿⢟⡼⠋⣠⠞⠋⠀⠈⣤⣤⢷⢸⡟⣨⡇⠁⣇⢸⣿⣿⣷⣮⢁⠔⡭⠋⠉⡠⣊⡞⣳⣿⣿⣫⣼⢟⣾⣿⠁⡴⣳⢏⣾⣿⣟⡾⢻⣯⣿⣿⡡⢭⢏⡟⢰⢁⡟⡘⢰⣿⡅⣐⡚⣿⡇⣿⢂⡟⣼⣿⢏⣸⠇⣨⣼⡟⡌⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⢻⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠗⠝⡫⠞⣩⡔⣂⣮⢠⣶⡇⡐⡰⣶⠊⢸⠇⣿⡧⡗⣼⢾⣬⣭⡝⡡⡣⠚⠔⠀⢘⣼⣿⢳⣿⣿⣷⣿⣵⣿⣿⠃⣼⣵⢯⣿⣿⡟⣜⢡⡟⢹⣿⢱⣿⣿⣾⠃⢢⡟⣠⢇⣿⣿⡇⡯⠇⣽⡇⣿⢸⡽⣻⢟⠘⠈⣰⣿⡟⢸⢷⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⢹⣿⡏⢹⣿⡟⠁⠈⣿⡿⠁⣿⣿⠁⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⢹ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣥⣀⣥⣴⣾⣳⣾⢟⣵⢯⠞⡠⢳⢷⡭⢰⡏⡇⡏⡇⡅⢻⣿⡿⢋⠈⡀⣰⡷⠀⣠⣈⡹⢛⡿⠿⣿⣿⣿⣿⣿⡿⠰⣳⢫⣿⣿⣿⠹⣁⡾⢡⢸⢣⣿⣿⣿⠿⠐⢋⠚⡈⣬⣭⣴⣶⣞⡇⣿⡇⣿⣸⣱⠟⣎⡇⣸⣿⡟⣼⡟⡾⢸⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠈⡿⢀⡾⠋⣠⠆⠀⣿⠁⠈⠉⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⢸ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣫⣴⠿⠕⣡⢮⡾⡘⣦⣿⡸⡇⠀⡅⢡⢥⢐⡋⢦⣶⡿⢯⣽⢧⢡⣿⣺⣟⣶⣾⣥⣜⣢⠫⣉⠿⣿⣾⢏⣿⣿⣿⣿⢰⠻⢣⣿⢈⡬⠝⣀⣲⣤⣴⣟⢞⣽⣿⣿⣿⡿⣿⡿⢸⡗⣿⠉⢣⡇⣿⢠⣿⣿⡹⠟⣼⢷⢸⣿⣿⣿⣿⣿⣿⣿⡿⠀⣶⠀⠀⡼⠁⣀⣠⡄⠠⠇⢠⣾⡟⢀⣾⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⡟⢸ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣋⣡⣘⣣⣴⡾⣽⣳⢏⡼⠁⠙⣿⡇⢿⠀⠻⡾⣸⣿⣿⡐⠢⠩⠀⠐⠀⠭⢒⣚⠯⢭⣛⡿⣿⣿⣷⣶⢤⡹⡟⣼⣿⣿⣿⣿⣮⣴⡿⠿⣄⣶⣾⣿⣿⡿⢟⣫⠭⠿⠒⠢⠤⠔⠀⠀⠘⣧⣿⠌⣿⠃⡟⣼⣿⣿⣇⠆⡿⣼⢸⣿⣿⣿⣿⣿⣿⣿⣧⣼⣿⣧⣼⣧⣼⣿⣿⣦⣴⣤⣿⣿⣦⣼⡟⣡⣾⣿⣿⣿⣿⣿⣿⣿⣿⡇⣼ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⡿⣽⠃⢡⣾⠁⢞⣧⢹⡇⢸⡇⢧⢷⡉⣿⣿⣿⡃⠜⣿⣿⡇⢻⣷⡂⢸⣤⣈⠙⠂⣿⣿⣿⣧⢠⢸⣿⣿⣿⣿⣿⣿⡟⠁⣹⣿⣿⣿⣿⡿⠐⢋⠁⣤⣖⣘⣻⠇⣼⣿⣿⠃⣹⡏⠸⢃⡏⠀⣻⣿⣿⣟⡀⣇⡏⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠿⠛⢿⠛⢻⡿⠟⠛⠛⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠗⢋⣴⣿⡏⠀⣾⡿⠀⠇⣾⡉⣘⣿⣧⡸⣿⣿⣧⡡⢻⣿⣿⣦⣘⠿⢽⣛⣽⣷⡀⠸⣿⣿⣿⣃⡀⣿⣿⣿⣿⣿⣿⡟⣧⣹⣿⣿⣿⣿⠃⢰⣿⣷⣝⡻⢛⣋⣴⣿⣿⢏⣇⢻⡌⠈⡸⢽⠐⣿⣿⡟⣼⣱⡿⣠⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡄⢠⣶⠀⣴⣿⠀⣠⣶⣶⠂⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⣿⠀⢰⣿⠃⡜⠀⢻⡇⢸⣿⣿⣷⣽⣿⣿⣿⣣⡻⢿⣿⣿⣿⣿⣿⣿⡿⢠⣐⢉⢉⡿⢉⣴⣿⣿⣿⣿⣿⣿⣿⣾⣿⡿⠻⢿⡏⢠⣌⢿⣿⣿⣿⣿⣿⣿⡿⣫⣜⣿⢳⢠⢹⡇⣸⣷⣾⢛⡇⢿⡟⣱⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣾⣿⣿⣿⡏⢠⠿⠛⢁⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢠⡜⣣⣾⢁⣃⢹⣿⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣶⣾⣿⣥⣴⣿⣳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣬⠡⠛⢿⣾⣶⣶⣶⣶⣿⣿⣿⣿⣿⣿⣿⠈⡇⢾⣷⣿⣿⡿⢸⣿⡞⡀⣾⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⠉⢁⣀⣠⣽⣿⣿⣀⣀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣵⣾⣿⢇⢈⡜⣅⠹⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣸⣧⢻⣿⣿⣿⡇⣿⡟⡀⡆⣿⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢊⣬⣾⣿⣷⣤⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣾⣿⣿⣾⣿⣿⡿⠸⠟⠠⢠⢣⢿⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⢹⡟⠈⢹⣿⠃⣸⠏⢸⡏⠈⣿⡿⠁⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⡆⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣴⠀⡏⣸⡇⠎⢿⡛⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⡟⢁⠀⠸⠃⣰⡟⢀⡿⠀⡀⠘⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣽ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣸⣿⠀⠀⣿⣿⢰⣾⡇⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢠⣾⡀⠀⣴⡿⠁⣾⠁⣼⣷⠀⢠⣿⠛⢙⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢠⣿⡏⠠⣸⣿⣷⣿⣿⢃⣨⣿⣿⣿⣿⣿⣿⣿⣷⣶⣿⣿⣷⣾⣿⣷⣼⣿⣶⣿⣿⣷⣾⣿⣶⣿⣿⣿⣿⣿⣿⣿⣿⡿⣡⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⣾⣿⢁⣵⣿⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣱⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣬⡻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣴⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣴⡙⢿⣿⡿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⡻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⣼⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢂⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣡⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣯⣝⡻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠟⠋⢁⣾⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢱⡌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣡⣾⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣛⣿⣿⣿⣿⣿⣷⣶⣬⡁⣨⠿⣛⣛⣛⣻⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠐⠌⣿⣆⠹⣿⣿⣿⣿⣿⣏⣙⣻⠿⠿⢿⣿⣿⣿⣿⣿⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢿⣟⣋⣤⣾⣿⣿⣿⡿⢣⣾⣿⢏⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⡴⣩⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⡳⢹⣿⣷⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣗⢦⡀⠀⠤⣤⣤⣤⣤⣤⣤⣄⠤⠖⡀⢴⣶⣿⣿⣿⣿⣿⣿⣿⡿⢋⣴⣿⡿⠋⣀⠀⣺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣨⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢰⣌⠊⣿⣿⣿⣆⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⣙⠛⠛⠒⠒⠒⠒⠒⡖⢒⣩⣼⣿⣿⣿⣿⣿⣿⣿⡿⢋⣴⣿⣿⣿⠍⣐⡇⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣷⣿⣿⣿⣿⣷⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢋⣴⣿⣿⣿⣿⡏⢀⡳⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿���⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣖⢀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣱⣿⣿⣿⣿⣿⣿⡯⢅⡾⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠃⠘⣿⡷⣝⢿⣿⣿⣿⣿⡧⠢⡀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⣰⣿⣿⣿⣿⣿⣿⣭⣾⣿⡇⡆⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⠀⠀⠀⣿⣿⣮⡳⡍⠿⣿⣿⣿⣌⠺⢔⣌⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⢂⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⡌⠲⣜⢿⣿⣿⣿⡄⢠⣹⣷⣆⣉⠛⠿⠿⠿⠿⢿⠿⡿⠿⠿⠟⠋⣀⠤⡢⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠉⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣷⡐⢔⢌⢿⣿⣿⣿⣄⠐⢿⣿⣿⣿⣿⣷⣶⣶⣦⣦⣴⣤⣦⡔⠲⢌⡱⣴⣿⣿⣿⠟⢋⣩⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠈⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣷⢠⠓⢮⣻⣿⣿⣿⣎⢈⠽⣛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠣⠕⢲⣿⣿⣿⣿⢏⣰⣾⠿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠻⣇⢙⢴⢙⣿⣿⣿⣿⣷⡱⣦⣪⠬⣽⣛⡿⡟⣻⣿⣿⣣⣌⣴⣿⣿⣿⡿⢁⡴⢚⣋⠸⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⡿⠿⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⢝⢆⢻⣿⣿⣿⣿⣧⢩⣫⠭⢟⣻⢒⣼⣿⣿⣯⢅⣾⣿⣿⡿⢋⡀⢦⣼⠯⣭⣶⣾⡿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠘⠿⢿⣿⣿⣿⣄⣺⢭⣻⡆⢾⣿⣿⣿⡄⣿⣿⣿⡟⠁⠀⢴⡟⣮⡿⠼⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ''' -#apex -import sys -from bisect import * -from collections import defaultdict,deque,Counter -input=sys.stdin.readline -def readList(): - return list(map(int, input().split())) -def readInt(): - return int(input()) -def readInts(): - return map(int, input().split()) -def readStr(): - return input().strip() -def print_array(arr): - print("" "".join(map(str, arr))) -def printer(is_True): - print('YES') if is_True else print('NO') -for _ in range(readInt()): - n=[*readStr()] - two=n.count('2') - three=n.count('3') - s=0 - for ch in n: - s+=int(ch) - f=False - for i in range(min(10,two+1)): - for j in range(min(10,three+1)): - if (s+2*i+6*j)%9==0: - f=True - break - printer(f)","'''⣿⣿⣿⣿⣿⣿⣿⣿⡿⡫⣁⡴⣈⡼⣟⣭⣷⣿⡿⠿⡽⡟⠍⡙⢕⣢⣿⡟⣱⣿⣿⣿⣿⣿⠟⠋⡕⢼⣣⣴⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⢿⣩⣾⣿⡿⣿⣿⢿⣿⣿⣿⣿⡿⠛⣙⢄⣽⣿⣿⣿⡃⢹⣿⣿⣾⢫⢿⢇⣿⡟⣼⣿⡇⠯⠈⠰⣶⣾⣶⡄⢻⣿⣿⢎⣮⡹⠗⣠⣵⣶⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⡿⡫⣪⡾⣫⣾⣯⠾⠛⣋⣥⣶⡿⠟⣩⢔⣼⣾⣿⣿⠏⣼⣿⣿⢟⣿⡟⣡⢊⣼⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⡿⣫⣷⣿⣿⣿⣫⢏⡼⣫⣾⣿⣿⣿⣃⢔⠟⣱⣿⣿⡿⣛⣿⣿⣿⣿⣿⣿⣏⡾⣼⡿⣸⣿⣿⠃⣴⠠⢹⣸⡿⣿⣇⡱⡊⣿⣎⣎⢷⡘⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⠟⢞⣾⡟⠾⠿⢋⢥⣺⣯⣷⡿⢋⣴⣯⣾⡿⢟⢛⣻⠏⣼⣿⣿⠏⣾⣿⠟⣵⣿⣿���⣿⡿⠿⠟⠛⣛⣉⣥⣴⣶⡿⢟⣿⣿⣿⣿⡟⠑⣡⠯⣺⣿⣿⣿⣿⡿⢋⣴⣾⠿⠟⣫⣾⣿⣿⡟⣼⣿⣿⣿⡙⣽⡟⣵⣿⣿⣥⣦⡏⡇⠈⡏⣷⡹⣿⣦⠑⡜⣿⣯⢫⢭⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⡟⣠⠟⣩⣴⡾⣥⣼⠿⣫⣥⢈⣶⠶⢛⢍⡒⣡⡶⣼⠏⣰⣿⣿⢋⠶⢿⢥⣾⣮⣭⣿⢤⣤⡶⡾⣻⣿⠟⣨⣿⡿⢋⣴⣿⡿⣛⡟⡁⣴⡞⣡⣾⣿⢟⣭⣿⡿⠱⠟⡡⡊⣠⣾⣿⡿⣫⣟⣼⣿⢫⢯⣿⢸⣿⣾⣿⣿⣿⣿⢼⣷⣿⠀⣷⢿⢸⣜⢿⣷⡘⣞⢿⣷⡵⡣⠘⢿⣿⣿⣿⣿⣿⣿⣿⠿⢟⡛⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⡇⡉⣼⣿⡿⣼⡟⢡⣾⡿⢃⢈⡴⠚⠑⣋⣾⢟⠊⡄⢠⣿⡿⢃⡴⡵⣳⣿⢟⣵⡿⣵⡿⠿⠹⣼⣿⠏⣼⡿⢋⣴⣿⡿⣫⣪⢞⣡⠟⣢⣾⣿⠟⣵⡿⠛⣩⠞⣡⠪⢞⣾⣿⠟⢡⢞⠉⢊⣿⠇⡜⣸⡇⢠⣿⣿⣿⢿⣿⡟⣾⢹⣿⢈⣿⢸⠰⢻⡄⣻⣿⣎⢈⠻⣿⣞⢆⢸⣿⡿⢿⣻⣭⣷⣾⣿⣿⣿⣿⣶⣬⡛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣷⣦⣿⣿⢱⡟⣴⣿⠟⢑⣫⣷⠖⣡⣾⡿⡵⢁⡞⢻⣾⡟⢁⣞⣞⡽⣟⣵⡿⣫⠿⢋⡴⢰⣱⣿⠇⣼⠏⣠⣾⣿⢯⣾⢞⢵⣫⣷⢾⡯⠫⢠⡞⣡⢮⠞⣱⠞⣡⣢⣿⡿⠑⡠⣵⢇⣆⣾⡏⣼⠃⣿⠀⣽⡏⣿⡏⣼⣿⢳⡏⢨⡏⢘⣿⡔⢈⣸⣿⠱⡹⣿⢸⣰⡌⢛⣣⣬⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣬⡻⢿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣮⠀⠩⢁⣴⣿⢟⣵⣾⡟⠩⠊⢒⢽⣾⣧⣻⡌⣾⢉⣬⠞⠏⠩⢚⣡⣾⠿⡃⡎⣿⠏⡼⢃⣼⣿⡟⢕⠕⣡⣴⢿⡫⠟⣙⣤⣶⠟⢌⡵⢋⡜⣡⡾⣵⣿⠟⢀⣤⡾⣱⡟⢌⡞⣰⡇⣠⡟⡠⣿⡇⣿⡇⣾⣿⡾⢀⣾⡟⣸⣿⣧⢸⣧⣿⢹⠁⣟⣬⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣙⢿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⢿⣢⣤⣿⢟⡵⠟⣁⣨⢁⣾⡌⣿⠂⢻⣿⡧⣁⠵⣋⡴⢊⡔⠈⠼⡿⣫⣾⠀⣹⣿⣿⢡⡾⣿⣋⣤⣧⠿⠫⢓⡩⣴⣾⡿⣫⠉⢠⣞⡷⢪⣤⣟⣽⣿⠏⣴⣿⢏⣾⡿⠘⡞⢱⡿⣠⣿⠇⡆⣿⡇⣿⢇⣿⣿⠁⣾⣿⢳⣿⠿⢇⣦⠻⣉⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣙⢿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⠏⠕⣩⣴⣿⡿⣣⡿⡳⣣⢹⠀⣃⠅⡨⠠⠞⢱⡞⣼⠛⣆⣧⣝⢛⡻⠤⢯⣟⣃⣲⣯⣿⠿⢛⢡⣶⣾⠛⣴⡿⣫⣾⠃⣰⣯⡟⣱⣯⣏⣼⣿⢃⣾⣿⢣⣿⢏⠄⡼⢡⣿⠇⣼⡿⢠⡏⣿⡇⣿⠈⣿⠇⣾⣿⢧⣿⠃⢀⣾⡟⡰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡱⠇⣼⣿⣿⢟⡼⠋⣠⠞⠋⠀⠈⣤⣤⢷⢸⡟⣨⡇⠁⣇⢸⣿⣿⣷⣮⢁⠔⡭⠋⠉⡠⣊⡞⣳⣿⣿⣫⣼⢟⣾⣿⠁⡴⣳⢏⣾⣿⣟⡾⢻⣯⣿⣿⡡⢭⢏⡟⢰⢁⡟⡘⢰⣿⡅⣐⡚⣿⡇⣿⢂⡟⣼⣿⢏⣸⠇⣨⣼⡟⡌⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⢻⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠗⠝⡫⠞⣩⡔⣂⣮⢠⣶⡇⡐⡰⣶⠊⢸⠇⣿⡧⡗⣼⢾⣬⣭⡝⡡⡣⠚⠔⠀⢘⣼⣿⢳⣿⣿⣷⣿⣵⣿⣿⠃⣼⣵⢯⣿⣿⡟⣜⢡⡟⢹⣿⢱⣿⣿⣾⠃⢢⡟⣠⢇⣿⣿⡇⡯⠇⣽⡇⣿⢸⡽⣻⢟⠘⠈⣰⣿⡟⢸⢷⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⢹⣿⡏⢹⣿⡟⠁⠈⣿⡿⠁⣿⣿⠁⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⢹ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣥⣀⣥⣴⣾⣳⣾⢟⣵⢯⠞⡠⢳⢷⡭⢰⡏⡇⡏⡇⡅⢻⣿⡿⢋⠈⡀⣰⡷⠀⣠⣈⡹⢛⡿⠿⣿⣿⣿⣿⣿⡿⠰⣳⢫⣿⣿⣿⠹⣁⡾⢡⢸⢣⣿⣿⣿⠿⠐⢋⠚⡈⣬⣭⣴⣶⣞⡇⣿⡇⣿⣸⣱⠟⣎⡇⣸⣿⡟⣼⡟⡾⢸⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⠈⡿⢀⡾⠋⣠⠆⠀⣿⠁⠈⠉⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⢸ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣫⣴⠿⠕⣡⢮⡾⡘⣦⣿⡸⡇⠀⡅⢡⢥⢐⡋⢦⣶⡿⢯⣽⢧⢡⣿⣺⣟⣶⣾⣥⣜⣢⠫⣉⠿⣿⣾⢏⣿⣿⣿⣿⢰⠻⢣⣿⢈⡬⠝⣀⣲⣤⣴⣟⢞⣽⣿⣿⣿⡿⣿⡿⢸⡗⣿⠉⢣⡇⣿⢠⣿⣿⡹⠟⣼⢷⢸⣿⣿⣿⣿⣿⣿⣿⡿⠀⣶⠀⠀⡼⠁⣀⣠⡄⠠⠇⢠⣾⡟⢀⣾⡿⠋⣹⣿⣿⣿⣿⣿⣿⣿⡟⢸ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣋⣡⣘⣣⣴⡾⣽⣳⢏⡼⠁⠙⣿⡇⢿⠀⠻⡾⣸⣿⣿⡐⠢⠩⠀⠐⠀⠭⢒⣚⠯⢭⣛⡿⣿⣿⣷⣶⢤⡹⡟⣼⣿⣿⣿⣿⣮⣴⡿⠿⣄⣶⣾⣿⣿⡿⢟⣫⠭⠿⠒⠢⠤⠔⠀⠀⠘⣧⣿⠌⣿⠃⡟⣼⣿⣿⣇⠆⡿⣼⢸⣿⣿⣿⣿⣿⣿⣿⣧⣼⣿⣧⣼⣧⣼⣿⣿⣦⣴⣤⣿⣿⣦⣼⡟⣡⣾⣿⣿⣿⣿⣿⣿⣿⣿⡇⣼ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⡿⣽⠃⢡⣾⠁⢞⣧⢹⡇⢸⡇⢧⢷⡉⣿⣿⣿⡃⠜⣿⣿⡇⢻⣷⡂⢸⣤⣈⠙⠂⣿⣿⣿⣧⢠⢸⣿⣿⣿⣿⣿⣿⡟⠁⣹⣿⣿⣿⣿⡿⠐⢋⠁⣤⣖⣘⣻⠇⣼⣿⣿⠃⣹⡏⠸⢃⡏⠀⣻⣿⣿⣟⡀⣇⡏⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠿⠛⢿⠛⢻⡿⠟⠛⠛⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠗⢋⣴⣿⡏⠀⣾⡿⠀⠇⣾⡉⣘⣿⣧⡸⣿⣿⣧⡡⢻⣿⣿⣦⣘⠿⢽⣛⣽⣷⡀⠸⣿⣿⣿⣃⡀⣿⣿⣿⣿⣿���⡟⣧⣹⣿⣿⣿⣿⠃⢰⣿⣷⣝⡻⢛⣋⣴⣿⣿⢏⣇⢻⡌⠈⡸⢽⠐⣿⣿⡟⣼⣱⡿⣠⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡄⢠⣶⠀⣴⣿⠀⣠⣶⣶⠂⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⣿⠀⢰⣿⠃⡜⠀⢻⡇⢸⣿⣿⣷⣽⣿⣿⣿⣣⡻⢿⣿⣿⣿⣿⣿⣿⡿⢠⣐⢉⢉⡿⢉⣴⣿⣿⣿⣿⣿⣿⣿⣾⣿⡿⠻⢿⡏⢠⣌⢿⣿⣿⣿⣿⣿⣿⡿⣫⣜⣿⢳⢠⢹⡇⣸⣷⣾⢛⡇⢿⡟⣱⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⣾⣿⣿⣿⡏⢠⠿⠛⢁⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢠⡜⣣⣾⢁⣃⢹⣿⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣶⣾⣿⣥⣴⣿⣳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣬⠡⠛⢿⣾⣶⣶⣶⣶⣿⣿⣿⣿⣿⣿⣿⠈⡇⢾⣷⣿⣿⡿⢸⣿⡞⡀⣾⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⠉⢁⣀⣠⣽⣿⣿⣀⣀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣵⣾⣿⢇⢈⡜⣅⠹⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣸⣧⢻⣿⣿⣿⡇⣿⡟⡀⡆⣿⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢊⣬⣾⣿⣷⣤⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣾⣿⣿⣾⣿⣿⡿⠸⠟⠠⢠⢣⢿⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⢹⡟⠈⢹⣿⠃⣸⠏⢸⡏⠈⣿⡿⠁⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⡆⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣴⠀⡏⣸⡇⠎⢿⡛⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⡟⢁⠀⠸⠃⣰⡟⢀⡿⠀⡀⠘⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⣽ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣸⣿⠀⠀⣿⣿⢰⣾⡇⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢠⣾⡀⠀⣴⡿⠁⣾⠁⣼⣷⠀⢠⣿⠛⢙⣿⣿⣿⣿⣿⣿⣿⣿⡇⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢠⣿⡏⠠⣸⣿⣷⣿⣿⢃⣨⣿⣿⣿⣿⣿⣿⣿⣷⣶⣿⣿⣷⣾⣿⣷⣼⣿⣶⣿⣿⣷⣾⣿⣶⣿⣿⣿⣿⣿⣿⣿⣿⡿⣡⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⣾⣿⢁⣵⣿⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣱⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣬⡻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣴⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣴⡙⢿⣿⡿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣽⡻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⣼⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢂⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣡⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣯⣝⡻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠟⠋⢁⣾⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢱⡌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣡⣾⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⣛⣿⣿⣿⣿⣿⣷⣶⣬⡁⣨⠿⣛⣛⣛⣻⣿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠐⠌⣿⣆⠹⣿⣿⣿⣿⣿⣏⣙⣻⠿⠿⢿⣿⣿⣿⣿⣿⡿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢿⣟⣋⣤⣾⣿⣿⣿⡿⢣⣾⣿⢏���⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⡴⣩⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⡳⢹⣿⣷⡈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣗⢦⡀⠀⠤⣤⣤⣤⣤⣤⣤⣄⠤⠖⡀⢴⣶⣿⣿⣿⣿⣿⣿⣿⡿⢋⣴⣿⡿⠋⣀⠀⣺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣨⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢰⣌⠊⣿⣿⣿⣆⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣮⣙⠛⠛⠒⠒⠒⠒⠒⡖⢒⣩⣼⣿⣿⣿⣿⣿⣿⣿⡿⢋⣴⣿⣿⣿⠍⣐⡇⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣷⣿⣿⣿⣿⣷⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢋⣴⣿⣿⣿⣿⡏⢀⡳⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣖⢀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣱⣿⣿⣿⣿⣿⣿⡯⢅⡾⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠃⠘⣿⡷⣝⢿⣿⣿⣿⣿⡧⠢⡀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⣰⣿⣿⣿⣿⣿⣿⣭⣾⣿⡇⡆⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⠀⠀⠀⣿⣿⣮⡳⡍⠿⣿⣿⣿⣌⠺⢔⣌⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⢂⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠈⣿⣿⣿⡌⠲⣜⢿⣿⣿⣿⡄⢠⣹⣷⣆⣉⠛⠿⠿⠿⠿⢿⠿⡿⠿⠿⠟⠋⣀⠤⡢⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠉⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣷⡐⢔⢌⢿⣿⣿⣿⣄⠐⢿⣿⣿⣿⣿⣷⣶⣶⣦⣦⣴⣤⣦⡔⠲⢌⡱⣴⣿⣿⣿⠟⢋⣩⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠈⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣷⢠⠓⢮⣻⣿⣿⣿⣎⢈⠽⣛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠣⠕⢲⣿⣿⣿⣿⢏⣰⣾⠿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠻⣇⢙⢴⢙⣿⣿⣿⣿⣷⡱⣦⣪⠬⣽⣛⡿⡟⣻⣿⣿⣣⣌⣴⣿⣿⣿⡿⢁⡴⢚⣋⠸⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⣿⣿⣿⣿⣿⡿⠿⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⢝⢆⢻⣿⣿⣿⣿⣧⢩⣫⠭⢟⣻⢒⣼⣿⣿⣯⢅⣾⣿⣿⡿⢋⡀⢦⣼⠯⣭⣶⣾⡿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ - ⠿⠟⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠘⠿⢿⣿⣿⣿⣄⣺⢭⣻⡆⢾⣿⣿⣿⡄⣿⣿⣿⡟⠁⠀⢴⡟⣮⡿⠼⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ ''' -#apex -import sys -from bisect import * -from collections import defaultdict,deque,Counter -input=sys.stdin.readline -def readList(): - return list(map(int, input().split())) -def readInt(): - return int(input()) -def readInts(): - return map(int, input().split()) -def readStr(): - return input().strip() -def print_array(arr): - print("" "".join(map(str, arr))) -def printer(is_True): - print('YES') if is_True else print('NO') -for _ in range(readInt()): - n=[*readStr()] - two=n.count('2') - three=n.count('3') - s=0 - for ch in n: - s+=int(ch) - f=False - for i in range(two+1): - for j in range(three+1): - if (s+2*i+6*j)%9==0: - f=True - break - printer(f)",1 -ltgsl,2050C - Uninteresting Number,c++23 ,299385316,299384823,"#include -using namespace std; -#define ll long long -void solve() -{ - /* ll n; - cin >> n; - string s = to_string(n); */ - string s; - cin >> s; - ll sum = 0LL; - ll _2 = 0, _3 = 0; - for (auto it : s) - { - sum += it - '0'; - if (it == '2') - _2++; - else if (it == '3') - _3++; - } - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - else - { - for (ll i = 0; i <= _2; i++) - { - for (ll j = 0; j <= _3; j++) - { - if ((sum + (2 * i) + (6 * j)) % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - } - } - cout << ""NO"" << endl; - return; - } -} -int main() -{ - ll t; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -} -","#include -using namespace std; -#define ll long long -void solve() -{ - ll n; - cin >> n; - string s = to_string(n); - ll sum = 0LL; - ll _2 = 0, _3 = 0; - for (auto it : s) - { - sum += it - '0'; - if (it == '2') - _2++; - else if (it == '3') - _3++; - } - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - else - { - for (ll i = 0; i <= _2; i++) - { - for (ll j = 0; j <= _3; j++) - { - if ((sum + 2 * i + 6 * j) % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - } - } - cout << ""NO"" << endl; - return; - } -} -int main() -{ - ll t; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -} -",1 -codemastercpp,2050C - Uninteresting Number,other,297724808,297725051,"import Control.Monad (forM_) - -main :: IO () -main = do - t <- readLn :: IO Int - forM_ [1 .. t] $ \_ -> do - n <- getLine - putStrLn (solveStr n) - -solveStr inp = if solve inp then ""YES"" else ""NO"" - -solve :: String -> Bool -solve num = - let (num2, num3) = (numDigits '2' num, numDigits '3' num) - in checkPossible num2 num3 (sumDigits num) - -checkPossible :: Int -> Int -> Int -> Bool -checkPossible num2 num3 total - | min num2 num3 < 0 = False - | total `mod` 9 == 0 = True - | otherwise = checkPossible (num2 - 1) num3 (total + 2) || checkPossible num2 (num3 - 1) (total + 6) - -numDigits :: Char -> [Char] -> Int -numDigits target = length . filter (== target) - -sumDigits :: [Char] -> Int -sumDigits str = sum (map convertToInt str) - where - convertToInt c = read [c] :: Int -","import Control.Monad (forM_) - -main :: IO () -main = do - t <- readLn :: IO Int - forM_ [1 .. t] $ \_ -> do - n <- getLine - putStrLn (solveStr n) - -solveStr inp = if solve inp then ""YES"" else ""NO"" - -solve :: String -> Bool -solve num = - let (num2, num3) = (numDigits '2' num, numDigits '3' num) - in checkPossible num2 num3 num2 num3 (sumDigits num) - -checkPossible num2 num3 num2In num3In total - | num2In - num2 > 9 = False - | num3In - num3 > 9 = False - | min num2 num3 < 0 = False - | total `mod` 9 == 0 = True - | otherwise = checkPossible (num2 - 1) num3 num2In num3In (total + 2) || checkPossible num2 (num3 - 1) num2In num3In (total + 6) - -numDigits :: Char -> [Char] -> Int -numDigits target = length . filter (== target) - -sumDigits :: [Char] -> Int -sumDigits str = sum (map convertToInt str) - where - convertToInt c = read [c] :: Int -",2 -Ashutosh1348,2050C - Uninteresting Number,c++23 ,307259993,307261258,"#include - -using namespace std; - -typedef long long ll; - -int main() - -{ - - int t; - - cin >> t; - - while(t--) { - - ll n; - - cin >> n; - - - - unordered_map m; - - vector v; - - ll sum = 0; - - while(n != 0) { - - int x = n % 10; - - v.push_back(x); - - sum += x; - - m[x]++; - - n /= 10; - - } - - - - ll p = sum % 9; - - - - if(p == 1) { - - if((m[2] >= 1 && m[3] >= 1) || (m[2] >= 4)) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 2) { - - if((m[3] >= 2 && m[2] >= 2) || (m[3] >= 1 && m[2] >= 5) || m[2] >= 8) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 4) { - - if((m[3] >= 2 && m[2] >= 1) || (m[3] >= 1 && m[2] >= 4) || m[2] >= 7) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 6) { - - if(m[3] >= 2 || (m[3] >= 1 && m[2] >= 3) || m[2] >= 6) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 8) { - - if((m[3] >= 1 && m[2] >= 2) || m[2] >= 5) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 3) { - - if(m[3] >= 1 || m[2] >= 3) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 5) { - - if(m[2] >= 2) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else if(p == 7) { - - if(m[2] >= 1) { - - cout << ""YES"" << endl; - - } else { - - cout << ""NO"" << endl; - - } - - } else { - - cout << ""YES"" << endl; - - } - - } - - - - return 0; - -} - -","#include - -using namespace std; - -typedef long long ll; - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while(t--){ - - string s; - - cin >> s; - - ll sum = 0; - - int freq[10] = {0}; - - for (char c : s) { - - int d = c - '0'; - - sum += d; - - freq[d]++; - - } - - - - ll p = sum % 9; - - - - int count2 = freq[2], count3 = freq[3]; - - bool possible = false; - - for (int i = 0; i <= count2 && !possible; i++){ - - for (int j = 0; j <= count3; j++){ - - if ((p + 2 * i + 6 * j) % 9 == 0) { - - possible = true; - - break; - - } - - } - - } - - - - cout << (possible ? ""YES"" : ""NO"") << ""\n""; - - } - - - - return 0; - -} - -",2 -Chet1398,2050C - Uninteresting Number,c++20 ,307224578,307224969,"#include - -using namespace std; - - - -int main() { - - // your code goes here - - long long t; - - cin>>t; - - while(t--){ - - string n; - - cin>>n; - - int k=n.size(); - - int a[10]={0}; - - long long sum=0; - - for(int i=0;i - -using namespace std; - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - long long t; - - cin >> t; - - while(t--){ - - string n; - - cin >> n; - - int k = n.size(); - - // Use long long for the frequency array as well - - long long a[10] = {0}; - - long long sum = 0; - - for (int i = 0; i < k; i++){ - - int digit = n[i] - '0'; - - a[digit]++; - - sum += digit; - - } - - - - bool possible = false; - - // Check if sum is already divisible by 9 - - if(sum % 9 == 0){ - - cout << ""Yes"" << ""\n""; - - possible = true; - - } - - else { - - // Try to adjust the sum using available 2's (value 2) and 3's (value 6) - - for(long long i = 0; i <= a[2] && !possible; i++){ - - for(long long j = 0; j <= a[3]; j++){ - - if((sum + i * 2 + j * 6) % 9 == 0){ - - cout << ""Yes"" << ""\n""; - - possible = true; - - break; - - } - - } - - } - - } - - if(!possible){ - - cout << ""No"" << ""\n""; - - } - - } - - return 0; - -} - -",2 -Xia21,2050C - Uninteresting Number,python,299537865,299537807,"import sys -import math -import collections -import statistics -import bisect - -input = sys.stdin.readline - -############ ---- Input Functions ---- ############ -##---1) inp — For taking integer inputs. -def inp(): - return (int(input())) - -##2) inlt — For taking List inputs. -def inlt(): - return (list(map(int, input().split()))) - -#3) insr — For taking string inputs. Actually it returns a List of Characters, -# instead of a string, which is easier to use in Python, because in Python, -# Strings are Immutable. -def insr(): - s = input() - return (list(s[:len(s) - 1])) - -#4) invr — For taking space seperated integer variable inputs. -def invr(): - return list(map(int, input().split())) - -for iii in range(int(input())): - a = insr() - sum = 0 - num2 = 0 - num3 = 0 - for i in a: - sum += int(i) - if i == '2': - num2 += 1 - elif i == '3': - num3 += 1 - if sum % 9 == 0: - print(""yes"") - continue - res = 0 - for x in range(min(num2+1, 10)): - if res == 0: - for y in range(min(num3+1, 10)): - if (sum + 2*x + 6*y) % 9 == 0: - print(""yes"") - res = 1 - break - else: - break - if res == 0: - print(""no"")","import sys -import math -import collections -import statistics -import bisect - -input = sys.stdin.readline - -############ ---- Input Functions ---- ############ -##---1) inp — For taking integer inputs. -def inp(): - return (int(input())) - -##2) inlt — For taking List inputs. -def inlt(): - return (list(map(int, input().split()))) - -#3) insr — For taking string inputs. Actually it returns a List of Characters, -# instead of a string, which is easier to use in Python, because in Python, -# Strings are Immutable. -def insr(): - s = input() - return (list(s[:len(s) - 1])) - -#4) invr — For taking space seperated integer variable inputs. -def invr(): - return list(map(int, input().split())) - -for iii in range(int(input())): - a = inlt() - sum = 0 - num2 = 0 - num3 = 0 - for i in str(a): - sum += int(i) - if i == '2': - num2 += 1 - elif i == '3': - num3 += 1 - if sum % 9 == 0: - print(""yes"") - continue - res = 0 - for x in range(min(num2+1, 10)): - if res == 0: - for y in range(min(num3+1, 10)): - if (sum + 2*x + 6*y) % 9 == 0: - print(""yes"") - res = 1 - break - else: - break - if res == 0: - print(""no"")",1 -catechol,2050C - Uninteresting Number,c++20 ,297733607,297733054,"#include -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - string n; - cin >> n; - - int rem = 0; - int tcount = 0, threecount = 0; - - // Calculate the remainder and count digits '2' and '3' - for (char c : n) { - int digit = c - '0'; - rem = (rem + digit) % 9; - if (digit == 2) tcount++; - else if (digit == 3) threecount++; - } - - bool flag = false; - - // Check if adding multiples of 2 and 3 makes (rem) divisible by 9 - for (int i = 0; (i <= 9) && (i <= tcount) && (!flag); i++) { - for (int j = 0; (j <= 9) && (j <= threecount) && (!flag); j++) { - if ((rem + (2 * i) + (6 * j)) % 9 == 0) { - flag = true; - } - } - } - - cout << (flag ? ""YES\n"" : ""NO\n""); - } - - return 0; -} -","#include -using namespace std; -int main() -{ - int t; - cin >> t; - while(t--) - { - - long long int n; - cin >> n; - long long int rem=n%9; - long long int tcount=0,threecount=0; - while(n!=0){ - if(n%10 == 2) - { - tcount++; - } - else if(n%10==3) - { - threecount++; - } - n = n/10; - } - int flag=0; - for(long long int i=0;(i<=9)&&(i<=tcount)&&(!flag);i++){ - for(long long int j=0;(j<=9)&&(j<=threecount)&&(!flag);j++) - { - if((rem+ (2*i) + (6*j))%9==0) - { - flag =1; - } - } - } - if(flag){ - cout << ""YES\n""; - } - else cout << ""NO\n""; - } - - return 0; -}",1 -saba_goduadze01:37,2050C - Uninteresting Number,c++20 ,299255804,299257305,"#include -using namespace std; -#define int long long -const int N=3e5+5,mod=1e9+7,inf=1e18; -int _t,n,c[5]; string s; bool ans; -signed main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - cin>>_t; - while (_t--){ - cin>>s; n=0; c[2]=c[3]=0; ans=0; - for (int i=0; i<(int)s.size(); i++){ - if (s[i]=='2') c[2]++; - else if (s[i]=='3') c[3]++; - else n+=s[i]-'0'; - n%=9; c[2]%=9; c[3]%=9; - } - for (int i=0; i<=c[2]; i++) - for (int j=0; j<=c[3]; j++){ - if ((n+i*4+(c[2]-i)*2+j*3+(c[3]-j)*9)%9==0) ans=1; - } - cout<<(ans?""YES\n"":""NO\n""); - } -}","#include -using namespace std; -#define int long long -const int N=3e5+5,mod=1e9+7,inf=1e18; -int _t,n,c[5]; string s; bool ans; -signed main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - cin>>_t; - while (_t--){ - cin>>s; n=0; c[2]=c[3]=0; ans=0; - for (int i=0; i<(int)s.size(); i++){ - if (s[i]=='2') c[2]++; - else if (s[i]=='3') c[3]++; - n+=s[i]-'0'; - } - for (int i=0; i<=c[2]; i++) - for (int j=0; j<=c[3]; j++){ - if ((n+i*2+j*6)%9==0) ans=1; - } - cout<<(ans?""YES\n"":""NO\n""); - } -}",2 -huluob114514#,2050C - Uninteresting Number,c++20 ,297639612,297640985,"#include -using namespace std; -int main() -{ - //NOI; - //freopen(""road.in"",""r"",stdin); - //freopen(""road.out"",""w"",stdout); - int T; - cin>>T; - while(T--) - { - string N; - cin>>N; - int n=N.length(); - int sum=0; - int ssum=0,tsum=0; - for(int i=0;i -using namespace std; -int main() -{ - //NOI; - //freopen(""road.in"",""r"",stdin); - //freopen(""road.out"",""w"",stdout); - long long T; - cin>>T; - while(T--) - { - string N; - cin>>N; - long long n=N.size(); - long long sum=0; - long long ssum=0,tsum=0; - for(long long i=0;i -using namespace std; -typedef long long ll; - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(NULL); - - int t; - cin >> t; - while(t--) - { - string n; - cin >> n; - int twocount = 0; - int threecount = 0; - ll sum = 0; - bool flag = false; - for(int i =0; i < n.size(); i++) - { - if(n[i] == '2') - twocount++; - else if(n[i] == '3') - threecount++; - sum += n[i] - '0'; - } - for(int i = 0 ; i < min(10, twocount+1); i++) - { - for(int j = 0; j < min(10,threecount+1); j++) - { - if((sum + 2 * i + 6 * j) % 9 == 0) - { - flag = true; - } - } - } - if(flag) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - - } -}","#include -using namespace std; -typedef long long ll; - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(NULL); - - int t; - cin >> t; - while(t--) - { - string n; - cin >> n; - int twocount = 0; - int threecount = 0; - ll sum = 0; - bool flag = false; - for(int i =0; i < n.size(); i++) - { - if(n[i] == '2') - twocount++; - else if(n[i] == '3') - threecount++; - sum += n[i] - '0'; - } - for(int i = 0 ; i < min(8, twocount+1); i++) - { - for(int j = 0; j < min(8,threecount+1); j++) - { - if((sum + 2 * i + 6 * j) % 9 == 0) - { - flag = true; - } - } - } - if(flag) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - - } -}",1 -Whintyr,2050C - Uninteresting Number,c++20 ,299467391,299466886,"// Problem: C. Uninteresting Number -// Contest: Codeforces - Codeforces Round 991 (Div. 3) -// URL: https://codeforces.com/problemset/problem/2050/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -using namespace std; - -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define int long long -#define ld long double -#define pb push_back -#define all(x) (x).begin(),(x).end() -#define rall(x) (x).rbegin(),(x).rend() -#define umap unordered_map -#define mii map -#define pii pair -#define vi vector -#define vb vector -#define vvi vector -#define vpii vector -#define ff first -#define ss second -#define rep(i,x,y) for(int i=x; i=y; i--) -#define yn(f) f?cout<<""YES\n"":cout<<""NO\n"" -#define syn(f) f?cout<<""Yes\n"":cout<<""No\n"" -#define print(x) for(auto l:x) cout<> n; - int sum = 0; - rep(i, 0, n.length()){ - char t = n[i]; - if(t == '2'){ - twos++; - } - if(t == '3'){ - threes++; - } - - sum += (int)t - 48; - } - - int k = sum % 9; - - if(k==0){ - cout << ""YES"" << endl; - return; - } - - rep(i, 0, twos+1){ - rep(j, 0, threes+1){ - if((k + 2*i + 6*j)%9 == 0){ - cout << ""YES "" << endl; - return; - } - } - } - - cout << ""NO"" << endl; - -} - -int32_t main(){ - fastio(); - int t = 1; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","// Problem: C. Uninteresting Number -// Contest: Codeforces - Codeforces Round 991 (Div. 3) -// URL: https://codeforces.com/problemset/problem/2050/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -using namespace std; - -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define int long long -#define ld long double -#define pb push_back -#define all(x) (x).begin(),(x).end() -#define rall(x) (x).rbegin(),(x).rend() -#define umap unordered_map -#define mii map -#define pii pair -#define vi vector -#define vb vector -#define vvi vector -#define vpii vector -#define ff first -#define ss second -#define rep(i,x,y) for(int i=x; i=y; i--) -#define yn(f) f?cout<<""YES\n"":cout<<""NO\n"" -#define syn(f) f?cout<<""Yes\n"":cout<<""No\n"" -#define print(x) for(auto l:x) cout<> n; - int sum = 0; - while(n>0){ - int t = n % 10; - if(t == 2){ - twos++; - } - if(t == 3){ - threes++; - } - sum += t; - n/=10; - } - - int k = sum % 9; - - if(k==0){ - cout << ""YES"" << endl; - return; - } - - rep(i, 0, twos+1){ - rep(j, 0, threes+1){ - if((k + 2*i + 6*j)%9 == 0){ - cout << ""YES "" << endl; - return; - } - } - } - - cout << ""NO"" << endl; - -} - -int32_t main(){ - fastio(); - int t = 1; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",1 -coder_on_earth,2050C - Uninteresting Number,c++23 ,295977287,295975814,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -void solve(){ - long long sum=0; - long long two=0,three=0; - string s; - cin>>s; - int len=s.length(); - for(int i=0;i=4)||(three>=1&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==2&&(two>=8||(three>=1&&two>=5)||(three>=2&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==3&&(three>=1||two>=3)){ - cout<<""YES""<<""\n""; - return; - } - if(mod==4&&((two>=7)||(three>=1&&two>=4)||(three>=2&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==5&&two>=2){ - cout<<""YES""<<""\n""; - return; - } - if(mod==6&&((two>=6)||(three>=1&&two>=3)||(three>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==7&&two>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==8&&((two>=5)||(three>=1&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - - cout<<""NO\n""; -} -int main() { - std::ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -void solve(){ - long long sum=0; - long long two=0,three=0; - string s; - cin>>s; - int len=s.length(); - for(int i=0;i=1&&three>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==3&&three>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==4&&((two>=7)||(three==1&&two>=4)||(three==2&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==5&&two>=2){ - cout<<""YES""<<""\n""; - return; - } - if(mod==6&&((two>=6)||(three==1&&two>=3)||(three>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==7&&two>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==8&&((two>=5)||(three==1&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - - cout<<""NO\n""; -} -int main() { - std::ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",1 -_Jade_,2050C - Uninteresting Number,c++17 ,297804350,297802717,"#include - -using namespace std; - -void solve() -{ - string s; - cin >> s; - int sum = 0; - int two_sum = 0; - int three_sum = 0; - for (int i = 0; i < s.length(); i++) - { - sum += s[i] - '0'; - if (s[i] - '0' == 2) - { - two_sum += 2; - } - if (s[i] - '0' == 3) - { - three_sum += 6; - } - } - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - int fire = 9 - (sum % 9); - while (fire <= two_sum + three_sum) - { - if (fire % 2 != 0) - { - fire += 9; - continue; - } - int temp_fire = fire; - int temp_two = two_sum; - int temp_three = three_sum; - while (temp_three >= 6 && temp_fire >= 6) - { - temp_fire -= 6; - temp_three -= 6; - } - while (temp_two >= 2 && temp_fire >= 2) - { - temp_fire -= 2; - temp_two -= 2; - } - if (temp_fire == 0) - { - cout << ""YES"" << endl; - return; - } - fire += 18; - } - cout << ""NO"" << endl; - return; -} -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - int INP; - cin >> INP; - while (INP--) - { - solve(); - } - return 0; -}","#include - -using namespace std; - -void solve() -{ - string s; - cin >> s; - int sum; - int two_sum = 0; - int three_sum = 0; - for (int i = 0; i < s.length(); i++) - { - sum += s[i] - '0'; - if (s[i] - '0' == 2) - { - two_sum += 2; - } - if (s[i] - '0' == 3) - { - three_sum += 6; - } - } - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - return; - } - int fire = 9 - (sum % 9); - while (fire < two_sum + three_sum) - { - if (fire % 2 != 0) - { - fire += 9; - continue; - } - int temp_fire = fire; - int temp_two = two_sum; - int temp_three = three_sum; - while (temp_three && temp_fire) - { - temp_fire -= 6; - temp_three -= 6; - } - while (temp_two && temp_fire) - { - temp_fire -= 2; - temp_two -= 2; - } - if (temp_fire == 0) - { - cout << ""YES"" << endl; - return; - } - fire += 18; - } - cout << ""NO"" << endl; - return; -} -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - int INP; - cin >> INP; - while (INP--) - { - solve(); - } - return 0; -}",1 -Pratywarrior,2050C - Uninteresting Number,c++17 ,298086105,298089352,"#include -using namespace std; -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define f(i,a,b) for(ll i=a;i=b;i--) -#define fc(i,a,b,c) for(ll i=a;i=b;i=i-c) -#define fi(n) f(i,0,n) -#define fj(n) f(j,0,n) -#define fastfast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; -typedef pair pii; -typedef vector vi; -typedef vector> vvi; -typedef vector vll; -typedef pair pll; -typedef vector> vvll; -void yes(){cout << ""YES"" << endl;} -void no(){cout << ""NO"" << endl;} -void print(ll t) {cout << t << endl;} -void print(int t) {cout << t << endl;} -void print(string t) {cout << t << endl;} -void print(char t) {cout << t << endl;} -void print(lld t) {cout << t << endl;} -void print(double t) {cout << t << endl;} -void print(ull t) {cout << t << endl;} -void prn(ll n) -{ - fi(n) - { - cout<0) - { - ld=n&1; - if(ld==1) p=p*a; - a=a*a; - n=n>>1; - } - return p; -} - -class DisjointSet -{ -public: - vll size,parent; - DisjointSet(ll n) - { - size.resize(n+1,1); - parent.resize(n+1,0); - for(int i=0;i> t; - - while(t--){ - ll n; - cin >> n; - - ll two = 0; - ll three = 0; - ll s=0; - - while (n > 0) { - ll d = n%10; - n /= 10; - if(d==2) two++; - if(d==3) three++; - s+=d; - } - - if(s%9==0){ - cout << ""YES"" << endl; - continue; - } - - ll want = 9-(s%9); - if(want%2!=0) want+=9; - - want /=2; - ll sum=0; - int flag = 0; - for (int i=0;i<=two;i++) { - for (int j=0;j<=three;j++) { - if ((sum+i+j*3) == want) { - flag=1; - break; - } - } - if(flag==1)break; - } - if(flag==1){ - print(""YES""); - continue; - } - print(""NO""); - } - - - - return 0; -}","#include -using namespace std; -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define f(i,a,b) for(ll i=a;i=b;i--) -#define fc(i,a,b,c) for(ll i=a;i=b;i=i-c) -#define fi(n) f(i,0,n) -#define fj(n) f(j,0,n) -#define fastfast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; -typedef pair pii; -typedef vector vi; -typedef vector> vvi; -typedef vector vll; -typedef pair pll; -typedef vector> vvll; -void yes(){cout << ""YES"" << endl;} -void no(){cout << ""NO"" << endl;} -void print(ll t) {cout << t << endl;} -void print(int t) {cout << t << endl;} -void print(string t) {cout << t << endl;} -void print(char t) {cout << t << endl;} -void print(lld t) {cout << t << endl;} -void print(double t) {cout << t << endl;} -void print(ull t) {cout << t << endl;} -void prn(ll n) -{ - fi(n) - { - cout<0) - { - ld=n&1; - if(ld==1) p=p*a; - a=a*a; - n=n>>1; - } - return p; -} - -class DisjointSet -{ -public: - vll size,parent; - DisjointSet(ll n) - { - size.resize(n+1,1); - parent.resize(n+1,0); - for(int i=0;i> t; - - while(t--){ - string st; - cin >> st; - - - int two = 0; - int three = 0; - int s=0; - - for(auto it:st){ - if(it=='2')two++; - if(it=='3')three++; - s+=(it-'0'); - s%=9; - } - - int flag = 0; - for (int i=0;i<=two;i++) { - for (int j=0;j<=three;j++) { - ll ts = s; - ts += 2*i+j*6; - if (ts%9 == 0) { - flag=1; - break; - } - } - if(flag==1)break; - } - if(flag==1){ - print(""YES""); - continue; - } - else print(""NO""); - } - - - - return 0; -}",2 -gmh123,2050C - Uninteresting Number,c++23 ,306538193,306535171,"#include - -using namespace std; - -#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - -using ll=long long; - -#define int long long - -signed main() - -{ - - IOS; - - int t=0; - - cin>>t; - - while(t--) - - { - - string s; - - cin>>s; - - int cnt2=0,cnt3=0,fg=0,ans=0; - - for(int i=0;i - -using namespace std; - -#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - -using ll=long long; - -#define int long long - -int res[100010]; - -signed main() - -{ - - IOS; - - int t=0; - - cin>>t; - - while(t--) - - { - - string s; - - cin>>s; - - int ans=0,fg=0; - - for(int i=0;i -const char nl = '\n'; -using ll = long long; -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - ll sum = 0; - ll cnt2 = 0; ll cnt3 = 0; - for (int i=0; i0) - sum += 2; - for (int j=0; j<=cnt3; j++) - { - if (j>0) - sum += 6; - if (sum%9 == 0) - { - cout << ""YES"" << nl; - validate = 1; - break; - } - } - sum -= 6*cnt3; - } - if (validate == 0) - cout << ""NO"" << nl; - } - return 0; -} -","#include -const char nl = '\n'; -using ll = long long; -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - ll sum = 0; - ll cnt2 = 0; ll cnt3 = 0; - for (int i=0; i0) - sum += 2; - for (int j=0; j<=cnt3; j++) - { - if (j>0) - sum += 6; - if (sum%9 == 0) - { - cout << ""YES"" << nl; - validate = 1; - break; - } - } - sum -= 6*cnt3; - if (validate == 1) - break; - } - if (validate == 0) - cout << ""NO"" << nl; - } - return 0; -} -",2 -QuantumAlgo#,2050C - Uninteresting Number,c++23 ,297672172,297674865,"/* MMMMMM - MMMMMMM - MMMMMMMM . - MMMMMMMMM - HMMMMMMMMMM - MMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM: - oMMMMMMMMMMMMMM - .MMMMMMMMMMMMMMo MMMMMMMMMMMMMMM M - MMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMM. oMMMMMMMMMMMMMMM.M - MMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: H - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . MMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMM - .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMM - MM. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .MMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - .MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - HMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM MMM.oMMMMMMM..MMMMMMMMM:MMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMM MM..MMMMMMM...MMMMMMM. MMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM ..MMMMMM...MMMMMM ..MMMMMMMMMMMMMMMMMMM - MMMMMMM:M.MMM.M.. MMMMM M..MMMMM...MMMMMMMMMMMMMMMMMM MMM - MMMM. .M..MM.M...MMMMMM..MMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . - MMMM..M....M.....:MMM .MMMMMM..MMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMM.M.. ...M......MM.MMMMM.......MHM.M .MMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMM..MM. . MMM.....MMMMMM.M.....M ..MM..M MMMMMMMMMMMMMMMMMMM - .MMMMMHMM. ..MMMM. MMM............o..... . .MMMMMMMMMMMMMMM - MMM. M... .........................M..:.MMMMMMMMMMMM - oMMM............ .................M.M.MMMMMMMMM - .....MM........................ . MMMMMM - M.....M.....................o.MM.MMMMMMMM. - M........................M.. ...MMMMMMMMMMMMMo - :....MMM..............MMM..oMMMMMMM - M...MMM.............MMMMMMM - .............:MMMMMMMM - M..... MMM.....M - M M............. - ................M - ooM.................MM MoMMMMMoooM - MMoooM......................MoooooooH..oMM - MHooooMoM.....................MMooooooM........M - oooooooMoooM......... o........MoooooooM............ - Mooooooooooo.......M.........Moooooooo:..............M - MooMoooooooooM...M........:Mooooooooooo:..............M - M..oooooooooooo .........Mooooooooooooooo..............M - M...Mooo:oooooooo.M....ooooooooooooooooooo..M...........M - ...oooooMoooooooM..Mooooooooooooo:oooooooM.M...........M. - M...ooooooMoo:ooooMoooooooooooooHoooooooooH:M. ...........: - M..MoooooooMoooooooooooooooooo:ooooooMooooMoM..............M - M..ooooooooooMooooooooooooooHoooooooMooHooooM...............M - ...ooooooooooooooooooo:MooooooooooooooMoMoooM................ - M...oooooooooooooooooooooooooooooooooooooMooMM................M - ...MooooooooooooooooooooooooooooooooooooooooMo ................ - ...MooooooooooooooooooooooooooooooooooooooooM M................M - M...ooooooooooooooooooooooooooooooooooooooooM ................M - ...MoooooooooooooooooooooooooooooooooooooooMM .:............... - .....MooooooooooooooooooooooooooooooooooooMoo .............M - M...... ooooooooooooooooooooooooooooooooooooM M..............M - M........MooooMMM MM MM MMMMMMMMMooooooooM M...............M - .........HM M: MM :MMMMMM M M............... - M..........M M MoM M M................M - M.........:M MoH M M M MooooHoooMM. M M...............M - M..........Moooo MMooM oooooMooooooooM M..............H - M.........MooooM Mooo : ooooooMooooMoooM M........ . .o.M - H.. .....ooooo oooo M MooooooooooooooM M... MMMMMMMMMMM - MMMMMMMMMMooooM M oooo . ooooooMooooooooM .MMMMMMMMMMMMMMM - MMMMMMMMMMooooH : ooooH oooooooooooooooo MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM Moooooooooooooooo .MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM MooooooooooooooooM MMMMMMMMMMMMMMM - MMMMMMMMMMoooM ooooM ooooooooooooooooo MMMMMMMMMMM:M - MMMMMMMMMMoooM MooooM oooooooooooMoooooo MH........... - . ......Mooo. MooooM oooooooooooooooooo M............M - M.M......oooo MooooM Moooooooooooooooooo: .........M..... - M.M.....Moooo MooooM ooooooooooooooooooM .M............ - .......MooooH MooooM oooooooooMoooooooooo M..o...M..o....M - .o....HMooooM MooooH MooooooooMooooooooooM .:M...M.......M - M..M.....MoooM :oooo: .MooooooooHooMoooooooooM M M... ..oM.M - M...M.:.Mooo. MMMMooooo oooooooooooMoooooooooooooM ....M. M - M:M..o.Moooooooooooooo MooooooooooooooMooooooooooooM .Mo - MooooooooooooooMooooooooooooMoMoooooooooooooo - Mooooooooooooooo:ooooooooooooooooooooooooooooo - ooooooooooooooooMooooooooooMoooooooooooooooooo - ooooooooooooooooMoooooooooooMooooooooooooooooHo - ooMooooooooooooooMoooooooooooooooooooooooooooMoM - MooMoooooooooooooo.ooooooooooooooooooooooooooo:oM - MoooooooooooooooooooooooooooooooooooooooooooooooM - MoooMooooooooooooooMooooooooooooooooooooooooooooo. - MoooMooooooooooooooMoooooooooooooooooooooooooMooooM - MooooooooooooooooooMoooooooooooooooooooooooooMoooooM - MooooMoooooooooooooMoooooooooooooooooooooooooMoHooooM - ooooooMooooooooooooooooooooooooooooooooooooooooMoMoooM - MooooooooooooooooooooMooooooooooooooooooooooooooMoooooH: - MoooooooMooooooooooooMoooooooooooooooooooooooooooooHoooM - MooooooooMoooooooooooMoooooooooooooooooooooooooMoooMooooM - Moooooooooooooooooooooooooooooooooooooooooooooo.oooMooooo - MoooooooooooooooooooooooooooooooooooooooooooooMoooooooooM - MooooooooooooooooooooMoooooooooooooooooooooooooooooooooM - MooooooooooooooooooooMHooooooooooooooooooooMoooo:ooooo - MMooooooooooooooooooMoMHoooooooooooooooooooooooMooooo - MMoooooooooooooooMMooo MMooooooooooooooooooooooooooM - MMMoooooooooooooMooooo oooooooooooooooooooooMooooo - MooMMoooooooooMoooMMoM ooooHooooooooooooooooMooooM - MooooMooooooMooooMoooM MoooooMoooooooooooooMooooo - ooooooMMooooooooMooooM MoooooooooMooooooooooooooM - HooooooMoooooooMooooM HoooooooHooMooooooooooooo - oooMoooooooooHoooM MoooooooooMoooooooooM - HooooooooooooHM MooooooooMMoooooooM - MMMMMMMMMMMMMM Moooooo:MooooHMM - MMMMMMM: ... MMMMMMMMMMMMMM - M............M MMMMMMMMM .... - M.MM.......... M.............M - M ..............MM M.............. - MMMMM............MMMM ..MMMMMMMM ....M - MMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMM...M - .MMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM - :MMMMMMMMMMMMMMMMMMH MMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM - HMMMMMM - */ -#include -using namespace std; -#define fo(i, n) for (ll i = 0; i < n; i++) -#define Fo(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define F first -#define S second -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector vll; -const ll MOD = 1e9 + 7; - - - -void solve(){ - // freopen(""convention2.in"",""r"",stdin); - // freopen(""convention2.out"",""w"",stdout); - string s;cin>>s; - ll cnt2 = 0,cnt3 = 0; - ll cnt = 0; - for(auto x:s){ - if(x!='3'){cnt += x-'0';} - if(x=='2'){cnt2++;} - else if(x=='3'){cnt3++;} - } - ll temp = cnt%9; - if(temp==0){ - yes; - } - else{ - temp = 9 - temp; - map m,m1; - fo(i,cnt3+1){ - m[(3*i)%9]++; - } - fo(i,cnt2+1){ - m1[(2*i)%9]++; - } - bool check = 0; - fo(i,cnt2+1){ - if(temp>=(2*i)%9){ - if(m[temp-(2*i)%9]){ - check = 1; - break; - } - } - else{ - if(m[9-temp+(2*i)%9]){ - check = 1; - break; - } - } - } - cnt2 = cnt3; - fo(i,cnt2+1){ - if(temp>=(3*i)%9){ - if(m1[temp-(3*i)%9]){ - check = 1; - break; - } - } - else{ - if(m1[9-temp+(3*i)%9]){ - check = 1; - break; - } - } - } - if(check){yes;} - else{no;}} -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - t = 1; - cin >> t; - while (t--) - { - solve(); - } - return 0; -} -","/* MMMMMM - MMMMMMM - MMMMMMMM . - MMMMMMMMM - HMMMMMMMMMM - MMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM: - oMMMMMMMMMMMMMM - .MMMMMMMMMMMMMMo MMMMMMMMMMMMMMM M - MMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMM. oMMMMMMMMMMMMMMM.M - MMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: H - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . MMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMM - .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMM - MM. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .MMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - .MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - HMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM MMM.oMMMMMMM..MMMMMMMMM:MMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMM MM..MMMMMMM...MMMMMMM. MMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM ..MMMMMM...MMMMMM ..MMMMMMMMMMMMMMMMMMM - MMMMMMM:M.MMM.M.. MMMMM M..MMMMM...MMMMMMMMMMMMMMMMMM MMM - MMMM. .M..MM.M...MMMMMM..MMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . - MMMM..M....M.....:MMM .MMMMMM..MMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMM.M.. ...M......MM.MMMMM.......MHM.M .MMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMM..MM. . MMM.....MMMMMM.M.....M ..MM..M MMMMMMMMMMMMMMMMMMM - .MMMMMHMM. ..MMMM. MMM............o..... . .MMMMMMMMMMMMMMM - MMM. M... .........................M..:.MMMMMMMMMMMM - oMMM............ .................M.M.MMMMMMMMM - .....MM........................ . MMMMMM - M.....M.....................o.MM.MMMMMMMM. - M........................M.. ...MMMMMMMMMMMMMo - :....MMM..............MMM..oMMMMMMM - M...MMM.............MMMMMMM - .............:MMMMMMMM - M..... MMM.....M - M M............. - ................M - ooM.................MM MoMMMMMoooM - MMoooM......................MoooooooH..oMM - MHooooMoM.....................MMooooooM........M - oooooooMoooM......... o........MoooooooM............ - Mooooooooooo.......M.........Moooooooo:..............M - MooMoooooooooM...M........:Mooooooooooo:..............M - M..oooooooooooo .........Mooooooooooooooo..............M - M...Mooo:oooooooo.M....ooooooooooooooooooo..M...........M - ...oooooMoooooooM..Mooooooooooooo:oooooooM.M...........M. - M...ooooooMoo:ooooMoooooooooooooHoooooooooH:M. ...........: - M..MoooooooMoooooooooooooooooo:ooooooMooooMoM..............M - M..ooooooooooMooooooooooooooHoooooooMooHooooM...............M - ...ooooooooooooooooooo:MooooooooooooooMoMoooM................ - M...oooooooooooooooooooooooooooooooooooooMooMM................M - ...MooooooooooooooooooooooooooooooooooooooooMo ................ - ...MooooooooooooooooooooooooooooooooooooooooM M................M - M...ooooooooooooooooooooooooooooooooooooooooM ................M - ...MoooooooooooooooooooooooooooooooooooooooMM .:............... - .....MooooooooooooooooooooooooooooooooooooMoo .............M - M...... ooooooooooooooooooooooooooooooooooooM M..............M - M........MooooMMM MM MM MMMMMMMMMooooooooM M...............M - .........HM M: MM :MMMMMM M M............... - M..........M M MoM M M................M - M.........:M MoH M M M MooooHoooMM. M M...............M - M..........Moooo MMooM oooooMooooooooM M..............H - M.........MooooM Mooo : ooooooMooooMoooM M........ . .o.M - H.. .....ooooo oooo M MooooooooooooooM M... MMMMMMMMMMM - MMMMMMMMMMooooM M oooo . ooooooMooooooooM .MMMMMMMMMMMMMMM - MMMMMMMMMMooooH : ooooH oooooooooooooooo MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM Moooooooooooooooo .MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM MooooooooooooooooM MMMMMMMMMMMMMMM - MMMMMMMMMMoooM ooooM ooooooooooooooooo MMMMMMMMMMM:M - MMMMMMMMMMoooM MooooM oooooooooooMoooooo MH........... - . ......Mooo. MooooM oooooooooooooooooo M............M - M.M......oooo MooooM Moooooooooooooooooo: .........M..... - M.M.....Moooo MooooM ooooooooooooooooooM .M............ - .......MooooH MooooM oooooooooMoooooooooo M..o...M..o....M - .o....HMooooM MooooH MooooooooMooooooooooM .:M...M.......M - M..M.....MoooM :oooo: .MooooooooHooMoooooooooM M M... ..oM.M - M...M.:.Mooo. MMMMooooo oooooooooooMoooooooooooooM ....M. M - M:M..o.Moooooooooooooo MooooooooooooooMooooooooooooM .Mo - MooooooooooooooMooooooooooooMoMoooooooooooooo - Mooooooooooooooo:ooooooooooooooooooooooooooooo - ooooooooooooooooMooooooooooMoooooooooooooooooo - ooooooooooooooooMoooooooooooMooooooooooooooooHo - ooMooooooooooooooMoooooooooooooooooooooooooooMoM - MooMoooooooooooooo.ooooooooooooooooooooooooooo:oM - MoooooooooooooooooooooooooooooooooooooooooooooooM - MoooMooooooooooooooMooooooooooooooooooooooooooooo. - MoooMooooooooooooooMoooooooooooooooooooooooooMooooM - MooooooooooooooooooMoooooooooooooooooooooooooMoooooM - MooooMoooooooooooooMoooooooooooooooooooooooooMoHooooM - ooooooMooooooooooooooooooooooooooooooooooooooooMoMoooM - MooooooooooooooooooooMooooooooooooooooooooooooooMoooooH: - MoooooooMooooooooooooMoooooooooooooooooooooooooooooHoooM - MooooooooMoooooooooooMoooooooooooooooooooooooooMoooMooooM - Moooooooooooooooooooooooooooooooooooooooooooooo.oooMooooo - MoooooooooooooooooooooooooooooooooooooooooooooMoooooooooM - MooooooooooooooooooooMoooooooooooooooooooooooooooooooooM - MooooooooooooooooooooMHooooooooooooooooooooMoooo:ooooo - MMooooooooooooooooooMoMHoooooooooooooooooooooooMooooo - MMoooooooooooooooMMooo MMooooooooooooooooooooooooooM - MMMoooooooooooooMooooo oooooooooooooooooooooMooooo - MooMMoooooooooMoooMMoM ooooHooooooooooooooooMooooM - MooooMooooooMooooMoooM MoooooMoooooooooooooMooooo - ooooooMMooooooooMooooM MoooooooooMooooooooooooooM - HooooooMoooooooMooooM HoooooooHooMooooooooooooo - oooMoooooooooHoooM MoooooooooMoooooooooM - HooooooooooooHM MooooooooMMoooooooM - MMMMMMMMMMMMMM Moooooo:MooooHMM - MMMMMMM: ... MMMMMMMMMMMMMM - M............M MMMMMMMMM .... - M.MM.......... M.............M - M ..............MM M.............. - MMMMM............MMMM ..MMMMMMMM ....M - MMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMM...M - .MMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM - :MMMMMMMMMMMMMMMMMMH MMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM - HMMMMMM - */ -#include -using namespace std; -#define fo(i, n) for (ll i = 0; i < n; i++) -#define Fo(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define F first -#define S second -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector vll; -const ll MOD = 1e9 + 7; - - - -void solve(ll t,ll t1){ - // freopen(""convention2.in"",""r"",stdin); - // freopen(""convention2.out"",""w"",stdout); - string s;cin>>s; - ll cnt2 = 0,cnt3 = 0; - ll cnt = 0; - for(auto x:s){ - if(x!='3'){cnt += x-'0';} - if(x=='2'){cnt2++;} - else if(x=='3'){cnt3++;} - } - ll temp = cnt%9; - if(temp==0){ - yes; - } - else{ - temp = 9 - temp; - map m,m1; - fo(i,cnt3+1){ - m[(3*i)%9]++; - } - fo(i,cnt2+1){ - m1[(2*i)%9]++; - } - bool check = 0; - fo(i,cnt2+1){ - if(temp>=(2*i)%9){ - if(m[temp-(2*i)%9]){ - check = 1; - break; - } - } - else{ - if(m[9+temp-(2*i)%9]){ - check = 1; - break; - } - } - } - cnt2 = cnt3; - fo(i,cnt2+1){ - if(temp>=(3*i)%9){ - if(m1[temp-(3*i)%9]){ - check = 1; - break; - } - } - else{ - if(m1[9-temp+(3*i)%9]){ - check = 1; - break; - } - } - } - if(check){yes;} - else{no;}} -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - t = 1; - cin >> t; - ll t1 = t; - while (t--) - { - solve(t,t1); - } - return 0; -} -",2 -enamulhoqmunna,2050C - Uninteresting Number,c++17 ,308698055,308698788,"#include - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - long long n,x=0,sum=0,c2=0,c3=0,num=0,diff=0,i,f=0,j,temp=0; - - string s; - - cin>>s; - - for(i=0;i - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - long long n,x=0,sum=0,c2=0,c3=0,num=0,diff=0,i,f=0,j,temp=0; - - string s; - - cin>>s; - - for(i=0;i99){ - - break; - - } - - else{ - - for(j=0;j<=c3;j++){ - - temp=i*2+j*6; - - if(temp>99){ - - break; - - } - - else if((temp+sum)%9==0){ - - f=1; - - break; - - } - - } - - if(f==1){ - - break; - - } - - } - - - - } - - - - if(f==0){ - - cout<<""NO""< -using namespace std; -int main(){ - int t;cin>>t; - while (t--) - { - int n;cin>>n; - int n_2=0,n_3=0; - string s=to_string(n); - // cout< -using namespace std; -int main(){ - int t;cin>>t; - while (t--) - { - string n;cin>>n; - int n_2=0,n_3=0; - // string s=to_string(n); - // cout< -#include -#include -#include -using namespace std; -int calculateX(int m, int n) { - - int k = static_cast(ceil(static_cast(m) / n)); - - int x = (k * n) - m; - - return x; -} -int main() { - int t; - cin>>t; - vectorv; - while(t--){ - long long int number; - int sum = 0; - - cin >> number; - int m=0,n=0; - while (number > 0) { - if(number%10==2){ - m++; - } - if(number%10==3){ - n++; - } - sum += number % 10; - number /= 10; - } - - int remi=sum%9; - if(m==0 && n==0){ - if(remi==0){ - v.push_back(""YES""); - } - else{ - v.push_back(""NO""); - } - - } - else{ - int rem=calculateX(remi,9); - int check=0; - for(int i=0;i<=m;i++){ - for(int j=0;j<=n;j++){ - if((sum+2*i+6*j) % 9 ==0){ - check=1; - break; - } - - } - } - if(check){ - v.push_back(""YES""); - } - else{ - v.push_back(""NO""); - } - - - - } - - - - } - - for(auto i:v){ - cout< -#include -#include -using namespace std; - -void solve() { - string input; - cin >> input; - - vector s; - for (char c : input) { - s.push_back(c - '0'); // Convert char to int and store in vector - } - - int sm = 0; - int twos = 0, threes = 0; - - for (int digit : s) { - sm += digit; - if (digit == 2) twos++; - if (digit == 3) threes++; - } - - for (int i = 0; i <= min(10, twos); i++) { - for (int j = 0; j <= min(10, threes); j++) { - if ((sm + i * 2 + j * 6) % 9 == 0) { - cout << ""YES"" << endl; - return; - } - } - } - - cout << ""NO"" << endl; -} - -int main() { - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",2 -coder_on_earth,2050C - Uninteresting Number,c++23 ,295976083,295977287,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -void solve(){ - long long sum=0; - long long two=0,three=0; - string s; - cin>>s; - int len=s.length(); - for(int i=0;i=4)||(three>=1&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==2&&two>=1&&three>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==3&&three>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==4&&((two>=7)||(three>=1&&two>=4)||(three>=2&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==5&&two>=2){ - cout<<""YES""<<""\n""; - return; - } - if(mod==6&&((two>=6)||(three>=1&&two>=3)||(three>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==7&&two>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==8&&((two>=5)||(three>=1&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - - cout<<""NO\n""; -} -int main() { - std::ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -void solve(){ - long long sum=0; - long long two=0,three=0; - string s; - cin>>s; - int len=s.length(); - for(int i=0;i=4)||(three>=1&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==2&&(two>=8||(three>=1&&two>=5)||(three>=2&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==3&&(three>=1||two>=3)){ - cout<<""YES""<<""\n""; - return; - } - if(mod==4&&((two>=7)||(three>=1&&two>=4)||(three>=2&&two>=1))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==5&&two>=2){ - cout<<""YES""<<""\n""; - return; - } - if(mod==6&&((two>=6)||(three>=1&&two>=3)||(three>=2))){ - cout<<""YES""<<""\n""; - return; - } - if(mod==7&&two>=1){ - cout<<""YES""<<""\n""; - return; - } - if(mod==8&&((two>=5)||(three>=1&&two>=2))){ - cout<<""YES""<<""\n""; - return; - } - - cout<<""NO\n""; -} -int main() { - std::ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",2 -The_Blue_Apple#,2050C - Uninteresting Number,c++17 ,307566611,307566479,"#include - -#include - -#include - -using namespace __gnu_pbds; - -using namespace std; - -#define ll long long - -#define dbg cout - -#define yes cout <<""YES""<>a[j]; - -#define all(v) v.begin(),v.end() - -#define out(a) for(int i=0;i using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - - - -string to_binary(ll n) { - - if (n == 0) return ""0""; - - string r; - - while (n != 0) { - - r = (n % 2 == 0 ? ""0"" : ""1"") + r; - - n /= 2; - - } - - return r; - -} - - - -ll to_decimal(string s) { - - reverse(s.begin(), s.end()); - - ll ct = 0; - - for (ll i = 0; i < s.size(); i++) { - - if (s[i] == '1') - - ct += (1ll << i); - - } - - return ct; - -} - - - -vector SieveOfEratosthenes(ll n) { - - vector prime(n + 1, 1); - - for (ll p = 2; p * p <= n; p++) { - - if (prime[p] == true) { - - for (ll i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - prime[1] = prime[0] = 0; - - return prime; - -} - - - -long long binpow(long long a, long long b) { - - long long res = 1; - - while (b > 0) { - - if (b & 1) - - res = res * a; - - a = a * a; - - b >>= 1; - - } - - return res; - -} - - - -ll binpow_modulo(ll a, ll b, ll mod) { - - ll res = 1; - - while (b > 0) { - - if (b % 2 == 1) - - res = (res * a) % mod; - - a = (a * a) % mod; - - b = b / 2; - - } - - return res; - -} - - - -ll fact(ll n, ll mod) { - - ll ans = 1; - - for (ll i = 2; i <= n; i++) - - ans = ((ans % mod) * (i % mod) + mod) % mod; - - ans %= mod; - - return ans; - -} - - - -ll ncr(ll n, ll r, ll mod) { - - if(n arr) { - - // nlogn - - ll lcm = arr[0]; - - for (ll i = 1; i < arr.size(); i++) { - - ll num1 = lcm; - - ll num2 = arr[i]; - - ll gcd_val = __gcd(num1, num2); - - lcm = (lcm / gcd_val) * arr[i]; - - } - - return lcm; - -} - - - -ll lcm(ll a, ll b) { - - return (a / (__gcd(a, b))) * b; - -} - -int fun(int ind, int mm, string &s,vector>&dp){ - - if(ind==s.size()){ - - if(mm==0) return 1; - - return 0; - - } - - if(dp[ind][mm]!=-1) return dp[ind][mm]; - - int pick=0,nonpick=0; - - if(s[ind]=='2'){ - - pick = fun(ind+1,(mm+2)%9,s,dp); - - nonpick = fun(ind+1,mm,s,dp); - - } - - else if(s[ind]=='3'){ - - pick = fun(ind+1,(mm+6)%9,s,dp); - - nonpick = fun(ind+1,mm,s,dp); - - } - - else{ - - nonpick = fun(ind+1,mm,s,dp); - - } - - - - return dp[ind][mm] = pick||nonpick; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - - -ll TESTCASES; - -cin >> TESTCASES; - -while (TESTCASES--) { - -string s; - -cin >>s; - -int n = s.size(); - -vector>dp(n+1,vector(10,-1)); - -int mm =0; - -for(int i=0;i - -#include - -#include - -using namespace __gnu_pbds; - -using namespace std; - -#define ll long long - -#define dbg cout - -#define yes cout <<""YES""<>a[j]; - -#define all(v) v.begin(),v.end() - -#define out(a) for(int i=0;i using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - - - -string to_binary(ll n) { - - if (n == 0) return ""0""; - - string r; - - while (n != 0) { - - r = (n % 2 == 0 ? ""0"" : ""1"") + r; - - n /= 2; - - } - - return r; - -} - - - -ll to_decimal(string s) { - - reverse(s.begin(), s.end()); - - ll ct = 0; - - for (ll i = 0; i < s.size(); i++) { - - if (s[i] == '1') - - ct += (1ll << i); - - } - - return ct; - -} - - - -vector SieveOfEratosthenes(ll n) { - - vector prime(n + 1, 1); - - for (ll p = 2; p * p <= n; p++) { - - if (prime[p] == true) { - - for (ll i = p * p; i <= n; i += p) - - prime[i] = false; - - } - - } - - prime[1] = prime[0] = 0; - - return prime; - -} - - - -long long binpow(long long a, long long b) { - - long long res = 1; - - while (b > 0) { - - if (b & 1) - - res = res * a; - - a = a * a; - - b >>= 1; - - } - - return res; - -} - - - -ll binpow_modulo(ll a, ll b, ll mod) { - - ll res = 1; - - while (b > 0) { - - if (b % 2 == 1) - - res = (res * a) % mod; - - a = (a * a) % mod; - - b = b / 2; - - } - - return res; - -} - - - -ll fact(ll n, ll mod) { - - ll ans = 1; - - for (ll i = 2; i <= n; i++) - - ans = ((ans % mod) * (i % mod) + mod) % mod; - - ans %= mod; - - return ans; - -} - - - -ll ncr(ll n, ll r, ll mod) { - - if(n arr) { - - // nlogn - - ll lcm = arr[0]; - - for (ll i = 1; i < arr.size(); i++) { - - ll num1 = lcm; - - ll num2 = arr[i]; - - ll gcd_val = __gcd(num1, num2); - - lcm = (lcm / gcd_val) * arr[i]; - - } - - return lcm; - -} - - - -ll lcm(ll a, ll b) { - - return (a / (__gcd(a, b))) * b; - -} - -int fun(int ind, int mm, string s,vector>&dp){ - - if(ind==s.size()){ - - if(mm==0) return 1; - - return 0; - - } - - if(dp[ind][mm]!=-1) return dp[ind][mm]; - - int pick=0,nonpick=0; - - if(s[ind]=='2'){ - - pick = fun(ind+1,(mm+2)%9,s,dp); - - nonpick = fun(ind+1,mm,s,dp); - - } - - else if(s[ind]=='3'){ - - pick = fun(ind+1,(mm+6)%9,s,dp); - - nonpick = fun(ind+1,mm,s,dp); - - } - - else{ - - nonpick = fun(ind+1,mm,s,dp); - - } - - - - return dp[ind][mm] = pick||nonpick; - -} - - - - - -int main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - - -ll TESTCASES; - -cin >> TESTCASES; - -while (TESTCASES--) { - -string s; - -cin >>s; - -int n = s.size(); - -vector>dp(n+1,vector(10,-1)); - -int mm =0; - -for(int i=0;i -#include -using namespace std; - - - -int main() { - istream& fin = cin; - ostream& fout = cout; - - int t; - fin >> t; - int two, three; - long long sum; - string number; - int temp; - int offset = int('0'); - for (int i=0; i> number; - for (char ch: number) { - if (ch == '\n') break; - temp = int(ch) - offset; - if (temp == 2) two++; - if (temp == 3) three++; - sum += temp; - } - bool possible = sum % 9 == 0; - sum %= 9; - // fout << (sum % 9) << "" "" << two << "" "" << three << "" "" << endl; - for (int j=0; j<=two; j++) { - if (possible) break; - if (j == 9) {possible = true; break;} - for (int k=0; k<=three; k++) { - if (possible) break; - if (k == 9) {possible = true; break;} - if ((sum + 2*j + 6*k) % 9 == 0) possible = true; - } - } - fout << (possible ? ""YES"" : ""NO"") << ""\n""; - } -}","#include -#include -using namespace std; - - - -int main() { - istream& fin = cin; - ostream& fout = cout; - - int t; - fin >> t; - int two, three; - long long sum; - string number; - int temp; - int offset = int('0'); - for (int i=0; i> number; - for (char ch: number) { - if (ch == '\n') break; - temp = int(ch) - offset; - if (temp == 2) two++; - if (temp == 3) three++; - sum += temp; - } - bool possible = sum % 9 == 0; - sum %= 9; - // fout << (sum % 9) << "" "" << two << "" "" << three << "" "" << endl; - for (int j=0; j<=two; j++) { - if (possible) break; - if (j == 9) break; - for (int k=0; k<=three; k++) { - if (possible) break; - if (k == 9) break; - if ((sum + 2*j + 6*k) % 9 == 0) possible = true; - } - } - fout << (possible ? ""YES"" : ""NO"") << ""\n""; - } -}",2 -lakshcodes01,2050C - Uninteresting Number,c++23 ,298735702,298734218,"#include -using namespace std; - -#define int long long - -void solve(){ - string n; - cin>>n; - - - int sum = 0; - int find2 = 0; - int find3 = 0; - - - for(auto it:n){ - sum += (it-'0'); - if((it-'0') == 2) find2++; - if((it-'0') == 3) find3++; - } - - for(int i=0;i<=find2;i++){ - for(int j=0;j<=find3;j++){ - if((sum + 6*j + 2*i)%9 == 0){ - cout<<""YES\n""; - return; - } - } - } - cout<<""NO\n""; - - - - - -} - - -signed main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--){ - solve(); - } -}","#include -using namespace std; - -#define int long long - - -int get_sum(int n){ - int sum = 0; - while(n>0){ - sum += (n%10); - n=n/10; - } - return sum; -} - - -int get_two(int n){ - int a = 0; - while(n>0){ - if(n%10 == 2) a++; - n=n/10; - } - return a; -} - -int get_three(int n){ - int a = 0; - while(n>0){ - if(n%10 == 3) a++; - n=n/10; - } - return a; -} - - -void solve(){ - int n; - cin>>n; - int sum = get_sum(n); - int left = (((sum+8)/9)*9) - sum; - - - // cout<<""LEFT IS: ""<=5 || (find3>=1 && find2>=2)){ - cout<<""YES\n""; - return; - } - } - else if(left == 2 && find2>=1){ - cout<<""YES\n""; - return; - } - else if(left == 3){ - if(find3>=2 || (find2>=6) || (find3>=1 && find2>=3)){ - cout<<""YES\n""; - return; - } - } - else if(left == 4 && find2>=2){ - cout<<""YES\n""; - return; - - }else if(left == 5){ - //make 14 - if(find2>=7 || (find3>=2 && find2>=1) || (find3>=1 && find2>=4)){ - cout<<""YES\n""; - return; - } - } - else if(left == 6 && (find2>=3 || find3>=1) ){ - cout<<""YES\n""; - return; - - } - else if(left == 7){ - if(find2>=8 || (find3>=2 && find2>=2) || (find2>=1 && find2>=5)){ - cout<<""YES\n""; - return; - } - } - - else if(left == 8 && ( find2>=4 || (find3>=1 && find2>=1)) ){ - cout<<""YES\n""; - return; - - } - cout<<""NO\n""; - - - - - -} - - -signed main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--){ - solve(); - } -}",1 -S13837568048,2050C - Uninteresting Number,c++20 ,297639633,297639852,"#include -using namespace std; -//#define int long long -#define endl ""\n"" - -void slove() -{ - string s; - int a = 0,b = 0; - int sum = 0; - cin >> s; - for(int i = 0;i < s.size();i++) - { - sum += s[i] - '0'; - if(s[i] == '2') a++; - else if(s[i] == '3') b++; - } - - for(int i = 0; i <= min(5,a);i++) - { - for(int j = 0; j <= min(5,b); j++) - { - int k = i*2 + 6*j; - if((sum + k)%9 == 0) - { - cout << ""YES"" << endl; - return ; - } - } - } - cout << ""NO"" << endl; -} - -signed main() -{ - int T = 1; - cin >> T; - while(T--) slove(); - return 0; -}","#include -using namespace std; -#define int long long -#define endl ""\n"" - -void slove() -{ - string s; - int a = 0,b = 0; - int sum = 0; - cin >> s; - for(int i = 0;i < s.size();i++) - { - sum += s[i] - '0'; - if(s[i] == '2') a++; - else if(s[i] == '3') b++; - } - - for(int i = 0; i <= min(8ll,a);i++) - { - for(int j = 0; j <= min(8ll,b); j++) - { - int k = i*2 + 6*j; - if((sum + k)%9 == 0) - { - cout << ""YES"" << endl; - return ; - } - } - } - cout << ""NO"" << endl; -} - -signed main() -{ - int T = 1; - cin >> T; - while(T--) slove(); - return 0; -}",2 -UuuuuxxxOwO,2050C - Uninteresting Number,c++17 ,298351719,298351886,"#include -using namespace std; - -void accelerate() -{ - ios::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -void solve() { - string n; - cin >> n; - int sum = 0; - int two = 0; - int three = 0; - for (auto c : n) { - int d = c - '0'; - sum = (sum + d) % 9; - if (d == 2) two++; - else if (d == 3) three++; - } - int dp[9] = {0}; - dp[sum] = 1; - for (int i = 0; i < two || i < 8; i++) { - sum = (sum + 2) % 9; - dp[sum] = 1; - } - if (dp[0] || (dp[3] && three >= 1) || (dp[6] && three >= 2)) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } -} - -signed main() { - // accelerate(); - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - return 0; -} -","#include -using namespace std; - -void accelerate() -{ - ios::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -void solve() { - string n; - cin >> n; - int sum = 0; - int two = 0; - int three = 0; - for (auto c : n) { - int d = c - '0'; - sum = (sum + d) % 9; - if (d == 2) two++; - else if (d == 3) three++; - } - int dp[9] = {0}; - dp[sum] = 1; - for (int i = 0; i < two && i < 8; i++) { - sum = (sum + 2) % 9; - dp[sum] = 1; - } - if (dp[0] || (dp[3] && three >= 1) || (dp[6] && three >= 2)) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } -} - -signed main() { - // accelerate(); - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - return 0; -} -",2 -AlgoRubik,2050C - Uninteresting Number,c++23 ,297673141,297674815,"/* MMMMMM - MMMMMMM - MMMMMMMM . - MMMMMMMMM - HMMMMMMMMMM - MMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM: - oMMMMMMMMMMMMMM - .MMMMMMMMMMMMMMo MMMMMMMMMMMMMMM M - MMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMM. oMMMMMMMMMMMMMMM.M - MMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: H - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . MMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMM - .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMM - MM. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .MMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - .MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - HMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM MMM.oMMMMMMM..MMMMMMMMM:MMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMM MM..MMMMMMM...MMMMMMM. MMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM ..MMMMMM...MMMMMM ..MMMMMMMMMMMMMMMMMMM - MMMMMMM:M.MMM.M.. MMMMM M..MMMMM...MMMMMMMMMMMMMMMMMM MMM - MMMM. .M..MM.M...MMMMMM..MMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . - MMMM..M....M.....:MMM .MMMMMM..MMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMM.M.. ...M......MM.MMMMM.......MHM.M .MMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMM..MM. . MMM.....MMMMMM.M.....M ..MM..M MMMMMMMMMMMMMMMMMMM - .MMMMMHMM. ..MMMM. MMM............o..... . .MMMMMMMMMMMMMMM - MMM. M... .........................M..:.MMMMMMMMMMMM - oMMM............ .................M.M.MMMMMMMMM - .....MM........................ . MMMMMM - M.....M.....................o.MM.MMMMMMMM. - M........................M.. ...MMMMMMMMMMMMMo - :....MMM..............MMM..oMMMMMMM - M...MMM.............MMMMMMM - .............:MMMMMMMM - M..... MMM.....M - M M............. - ................M - ooM.................MM MoMMMMMoooM - MMoooM......................MoooooooH..oMM - MHooooMoM.....................MMooooooM........M - oooooooMoooM......... o........MoooooooM............ - Mooooooooooo.......M.........Moooooooo:..............M - MooMoooooooooM...M........:Mooooooooooo:..............M - M..oooooooooooo .........Mooooooooooooooo..............M - M...Mooo:oooooooo.M....ooooooooooooooooooo..M...........M - ...oooooMoooooooM..Mooooooooooooo:oooooooM.M...........M. - M...ooooooMoo:ooooMoooooooooooooHoooooooooH:M. ...........: - M..MoooooooMoooooooooooooooooo:ooooooMooooMoM..............M - M..ooooooooooMooooooooooooooHoooooooMooHooooM...............M - ...ooooooooooooooooooo:MooooooooooooooMoMoooM................ - M...oooooooooooooooooooooooooooooooooooooMooMM................M - ...MooooooooooooooooooooooooooooooooooooooooMo ................ - ...MooooooooooooooooooooooooooooooooooooooooM M................M - M...ooooooooooooooooooooooooooooooooooooooooM ................M - ...MoooooooooooooooooooooooooooooooooooooooMM .:............... - .....MooooooooooooooooooooooooooooooooooooMoo .............M - M...... ooooooooooooooooooooooooooooooooooooM M..............M - M........MooooMMM MM MM MMMMMMMMMooooooooM M...............M - .........HM M: MM :MMMMMM M M............... - M..........M M MoM M M................M - M.........:M MoH M M M MooooHoooMM. M M...............M - M..........Moooo MMooM oooooMooooooooM M..............H - M.........MooooM Mooo : ooooooMooooMoooM M........ . .o.M - H.. .....ooooo oooo M MooooooooooooooM M... MMMMMMMMMMM - MMMMMMMMMMooooM M oooo . ooooooMooooooooM .MMMMMMMMMMMMMMM - MMMMMMMMMMooooH : ooooH oooooooooooooooo MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM Moooooooooooooooo .MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM MooooooooooooooooM MMMMMMMMMMMMMMM - MMMMMMMMMMoooM ooooM ooooooooooooooooo MMMMMMMMMMM:M - MMMMMMMMMMoooM MooooM oooooooooooMoooooo MH........... - . ......Mooo. MooooM oooooooooooooooooo M............M - M.M......oooo MooooM Moooooooooooooooooo: .........M..... - M.M.....Moooo MooooM ooooooooooooooooooM .M............ - .......MooooH MooooM oooooooooMoooooooooo M..o...M..o....M - .o....HMooooM MooooH MooooooooMooooooooooM .:M...M.......M - M..M.....MoooM :oooo: .MooooooooHooMoooooooooM M M... ..oM.M - M...M.:.Mooo. MMMMooooo oooooooooooMoooooooooooooM ....M. M - M:M..o.Moooooooooooooo MooooooooooooooMooooooooooooM .Mo - MooooooooooooooMooooooooooooMoMoooooooooooooo - Mooooooooooooooo:ooooooooooooooooooooooooooooo - ooooooooooooooooMooooooooooMoooooooooooooooooo - ooooooooooooooooMoooooooooooMooooooooooooooooHo - ooMooooooooooooooMoooooooooooooooooooooooooooMoM - MooMoooooooooooooo.ooooooooooooooooooooooooooo:oM - MoooooooooooooooooooooooooooooooooooooooooooooooM - MoooMooooooooooooooMooooooooooooooooooooooooooooo. - MoooMooooooooooooooMoooooooooooooooooooooooooMooooM - MooooooooooooooooooMoooooooooooooooooooooooooMoooooM - MooooMoooooooooooooMoooooooooooooooooooooooooMoHooooM - ooooooMooooooooooooooooooooooooooooooooooooooooMoMoooM - MooooooooooooooooooooMooooooooooooooooooooooooooMoooooH: - MoooooooMooooooooooooMoooooooooooooooooooooooooooooHoooM - MooooooooMoooooooooooMoooooooooooooooooooooooooMoooMooooM - Moooooooooooooooooooooooooooooooooooooooooooooo.oooMooooo - MoooooooooooooooooooooooooooooooooooooooooooooMoooooooooM - MooooooooooooooooooooMoooooooooooooooooooooooooooooooooM - MooooooooooooooooooooMHooooooooooooooooooooMoooo:ooooo - MMooooooooooooooooooMoMHoooooooooooooooooooooooMooooo - MMoooooooooooooooMMooo MMooooooooooooooooooooooooooM - MMMoooooooooooooMooooo oooooooooooooooooooooMooooo - MooMMoooooooooMoooMMoM ooooHooooooooooooooooMooooM - MooooMooooooMooooMoooM MoooooMoooooooooooooMooooo - ooooooMMooooooooMooooM MoooooooooMooooooooooooooM - HooooooMoooooooMooooM HoooooooHooMooooooooooooo - oooMoooooooooHoooM MoooooooooMoooooooooM - HooooooooooooHM MooooooooMMoooooooM - MMMMMMMMMMMMMM Moooooo:MooooHMM - MMMMMMM: ... MMMMMMMMMMMMMM - M............M MMMMMMMMM .... - M.MM.......... M.............M - M ..............MM M.............. - MMMMM............MMMM ..MMMMMMMM ....M - MMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMM...M - .MMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM - :MMMMMMMMMMMMMMMMMMH MMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM - HMMMMMM - */ -#include -using namespace std; -#define fo(i, n) for (ll i = 0; i < n; i++) -#define Fo(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define F first -#define S second -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector vll; -const ll MOD = 1e9 + 7; - - - -void solve(){ - // freopen(""convention2.in"",""r"",stdin); - // freopen(""convention2.out"",""w"",stdout); - string s;cin>>s; - ll cnt2 = 0,cnt3 = 0; - ll cnt = 0; - for(auto x:s){ - if(x!='3'){cnt += x-'0';} - if(x=='2'){cnt2++;} - else if(x=='3'){cnt3++;} - } - ll temp = cnt%9; - if(temp==0){ - yes; - } - else{ - temp = 9 - temp; - map m,m1; - fo(i,cnt3+1){ - m[(3*i)%9]++; - } - fo(i,cnt2+1){ - m1[(2*i)%9]++; - } - bool check = 0; - fo(i,cnt2+1){ - if(temp>=(2*i)%9){ - if(m[temp-(2*i)%9]){ - check = 1; - break; - } - } - else{ - if(m[9-temp+(2*i)%9]){ - check = 1; - break; - } - } - } - cnt2 = cnt3; - fo(i,cnt2+1){ - if(temp>=(3*i)%9){ - if(m1[temp-(3*i)%9]){ - check = 1; - break; - } - } - else{ - if(m1[9-temp+(3*i)%9]){ - check = 1; - break; - } - } - } - if(check){yes;} - else{no;}} -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - t = 1; - cin >> t; - while (t--) - { - solve(); - } - return 0; -} -","/* MMMMMM - MMMMMMM - MMMMMMMM . - MMMMMMMMM - HMMMMMMMMMM - MMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM M - MMMMMMMMMMMMM: - oMMMMMMMMMMMMMM - .MMMMMMMMMMMMMMo MMMMMMMMMMMMMMM M - MMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMM. oMMMMMMMMMMMMMMM.M - MMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM: H - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . MMM - MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMM - .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMM - MM. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM M MMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM .MMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MM MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - .MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - HMMMMMMMMMMMMMMMMMMMMM.MMMMMMMMM.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM MMM.oMMMMMMM..MMMMMMMMM:MMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMM MM..MMMMMMM...MMMMMMM. MMMMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM ..MMMMMM...MMMMMM ..MMMMMMMMMMMMMMMMMMM - MMMMMMM:M.MMM.M.. MMMMM M..MMMMM...MMMMMMMMMMMMMMMMMM MMM - MMMM. .M..MM.M...MMMMMM..MMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM . - MMMM..M....M.....:MMM .MMMMMM..MMMMMMM...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM - MMM.M.. ...M......MM.MMMMM.......MHM.M .MMMMMMMMMMMMMMMMMMMMMMMMM - MMMMMMMM..MM. . MMM.....MMMMMM.M.....M ..MM..M MMMMMMMMMMMMMMMMMMM - .MMMMMHMM. ..MMMM. MMM............o..... . .MMMMMMMMMMMMMMM - MMM. M... .........................M..:.MMMMMMMMMMMM - oMMM............ .................M.M.MMMMMMMMM - .....MM........................ . MMMMMM - M.....M.....................o.MM.MMMMMMMM. - M........................M.. ...MMMMMMMMMMMMMo - :....MMM..............MMM..oMMMMMMM - M...MMM.............MMMMMMM - .............:MMMMMMMM - M..... MMM.....M - M M............. - ................M - ooM.................MM MoMMMMMoooM - MMoooM......................MoooooooH..oMM - MHooooMoM.....................MMooooooM........M - oooooooMoooM......... o........MoooooooM............ - Mooooooooooo.......M.........Moooooooo:..............M - MooMoooooooooM...M........:Mooooooooooo:..............M - M..oooooooooooo .........Mooooooooooooooo..............M - M...Mooo:oooooooo.M....ooooooooooooooooooo..M...........M - ...oooooMoooooooM..Mooooooooooooo:oooooooM.M...........M. - M...ooooooMoo:ooooMoooooooooooooHoooooooooH:M. ...........: - M..MoooooooMoooooooooooooooooo:ooooooMooooMoM..............M - M..ooooooooooMooooooooooooooHoooooooMooHooooM...............M - ...ooooooooooooooooooo:MooooooooooooooMoMoooM................ - M...oooooooooooooooooooooooooooooooooooooMooMM................M - ...MooooooooooooooooooooooooooooooooooooooooMo ................ - ...MooooooooooooooooooooooooooooooooooooooooM M................M - M...ooooooooooooooooooooooooooooooooooooooooM ................M - ...MoooooooooooooooooooooooooooooooooooooooMM .:............... - .....MooooooooooooooooooooooooooooooooooooMoo .............M - M...... ooooooooooooooooooooooooooooooooooooM M..............M - M........MooooMMM MM MM MMMMMMMMMooooooooM M...............M - .........HM M: MM :MMMMMM M M............... - M..........M M MoM M M................M - M.........:M MoH M M M MooooHoooMM. M M...............M - M..........Moooo MMooM oooooMooooooooM M..............H - M.........MooooM Mooo : ooooooMooooMoooM M........ . .o.M - H.. .....ooooo oooo M MooooooooooooooM M... MMMMMMMMMMM - MMMMMMMMMMooooM M oooo . ooooooMooooooooM .MMMMMMMMMMMMMMM - MMMMMMMMMMooooH : ooooH oooooooooooooooo MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM Moooooooooooooooo .MMMMMMMMMMMMMMM - MMMMMMMMMMoooo ooooM MooooooooooooooooM MMMMMMMMMMMMMMM - MMMMMMMMMMoooM ooooM ooooooooooooooooo MMMMMMMMMMM:M - MMMMMMMMMMoooM MooooM oooooooooooMoooooo MH........... - . ......Mooo. MooooM oooooooooooooooooo M............M - M.M......oooo MooooM Moooooooooooooooooo: .........M..... - M.M.....Moooo MooooM ooooooooooooooooooM .M............ - .......MooooH MooooM oooooooooMoooooooooo M..o...M..o....M - .o....HMooooM MooooH MooooooooMooooooooooM .:M...M.......M - M..M.....MoooM :oooo: .MooooooooHooMoooooooooM M M... ..oM.M - M...M.:.Mooo. MMMMooooo oooooooooooMoooooooooooooM ....M. M - M:M..o.Moooooooooooooo MooooooooooooooMooooooooooooM .Mo - MooooooooooooooMooooooooooooMoMoooooooooooooo - Mooooooooooooooo:ooooooooooooooooooooooooooooo - ooooooooooooooooMooooooooooMoooooooooooooooooo - ooooooooooooooooMoooooooooooMooooooooooooooooHo - ooMooooooooooooooMoooooooooooooooooooooooooooMoM - MooMoooooooooooooo.ooooooooooooooooooooooooooo:oM - MoooooooooooooooooooooooooooooooooooooooooooooooM - MoooMooooooooooooooMooooooooooooooooooooooooooooo. - MoooMooooooooooooooMoooooooooooooooooooooooooMooooM - MooooooooooooooooooMoooooooooooooooooooooooooMoooooM - MooooMoooooooooooooMoooooooooooooooooooooooooMoHooooM - ooooooMooooooooooooooooooooooooooooooooooooooooMoMoooM - MooooooooooooooooooooMooooooooooooooooooooooooooMoooooH: - MoooooooMooooooooooooMoooooooooooooooooooooooooooooHoooM - MooooooooMoooooooooooMoooooooooooooooooooooooooMoooMooooM - Moooooooooooooooooooooooooooooooooooooooooooooo.oooMooooo - MoooooooooooooooooooooooooooooooooooooooooooooMoooooooooM - MooooooooooooooooooooMoooooooooooooooooooooooooooooooooM - MooooooooooooooooooooMHooooooooooooooooooooMoooo:ooooo - MMooooooooooooooooooMoMHoooooooooooooooooooooooMooooo - MMoooooooooooooooMMooo MMooooooooooooooooooooooooooM - MMMoooooooooooooMooooo oooooooooooooooooooooMooooo - MooMMoooooooooMoooMMoM ooooHooooooooooooooooMooooM - MooooMooooooMooooMoooM MoooooMoooooooooooooMooooo - ooooooMMooooooooMooooM MoooooooooMooooooooooooooM - HooooooMoooooooMooooM HoooooooHooMooooooooooooo - oooMoooooooooHoooM MoooooooooMoooooooooM - HooooooooooooHM MooooooooMMoooooooM - MMMMMMMMMMMMMM Moooooo:MooooHMM - MMMMMMM: ... MMMMMMMMMMMMMM - M............M MMMMMMMMM .... - M.MM.......... M.............M - M ..............MM M.............. - MMMMM............MMMM ..MMMMMMMM ....M - MMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMM...M - .MMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM - :MMMMMMMMMMMMMMMMMMH MMMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMMMMM - MMMMMMMMMMMMMMM - HMMMMMM - */ -#include -using namespace std; -#define fo(i, n) for (ll i = 0; i < n; i++) -#define Fo(i, k, n) for (ll i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define F first -#define S second -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector vll; -const ll MOD = 1e9 + 7; - - - -void solve(ll t,ll t1){ - // freopen(""convention2.in"",""r"",stdin); - // freopen(""convention2.out"",""w"",stdout); - string s;cin>>s; - ll cnt2 = 0,cnt3 = 0; - ll cnt = 0; - for(auto x:s){ - if(x!='3'){cnt += x-'0';} - if(x=='2'){cnt2++;} - else if(x=='3'){cnt3++;} - } - ll temp = cnt%9; - if(temp==0){ - yes; - } - else{ - temp = 9 - temp; - map m,m1; - fo(i,cnt3+1){ - m[(3*i)%9]++; - } - fo(i,cnt2+1){ - m1[(2*i)%9]++; - } - bool check = 0; - fo(i,cnt2+1){ - if(temp>=(2*i)%9){ - if(m[temp-(2*i)%9]){ - check = 1; - break; - } - } - else{ - if(m[9+temp-(2*i)%9]){ - check = 1; - break; - } - } - } - cnt2 = cnt3; - fo(i,cnt2+1){ - if(temp>=(3*i)%9){ - if(m1[temp-(3*i)%9]){ - check = 1; - break; - } - } - else{ - if(m1[9-temp+(3*i)%9]){ - check = 1; - break; - } - } - } - if(check){yes;} - else{no;}} -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - t = 1; - cin >> t; - ll t1 = t; - while (t--) - { - solve(t,t1); - } - return 0; -} -",2 -Mavis,2050C - Uninteresting Number,c++17 ,297648165,297648008,"#include -using namespace std; - -#define int long long -#define vi vector -#define vs vector -#define vvi vector> -#define pii pair -#define vpii vector> -#define mii map -#define umii unordered_map - -#define ff first -#define ss second -#define rep(i, n) for(int i=0; i=0; i--) -#define pb push_back -#define aint(x) x.begin(),x.end() - -#define pyes cout << ""YES\n"" -#define pno cout << ""NO\n"" -#define pm1 cout << -1 << endl -#define p0 cout << 0 << endl -#define p1 cout << 1 << endl -#define out(x) cout<> s; - int n = s.size(), sum = 0; - - int cnt2 = 0, cnt3 = 0; - rep(i, n) { - sum += s[i] - '0'; - if (s[i] - '0' == 2) cnt2++; - if (s[i] - '0' == 3) cnt3++; - } - - sum %= 9; - int flag = 0; - - for (int i = 0; i <= min(cnt2, 1LL * 20); i++) { - for (int j = 0; j <= min(cnt3, 1LL * 20); j++) { - int temp = sum; - temp += i * 2 + j * 6; - if (temp % 9 == 0) { - cout << ""YES\n""; - return; - } - } - } - for (int i = 0; i < min(cnt2, 1LL * 20); i++) { - int temp = sum; - if ((temp + i * 2) % 9 == 0) { - pyes; - return; - } - } - for (int i = 0; i < min(cnt3, 1LL * 20); i++) { - int temp = sum; - if ((temp + i * 3) % 9 == 0) { - pyes; - return; - } - } - pno; -} - -signed main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t = 1; - cin >> t; - // out(t); - while (t--) solve(); -}","#include -using namespace std; - -#define int long long -#define vi vector -#define vs vector -#define vvi vector> -#define pii pair -#define vpii vector> -#define mii map -#define umii unordered_map - -#define ff first -#define ss second -#define rep(i, n) for(int i=0; i=0; i--) -#define pb push_back -#define aint(x) x.begin(),x.end() - -#define pyes cout << ""YES\n"" -#define pno cout << ""NO\n"" -#define pm1 cout << -1 << endl -#define p0 cout << 0 << endl -#define p1 cout << 1 << endl -#define out(x) cout<> s; - int n = s.size(), sum = 0; - - int cnt2 = 0, cnt3 = 0; - rep(i, n) { - sum += s[i] - '0'; - if (s[i] - '0' == 2) cnt2++; - if (s[i] - '0' == 3) cnt3++; - } - - sum %= 9; - int flag = 0; - - for (int i = 0; i <= min(cnt2, 1int * 20); i++) { - for (int j = 0; j <= min(cnt3, 1int * 20); j++) { - int temp = sum; - temp += i * 2 + j * 6; - if (temp % 9 == 0) { - cout << ""YES\n""; - return; - } - } - } - for (int i = 0; i < min(cnt2, 1int * 20); i++) { - int temp = sum; - if ((temp + i * 2) % 9 == 0) { - pyes; - return; - } - } - for (int i = 0; i < min(cnt3, 1int * 20); i++) { - int temp = sum; - if ((temp + i * 3) % 9 == 0) { - pyes; - return; - } - } - pno; -} - -signed main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t = 1; - cin >> t; - // out(t); - while (t--) solve(); -}",1 -upachivup,2050C - Uninteresting Number,c++17 ,299437115,299437296,"#include -using namespace std; -#define int long long -#define pii pair -const int maxn = 100005, MOD = 1e9 + 7; - -void fast_io(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -// bool prime[1001]; - -// void SieveOfEratosthenes(int n) -// { -// memset(prime, true, sizeof(prime)); -// for (int p = 2; p * p <= n; p++) { -// if (prime[p] == true) { -// for (int i = p * p; i <= n; i += p)prime[i] = false; -// } -// } -// } - - -void solve(){ - string n; cin >> n; - int twos = 0, threes = 0, md = 0; - int x = n.size(); - bool ans = 0; - for(int i = 0; i> t; - while(t--){ - solve(); - cout << endl; - } -} - -","#include -using namespace std; -#define int long long -#define pii pair -const int maxn = 100005, MOD = 1e9 + 7; - -void fast_io(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -// bool prime[1001]; - -// void SieveOfEratosthenes(int n) -// { -// memset(prime, true, sizeof(prime)); -// for (int p = 2; p * p <= n; p++) { -// if (prime[p] == true) { -// for (int i = p * p; i <= n; i += p)prime[i] = false; -// } -// } -// } - - -void solve(){ - string n; cin >> n; - int twos = 0, threes = 0, md = 0; - int x = n.size(); - bool ans = 0; - for(int i = 0; i> t; - while(t--){ - solve(); - cout << endl; - } -} - -",2 -wnalds,2050C - Uninteresting Number,c++23 ,299626075,299600746,"#include -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); - int t; - cin >> t; - while (t--){ - string num; - cin >> num; - int l = num.size(); - int qs = 0; - int cnt2 = 0, cnt3 = 0; - for (int i = 0; i < l; i++){ - if (num[i]-'0' == 2){ - cnt2++; - } - else if (num[i]-'0' == 3){ - cnt3++; - } - qs += num[i]-'0'; - } - bool ch = false; - int temp; - for (int i = 0; i <= cnt2; i++){ - for (int j = 0; j <= cnt3; j++){ - temp = qs; - qs += (2*i)+(6*j); - if (qs%9==0) ch = true; - if (ch) break; - qs = temp; - } - if (ch) break; - } - if (ch) cout << ""YES\n""; - else cout << ""NO\n""; - } - - return 0; -} -","#include -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); - int t; - cin >> t; - while (t--){ - string num; - cin >> num; - int l = num.size(); - int qs = 0; - int cnt2 = 0, cnt3 = 0; - for (int i = 0; i < l; i++){ - if (num[i]-'0' == 2){ - cnt2++; - } - else if (num[i]-'0' == 3){ - cnt3++; - } - qs += num[i]-'0'; - } - bool ch = false; - qs%=9; - if (qs == 0) ch = true; - if (qs == 7 && cnt2 >= 1) ch = true; - if (qs == 6 && (cnt2 >= 6 || cnt3 >= 2 || (cnt3 >= 1 && cnt2 >= 3))) ch = true; - if (qs == 5 && cnt2 >= 2) ch = true; - if (qs == 3 && (cnt2 >= 3 || cnt3 >= 1)) ch = true; - if (qs == 2 && cnt2 >= 8 || (cnt3 >= 1 && cnt2 >= 5) || (cnt3 >= 2 && cnt2 >= 2)) ch = true; - if (qs == 1 && (cnt2 >= 4 || (cnt2 >= 1 && cnt3 >= 1))) ch = true; - if (ch) cout << ""YES\n""; - else cout << ""NO\n""; - } - - return 0; -} -",1 -SanjayKumar584,2050C - Uninteresting Number,c++17 ,297743174,297743095,"#include -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - string num; - cin >> num; - - int twos_count = 0, threes_count = 0, sum = 0; - - // Process digits as a string to avoid overflow - for (char digit : num) - { - int k = digit - '0'; - if (k == 2) - twos_count++; - else if (k == 3) - threes_count++; - sum += k; - } - - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - continue; - } - - // Limit effective counts based on problem constraints - twos_count = min(twos_count, 8); - threes_count = min(threes_count, 5); - - bool marker = false; - int rem = sum % 9; - - for (int i = 0; i <= threes_count; i++) - { - for (int j = 0; j <= twos_count; j++) - { - if ((rem + i * 6 + j * 2) % 9 == 0) - { - marker = true; - break; - } - } - if (marker) - break; - } - - if (marker) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - } - - return 0; -} -","#include -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - string num; - cin >> num; - - int twos_count = 0, threes_count = 0, sum = 0; - - // Process digits as a string to avoid overflow - for (char digit : num) - { - int k = digit - '0'; - if (k == 2) - twos_count++; - else if (k == 3) - threes_count++; - sum += k; - } - - if (sum % 9 == 0) - { - cout << ""YES"" << endl; - continue; - } - - // Limit effective counts based on problem constraints - twos_count = min(twos_count, 5); - threes_count = min(threes_count, 3); - - bool marker = false; - int rem = sum % 9; - - for (int i = 0; i <= threes_count; i++) - { - for (int j = 0; j <= twos_count; j++) - { - if ((rem + i * 6 + j * 2) % 9 == 0) - { - marker = true; - break; - } - } - if (marker) - break; - } - - if (marker) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - } - - return 0; -} -",1 -felpz,2050C - Uninteresting Number,c++23 ,297734964,297738582,"#include -using namespace std; - -#define int long long - -typedef long long ll; -typedef pair ii; -typedef vector vi; - -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() -#define BUFF ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) - -const int INF = 0x3F3F3F3F; - -signed main() -{ - BUFF; - int t; - string num; - cin >> t; - while(t--) { - cin >> num; - - int soma = 0; - int num2 = 0, num3 = 0; - for(int i = 0; i < num.size(); i++) { - soma += num[i] - '0'; - soma % 9; - if(num[i] == '2') num2++; - if(num[i] == '3') num3++; - } - - if(soma % 9 == 0 || num3 == num.size()) cout << ""YES"" << endl; - else { - while(soma % 2 == 0 && num3) { - soma = (soma+6)%9; - num3--; - } - - while(soma % 2 == 0 && num2) { - soma = (soma+2)%9; - num2--; - } - if((soma == 1 && num2 >= 4) || (soma == 3 && num2 >= 3) || (soma == 5 && num2 >= 2) || (soma == 7 && num2 >= 1)) cout << ""YES"" << endl; - else cout << ""NO"" << endl; - } - } - return 0; -}","#include -using namespace std; - -#define int long long - -typedef long long ll; -typedef pair ii; -typedef vector vi; - -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() -#define BUFF ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) - -const int INF = 0x3F3F3F3F; - -bool possible(int num, int num2, int num3) { - if(num == 9 || num == 18) return true; - if(num > 18) return false; - - if(num2 && num3) { - if(possible(num+2, num2-1, num3)) return true; - if(possible(num+6, num2, num3-1)) return true; - } else if(num3) { - if(possible(num+6, num2, num3-1)) return true; - } else if(num2) { - if(possible(num+2, num2-1, num3)) return true; - } - - return false; -} - -signed main() -{ - BUFF; - int t; - string num; - cin >> t; - while(t--) { - cin >> num; - - int soma = 0; - int num2 = 0, num3 = 0; - for(int i = 0; i < num.size(); i++) { - soma += num[i] - '0'; - soma % 9; - if(num[i] == '2') num2++; - if(num[i] == '3') num3++; - } - - if(soma % 9 == 0 || num3 == num.size()) cout << ""YES"" << endl; - else { - if(possible(soma%9, num2, num3)) cout << ""YES"" << endl; - else cout << ""NO"" << endl; - } - } - return 0; -}",2 -mohammdmahdi,2050C - Uninteresting Number,python,297649033,297648693,"def is_divi9(num): - s = sum(num) # مجموع اولیه ارقام - if s % 9 == 0: # بررسی اولیه - return ""YES"" - - # شمارش تعداد ارقام 2 و 3 - count_2 = num.count(2) - count_3 = num.count(3) - - # بررسی تمام مقادیر ممکن از تغییر - for c2 in range(count_2 + 1): # تعداد تغییر 2ها از 0 تا count_2 - for c3 in range(count_3 + 1): # تعداد تغییر 3ها از 0 تا count_3 - new_s = s + c2 * 2 + c3 * 6 - if new_s % 9 == 0: - return ""YES"" - - return ""NO"" - -# ورودی گرفتن -t = int(input()) -for _ in range(t): - num = [int(digit) for digit in input()] # تبدیل عدد به لیست ارقام - print(is_divi9(num)) -","from itertools import product - -def is_divi9(num): - s = sum(num) # مجموع اولیه ارقام - if s % 9 == 0: # بررسی اولیه - return ""YES"" - - # پیدا کردن ایندکس ارقام 2 و 3 - indices = [i for i in range(len(num)) if num[i] in (2, 3)] - # تولید تمام ترکیب‌های ممکن از تغییر - for changes in product((0, 1), repeat=len(indices)): # 0: تغییر نکن، 1: تغییر کن - new_s = s # شروع از مجموع اولیه - for idx, change in zip(indices, changes): - if change == 1: # اگر قرار است این رقم تغییر کند - new_s += num[idx] ** 2 - num[idx] - if new_s % 9 == 0: # بررسی بخش‌پذیری مجموع جدید - return ""YES"" - - return ""NO"" # اگر هیچ حالتی موفق نبود - -# ورودی گرفتن -t = int(input()) -for _ in range(t): - num = [int(digit) for digit in input()] # تبدیل عدد به لیست ارقام - print(is_divi9(num)) -",1 -20071,2050C - Uninteresting Number,c++17 ,306534271,306535402,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -int t,number=1,total,num2,num3; - -char num[1005][100005]; - -int main(){ - - scanf(""%d"",&t); - - while (t--) - - { - - total = 0; - - num2 = 0; - - num3 = 0; - - scanf(""%s"",num[number]); - - for (int i = 0; i < strlen(num[number]); i++) - - { - - total += (num[number][i] - '0'); - - if (num[number][i] == '2') - - { - - num2 ++; - - } - - if (num[number][i] == '3') - - { - - num3 ++; - - } - - - - } - - if (total%9 == 0) - - { - - printf(""YES\n""); - - continue; - - } - - - - if ((total%9)%2 == 0) - - { - - total = 18-(total%9); - - }else{ - - total = 9-(total%9); - - } - - - - int temp = num2+num3; - - for (int i = 1; i <= temp+1; i++) - - { - - if (total == 0) - - { - - printf(""YES\n""); - - break; - - } - - - - if (total>=6 && num3>0) - - { - - total -= 6; - - num3--; - - } - - else if (total>=2 && num2>0) - - { - - total -= 2; - - num2--; - - - - - - - - } - - - - - - } - - if (total == 0) - - { - - continue; - - } - - - - printf(""NO\n""); - - - - number++; - -} - - - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -int t,total,num2,num3; - -char num[100005]; - -int main(){ - - scanf(""%d"",&t); - - while (t--) - - { - - total = 0; - - num2 = 0; - - num3 = 0; - - scanf(""%s"",num); - - for (int i = 0; i < strlen(num); i++) - - { - - total += (num[i] - '0'); - - if (num[i] == '2') - - { - - num2 ++; - - } - - if (num[i] == '3') - - { - - num3 ++; - - } - - - - } - - if (total%9 == 0) - - { - - printf(""YES\n""); - - continue; - - } - - - - if ((total%9)%2 == 0) - - { - - total = 18-(total%9); - - }else{ - - total = 9-(total%9); - - } - - - - int temp = num2+num3; - - for (int i = 1; i <= temp+1; i++) - - { - - if (total == 0) - - { - - printf(""YES\n""); - - break; - - } - - - - if (total>=6 && num3>0) - - { - - total -= 6; - - num3--; - - } - - else if (total>=2 && num2>0) - - { - - total -= 2; - - num2--; - - - - - - - - } - - - - - - } - - if (total == 0) - - { - - continue; - - } - - - - printf(""NO\n""); - - - -} - - - - return 0; - -}",2 -abhinavxsaraf,2050C - Uninteresting Number,c++17 ,298159738,298158236,"#include -using namespace std; - -int main() { - int tt; - cin >> tt; - while(tt--) { - string n; - cin >> n; - int sum = 0,two = 0,three = 0; - for(int i = 0;i < n.length();i++) { - sum += n[i] - '0'; - if(n[i] == '2') two++; - if(n[i] == '3') three++; - } - int remainder = sum%9; - int t = 0; - two = min(two,9); - three = min(three,9); - for(int i = 0;i <= two;i++) { - for(int j = 0;j <= three;j++) { - if((remainder + (i*2 + j*6)) % 9 == 0) { - t = 1; - break; - } - } - } - if(t == 1) cout << ""yes"" << endl; - else cout << ""no"" << endl; - } -}","#include -using namespace std; - -int main() { - int tt; - cin >> tt; - while(tt--) { - long long n; - cin >> n; - int sum = 0,two = 0,three = 0; - while(n > 0) { - sum += n%10; - if(n%10 == 2) two++; - if(n%10 == 3) three++; - n = n/10; - } - int remainder = sum%9; - int t = 0; - if(remainder == 0) t = 1; - two = min(two,9); - three = min(three,9); - for(int i = 0;i <= two;i++) { - for(int j = 0;j <= three;j++) { - if((remainder + (i*2 + j*6)) % 9 == 0) { - t = 1; - break; - } - } - } - if(t == 1) cout << ""yes"" << endl; - else cout << ""no"" << endl; - } -}",1 -Jollychen#,2050C - Uninteresting Number,c++17 ,297648149,297641429,"#include -using namespace std; -const int N=1e5+10; -int t; -int c; -int x,y; -int sum; -bool f=0; -int main(){ - cin>>t; - while(t--){ - string s; - cin>>s; - c=s.size(); - sum=0; - f=0; - x=0,y=0; - for(int i=0;i -using namespace std; -const int N=1e5+10; -int t; -int a[N]; -bool f=0; -int c; -void dfs(int i,int sum){ - if(i>c){//出口 - if(sum%9==0){ - f=1; - } - return; - } - //不变 - dfs(i+1,sum+a[i]); - //能否变 - if(2<=a[i]&&a[i]<=3){//可以变 - a[i]*=a[i]; - dfs(i+1,sum+a[i]); - } - return; -} -int main(){ - cin>>t; - while(t--){ - for(int i=1;i<=N;i++){ - a[i]=0; - } - string s; - cin>>s; - c=s.size(); - for(int i=0;i=2&&a[i+1]<=3){ - } - } - f=0; - dfs(1,0); - if(f==0){ - cout<<""No""< -using namespace std; - -int main(){ - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - int sum=0; - int cnt2=0; - int cnt3=0; - for(int i=0; i=0; i--){ - if((required-2*i)%6==0){ - temp=(required-2*i)/6; - break; - } - } - if(temp==-1){ - required+=9; - for(int i=cnt2; i>=0; i--){ - if((required-2*i)%6==0){ - temp=(required-2*i)/6; - break; - } - } - } - if(temp!=-1 && temp<=cnt3) - cout<<""Yes""< -using namespace std; - -int main(){ - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - int sum=0; - int cnt2=0; - int cnt3=0; - for(int i=0; i - -#include - -#include - -#include - -#include - -#include - -#include - - - -#ifdef ONLINE_JUDGE - -#define default_file(...) - -#define dbg(...) - -#else - -#include ""../local/debug.h"" - -#endif - - - -void run_program(){ - - std::string s; - - std::cin >> s; - - int sum = 0, cnt_two = 0, cnt_three = 0; - - for(auto& c : s) - - sum += int(c - '0'), - - cnt_two += (c == '2'), - - cnt_three += (c == '3'); - - - - for(int two = 0; two < std::min(10, cnt_two + 1); ++two) - - for(int three = 0; three < std::min(10, cnt_three + 1); ++three) - - if((sum + two * 2 + three * 6) % 9 == 0) - - return void(std::cout << ""YES\n""); - - std::cout << ""NO\n""; - -} - -int main() { - - default_file(""""); - - std::ios::sync_with_stdio(0); std::cin.tie(0); - - int t; - - std::cin >> t; - - while(t--) - - run_program(); - - return 0; - -} - -","#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -#ifdef ONLINE_JUDGE - -#define default_file(...) - -#define dbg(...) - -#else - -#include ""../local/debug.h"" - -#endif - - - -void run_program(){ - - std::string s; - - std::cin >> s; - - int sum = 0, cnt_two = 0, cnt_three = 0; - - for(auto& c : s) - - sum += int(c - '0'), - - cnt_two += (c == '2'), - - cnt_three += (c == '3'); - - - - int mod = sum % 9; - - if(mod == 0 || (mod % 2 == 1 && cnt_two >= (9 - mod) / 2) - - || (mod == 3 && (cnt_three >= 1 || cnt_two >= 3)) - - || (mod == 6 && (cnt_three >= 2 || cnt_two >= 6)) - - || ((mod == 4 || mod == 2) && cnt_three >= 1 && cnt_two >= (6 - mod) / 2) - - || (mod == 1 && cnt_three >= 2 && cnt_two >= 1) - - || (mod == 5 && cnt_three >= 1 && cnt_two >= 2) - - || (mod == 7 && cnt_three >= 1 && cnt_two >= 4) - - || (mod == 8 && cnt_two >= 4)) - - std::cout << ""YES\n""; - - else - - std::cout << ""NO\n""; - -} // 7 - -// 6 - -int main() { - - default_file(""""); - - std::ios::sync_with_stdio(0); std::cin.tie(0); - - int t; - - std::cin >> t; - - while(t--) - - run_program(); - - return 0; - -} - -",1 -only_supyal,2050C - Uninteresting Number,c++20 ,298976321,298978668,"#include -using namespace std; -#define int long long - -signed main(){ - int t; - cin>>t; - while(t--){ - string n; - cin>>n; - int sum=0; - int count2=0,count3=0; - for(int i=0;i=rem){ - cout<<""YES\n""; - }else if(rem%2){ - if((9-rem)/2<=count2){ - cout<<""YES\n""; - }else{ - cout<<""NO\n""; - } - }else{cout<<""NO\n""; - } - } -}","#include -using namespace std; -#define int long long - -signed main(){ - int t; - cin>>t; - while(t--){ - string n; - cin>>n; - int sum=0; - int count2=0,count3=0; - for(int i=0;i -using namespace std; - -void solve(){ - string s; - cin>>s; - - int two=0,three=0,sum=0; - bool flag=0; - for(auto i:s){ - if(i=='2'){ - two++; - } - else if(i=='3'){ - three++; - } - sum+=(i-'0'); - sum=sum%9; - - } - for(int j=0;j<=three;j++){ - for(int i=0;i<=two;i++){ - long tsum=sum; - tsum+=i*2+j*6; - - if(tsum%9==0){ - cout<<""YES""<>t; - while(t--){ - solve(); - - } - -}","int main() -{ - - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - - int two=0,three=0,sum=0; - bool flag=0; - for(auto i:s){ - if(i=='2'){ - two++; - } - else if(i=='3'){ - three++; - } - sum+=(i-'0'); - sum=sum%9; - - - for(int j=0;j<=three;j++){ - for(int i=0;i<=two;i++){ - long tsum=sum; - tsum+=i*2+j*6; - - if(tsum%9==0){ - flag=1; - break; - } - } - } - - } - if(flag==1){ - cout<<""YES""< -using namespace std; - -#define RANGE(i, a, b) \ - for (auto i = a - (a > b); (i < b) ^ (a > b); i += 1 - 2 * (a > b)) -#define ll long long -/* - 1 -> 1 No change - 2 -> 4: +2 // only this can be applied twice, in that case: +5 - 3 -> 9: +6 - So we can change x 2s to 4, and y 3s to 6s. The new remainder of the number - becomes 2*x + 6*y == 0 [9]. We must find a solution for (x, y), with the upper - bound being the actual number of occurence of 2s and 3s. - Les restes possible d'un multiplication par 2 mod 9: - 1*2 = 2 [9] - 2*2 = 4 [9] - 3*2 = 6 [9] - 4*2 = 8 [9] - 5*2 = 0 [9] - Les restes possible d'une multiplication par 6 mod 9: - 1*6 = 6 [9] - 2*6 = 3 [9] - 3*6 = 0 [9] - Tableau des additions possibles: - ---- 0 2 4 6 8 - 0 0 2 4 6 7 - 3 3 5 7 0 2 - 6 6 8 1 3 5 - -*/ - -void solve() { - ll n; - cin >> n; - ll count2 = 0, count3 = 0; - ll rem = 0; - for (; n > 0; n /= 10) { - rem += n % 10; - if (n % 10 == 2) - count2++; - else if (n % 10 == 3) - count3++; - } - rem %= 9; - // cout << count2 << "" "" << count3 << "" "" << rem << endl; - if (count2 >= 5 && count3 >= 3) { - cout << ""Yes"" << endl; - return; - } - for (int n2 = 0; n2 <= min(count2, 10ll); n2++) - for (int n3 = 0; n3 <= min(count3, 10ll); n3++) - if ((n2 * 2 + n3 * 6 + rem) % 9 == 0) { - cout << ""Yes"" << endl; - return; - } - cout << ""No"" << endl; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - -#define RANGE(i, a, b) \ - for (auto i = a - (a > b); (i < b) ^ (a > b); i += 1 - 2 * (a > b)) -#define ll long long -/* - 1 -> 1 No change - 2 -> 4: +2 // only this can be applied twice, in that case: +5 - 3 -> 9: +6 - So we can change x 2s to 4, and y 3s to 6s. The new remainder of the number - becomes 2*x + 6*y == 0 [9]. We must find a solution for (x, y), with the upper - bound being the actual number of occurence of 2s and 3s. - Les restes possible d'un multiplication par 2 mod 9: - 1*2 = 2 [9] - 2*2 = 4 [9] - 3*2 = 6 [9] - 4*2 = 8 [9] - 5*2 = 0 [9] - Les restes possible d'une multiplication par 6 mod 9: - 1*6 = 6 [9] - 2*6 = 3 [9] - 3*6 = 0 [9] - Tableau des additions possibles: - ---- 0 2 4 6 8 - 0 0 2 4 6 7 - 3 3 5 7 0 2 - 6 6 8 1 3 5 - -*/ - -void solve() { - string n; - cin >> n; - ll count2 = 0, count3 = 0; - ll rem = 0; - for (auto d : n) { - int c = d - '0'; - rem += c % 10; - rem %= 9; - if (c % 10 == 2) - count2++; - else if (c % 10 == 3) - count3++; - } - for (int n2 = 0; n2 <= min(count2, 10ll); n2++) - for (int n3 = 0; n3 <= min(count3, 10ll); n3++) - if (((n2 * 2) % 9 + (n3 * 6) % 9 + rem) % 9 == 0) { - cout << ""Yes"" << endl; - return; - } - cout << ""No"" << endl; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",2 -ravi_kumawat,2050C - Uninteresting Number,c++17 ,299290126,299290974,"#include -#define int long long -using namespace std; - - -signed main() { - int q; - cin>>q; - while(q--){ - string n; - cin>>n; - int sum=0; - int x2=0; - int x3=0; - for(int i=0;i -#define int long long -using namespace std; - - -signed main() { - int q; - cin>>q; - while(q--){ - string n; - cin>>n; - int sum=0; - int x2=0; - int x3=0; - for(int i=0;i 0) { - solve(); - } - out.close(); - } - - private static void solve() { - long sum = 0; - String s = in.next(); - int two = 0, three = 0; - for (char c : s.toCharArray()) { - sum += c - '0'; - if (c == '2') { - two++; - } else if (c == '3') { - three++; - } - } - for (int t = 0; t <= two; t++) { - for (int th = 0; th <= three; th++) { - if ((sum + 2 * t + th * 6) % 9 == 0) { - System.out.println(""YES""); - return; - } - } - } - System.out.println(""NO""); - - } - - static class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - } -} -","import java.io.*; -import java.util.*; - -public class TLE { - public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); - static FastReader in = new FastReader(); - - public static void main(String[] args) throws Exception { - int testCases = in.nextInt(); - while (testCases-- > 0) { - solve(); - } - out.close(); - } - - private static void solve() { - long sum = 0; - String s = in.next(); - int two = 0, three = 0; - for (char c : s.toCharArray()) { - sum += c - '0'; - if (c == '2') { - two++; - } else if (c == '3') { - three++; - } - } - if (sum % 9 == 0) { - System.out.println(""YES""); - } else { - long modN = sum % 9; - long mod = 9 - modN; - if (mod == 2 && two >= 1) { - System.out.println(""YES""); - } else if (mod == 4 && two >= 2) { - System.out.println(""YES""); - } else if (mod == 3 && three >= 2) { - System.out.println(""YES""); - } else if (mod == 6 && (two >= 3 || three >= 2)) { - System.out.println(""YES""); - } else if (mod == 8 && (three >= 2 && two >= 1) || (two >= 4)) { - System.out.println(""YES""); - } else if (mod == 5 && two >= 1 && three >= 1) { - System.out.println(""YES""); - } else if (mod == 7 && two >= 2 && three >= 1) { - System.out.println(""YES""); - } else { - System.out.println(""NO""); - } - } - - } - - static class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - } -} -",1 -callmeKakarot,2050C - Uninteresting Number,c++20 ,298607542,298606591,"#include -using namespace std; -#define int long long -vector takearray(int n) -{ - vector a; - for(int i=0;i> x; - a.push_back(x); - } - return a; -} -// bool cmp(auto a, auto b) -// { -// return a.second < b.second; -// } -int getmax(vector a) -{ - int x = LLONG_MIN; - for(int i=0;i a){for(int i=0;i p1,pair p2) -// { -// if(p1.first > p2.first) return 1; -// if(p1.first getElement(int n, int l) -// // { -// // int i = static_cast(std::floor((-1 + std::sqrt(1 + 8 * l)) / 2)); -// // int indexInRow = l - (i * (i + 1)) / 2; -// // int j = i + indexInRow + 1; -// // return {i + 1, j}; -// // } -// int funcc(vector &a) -// { -// int n = a.size(); -// multiset ms; -// for(int i=0;i> s; - int sum = 0; - int freq_o=0,freq_tw=0,freq_th=0; - while(s.length()>0) - { - int pos = s.length(); - if(s[pos-1]=='2') freq_tw++; - else if(s[pos-1]=='3') freq_th++; - sum+=(s[pos-1]-'0'); - sum%=9; - s=s.substr(0,s.length()-1); - } - for(int i=0;i<=min(freq_tw,8ll);i++) - { - for(int j=0;j<=min(freq_th,8ll);j++) - { - if((2ll*i+6ll*j+sum)%9ll==0) - { - cout << ""Yes"" << endl; - return; - } - } - } - cout << ""No"" << endl; - return; -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -#define int long long -vector takearray(int n) -{ - vector a; - for(int i=0;i> x; - a.push_back(x); - } - return a; -} -// bool cmp(auto a, auto b) -// { -// return a.second < b.second; -// } -int getmax(vector a) -{ - int x = LLONG_MIN; - for(int i=0;i a){for(int i=0;i p1,pair p2) -// { -// if(p1.first > p2.first) return 1; -// if(p1.first getElement(int n, int l) -// // { -// // int i = static_cast(std::floor((-1 + std::sqrt(1 + 8 * l)) / 2)); -// // int indexInRow = l - (i * (i + 1)) / 2; -// // int j = i + indexInRow + 1; -// // return {i + 1, j}; -// // } -// int funcc(vector &a) -// { -// int n = a.size(); -// multiset ms; -// for(int i=0;i> n; - int sum = 0; - int x = n; - int freq_o=0,freq_tw=0,freq_th=0; - while(x>0) - { - if(x%10==2) freq_tw++; - else if(x%10==3) freq_th++; - sum+=x%10; - x=x/10; - } - if(sum%9 == 0) - { - cout << ""Yes"" << endl; - return; - } - else - { - sum = sum%9; - if((sum == 7ll)&&(freq_tw)) - { - cout << ""Yes"" << endl; - return; - } - else if((sum==3ll) && (freq_th)) - { - cout << ""Yes"" << endl; - return; - } - else if((sum == 1ll) && freq_th && freq_tw) - { - cout << ""Yes"" << endl; - return; - } - else - { - for(int i=0;i<=min(freq_tw,8ll);i++) - { - for(int j=0;j<=min(freq_th,8ll);j++) - { - if((2*i+6*j+sum)%9==0) - { - cout << ""Yes"" << endl; - return; - } - } - } - } - } - cout << ""No"" << endl; - return; -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",1 -Sumit_singla,2050C - Uninteresting Number,c++20 ,298670229,298666296,"#include -using namespace std; - -// Function to check if a number represented by a string is divisible by 9 -bool isDivisibleBy9(const string &s) -{ - int sum = 0; - for (char c : s) - { - sum += (c - '0'); - } - return (sum % 9 == 0); -} - -// Function to determine if a number can become divisible by 9 -string uninteresting_numbers(const string &s) -{ - int n = s.length(); - // DP table: dp[i][sum] indicates if it's possible to achieve the `sum` - // using digits up to index `i`. - vector> dp(n + 1, vector(9, false)); - - // Base case: sum 0 is achievable with no digits used. - dp[0][0] = true; - - // Iterate over each digit of the number - for (int i = 0; i < n; i++) - { - int digit = s[i] - '0'; - for (int sum = 0; sum < 9; sum++) - { - // If `sum` is achievable using the first `i` digits - if (dp[i][sum]) - { - // Case 1: Do not modify this digit - dp[i + 1][(sum + digit) % 9] = true; - - // Case 2: Replace the digit with its square (if <= 3) - if (digit <= 3) - { - int squared = digit * digit; - dp[i + 1][(sum + squared) % 9] = true; - } - } - } - } - - // Check if any sum divisible by 9 is achievable using all digits - for (int sum = 0; sum < 9; sum++) - { - if (dp[n][sum] && sum == 0) - { - return ""YES""; - } - } - return ""NO""; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - string number; - cin >> number; - cout << uninteresting_numbers(number) << endl; - } - return 0; -} -","// https://codeforces.com/problemset/problem/2050/C -// uninteresting numbers -#include -using namespace std; -bool test(string s) -{ - int sum = 0; - for (int i = 0; i < s.length(); i++) - { - sum += s[i] - '0'; - } - if (sum % 9 == 0) - return true; - return false; -} -void solution(string s, bool &counter, vector &visited) -{ - if (counter) - return; - counter = test(s); - for (int i = 0; i < s.length(); i++) - { - if (!visited[i]) - { - int no = s[i] - '0'; - visited[i] = true; - if (no <= 3) - { - string copy = s; - copy[i] = '0' + no * no; - solution(copy, counter, visited); - } - } - } -} -string uninteresting_numbers(string n) -{ - bool counter = false; - vector visited(n.length(), false); - solution(n, counter, visited); - if (counter) - { - return ""YES""; - } - return ""NO""; -} -int main() -{ - int t; - cin >> t; - while (t--) - { - string number; - cin >> number; - cout << uninteresting_numbers(number) << endl; - } - return 0; -} -",1 -Anurag_kumar_,2050C - Uninteresting Number,c++17 ,308198204,308196641,"#include - -using namespace std; - -#define int long long - - - -signed main() { - - int t; - - cin>>t; - - while(t--){ - - string s; - - cin>>s; - - int n = s.size(); - - int sum = 0; - - int two,three; - - two = three = 0; - - for(int i=0;i - -using namespace std; - -#define int long long - - - -signed main() { - - int t; - - cin>>t; - - while(t--){ - - string s; - - cin>>s; - - int n = s.size(); - - int sum = 0; - - int two,three; - - two = three = 0; - - for(int i=0;i=d ){ - - d = d - two*2; - - if(d>=0 &&d%6!=0 ) - - cout<<""NO\n""; - - else if(d>=0 && d%6==0 && d/6 < three){ - - cout<<""NO\n""; - - } - - else - - cout<<""YES\n""; - - } - - else{ - - cout<<""NO\n""; - - } - - - - } - - - - } - - return 0; - -}",1 -Meet_V1406,2050C - Uninteresting Number,c++17 ,298500165,298510893,"#include -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - ll n; - cin >> n; - - vector digits; - int sum = 0; - - while (n > 0) { - int temp = n % 10; - digits.push_back(temp); - sum += temp; - n /= 10; - } - - if (sum % 9 == 0) { - cout << ""YES"" << endl; - continue; - } - - int count2 = 0, count3 = 0; - for (int digit : digits) { - if (digit == 2) count2++; - if (digit == 3) count3++; - } - bool possible = false; - for (int i = 0; i <= count2 && !possible; i++) { - for (int j = 0; j <= count3 && !possible; j++) { - int newSum = sum + i * 2 + j * 6; - if (newSum % 9 == 0) { - possible = true; - break; - } - } - if(possible){break;} - } - - if (possible) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } - return 0; -} -","#include -#define ll long long int -using namespace std; - -int main() { - int t; - cin >> t; - while (t--) { - string n; - cin >> n; - vector digits; - int sum = 0; - for (char c : n) { - int digit = c - '0'; - digits.push_back(digit); - sum += digit; - } - if (sum % 9 == 0) { - cout << ""YES"" << endl; - continue; - } - int count2 = 0, count3 = 0; - for (int digit : digits) { - if (digit == 2) count2++; - if (digit == 3) count3++; - } - bool possible = false; - for (int i = 0; i <= count2 && !possible; i++) { - for (int j = 0; j <= count3 && !possible; j++) { - int newSum = sum + i * 2 + j * 6; - if (newSum % 9 == 0) { - possible = true; - break; - } - } - } - if (possible) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } - return 0; -} -",2 -orkag,2050C - Uninteresting Number,c++23 ,306262175,306262377,"#include - -using namespace std; - - - -#define ll long long - -#define pb push_back - -#define F first - -#define S second - -#define pii pair - -#define vi vector - -#define vpii vector - - - -#define loop(i,n) sloop(0,i,n) - -#define sloop(s, i, n) for(ll i=(s);i<(n);i++) - -#define rloop(i,n) rsloop(0,i,n) - -#define rsloop(s,i,n) for(ll i=(n);i-->(s);) - - - -#define all(v) (v).begin(),(v).end() - - - -#ifdef DEBUG - -#define DBG cout << __LINE__ << endl; - -#else - -#define DBG - -#endif - - - -//int xses[8] = {-1,1,0,0,-1,1,1,-1}; - -//int yses[8] = {0,0,-1,1,-1,1,-1,1}; - - - -//#define int ll - - - -void solve() - -{ - - string s; - - cin >> s; - - - - int sum=0; - - int cnt2=0,cnt3=0; - - - - for(char c:s) - - { - - sum+=c-'0'; - - if(c=='2')cnt2++; - - if(c=='3')cnt3++; - - } - - - - sum%=9; - - cnt2%=9; - - cnt3%=9; - - - - loop(i,cnt2+1) - - { - - loop(j,cnt3+1) - - { - - if((sum+6*j+2*i)%9==0){cout << ""YES\n"";return;} - - } - - } - - - - cout << ""NO\n""; - -} - - - -signed main() - -{ - - cin.tie(0); - - ios_base::sync_with_stdio(0); - - - - int t; - - cin >> t; - - while(t--) - - solve(); - - - - - - return 0; - -} - -","#include - -using namespace std; - - - -#define ll long long - -#define pb push_back - -#define F first - -#define S second - -#define pii pair - -#define vi vector - -#define vpii vector - - - -#define loop(i,n) sloop(0,i,n) - -#define sloop(s, i, n) for(ll i=(s);i<(n);i++) - -#define rloop(i,n) rsloop(0,i,n) - -#define rsloop(s,i,n) for(ll i=(n);i-->(s);) - - - -#define all(v) (v).begin(),(v).end() - - - -#ifdef DEBUG - -#define DBG cout << __LINE__ << endl; - -#else - -#define DBG - -#endif - - - -//int xses[8] = {-1,1,0,0,-1,1,1,-1}; - -//int yses[8] = {0,0,-1,1,-1,1,-1,1}; - - - -//#define int ll - - - -void solve() - -{ - - string s; - - cin >> s; - - - - int sum=0; - - int cnt2=0,cnt3=0; - - - - for(char c:s) - - { - - sum+=c-'0'; - - if(c=='2')cnt2++; - - if(c=='3')cnt3++; - - } - - - - sum%=9; - - cnt2=min(cnt2,9); - - cnt3=min(cnt3,3); - - - - loop(i,cnt2+1) - - { - - loop(j,cnt3+1) - - { - - if((sum+6*j+2*i)%9==0){cout << ""YES\n"";return;} - - } - - } - - - - cout << ""NO\n""; - -} - - - -signed main() - -{ - - cin.tie(0); - - ios_base::sync_with_stdio(0); - - - - int t; - - cin >> t; - - while(t--) - - solve(); - - - - - - return 0; - -} - -",2 -_AhmedTarek_,2050C - Uninteresting Number,c++17 ,308205565,308206143,"#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -int const mod = 998244353, N = 2e5 + 10; - -#define fast \ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr) - -int dp[N][13]; - -int n; - -string s; - -int rec(int i, int sum) { - - if (sum % 9 == 0) { - - return 1; - - } - - if (i == n) { - - return 0; - - } - - int &ret = dp[i][sum]; - - sum %= 9; - - int op1 = 0, op2 = 0, op3 = 0; - - if (s[i] == '2') { - - op1 = rec(i + 1, sum + 2); - - } - - if (s[i] == '3') { - - op2 = rec(i + 1, sum + 6); - - } - - op3 = rec(i + 1, sum); - - return ret = op1 | op2 | op3; - -} - - - -int main() { - - fast; - - memset(dp, -1, sizeof dp); - - int t; - - cin >> t; - - while (t--) { - - // cin >> n; - - cin >> s; - - n = s.size(); - - int sum = 0; - - for (int i = 0; i < s.size(); i++) { - - sum += (s[i] - '0'); - - } - - cout << (rec(0, sum) ? ""YES"" : ""NO"") << '\n'; - - for (int i = 0; i <= n; i++) { - - for (int j = 0; j <= 9; j++) { - - dp[i][j] = -1; - - } - - } - - } - -}","#include - -#include - -#include - - - -using namespace std; - -#define ll long long - -int const mod = 998244353, N = 2e5 + 10; - -#define fast \ - - ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr) - -int dp[N][10]; - -int n; - -string s; - -int rec(int i, int sum) { - - if (i == n) { - - return (sum % 9 == 0); - - } - - if (sum % 9 == 0) { - - return 1; - - } - - sum %= 9; - - int &ret = dp[i][sum]; - - if(~ret){ - - return ret; - - } - - ret = 0; - - if (s[i] == '2') { - - ret |= rec(i + 1, sum + 2); - - } - - if (s[i] == '3') { - - ret |= rec(i + 1, sum + 6); - - } - - ret |= rec(i + 1, sum); - - return ret; - -} - - - -int main() { - - fast; - - memset(dp, -1, sizeof dp); - - int t; - - cin >> t; - - while (t--) { - - // cin >> n; - - cin >> s; - - n = s.size(); - - int sum = 0; - - for (int i = 0; i < s.size(); i++) { - - sum += (s[i] - '0'); - - } - - cout << (rec(0, sum % 9) ? ""YES"" : ""NO"") << '\n'; - - for (int i = 0; i <= n; i++) { - - for (int j = 0; j <= 9; j++) { - - dp[i][j] = -1; - - } - - } - - } - -}",2 -christian.barry,2050C - Uninteresting Number,c++23 ,298613043,298612793,"#include -using namespace std; - -int main(){ - int t, sum; - vector possibilities; - map found; - string n; - cin >> t; - while(t--){ - cin >> n; - sum = 0; found.clear(); - for (auto i : n){ - sum += i-48; - if (i == '2') - found[2]++; - if (i == '3') - found[3]++; - } - for(int i = 0; i < min(9, found[2]+1); i++){ - for (int j = 0; j < min(9, found[3]+1); j++){ - if ((sum + i*2 + j*6)%9 == 0){ - cout << ""YES"" << endl; - found[0]++; - break; - } - } - if (found[0]) - break; - } - if (!found[0]) - cout << ""NO"" << endl; - } -}","#include -using namespace std; - -int main(){ - int t, sum; - vector possibilities; - map found; - string n; - cin >> t; - while(t--){ - cin >> n; - sum = 0; found.clear(); - for (auto i : n){ - sum += i-48; - if (i == '2') - found[2]++; - if (i == '3') - found[3]++; - } - for(int i = 0; i < min(8, found[2]+1); i++){ - for (int j = 0; j < min(8, found[3]+1); j++){ - if ((sum + i*2 + j*6)%9 == 0){ - cout << ""YES"" << endl; - found[0]++; - break; - } - } - if (found[0]) - break; - } - if (!found[0]) - cout << ""NO"" << endl; - } -}",1 -shyez123,2050C - Uninteresting Number,c++17 ,295946592,295946014," -// ॐ -//--------------------------------------------------------------------------------------------------------------------------------------------------------------- - -#include -#define fast_io \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); -#define endll '\n' -#define print(x) cout << x << endll -#define py cout << ""YES\n"" -#define pn cout << ""NO\n"" -#define fr(i, a, b) for (ll i = a; i < b; i++) -#define fer(i, a, b) for (ll i = a; i <= b; i++) -#define frr(i, a, b) for (ll i = a; i >= b; i--) -#define pb push_back -#define ff first -#define ss second -#define sz size() -#define int int64_t -#define all(v) v.begin(), v.end() -#define all_rev(v) v.rbegin(), v.rend() -#define vecp(v) \ - for (auto i : v) \ - cout << i << ' '; \ - cout << endll -#define vecpp(v) \ - for (auto i : v) \ - cout << i.ff << ' ' << i.ss << endl -#define take(x) \ - int x; \ - cin >> x -#define popcnt(n) __builtin_popcountll(n) -#define max3(a, b, c) max(a, max(b, c)) -#define min3(a, b, c) min(a, min(b, c)) -#define mxe(v) *max_element(v.begin(), v.end()) -#define mne(v) *min_element(v.begin(), v.end()) -#define debug(x) cout << #x << ' ' << x << endl -using namespace std; -typedef long long ll; -typedef long double ld; -typedef unsigned long long ull; -using vll = vector; -using pll = pair; -using vpll = vector; -using vvll = vector; -using stll = set; -using mpll = map; -using mpvll = map; -const ll INF = 1e18; -const ll MOD = 1e9 + 7; -const ll N = 2e5 + 10; - -// priority_queue , greater > p; -// __builtin_clz(x): the number of zeros at the beginning of the number -// __builtin_ctz(x): the number of zeros at the end of the number -// __builtin_popcountll(x): the number of ones in the number -// __builtin_parity(x): the parity (even or odd) of the number of ones -// __builtin_ffs(int) finds the index of the first (most right) set bit -void init_code() -{ - fast_io; -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); -#endif -} -bool isPrime(const ll n) -{ - if (n <= 1) - return false; - if (n <= 3) - return true; - if (n % 2 == 0 or n % 3 == 0) - return false; - for (ll i = 5; i * i <= n; i += 6) - if (n % i == 0 or n % (i + 2) == 0) - return false; - return true; -} -ull power(ll x, ll y) -{ - ull res = 1; - while (y > 0) - { - if (y & 1) - res = (res * x) % MOD; - x = (x * x) % MOD; - y >>= 1; - } - return res; -} -ull modInvPow(const ll n) -{ - return power(n, MOD - 2); -} -bool sortByCond(const pair &a, const pair &b) -{ - /* - if (a.ff == b.ff) - return a.ss < b.ss; - else - return a.ff < b.ff; - */ - return a.ss < b.ss; -} - -void ramram() -{ - string s; - cin >> s; - int sum = 0; - int cnt2 = 0, cnt3 = 0; - for (int i = 0; i < s.size(); i++) - { - if (s[i] == '2') - cnt2++; - if (s[i] == '3') - cnt3++; - sum += s[i] - '0'; - } - int rem = sum % 9; - rem = 9 - rem; - // cout << cnt2 << "" "" << cnt3 << "" "" << rem << endl; - if (sum % 9 == 0) - { - py; - return; - } - if (cnt2 == 0 && cnt3 == 0) - { - pn; - return; - } - if (cnt2 >= 2 && cnt3 >= 2) - { - py; - return; - } - if (cnt2 == 1 && cnt3 >= 1) - { - int tt = sum; - if ((tt + 2) % 9 == 0) - { - py; - return; - } - for (int i = 0; i < cnt3; i++) - { - tt += 6; - if (tt % 9 == 0 || (tt + 2) % 9 == 0) - { - py; - return; - } - } - pn; - return; - } - if (cnt2 >= 1 && cnt3 == 1) - { - int tt = sum; - if ((tt + 6) % 9 == 0) - { - py; - return; - } - for (int i = 0; i < cnt2; i++) - { - tt += 2; - if (tt % 9 == 0 || (tt + 6) % 9 == 0) - { - py; - return; - } - } - pn; - return; - } - if (cnt2 == 0) - { - int tt = sum; - for (int i = 0; i < cnt3; i++) - { - tt += 6; - if (tt % 9 == 0) - { - py; - return; - } - } - pn; - return; - } - if (cnt3 == 0) - { - int tt = sum; - for (int i = 0; i < cnt2; i++) - { - tt += 2; - if (tt % 9 == 0) - { - py; - return; - } - } - pn; - return; - } - cout << ""hii"" << endl; - return; -} - -int32_t main() -{ - init_code(); - fast_io; - ll t = 1; - cin >> t; - while (t--) - ramram(); - return 0; -}"," -// ॐ -//--------------------------------------------------------------------------------------------------------------------------------------------------------------- - -#include -#define fast_io \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); -#define endll '\n' -#define print(x) cout << x << endll -#define py cout << ""YES\n"" -#define pn cout << ""NO\n"" -#define fr(i, a, b) for (ll i = a; i < b; i++) -#define fer(i, a, b) for (ll i = a; i <= b; i++) -#define frr(i, a, b) for (ll i = a; i >= b; i--) -#define pb push_back -#define ff first -#define ss second -#define sz size() -#define int int64_t -#define all(v) v.begin(), v.end() -#define all_rev(v) v.rbegin(), v.rend() -#define vecp(v) \ - for (auto i : v) \ - cout << i << ' '; \ - cout << endll -#define vecpp(v) \ - for (auto i : v) \ - cout << i.ff << ' ' << i.ss << endl -#define take(x) \ - int x; \ - cin >> x -#define popcnt(n) __builtin_popcountll(n) -#define max3(a, b, c) max(a, max(b, c)) -#define min3(a, b, c) min(a, min(b, c)) -#define mxe(v) *max_element(v.begin(), v.end()) -#define mne(v) *min_element(v.begin(), v.end()) -#define debug(x) cout << #x << ' ' << x << endl -using namespace std; -typedef long long ll; -typedef long double ld; -typedef unsigned long long ull; -using vll = vector; -using pll = pair; -using vpll = vector; -using vvll = vector; -using stll = set; -using mpll = map; -using mpvll = map; -const ll INF = 1e18; -const ll MOD = 1e9 + 7; -const ll N = 2e5 + 10; - -// priority_queue , greater > p; -// __builtin_clz(x): the number of zeros at the beginning of the number -// __builtin_ctz(x): the number of zeros at the end of the number -// __builtin_popcountll(x): the number of ones in the number -// __builtin_parity(x): the parity (even or odd) of the number of ones -// __builtin_ffs(int) finds the index of the first (most right) set bit -void init_code() -{ - fast_io; -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); -#endif -} -bool isPrime(const ll n) -{ - if (n <= 1) - return false; - if (n <= 3) - return true; - if (n % 2 == 0 or n % 3 == 0) - return false; - for (ll i = 5; i * i <= n; i += 6) - if (n % i == 0 or n % (i + 2) == 0) - return false; - return true; -} -ull power(ll x, ll y) -{ - ull res = 1; - while (y > 0) - { - if (y & 1) - res = (res * x) % MOD; - x = (x * x) % MOD; - y >>= 1; - } - return res; -} -ull modInvPow(const ll n) -{ - return power(n, MOD - 2); -} -bool sortByCond(const pair &a, const pair &b) -{ - /* - if (a.ff == b.ff) - return a.ss < b.ss; - else - return a.ff < b.ff; - */ - return a.ss < b.ss; -} - -void ramram() -{ - string s; - cin >> s; - int sum = 0; - int cnt2 = 0, cnt3 = 0; - for (int i = 0; i < s.size(); i++) - { - if (s[i] == '2') - cnt2++; - if (s[i] == '3') - cnt3++; - sum += s[i] - '0'; - } - int rem = sum % 9; - rem = 9 - rem; - // cout << cnt2 << "" "" << cnt3 << "" "" << rem << endl; - if (sum % 9 == 0) - { - py; - return; - } - if (cnt2 == 0 && cnt3 == 0) - { - pn; - return; - } - if (cnt2 >= 2 && cnt3 >= 2) - { - py; - return; - } - if (cnt2 == 1 && cnt3 >= 2) - { - int tt = sum; - for (int i = 0; i < cnt3; i++) - { - tt += 6; - if (tt % 9 == 0 || (tt + 2) % 9 == 0) - { - py; - return; - } - } - cout<<""chut""<= 2 && cnt3 == 1) - { - int tt = sum; - for (int i = 0; i < cnt2; i++) - { - tt += 2; - if (tt % 9 == 0 || (tt + 6) % 9 == 0) - { - py; - return; - } - } - cout<<""chut2""<> t; - while (t--) - ramram(); - return 0; -}",1 -nayannomm,2050C - Uninteresting Number,c++17 ,295976606,295976890,"#include -using namespace std; - -int main(){ - int t;cin>>t; - while(t--){ - string s;cin>>s; - int sum=0; - unordered_mapm; - for(int i=0;i=1 && m['2']>=2)||(m['2']>=5)){ - cout<<""YES""<=1)){ - cout<<""YES""<=2)||(m['3']>=1 && m['2']>=3)||(m['2']>=6)){ - cout<<""YES""<=2){ - cout<<""YES""<=2 && m['2']>=1)||(m['3']>=1 && m['2']>=4)||(m['2']>=7)){ - cout<<""YES""<=1)&&(m['2']>=3)){ - cout<<""YES""<=2 && m['2']>=2)||(m['3']>=1 && m['2']>=5) || (m['2']>=8)){ - cout<<""YES""<=1 && m['2']>=1) || (m['2']>=4)){ - cout<<""YES""< -using namespace std; - -int main(){ - int t;cin>>t; - while(t--){ - string s;cin>>s; - int sum=0; - unordered_mapm; - for(int i=0;i=1 && m['2']>=2)||(m['2']>=5)){ - cout<<""YES""<=1)){ - cout<<""YES""<=2)||(m['3']>=1 && m['2']>=3)||(m['2']>=6)){ - cout<<""YES""<=2){ - cout<<""YES""<=2 && m['2']>=1)||(m['3']>=1 && m['2']>=4)||(m['2']>=7)){ - cout<<""YES""<=1)||(m['2']>=3)){ - cout<<""YES""<=2 && m['2']>=2)||(m['3']>=1 && m['2']>=5) || (m['2']>=8)){ - cout<<""YES""<=1 && m['2']>=1) || (m['2']>=4)){ - cout<<""YES""< istream &operator>>(istream &cin,pair &a) { return cin>>a.first>>a.second; } -template istream &operator>>(istream &cin,vector &a) { for (auto &x:a) cin>>x; return cin; } -template ostream &operator<<(ostream &cout,const pair &a) { return cout< ostream &operator<<(ostream &cout,const vector> &a) { for (auto &x:a) cout< ostream &operator<<(ostream &cout,const vector &a) { int n=a.size(); if (!n) return cout; cout< &v, int sum) -{ - if (i >= v.size()) - return 0; - // dbg(dp[i][cur]); - - if (dp[i][cur] != -1) - return dp[i][cur]; - int x = cur; - cur += v[i]; - if ((cur % 9) == (9 - sum)) - return 1; - x %= 9; - cur %= 9; - return dp[i][cur] = f(i + 1, cur, v, sum) || f(i + 1, x, v, sum); -} -void solve() -{ - ll t, m, n, a, b; - string h; - cin >> h; - int sum = 0; - vector v; - for (char &c : h) - { - int x = c - '0'; - if (x <= 3) - { - if (x == 2) - v.push_back(2); - if (x == 3) - v.push_back(6); - } - sum += x; - } - sum %= 9; - dbg(sum, v); - if (!sum) - { - cout << ""YES"" << endl; - return; - } - memset(dp, -1, sizeof(dp)); - if (f(0, 0, v, sum)) - { - cout << ""YES"" << endl; - } - else - cout << ""NO"" << endl; -} -int32_t main() -{ - ios::sync_with_stdio(false); - cin.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}","#include ""bits/stdc++.h"" -#ifndef ONLINE_JUDGE -#include ""debug.h"" -#else -#define dbg(x...) -#endif -using namespace std; -using ll = long long; -#define int ll -#define endl '\n' -const int mod = 1000000007; -// clang-format off -template istream &operator>>(istream &cin,pair &a) { return cin>>a.first>>a.second; } -template istream &operator>>(istream &cin,vector &a) { for (auto &x:a) cin>>x; return cin; } -template ostream &operator<<(ostream &cout,const pair &a) { return cout< ostream &operator<<(ostream &cout,const vector> &a) { for (auto &x:a) cout< ostream &operator<<(ostream &cout,const vector &a) { int n=a.size(); if (!n) return cout; cout< &v, int sum, vector> &dp) -{ - if (i >= v.size()) - return 0; - - if (dp[i][cur] != -1) - return dp[i][cur]; - int x = cur; - x += v[i]; - x %= 9; - int pick = 0, notpick = 0; - if (x == 9 - sum) - { - return 1; - } - pick = f(i + 1, x, v, sum, dp); - notpick = f(i + 1, cur, v, sum, dp); - return dp[i][cur] = (pick || notpick); -} -void solve() -{ - ll t, m, n, a, b; - string h; - cin >> h; - int sum = 0; - vector v; - for (char &c : h) - { - int x = c - '0'; - if (x <= 3) - { - if (x == 2) - v.push_back(2); - if (x == 3) - v.push_back(6); - } - sum += x; - } - sum %= 9; - dbg(sum, v); - if (!sum) - { - cout << ""YES"" << endl; - return; - } - vector> dp(v.size() + 1, vector(10, -1)); - if (f(0, 0, v, sum, dp)) - { - cout << ""YES"" << endl; - } - else - cout << ""NO"" << endl; -} -int32_t main() -{ - ios::sync_with_stdio(false); - cin.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}",2 -Bhagwa009,2050C - Uninteresting Number,c++23 ,307638612,307637521,"// Jai Ho mere Gurudev Bhagwan Ki - -// Jai Jai Shree Radhey Shyam - -#include - -#define int long long int - -#define ll long long int - -#define pb push_back - -#define debug(...) __f (#__VA_ARGS__, __VA_ARGS__) - -using namespace std; - - - -/*B U G*/ - -template - -void __f (const char* name, Arg1&& arg1) { cout << name << "" : "" << arg1 << endl; } - -template - -void __f (const char* names, Arg1&& arg1, Args&&... args){ - - const char* comma = strchr (names + 1, ','); - - cout.write (names, comma - names) << "" : "" << arg1 << "" | ""; - - __f (comma + 1, args...); - -} - -/*B U G*/ - -vector> dp; - - - -bool sol(int index, int sum, int n, const vector &vec) { - - if (index == n) return (sum % 9 == 0); - - if (sum % 9 == 0) return true; - - - - if (dp[index][sum % 9] != -1) return dp[index][sum % 9]; - - - - // Option 1: Don't change vec[index] - - bool res = sol(index + 1, sum, n, vec); - - if (res) { - - dp[index][sum % 9] = true; - - return true; - - } - - - - // Option 2: Square vec[index] if possible - - int val = vec[index]; - - int squared = val * val; - - if (squared < 10) { - - res = sol(index + 1, sum - val + squared, n, vec); - - if (res) { - - dp[index][sum % 9] = true; - - return true; - - } - - } - - - - dp[index][sum % 9] = false; - - return false; - -} - - - -void solve() { - - string s; - - cin >> s; - - int sum = 0; - - vector vec; - - - - for (char c : s) { - - int val = c - '0'; - - sum += val; - - if (val != 1 && val < 4) vec.push_back(val); - - } - - - - dp.assign(vec.size() + 1, vector(9, -1)); - - - - cout << (sol(0, sum, vec.size(), vec) ? ""YES\n"" : ""NO\n""); - -} - - - -int32_t main(){ - - ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); - - #ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - - #endif - - int t = 1; - - cin >> t; - - for(int i = 0; i < t; i++){ - - solve(); - - } - - return 0; - -}","// Jai Ho mere Gurudev Bhagwan Ki - -// Jai Jai Shree Radhey Shyam - -#include - -#define int long long int - -#define ll long long int - -#define pb push_back - -#define debug(...) __f (#__VA_ARGS__, __VA_ARGS__) - -using namespace std; - - - -/*B U G*/ - -template - -void __f (const char* name, Arg1&& arg1) { cout << name << "" : "" << arg1 << endl; } - -template - -void __f (const char* names, Arg1&& arg1, Args&&... args){ - - const char* comma = strchr (names + 1, ','); - - cout.write (names, comma - names) << "" : "" << arg1 << "" | ""; - - __f (comma + 1, args...); - -} - -/*B U G*/ - -struct hash_pair { - - size_t operator()(const pair& p) const { - - return hash()(p.first) ^ (hash()(p.second) << 1); - - } - -}; - -unordered_map, bool, hash_pair> dp; - -bool sol(int index, int sum, int n, vector &vec){ - - pair key = {index, sum}; - - if(index == n) return dp[key] = (sum%9 == 0); - - if(sum%9 == 0) return dp[key] = true; - - if(dp.find(key) != dp.end()) return dp[key]; - - int real_val = vec[index], real_sum = sum; - - sum+=(vec[index]*(vec[index]-1)); vec[index]*=vec[index]; - - if(sum%9 == 0) return dp[key] = true; - - if(sol(index+1, sum, n, vec)) return dp[key] = true; - - vec[index] = real_val, sum = real_sum; - - if(sol(index+1, sum, n, vec)) return dp[key] = true; - - - - return dp[key] = false; - -} - -void solve() { - - string s; cin>>s; int n = s.size(), sum = 0; - - vector vec; - - for(int i = 0; i> t; - - for(int i = 0; i < t; i++){ - - solve(); - - } - - return 0; - -}",1 -javaandgames,2050C - Uninteresting Number,c++17 ,297729888,297730214,"#include -#define ll long long -using namespace std; - -vector digitchanges(9); - //track the digits already searched - -bool searchchanges(int curmod9, int remaining2s, int remaining3s){ - if(curmod9 == 0){ - return true; - } - // 1 2 3 4 5 6 7 8 0 - /* - if(digitchanges[curmod9] == true){ - cout << curmod9 << ""\n""; - return false; - } - */ - if(remaining2s == 0 && remaining3s == 0){ - // cout << remaining2s << "" "" << remaining3s << ""\n""; - return false; - } - digitchanges[curmod9] = true; - bool true2 = false; - bool true3 = false; - if(remaining2s > 0){ - int newmod9 = (2 + curmod9) % 9; - true2 = searchchanges(newmod9, remaining2s-1, remaining3s); - } - if(remaining3s > 0){ - int newmod9 = (6+curmod9) % 9; - true3 = searchchanges(newmod9, remaining2s, remaining3s-1); - } - if(true2 == true || true3 == true){ - return true; - } - return false; -} - -void solve() { - int n[2]; //only store twos and threes - n[0] = 0; //count of 2s - n[1] = 0; //count of 3s - int totalmod9 = 0; - string s; - cin >> s; - int len = s.length(); - for(int i = 0; i < len; i++){ - if(s[i] == '3'){ - n[1]++; - } - if(s[i] == '2'){ - n[0]++; - } - int digit = s[i] - '0'; - totalmod9 += digit; - totalmod9 = totalmod9 % 9; - } - - if(n[0] > 10){ - cout << ""YES""; - } else if(n[0]>5&&n[1]>5){ - cout << ""YES""; - }else if(searchchanges(totalmod9, n[0], n[1]) == true){ - cout << ""YES""; - } else{ - cout << ""NO""; - } - return; -} - -int main() { - int TESTS; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}","#include -#define ll long long -using namespace std; - -vector digitchanges(9); - //track the digits already searched - -bool searchchanges(int curmod9, int remaining2s, int remaining3s, int iterator){ - if(curmod9 == 0){ - return true; - } - if(iterator > 9){ - return false; - } - iterator++; - // 1 2 3 4 5 6 7 8 0 - /* - if(digitchanges[curmod9] == true){ - cout << curmod9 << ""\n""; - return false; - } - */ - if(remaining2s == 0 && remaining3s == 0){ - // cout << remaining2s << "" "" << remaining3s << ""\n""; - return false; - } - digitchanges[curmod9] = true; - bool true2 = false; - bool true3 = false; - if(remaining2s > 0){ - int newmod9 = (2 + curmod9) % 9; - true2 = searchchanges(newmod9, remaining2s-1, remaining3s, iterator); - } - if(remaining3s > 0){ - int newmod9 = (6+curmod9) % 9; - true3 = searchchanges(newmod9, remaining2s, remaining3s-1, iterator); - } - if(true2 == true || true3 == true){ - return true; - } - return false; -} - -void solve() { - int n[2]; //only store twos and threes - n[0] = 0; //count of 2s - n[1] = 0; //count of 3s - int totalmod9 = 0; - string s; - cin >> s; - int len = s.length(); - for(int i = 0; i < len; i++){ - if(s[i] == '3'){ - n[1]++; - } - if(s[i] == '2'){ - n[0]++; - } - int digit = s[i] - '0'; - totalmod9 += digit; - totalmod9 = totalmod9 % 9; - } - - if(n[0] > 9){ - cout << ""YES""; - } else if(n[0]>3&&n[1]>3){ - cout << ""YES""; - } else if(n[1]>3 && totalmod9%3==0){ - cout << ""YES""; - }else if(searchchanges(totalmod9, n[0], n[1], 0) == true){ - cout << ""YES""; - } else{ - cout << ""NO""; - } - return; -} - -int main() { - int TESTS; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}",2 -rourkela,2050C - Uninteresting Number,c++17 ,298076002,298075642,"#include -#define inpv(v,n) for(int i=0;i>v[i] -#define disp(v) for(auto x:v) cout< vll; - -void solve() { - // Your code here - string s; - cin>>s; - int sum=0; - ll three=0; - ll two=0; - for(ll i=0;i> t; - while (t--) solve(); -}","#include -#define inpv(v,n) for(int i=0;i>v[i] -#define disp(v) for(auto x:v) cout< vll; - -void solve() { - // Your code here - string s; - cin>>s; - int sum=0; - ll three=0; - ll two=0; - for(ll i=0;i> t; - while (t--) solve(); -}",1 -rokonio,2050C - Uninteresting Number,c++17 ,299507818,299505929,"#include -using namespace std; - -#define RANGE(i, a, b) \ - for (auto i = a - (a > b); (i < b) ^ (a > b); i += 1 - 2 * (a > b)) -#define ll long long -/* - 1 -> 1 No change - 2 -> 4: +2 // only this can be applied twice, in that case: +5 - 3 -> 9: +6 - So we can change x 2s to 4, and y 3s to 6s. The new remainder of the number - becomes 2*x + 6*y == 0 [9]. We must find a solution for (x, y), with the upper - bound being the actual number of occurence of 2s and 3s. - Les restes possible d'un multiplication par 2 mod 9: - 1*2 = 2 [9] - 2*2 = 4 [9] - 3*2 = 6 [9] - 4*2 = 8 [9] - 5*2 = 0 [9] - Les restes possible d'une multiplication par 6 mod 9: - 1*6 = 6 [9] - 2*6 = 3 [9] - 3*6 = 0 [9] - Tableau des additions possibles: - ---- 0 2 4 6 8 - 0 0 2 4 6 7 - 3 3 5 7 0 2 - 6 6 8 1 3 5 - -*/ - -void solve() { - string n; - cin >> n; - ll count2 = 0, count3 = 0; - ll rem = 0; - for (auto d : n) { - int c = d - '0'; - rem += c % 10; - rem %= 9; - if (c % 10 == 2) - count2++; - else if (c % 10 == 3) - count3++; - } - for (int n2 = 0; n2 <= min(count2, 10ll); n2++) - for (int n3 = 0; n3 <= min(count3, 10ll); n3++) - if (((n2 * 2) % 9 + (n3 * 6) % 9 + rem) % 9 == 0) { - cout << ""Yes"" << endl; - return; - } - cout << ""No"" << endl; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - -#define RANGE(i, a, b) \ - for (auto i = a - (a > b); (i < b) ^ (a > b); i += 1 - 2 * (a > b)) -#define ll long long -/* - 1 -> 1 No change - 2 -> 4: +2 // only this can be applied twice, in that case: +5 - 3 -> 9: +6 - So we can change x 2s to 4, and y 3s to 6s. The new remainder of the number - becomes 2*x + 6*y == 0 [9]. We must find a solution for (x, y), with the upper - bound being the actual number of occurence of 2s and 3s. - Les restes possible d'un multiplication par 2 mod 9: - 1*2 = 2 [9] - 2*2 = 4 [9] - 3*2 = 6 [9] - 4*2 = 8 [9] - 5*2 = 0 [9] - Les restes possible d'une multiplication par 6 mod 9: - 1*6 = 6 [9] - 2*6 = 3 [9] - 3*6 = 0 [9] - Tableau des additions possibles: - ---- 0 2 4 6 8 - 0 0 2 4 6 7 - 3 3 5 7 0 2 - 6 6 8 1 3 5 - -*/ - -void solve() { - ll n; - cin >> n; - ll count2 = 0, count3 = 0; - ll rem = 0; - for (; n > 0; n /= 10) { - rem += n % 10; - if (n % 10 == 2) - count2++; - else if (n % 10 == 3) - count3++; - } - rem %= 9; - // cout << count2 << "" "" << count3 << "" "" << rem << endl; - // if (count2 >= 5 && count3 >= 3) { - // cout << ""Yes"" << endl; - // return; - // } - for (int n2 = 0; n2 <= min(count2, 10ll); n2++) - for (int n3 = 0; n3 <= min(count3, 10ll); n3++) - if (((n2 * 2) % 9 + (n3 * 6) % 9 + rem) % 9 == 0) { - cout << ""Yes"" << endl; - return; - } - cout << ""No"" << endl; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -lazieV,2050C - Uninteresting Number,c++23 ,298461581,298463085,"#include -#include -#include -#include - -using namespace std; - -int main(){ - int tc; - cin>>tc; - for(int _=0; _>x; - long long sum=0; - int twos=0; - int threes=0; - for(long long i=0; i -#include -#include -#include - -using namespace std; - -int main(){ - int tc; - cin>>tc; - for(int _=0; _>x; - long long sum=0; - int twos=0; - int threes=0; - for(long long i=0; i -using namespace std; - -#define endl ""\n"" -#define read(arr) for (auto &x : arr) cin >> x; -#define print(arr) for (auto &x : arr) cout << x << ' '; cout << endl; -#define sortv(arr) sort(arr.begin(), arr.end()) -#define sorta(arr) sort(arr.begin(), arr.end()) -#define revers(arr) reverse(arr.begin(), arr.end()) -#define ll long long -#define vi vector -#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL)) - -void solve() { - ll n; - cin>>n; - ll c2=0,c3=0; - ll sum=0; - while(n){ - int l =n%10; - if(l==2){ - c2++; - } - if(l==3){ - c3++; - } - sum+=l; - n/=10; - } - if(c2>10) c2=10; - if(c3>10) c3=10; - for(int i =0;i<=c2;i++){ - for(int j =0;j<=c3;j++){ - ll x =sum + i*2 + j*6; - if(x%9==0){ - cout<<""YES""<> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - -#define endl ""\n"" -#define read(arr) for (auto &x : arr) cin >> x; -#define print(arr) for (auto &x : arr) cout << x << ' '; cout << endl; -#define sortv(arr) sort(arr.begin(), arr.end()) -#define sorta(arr) sort(arr.begin(), arr.end()) -#define revers(arr) reverse(arr.begin(), arr.end()) -#define ll long long -#define vi vector -#define fastread() (ios_base::sync_with_stdio(false), cin.tie(NULL)) - -void solve() { - string s; - cin>>s; - ll c2=0,c3=0; - ll sum=0; - for(auto &i:s){ - if(i=='2') c2++; - if(i=='3') c3++; - sum+=i-'0'; - } - if(c2>10) c2=10; - if(c3>10) c3=10; - for(int i =0;i<=c2;i++){ - for(int j =0;j<=c3;j++){ - ll x =sum + i*2 + j*6; - if(x%9==0){ - cout<<""YES""<> t; - while (t--) { - solve(); - } - return 0; -}",2 -NO_LMfoor,2050C - Uninteresting Number,c++23 ,299287729,299180776,"#include -#pragma GCC optimize(""O3"") -#define all(x) x.begin(),x.end() ; -using namespace std; -int main(){ - - ios_base::sync_with_stdio(false); - cin.tie(NULL);cout.tie(NULL); - int testcase; - cin>>testcase; - while(testcase--){ - string s; - cin>>s; - int cnttwo=0,cntthree=0 ,sum=0; - for(int i=0;i29,31,33,35,41,47,53 -// {3}->33,39,45,47,49,51,53 - -// {8}->35,43,51 -// 2-29,31,37,43 -// 3-33,39,41,43 -// 8->35,43 -// 2,3 -// 41- -// 2--3 -// 3--2 -// 41- -// 2=>43,45,47,53,59 -// 3=>47,53,55,57,59 -// // 8=>49,57,5930+2 -// 10-3 -// 7-2 -// 69+56= -","#include -#pragma GCC optimize(""O3"") -#define all(x) x.begin(),x.end() ; -using namespace std; -int main(){ - - ios_base::sync_with_stdio(false); - cin.tie(NULL);cout.tie(NULL); - int testcase; - cin>>testcase; - while(testcase--){ - string s; - cin>>s; - int cnttwo=0,cntthree=0 ,sum=0; - for(int i=0;itwo; - vectorsix; - vectoreight; - int sum_=sum,sum__=sum,sum___=sum; - for(int i=0;ist; - for(auto it: two){ - st.insert(it); - } - for(auto it: six)st.insert(it); - for(auto it: eight)st.insert(it); - - bool flag=false; - for(auto it: st){ - if(it%9==0){ -// cout<<""Yes\n""; - flag=true; - } - } - flag?cout<<""Yes\n"":cout<<""No\n""; - } - - } - return 0; -} -",1 -anushkarajput,2050C - Uninteresting Number,c++23 ,307140630,307142540,"#include - -using namespace std; - - - -int main() { - - int t; cin >> t; - - while (t--) { - - long long n; cin >> n; - - if(n%9 == 0){ - - cout << ""yes"" << endl; - - continue; - - } - - - - long long sum = 0; - - int cnt2 = 0, cnt3 = 0; - - long long temp = n; - - while(temp>0){ - - int d = temp%10; - - sum += d; - - if(d==2) cnt2++; - - if(d==3) cnt3++; - - temp /= 10; - - } - - - - int r = 9-sum % 9; - - bool possible = false; - - int max_a = min(cnt2, 9); - - int max_b = min(cnt3, 3); - - for (int a = 0; a <= max_a; a++){ - - for (int b = 0; b <= max_b; b++){ - - if ((2 * a + 6 * b) % 9 == r) { - - possible = true; - - break; - - } - - } - - if(possible) break; - - } - - cout << (possible ? ""yes"" : ""no"") << endl; - - } - - return 0; - -}","#include - -using namespace std; - - - -int main() { - - int t; cin >> t; - - while (t--) { - - string n; cin >> n; - - long long sum = 0; - - int cnt2 = 0, cnt3 = 0; - - for (char c : n) { - - int d = c - '0'; - - sum += d; - - if(d == 2) cnt2++; - - if(d == 3) cnt3++; - - } - - - - if(sum % 9 == 0) { - - cout << ""yes"" << endl; - - continue; - - } - - - - int r = 9-(sum % 9); - - bool possible = false; - - int max_a = min(cnt2, 9); - - int max_b = min(cnt3, 3); - - for (int a = 0; a <= max_a; a++){ - - for (int b = 0; b <= max_b; b++){ - - if ((2*a + 6*b) % 9==r) { - - possible = true; - - break; - - } - - } - - if(possible) break; - - } - - cout << (possible ? ""yes"" : ""no"") << endl; - - } - - return 0; - -}",2 -star.light,2050C - Uninteresting Number,c++17 ,308493091,308493678,"#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long; - - - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define f(i, a, b) for (int i = a; i < b; ++i) - -#define pb push_back - - - -/*vector getDigits(ll num) { - - vector digits; - - while (num > 0) { - - digits.push_back(num % 10); - - num /= 10; - - } - - return digits; - -}*/ - - - -void solve() { - - string n; - - cin >> n; - - - - //vector num; - - //num= getDigits(n); - - //int k = accumulate(num.begin(), num.end(), 0LL); - - - - int k=0; - - for(char i:n){ - - k=k+(i-'0'); - - } - - bool no= true; - - int tw=0; - - int si=0; - - for(char i:n){ - - if(i=='2') tw++; - - if(i=='3') si++; - - } - - - - tw=min(tw,10); - - si=min(si,10); - - - - f(i,0,tw+1){ - - f(j,0,si+1){ - - if((k+2*i+6*j)%9==0){ - - cout<<""Yes""<<""\n""; - - no=false; - - break; - - } - - } - - } - - if(no) cout<<""No""<<""\n""; - - - - - -} - - - -int main() { - - fastio; - - int t; - - cin >> t; - - while (t--) solve(); - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long; - - - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define f(i, a, b) for (int i = a; i < b; ++i) - -#define pb push_back - - - -/*vector getDigits(ll num) { - - vector digits; - - while (num > 0) { - - digits.push_back(num % 10); - - num /= 10; - - } - - return digits; - -}*/ - - - -void solve() { - - string n; - - cin >> n; - - - - //vector num; - - //num= getDigits(n); - - //int k = accumulate(num.begin(), num.end(), 0LL); - - - - int k=0; - - for(char i:n){ - - k=k+(i-'0'); - - } - - - - int tw=0; - - int si=0; - - for(char i:n){ - - if(i=='2') tw++; - - if(i=='3') si++; - - } - - - - tw=min(tw,10); - - si=min(si,10); - - - - f(i,0,tw+1){ - - f(j,0,si+1){ - - int v=(k+2*i+6*j); - - if(v%9==0){ - - cout<<""Yes""<<""\n""; - - - - return; - - } - - } - - } - - cout<<""No""<<""\n""; - - - - - -} - - - -int main() { - - fastio; - - int t; - - cin >> t; - - while (t--) solve(); - - return 0; - -}",2 -dk2005,2050C - Uninteresting Number,c++17 ,298594795,298629897,"#include -using namespace std; -#define ll long long int - -void solve() { - string s; - cin >> s; - map mp; - mp['1']=0; - mp['2']=0; - mp['3']=0; - mp['4']=0; - mp['5']=0; - mp['6']=0; - mp['7']=0; - mp['8']=0; - for(int i=0;i0) mp['8']--; - else mp['1']++; - } - if(s[i]=='2'){ - mp['2']++; - }if(s[i]=='4'){ - if(mp['5']>0) mp['5']--; - else mp['4']++; - }if(s[i]=='5'){ - if(mp['4']>0) mp['4']--; - else mp['5']++; - }if(s[i]=='7'){ - mp['7']++; - } - if(s[i]=='8'){ - if(mp['1']>0) mp['1']--; - else mp['8']++; - } - if(s[i]=='6') mp['6']++; - if(s[i]=='3') mp['3']++; - } - ll sum=0; - sum += 9 - (mp['1'] % 9); - sum += 9 - ((3*mp['3']) % 9); - sum += 9 - ((8*mp['8']) % 9); - sum += 9 - ((7*mp['7']) % 9); - sum += 9 - ((4*mp['4']) % 9); - sum += 9 - ((5*mp['5']) % 9); - sum += 9 - ((2*mp['2']) % 9); - if(mp['6']%3 != 0) sum += 9 - ((6*mp['6']) % 9); - int ans = (sum%9); - if(ans==0 || ans==9){ - cout << ""YES\n""; - } - if(ans==1){ - if(mp['2']>=5){ - cout << ""YES\n""; - } - else cout << ""NO\n""; - } - if(ans==2){ - if(mp['2']>=1) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==3){ - if(mp['2']>=6 || mp['3']>=2) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==4){ - if(mp['2']>=2) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==5){ - if((mp['2']>=4 && mp['3']>=1) || (mp['2']>=1 && mp['3']>=2) || (mp['2']>=7)) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==6){ - if(mp['3']>=1 || mp['2']>=3) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==7){ - if((mp['2']>=5 && mp['3']>=1) || (mp['2']>=1 && mp['3']>=2) || (mp['2']>=8)) cout << ""YES\n""; - else cout << ""NO\n""; - } - if(ans==8){ - if(mp['2']>=4) cout << ""YES\n""; - else cout << ""NO\n""; - } -} - -int main() { - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -#define ll long long int - -void solve() { - string s; - cin >> s; - map mp; - mp['2']=0; - mp['3']=0; - ll sum=0; - for(int i=0;i> t; - while (t--) { - solve(); - } - return 0; -} -",2 -pred695,2050C - Uninteresting Number,c++23 ,298862119,298858945," -/* - * - *@author - pred695 - * - */ -/*弱い も -خاک سے آیا ہوں، خاک بنوں گا۔*/ -/*-------------------------------------------****************-------------------------------------------------------****************----------------------------------------------------------------------*/ -#include -using namespace std; -#define vi vector -#define vvi vector> -#define pb push_back -#define eb emplace_back -#define pii pair -#define vp vector -#define ppb pop_back -#define pf push_front -#define ppf pop_front -#define int long long -#define ull unsigned long long -#define lld long double -#define all(x) x.begin(),x.end() -#define rep(i, a, b) for(int i = a; i < b; i++) -#define repr(i, a, b) for(int i = a; i >= b; i--) -#define read(a, n) rep(i, 0, n) cin >> a[i] -#define readx(a, n, m) rep(i, 0, n){rep(j, 0, m) cin >> a[i][j];} -#define print(a, n) rep(i, 0, n) cout << a[i] << "" ""; cout << endl -#define printx(a, n, m) rep(i, 0, n){rep(j, 0, m) cout << a[i][j] << "" ""; cout << endl;} -#define endl ""\n"" -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define M 1000000007 -#define prec(x) cout << fixed << setprecision(x) -#define bpc(x) __builtin_popcountll(x) -#define sz(x) (int)(x.size()) -#define bpl(x) __builtin_clzll(x) -#define bpt(x) __builtin_ctzll(x) -#define lg(x) __lg(x) - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"": ""; deb(x); cerr << endl; -#else -#define debug(x) -#endif - -void deb(int t) {cerr << t;} -void deb(string t) {cerr << t;} -void deb(char t) {cerr << t;} -void deb(double t) {cerr << t;} -void deb(ull t) {cerr << t;} - -template void deb(pair p) {cerr << ""{""; deb(p.ff); cerr << "",""; deb(p.ss); cerr << ""}"";} -template void deb(vector v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(set v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(multiset v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(map v) {cerr << ""[ ""; for (auto i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(map> v) {cerr << ""{ ""; for (auto i : v) {cerr << i.first << "": "";deb(i.second);cerr << "" "";}cerr << ""}"";} -template void deb(priority_queue pq) {cerr << ""[ ""; while (!pq.empty()) {deb(pq.top()); cerr << "" ""; pq.pop();} cerr << ""]"";} -template void deb(deque dq) {cerr << ""[ ""; for (T i : dq) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(list lst) {cerr << ""[ ""; for (T i : lst) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(unordered_map um) {cerr << ""{ ""; for (auto i : um) {cerr << i.first << "": ""; deb(i.second); cerr << "" "";} cerr << ""}"";} - -void fast(){ -ios_base::sync_with_stdio(false); -cin.tie(NULL); -cout.tie(NULL); -} -int ipow(int a, int b){ - int ans = 1; - while(b) - { - if(b & 1) - ans = (ans*a)%M; - a = (a*a)%M; - b>>=1; - } - return ans; -} -clock_t start; -void exectime(){ - clock_t end=clock(); - double time_taken = double(end - start) / double(CLOCKS_PER_SEC); - #ifndef ONLINE_JUDGE - cout << endl; - cout << endl; - cout << ""Executed in ""<< fixed << time_taken << setprecision(10); - cout << "" secs "" << endl; - #endif -} -const int d4x[4]={-1, 0, 1, 0}, d4y[4]={0, 1, 0, -1}; -const int d8x[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8]={0, 1, 1, 1, 0, -1, -1, -1}; -const int c8x[8]={-2, -1, 1, 2, 2, 1, -1, -2}, c8y[8]={1, 2, 2, 1, -1, -2, -2, -1}; -vector custom_c8x(8, 0), custom_c8y(8, 0); -void make_custom_movements(int a, int b){ - custom_c8x={b, -b, b, -b, a, -a, a, -a}; - custom_c8y={a, a, -a, -a, b, b, -b, -b}; -} - -struct custom_priority{ - bool operator() (pii &a, pii &b){ - if(a.ff == b.ff){ - return a.ss < b.ss; - } - return a.ff > b.ff; - } -}; - -const int N = 1e7 + 10; - -/*----------------------------------------------------------------------MAIN CODE------------------------------------------------------------------------------------------------------------------------*/ -void solve(){ - string n; - cin >> n; - ull s = 0; - int two = 0, three = 0; - for(auto &x : n) { - two += x == '2'; - three += x == '3'; - s += (x - '0'); - } - // only two and three needs to be considered. - for(int i = 0; i <= min(two, 8LL); i++) { - for(int j = 0; j <= min(three, 8LL); j++) { - debug(s + 6 * j) - if((s + (i * 2) + (j * 6)) % 9 == 0) { - yes; - return; - } - } - } - no; - - -} -/*----------------------------------------------------------------------ありがと-------------------------------------------------------------------------------------------------------------------------*/ -signed main(){ -fast(); -int t = 1; -cin >> t; -start = clock(); -for(int i = 0; i < t; i++){ - // cout << ""Case #"" << i + 1 << "": ""; - solve(); -} -exectime(); -return 0; -}"," -/* - * - *@author - pred695 - * - */ -/*弱い も -خاک سے آیا ہوں، خاک بنوں گا۔*/ -/*-------------------------------------------****************-------------------------------------------------------****************----------------------------------------------------------------------*/ -#include -using namespace std; -#define vi vector -#define vvi vector> -#define pb push_back -#define eb emplace_back -#define pii pair -#define vp vector -#define ppb pop_back -#define pf push_front -#define ppf pop_front -#define int long long -#define ull unsigned long long -#define lld long double -#define all(x) x.begin(),x.end() -#define rep(i, a, b) for(int i = a; i < b; i++) -#define repr(i, a, b) for(int i = a; i >= b; i--) -#define read(a, n) rep(i, 0, n) cin >> a[i] -#define readx(a, n, m) rep(i, 0, n){rep(j, 0, m) cin >> a[i][j];} -#define print(a, n) rep(i, 0, n) cout << a[i] << "" ""; cout << endl -#define printx(a, n, m) rep(i, 0, n){rep(j, 0, m) cout << a[i][j] << "" ""; cout << endl;} -#define endl ""\n"" -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define M 1000000007 -#define prec(x) cout << fixed << setprecision(x) -#define bpc(x) __builtin_popcountll(x) -#define sz(x) (int)(x.size()) -#define bpl(x) __builtin_clzll(x) -#define bpt(x) __builtin_ctzll(x) -#define lg(x) __lg(x) - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"": ""; deb(x); cerr << endl; -#else -#define debug(x) -#endif - -void deb(int t) {cerr << t;} -void deb(string t) {cerr << t;} -void deb(char t) {cerr << t;} -void deb(double t) {cerr << t;} -void deb(ull t) {cerr << t;} - -template void deb(pair p) {cerr << ""{""; deb(p.ff); cerr << "",""; deb(p.ss); cerr << ""}"";} -template void deb(vector v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(set v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(multiset v) {cerr << ""[ ""; for (T i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(map v) {cerr << ""[ ""; for (auto i : v) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(map> v) {cerr << ""{ ""; for (auto i : v) {cerr << i.first << "": "";deb(i.second);cerr << "" "";}cerr << ""}"";} -template void deb(priority_queue pq) {cerr << ""[ ""; while (!pq.empty()) {deb(pq.top()); cerr << "" ""; pq.pop();} cerr << ""]"";} -template void deb(deque dq) {cerr << ""[ ""; for (T i : dq) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(list lst) {cerr << ""[ ""; for (T i : lst) {deb(i); cerr << "" "";} cerr << ""]"";} -template void deb(unordered_map um) {cerr << ""{ ""; for (auto i : um) {cerr << i.first << "": ""; deb(i.second); cerr << "" "";} cerr << ""}"";} - -void fast(){ -ios_base::sync_with_stdio(false); -cin.tie(NULL); -cout.tie(NULL); -} -int ipow(int a, int b){ - int ans = 1; - while(b) - { - if(b & 1) - ans = (ans*a)%M; - a = (a*a)%M; - b>>=1; - } - return ans; -} -clock_t start; -void exectime(){ - clock_t end=clock(); - double time_taken = double(end - start) / double(CLOCKS_PER_SEC); - #ifndef ONLINE_JUDGE - cout << endl; - cout << endl; - cout << ""Executed in ""<< fixed << time_taken << setprecision(10); - cout << "" secs "" << endl; - #endif -} -const int d4x[4]={-1, 0, 1, 0}, d4y[4]={0, 1, 0, -1}; -const int d8x[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8y[8]={0, 1, 1, 1, 0, -1, -1, -1}; -const int c8x[8]={-2, -1, 1, 2, 2, 1, -1, -2}, c8y[8]={1, 2, 2, 1, -1, -2, -2, -1}; -vector custom_c8x(8, 0), custom_c8y(8, 0); -void make_custom_movements(int a, int b){ - custom_c8x={b, -b, b, -b, a, -a, a, -a}; - custom_c8y={a, a, -a, -a, b, b, -b, -b}; -} - -struct custom_priority{ - bool operator() (pii &a, pii &b){ - if(a.ff == b.ff){ - return a.ss < b.ss; - } - return a.ff > b.ff; - } -}; - -const int N = 1e7 + 10; - -/*----------------------------------------------------------------------MAIN CODE------------------------------------------------------------------------------------------------------------------------*/ -void solve(){ - int n; - cin >> n; - int s = 0; - unordered_map mp; - mp[2] = 0; - mp[3] = 0; - while(n > 0) { - s += n % 10; - mp[n % 10]++; - n /= 10; - } - // only two and three needs to be considered. - if(s % 9 == 0) { - yes; - return; - } - int temp = s; - debug(s) - debug(mp[2]) - debug(mp[3]) - for(int i = 0; i <= min(mp[2], 8LL); i++) { - s += i * 2; - for(int j = 0; j <= min(mp[3], 8LL); j++) { - debug(j) - debug(i) - debug(s + 6 * j) - if((s + (j * 6)) % 9 == 0) { - yes; - return; - } - } - s = temp; - } - no; - - -} -/*----------------------------------------------------------------------ありがと-------------------------------------------------------------------------------------------------------------------------*/ -signed main(){ -fast(); -int t = 1; -cin >> t; -start = clock(); -for(int i = 0; i < t; i++){ - // cout << ""Case #"" << i + 1 << "": ""; - solve(); -} -exectime(); -return 0; -}",1 -salmansakib,2050C - Uninteresting Number,c++17 ,307623124,308567922,"#include - -using namespace std; - -int main() - -{ - - long long int n,a,b,t=0,th=0,p,i,j,sum,d,s; - - cin>>s;while(s--){ - - cin>>n; - - a=n; - - b=0; - - t=0;th=0; - - while(a>0) - - { - - b=b+(a%10); - - if((a%10)==2){t=t+1;} - - if((a%10)==3){th=th+1;} - - a=a/10; - - } - - - - - - p=0; - - for(i=0;i - -using namespace std; - -int main() - -{ - - int n,i,t,th,sum,p,j,d,b,s; - - char str[100005]; - - cin>>s;while(s--){ - - cin>>str; - - t=0;th=0;sum=0; - - for(i=0;i=1) - - { - - cout<<""YES""; - - }else{cout<<""NO"";} - - cout<<""\n""; - - } - - return 0; - -} - -",2 -HeloWorldwontwork,2050C - Uninteresting Number,c++17 ,299301769,299301848,"using namespace std; -#include -#define ll long long -#define vi vector -#define vll vector -#define vb vector -#define vc vector -#define vs vector -#define si set -#define sll set -#define sc set -#define ss set -#define usi unordered_set -#define pqi priority_queue -#define pqll priority_queue -#define mii map -#define umii unordered_map -#define pii pair -#define pllll pair -#define f(i,s,e) for(int i = s; i < e; i++) -#define cf(i,s,e) for(int i = s; i <= e; i++) -#define rf(i,e,s) for(int i = e-1; i >= s; i--) -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define pb push_back -#define eb embrace_back -#define mp make_pair -#define fi first -#define se second -#define ub upper_bound -#define lb lower_bound -#define sz(x) (int)(x).size() -#define fastioa ios::sync_with_stdio(0); cin.tie(0); freopen(""a.in"", ""r"", stdin); freopen(""a.out"", ""w"", stdout); -#define fastio ios::sync_with_stdio(0); cin.tie(0); -#define MOD 1000000007 -#define inf 1e9 // Use for int (e.g., distance) -#define inf_ll 1e18 // Use for long long -#define eps 1e-9 // Precision for floating-point comparisons - -void solve() -{ - string number; - cin >> number; - ll sum = 0; - int a = 0, b = 0; - for (char digit : number) - { - sum += (digit - '0'); - if (digit - '0' == 2) a++; - if (digit - '0' == 3) b++; - } - f (i, 0, min(8, a + 1)) - { - f (j, 0, min(8, b + 1)) - { - if ((sum + i * 2 + j * 6) % 9 == 0) - { - cout << ""YES"" << ""\n""; return; - } - } - } - cout << ""No"" << ""\n""; - - -} -int main() -{ - fastio - int t; cin >> t; - while (t --) - { - solve(); - } -}","using namespace std; -#include -#define ll long long -#define vi vector -#define vll vector -#define vb vector -#define vc vector -#define vs vector -#define si set -#define sll set -#define sc set -#define ss set -#define usi unordered_set -#define pqi priority_queue -#define pqll priority_queue -#define mii map -#define umii unordered_map -#define pii pair -#define pllll pair -#define f(i,s,e) for(int i = s; i < e; i++) -#define cf(i,s,e) for(int i = s; i <= e; i++) -#define rf(i,e,s) for(int i = e-1; i >= s; i--) -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define pb push_back -#define eb embrace_back -#define mp make_pair -#define fi first -#define se second -#define ub upper_bound -#define lb lower_bound -#define sz(x) (int)(x).size() -#define fastioa ios::sync_with_stdio(0); cin.tie(0); freopen(""a.in"", ""r"", stdin); freopen(""a.out"", ""w"", stdout); -#define fastio ios::sync_with_stdio(0); cin.tie(0); -#define MOD 1000000007 -#define inf 1e9 // Use for int (e.g., distance) -#define inf_ll 1e18 // Use for long long -#define eps 1e-9 // Precision for floating-point comparisons - -void solve() -{ - string number; - cin >> number; - ll sum = 0; - int a = 0, b = 0; - for (char digit : number) - { - sum += (digit - '0'); - if (digit - '0' == 2) a++; - if (digit - '0' == 3) b++; - } - cf (i, 0, min(8, a)) - { - cf (j, 0, min(8, b)) - { - if ((sum + i * 2 + j * 6) % 9 == 0) - { - cout << ""YES"" << ""\n""; return; - } - } - } - cout << ""No"" << ""\n""; - - -} -int main() -{ - fastio - int t; cin >> t; - while (t --) - { - solve(); - } -}",2 -Aakash19971,2050C - Uninteresting Number,c++23 ,298634244,298637060,"#include - #include - #include - #include - using namespace std; - typedef long long ll; - typedef vector vi; - typedef vector vll; - #define cy() cout << ""YES"" << '\n' - #define cn() cout << ""NO"" << '\n' - const double pi= 3.14159265358979323846; - - // Function to check if an integer is prime or not - bool isprime(ll n){ - if(n<2){ - return false; - } - for(ll i = 2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; - } - bool pointscompare(pair &a ,pair &b){ - return a.second>b.second; - } - bool goaldiffcompare(pair &a , pair &b){ - return a.second>b.second; - } - bool cmp(pair& a, - pair& b) - { - return a.second < b.second; - } - bool isSorted(const std::vector& arr) { - for (size_t i = 1; i < arr.size(); ++i) { - if (arr[i] < arr[i - 1]) { - return false; - } - } - return true; - } - - void solve(){ - // ............................... - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - string s; - cin >> s; - int sum = 0; - int two = 0; - int three = 0; - - for(int i = 0;i,int> v; - for(int i = 0;i<=two;i++){ - for(int j = 0;j<=three;j++){ - v[{i,j}] = 2*i + 6*j; - } - } - for(auto x : v){ - // cout << x.first.first << "" "" << x.first.second << "" "" << x.second << ' ' << sum%9 << '\n'; - } - bool p = false; - for(auto x : v){ - if((sum+x.second)%9==0){ - cout << ""YES"" << '\n'; - p = true; - break; - } - } - if(!p){ - cout << ""NO"" << '\n'; - } - - } - int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - std::cout.tie(0); - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - int tt; - cin >> tt; - while(tt--){ - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - auto t1 = high_resolution_clock::now(); - solve(); - auto t2 = high_resolution_clock::now(); - auto ms_int = duration_cast(t2 - t1); - duration ms_double = t2 - t1; - // std::cout << ms_double.count() << ""ms\n""; - } - return 0; - } ","#include - #include - #include - #include - using namespace std; - typedef long long ll; - typedef vector vi; - typedef vector vll; - #define cy() cout << ""YES"" << '\n' - #define cn() cout << ""NO"" << '\n' - const double pi= 3.14159265358979323846; - - // Function to check if an integer is prime or not - bool isprime(ll n){ - if(n<2){ - return false; - } - for(ll i = 2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; - } - bool pointscompare(pair &a ,pair &b){ - return a.second>b.second; - } - bool goaldiffcompare(pair &a , pair &b){ - return a.second>b.second; - } - bool cmp(pair& a, - pair& b) - { - return a.second < b.second; - } - bool isSorted(const std::vector& arr) { - for (size_t i = 1; i < arr.size(); ++i) { - if (arr[i] < arr[i - 1]) { - return false; - } - } - return true; - } - - void solve(){ - // ............................... - // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - string s; - cin >> s; - int sum = 0; - int two = 0; - int three = 0; - - for(int i = 0;i v; - if(sum%9!=0){ - - - for(int i = 0;i<=min(8,two);i++){ - for(int j = 0;j<=min(8,three);j++){ - v.insert(2*i + 6*j); - } - } - for(auto x : v){ - // cout << x.first.first << "" "" << x.first.second << "" "" << x.second << ' ' << sum%9 << '\n'; - } - bool p = false; - for(auto x : v){ - if((sum+x)%9==0){ - cout << ""YES"" << '\n'; - p = true; - break; - } - } - if(!p){ - cout << ""NO"" << '\n'; - } - }else{ - cout << ""YES"" << '\n'; - } - } - int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - std::cout.tie(0); - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - int tt; - cin >> tt; - while(tt--){ - using std::chrono::high_resolution_clock; - using std::chrono::duration_cast; - using std::chrono::duration; - using std::chrono::milliseconds; - auto t1 = high_resolution_clock::now(); - solve(); - auto t2 = high_resolution_clock::now(); - auto ms_int = duration_cast(t2 - t1); - duration ms_double = t2 - t1; - // std::cout << ms_double.count() << ""ms\n""; - } - return 0; - } ",2 -Rhythm-Panchal,2050C - Uninteresting Number,c++23 ,299387957,299386721,"#include -using namespace std; - - -#include -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set ; - - -#define int long long -#define fr(i , j, k) for(int i=j ; i> n; -#define pb push_back -#define nl ""\n"" - -int mod = 1e9 + 7 ; -int power(int x , int y , int m){ - int res =1 ; - x = x%m; - if ( x == 0 )return 0 ; - while( y >0 ) { - if( y%2 )res = (res*x)%m ; - y = y>>1 ; - x = (x*x ) %m ; - } - return res ; -} -int submod( int x , int y , int mod ){ - return ( (x-y)%mod + mod )%mod; -} - - - -int32_t main () { - int tt; - cin >> tt ; - while(tt--){ - string s; - cin >> s; - int x = 0 , y =0 ; - int sum =0 ; - for(auto it: s ){ - if( it == '2')x++; - else if ( it == '3')y++; - sum += it-'0'; - } - - // cerr << x << "" "" << y << "" "" << sum << nl; - int ans =0 ; - fr(i,0,min((int)10,x+1)){ - fr(j,0,min((int)10,y+1)){ - int temp = (j*6 + i*2); - // cout << temp+sum << nl; - if( (temp + sum)%9 == 0 )ans = 1 ; - } - } - if(ans )cout << ""YES"" << nl; - else cout << ""NO"" << nl; - - } - return 0; -}","#include -using namespace std; - - -#include -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set ; - - -#define int long long -#define fr(i , j, k) for(int i=j ; i> n; -#define pb push_back -#define nl ""\n"" - -int mod = 1e9 + 7 ; -int power(int x , int y , int m){ - int res =1 ; - x = x%m; - if ( x == 0 )return 0 ; - while( y >0 ) { - if( y%2 )res = (res*x)%m ; - y = y>>1 ; - x = (x*x ) %m ; - } - return res ; -} -int submod( int x , int y , int mod ){ - return ( (x-y)%mod + mod )%mod; -} - - - -int32_t main () { - int tt; - cin >> tt ; - while(tt--){ - string s; - cin >> s; - int x = 0 , y =0 ; - int sum =0 ; - for(auto it: s ){ - if( it == '2')x++; - else if ( it == '3')y++; - sum += it-'0'; - } - x = x%9; - y = y%3; - // cerr << x << "" "" << y << "" "" << sum << nl; - int ans =0 ; - fr(i,0,x+1){ - fr(j,0,y+1){ - int temp = (j*6 + i*2); - // cout << temp+sum << nl; - if( (temp + sum)%9 == 0 )ans = 1 ; - } - } - if(ans )cout << ""YES"" << nl; - else cout << ""NO"" << nl; - - } - return 0; -}",1 -ajaythakurr,2050C - Uninteresting Number,c++23 ,299548380,299549107,"#include -#include -using namespace std; -#define int long long -signed main() -{ - int tt;cin>>tt; - while(tt--){ - int n;cin>>n; - int sum=0; - int ct2=0,ct3=0; - while(n>0){ - sum+=n%10; - if(n%10==2) ct2+=1; - else if(n%10==3) ct3+=1; - n/=10; - } - int temp=sum; - bool f=false; - int p=10; - for(int i=0;i<=min(p,ct2);i++){ - - for (int j=0;j<=min(p,ct3);j++){ - temp=sum; - temp+=(i*2)+(j*6); - if(temp%9==0) { - - f=true; - break; - } - } - if(f) break; - - } - if(f) cout<<""YES""< -using namespace std; -#define int long long - -signed main() { - int tt; - cin >> tt; - while (tt--) { - string s; - cin >> s; - - int sum = 0, ct2 = 0, ct3 = 0; - - for (char c : s) { - int digit = c - '0'; - sum += digit; - if (digit == 2) ct2++; - if (digit == 3) ct3++; - } - - bool f = false; - for (int i = 0; i <= min(10LL, ct2); i++) { - for (int j = 0; j <= min(10LL, ct3); j++) { - if ((sum + i * 2 + j * 6) % 9 == 0) { - f = true; - break; - } - } - if (f) break; - } - - if (f) cout << ""YES"" << endl; - else cout << ""NO"" << endl; - } - return 0; -} -",2 -AlexZdor,2050C - Uninteresting Number,c++23 ,306109772,306108702,"#include - -#include - -#include - -#include - - - -typedef long long ll; - - - -using namespace std; - - - - - -int main() - -{ - - int t; - - cin >> t; - - while(t--) - - { - - string s; - - cin >> s; - - - - if(s == ""5472778912773"") - - { - - cout << ""NO"" << endl; - - continue; - - } - - int twos = 0; - - int threes = 0; - - long long sum = 0; - - for(int i = 0; i < s.size(); i++) - - { - - if(s[i] == '2')twos++; - - if(s[i] == '3')threes++; - - sum += (int)s[i] - 48; - - } - - int fl = 0; - - //cout << twos << "" "" << threes << "" ""<< sum << endl; - - for(int i = 0; i <= min(10, twos);i++) - - { - - for(int j = 0; j <= min(10, threes); j++) - - { - - if (((sum + 2*i + 6*j)%9) == 0) - - { - - fl = 1; - - //cout << i << "" "" << j << endl; - - } - - } - - } - - if(fl) - - cout << ""YES"" << endl; - - else - - cout << ""NO"" << endl; - - - - - - } - -}","#include - -#include - -#include - -#include - - - -typedef long long ll; - - - -using namespace std; - - - - - -int main() - -{ - - int t; - - cin >> t; - - while(t--) - - { - - string s; - - cin >> s; - - int twos = 0; - - int threes = 0; - - long long sum = 0; - - for(int i = 0; i < s.size(); i++) - - { - - if(s[i] == '2')twos++; - - if(s[i] == '3')threes++; - - sum += (int)s[i]; - - } - - int fl = 0; - - for(int i = 0; i <= min(10, twos);i++) - - { - - for(int j = 0; j <= min(10, threes); j++) - - { - - if (((sum + 2*i + 6*j)%9) == 0) - - { - - fl = 1; - - cout << i << "" "" << j << endl; - - } - - } - - } - - if(fl) - - cout << ""YES"" << endl; - - else - - cout << ""NO"" << endl; - - - - - - } - -}",1 -AA8403,2050C - Uninteresting Number,c++17 ,299283451,299284474,"#include -#include -#include -using namespace std; - -int main() -{ - int t; - cin>>t; - - while(t--) - { - string s; - cin>>s; - - int rem=0; -int cnt2=0; -int cnt3=0; - for(int i=0;i -#include -#include -using namespace std; - -int main() -{ - int t; - cin>>t; - - while(t--) - { - string s; - cin>>s; - - int rem=0; -int cnt2=0; -int cnt3=0; - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int tc; cin >> tc; - for(int t = 0; t < tc; t++){ - string s; cin >> s; - int twos = 0, threes = 0, sum = 0; - for(char n : s){ - int curr = n - '0'; - sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; } - } - bool works = false; - int need = 9 - (sum % 9); - if(need % 2 == 1){ need+=9; } - if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? (need%6 == 0 ? 6 :need%6) : 6*threes))/2 <= twos)){ works = true; } - if(works || need % 9 == 0){ cout << ""YES"" << endl; } else{ cout << ""NO"" << endl; } - } -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int tc; cin >> tc; - for(int t = 0; t < tc; t++){ - string s; cin >> s; - int twos = 0, threes = 0, sum = 0; - for(char n : s){ - int curr = n - '0'; - sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; } - } - bool works = false; - int need = 9 - (sum % 9); - if(need % 2 == 1){ need+=9; } - if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need - (need % 6) : 6*threes))/2 <= twos)){ works = true; } - if(works || need % 9 == 0){ cout << ""YES"" << endl; } else{ cout << ""NO"" << endl; } - } -}",2 -atharva,2050C - Uninteresting Number,c++23 ,297714163,297717797,"#include - -#define ll long long -#define pb push_back -#define ff first -#define ss second - -using namespace std; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - //freopen(""input1.txt"", ""r"", stdin); - //freopen(""output1.txt"", ""w"", stdout); - int t; cin >> t; - while(t--){ - string s; cin >> s; - int twos=0,sixs=0,sum=0; - for(int i=0; i ((2*twos)+(6*sixs))){ - break; - } - if(isum-(6*sixs) >= 0){ - isum -= 6*sixs; - } - if(isum%2 == 0 and (2*twos)>=(isum-(isum%2))){ - flag = 1; - break; - } - } - if(flag == 1) cout << ""YES"" << endl; - else cout << ""NO"" << endl; - } - } -}","#include - -#define ll long long -#define pb push_back -#define ff first -#define ss second - -using namespace std; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - //freopen(""input1.txt"", ""r"", stdin); - //freopen(""output1.txt"", ""w"", stdout); - int t; cin >> t; - while(t--){ - string s; cin >> s; - int twos=0,sixs=0,sum=0; - for(int i=0; i twos) break; - for(int j=0; j<9; j++){ - if(j > sixs) break; - if((sum + (i*2) + (j*6))%9 == 0){ - flag = 1; - break; - } - } - if(flag == 1){ - break; - } - } - if(flag==1) cout << ""YES"" << endl; - else cout << ""NO"" << endl; - } - } -}",2 -Madhav_2023,2050C - Uninteresting Number,c++17 ,306425453,306428435,"#include - -using namespace std; - - - -#define RADHE_RADHE ios_base::sync_with_stdio(false); - -#define endl '\n' - - - -int main() { - - RADHE_RADHE; - - - - int t; - - cin >> t; - - while (t--) { - - // First of all if no.s sum%9==0, then ""YES""... - - // If not the case and there is no presence of 2 or 3 then ""NO""... - - - - // Its not required to have more than 8 2's and 3 6's... - - - - string s; - - cin>>s; - - - - int n = s.size(); - - int cnt2 = 0; - - int cnt3 = 0; - - - - long long sum = 0; - - - - for(int i = 0;i - -using namespace std; - - - -#define RADHE_RADHE ios_base::sync_with_stdio(false); - -#define endl '\n' - - - -int main() { - - RADHE_RADHE; - - - - int t; - - cin >> t; - - while (t--) { - - // First of all if no.s sum%9==0, then ""YES""... - - // If not the case and there is no presence of 2 or 3 then ""NO""... - - // Its not required to have more than 8 2's and 3 6's... - - - - string s; - - cin>>s; - - - - int n = s.size(); - - int cnt2 = 0; - - int cnt3 = 0; - - - - long long sum = 0; - - - - for(int i = 0;i -#define int long long int -#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); -using namespace std; - -void solve(){ - string s; cin >> s; - - int sum = 0; - int cnt_2 = 0, cnt_3 = 0; - for(int i = 0; i < s.size(); i++){ - sum += (s[i] - '0'); - if(s[i] == '2') cnt_2++; - else if(s[i] == '3') cnt_3++; - } - - for(int i = 0; i <= cnt_2; i++){ - int k = (sum + (i * 2)) % 9; - if((k % 9 == 0) || (cnt_3 && (k % 9 == 3)) || (cnt_3 >= 2 && (k % 9 == 6))){ - cout << ""YES\n""; - return; - } - } - cout << ""NO\n""; - -} - -signed main(){ - fast; - int t = 1; - cin >> t; - while(t--){ - solve(); - } -}","#include -#define int long long int -#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); -using namespace std; - -void solve(){ - string s; cin >> s; - int sum = 0; - for(int i = 0; i < s.size(); i++){ - sum += (s[i] - '0'); - } - - int cnt_2 = 0, cnt_3 = 0; - for(int i = 0; i < s.size(); i++){ - if(s[i] == '2') cnt_2++; - else if(s[i] == '3') cnt_3++; - } - - while(1){ - int t = sum; - if(sum % 9 == 0){ - cout << ""YES\n""; - return; - } - - int d = 18 - (sum % 18); - if(d & 1){ - d = 9 - (sum % 9); - } - int six = min(cnt_3, (d / 6)); - d -= six * 6; - sum += (six * 6); - cnt_3 -= six; - - int two = min(cnt_2, (d / 2)); - d -= two * 2; - sum += (two * 2); - cnt_2 -= two; - - if(t == sum) break; - } - - cout << ""NO\n""; -} - -signed main(){ - fast; - int t = 1; - cin >> t; - while(t--){ - solve(); - } -}",1 -Aya92,2050C - Uninteresting Number,c++17 ,298159649,298157118,"#include -using namespace std; -#define ll long long -#define pb push_back -int main(){ - ll t,ans=0; - cin>>t; - string n; - for(ll i=0; i>n; - ll m=n.size(); - ans=0; - map map; - for(ll i=0; i=4){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==2){ - if(map['3']>=2 && map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - if(map['2']>=8){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=5){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==3){ - if(map['3']>=1){ - cout<<""YES""<<""\n""; - continue; - } - if(map['2']>=3){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==4){ - if(map['3']>=2 && map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - if(map['2']>=7){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=4){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==5){ - if(map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==6){ - if(map['3']>=2 ||map['2']>=6 ){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=3){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==7){ - if(map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==8){ - if(map['2']>=5){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - } - cout<<""NO""<<""\n""; - } - return 0; -}","#include -using namespace std; -#define ll long long -#define pb push_back -int main(){ - ll t,ans=0; - cin>>t; - string n; - for(ll i=0; i>n; - ll m=n.size(); - ans=0; - map map; - for(ll i=0; i=4){ - cout<<""YES""<<""\n""; - continue; - } - else if(map['3']>=1 && map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==2){ - if(map['3']>=2 && map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - if(map['2']>=8){ - cout<<""YES""<<""\n""; - continue; - } - if(map['3']>=1 && map['2']>=5){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==3){ - if(map['3']>=1){ - cout<<""YES""<<""\n""; - continue; - } - else if(map['2']>=3){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==4){ - if(map['3']>=2 && map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - else if(map['2']>=7){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==5){ - if(map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==6){ - if(map['3']>=2 ||map['2']>=6 ){ - cout<<""YES""<<""\n""; - continue; - } - else if(map['3']>=1 && map['2']>=3){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==7){ - if(map['2']>=1){ - cout<<""YES""<<""\n""; - continue; - } - } - else if(ans==8){ - if(map['2']>=5){ - cout<<""YES""<<""\n""; - continue; - } - else if(map['3']>=1 && map['2']>=2){ - cout<<""YES""<<""\n""; - continue; - } - } - cout<<""NO""<<""\n""; - } - return 0; -}",1 -rohitkumaroff,2050C - Uninteresting Number,c++20 ,298899194,298770462,"#include -using namespace std; - -#define int long long int - -int m = 1; - -int find9(string x, int i, int n, int d){ - - - - if(d == 0){ - return 1; - } - if(i >= n){ - return 0; - } - - if((x[i]-'0') == 2){ - - int a1 = find9(x, i+1, n, d); - - - d+=2; - d%=9; - - int a2 = find9(x, i+1, n, d); - - return (a1||a2); - } - else if(x[i]-'0' == 3){ - int a1 = find9(x, i+1, n, d); - - - d+= 6; - d%=9; - - int a2 = find9(x, i+1, n, d); - - return (a1||a2); - } - else - return find9(x, i+1, n, d); -} - - -void solve(){ - string x; - cin >> x; - - int ans = 0; - - - int n = x.size(); - - int a = 0, b = 0; - - int d = 0; - for (int i = 0; i < n; ++i){ - - if(x[i]-'0' == 2) - a++; - if(x[i]-'0' == 3) - b++; - - int s = (x[i]-'0') + d*10; - - d = s%9; - } - - if(d == 0 || a >= 8){ - ans = 1; - } - - if(d == 1){ - if(a >= 4 || (b>= 1 && a >= 1)){ - ans = 1; - } - - }else if(d == 2){ - if(a>=8 || (b>=1 && a>= 5) || (b >=2 && a >=2)) - ans = 1; - - }else if(d == 3){ - if(b>=1 || a >= 3){ - ans = 1; - } - - }else if(d == 4){ - if(a >= 7 || (b>=2 && a>= 1) || (b>=1 && a>= 4)) - ans = 1; - - }else if(d == 5){ - if(a>=2) - ans = 1; - - }else if(d == 6){ - if(b>= 2 || a>= 6 || (b>=1 && a>= 3)) - ans = 1; - - }else if(d == 7){ - if(a>= 1) - ans = 1; - - }else if(d == 8){ - if(a>= 5 || (b>= 1 && a>= 2)) - ans = 1; - } - - // else - // ans = find9(x, 0, n, d); - - - - - - if(ans){ - cout<< ""YES""<< endl; - } - else{ - cout<< ""NO"" << endl; - } -} - -int32_t main(){ - string s; - int x = 0; - - // for(int i = 0; i<43*2+1; i++) - // getline(cin, s); - - // int i = 0; - // while(s[i] != '\0'){ - // cout<< s[i]; - // i++; - // } - - // cout<< s << endl; - - int t = 0; - - cin>> t; - while(t--){ - solve(); - } - - return 0; -}","#include -using namespace std; - -#define int long long int - -int m = 1; - -int find9(string x, int i, int n, int m){ - - // cerr << i << ""-""<= n){ - return 0; - } - - // cerr << m; - - // cerr << (x/(m*1)) << "" ..""; - - - if( (x[i]-'0') < 4 && (x[i]-'0') > 1 ){ - - - - if((x[i]-'0') == 2){ - - int a1 = find9(x, i+1, n, m); - - x[i] = (4+'0'); - - int a2 = find9(x, i+1, n, m); - - return (a1||a2); - } - else{ - int a1 = find9(x, i+1, n, m); - - x[i] = (9+'0'); - - int a2 = find9(x, i+1, n, m); - - return (a1||a2); - } - - } - else - return find9(x, i+1, n, m); -} - - -void solve(){ - string x; - cin >> x; - - int ans = 0; - - - int n = x.size(); - - - ans = find9(x, 0, n, 1); - - - if(ans){ - cout<< ""YES""<< endl; - } - else{ - cout<< ""NO"" << endl; - } -} - -int32_t main(){ - string s; - int x = 0; - - // for(int i = 0; i<43*2+1; i++) - // getline(cin, s); - - // int i = 0; - // while(s[i] != '\0'){ - // cout<< s[i]; - // i++; - // } - - // cout<< s << endl; - - int t = 0; - - cin>> t; - while(t--){ - solve(); - } - - return 0; -}",1 -todh_dunga_podh_dunga,2050C - Uninteresting Number,c++23 ,299403598,299398469,"#include -using namespace std; -int main(){ - int t; - cin>>t; - while (t>0){ - t--; - string s; - cin>>s; - int sum=0; - int n=s.length(); - int two=0,three=0; - for (int i=0;i -using namespace std; -int main(){ - int t; - cin>>t; - while (t>0){ - t--; - string s; - cin>>s; - int sum=0; - int n=s.length(); - int two=0,three=0; - for (int i=0;i=1 && three>=1) || (two>=4))){ - cout<<""YES""<=1)||(two>=3))){ - cout<<""YES""<=2){ - cout<<""YES""<=1){ - cout<<""YES""<=2){ - if ((three==1 && two>=5)|| (three>1)){ - cout<<""YES""<=1){ - if ((three==1 && two>=4)|| (three>=2)){ - cout<<""YES""<=3) || (three>=2)){ - cout<<""YES""<=2){ - if ((three==1)|| (two>=5)){ - cout<<""YES""< -using namespace std; - -#define add emplace_back -#define FOR(i, a, b) for(int i = a;i < (b); ++i) -#define FORD(i , a, b) for(int i = a;i >= (b);i--) -#define all(v) v.begin(), v.end() -#define len(x) (x).size(); - -using ll = long long; -using pi = pair; -using vi = vector; -using vll = vector; - -const int mod = 1e9+7; - -void Main(){ - string s; - cin >> s; - int sum = 0, two = 0, three = 0; - - for(int i = 0;i < s.size(); i++){ - sum = (sum + (s[i]-48)) % 9; - two += (s[i]=='2'); - three += (s[i]=='3'); - } - if(sum==0) return void( cout << ""YES"" << ""\n""); - bool ok = 0; - for(int i = 0;i <= min(two, 6); i++){ - for(int j = 0;j <= min(three, 4); j++){ - if((sum+2*i+6*j)%9 == 0) ok = 1; - } - } - cout << (ok?""YES"":""NO"") << ""\n""; -} - -int main(){ - cin.tie(0)->sync_with_stdio(0); - cin.tie(NULL); - - int t; - for(cin>>t; t; t--) Main(); - - return 0; -} - -","#include -using namespace std; - -#define add emplace_back -#define FOR(i, a, b) for(int i = a;i < (b); ++i) -#define FORD(i , a, b) for(int i = a;i >= (b);i--) -#define all(v) v.begin(), v.end() -#define len(x) (x).size(); - -using ll = long long; -using pi = pair; -using vi = vector; -using vll = vector; - -const int mod = 1e9+7; - -void Main(){ - string s; - cin >> s; - int sum = 0, two = 0, three = 0; - - for(int i = 0;i < s.size(); i++){ - sum = (sum + (s[i]-48)) % 9; - two += (s[i]=='2'); - three += (s[i]=='3'); - } - if(sum==0) return void( cout << ""YES"" << ""\n""); - bool ok = 0; - for(int i = 0;i <= min(two, 100); i++){ - for(int j = 0;j <= min(three, 100); j++){ - if((sum+2*i+6*j)%9 == 0) ok = 1; - } - } - cout << (ok?""YES"":""NO"") << ""\n""; -} - -int main(){ - cin.tie(0)->sync_with_stdio(0); - cin.tie(NULL); - - int t; - for(cin>>t; t; t--) Main(); - - return 0; -} - -",2 -Jollychen#,2050C - Uninteresting Number,c++17 ,297646975,297648149,"#include -using namespace std; -const int N=1e5+10; -int t; -int a[N]; -int c; -int x,y; -int sum; -bool f=0; -int main(){ - cin>>t; - while(t--){ - x=0,y=0; - for(int i=1;i<=N;i++){ - a[i]=0; - } - string s; - cin>>s; - c=s.size(); - sum=0; - f=0; - for(int i=0;i -using namespace std; -const int N=1e5+10; -int t; -int c; -int x,y; -int sum; -bool f=0; -int main(){ - cin>>t; - while(t--){ - string s; - cin>>s; - c=s.size(); - sum=0; - f=0; - x=0,y=0; - for(int i=0;i - -using namespace std; - -#define int long long - - - -signed main () { - - ios_base::sync_with_stdio(0); cin.tie(0); - - - - int tt; cin >> tt; - - - - while (tt--) { - - string s; cin >> s; - - int n = s.size(); - - vector a (n); - - for(int i = 0; i < n; i++) a[i] = s[i] - '0'; - - - - vector> dp (n + 1 , vector (10 , 0)); - - - - dp[0][a[0]] = 1; - - if(a[0] * a[0] < 10) dp[0][(a[0] * a[0]) % 9] = 1; - - - - for(int i = 1; i < n; i++){ - - for(int j = 0; j < 10; j++){ - - if(dp[i - 1][j]){ - - dp[i][(j + a[i]) % 9] = 1; - - if(a[i] * a[i] < 10) dp[i][(j + a[i] * a[i]) % 9] = 1; - - } - - } - - } - - - - cout << (dp[n - 1][0] ? ""YES\n"" : ""NO\n""); - - } - - - - return 0; - -} - -","#include - -using namespace std; - -#define int long long - - - -signed main () { - - ios_base::sync_with_stdio(0); cin.tie(0); - - - - int tt; cin >> tt; - - - - while (tt--) { - - string s; cin >> s; - - int n = s.size(); - - vector a (n); - - for(int i = 0; i < n; i++) a[i] = s[i] - '0'; - - - - vector> dp (n + 1 , vector (10 , 0)); - - - - dp[0][a[0] % 9] = 1; - - if(a[0] * a[0] < 10) dp[0][(a[0] * a[0]) % 9] = 1; - - - - for(int i = 1; i < n; i++){ - - for(int j = 0; j < 10; j++){ - - if(dp[i - 1][j]){ - - dp[i][(j + a[i]) % 9] = 1; - - if(a[i] * a[i] < 10) dp[i][(j + a[i] * a[i]) % 9] = 1; - - } - - } - - } - - - - cout << (dp[n - 1][0] ? ""YES\n"" : ""NO\n""); - - } - - - - return 0; - -} - -",2 -Happiness_3,2050C - Uninteresting Number,c++23 ,297653254,297652981,"#include -using namespace std; -#define ll long long - -void solve(){ - string s; - cin >> s; - ll n = s.size(); - s = '?' + s; - ll n2 = 0; - ll n3 = 0; - ll sum = 0; - for(ll i = 1 ; i <= n ; ++i){ - if(s[i] == '2') n2++; - if(s[i] == '3') n3++; - sum += s[i] - '0'; - } - if(sum % 9 == 0){ - cout << ""YES"" << endl; - return; - } - for(ll i = 0 ; i <= n2 ; ++i){ - for(ll j = 0 ; j <= n3 ; ++j){ - ll tsum = sum + i * 2 + j * 6; - if(tsum % 9 == 0){ - cout << ""YES"" << endl; - return; - } - } - } - cout << ""NO"" << endl; -} - -signed main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define ll long long - -void solve(){ - string s; - cin >> s; - ll n = s.size(); - s = '?' + s; - ll n2 = 0; - ll n3 = 0; - ll sum = 0; - for(ll i = 1 ; i <= n ; ++i){ - if(s[i] == '2') n2++; - if(s[i] == '3') n3++; - sum += s[i] - '0'; - } - if(sum % 9 == 0){ - cout << ""YES"" << endl; - return; - } - for(ll i = 0 ; i <= n2 ; ++i){ - for(ll j = 0 ; j <= n3 ; ++j){ - sum += i * 2 + j * 6; - if(sum % 9 == 0){ - cout << ""YES"" << endl; - return; - } - } - } - cout << ""NO"" << endl; -} - -signed main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}",1 -JagannathHari,2050C - Uninteresting Number,python,298735495,298735801,"def solve(num): - three = 0 - two = 0 - s = 0 - s2 = 0 - for i in num: - if i == '2': - two += 1 - - if i == '3': - s2 += 9 - else: - s2 += int(i) - s += int(i) - - if s%9 == 0 or s2%9==0: - return ""YES"" - - if two == 0: - return ""NO"" - - for i in range(1,two + 1): - if (2*i + s ) % 9 == 0 or (2*i + s2 ) % 9 == 0 : - return ""YES"" - return ""NO"" - -for _ in range(int(input())): - print(solve(input())) -","def solve(num): - three = 0 - two = 0 - s = 0 - for i in num: - if i == '2': - two += 1 - elif i == '3': - three += 1 - s += int(i) - - if s % 9 == 0: - return ""YES"" - - for i in range(min(9,two+1)): - for j in range(min(7,three+1)): - if (s + 2*i + 6*j ) % 9 == 0: - return ""YES"" - return ""NO"" - - - - -for _ in range(int(input())): - print(solve(input())) -",2 -shivani_12,2050C - Uninteresting Number,c++17 ,299388160,299387813,"#include -using namespace std ; - -typedef unsigned long long ull ; -typedef long long ll ; -typedef long double ld ; - -const ll mod = 1e9+7; -const ld eps = 1e-9 ; -const ll maxn = 1e5+1; -const ll inf = 1e15; -const ll minf = -inf; - -#define int long long -#define ll long long int -#define pb push_back -#define mp make_pair -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() - - -void solve(){ - string s ; cin >> s ; - int n = s.size() ; - - int sum = 0 ; - int two = 0 , three = 0 ; - - for(int i=0;i> t; - for(int i=1; i<=t; i++){ - //cout<<""Case #""< -using namespace std ; - -typedef unsigned long long ull ; -typedef long long ll ; -typedef long double ld ; - -const ll mod = 1e9+7; -const ld eps = 1e-9 ; -const ll maxn = 1e5+1; -const ll inf = 1e15; -const ll minf = -inf; - -#define int long long -#define ll long long int -#define pb push_back -#define mp make_pair -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() - - -void solve(){ - string s ; cin >> s ; - int n = s.size() ; - - int sum = 0 ; - int two = 0 , three = 0 ; - - for(int i=0;i> t; - for(int i=1; i<=t; i++){ - //cout<<""Case #""< -using namespace std; -#define ll long long -#define M 1000000007 -void solve() { - string n; - cin>>n; - ll b = 0, c = 0; - ll sum = 0; - for(ll i = 0;i>t; - for(ll j = 0;j -using namespace std; -#define ll long long -#define M 1000000007 -void solve() { - ll n; - cin>>n; - map mp; - ll sum = 0; - while(n>0) { - ll a = n%10; - n/=10; - mp[a]++; - sum+=a; - } - ll b = mp[2]; - ll c = mp[3]; - for(ll i = 0;i<=b;i++) { - for(ll x = 0;x<=c;x++) { - if((sum+(i*2)+(x*6))%9==0) { - cout<<""YES""<<""\n""; - return; - } - } - } - cout<<""NO""<<""\n""; -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t; - cin>>t; - for(ll j = 0;j -#define ll long long -#define yes cout<<""YES""<<'\n'; -#define no cout<<""NO""<<'\n'; -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) (a*b)/gcd(a,b) -#define tst int t;cin>>t;while(t--) -#define pb push_back -#define rvs reverse(v.begin(),v.end()) -#define srt sort(v.begin(),v.end()) - -#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) -using namespace std; -const ll N = 1e7+9; - -void solve() -{ -string s; -cin>>s; -ll n,i,j, sum = 0, c2 = 0, c3 = 0; -for(i = 0;i=0 && c3>0) - { - mod-=6; - c3--; - } - while(mod-2>=0 && c2>0) - { - mod-=2; - c2--; - } - if(mod==0)yes - else no -} -} - - - -int main() -{ -optimize(); -tst{ -solve(); -} -return 0; -} -","/* In the Name of ALLAH */ -/** Minhaz Uddin - Dept of CSE,Comilla University*/ - -#include -#define ll long long -#define yes cout<<""YES""<<'\n'; -#define no cout<<""NO""<<'\n'; -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) (a*b)/gcd(a,b) -#define tst int t;cin>>t;while(t--) -#define pb push_back -#define rvs reverse(v.begin(),v.end()) -#define srt sort(v.begin(),v.end()) - -#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) -using namespace std; -const ll N = 1e7+9; - -void solve() -{ -string s; -cin>>s; -ll n,i,j, sum = 0, c2 = 0, c3 = 0; -for(i = 0;i=1 && c2>=1)yes - else if(c3>=0 && c2>=4)yes - else no - } - else if(mod==7) - { - if(c2>=2 && c3>=2)yes - else if(c3>=1 && c2>=5)yes - else no - } - else if(mod==6) - { - if(c3>=1)yes - else if(c2>=3) yes - else no - } - else if(mod==5) - { - if(c3>=2 && c2>=1)yes - else if(c3>=1 && c2>=4)yes - else no - } - else if(mod==4) - { - if(c2>=2 )yes - else no - } - else if(mod==3) - { - if(c3>=1 && c2>=3)yes - else if(c3>=2)yes - else if(c2>=6)yes - else no - } - else if(mod==2) - { - if(c2>=1)yes - else no - } - else if(mod==1) - { - if(c2>=2 && c3>=1)yes - else if(c2>=5)yes - else no - } - - else no -} -} - - - -int main() -{ -optimize(); -tst{ -solve(); -} -return 0; -}",1 -LinGu,2050C - Uninteresting Number,c++23 ,306285913,306288272,"// Problem: B. Transfusion - -// Contest: Codeforces - Codeforces Round 991 (Div. 3) - -// URL: https://codeforces.com/contest/2050/problem/B - -// Memory Limit: 256 MB - -// Time Limit: 2000 ms - -// - -// Powered by CP Editor (https://cpeditor.org) - - - -//#pragma GCC optimize(""O3"") - -//#pragma GCC optimize(""Ofast"") - - - -#include - -#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) - -#define pii pair - -#define pdd pair - -#define lowbit(x) (x & -x) - -#define all(x) x.begin(), x.end() - - - -#define Rep(i, x) for(auto &i : x) - -#define L(i, x, y) for(int i = x; i <= y; ++ i) - -#define R(i, x, y) for(int i = x; i >= y; -- i) - -#define rd(x) scanf(""%lld"", &(x)) - -#define p_b push_back - -#define ft first - -#define sd second - -using namespace std; - -template using vc = vector; - -template using _pq = priority_queue, greater>; - -using i64 = long long; - -using u64 = unsigned long long; - -using u32 = unsigned; - -const int N = 2e5 + 10; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void solve() { - - int n; cin >> n; - - vc a(n); - - L(i, 0, n - 1) cin >> a[i]; - - i64 sum = reduce(a.begin(), a.end()); - - if(sum % n) { - - cout << ""NO\n""; - - return; - - } - - i64 sd = sum / n; - - //cout << sd << ""\n""; - - L(i, 0, n - 1) { - - //cout << i << "" "" << a[i] << ""\n""; - - if(i >= n - 2 && a[i] != sd) { - - cout << ""NO\n""; - - return; - - } - - if(a[i] == sd) continue; - - else { - - - - if(a[i] < sd) { - - i64 dif = sd - a[i]; - - a[i] = sd; - - if(a[i + 2] >= dif) a[i + 2] -= dif; - - else { - - cout << ""NO\n""; - - return; - - } - - } - - else { - - i64 dif = a[i] - sd; - - a[i] = sd; - - a[i + 2] += dif; - - } - - - - - - - - - - } - - } - - L(i, 0, n - 1) { - - if(a[i] != sd) { - - cout << ""NO\n""; - - return; - - } - - } - - cout << ""YES\n""; - -} - - - - - -int main() { - - Begin; - - int _; _ = 1; - - cin >> _; - - while(_--) solve(); - - return 0; - -}","// Problem: C. Uninteresting Number - -// Contest: Codeforces - Codeforces Round 991 (Div. 3) - -// URL: https://codeforces.com/contest/2050/problem/C - -// Memory Limit: 256 MB - -// Time Limit: 2000 ms - -// - -// Powered by CP Editor (https://cpeditor.org) - - - -//#pragma GCC optimize(""O3"") - -//#pragma GCC optimize(""Ofast"") - - - -#include - -#define Begin ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) - -#define pii pair - -#define pdd pair - -#define lowbit(x) (x & -x) - -#define all(x) x.begin(), x.end() - - - -#define Rep(i, x) for(auto &i : x) - -#define L(i, x, y) for(int i = x; i <= y; ++ i) - -#define R(i, x, y) for(int i = x; i >= y; -- i) - -#define rd(x) scanf(""%lld"", &(x)) - -#define p_b push_back - -#define ft first - -#define sd second - -using namespace std; - -template using vc = vector; - -template using _pq = priority_queue, greater>; - -using i64 = long long; - -using u64 = unsigned long long; - -using u32 = unsigned; - -const int N = 2e5 + 10; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void solve() { - - string s; cin >> s; - - int sum = 0; map mp; - - int n = s.size(); - - L(i, 0, n - 1) { - - if(s[i] - '0' == 2) mp[2] ++; - - if(s[i] - '0' == 3) mp[3] ++; - - sum += s[i] - '0'; - - } - - if(sum % 9 == 0) { - - cout << ""YES\n""; - - return; - - } - - int dif = sum % 9; - - L(i, 0, mp[2]) { - - L(j, 0, mp[3]) { - - if((i * 2 + j * 6 + dif) % 9 == 0) { - - cout << ""YES\n""; - - return; - - } - - } - - } - - cout << ""NO\n""; - -} - - - - - -int main() { - - Begin; - - int _; _ = 1; - - cin >> _; - - while(_--) solve(); - - return 0; - -}",2 -zaemon2806,2050C - Uninteresting Number,c++17 ,298545879,298545602,"#include -using namespace std; -#define int long long - -int32_t main(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int sum = 0; - for (char c : s) - { - sum += c - '0'; - } - int twos = 0; - int threes = 0; - for (char c : s) - { - if (c == '2') - { - twos++; - } - else if (c == '3') - { - threes++; - } - } - int flag = 0; - for (int i = 0; i <= min(10ll, twos); i++) - { - for (int j = 0; j <= min(10ll, threes); j++) - { - if ((sum + 2 * i + 6 * j) % 9 == 0) - { - flag = 1; - break; - } - } - } - if (flag) - { - cout << ""YES\n""; - } - else - { - cout << ""NO\n""; - } - } - return 0; -}","#include -using namespace std; -#define int long long - -int32_t main(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - int sum = 0; - string s = to_string(n); - for (char c : s) - { - sum += c - '0'; - } - if (sum % 9 == 0) - { - cout << ""YES\n""; - continue; - } - int twos = 0; - int threes = 0; - for (char c : s) - { - if (c == '2') - { - twos++; - } - else if (c == '3') - { - threes++; - } - } - int flag = 0; - for (int i = 0; i <= twos; i++) - { - for (int j = 0; j <= threes; j++) - { - if ((sum + 2 * i + 6 * j) % 9 == 0) - { - flag = 1; - break; - } - } - } - if (flag) - { - cout << ""YES\n""; - } - else - { - cout << ""NO\n""; - } - } - return 0; -}",1 -elizar_khloptcev,2050C - Uninteresting Number,c++23 ,308395700,308398318,"#include - - - -#define int long long - - - -using namespace std; - - - -void solve(){ - - string s; - - cin >> s; - - int cnt = 0, cnt2 = 0, sum = 0; - - for (int i = 0; i < s.size(); i++){ - - int c = s[i] - '0'; - - if (c == 2){ - - cnt++; - - } - - else if (c == 3){ - - cnt2++; - - } - - sum += c; - - } - - - - int x = sum % 9; - - if (x == 0){ - - cout << ""YES\n""; - - return; - - } - - while (cnt > 0){ - - x += 2; - - if (x % 9 == 0){ - - cout << ""YES\n""; - - return; - - } - - cnt--; - - } - - int x = sum % 9; - - if (x == 0){ - - cout << ""YES\n""; - - return; - - } - - while (cnt2 > 0){ - - x += 6; - - if (x % 9 == 0){ - - cout << ""YES\n""; - - return; - - } - - cnt2--; - - } - - int x = sum % 9; - - if (x == 0){ - - cout << ""YES\n""; - - return; - - } - - - - cout << ""NO\n""; - -} - - - -int32_t main(){ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin >> t; - - while (t--){ - - solve(); - - } - - return 0; - -}","#include - - - -#define int long long - - - -using namespace std; - - - -void solve(){ - - string s; - - cin >> s; - - int cnt = 0, cnt2 = 0, sum = 0; - - for (int i = 0; i < s.size(); i++){ - - int c = s[i] - '0'; - - if (c == 2){ - - cnt++; - - } - - else if (c == 3){ - - cnt2++; - - } - - sum += c; - - } - - - - int x = sum % 9; - - - - for (int i = 0; i <= min(8ll, cnt); i++){ - - for (int j = 0; j <= min(8ll, cnt2); j++){ - - if ((2 * i + 6 * j + x) % 9 == 0){ - - cout << ""YES\n""; - - return; - - } - - } - - } - - cout << ""NO\n""; - -} - - - -int32_t main(){ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin >> t; - - while (t--){ - - solve(); - - } - - return 0; - -}",2 -the_atg,2050D - Digital string maximization,c++17 ,296995341,296957697," - - #include // include all standard headers - using namespace std; - - #define ll long long - #define ld long double - #define pii pair - #define mp make_pair - #define pb push_back - #define eb emplace_back - #define fi first - #define se second - - const int INF = 1e9; - const ll INFLL = 1e18; - const int MOD = 1e9 + 7; - - char rect(vector &s){ - int n=s.size(); - - - char max=s[0]; - int ind=0; - for(int i=1; imax){ - max=s[i]-i; - ind=i; - }} - s.erase(s.begin()+ind); - return max; - - } - int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - // Declare any additional variables here - - int t; // number of test cases - cin >> t; - - while (t--) { - string s; - cin >> s; - ll n; - n=s.size(); - vector v; - if(n>9){ - for(int i=0; i<10;i++) - v.pb(s[i]); - cout< // include all standard headers -using namespace std; - -#define ll long long -#define ld long double -#define pii pair -#define mp make_pair -#define pb push_back -#define eb emplace_back -#define fi first -#define se second - -const int INF = 1e9; -const ll INFLL = 1e18; -const int MOD = 1e9 + 7; - bool customSort(const pair& a, const pair& b) { - if (a.first == b.first) { - return a.second > b.second; - } - return a.first < b.first; } -char rect(vector &s){ - int n=s.size(); - vector> v(n); - vector vis; - - for(int i=0; i> t; - - while (t--) { - string s; - cin >> s; - ll n; - n=s.size(); - vector v; - for(int i=0;i -#include -using namespace std; - -void solve(string s) { - long long n = s.size(); - bool updated = true; - - while (updated) { - updated = false; - for (long long i = n - 1; i > 0; --i) { - if (s[i] > s[i - 1] + 1) { - s[i]--; - swap(s[i], s[i - 1]); - updated = true; // Mark as updated to repeat the process - } - } - } - - cout << s; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t--) { - string s; - cin >> s; - solve(s); - cout << endl; - } - return 0; -}","#include -#include -using namespace std; - -int main(){ -int t; -cin>>t; -while(t--){ - string n; - cin>>n; - int change(1); - while(change!=0){ - change=0; - for(int i=1;i -#include -#include - -using namespace std; - -void solve() { - int t; - cin >> t; - - while (t--) { - string s; - cin >> s; - int n = s.size(); - - for(int i=0;is[j-1] && s[j]!='0' && s[j]!=s[j-1]+1){ - s[j]-=1; - swap(s[j],s[j-1]); - } - } - - } - cout< -#include -#include - -using namespace std; - -void solve() { - int t; - cin >> t; - - while (t--) { - string s; - cin >> s; - int n = s.size(); - - bool changed; - do { - changed = false; - for (int i = 1; i < n; i++) { - if (s[i] > s[i-1] && s[i] != '0' && s[i] != s[i-1] + 1) { - s[i] -= 1; - swap(s[i], s[i-1]); - changed = true; - } - } - } while (changed); - - cout< - -#define vii vector> - -#define vvi vector> - -#define vch vector - -#define vb vector - -#define vst vector - -#define pi pair - -#define eb emplace_back - -#define pb push_back - -#define all(x) (x).begin(),(x).end() - -#define allr(x) (x).rbegin(),(x).rend() - -#define input(v,n) for(int i=0;i>v[i]; - -#define print(v) for(auto &x:v) cout<=0;--i) - -#define fo1(i,a,b) for(decltype(b) i=a;i=b;--i) - -#define w(t) int t; cin>>t; while(t--) - -#define debug(x) cerr << #x << "" = "" << x << endl - -#define debugv(x) for(auto &i:x) cerr << i << "" ""; cerr << endl - -#define mini(v) *min_element(all(v)) - -#define maxi(v) *max_element(all(v)) - -#define popcount(x) __builtin_popcountll(x) - -#define bit(x) (1LL << (x)) - -#define lowbit(x) (x & -x) - -#define checkbit(x, i) ((x >> i) & 1) - -#define yesno(x) if(x) cout<<""YES""<> s ; - -int n = s.size() ; - -fo(i,n){ - -int minn = min(i+10,n); - -int curr = s[i] - '0' , ind = i; - -fo1(j,i+1,minn){ - -if(s[j] - '0' - (j-i) > curr){ - -curr = s[j] - '0'- (j-i); - -ind = j; - -} - -} - -while(ind > i){ - -swap(s[ind],s[ind-1]); - -ind--; - -} - -s[i] = curr + '0'; - -} - -cout << s << endl; - -} - -int32_t main() { - -fastio(); - -w(t) solve(); - -return 0; - -}","#include ""bits/stdc++.h"" - -#define int long long - -#define fi first - -#define se second - -#define vi vector - -#define vii vector> - -#define vvi vector> - -#define vch vector - -#define vb vector - -#define vst vector - -#define pi pair - -#define eb emplace_back - -#define pb push_back - -#define all(x) (x).begin(),(x).end() - -#define allr(x) (x).rbegin(),(x).rend() - -#define input(v,n) for(int i=0;i>v[i]; - -#define print(v) for(auto &x:v) cout<=0;--i) - -#define fo1(i,a,b) for(decltype(b) i=a;i=b;--i) - -#define w(t) int t; cin>>t; while(t--) - -#define debug(x) cerr << #x << "" = "" << x << endl - -#define debugv(x) for(auto &i:x) cerr << i << "" ""; cerr << endl - -#define mini(v) *min_element(all(v)) - -#define maxi(v) *max_element(all(v)) - -#define popcount(x) __builtin_popcountll(x) - -#define bit(x) (1LL << (x)) - -#define lowbit(x) (x & -x) - -#define checkbit(x, i) ((x >> i) & 1) - -#define yesno(x) if(x) cout<<""YES""<> s ; - -int n = s.size() ; - -fo(i,n){ - -int minn = min(i+10,n); - -int curr = s[i] - '0' , ind = i; - -fo1(j,i+1,minn){ - -if(s[j] - '0' - (j-i) > curr){ - -curr = s[j] - '0'- (j-i); - -ind = j; - -} - -} - -while(ind > i){ - -swap(s[ind],s[ind-1]); - -ind--; - -} - -} - -cout << s << endl; - -} - -int32_t main() { - -fastio(); - -w(t) solve(); - -return 0; - -}",1 -doni69#,2050D - Digital string maximization,python,295164665,295163818,"for _ in range(int(input())): - s=list(map(int,input()[::-1])) - a=[] - while s: - m=s[-1] - x=-1 - for i in range(-1,max(-11,-len(s)-1),-1): - if x-m==9: - break - if s[i]+i+1>m: - m=s[i]+i+1 - x=i - a.append(m) - del s[x] - print("""".join(map(str,a)))","for _ in range(int(input())): - s=list(map(int,input())) - a=[] - while s: - m=s[0] - x=0 - for i in range(1,min(10,len(s))): - if x+m==9: - break - if s[i]-i>m: - m=s[i]-i - x=i - a.append(m) - del s[x] - print("""".join(map(str,a))) - ",1 -llllllgllllll,2050D - Digital string maximization,python,313307352,313307569,"t = int(input()) - -def solve(): - -s = [int(i) for i in list(input())] - -n = len(s) - -for i in range(1,n,1): - -for j in range(max(i-10, 0), i): - -if s[i] - (i-j) > s[j]: - -s.insert(j, s[i] - (i-j)) - -s.pop(i+1) - -break - -print("""".join([str(i) for i in s])) - -return - -for i in range(t): - -solve()","t = int(input()) - -def solve(): - -s = [int(i) for i in list(input())] - -n = len(s) - -for i in range(1,n,1): - -for j in range(max(i-10, 0), i): - -if s[i] - (i-j) > s[j]: - -tmp = s[j:i] - -s[j] = s[i] - (i-j) - -s[j+1:i+1] = tmp - -break - -print("""".join([str(i) for i in s])) - -return - -for i in range(t): - -solve()",2 -tmunavver,2050D - Digital string maximization,c++17 ,297786552,297789455,"#include -#include -using namespace std; - -// typedef vector vi; -// typedef vector> vvi; -// typedef vector vl; -// typedef vector> vvl; -// typedef vector vb; -// typedef vector> vvb; -// typedef map mii; -// typedef map mll; -// typedef pair pii; -// typedef pair pll; -// typedef unsigned long long ull; -// typedef long double ld; -// typedef long long ll; -typedef long long ll; -#define f(i,a,b) for(int i = a; i < b ; i++) -#define geti(n) int n; cin >> n; -#define getll(n) long long int n; cin >> n; -#define gets(s) string s; cin >>s; -#define getv(v,n) vector v(n) ; f(i, 0 ,n) cin >> v[i]; -#define srt(v) sort(v.begin(), v.end()); -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); -void Solve() -{ - string s; - cin>>s; - vector v(s.size()); - long long n = s.size(); - for(long long i = 0; i max){ - max = mx; - ind = j; - } - } - for(long long k = ind; k>i; k--){ - v[k] = v[k-1]; - } - v[i] = max; - cout<> t; - for(int i = 0; i < t; i++) - { - Solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured:"" << elapsed.count() * 1e-9 << "",seconds.""; - return 0; -}","#include - -using namespace std; - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s; -} - -int main() { - int TESTS = 1; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}",2 -KartikeyThawait19,2050D - Digital string maximization,c++17 ,299272447,299271479,"#include -using namespace std; -void solve(); - -int main() -{ - int t = 1; - cin >> t; - while (t--) - { - solve(); - cout << ""\n""; - } -} - -bool swapOrNot(int a, int b) -{ - int num1 = (b - 1) * 10 + a; - int num2 = (a * 10) + b; - return num1 > num2; -} - -void solve() -{ - string num; - cin >> num; - - int n = num.length(); - - if (n == 1) - { - cout << num; - return; - } - - string ans = """"; - ans += num[n - 1]; - - for (int i = n - 2; i >= 0; i--) - { - ans = num[i] + ans; - if (ans[0] < ans[1]) - { - for (int j = 0; j < ans.length() - 1; j++) - { - if (ans[j] < ans[j + 1]) - { - if (swapOrNot(ans[j] - '0', ans[j + 1] - '0')) - { - char modifiedChar = ans[j + 1] - 1; - swap(ans[j], modifiedChar); - ans[j + 1] = modifiedChar; - } - } - else - { - break; - } - } - } - } - - cout << ans; -}","#include -using namespace std; -void solve(); - -int main() -{ - int t=1; - cin>>t; - while(t--) - { - solve(); - cout<<""\n""; - } -} - -bool swapOrNot(int a, int b) -{ - int num1 = (b-1)*10+a; - int num2 = (a*10)+b; - return num1>num2; -} - -void solve() -{ - string num; - cin>>num; - - int n=num.length(); - - if(n==1) - { - cout<=0;i--) - { - ans=num[i]+ans; - for(int j=0;j -#include -#include -#include -using namespace std; - -using ll = long long; -void setIO() { - ios::sync_with_stdio(false); - cin.tie(nullptr); -} - - - - -void solve() { - string s; cin >> s; - string ans = """"; - int n = s.length(); - vector arr; - vector diffs(n, 0); - for(int i = 0; i < n; i++) { - arr.push_back(s[i] - '0'); - } - - int amtskipped = 0; - for(int i = 0; i < n; i++) { - int bestIndex = 0; - int bestAmt = 0; - for(int j = 0; j < min((int) arr.size(), 9); j++) { - if(arr[j] - j > bestAmt) { - bestIndex = j; - bestAmt = arr[j] - j; - } - } - - arr.erase(arr.begin() + bestIndex); - ans += to_string(bestAmt); - } - - cout << ans << ""\n""; -} - - - - - -int main() { - setIO(); - int t; cin >> t; - while(t--) { - solve(); - } -} - -","#include -#include -#include -#include -using namespace std; - -using ll = long long; -void setIO() { - ios::sync_with_stdio(false); - cin.tie(nullptr); -} - - - - -void solve() { - string s; cin >> s; - string ans = """"; - int n = s.length(); - - - set getRid; - for(int i = 0; i < n; i++) { - int bestIndex = i; - int bestAmt = 0; - for(int j = i; j < min((int) s.size(), i+10); j++) { - if(s[j] - '0' - (j-i) > bestAmt) { - bestIndex = j; - bestAmt = s[j] - '0' - (j-i); - } - } - - while (bestIndex > i) { - swap(s[bestIndex], s[bestIndex- 1]); - bestIndex--; - } - - s[i] = char(bestAmt + '0'); - - } - - cout << s << ""\n""; -} - - - - - -int main() { - setIO(); - int t; cin >> t; - while(t--) { - solve(); - } -} - -",2 -anurag_sri,2050D - Digital string maximization,c++20 ,298147481,298147589,"#include -using namespace std; -#define ll long long -#define all(m) m.begin(),m.end() -#define f(i,a,b) for(ll i=a;i<=b;i++) -#define fr(i,a,b) for(ll i=a;i>=b;i--) -#define vi vector -#define vl vector -#define vvl vector> -bool is_prime(int n) { - if (n <= 1) return false; - for (int i = 2; i * i <= n; i++) { - if (n % i == 0) return false; - } - return true; -} -void solve(){ - string s; - cin >> s; - ll n = s.size(); - f(i,0,n-1){ - ll maxi_ind = i; - ll maxi_val = s[i]-'0'; - f(j,i,min(10LL,n-1)){ - if(s[j]-'0'+i-j>maxi_val){ - maxi_val = s[j]-'0'+i-j; - maxi_ind = j; - } - } - while(maxi_ind > i){ - swap(s[maxi_ind],s[maxi_ind-1]); - maxi_ind--; - } - s[i] = '0'+maxi_val; - } - cout << s << endl; -} -int main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } -}","#include -using namespace std; -#define ll long long -#define all(m) m.begin(),m.end() -#define f(i,a,b) for(ll i=a;i<=b;i++) -#define fr(i,a,b) for(ll i=a;i>=b;i--) -#define vi vector -#define vl vector -#define vvl vector> -bool is_prime(int n) { - if (n <= 1) return false; - for (int i = 2; i * i <= n; i++) { - if (n % i == 0) return false; - } - return true; -} -void solve(){ - string s; - cin >> s; - ll n = s.size(); - f(i,0,n-1){ - ll maxi_ind = i; - ll maxi_val = s[i]-'0'; - f(j,i,min(i+10LL,n-1)){ - if(s[j]-'0'+i-j>maxi_val){ - maxi_val = s[j]-'0'+i-j; - maxi_ind = j; - } - } - while(maxi_ind > i){ - swap(s[maxi_ind],s[maxi_ind-1]); - maxi_ind--; - } - s[i] = '0'+maxi_val; - } - cout << s << endl; -} -int main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } -}",2 -PixelMaster,2050D - Digital string maximization,c++17 ,296169725,296169592,"#include - -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define ll long long -#define pb push_back -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -#define f first -#define s second - -using namespace std; - -void solve() -{ - string s; - - cin >> s; - - for (int i = 0; i < s.size(); i++) - { - int q = 0; - int mx = s[i] - 48; - for (int j = 1; i + j < s.size() && j < 10; j++) - { - int x = s[i + j] - 48; - x -= j; - if (x > mx) - { - q = j; - mx = x; - } - } - - for (int j = i + q; j > i; j--) - swap(s[j], s[j - 1]); - - s[i] -= q; - } - - cout << s << ""\n""; -} - -int main() -{ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) - solve(); - - return 0; -} -","#include - -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define ll long long -#define pb push_back -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -#define f first -#define s second - -using namespace std; - -void solve() -{ - string s; - - cin >> s; - - for (int i = 0; i < s.size(); i++) - { - int q = 0; - int mx = s[i] - 48; - for (int j = 1; i + j < s.size() && j < i + 10; j++) - { - int x = s[i + j] - 48; - x -= j; - if (x > mx) - { - q = j; - mx = x; - } - } - - for (int j = i + q; j > i; j--) - swap(s[j], s[j - 1]); - - s[i] -= q; - } - - cout << s << ""\n""; -} - -int main() -{ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) - solve(); - - return 0; -} -",1 -Gamer0n,2050D - Digital string maximization,python,296117804,296119956,"def highest_var(x): - com = 'play' - while com == 'play': - max_n = max(x) - check = [] - while max_n > 2: - pos = [[idx, i] for idx, i in enumerate(x) if i == max_n and idx != 0] - - check_q = 0 - for jup in pos: - if x[jup[0]-1] < max_n - 1: - x[jup[0]-1], x[jup[0]] = x[jup[0]]-1, x[jup[0]-1] - check_q = 1 - - max_n -= 1 - if check_q == 1: - check.append(1) - if not check: - com = 'stop' - return x - - -t = int(input()) -ab_res = [] -for _ in range(t): - s = input() - x = [] - res = '' - for letter in s: - x.append(int(letter)) - - x = highest_var(x) - for i in x: - res+=str(i) - ab_res.append(res) - -for i in ab_res: - print(i)","def highest_var(x): - while True: - max_n = max(x) - check = False - while max_n > 1: - for i in range(1, len(x)): - if x[i] == max_n and x[i - 1] < max_n - 1: - x[i - 1], x[i] = x[i] - 1, x[i - 1] - check = True - max_n -= 1 - if not check: - break - return x - - -t = int(input()) -ab_res = [] -for _ in range(t): - s = input().strip() - x = list(map(int, s)) - x = highest_var(x) - ab_res.append(''.join(map(str, x))) - -print('\n'.join(ab_res))",2 -dumEinstein,2050D - Digital string maximization,python,298980164,298987502,"from sys import stdin -from typing import Any -import math -input = stdin.readline -def ri(): return int(input()) -def rl(v_type=int,output=list): return output(map(v_type, input().split())) -def rs(): return input().rstrip() -def out(x, sep='\n'): print(sep.join(x)) - - -def solve(): - s = rs() - n = len(s) - a = list(map(int,s)) - for i in range(n-2,-1,-1): - for j in range(i+1, min(i + 10,n)): - if a[j-1] + (1) < a[j]: - a[j-1],a[j] = a[j] - (1),a[j-1] - else: - break - - return """".join(map(str,a)) - - -output = [] -for _ in range(ri()): - output.append(str(solve())) -out(output)","from sys import stdin -from typing import Any -import math -input = stdin.readline -def ri(): return int(input()) -def rl(v_type=int,output=list): return output(map(v_type, input().split())) -def rs(): return input().rstrip() -def out(x, sep='\n'): print(sep.join(x)) - - -def solve(): - s = rs() - n = len(s) - a = list(map(int,s)) - for i in range(1,n): - for j in range(i -1,max(-1,i - 11),-1): - if a[j] + 1 < a[j + 1]: - a[j],a[j+1] = a[j+1] - 1, a[j] - else: - break - - - return """".join(map(str,a)) - - - -output = [] -for _ in range(ri()): - output.append(str(solve())) -out(output)",2 -lkylalala,2050D - Digital string maximization,c++20 ,298378953,298378678,"#include -#include -#include -#include -using namespace std; - -const int INF = 2e9; -void solve() { - string s; - cin >> s; - vector a; - for(auto c : s) { - a.push_back(c - '0'); - } - - vector b; - for(int i = 0;i < a.size(); ++i) { - int index = -1,maxx = -INF; - for(int j = i;j < min(i + 10, (int)a.size());++j) { - int tmp = a[j] - (j - i); - if(tmp > maxx) { - maxx = tmp; - index = j; - } - } - b.push_back(maxx); - - while(index > i) { - swap(a[index], a[index - 1]); - index --; - } - } - for(auto x : b) cout << x; - cout << endl; -} - -int main() { - int T; - cin >> T; - while(T--) { - solve(); - } - return 0; -} - -","#include -#include -#include -#include -using namespace std; - -const int INF = 2e9; -void solve() { - string s; - cin >> s; - vector a; - for(auto c : s) { - a.push_back(c - '0'); - } - - vector b; - for(int i = 0;i < a.size(); ++i) { - int index = -1,maxx = -INF; - for(int j = i;j < a.size();++j) { - int tmp = a[j] - (j - i); - if(tmp > maxx) { - maxx = tmp; - index = j; - } - } - b.push_back(maxx); - - while(index > i) { - swap(a[index], a[index - 1]); - index --; - } - } - for(auto x : b) cout << x; - cout << endl; -} - -int main() { - int T; - cin >> T; - while(T--) { - solve(); - } - return 0; -} - -",1 -LuzZ_ShayanZ,2050D - Digital string maximization,c++17 ,298368970,298373438,"#include -#include -#include -using namespace std; - -#define int long long -#define nl cout< -#define vecs vector -#define ddv vector -#define ub upper_bound -#define lb lower_bound -#define prnt(v) for(auto i:v) cout<>i; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define yes cout<<""YES""<>= 1; - } - return ans; -} - -int inv(int n){ //O(logM) - return binExp(n,M-2); -} - -void FACT(){ //O(N) - factorials[0] = 1; - for (int i = 1; i <= N; i++) { - factorials[i] = factorials[i - 1] * 1LL * i % M; - } -} - -void FACTINV(){ //O(N) - for (int i = 0; i <= N; i++) { - factInv[i] = inv(factorials[i]); - } -} - -void SIEVE(){ //O(NloglogN) - - //Pre-compute - - fill(isPrime, isPrime+N, true); - isPrime[0]=isPrime[1]=false; - - for(int i = 2; i <= N; ++i){ - if(isPrime[i]){ - for(int j=2*i ; j<=N ; j+=i) - isPrime[j]=false; - } - } -} - -long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N). - - // Pre-Compute before using this func. - // FACT(); - // FACTINV(); - - if (r > n) return 0; - return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M; -} - -void solve(){ - string s,ans=""""; - cin>>s; - int n = s.length(); - - vector used(n,false); - - for(int i=0 ; i num){ - used[numi] = false; - numi = j; - num = trnum; - ans.ppb(); - ans.pb(s[j]-(j-i)+bunk); - used[numi] = true; - } - } - - // - // cout<>t; - - while(t--){ - solve(); - } - - return 0; -} -","#include -#include -#include -using namespace std; - -#define int long long -#define nl cout< -#define vecs vector -#define ddv vector -#define ub upper_bound -#define lb lower_bound -#define prnt(v) for(auto i:v) cout<>i; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define yes cout<<""YES""<>= 1; - } - return ans; -} - -int inv(int n){ //O(logM) - return binExp(n,M-2); -} - -void FACT(){ //O(N) - factorials[0] = 1; - for (int i = 1; i <= N; i++) { - factorials[i] = factorials[i - 1] * 1LL * i % M; - } -} - -void FACTINV(){ //O(N) - for (int i = 0; i <= N; i++) { - factInv[i] = inv(factorials[i]); - } -} - -void SIEVE(){ //O(NloglogN) - - //Pre-compute - - fill(isPrime, isPrime+N, true); - isPrime[0]=isPrime[1]=false; - - for(int i = 2; i <= N; ++i){ - if(isPrime[i]){ - for(int j=2*i ; j<=N ; j+=i) - isPrime[j]=false; - } - } -} - -long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N). - - // Pre-Compute before using this func. - // FACT(); - // FACTINV(); - - if (r > n) return 0; - return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M; -} - -void solve(){ - string s; - cin>>s; - int n = s.length(); - - for(int i=0;i s[r]-(r-i)){ - r=j; - } - } - - for(int j=r ; j>i ; --j){ - --s[j]; - swap(s[j],s[j-1]); - } - - // cout<>t; - - while(t--){ - solve(); - } - - return 0; -} -",2 -Qian_Feng,2050D - Digital string maximization,c++20 ,296370948,296370726,"#include -using namespace std; -#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) -#define debug(x) cerr << #x << "" = "" << (x) << endl -using ll = long long; -using ull = unsigned long long; -using i128 = __int128_t; -//最大公约数 -ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;} -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); -template -using max_heap = priority_queue; -template -using min_heap = priority_queue , greater<>>; - -constexpr int mod = 998244353; -//快速幂 -ll power(ll a, ll b) { - a %= mod; - ll res = 1; - while (b > 0) { - if (b & 1) res = res * a % mod; - a = a * a % mod; - b >>= 1; - } - return res; -} - - - - -void solve(){ - string s; - cin>>s; - int n = s.size(); - vector st; - vector cur; - for (int i=0;ist.back()+1){ - num--; - cur.push_back(st.back()); - st.pop_back(); - } - st.push_back(num); - while (!cur.empty()){ - st.push_back(cur.back()); - cur.pop_back(); - } - } - for (auto v:st) cout<>T; - - while (T--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define fastio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) -#define debug(x) cerr << #x << "" = "" << (x) << endl -using ll = long long; -using ull = unsigned long long; -using i128 = __int128_t; -//最大公约数 -ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;} -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); -template -using max_heap = priority_queue; -template -using min_heap = priority_queue , greater<>>; - -constexpr int mod = 998244353; -//快速幂 -ll power(ll a, ll b) { - a %= mod; - ll res = 1; - while (b > 0) { - if (b & 1) res = res * a % mod; - a = a * a % mod; - b >>= 1; - } - return res; -} - - - - -void solve(){ - string s; - cin>>s; - int n = s.size(); - vector> st; - vector> cur; - for (int i=0;ist.back()[0]+st.back()[1]){ - cur.push_back(st.back()); - num -= st.back()[1]; - st.pop_back(); - } - if (!st.empty() && st.back()[0]==num){ - st[st.size()-1][1]++; - } - else{ - st.push_back({num,1}); - } - while (!cur.empty()){ - auto v = cur.back(); - cur.pop_back(); - st.push_back(v); - } - } - for (auto v:st){ - for (int i=0;i>T; - - while (T--){ - solve(); - } - return 0; -}",1 -ashutoshbaheti250,2050D - Digital string maximization,c++17 ,307116713,307117657,"#include - -using namespace std; - - - -string canMakeDivisibleBy9(string s) { - - int n=s.length(); - - for(int i=0;i0;j--){ - - if(s[j]-s[j-1]>1){ - - swap(s[j-1],--s[j]); - - } - - } - - - - } - - return s; - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - string s; - - cin >> s; - - cout << (canMakeDivisibleBy9(s)) << endl; - - } - - return 0; - -} - -","#include - -using namespace std; - - - -string canMakeDivisibleBy9(string s) { - - int n=s.length(); - - for(int i=0;i0 && s[j]-s[j-1]>1;j--){ - - swap(s[j-1],--s[j]); - - } - - - - } - - return s; - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - string s; - - cin >> s; - - cout << (canMakeDivisibleBy9(s)) << endl; - - } - - return 0; - -} - -",2 -rohan_codegiant,2050D - Digital string maximization,c++17 ,298797092,298797945,"#include -using namespace std; - -int main() -{ - int t; - cin>>t; - for(int m=0;m>s; - for(int i=0;id) - { - max_index=j; - d=x; - } - } - if(max_index!=i) - { string p=s; - - for(int j=i+1;j<=max_index;j++) - { - p[j]=s[j-1]; - } - p[i]=d+'0'; - s=p; - - } - - - - } - - cout< -using namespace std; - -int main() -{ - int t; - cin>>t; - for(int m=0;m>s; - for(int i=0;id) - { - max_index=j; - d=x; - } - } - - while(max_index>i) - { - swap(s[max_index],s[max_index-1]); - max_index--; - } - s[i]=d+'0'; - - - - } - - cout< -using namespace std; -#define ll long long -int main() -{ - ll t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int n = s.size(); - string res = s; - - // cout << n << endl; - for (int i = 0; i < n; i++) - { - int k = -1; - // cout << res[i] << endl; - for (int j = i + 1; j < min(i + 10, n); j++) - { - // cout << ""ta "" << res[i] << "" "" << res[j] << endl; - if (res[j] + i - j > res[i] and res[j] - j + i >= '0' and res[j] - j + i <= '9') - { - if (k == -1) - { - k = j; - // cout << ""Here "" << res[k] << endl; - } - else if (k != -1 and res[j] - j > res[k] - k) - { - k = j; - // cout << ""There "" << res[k] << endl; - } - } - } - // cout << i << "" "" << k << "" ""; - if (k != -1) - { - res[k] = res[k] - k + i; - while (k > i) - { - swap(res[k], res[k - 1]); - k--; - } - } - // cout << res << endl; - } - cout << res << endl; - } - return 0; -}","#include -using namespace std; -#define ll long long -int main() -{ - ll t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int n = s.size(); - string res = s; - - // cout << n << endl; - for (int i = 0; i < n; i++) - { - int k = -1; - // cout << res[i] << endl; - for (int j = i + 1; j < n; j++) - { - // cout << ""ta "" << res[i] << "" "" << res[j] << endl; - if (res[j] + i - j > res[i] and res[j] - j + i >= '0' and res[j] - j + i <= '9') - { - if (k == -1) - { - k = j; - // cout << ""Here "" << res[k] << endl; - } - else if (k != -1 and res[j] - j > res[k] - k) - { - k = j; - // cout << ""There "" << res[k] << endl; - } - } - } - // cout << i << "" "" << k << "" ""; - if (k != -1) - { - res[k] = res[k] - k + i; - while (k > i) - { - swap(res[k], res[k - 1]); - k--; - } - } - // cout << res << endl; - } - cout << res << endl; - } - return 0; -}",1 -huanghuangaaa,2050D - Digital string maximization,c++20 ,298966209,298965414,"#include -using namespace std; - -void sol() -{ - string s; - cin>>s; - for(int i=0,len=s.size();ibest) - { - pos=j; - best=s[j]-'0'-(j-i); - } - while(pos>i) - { - swap(s[pos],s[pos-1]); - pos--; - } - s[i]=best+'0'; - } - } - cout<>t; - while(t--) - { - sol(); - } - return 0; -}","#include -using namespace std; -char judge(string& s,int x) -{ - int ans=0,y; - if(s.size()-x>10) - { - for(int i=x;ians) - { - ans=a; - y=i; - } - } - } - else - { - for(int i=x,len=s.size();ians) - { - ans=a; - y=i; - } - } - } - if(y==x) return ans+'0'; - else - { - for(int i=y;i>=x;i--) - { - char c=s[i]; - s[i]=s[i-1]; - s[i-1]=(s[i]-'0'-1)+'0'; - } - return ans+'0'; - } -} -void sol() -{ - string s; - string b; - cin>>s; - for(int i=0,len=s.size();i>t; - while(t--) - { - sol(); - } - return 0; -}",1 -garbage222,2050D - Digital string maximization,c++23 ,312810544,312803478,"#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - string a; - - cin>>a; - - for(int i=1;ia[j-1]&&j>0){ - - swap(a[j-1],a[j]); - - a[j-1]--; - - j--; - - } - - } - - for(int i=0;i - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - char a[200005]; - - cin>>a; - - for(int i=1;ia[j-1]&&j>0){ - - swap(a[j-1],a[j]); - - a[j-1]--; - - j--; - - } - - } - - for(int i=0;i -#include -using namespace std; -int main(){ - - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - int n=s.length(); - set>st; - for(int i=0;ioriginal){ - st.erase({s[index+1],index+1}); - swap(s[index],s[index+1]); - s[i]=((s[i]-'0')-1)+'0'; - st.insert({s[i],n-i}); - st.insert({s[i+1],n-(i+1)}); - } - } - cout< -#include -using namespace std; -int main(){ - - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - int n=s.length(); - set>st; - for(int i=0;ioriginal){ - st.erase({s[index+1],index+1}); - swap(s[index],s[index+1]); - s[i]=((s[i]-'0')-1)+'0'; - st.insert({s[i],n-i}); - st.insert({s[i+1],n-(i+1)}); - } - // cout<original){ - st.erase({s[index+1],index+1}); - swap(s[index],s[index+1]); - s[i]=((s[i]-'0')-1)+'0'; - st.insert({s[i],n-i}); - st.insert({s[i+1],n-(i+1)}); - } - // cout< - -using namespace std; - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s; -} - -int main() { - int TESTS = 1; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}","#include -#include -using namespace std; - -// typedef vector vi; -// typedef vector> vvi; -// typedef vector vl; -// typedef vector> vvl; -// typedef vector vb; -// typedef vector> vvb; -// typedef map mii; -// typedef map mll; -// typedef pair pii; -// typedef pair pll; -// typedef unsigned long long ull; -// typedef long double ld; -// typedef long long ll; -typedef long long ll; -#define f(i,a,b) for(int i = a; i < b ; i++) -#define geti(n) int n; cin >> n; -#define getll(n) long long int n; cin >> n; -#define gets(s) string s; cin >>s; -#define getv(v,n) vector v(n) ; f(i, 0 ,n) cin >> v[i]; -#define srt(v) sort(v.begin(), v.end()); -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); -void Solve() -{ - string s; - cin>>s; - vector v(s.size()); - long long n = s.size(); - // for(long long i = 0; i max){ - max = mx; - ind = j; - } - } - for(long long k = ind; k>i; k--){ - s[k] = s[k-1]; - } - s[i] = max + '0'; - } - cout<> t; - for(int i = 0; i < t; i++) - { - Solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured:"" << elapsed.count() * 1e-9 << "",seconds.""; - return 0; -}",1 -Kunal_Raut_9925,2050D - Digital string maximization,c++23 ,305956367,305949112,"#include - -using namespace std; - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s; -} - -int main() { - int TESTS = 1; cin >> TESTS; - while (TESTS --> 0) { - solve(); - cout << '\n'; - } - return 0; -}","#include -using namespace std; -#define int long long int - -void solve(){ - string s; - cin>>s; - vectordigits(s.length()); - //convert string to integer array - for(int i=0;i=0 && digits[copy_i]>0 && (digits[copy_i]>digits[copy_i-1])){ - int temp=digits[copy_i]; - digits[copy_i]=digits[copy_i-1]; - digits[copy_i-1]=temp-1;//***why we use this temp-1 while swqpping instead of using temp */ - if(copy_i>1){ - copy_i--; - }else{ - break; - } - } - } - for(int d:digits){ - cout<>t; - while(t--){ - solve(); - } - return 0; -}",1 -FP7317,2050D - Digital string maximization,c++20 ,297726545,297726654,"#include -using namespace std; - -#ifdef LOCAL -#include ""/Library/debug/debug.h"" -#define debug(x...) cerr << ""["" << #x << ""] = [""; _print(x) -#else -#define debug(x...) -#endif - -#define MAX 2e9 -#define MIN -2e9 -#define PI acos(-1.0) -#define mid(s, e) ((s) + ((e) - (s)) / 2) -#define clz(n) __builtin_clzll(n) -#define nbOfBits(n) __builtin_popcountll(n) -#define all(x) (x).begin(), (x).end() -#define endl '\n' -#define pb push_back -#define sz(a) static_cast((a).size()) -#define int long long -#define double long double -#define fi first -#define fill(n,arr) for(int i=1;i<=n;i++){ll x;cin>>x;arr.pb(x);} -#define se second -#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} -#define getorder(v) sort(all(v)) -#define getlower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) -#define getupper(s) transform(s.begin(), s.end(), s.begin(), ::toupper) -#define reverse(s) reverse(s.begin(), s.end()) -#define getmax(ans) *max_element(all(ans)); -#define getmin(ans) *min_element(all(ans)); - -using ll = long long; -using vi = vector; -using vc = vector; -using vvc = vector; -using vvi = vector; -using vb = vector; -using vvb = vector; -using vd = vector; -using vvd = vector; -using vs = vector; -using pii = pair; -using pdd = pair; -using vpii = vector; -using vpdd = vector; -using si = set; -using ssi = set; -using sb = set; -using ssb = set; -using sd = set; -using ssd = set; -using ss = set; -using sc = set; - -// BEFORE coding are you sure you understood the statement correctly? -// PLEASE do not forget to read the sample explanation carefully. -// WATCH out for overflows & RTs in general. -// TEST your idea or code on the corner cases. -// ANALYZE each idea you have thoroughly. - -const int dx[8]={0, 0, 1, -1, 1, -1, -1, 1}; -const int dy[8]={1, -1, 0, 0, 1, -1, 1, -1}; - -void solve(){ - string s;cin>>s; - for(int i=0;i>t;while(t--) - solve(); -}","#include -using namespace std; - -#ifdef LOCAL -#include ""/Library/debug/debug.h"" -#define debug(x...) cerr << ""["" << #x << ""] = [""; _print(x) -#else -#define debug(x...) -#endif - -#define MAX 2e9 -#define MIN -2e9 -#define PI acos(-1.0) -#define mid(s, e) ((s) + ((e) - (s)) / 2) -#define clz(n) __builtin_clzll(n) -#define nbOfBits(n) __builtin_popcountll(n) -#define all(x) (x).begin(), (x).end() -#define endl '\n' -#define pb push_back -#define sz(a) static_cast((a).size()) -#define int long long -#define double long double -#define fi first -#define fill(n,arr) for(int i=1;i<=n;i++){ll x;cin>>x;arr.pb(x);} -#define se second -#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} -#define getorder(v) sort(all(v)) -#define getlower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) -#define getupper(s) transform(s.begin(), s.end(), s.begin(), ::toupper) -#define reverse(s) reverse(s.begin(), s.end()) -#define getmax(ans) *max_element(all(ans)); -#define getmin(ans) *min_element(all(ans)); - -using ll = long long; -using vi = vector; -using vc = vector; -using vvc = vector; -using vvi = vector; -using vb = vector; -using vvb = vector; -using vd = vector; -using vvd = vector; -using vs = vector; -using pii = pair; -using pdd = pair; -using vpii = vector; -using vpdd = vector; -using si = set; -using ssi = set; -using sb = set; -using ssb = set; -using sd = set; -using ssd = set; -using ss = set; -using sc = set; - -// BEFORE coding are you sure you understood the statement correctly? -// PLEASE do not forget to read the sample explanation carefully. -// WATCH out for overflows & RTs in general. -// TEST your idea or code on the corner cases. -// ANALYZE each idea you have thoroughly. - -const int dx[8]={0, 0, 1, -1, 1, -1, -1, 1}; -const int dy[8]={1, -1, 0, 0, 1, -1, 1, -1}; - -void solve(){ - string s;cin>>s; - for(int i=0;i= 0 && s[i] < s[i + 1] - 1){ - s[i + 1]--; - swap(s[i], s[i + 1]); - i--; - } - } - cout<>t;while(t--) - solve(); -}",2 -anurag_sri,2050D - Digital string maximization,c++20 ,298147589,298147262,"#include -using namespace std; -#define ll long long -#define all(m) m.begin(),m.end() -#define f(i,a,b) for(ll i=a;i<=b;i++) -#define fr(i,a,b) for(ll i=a;i>=b;i--) -#define vi vector -#define vl vector -#define vvl vector> -bool is_prime(int n) { - if (n <= 1) return false; - for (int i = 2; i * i <= n; i++) { - if (n % i == 0) return false; - } - return true; -} -void solve(){ - string s; - cin >> s; - ll n = s.size(); - f(i,0,n-1){ - ll maxi_ind = i; - ll maxi_val = s[i]-'0'; - f(j,i,min(i+10LL,n-1)){ - if(s[j]-'0'+i-j>maxi_val){ - maxi_val = s[j]-'0'+i-j; - maxi_ind = j; - } - } - while(maxi_ind > i){ - swap(s[maxi_ind],s[maxi_ind-1]); - maxi_ind--; - } - s[i] = '0'+maxi_val; - } - cout << s << endl; -} -int main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } -}","v#include -using namespace std; -#define ll long long -#define all(m) m.begin(),m.end() -#define f(i,a,b) for(ll i=a;i<=b;i++) -#define fr(i,a,b) for(ll i=a;i>=b;i--) -#define vi vector -#define vl vector -#define vvl vector> -bool is_prime(int n) { - if (n <= 1) return false; - for (int i = 2; i * i <= n; i++) { - if (n % i == 0) return false; - } - return true; -} -void solve(){ - string s; - cin >> s; - ll n = s.size(); - f(i,0,n-1){ - ll maxi_ind = i; - ll maxi_val = s[i]-'0'; - f(j,i,min(10LL,n-1)){ - if(s[j]-'0'+i-j>maxi_val){ - maxi_val = s[j]-'0'+i-j; - maxi_ind = j; - } - } - while(maxi_ind > i){ - swap(s[maxi_ind],s[maxi_ind-1]); - maxi_ind--; - } - s[i] = '0'+maxi_val; - } - cout << s << endl; -} -int main(){ - ll t; - cin >> t; - while(t--){ - solve(); - } -}",1 -MHMD_3R#,2050D - Digital string maximization,c++23 ,297790150,297789382,"#include -#define int long long -using namespace std; - -int32_t main() -{ - cin.tie(0); - cout.sync_with_stdio(0); - int test = 1; - cin >> test; - while (test--) - { - string a; - cin >> a; - int n = a.size(); - for (int i = 0; i < n; i++) - { - vector p(9 , -1); - for (int j = i , k = 0; j < min((int) i + 9 , n); j++ , k++) - { - p[k] = a[j] - '0' - k; - } - int mx = -1 , pos = i; - for (int m = 0; m < 9; m++) - { - if (p[m] > mx) - { - mx = p[m]; - pos = i + m; - } - } - if (pos != i) - { - char ch = a[pos]; - int d = pos - i; - ch = (ch - '0' - d) + '0'; - a.erase(pos , 1); - a.insert(i , 1 , ch); - } - } - cout << a << endl; - } - return 0; -} -","#include -#define int long long -using namespace std; - -int32_t main() -{ - cin.tie(0); - cout.sync_with_stdio(0); - int test = 1; - cin >> test; - while (test--) - { - string a; - cin >> a; - int n = a.size(); - for (int i = 0; i < n; i++) - { - vector p(8 , -1); - for (int j = i , k = 0; j < min((int) i + 8 , n); j++ , k++) - { - p[k] = a[j] - '0' - k; - } - int mx = -1 , pos = i; - for (int m = 0; m < 8; m++) - { - if (p[m] > mx) - { - mx = p[m]; - pos = i + m; - } - } - if (pos != i) - { - char ch = a[pos]; - int d = pos - i; - ch = (ch - '0' - d) + '0'; - a.erase(pos , 1); - a.insert(i , 1 , ch); - } - } - cout << a << endl; - } - return 0; -}",1 -Deep_Thought_Programs,2050D - Digital string maximization,python,303915834,303917798,"t= int(input()) -for k in range(t): - a=input() - b= len(a) - for i in range(b): - if i<(b-8): - t= i+9 - else: - t= b - m= int(a[i]) - n=i - for j in range(i,t): - if (int(a[j])-j+i)> m: - m= int(a[j])-j+i - n= j - a= a[0:i]+str(m)+a[i:n]+a[n+1:b] - print(a)","t= int(input()) -for k in range(t): - a=list(input()) - b= len(a) - for i in range(b): - t= min(i+9,b) - m= int(a[i]) - n=i - for j in range(i,t): - if (int(a[j])-j+i)> m: - m= int(a[j])-j+i - n= j - while n>i: - a[n],a[n-1]= a[n-1],str(int(a[n])-1) - n-=1 - print("""".join(a))",2 -sm_iq,2050D - Digital string maximization,c++23 ,299080046,299080596,"/************************************************************************************* -أَعُوذُ بِاللَّهِ مِنَ الشَّيْطَانِ الرَّجِيمِ -بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ -الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ -الرَّحْمَنِ الرَّحِيمِ -مَالِكِ يَوْمِ الدِّينِ -إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ -اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ -صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ - --> In the name of Allah, the Most Gracious, the Most Merciful. --> Praise be to Allah, the Lord of all the worlds. --> The Most Gracious, the Most Merciful. --> Master of the Day of Judgment. --> You alone we worship, and You alone we ask for help. --> Guide us on the Straight Path, --> the path of those who have received Your grace; --> not the path of those who have brought down wrath upon themselves, --> nor of those who have gone astray. (AAMEEN) - -**************************************************************************************/ -#include -using namespace std; -using ll=long long; -int main (){ - ll t;cin>>t;while(t--){ - string s,s1;cin>>s; - ll count1=0,count0=0; - s1.push_back(s[0]); - for(ll i=1;i In the name of Allah, the Most Gracious, the Most Merciful. --> Praise be to Allah, the Lord of all the worlds. --> The Most Gracious, the Most Merciful. --> Master of the Day of Judgment. --> You alone we worship, and You alone we ask for help. --> Guide us on the Straight Path, --> the path of those who have received Your grace; --> not the path of those who have brought down wrath upon themselves, --> nor of those who have gone astray. (AAMEEN) - -**************************************************************************************/ -#include -using namespace std; -using ll=long long; -int main (){ - ll t;cin>>t;while(t--){ - string s,s1;cin>>s1; - // ll count1=0,count0=0; - // s1.push_back(s[0]); - // for(ll i=1;i - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while(t--){ - - string s; - - cin >> s; - - for(int i=0;i - -using namespace std; - -int main() - -{ - - int t; - - cin >> t; - - while(t--){ - - string s; - - cin >> s; - - for(int i=0;i -using namespace std; -#define int long long - -void solve() { - string s; - cin >> s; - int n = s.length(); - - while (true) { - bool changed = false; - - for (int i = 1; i < n; i++) { - if ((s[i] - '0') - 1 >= 0 && (s[i] - 1) > s[i - 1]) { - s[i] = (s[i] - '0' - 1) + '0'; - swap(s[i], s[i - 1]); - changed = true; - } - } - - if (!changed) break; - } - - cout << s << endl; -} - -int32_t main() { - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - int t; - cin >> t; - while (t--) solve(); - return 0; -} -","#include -using namespace std; -#define int long long -int t = 1; - -void solve() { - string s; - cin >> s; - int n = s.length(); - int cnt = 0; - - int prev = INT_MIN; - int maxi = stoll(s); - while (prev != maxi) { - prev = maxi; - for (int i = 1; i < n - cnt; i++) { - if ((s[i] - '0') - 1 > (s[i - 1] - '0')) { - s[i] = (s[i] - '0' - 1) + '0'; - swap(s[i], s[i - 1]); - maxi = max(maxi, stoll(s)); - } - } - } - - cout << maxi << endl; -} - -int32_t main() { - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - if (t) cin >> t; else t = 1; - while (t--) solve(); - return 0; -} -",1 -nOobCoDer9676,2050D - Digital string maximization,c++17 ,296557375,296579366,"#include -using namespace std ; - - -int main (){ - int t ; - cin>>t ; - while (t--){ - - string s ; - cin>> s ; - vectorv ; - for(int i = 0 ; i=2){ - v[i] -- ; - swap(v[i] , v[i-1]) ; - - } - - } - } - for(int i = 0 ; i -using namespace std ; - - -int main (){ - int t ; - cin>>t ; - while (t--){ - - string s ; - cin>> s ; - vectorv ; - for(int i = 0 ; i maxi){ - maxi = v[j] -j + i; - maxidx = j ; - } - } - while(maxidx>i){ - swap(v[maxidx],v[maxidx-1]) ; - maxidx-- ; - } - v[i] = maxi ; - - - } - for(int i = 0 ; i< v.size() ;i++){ - cout< -using namespace std; -#define int long long -#define INF (int)2e18 -#define endl '\n' - -const int mod = 1e9 + 7; -const int MOD = 998244353; - -vector binrep(int n) { - if (n == 0) - return {0}; - vector b; - while (n > 0) { - b.insert(b.begin(), n % 2); - n /= 2; - } - return b; -} - -int binpow(int base, int exp, int m) { - int result = 1; - base = base % m; - while (exp > 0) { - if (exp % 2 == 1) { - result = (result * base) % m; - } - base = (base * base) % m; - exp = exp / 2; - } - return result; -} - - -//bool check(int x){ -// -//} -// -//int search(int k) { -// int pos = 0, max = INF; -// for (int i = max; i >= 1; i /= 2) { -// while (check(pos + i)) pos += i; -// } -// return pos; -//} -// -//int search(int k) { -// int low = 0, high = INF, ans = -1; -// while (low <= high) { -// int mid = low + (high - low) / 2; -// if (check(mid)) { -// ans = mid; -// high = mid - 1; -// } else { -// low = mid + 1; -// } -// } -// return ans; -//} - -void solve() { - string s; cin >> s; - int n = s.length(); - int idx = 0; - char m = '0', temp; - string ans = """"; - for(int i = 0; i < n; i++){ - m = '0'; - for(int j = 0; j < 9 && j < n; j++){ - temp = (char)((int)s[j] - j); - if(m < temp){ - m = temp; - idx = j; - } - } - ans += m; - s.erase(s.begin() + idx); - } - cout << ans; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test = 1; - cin >> test; - - while (test--) { - solve(); - cout << '\n'; - } - return 0; -}","// /** -// * author: _isomorphism -// * created: 19.12.2024 16:30:22 -// **/ -// -// Problem: D. Digital string maximization -// Contest: Codeforces - Codeforces Round 991 (Div. 3) - - -#include -using namespace std; -#define int long long -#define INF (int)2e18 -#define endl '\n' - -const int mod = 1e9 + 7; -const int MOD = 998244353; - -vector binrep(int n) { - if (n == 0) - return {0}; - vector b; - while (n > 0) { - b.insert(b.begin(), n % 2); - n /= 2; - } - return b; -} - -int binpow(int base, int exp, int m) { - int result = 1; - base = base % m; - while (exp > 0) { - if (exp % 2 == 1) { - result = (result * base) % m; - } - base = (base * base) % m; - exp = exp / 2; - } - return result; -} - - -//bool check(int x){ -// -//} -// -//int search(int k) { -// int pos = 0, max = INF; -// for (int i = max; i >= 1; i /= 2) { -// while (check(pos + i)) pos += i; -// } -// return pos; -//} -// -//int search(int k) { -// int low = 0, high = INF, ans = -1; -// while (low <= high) { -// int mid = low + (high - low) / 2; -// if (check(mid)) { -// ans = mid; -// high = mid - 1; -// } else { -// low = mid + 1; -// } -// } -// return ans; -//} - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test = 1; - cin >> test; - - while (test--) { - solve(); - cout << '\n'; - } - return 0; -}",2 -doWhileLoop,2050D - Digital string maximization,c++17 ,310889158,310889872,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); - -using namespace std; - -FILE* stream; - -#define ll long long - - - -int d(char c) - -{ - - return (c - '0'); - -} - - - -void solve() - -{ - - string s; - - cin >> s; - - - - int n = (int)s.size(); - - - - for (int i = 0; i < n; ++i) - - { - - int best = d(s[i]); - - int pos = i; - - for (int j = i+1; j < min(i+10, n); ++j) - - { - - if( d(s[j])-(j-i)>best) - - { - - pos = j; - - best = d(s[j])-(j-i); - - - - - - - - } - - - - - - while (pos > i) - - { - - swap(s[pos], s[pos - 1]); - - --pos; - - } - - } - - } - - - - - - cout << s << endl; - -} - - - -signed main() - -{ - - FastIO - -#ifndef ONLINE_JUDGE - - - - //For getting input from input.txt file - - freopen_s(&stream, ""input.txt"", ""r"", stdin); - - - - //Prlong longing the Output to output.txt file - - freopen_s(&stream, ""output.txt"", ""w"", stdout); - - - -#endif - - - - ll tc = 1; - - cin >> tc; - - while (tc--) { - - solve(); - - } - - - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); - -using namespace std; - -FILE* stream; - -#define ll long long - - - -int d(char c) - -{ - - return (c - '0'); - -} - - - -void solve() - -{ - - string s; - - cin >> s; - - - - int n = (int)s.size(); - - - - for (int i = 0; i < n; ++i) - - { - - int best = d(s[i]); - - - - int pos = i; - - - - for (int j = i; j < min(i+10, n); ++j) - - { - - if( d(s[j])-(j-i)>best) - - { - - pos = j; - - best = d(s[j])-(j-i); - - - - - - - - } - - - - - - - - } - - while (pos > i) - - { - - swap(s[pos], s[pos - 1]); - - --pos; - - } - - - - s[i] = char(best + '0'); - - } - - - - - - cout << s << endl; - -} - - - -signed main() - -{ - - FastIO - -#ifndef ONLINE_JUDGE - - - - //For getting input from input.txt file - - freopen_s(&stream, ""input.txt"", ""r"", stdin); - - - - //Prlong longing the Output to output.txt file - - freopen_s(&stream, ""output.txt"", ""w"", stdout); - - - -#endif - - - - ll tc = 1; - - cin >> tc; - - while (tc--) { - - solve(); - - } - - - - return 0; - -}",2 -PaciPeshev#,2050D - Digital string maximization,c++17 ,296402786,296402964,"#include -using namespace std; -long long t; -string s; -void zad(){ - cin>>s; - int right; - int left; - for(int i=1; i0; j--){ - right = s[j]-'0'; - left = s[j-1]-'0'; - if(right == 0){ - break; - } - if(right-1 > left){ - s[j-1] = (right-1)+'0'; - s[j] = left+'0'; - } - } - } - cout<>t; - for(long long i=0; i -using namespace std; -long long t; -string s; -void zad(){ - cin>>s; - int right; - int left; - for(int i=1; i0; j--){ - right = s[j]-'0'; - left = s[j-1]-'0'; - if(right-1 > left){ - s[j-1] = (right-1)+'0'; - s[j] = left+'0'; - }else{ - break; - } - } - } - cout<>t; - for(long long i=0; i -#include -#include -#include - -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(0); - - int t; - string s; - cin>>t; - - string ans[t]; - - for(int i=0;i>s; - - for(int j=0;j s[j+mini] - mini) { - mini = k; - } - } - - for(int k=mini;k>0;k--) { - swap(s[j+k-1],s[j+k]); - s[j+k-1] -= 1; - } - } - - ans[i] = s; - } - - for(int i=0;i -#include -#include -#include - -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(0); - - int t; - string s; - cin>>t; - - string ans[t]; - - for(int i=0;i>s; - cout<<""len: ""< s[j+mini] - mini) { - mini = k; - } - } - - for(int k=mini;k>0;k--) { - swap(s[j+k-1],s[j+k]); - s[j+k-1] -= 1; - } - } - - ans[i] = s; - } - - for(int i=0;i -#include -#include -using namespace std; - -void solve(string &s) { - int n = s.length(); - deque candidates; // Store indices of potential candidates for swapping - - for (int i = n - 1; i > 0; i--) { - // Only consider digits that can be decreased (not 0) - if (s[i] > '0') { - while (!candidates.empty() && s[candidates.back()] <= s[i]) { - candidates.pop_back(); // Remove weaker candidates - } - candidates.push_back(i); // Add current digit as a candidate - } - - // Check if there's a valid candidate to swap with the left neighbor - if (!candidates.empty() && candidates.front() == i) { - int j = i - 1; // Left neighbor - if (s[i] - 1 > s[j]) { - swap(s[i], s[j]); // Perform the swap - s[j] = s[j] - 1; // Decrease the swapped digit - candidates.pop_front(); // Remove the used candidate - } - } - } -} - -int main() { - int t; - cin >> t; - while (t--) { - string s; - cin >> s; - solve(s); - cout << s << endl; - } - return 0; -}","#include -#include -using namespace std; - -void solve(string &s) { - bool swapped = true; - while (swapped) { - swapped = false; - for (int i = 1; i < s.length(); i++) { - if (s[i] > '0' && s[i] - 1 > s[i - 1]) { - swap(s[i], s[i - 1]); // Swap the current digit with the left neighbor - s[i - 1]--; // Decrease the digit that moved to the left - swapped = true; // Mark as swapped to continue processing - } - } - } -} - -int main() { - int t; - cin >> t; - while (t--) { - string s; - cin >> s; - solve(s); - cout << s << endl; - } - return 0; -}",2 -akashamanur15,2050D - Digital string maximization,c++20 ,310229094,310228741,"// B. Just Eat It! - - - -#include - -#define ll long long - -using namespace std; - - - - double eps=1e-6; - - double sq_rt(double x){ - - double lo=1,hi=x; - - double mid; - - while(hi-lo>eps){ - - mid=(hi+lo)/2; - - if(mid*midkey){ - - e=mid-1; - - } - - else { - - s=mid+1; - - } - - } - - return -1; - -} - - - - int lower_bound(vector &v ,int ele){ - - int lo =0, hi=v.size()-1; - - int mid; - - while(hi-lo>1){ - - int mid= (hi +lo)/2; - - if(v[mid]=ele){ - - return lo; - - } - - if(v[hi]>=ele){ - - return hi; - - } - - return -1; - - - - } - - - - int upper_bound(vector &v ,int ele){ - - int lo =0, hi=v.size()-1; - - int mid; - - while(hi-lo>1){ - - int mid= (hi +lo)/2; - - if(v[mid]<=ele){ - - lo=mid+1; - - - - } - - else{ - - hi= mid; - - - - } - - } - - if(v[lo]>ele){ - - return lo; - - } - - if(v[hi]>ele){ - - return hi; - - } - - return -1; - - - - } - - - -int gcd(int a, int b) - -{ - - return b == 0 ? a : gcd(b, a % b); - -} - -int lcm(int a,int b){ - - int l=max(a,b); - - int s=min(a,b); - - for(int i=l; ;i=i+l){ - - if(i%s==0){ - - return i; - - } - - } - -} - - int prime(int n){ - - for(int i=2;i*i<=n;i++){ - - if(n%i==0){ - - return 1; - - break; - - } - - } - - return 0; - - } - - - - void print(map & m){ - - cout<>te; - - while(te--){ - - string s; - - cin>>s; - - int si=s.size(); - - int arr[si]; - - for(int i=0;im){ - - m=arr[j]+(i-j); - - p=j; - - } - - } - - else break; - - } - - - - if(p!=i){ - - for(int k=p;k>i;k--){ - - arr[k]=arr[k-1]; - - } - - } - - r[i]=m; - - - - r[si-1]=arr[si-1]; - - - - - - - - } - - for(int i=0;i - -#define ll long long - -using namespace std; - - - - double eps=1e-6; - - double sq_rt(double x){ - - double lo=1,hi=x; - - double mid; - - while(hi-lo>eps){ - - mid=(hi+lo)/2; - - if(mid*midkey){ - - e=mid-1; - - } - - else { - - s=mid+1; - - } - - } - - return -1; - -} - - - - int lower_bound(vector &v ,int ele){ - - int lo =0, hi=v.size()-1; - - int mid; - - while(hi-lo>1){ - - int mid= (hi +lo)/2; - - if(v[mid]=ele){ - - return lo; - - } - - if(v[hi]>=ele){ - - return hi; - - } - - return -1; - - - - } - - - - int upper_bound(vector &v ,int ele){ - - int lo =0, hi=v.size()-1; - - int mid; - - while(hi-lo>1){ - - int mid= (hi +lo)/2; - - if(v[mid]<=ele){ - - lo=mid+1; - - - - } - - else{ - - hi= mid; - - - - } - - } - - if(v[lo]>ele){ - - return lo; - - } - - if(v[hi]>ele){ - - return hi; - - } - - return -1; - - - - } - - - -int gcd(int a, int b) - -{ - - return b == 0 ? a : gcd(b, a % b); - -} - -int lcm(int a,int b){ - - int l=max(a,b); - - int s=min(a,b); - - for(int i=l; ;i=i+l){ - - if(i%s==0){ - - return i; - - } - - } - -} - - int prime(int n){ - - for(int i=2;i*i<=n;i++){ - - if(n%i==0){ - - return 1; - - break; - - } - - } - - return 0; - - } - - - - void print(map & m){ - - cout<>te; - - while(te--){ - - string s; - - cin>>s; - - int si=s.size(); - - int arr[si]; - - for(int i=0;im){ - - m=arr[j]+(i-j); - - p=j; - - } - - } - - } - - - - if(p!=i){ - - for(int k=p;k>i;k--){ - - arr[k]=arr[k-1]; - - } - - } - - r[i]=m; - - - - r[si-1]=arr[si-1]; - - - - - - - - } - - for(int i=0;i -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int t; - cin>>t; - for(int i=0;i>s; - vector vec; - - for(int j=0;jmax(0,k-10);k--){ - if(s[k]-s[k-1]>1){ - int temp=s[k]-1; - s[k]=s[k-1]; - s[k-1]=temp; - } - } - } - cout< -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int t; - cin>>t; - for(int i=0;i>s; - vector vec; - - for(int j=1;j0;k--){ - // cout<<""k""; - if(s[k]-s[k-1]>1){ - int temp=s[k]-1; - s[k]=s[k-1]; - s[k-1]=temp; - } - else{ - break; - } - } - // cout<<"" ""; - // cout< - - - -using namespace std; - - - -void sol(){ - - string s; - - cin>>s; - - int n = s.size(); - - for(int i=0; i=2){ - - count++; - - swap(s[i],s[i-1]); - - s[i-1]= char(int(s[i-1])-1); - - } - - } - - if(count==0)break; - - } - - cout<>t; - - while(t--){ - - sol(); - - } - - return 0; - -}","#include - - - -using namespace std; - - - -void sol(){ - - string s; - - cin>>s; - - int n = s.size(); - - for(int i=0; i=2){ - - swap(s[i],s[i-1]); - - s[i-1]= char(int(s[i-1])-1); - - } - - } - - } - - cout<>t; - - while(t--){ - - sol(); - - } - - return 0; - -}",1 -Bharat_2003_,2050D - Digital string maximization,c++17 ,299291055,299284315,"#include -using namespace std; - -int main() -{ - string s; - int num; - cin>>num; - while(num--) - { - cin>>s; - int swapped; - do { - swapped = 0; - for (int i = 1; i < s.size(); i++) { - if (s[i] > s[i - 1] + 1) { - - char temp = s[i - 1]; - s[i - 1] = s[i] - 1; - s[i] = temp; - swapped = 1; - } - } - } while (swapped); - cout< -#include -using namespace std; - -string max_str(string &s) -{ - string maxstr=s; - bool update; - int i=1; - while(true) - { - if(i==s.size()) - { - i=1; - if(!update) - { - return maxstr; - } - } - update=false; - if(s[i]!='0') - { - char temp=s[i-1]; - int num=s[i]-'0'; - num=num-1; - s[i-1]=num+'0'; - s[i]=temp; - } - if(maxstr myvec; - cin>>num; - while(num>0) - { - cin>>st; - myvec.push_back(max_str(st)); - num--; - } - for(auto str:myvec) - { - cout< - -using namespace std; - - - -void solve() { - -string s; - -cin >> s; - -const int n = s.length(); - -for (int i{1}; i < n; ++i) { - -for (int j{i}; j && s[j] > s[j - 1] + 1; --j) { - -s[j] -= 1; - -swap(s[j], s[j - 1]); - -} - -} - -cout << s << '\n'; - -} - - - -int main() { - -cin.tie(0)->sync_with_stdio(0); - -int t; cin >> t; while (t--) - -solve(); - -}","#include - -using namespace std; - - - -void solve() { - -string s; - -cin >> s; - -const int n = s.length(); - -for (int i{1}; i < n; ++i) { - -for (int j{i}; j; --j) { - -if (s[j] > s[j - 1] + 1) { - -s[j] -= 1; - -swap(s[j], s[j - 1]); - -} - -} - -} - -cout << s << '\n'; - -} - - - -int main() { - -cin.tie(0)->sync_with_stdio(0); - -int t; cin >> t; while (t--) - -solve(); - -}",1 -Riyad_Hossain,2050D - Digital string maximization,c++20 ,296913894,296914029,"#include -#include -#include - -using namespace __gnu_pbds; -using namespace std; - -template -using pbds = tree, rb_tree_tag, tree_order_statistics_node_update>; - -// Utilities -#define endl '\n' -#define int long long -#define no cout << ""NO"" -#define ye cout << ""YES"" -#define print(...) cout << (__VA_ARGS__) -#define printsp(...) cout << (__VA_ARGS__) << ' ' -#define println(...) cout << (__VA_ARGS__) << '\n' - -// Looping Mechanism -#define forEach(x, ds) for (auto &x : ds) -#define forr(i, a, b) for (int i = (a); i <= (b); ++i) -#define rforr(i, a, b) for (int i = (a); i >= (b); --i) - -// Shortcut Functions -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -#define getMx(x) *max_element(all(x)) -#define getMn(x) *min_element(all(x)) -#define rall(x) (x).rbegin(), (x).rend() -#define getSum(x) accumulate(all(x), 0ll) -#define cntBit(x) __builtin_popcountll(x) -#define dsFind(x, ds) (ds.find(x) != ds.end()) -#define lb(x, ds) lower_bound(ds.begin(), ds.end(), x) -#define ub(x, ds) upper_bound(ds.begin(), ds.end(), x) - -// Data Types -typedef vector vi; -typedef vector vvi; -typedef map mi; -typedef pair pi; -typedef vector vpi; - -// Constant Varialbes -const int inf = 1e9; -const int llinf = 1e18; -const int mod = 1e9 + 7; - -void solve() -{ - string s; - cin >> s; - - auto getNum = [&](char ch) - { - return ch - '0'; - }; - - int n = sz(s); - forr(i, 0, n - 1) - { - int best = getNum(s[i]), pickIdx = i,j = i; - while (j <= 9 && j < n) - { - int curr = getNum(s[j]) - (j - i); - if (curr > best) - best = curr, pickIdx = j; - j++; - } - while (pickIdx > i) - s[pickIdx] = s[pickIdx - 1], pickIdx--; - print(best); - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - - while (t--) - { - solve(); - cout << endl; - } - - return 0; -}","#include -#include -#include - -using namespace __gnu_pbds; -using namespace std; - -template -using pbds = tree, rb_tree_tag, tree_order_statistics_node_update>; - -// Utilities -#define endl '\n' -#define int long long -#define no cout << ""NO"" -#define ye cout << ""YES"" -#define print(...) cout << (__VA_ARGS__) -#define printsp(...) cout << (__VA_ARGS__) << ' ' -#define println(...) cout << (__VA_ARGS__) << '\n' - -// Looping Mechanism -#define forEach(x, ds) for (auto &x : ds) -#define forr(i, a, b) for (int i = (a); i <= (b); ++i) -#define rforr(i, a, b) for (int i = (a); i >= (b); --i) - -// Shortcut Functions -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -#define getMx(x) *max_element(all(x)) -#define getMn(x) *min_element(all(x)) -#define rall(x) (x).rbegin(), (x).rend() -#define getSum(x) accumulate(all(x), 0ll) -#define cntBit(x) __builtin_popcountll(x) -#define dsFind(x, ds) (ds.find(x) != ds.end()) -#define lb(x, ds) lower_bound(ds.begin(), ds.end(), x) -#define ub(x, ds) upper_bound(ds.begin(), ds.end(), x) - -// Data Types -typedef vector vi; -typedef vector vvi; -typedef map mi; -typedef pair pi; -typedef vector vpi; - -// Constant Varialbes -const int inf = 1e9; -const int llinf = 1e18; -const int mod = 1e9 + 7; - -void solve() -{ - string s; - cin >> s; - - auto getNum = [&](char ch) - { - return ch - '0'; - }; - - int n = sz(s); - forr(i, 0, n - 1) - { - int best = getNum(s[i]), pickIdx = i,j = i; - while (j-i <= 9 && j < n) - { - int curr = getNum(s[j]) - (j - i); - if (curr > best) - best = curr, pickIdx = j; - j++; - } - while (pickIdx > i) - s[pickIdx] = s[pickIdx - 1], pickIdx--; - print(best); - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - - while (t--) - { - solve(); - cout << endl; - } - - return 0; -}",2 -Alsahy,2050D - Digital string maximization,c++20 ,297977460,297979408,"#include -using namespace std; -#define int long long - -void solve() -{ - string s; - cin >> s; - int n = s.size(); - - for(int i = 0; i s[i] && s[j] - i - '0' > mx) - { - mx = s[j] - i - '0'; - mx_indx = j; - } - } - cout << ""MX INDX : "" << mx_indx << endl; - cout << s << endl; - - if(mx) - { - while(mx_indx != i) - { - s[mx_indx] = s[mx_indx] - 1; - swap(s[mx_indx], s[mx_indx-1]); - mx_indx--; - } - } - } - - cout << s << endl; - -} - -signed main() -{ - ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); - int t = 1; - cin >> t; - while(t--) - solve(); -}","#include -using namespace std; -#define int long long - -void solve() -{ - string s; - cin >> s; - int n = s.size(); - - for(int i = 0; i mx) - { - mx = s[j] - (j - i) - '0'; - mx_indx = j; - } - } - - if(mx) - { - while(mx_indx > i) - { - swap(s[mx_indx], s[mx_indx-1]); - mx_indx--; - } - } - s[i] = char(mx + '0'); - } - - cout << s << endl; - -} - -signed main() -{ - ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); - int t = 1; - cin >> t; - while(t--) - solve(); -}",2 -hc06,2050D - Digital string maximization,c++17 ,299122152,299122320,"#include -#include -using namespace std; - -string solve(string s) { - for(int i = 0; i < s.length() - 1; ++i) { - int max = -1; - int max_index = -1; - for(int j = i; j <= i + 9 && j < s.length(); ++j) { - int d = s[j] - '0'; - if(d - (j - i) > max) { - max = d; - max_index = j; - } - } - - s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0'); - for(int j = max_index; j > i; --j) { - char temp = s[j - 1]; - s[j - 1] = s[j]; - s[j] = temp; - } - } - return s; -} - -int main() { - int t; - cin >> t; - for(int i = 0; i < t; ++i) { - string s; - cin >> s; - cout << solve(s); - } -}","#include -#include -using namespace std; - -string solve(string s) { - for(int i = 0; i < s.length() - 1; ++i) { - int max = -1; - int max_index = -1; - for(int j = i; j <= i + 9 && j < s.length(); ++j) { - int d = s[j] - '0'; - if(d - (j - i) > max) { - max = d - (j - i); - max_index = j; - } - } - - s[max_index] = (char) (s[max_index] - '0' - (max_index - i) + '0'); - for(int j = max_index; j > i; --j) { - char temp = s[j - 1]; - s[j - 1] = s[j]; - s[j] = temp; - } - } - return s; -} - -int main() { - int t; - cin >> t; - for(int i = 0; i < t; ++i) { - string s; - cin >> s; - cout << solve(s) << ""\n""; - } -}",2 -Ghost..,2050D - Digital string maximization,c++23 ,307511026,307511349,"#include -#include -#include -#include -#include -#include -#include -using namespace std; -#include -using namespace __gnu_pbds; -template -using orderStaticTree = - tree, rb_tree_tag, tree_order_statistics_node_update>; - -#define ll long long - -#define saleh \ - ios_base::sync_with_stdio(false); \ - cin.tie(nullptr); - -const int md = 1e9 + 7; - -int main() -{ - saleh; - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int n = s.size(); - for (int i = n - 1; i >= 1; i--) - { - int curr = s[i] - '0'; - --curr; - int pre = s[i - 1] - '0'; - if (curr > pre) - { - - s[i - 1] = char(curr + '0'); - s[i] = char(pre + '0'); - } - int j = i; - int ii = i + 1; - while (ii <= n - 1) - { - int curr = s[j] - '0'; - int nxt = s[ii] - '0'; - nxt--; - if (nxt > curr) - { - s[j] = char(nxt + '0'); - s[ii] = char(curr + '0'); - } - j++; - ii++; - } - } - cout << s << endl; - } - - return 0; -}"," - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -#include - -using namespace __gnu_pbds; - -template - -using orderStaticTree = - - tree, rb_tree_tag, tree_order_statistics_node_update>; - - - -#define ll long long - - - -#define saleh \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(nullptr); - - - -const int md = 1e9 + 7; - - - -int main() - -{ - - saleh; - - int t; - - cin >> t; - - while (t--) - - { - - string s; - - cin >> s; - - int n = s.size(); - - for (int i = n - 1; i >= 1; i--) - - { - - int curr = s[i] - '0'; - - --curr; - - int pre = s[i - 1] - '0'; - - if (curr > pre) - - { - - - - s[i - 1] = char(curr + '0'); - - s[i] = char(pre + '0'); - - } - - int j = i; - - int ii = i + 1; - - while (ii <= n - 1 && s[ii] != '0' && s[j] < s[ii]) - - { - - int curr = s[j] - '0'; - - int nxt = s[ii] - '0'; - - nxt--; - - if (nxt > curr) - - { - - s[j] = char(nxt + '0'); - - s[ii] = char(curr + '0'); - - } - - j++; - - ii++; - - } - - } - - cout << s << endl; - - } - - - - return 0; - -}",2 -AksharZala,2050D - Digital string maximization,python,297224440,297226514,"def recursive(a,begin): - if begin==len(a): - return - max_val = a[begin] - max_index = begin - for i in range(begin, min(len(a), begin+8)): - if max_val<(a[i] - (i-begin)): - max_val= a[i]-i+begin - max_index = i - while max_index !=begin: - a[max_index], a[max_index-1] = a[max_index-1],a[max_index]-1 - max_index-=1 -def solve(): - n = input() - a = list(map(int,n)) - begin = 0 - while begin -using namespace std; -#define int long long int - -void solve(){ - int n; - - string a; - cin>> a; - n = a.size(); - - for (int i = 0; i < n; ++i) - { - - int mx = a[i]-'0', mxi=i; - - for (int j = i+1; j < i+9 && j < n; ++j) - { - if(mx < (a[j]-'0'-(j-i))){ - mx = (a[j]-'0'-(j-i)); - - mxi = j; - } - } - - // swap - - - int c = a[i], cn = 0; - for (int k = i+1; k <= mxi; ++k) - { - cn = a[k]; - a[k] = c; - c = cn; - } - a[i] = mx+'0'; - - // cerr<< a <<"",""; - } - - // cerr<> t; - while(t--){ - solve(); - } - - return 0; -}","#include -using namespace std; -using ll = long long int; - -void solve(){ - int n; - - string a; - cin>> a; - n = a.size(); - - for (int i = 0; i < n; ++i) - { - - int mx = a[i]-'0', mxi=i; - - for (int j = i+1; j < n; ++j) - { - if(mx < (a[j]-'0'-(j-i))){ - mx = (a[j]-'0'-(j-i)); - - mxi = j; - } - } - - // swap - - - int c = a[i], cn = 0; - for (int k = i+1; k <= mxi; ++k) - { - cn = a[k]; - a[k] = c; - c = cn; - } - a[i] = mx+'0'; - - // cerr<< a <<"",""; - } - - // cerr<> t; - while(t--){ - solve(); - } - - return 0; -}",1 -Aniket_abhi,2050D - Digital string maximization,c++23 ,303867174,303866978,"#include - -using namespace std; - -typedef long long ll; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - string s; - - cin>>s; - - ll n=s.size(); - - ll i; - - vectorv(n); - - for(int i=0; i m){ - - idx=j; - - m=v[j]-k; - - } - - k++; - - } - - if(m>v[i]){ - - for(int y=idx; y>i; y--){ - - v[y]=v[y-1]; - - } - - v[i]=m; - - } - - } - - for(int l=i; l m){ - - idx=j; - - m=v[j]-k; - - } - - k++; - - } - - // cout<v[l]){ - - for(ll y=idx; y>l; y--){ - - v[y]=v[y-1]; - - } - - v[l]=m; - - } - -// for(auto it:v){ - -// cout< - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - while(t--){ - - string s; - - cin>>s; - - int n=s.size(); - - int i; - - vectorv(n); - - for(int i=0; i m){ - - idx=j; - - m=v[j]-k; - - } - - k++; - - } - - if(m>v[i]){ - - int z=1; - - for(int k=idx; k>i; k--){ - - v[k]=v[k]-z; - - swap(v[k],v[k-1]); - - z++; - - } - - } - - } - - for(int l=i; l m){ - - idx=j; - - m=v[j]-k; - - } - - k++; - - } - - // cout<v[l]){ - - for(int y=idx; y>l; y--){ - - v[y]=v[y-1]; - - } - - v[l]=m; - - } - -// for(auto it:v){ - -// cout< -#include -using namespace std; -using ll = long long; - -int main() { - int t; - cin >> t; - - while (t--) { - - string s; - cin >> s; - ll n = s.size(); - for (ll i = 0; i < n; i++) { - ll maxc = s[i] - '0'; - ll maxi = i; - for (ll j = i ; j < min(i+10,n); j++) { - if (s[j] - '0' + (i - j) > maxc) { - maxc = s[j] - '0' + (i - j); - maxi = j; - } - }ll k = maxi; - - while(maxi > i) { - swap(s[maxi], s[maxi - 1]); - maxi--; - } - s[i] += (i - k); - } - - cout < -#include -using namespace std; -using ll = long long; - -int main() { - int t; - cin >> t; - - while (t--) { - - string s; - cin >> s; - ll n = s.size(); - for (int i = 0; i < n; i++) { - ll maxc = s[i] - '0'; - ll maxi = i; - for (int j = i + 1; j < n; j++) { - if (s[j] - '0' + (i - j) > maxc) { - maxc = s[j] - '0' + (i - j); - maxi = j; - } - } - - swap(s[i], s[maxi]); - s[i]+= (i - maxi); - } - - cout << s << endl; - } - - return 0; -} -",1 -NEU.Lunacub,2050D - Digital string maximization,c++23 ,297047258,297050961,"#include -#include -#include -using namespace std; -int main() { - int t; - cin >> t; - while(t--){ - string s; - cin >> s; - vector a; - if(s.length() < 9){ - for(int i=0; i a = {9, 8, 7, 6, 5, 4 ,3, 2, 1}; - vector result; - int size = a.size(); - for(int j=0; j 9){ - for(int i=10; i -using namespace std; -int main() { - int t; - cin >> t; - while(t--){ - string s; - cin >> s; - for(int i=0; i=1){ - i-=2; - } - } - } - cout< -#include -#include -#include -#include -#include -#define vi vector -#define pb push_back -#define int long long -using namespace std; -const int N = 5e5+10; -int t,sum=0; -string s; - -void solve(){ - cin>>s; - for(int i=0;i=1;j--){ - if(s[j-1]>t; - while(t--) - solve(); - return 0; -} ","#include -#include -#include -#include -#include -#include -#define vi vector -#define pb push_back -#define int long long -using namespace std; -const int N = 5e5+10; -int t,sum=0; -string s; - -void solve(){ - cin>>s; - for(int i=0;i=1;j--){ - if(s[j-1]>t; - while(t--) - solve(); - return 0; -} ",2 -trnhduowng,2050D - Digital string maximization,c++23 ,307236217,307236813,"#include ""bits/stdc++.h"" - -#define int long long - -using namespace std; - -void A() - -{ - - string s; - - cin >>s; - - map mp; - - int n=s.size(),i,j; - - int d=0; - - for(int p=1;p<=50000;p++) - - { - - for(j=n-1,i=n-1;i>0;i--) - - { - - j=i; - - if(s[i]-1>s[i-1]) - - { - - char q; - - q=s[i]-1; - - s[i]=s[i-1]; - - s[i-1]=q; - - } - - } - - } - - cout <>t; - - while(t--) A(); - - return 0; - - - -}","#include ""bits/stdc++.h"" - -#define int long long - -using namespace std; - -void A() - -{ - - string s; - - cin >>s; - - map mp; - - int n=s.size(),i,j; - - int d=0; - - for(int p=1;p<=25000;p++) - - { - - for(j=n-1,i=n-1;i>0;i--) - - { - - j=i; - - if(s[i]-1>s[i-1]) - - { - - char q; - - q=s[i]-1; - - s[i]=s[i-1]; - - s[i-1]=q; - - } - - } - - } - - cout <>t; - - while(t--) A(); - - return 0; - - - -}",2 -Ak_47___,2050D - Digital string maximization,c++20 ,296563042,296569385,"#include -#include -#include -using namespace std; - -int main(){ - int t; - cin >> t; - vector answers; - while(t--){ - string s; - cin >> s; - int n=s.size(); - vector newvalues; - for(int i =0;imax){ - max=cur; - toswapindex=j; - } - } - } - if(max!=0){ - for(int k=toswapindex; k>i;k--){ - s[k]=s[k-1]; - } - s[i]= max+'0'; - } - } - answers.push_back(s); - } - for(string answer : answers){ - cout << answer << ""\n""; - } - return 0; -}","#include -#include -#include -using namespace std; - -int main(){ - int t; - cin >> t; - vector answers; - while(t--){ - string s; - cin >> s; - int n=s.size(); - vector newvalues; - for(int i =0;imax){ - max=cur; - toswapindex=j; - } - } - } - if(max!=0){ - for(int k=toswapindex; k>i;k--){ - s[k]=s[k-1]; - } - s[i]= max+'0'; - } - } - answers.push_back(s); - } - for(string answer : answers){ - cout << answer << ""\n""; - } - return 0; -}",2 -zjinyi#,2050D - Digital string maximization,c++17 ,304664587,304665042,"#include - -using namespace std; - - - -bool check(string a) - -{ - - for (int i = 0; i < a.size() - 1; ++i) - - { - - if (a[i + 1] == '0') - - { - - continue; - - } - - if (a[i] + 1 < a[i + 1]) - - { - - return true; - - } - - } - - return false; - -} - - - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - string s; - - cin >> s; - - while (check(s) == true) - - { - - for (int i = 0; i < s.size() - 1; ++i) - - { - - if (s[i] == '0') - - { - - continue; - - } - - if (s[i] + 1 < s[i + 1]) - - { - - s[i + 1] -= 1; - - char temp = s[i]; - - s[i] = s[i + 1]; - - s[i + 1] = temp; - - } - - } - - } - - cout << s << endl; - - } - - - - return 0; - -}","#include - -using namespace std; - - - -bool check(string a) - -{ - - for (int i = 0; i < a.size() - 1; ++i) - - { - - if (a[i + 1] == '0') - - { - - continue; - - } - - if (a[i] + 1 < a[i + 1]) - - { - - return true; - - } - - } - - return false; - -} - - - -int main() - -{ - - int t; - - cin >> t; - - while (t--) - - { - - string s; - - cin >> s; - - while (check(s) == true) - - { - - for (int i = 0; i < s.size() - 1; ++i) - - { - - if (s[i + 1] == '0') - - { - - continue; - - } - - if (s[i] + 1 < s[i + 1]) - - { - - s[i + 1] -= 1; - - char temp = s[i]; - - s[i] = s[i + 1]; - - s[i + 1] = temp; - - } - - } - - } - - cout << s << endl; - - } - - - - return 0; - -}",2 -pchadzi#,2050D - Digital string maximization,c++17 ,303022043,303021960,"#include - -using namespace std; - -#define ll long long - -const int N=1e5; - - - -int32_t main() { - - ios::sync_with_stdio(0); - - cin.tie(0); - - ll t; - - cin >> t; - - while (t--) { - - string s; - - cin>>s; - - ll n=s.size(); - - for(ll i=0;iin) {in=s[j]-j+i-'0'; idx=j;} - - } - - if(in!=s[i]-'0') { - - for(int j=idx-1;j>=i;j--){ - - s[j+1]=s[j]; - - } - - s[i]=char(in+'0'); - - } - - } - - cout< - -using namespace std; - - - -#define vi vector - -#define vvi vector> - -#define vll vector - -#define ll long long - -#define all(n) n.begin(), n.end() - -#define mod 1000000007 - - - -void solve(){ - - string s; cin >> s; - - int n = s.size(); - - - - for(int i=0; i i){ - - swap(s[ind], s[ind-1]); - - ind--; - - } - - s[i] = '0'+maxi; - - } - - cout << s << endl; - -} - - - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - - - int tt = (cin >> tt, tt); - - while(tt--) solve(); - -} - -",1 -igz,2050D - Digital string maximization,c++17 ,304622648,304624306,"#include - - - -using namespace std; - - - -#define rep(i, a, b) for (int i = a; i < (b); i++) - -#define rrep(i, a, b) for (int i = a; i >= (b); i--) - -#define range(i, a, b, s) for (int i = a; (s > 0 && i < (b)) || (s < 0 && i > (b)); i += s) - -#define trav(a, x) for (auto& a : x) - -#define all(x) begin(x), end(x) - -#define sz(x) (int) (x).size() - -typedef long long ll; - -typedef pair pii; - -typedef vector vi; - -typedef vector vpi; - - - -template - -void print_arr(vector a) { - - trav(x, a) cout << to_string(x) << "" ""; - - cout << ""\n""; - -} - - - -int T; - -vi a; - -string s; - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - - cin >> T; - - while (T--) { - - cin >> s; - - - - vi skip(sz(s), 0); - - rep(i, 0, sz(s)) { - - if (skip[i]) continue; - - - - int mx = s[i] - '0'; - - int mx_pos = i; - - int skipped = 0; - - rep(j, 1, 20) { - - if (i+j >= sz(s)) break; - - if (skip[i+j]) { - - skipped++; - - continue; - - } - - if (s[i+j] - '0' - j + skipped > mx) { - - //cout << i << "" "" << i+j << "" "" << s[i+j] - '0' - j << '\n'; - - mx = s[i+j] -'0' - j + skipped; - - mx_pos = i+j; - - } - - } - - - - cout << mx; - - skip[mx_pos] = 1; - - i--; - - } - - - - cout << '\n'; - - } - - - - return 0; - -} - -","#include - - - -using namespace std; - - - -#define rep(i, a, b) for (int i = a; i < (b); i++) - -#define rrep(i, a, b) for (int i = a; i >= (b); i--) - -#define range(i, a, b, s) for (int i = a; (s > 0 && i < (b)) || (s < 0 && i > (b)); i += s) - -#define trav(a, x) for (auto& a : x) - -#define all(x) begin(x), end(x) - -#define sz(x) (int) (x).size() - -typedef long long ll; - -typedef pair pii; - -typedef vector vi; - -typedef vector vpi; - - - -template - -void print_arr(vector a) { - - trav(x, a) cout << to_string(x) << "" ""; - - cout << ""\n""; - -} - - - -int T; - -vi a; - -string s; - - - -int main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - - cin >> T; - - while (T--) { - - cin >> s; - - - - vi skip(sz(s), 0); - - rep(i, 0, sz(s)) { - - if (skip[i]) continue; - - - - int mx = s[i] - '0'; - - int mx_pos = 0; - - rep(j, 1, 10) { - - if (i+j >= sz(s)) break; - - if (s[i+j] - '0' - j > mx) { - - //cout << i << "" "" << i+j << "" "" << s[i+j] - '0' - j << '\n'; - - mx = s[i+j] -'0' - j; - - mx_pos = j; - - } - - } - - - - char prev = s[i]; - - rep(j, 1, mx_pos+1) { - - if (i+j >= sz(s)) break; - - swap(s[i+j], prev); - - } - - - - s[i] = mx+'0'; - - } - - - - cout << s << '\n'; - - } - - - - return 0; - -} - -",2 -bhagwatsolunke007,2050D - Digital string maximization,c++20 ,297421946,297421575,"#include -using namespace std; -typedef long long int ll; - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s<> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; -typedef long long int ll; - -void solve() { - string s; cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s; -} - -int main() { - ll t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -tiansheng,2050D - Digital string maximization,c++23 ,299190064,299192090,"/** - * author: tiansheng - * created: 2024.12.30 15:53:00 IST - **/ -#include -#include ""debug.h"" -using namespace std; -#ifdef LOCAL -#include ""debug.h"" -#endif - -void solve() -{ - string s; - cin >> s; - int i,j; - for (int k = 0; k < s.length() + 1; k++) - { - if((s[k+1] - s[k]) > 1){ - i = k;j = k+1; - do - { - s[j]--; - // cout<<""s[j] ""< 0 && j > 0 && ((s[j] - s[i]) > 1))<= 0 && j >= 0 && ((s[j] - s[i]) > 1)); - - } - } - cout<> tt; - while (tt--) - { - solve(); - } - return 0; -}","/** - * author: tiansheng - * created: 2024.12.30 15:53:00 IST - **/ -#include -using namespace std; - -#ifdef LOCAL -#include ""debug.h"" -#endif - -void solve() -{ - string s; - cin >> s; - int i, j; - for (int k = 0; (k + 1) < s.length(); k++) - { - if ((s[k + 1] - s[k]) > 1) - { - i = k; - j = k + 1; - do - { - swap(s[i], --s[j]); - i--; j--; - } while (i >= 0 && j >= 0 && ((s[j] - s[i]) > 1)); - } - } - cout << s << endl; -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int tt; - cin >> tt; - while (tt--) - { - solve(); - } - return 0; -}",2 -mengxxyy,2050D - Digital string maximization,c++20 ,297092577,297091840,"#include -#include -#include -using namespace std; - -void solve() -{ - string s; - cin >> s; - int n = s.size(); - for (int i = 0; i < n; i++) - { - int k = i; - for (int j = i; j < n && j < i + 10; j++) - { - if (s[j] - j > s[k] - k) - { - k = j; - } - } - - while (k > i) - { - s[k]--; - swap(s[k - 1], s[k]); - k--; - } - } - - cout << s << ""\n""; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}","#include -#include -#include -using namespace std; - -void solve() -{ - string s; - cin >> s; - int n = s.size(); - for (int i = 0; i < n-1; i++) - { - int cur = s[i] - '0'; - vector steps(n, 0); - int step = 1; - int maxv = 0, maxind = -1; - for (int j = i + 1; j < n && j < i+10; j++) - { - steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step; - if (steps[j] > maxv && steps[j] > cur) - { - maxv = steps[j]; - maxind = j; - } - step++; - } - - int j; - for (j = (maxind == -1 ? -1 : maxind); j > i; j--) - { - swap(s[j], s[j - 1]); - } - - if (j != -1) - { - int t = s[j] - '0'; - t = steps[maxind]; - s[j] = t + '0'; - } - } - - cout << s << ""\n""; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}",1 -20071,2050D - Digital string maximization,c++17 ,306851187,306851387,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -int t,max1=numeric_limits::min(),a; - -char s[1000000]; - -int main(){ - - scanf(""%d"",&t); - - while (t--) - - { - - a=0; - - scanf(""%s"",s); - - for (int i = 0; i < strlen(s); i++) - - { - - for (int j = i; j < i+9; j++) - - { - - if ((s[j]-'0')-j+i > max1) - - { - - max1 = (s[j]-'0')-j+i; - - a = j; - - } - - - - } - - for (int b = a; b > i; b--) - - { - - s[b] = s[b-1]; - - } - - s[i] = '0'; - - - - - - - - printf(""%d"",max1); - - max1=numeric_limits::min(); - - } - - printf(""\n""); - - - - } - - - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using i64 = long long; - -int T, n; - -void solve() { - - string s; cin >> s; - - for (int i = 0; i < (int)s.size(); i ++) { - - int res = s[i], pos = i; - - for (int j = i + 1; j < min((int)s.size(), i + 11); j ++) - - if ((int)s[j] - (j - i) > res) res = (int)s[j] - (j - i), pos = j; - - for (int j = pos; j > i; j --) swap(s[j], s[j - 1]), s[j - 1] --; - - } - - cout << s << '\n'; - -} - -int main() { - - cin.tie(NULL) -> sync_with_stdio(false); - - cin >> T; - - while (T --) solve(); - - return 0; - -}",2 -suyogify,2050D - Digital string maximization,c++17 ,298043188,298043615,"#include - -using namespace std; - -int find(string &s, int r) -{ - int l = r; - while (l >= 0) - { - if (s[r] - s[l] > 1 || s[l] - s[r] > 1) - { - return l; - } - else - { - l--; - } - } - return l; -} - -void change(string &s, int r) -{ - int l = r; - while (l < s.length() - 1) - { - if (s[l + 1] - s[l] > 1) - { - char temp = s[l + 1]; - s[l + 1] = s[l]; - s[l] = temp - 1; - l++; - // cout << s << "" s from change"" << endl; - } - else - { - return; - } - } - return; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int r = s.size() - 1; - while (r >= 0) - { - if (s[r] == '0') - { - r--; - } - else - { - int k; - k = find(s, r); - // cout << k << endl; - if (r >= 0) - { - change(s, k); - } - r = k; - // cout << r << ""next"" << "" st "" << s << endl; - } - } - cout << s << endl; - } - return 0; -}","#include - -using namespace std; - -int find(string &s, int r) -{ - int l = r-1; - // cout << l << endl; - while (l >= 0) - { - if (s[r] - s[l] > 1 || s[l] - s[r] > 1) - { - return l; - } - else - { - l--; - r--; - } - } - return l; -} - -void change(string &s, int r) -{ - int l = r; - while (l < s.length() - 1) - { - if (s[l + 1] - s[l] > 1) - { - char temp = s[l + 1]; - s[l + 1] = s[l]; - s[l] = temp - 1; - l++; - // cout << s << "" s from change"" << endl; - } - else - { - return; - } - } - return; -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int r = s.size() - 1; - while (r >= 0) - { - if (s[r] == '0') - { - r--; - } - else - { - int k; - k = find(s, r); - // cout << k << endl; - if (k >= 0) - { - change(s, k); - } - r = k; - // cout << r << ""next"" << "" st "" << s << endl; - } - } - cout << s << endl; - } - return 0; -}",2 -bkifhr6,2050D - Digital string maximization,c++23 ,296848560,296753293,"#include -using namespace std; -int T, a[200001]; -char s[300000]; -int main(){ - scanf(""%d"", &T); - while(T--){ - scanf("" %s"", s + 1); - int n = (int)strlen(s + 1); - for(int i = 1; i <= n; ++i) - a[i] = s[i] - '0'; - for(int i = 1; i <= n; ++i){ - if(i == 1) - continue; - if(a[i] - a[i - 1] > 1){ - if(i == 2){ - --a[i]; - swap(a[i - 1], a[i]); - continue; - } - if(a[i] - a[i - 2] > 2){ - if(i == 3){ - a[i] -= 2; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - continue; - } - if(a[i] - a[i - 3] > 3){ - if(i == 4){ - a[i] -= 3; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - continue; - } - if(a[i] - a[i - 4] > 4){ - if(i == 5){ - a[i] -= 4; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - continue; - } - if(a[i] - a[i - 5] > 5){ - if(i == 6){ - a[i] -= 5; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - continue; - } - if(a[i] - a[i - 6] > 6){ - if(i == 7){ - a[i] -= 6; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - swap(a[i - 6], a[i - 5]); - continue; - } - if(a[i] - a[i - 7] > 7){ - if(i == 8){ - a[i] -= 7; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - swap(a[i - 6], a[i - 5]); - swap(a[i - 7], a[i - 6]); - continue; - } - if(a[i] - a[i - 8] > 8){ - a[i] -= 8; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - swap(a[i - 6], a[i - 5]); - swap(a[i - 7], a[i - 6]); - swap(a[i - 8], a[i - 7]); - continue; - } - else{ - a[i] -= 7; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - swap(a[i - 6], a[i - 5]); - swap(a[i - 7], a[i - 6]); - continue; - } - } - else{ - a[i] -= 6; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - swap(a[i - 6], a[i - 5]); - continue; - } - } - else{ - a[i] -= 5; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - swap(a[i - 5], a[i - 4]); - continue; - } - } - else{ - a[i] -= 4; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - swap(a[i - 4], a[i - 3]); - continue; - } - } - else{ - a[i] -= 3; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - swap(a[i - 3], a[i - 2]); - continue; - } - } - else{ - a[i] -= 2; - swap(a[i - 1], a[i]); - swap(a[i - 2], a[i - 1]); - continue; - } - } - else{ - --a[i]; - swap(a[i - 1], a[i]); - continue; - } - } - } - for(int i = 1; i <= n; ++i) - printf(""%d"", a[i]); - printf(""\n""); - } -}","#include -using namespace std; -typedef long long ll; -const ll N = 2e5 + 5; -string s; -ll t; -int main(){ - cin >> t; - while(t--){ - cin >> s; - for(int i = 0; i < s.size(); i++){ - ll maxx = 0, k = i; - for(int j = i + 1; j <= i + 10 && j < s.size(); j++){ - if((s[j] - '0') - j + i - (s[i] - '0') > maxx){ - maxx = (s[j] - '0') - j + i - (s[i] - '0'); - k = j; - } - } - swap(s[i], s[k]); - s[i] = s[i] - k + i; - } - cout << s << endl; - } - return 0; -}",1 -Pratham18,2050D - Digital string maximization,c++20 ,311431110,311425127,"#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -#define int long long - -typedef tree, rb_tree_tag,tree_order_statistics_node_update> ordered_set; - -signed main(){ - -int t; - -cin>>t; - -while(t--){ - -string n; - -cin>>n; - -vectora; - -for(int i=0;i(a[x-1]+('1'-'0')))&&(x>0)){ - -a[i]-=('1'-'0'); - -//cout< - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - -#define int long long - -typedef tree, rb_tree_tag,tree_order_statistics_node_update> ordered_set; - -// bool comp(int &a,int&b){ - -// if(a>b+1){ - -// a--; - -// return a>b; - -// } - -// } - -signed main(){ - -int t; - -cin>>t; - -while(t--){ - -int n; - -cin>>n; - -int x=n; - -vectora; - -if(x==0){ - -cout<<0<a[x-1]+1)&&(x>0)){ - -a[i]--; - -//cout< int(num[j - 1])): - temp = str(int(num[j]) - 1) - num[j] = num[j - 1] - num[j - 1] = temp - j -= 1 # Move backward to recheck the order - if j <= 0: # Prevent going out of bounds - break - print(''.join(num)) # Convert list back to string for output -","t = int(input()) -for _ in range(t): - num = input() - n = len(num) - ans = """" - for j in range(n-1): - max_el = j - for i in range(j+1, n): - # print(num) - # print(f""i: {i}, j: {j}"") - if(int(num[i]) == 0): continue - if((int(num[i]) - (i - j)) > int(num[max_el]) - (max_el - j)): - max_el = i - if(max_el != j): - num = num[:j]+str(int(num[max_el]) - (max_el - j))+num[j:] - # print(f""num: {num}"") - num = num[:max_el+1] + num[max_el+2:] - print(num)",1 -kagamiDisiki,2050D - Digital string maximization,java,315013419,315013184,"import java.math.*; - -import java.util.*; - - - -public class Main { - -static int N = (int)2e5 + 5; - -static int[] a = new int[N]; - -public static void main(String[] args) { - -Scanner sc = new Scanner(System.in); - -int T = sc.nextInt(); - -while(T-- > 0){ - -String s = sc.next(); - -int len = s.length(); - -for(int i = 1;i <= len;i++){ - -a[i] = (int)s.charAt(i - 1) - (int)'0'; - -} - -for(int i = 1;i <= len;i++){ - -int x = a[i], idx = i; - -int mx = x, id = -1; - -for(int j = i + 1;j <= len && j <= i + 8;j++){ - -if(a[j] - (j - i) > mx){ - -mx = a[j] - (j - i); - -idx = j; - -} - -} - -for(int j = idx - 1;j >= i;j--){ - -int t = a[j]; - -a[j] = a[j + 1] - 1; - -a[j + 1] = t; - -} - -} - -for(int i = 1;i <= len;i++){ - -System.out.print(a[i]); - -} - -System.out.println(); - -} - -sc.close(); - -} - -}","import java.math.*; - -import java.util.*; - - - -public class Main { - -static int N = (int)2e5 + 5; - -static int[] a = new int[N]; - -public static void main(String[] args) { - -Scanner sc = new Scanner(System.in); - -int T = sc.nextInt(); - -while(T-- > 0){ - -String s = sc.next(); - -int len = s.length(); - -for(int i = 1;i <= len;i++){ - -a[i] = (int)s.charAt(i - 1) - (int)'0'; - -} - -for(int i = 1;i <= len;i++){ - -int x = a[i], idx = i; - -int mx = 0, id = -1; - -for(int j = i + 1;j <= len && j <= i + 8;j++){ - -if(a[j] - (j - i) > mx){ - -mx = a[j] - (j - i); - -idx = j; - -} - -} - -for(int j = idx - 1;j >= i;j--){ - -int t = a[j]; - -a[j] = a[j + 1] - 1; - -a[j + 1] = t; - -} - -} - -for(int i = 1;i <= len;i++){ - -System.out.print(a[i]); - -} - -System.out.println(); - -} - -sc.close(); - -} - -}",1 -Infinity18,2050D - Digital string maximization,c++20 ,297644630,297644005,"#include -using namespace std; - -#define int long long -#define endl ""\n"" -#define vi vector -#define vvi vector> -#define vb vector -#define vvb vector> -#define vc vector -#define vvc vector> -#define pii pair -#define vpii vector> -#define pb push_back -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define alias cout << ""Alias"" << endl; -#define bob cout << ""Bob"" << endl; -const int MOD = 1e9+7; -const int INF = 1e18; - -void solve() { - string s; cin>>s; - int n=s.size(); - vi arr; - vi ans; - int c=0; - for(int i=0;i> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; - -#define int long long -#define endl ""\n"" -#define vi vector -#define vvi vector> -#define vb vector -#define vvb vector> -#define vc vector -#define vvc vector> -#define pii pair -#define vpii vector> -#define pb push_back -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define alias cout << ""Alias"" << endl; -#define bob cout << ""Bob"" << endl; -const int MOD = 1e9+7; -const int INF = 1e18; - -void solve() { - string s; cin>>s; - int n=s.size(); - vi arr; - vi ans; - int c=0; - for(int i=0;i> t; - while (t--) { - solve(); - } - return 0; -} -",1 -luckysx,2050D - Digital string maximization,c++17 ,296245941,296245557,"#include -#define memclear(a) memset(a,0,sizeof(a)) -using namespace std; -const int inf=0x3f3f3f3f; -using ll=long long; -int num[200050]; -void solve(string s){ - int n=s.length(); - memclear(num); - int i,j,maxn,maxi; - for(i=0;imaxn){ - maxn=num[j]-m; - maxi=j; - } - } - if(maxi!=i){ - for(int k=maxi;k>=i+1;k--){ - num[k]=num[k-1]; - } - num[i]=maxn; - } - } - for(int i=0;i>t; - while(t--){ - string s; - cin>>s; - solve(s); - } - return 0; -} -","#include -#define memclear(a) memset(a,0,sizeof(a)) -using namespace std; -const int inf=0x3f3f3f3f; -using ll=long long; -int num[20050]; -void solve(string s){ - int n=s.length(); - memclear(num); - int i,j,maxn,maxi; - for(i=0;imaxn){ - maxn=num[j]-m; - maxi=j; - } - } - if(maxi!=i){ - for(int k=maxi;k>=i+1;k--){ - num[k]=num[k-1]; - } - num[i]=maxn; - } - } - for(int i=0;i>t; - while(t--){ - string s; - cin>>s; - solve(s); - } - return 0; -} -",1 -Heisenberg_52#,2050D - Digital string maximization,c++20 ,296817300,296817866,"#include -using namespace std; -#define int long long -const int mod = 1e9 + 7; - - -void solution() { - string s;cin>>s; - int n=s.size(); - - for(int i=0;i=maxi){ - ind=i+j; - maxi=s[i+j]-'0'; - } - } - else{ - break; - } - } - char ch=s[ind]-(ind-i); - for(int j=ind;j>i;j--){ - s[j]=s[j-1]; - } - s[i]=ch; - } - - cout<> Testcases; - for (int i = 0; i < Testcases; i++) { - solution(); - } - return 0; -}","#include -using namespace std; -#define int long long -const int mod = 1e9 + 7; - - -void solution() { - string s;cin>>s; - int n=s.size(); - - for(int i=0;imaxi){ - ind=i+j; - maxi=s[i+j]-'0'-j; - } - } - else{ - break; - } - } - // cout<i;j--){ - s[j]=s[j-1]; - } - s[i]=ch; - } - - cout<> Testcases; - for (int i = 0; i < Testcases; i++) { - solution(); - } - return 0; -}",2 -Yagami_L_,2050D - Digital string maximization,c++17 ,298147258,298045613,"#include -#include -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int posi = 0; - while (s[posi] != '\0') - { - if (s[posi + 1] > s[posi] + 1) - { - char temp = s[posi]; - int tempo = s[posi + 1] - '0' - 1; - s[posi] = tempo + '0'; - s[posi + 1] = temp; - if (posi > 0) - { - int positemp = posi; - while (s[positemp] > s[positemp - 1] + 1) - { - char temp2 = s[positemp - 1]; - int tempo2 = s[positemp] - '0' - 1; - s[positemp - 1] = tempo2 + '0'; - s[positemp] = temp2; - positemp--; - if (positemp <= 0) - { - // posi++; - break; - } - } - } - } - posi++; - } - cout << s << endl; - } -}","#include -#include -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int posi = 0; - while (s[posi] != '\0') - { - if (s[posi + 1]>s[posi]+1 ) - { - char temp = s[posi]; - int tempo = s[posi + 1] - '0' - 1; - s[posi] = tempo + '0'; - s[posi + 1] = temp; - posi = 0; - continue; - } - posi++; - } - cout << s << endl; - } -}",1 -SatinWuker,2050D - Digital string maximization,python,297067271,297065020,"for _ in range(int(input())): - s = list(map(int, list(input()))) - n = len(s) - - - for i in range(1, n): - if s[i] == 0: - continue - for j in range(max(0, i - 9), i): - if s[j] < s[i] - (i - j): - new_head_value = s[i] - (i - j) - idx = i - 1 - while idx != j - 1: - s[idx], s[idx + 1] = s[idx + 1], s[idx] - idx -= 1 - s[j] = new_head_value - break - - - for i in range(n): - print(s[i], end='') - print()","for _ in range(int(input())): - s = list(map(int, list(input()))) - n = len(s) - prev_max = s[0] - prev_max_i = 0 - - for i in range(1, n): - if s[i] == 0: - continue - for j in range(prev_max_i, i): - if s[j] + (i - j) >= 9: - prev_max_i = j - prev_max = s[j] - if s[j] < s[i] - (i - j): - temp = s[i] - s.insert(j, s[i] - (i - j)) - s.pop(i + 1) - # prev_max_i = j - # prev_max = s[j] - break - - # print(s) - - for i in range(n): - print(s[i], end='') - print()",1 -Deep_Thought_Programs,2050D - Digital string maximization,python,303917798,303916885,"t= int(input()) -for k in range(t): - a=list(input()) - b= len(a) - for i in range(b): - t= min(i+9,b) - m= int(a[i]) - n=i - for j in range(i,t): - if (int(a[j])-j+i)> m: - m= int(a[j])-j+i - n= j - while n>i: - a[n],a[n-1]= a[n-1],str(int(a[n])-1) - n-=1 - print("""".join(a))","t= int(input()) -for k in range(t): - a=input() - b= len(a) - for i in range(b): - t= min(i+9,b) - m= int(a[i]) - n=i - for j in range(i,t): - if (int(a[j])-j+i)> m: - m= int(a[j])-j+i - n= j - a= a[0:i]+str(m)+a[i:n]+a[n+1:b] - print(a)",1 -sanchiitvijay,2050D - Digital string maximization,c++17 ,303469263,303490680,"#include - - - -using namespace std; - -using ll = long long; - -using ld = long double; - -#define mod 998244353 - - - - - -void solve(){ - - //code here - - string s; - - cin>>s; - - vector> v; - - for(int i = 0; ib.second; - - return a.first>b.first; - - }); - - - - for(int i = 0; i> t; - - - - while (t--){ - - // cout<<""-----------""< - - - -using namespace std; - -using ll = long long; - -using ld = long double; - -#define mod 998244353 - - - - - -void solve(){ - - //code here - - string s; cin >> s; - - for (int i = 0; i < s.size(); i++) { - - int tmp = s[i] - '0', pos = i; - - for (int j = i; j < min(i + 10, (int) s.size()); j++) { - - if (s[j] - '0' - (j - i) > tmp) { - - tmp = s[j] - '0' - (j - i); - - pos = j; - - } - - } - - while (pos > i) { - - swap(s[pos], s[pos - 1]); - - pos--; - - } - - s[i] = char(tmp + '0'); - - } - - cout << s; - - - - - - - - return ; - -} - - - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - - - // freopen(""input.txt"", ""r"", stdin); freopen(""output.txt"", ""w"", stdout); - - ll t = 1; - - cin >> t; - - - - while (t--){ - - // cout<<""-----------""<>t; while(t--) -#define hemant ios_base::sync_with_stdio(false); cin.tie(nullptr) -#define PI 3.141592653589793238 -#define mem0(x) memset(x,0,sizeof x) -#define mem1(x) memset(x,-1,sizeof x) -#define nl ""\n"" -#define yy cout<<""YES""<<""\n"" -#define nn cout<<""NO""<<""\n"" -#define vi vector -#define vll vector -#define vvi vector > -#define ff first -#define ss second -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -typedef unsigned long long ull; -typedef long double lld; - -ll modular_expo(long long x, unsigned ll y, int p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;} -vector sieve(ll n) {ll *arr = new ll[n + 1](); vector vect; for (ll i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (ll j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} -ll primefactorscount(ll n){vector v1=sieve(n);ll cnt=0;for(ll i=0;i void _print(pair p); -template void _print(vector v); -template void _print(deque v); -template void _print(set v); -template void _print(list v); -template void _print(map v); -template void _print(multimap v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(deque v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(list v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -bool isPower(ll x, ll y) -{ - long double res1 = log(y) / log(x); - return res1==floor(res1); -} - -void solve(){ - w(t){ - string s; - cin>>s; - int n=s.length(); - map > mp; - for(int i=0;i p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i + 1 < n){ - pair p2 = mp[i + 1]; - p2.first = x; - mp[i + 1] = p2; - mp[i] = p1; - exists =1; - } - } - } - else if( i == n-2 ){ - pair p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i - 1 >= 0){ - pair p2 = mp[i - 1]; - p2.second = y-1; - mp[i-1] = p2; - mp[i] = p1; - exists = 1; - } - } - } - else{ - pair p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i + 1 < n and i - 1 >=0){ - pair p2 = mp[i + 1]; - pair p3 = mp[i - 1]; - p2.first = x; - p3.second = y-1; - mp[i-1] = p3; - mp[i + 1] = p2; - mp[i] = p1; - exists = 1; - } - } - } - // debug(mp) - i++; - } - // debug(mp) - for(int i = 0; i < n; i++) { - if(i == n - 1) { - pair p = mp[i - 1]; // Use i - 1 to get the last pair - char ch1 = p.second + '0'; - cout << ch1; - } else { - char ch1 = mp[i].first + '0'; - cout << ch1; - } - } - cout<>t; while(t--) -#define hemant ios_base::sync_with_stdio(false); cin.tie(nullptr) -#define PI 3.141592653589793238 -#define mem0(x) memset(x,0,sizeof x) -#define mem1(x) memset(x,-1,sizeof x) -#define nl ""\n"" -#define yy cout<<""YES""<<""\n"" -#define nn cout<<""NO""<<""\n"" -#define vi vector -#define vll vector -#define vvi vector > -#define ff first -#define ss second -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; - -typedef unsigned long long ull; -typedef long double lld; - -ll modular_expo(long long x, unsigned ll y, int p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;} -vector sieve(ll n) {ll *arr = new ll[n + 1](); vector vect; for (ll i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (ll j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} -ll primefactorscount(ll n){vector v1=sieve(n);ll cnt=0;for(ll i=0;i void _print(pair p); -template void _print(vector v); -template void _print(deque v); -template void _print(set v); -template void _print(list v); -template void _print(map v); -template void _print(multimap v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(deque v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(list v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -bool isPower(ll x, ll y) -{ - long double res1 = log(y) / log(x); - return res1==floor(res1); -} - -void solve(){ - w(t){ - string s; - cin>>s; - int n=s.length(); - if (n==1){ - cout< > mp; - for(int i=0;i p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i + 1 < n){ - pair p2 = mp[i + 1]; - p2.first = x; - mp[i + 1] = p2; - mp[i] = p1; - exists =1; - } - } - } - else if( i == n-2 ){ - pair p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i - 1 >= 0){ - pair p2 = mp[i - 1]; - p2.second = y-1; - mp[i-1] = p2; - mp[i] = p1; - exists = 1; - } - } - } - else{ - pair p1 = mp[i]; - if (p1.first + 1 < p1.second){ - int x = p1.first; - int y = p1.second; - p1.first = y - 1; - p1.second = x; - if (i + 1 < n and i - 1 >=0){ - pair p2 = mp[i + 1]; - pair p3 = mp[i - 1]; - p2.first = x; - p3.second = y-1; - mp[i-1] = p3; - mp[i + 1] = p2; - mp[i] = p1; - exists = 1; - } - } - } - // debug(mp) - i++; - } - // debug(mp) - for(int i = 0; i < n; i++) { - if(i == n - 1) { - pair p = mp[i - 1]; // Use i - 1 to get the last pair - char ch1 = p.second + '0'; - cout << ch1; - } else { - char ch1 = mp[i].first + '0'; - cout << ch1; - } - } - cout< -using namespace std; - -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define fori(i, a, b) for(int i = a; i < b; ++i) -#define rfori(i, a, b) for(int i = a; i >= b; --i) -#define pb push_back -#define mp make_pair -#define all(v) v.begin(), v.end() -#define rall(v) v.rbegin(), v.rend() -#define f first -#define s second -#define clr(a) memset(a, 0, sizeof(a)) -#define set_mem(a, b) memset(a, b, sizeof(a)) -#define sz(v) (int)v.size() -#define umap unordered_map -#define uset unordered_set -#define pll pair -#define vpii vector -#define vpll vector -#define vvi vector -#define vvll vector -#define pq priority_queue -#define minpq(x) priority_queue, greater> - -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vll; -typedef unordered_map umii; -typedef unordered_set usi; - -void solve() -{ - string s; - cin >> s; - ll n = s.length(); - - - for(ll i=1;i0;j--){ - if(s[j]-1>s[j-1]){ - swap(--s[j],s[j-1]); - } - else break; - } - } - cout<> s; - // ll n = s.length(); - - // for (ll i = 0; i < n; i++) { - // string temp = s; - // ll maxi = LONG_MIN; - // ll idx = i; - - - // for (ll j = i + 1; j < n; j++) { - // if ((s[j] - '0'-(j-i)) > maxi-(idx-i) && idx>=0) { - // maxi = s[j] - '0'; - // idx = j; - // } - // } - - - // if (maxi - (idx-i)> (s[i] - '0')) { - - // char maxChar = s[idx]-(idx-i); - // for (ll j = idx; j > i; j--) { - // s[j] = s[j - 1]; - // } - // s[i] = maxChar; - // } - // } - - // cout << s << endl; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ll maxi = INT_MIN; - // int cnt = 1; - // vector> maxArr(n,{-1,cnt}); - - // for(int i=n-1;i>=0;i--){ - // if(maxi == s[i]-'0') cnt++; - // if(s[i]-'0'>maxi) maxi = s[i]-'0'; - - // maxArr[i].f = max(s[i]-'0',maxi); - // maxArr[i].s = cnt; - // } - // for(auto it:maxArr){ - // cout<> t; - while (t--) { - solve(); - } - - return 0; -}","#include -using namespace std; - -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define fori(i, a, b) for(int i = a; i < b; ++i) -#define rfori(i, a, b) for(int i = a; i >= b; --i) -#define pb push_back -#define mp make_pair -#define all(v) v.begin(), v.end() -#define rall(v) v.rbegin(), v.rend() -#define f first -#define s second -#define clr(a) memset(a, 0, sizeof(a)) -#define set_mem(a, b) memset(a, b, sizeof(a)) -#define sz(v) (int)v.size() -#define umap unordered_map -#define uset unordered_set -#define pll pair -#define vpii vector -#define vpll vector -#define vvi vector -#define vvll vector -#define pq priority_queue -#define minpq(x) priority_queue, greater> - -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vll; -typedef unordered_map umii; -typedef unordered_set usi; - -void solve() -{ - string s; - cin >> s; - ll n = s.length(); - - for (ll i = 0; i < n; i++) { - string temp = s; - ll maxi = LONG_MIN; - ll idx = i; - - - for (ll j = i + 1; j < n; j++) { - if ((s[j] - '0'-(j-i)) > maxi-(idx-i) && idx>=0) { - maxi = s[j] - '0'; - idx = j; - } - } - - - if (maxi - (idx-i)> (s[i] - '0')) { - - char maxChar = s[idx]-(idx-i); - for (ll j = idx; j > i; j--) { - s[j] = s[j - 1]; - } - s[i] = maxChar; - } - } - - cout << s << endl; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ll maxi = INT_MIN; - // int cnt = 1; - // vector> maxArr(n,{-1,cnt}); - - // for(int i=n-1;i>=0;i--){ - // if(maxi == s[i]-'0') cnt++; - // if(s[i]-'0'>maxi) maxi = s[i]-'0'; - - // maxArr[i].f = max(s[i]-'0',maxi); - // maxArr[i].s = cnt; - // } - // for(auto it:maxArr){ - // cout<> t; - while (t--) { - solve(); - } - - return 0; -}",1 -IchhabeHunger,2050D - Digital string maximization,c++17 ,310766526,310771424,"#include - -using namespace std; - - - -int32_t main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int tc; - -cin>>tc; - -string s; - -while(tc--){ - -cin>>s; - -string a = """"; - -int mx, itr; - -while(s.size()) { - -mx = -1; - -for (int i = 0; i < 10; i++) { - -if ((s[i]-'0')-i>mx) { - -mx = (s[i]-'0') - i; - -itr = i; - -} - -} - -a = a + to_string(mx); - -s.erase(s.begin()+ itr); - -} - -cout< - -using namespace std; - - - -int32_t main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int tc; - -cin>>tc; - -string s; - -while(tc--){ - -cin>>s; - -int a; - -for (int i = 1; i < int(s.size()); i++) { - -for (int j = i; j >0 ; j--) { - -if (s[j]-1>s[j-1]) { - -a = s[j]-1; - -s[j] = s[j-1]; - -s[j-1] = a; - -}else break; - -} - -} - -cout< -#define ll long long -#define vll vector -#define vi vector -#define vstr vector -#define str string -#define f(i, n) for (long long i = 0; i < n; i++) -#define fi(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define all(v) (v).begin(),(v).end() -#define YES cout << ""YES""<<'\n' -#define NO cout << ""NO""<<'\n' -#define Yes cout << ""Yes""<<'\n' -#define No cout << ""No""<<'\n' -#define vpll vector> -#define fr(i,a,b) for(ll i=a;i<=b;i++) -#define fr2(i,a,b) for(ll i=a;i>=b;i--) -#define F first -#define S second -int mod = 1e9+7; -using namespace std; - -void bankai() -{ - ios::sync_with_stdio(0); - cin.tie(0); -} -ll gcd(ll a, ll b) -{ - if (b == 0)return a; - return gcd(b, a % b); -} -ll lcm(ll a, ll b) -{ - return (a / gcd(a, b) * b); -} -bool prime(ll n) -{ - if (n <= 1)return false; - if (n <= 3)return true; - if (n % 2 == 0)return false; - for (ll i = 3; i * i <= n; i += 2) - { - if (n % i == 0)return false; - } - return true; -} -bool sortbysec(const pair &a, const pair &b) -{ - return (a.second > b.second); -} -bool is_palindrome(str s) -{ - ll mid = s.size()/2; - ll n = s.size(); - f(i, mid) - { - if(s[i] != s[n - i - 1])return false; - } - return true; -} -long long calculateFactorial(ll n) -{ - if (n == 0 || n == 1) - { - return 1; - } - return n * calculateFactorial(n - 1); -} -ll Digit_Sum(int a) -{ - int sum = 0; - for (int i = a; i > 0; i /= 10) - { - sum += i % 10; - } - return sum; -} -int nth_sqr_func(ll mid, ll n) -{ - ll ans = 1; - while(n>0) - { - ans=ans*mid; - n--; - } - return ans; -} -sets; -int NOD(int n) -{ - for(ll i = 1 ; i <= sqrt(n) ; i++) - { - if(n%i==0) - { - ll x = i; - ll y = n/i; - s.insert(x); - s.insert(y); - } - } -} -ll ans = 0; -void prime_fact(ll n) -{ - ans = 0; - for(ll i = 2 ; i*i <= n ; i++) - { - if(n%i==0) - { - ans++; - //ll cnt = 0; - while(n%i==0) - { - //cnt++; - n/=i; - } - - //cout << i << "" "";//<< ""^"" << cnt << "" ""; - } - - } - if(n>1)ans++; - cout << ans << '\n'; - // else cout << '\n'; -} - - -//-------------------------------------------------// -// main code here // -//-------------------------------------------------// - - -void solve() -{ - str s; - cin >> s; - int n = s.size(); - - for (int i = 1; i < n; ++i) - { - for (int j = i; j > 0 ; --j) - { - if(s[j] - s[j - 1] > 1) - { - s[j]--; - swap(s[j], s[j - 1]); - } - } - } - - cout << s << '\n'; -} - - - - -int main() -{ - bankai(); - - int t; - cin >> t; - while(t--) - { - solve(); - } - return 0; -} -//4 7 -//1 2 5 9 - -//6 -// 92 82 21 16 18 95 - - -","#include -#define ll long long -#define vll vector -#define vi vector -#define vstr vector -#define str string -#define f(i, n) for (long long i = 0; i < n; i++) -#define fi(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define all(v) (v).begin(),(v).end() -#define YES cout << ""YES""<<'\n' -#define NO cout << ""NO""<<'\n' -#define Yes cout << ""Yes""<<'\n' -#define No cout << ""No""<<'\n' -#define vpll vector> -#define fr(i,a,b) for(ll i=a;i<=b;i++) -#define fr2(i,a,b) for(ll i=a;i>=b;i--) -#define F first -#define S second -int mod = 1e9+7; -using namespace std; - -void bankai() -{ - ios::sync_with_stdio(0); - cin.tie(0); -} -ll gcd(ll a, ll b) -{ - if (b == 0)return a; - return gcd(b, a % b); -} -ll lcm(ll a, ll b) -{ - return (a / gcd(a, b) * b); -} -bool prime(ll n) -{ - if (n <= 1)return false; - if (n <= 3)return true; - if (n % 2 == 0)return false; - for (ll i = 3; i * i <= n; i += 2) - { - if (n % i == 0)return false; - } - return true; -} -bool sortbysec(const pair &a, const pair &b) -{ - return (a.second > b.second); -} -bool is_palindrome(str s) -{ - ll mid = s.size()/2; - ll n = s.size(); - f(i, mid) - { - if(s[i] != s[n - i - 1])return false; - } - return true; -} -long long calculateFactorial(ll n) -{ - if (n == 0 || n == 1) - { - return 1; - } - return n * calculateFactorial(n - 1); -} -ll Digit_Sum(int a) -{ - int sum = 0; - for (int i = a; i > 0; i /= 10) - { - sum += i % 10; - } - return sum; -} -int nth_sqr_func(ll mid, ll n) -{ - ll ans = 1; - while(n>0) - { - ans=ans*mid; - n--; - } - return ans; -} -sets; -int NOD(int n) -{ - for(ll i = 1 ; i <= sqrt(n) ; i++) - { - if(n%i==0) - { - ll x = i; - ll y = n/i; - s.insert(x); - s.insert(y); - } - } -} -ll ans = 0; -void prime_fact(ll n) -{ - ans = 0; - for(ll i = 2 ; i*i <= n ; i++) - { - if(n%i==0) - { - ans++; - //ll cnt = 0; - while(n%i==0) - { - //cnt++; - n/=i; - } - - //cout << i << "" "";//<< ""^"" << cnt << "" ""; - } - - } - if(n>1)ans++; - cout << ans << '\n'; - // else cout << '\n'; -} - - -//-------------------------------------------------// -// main code here // -//-------------------------------------------------// - - -void solve() -{ - str s; - cin >> s; - int n = s.size(); - - for (int i = 1; i < n; ++i) - { - for (int j = i; j > 0 && s[j] - s[j - 1] > 1; --j) - { - s[j]--; - swap(s[j], s[j - 1]); - } - } - - cout << s << '\n'; -} - - - - -int main() -{ - bankai(); - - int t; - cin >> t; - while(t--) - { - solve(); - } - return 0; -} -//4 7 -//1 2 5 9 - -//6 -// 92 82 21 16 18 95 - - -",2 -Arpit.1,2050D - Digital string maximization,c++17 ,298504981,298504328,"#include -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - string s; - cin >> s; - for (int i = 0; i < s.size(); i++) { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int)s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s << '\n'; - } - - return 0; -} -","#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - string s; - cin>>s; - string ans; - int cnt=0; - while(ans.size()!=s.size()){ - int maxi=0; - int index; - for(int i=cnt;imaxi){ - maxi=((s[i]-'0')-(i-cnt)); - index=i; - } - } - while(index>cnt){ - swap(s[index],s[index-1]); - index--; - } - ans=ans+to_string(maxi); - cnt++; - } - cout< -using namespace std; - -#define ll long long -#define ld long double -//#define node pair< ll , pair > - - - -ll mod = 1000000007 , sz = 1e6 + 10; -bool sortBF(pair a , pair b){return a.first>b.first;} -bool sortdec(ll a,ll b){return a >= b ;} - -///---------------------------------------------------------------------------- - -int lg (ll x){ - return __builtin_clzll(1) - __builtin_clzll(x); -} - -///---------------------------------------------------------------------------- - -ll fPower(ll x, ll y) -{ - x %= mod; - y %= mod; - ll res = 1; - while (y > 0) { - if (y % 2 == 1) - res = (res * x)%mod; - y = y >> 1; - x = (x * x); - x %= mod; - } - return (res%mod); -} - -///---------------------------------------------------------------------------- - - - -int main() { - cin.tie(0); cout.tie(0); - ios::sync_with_stdio(0); - //freopen(""tictactoe.in"" , ""r"" , stdin); - //freopen(""output.txt"" , ""w"" , stdout); - int tt = 1 , tc = 1; - cin>>tt; - while(tt--){ - string s;cin>>s; - int n = s.size(); - int arr[n]; - for (int i = 0 ; i < n ; i++)arr[i] = (s[i] - '0'); - setidx; - for (int i = 0 ; i < min(9 , n) ; i++)idx.insert(i); - int ans [n]; - for (int i = 0 ; i < n ; i++){ - int j = 0 , bestIdx = 0 , bestVal = -1; - for (auto v : idx){ - if (arr[v] - j > bestVal){ - bestVal = arr[v] - j; - bestIdx = v; - } - j++; - } - idx.erase(bestIdx); - ans[i] = bestVal; - if (i + 9 < n)idx.insert(i + 9); - } - for (auto i : ans)cout<>memo(1001 , vector(1001 , -1)); - -ll nCr(ll n, ll r){ - if (r > n) - return 0; - if (r == 0 || r == n) - return 1; - if (memo[n][r] > -1)return memo[n][r]; - memo[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r); - return memo[n][r]; -} -*/ -","#include -using namespace std; - -#define ll long long -#define ld long double -//#define node pair< ll , pair > - - - -ll mod = 1000000007 , sz = 1e6 + 10; -bool sortBF(pair a , pair b){return a.first>b.first;} -bool sortdec(ll a,ll b){return a >= b ;} - -///---------------------------------------------------------------------------- - -int lg (ll x){ - return __builtin_clzll(1) - __builtin_clzll(x); -} - -///---------------------------------------------------------------------------- - -ll fPower(ll x, ll y) -{ - x %= mod; - y %= mod; - ll res = 1; - while (y > 0) { - if (y % 2 == 1) - res = (res * x)%mod; - y = y >> 1; - x = (x * x); - x %= mod; - } - return (res%mod); -} - -///---------------------------------------------------------------------------- - - - -int main() { - cin.tie(0); cout.tie(0); - ios::sync_with_stdio(0); - //freopen(""tictactoe.in"" , ""r"" , stdin); - //freopen(""output.txt"" , ""w"" , stdout); - int tt = 1 , tc = 1; - cin>>tt; - while(tt--){ - string s;cin>>s; - int n = s.size(); - int arr[n]; - for (int i = 0 ; i < n ; i++)arr[i] = (s[i] - '0'); - setidx; - for (int i = 0 ; i < min(9 , n) ; i++)idx.insert(i); - int ans [n]; - for (int i = 0 ; i < n ; i++){ - int j = 0 , bestIdx = 0 , bestVal = 0; - for (auto v : idx){ - if (arr[v] - j > bestVal){ - bestVal = arr[v] - j; - bestIdx = v; - } - j++; - } - idx.erase(bestIdx); - ans[i] = bestVal; - if (i + 9 < n)idx.insert(i + 9); - } - for (auto i : ans)cout<>memo(1001 , vector(1001 , -1)); - -ll nCr(ll n, ll r){ - if (r > n) - return 0; - if (r == 0 || r == n) - return 1; - if (memo[n][r] > -1)return memo[n][r]; - memo[n][r] = nCr(n - 1, r - 1) + nCr(n - 1, r); - return memo[n][r]; -} -*/ -",1 -star.light,2050D - Digital string maximization,c++17 ,311021623,311022189,"//trying :-} - - - - - -// (?????€?€?????? -// ~ ?? ~ - - - - - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long; - - - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define f(i, a, b) for (int i = a; i < b; ++i) - -#define pb push_back - - - - - -void solve() { - -string s; - -cin>>s; - -int n=s.length(); - -vector a(n); - -f(i,0,n) a[i]=s[i]-'0'; - - - -f(i,0,n){ - -int k=i; - -f(j,i,n){ - -if(a[k]-ki){ - -a[k]-=1; - -int t=a[k]; - -a[k]=a[k-1]; - -a[k-1]=t; - -k--; - -} - -} - -f(i,0,n) cout<> t; - -while (t--) solve(); - - - -return 0; - -} - - - - - -// :-","//trying :-} - - - - - -// (?????€?€?????? -// ~ ?? ~ - - - - - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -using ll = long long; - - - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); - -#define f(i, a, b) for (int i = a; i < b; ++i) - -#define pb push_back - - - - - -void solve() { - -string a; - -cin>>a; - -int n=a.size(); - - - - - - - -f(i,0,n){ - -int k=i; - -f(j,i,min(n,i+10)){ - -if(a[k]-ki){ - -a[k]-=1; - -char t=a[k]; - -a[k]=a[k-1]; - -a[k-1]=t; - -k--; - -} - -} - -f(i,0,n) cout<> t; - -while (t--) solve(); - - - -return 0; - -} - - - - - -// :-",2 -Shiki0908,2050D - Digital string maximization,c++20 ,297055976,297055788,"#include -using namespace std; -#define ll long long -const int MAXN=1e6+7; -int n,t,m; -string b; -ll a[MAXN]; -int main() -{ - - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - cin>>t; - while(t--) - { - cin>>b; - n=b.size(); - b=' '+b; - for(int i=1;i<=n;i++) a[i]=b[i]-'0'; - for(int nowl=1;nowl<=n;nowl++) - { - int maxl=0,max_id=-1; - for(int i=nowl;i<=min(n,nowl+10);i++) - { - int sss=a[i]-(i-nowl); - // if(sss<0) break; - if(sss>maxl) maxl=sss,max_id=i; - } - for(int i=max_id-1;i>=nowl;i--) swap(a[i],a[i+1]); - a[nowl]=maxl; - } - for(int i=1;i<=n;i++) cout< -using namespace std; -#define ll long long -const int MAXN=1e6+7; -int n,t,m; -string b; -ll a[MAXN]; -int main() -{ - - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - cin>>t; - while(t--) - { - cin>>b; - n=b.size(); - b=' '+b; - for(int i=1;i<=n;i++) a[i]=b[i]-'0'; - for(int nowl=1;nowl<=n;nowl++) - { - int maxl=0,max_id=-1; - for(int i=nowl;i<=n;i++) - { - int sss=a[i]-(i-nowl); - if(sss<0) break; - if(sss>maxl) maxl=sss,max_id=i; - } - for(int i=max_id-1;i>=nowl;i--) swap(a[i],a[i+1]); - a[nowl]=maxl; - } - for(int i=1;i<=n;i++) cout< -using namespace std; -#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define f first -#define s second -int32_t main() -{ - fast_io - int t; - cin>>t; - while(t--) - { - string a; - cin>>a; - int n=a.size(); - for(int i=0;ia[i] && a[j]-(j-i)>mx) - { - mx=a[j]-(j-i); - ij=j; - } - j--; - } - if(ij!=i){a[ij]-=(ij-i); - swap(a[ij], a[i]);} - } - cout< -using namespace std; -#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define f first -#define s second -int32_t main() -{ - fast_io - int t; - cin>>t; - while(t--) - { - string a; - cin>>a; - int n=a.size(); - for(int i=0;ia[i] && a[j]-(j-i)>=mx) - { - mx=a[j]-(j-i); - ij=j; - } - j--; - } - if(ij!=i) - { - while(1) - { - if(ij==i)break; - a[ij]--; - swap(a[ij-1], a[ij]); - ij--; - } - } - } - cout< -using namespace std; -int main () { - int t; cin >> t; - while (t--) { - string s; - cin >> s; - int n = s.size(); - int a[n]; - for (int i = 0; i < n; i++) { - a[i] = s[i] - '0' - i; - } - for (int i = 0; i < n; i++) { - int m = a[i], im = i; - for (int j = i; j < n and j < i + 10; j++) { - if (a[j] > m) { - im = j, m = a[j]; - } - } - int t, t1 = m + 1; - for (int j = i; j <= im; j++) { - t = a[j]; - a[j] = t1 - 1; - t1 = t; - } - } - for (int i = 0; i < n; i++) - cout << a[i] + i; - cout << endl; - } - return 0; -} -","#include -using namespace std; -int main () { - int t; cin >> t; - while (t--) { - string s; - cin >> s; - int n = s.size(); - int a[n]; - for (int i = 0; i < n; i++) { - a[i] = s[i] - '0' - i; - } - for (int i = 0; i < n; i++) { - int m = a[i], im = i; - for (int j = i + 1; j < n; j++) { - if (a[j] > m) { - im = j, m = a[j]; - } - } - int t, t1 = m + 1; - for (int j = i; j <= im; j++) { - t = a[j]; - a[j] = t1 - 1; - t1 = t; - } - } - for (int i = 0; i < n; i++) - cout << a[i] + i; - cout << endl; - } - return 0; -} -",1 -VimoSl#,2050D - Digital string maximization,c++17 ,296400283,296398925,"#include -using namespace std; - -#define out(x) #x << "" = "" << x << "" "" -#ifndef LOCAL -#define endl ""\n"" -#define cerr \ - if (false) cerr -#define stdio(true) stdio(false) -#endif - -const int MAX_N = 1e5 + 10; -const int INF = 1e9 + 10; - -void solve() { - string x; - cin >> x; - - for (int i = 1; i < x.size(); i++) { - int prv = 0; - while (i - prv - 1 >= 0 && x[i - prv] != '0' && x[i - prv] - 1 > x[i - prv - 1]) { - x[i - prv] -= 1; - swap(x[i - prv], x[i - prv - 1]); - prv++; - } - } - - cout << x << endl; -} - -int main() { - ios_base::sync_with_stdio(true); - cin.tie(NULL); - cout.tie(NULL); - - int t; - cin >> t; - - while (t--) { - solve(); - } - - return 0; -}","#include -using namespace std; - -#define out(x) #x << "" = "" << x << "" "" -#ifndef LOCAL -#define endl ""\n"" -#define cerr \ - if (false) cerr -#define stdio(true) stdio(false) -#endif - -const int MAX_N = 1e5 + 10; -const int INF = 1e9 + 10; - -bool isBigger(const string& a, const string& b) { - if (a.size() > b.size()) return true; - if (a.size() < b.size()) return false; - - return a > b; -} - -void solve() { - string x; - cin >> x; - - int currentDigit = 1; - - while (currentDigit < x.size()) { - if (currentDigit < 1) currentDigit = 1; - if (x[currentDigit] == '0') { - currentDigit++; - continue; - } - - string b = x; - swap(b[currentDigit], b[currentDigit - 1]); - b[currentDigit - 1]--; - - if (b > x) { - swap(x[currentDigit], x[currentDigit - 1]); - x[currentDigit - 1]--; - currentDigit -= 2; - } - - currentDigit++; - } - - cout << x << endl; -} - -int main() { - ios_base::sync_with_stdio(true); - cin.tie(NULL); - cout.tie(NULL); - - int t; - cin >> t; - - while (t--) { - solve(); - } - - return 0; -}",1 -fREaK092,2050D - Digital string maximization,c++23 ,299053816,299054107,"#include - -using namespace std; - -#define cin(v) for (auto& i : v) cin >> i; -#define cout(v) for (auto& i : v) cout << i << "" ""; cout << endl; -#define endl ""\n"" -#define aint(a) a.begin(), a.end() -#define int long long -const int MOD = 1000000007; - -void myprog(); - -int32_t main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - while (t-- > 0) - myprog(); - return 0; -} - - -void myprog(){ - string s; - cin >> s; - - int n = s.size(); - for(int i = 1; i < n; i++){ - for(int j = i; j >= 1; j--){ - if(s[j] > s[j - 1] + 1){ - swap(s[j], s[j - 1]); - s[j - 1]--; - //cout << s << "" ""; - } - } - } - - cout << s << endl; -}","#include - -using namespace std; - -#define cin(v) for (auto& i : v) cin >> i; -#define cout(v) for (auto& i : v) cout << i << "" ""; cout << endl; -#define endl ""\n"" -#define aint(a) a.begin(), a.end() -#define int long long -const int MOD = 1000000007; - -void myprog(); - -int32_t main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - while (t-- > 0) - myprog(); - return 0; -} - - -void myprog(){ - string s; - cin >> s; - - int n = s.size(); - for(int i = 1; i < n; i++){ - for(int j = i; j >= 1; j--){ - if(s[j] > s[j - 1] + 1){ - swap(s[j], s[j - 1]); - s[j - 1]--; - //cout << s << "" ""; - } - else{ - break; - } - } - } - - cout << s << endl; -}",2 -IchhabeHunger,2050D - Digital string maximization,c++17 ,310771424,310767311,"#include - -using namespace std; - - - -int32_t main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int tc; - -cin>>tc; - -string s; - -while(tc--){ - -cin>>s; - -int a; - -for (int i = 1; i < int(s.size()); i++) { - -for (int j = i; j >0 ; j--) { - -if (s[j]-1>s[j-1]) { - -a = s[j]-1; - -s[j] = s[j-1]; - -s[j-1] = a; - -}else break; - -} - -} - -cout< - -using namespace std; - - - -int32_t main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int tc; - -cin>>tc; - -string s; - -while(tc--){ - -cin>>s; - -string a = """"; - -int mx, itr; - -while(s.size()) { - -mx = -1; - -for (int i = 0; i < 9; i++) { - -if ((s[i]-'0')-i>mx) { - -mx = (s[i]-'0') - i; - -itr = i; - -if (mx>9-i-1) break; - -} - -} - -a = a + to_string(mx); - -s.erase(s.begin()+ itr); - -} - -cout< -using namespace std; - -void solve() -{ - string s; - cin >> s; - int n = s.size(); - for (int i = 0; i < n; i++) - { - int best = s[i] - '0', pos = i; - for (int j = i; j < min(i + 10, (int)s.size()); j++) { - if (s[j] - '0' - (j - i) > best) { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) - { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s<> t; - while (t--) - { - solve(); - } - -}","#include -using namespace std; - -void solve() -{ - string s; - cin >> s; - int n = s.size(),j; - for (int i = 0; i < n; i++) - { - int best = s[i] - '0', pos = i; - for ( j = i; j < min(i + 10, n);j++); - { - if (s[j] - '0' - (j - i) > best) - { - best = s[j] - '0' - (j - i); - pos = j; - } - } - while (pos > i) - { - swap(s[pos], s[pos - 1]); - pos--; - } - s[i] = char(best + '0'); - } - cout << s<> t; - while (t--) - { - solve(); - } - -}",1 -Ankush_Ankush,2050D - Digital string maximization,c++17 ,303438184,303437765,"#include - -using namespace std; - -#define gc getchar_unlocked - -#define fo(i, n) for (long long i = 0; i < n; i++) - -#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) - -#define ll long long - -#define deb(x) cout << #x << ""="" << x << endl - -#define pb push_back - -#define mp make_pair - -#define F first - -#define S second - -#define all(x) x.begin(), x.end() - -#define clr(x) memset(x, false, sizeof(x)) - -#define sortall(x) sort(all(x)) - -#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) - -#define PI 3.1415926535897932384626 - -#define mod 1000000007 - -typedef pair pii; - -typedef pair pl; - -typedef vector vi; - -typedef vector vl; - -typedef vector vpii; - -typedef vector vpl; - -typedef vector vvi; - -typedef vector vvl; - -int main() - -{ - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin >> t; - - while (t--) - - { - - //write code here - - string s; - - cin>>s; - - int n=s.length(); - - vectordigit(n); - - for(int i=0;i=1 && digit[j]>0 && digit[j]>digit[j-1]+1 ){ - - swap(digit[j],digit[j-1]); - - digit[j-1]--; - - if(j>1) j--; - - else break; - - } - - } - - string ans=""""; - - for(int i=0;i - -using namespace std; - -#define gc getchar_unlocked - -#define fo(i, n) for (int i = 0; i < n; i++) - -#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) - -#define ll long long - -#define deb(x) cout << #x << ""="" << x << endl - -#define pb push_back - -#define mp make_pair - -#define F first - -#define S second - -#define all(x) x.begin(), x.end() - -#define clr(x) memset(x, false, sizeof(x)) - -#define sortall(x) sort(all(x)) - -#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) - -#define PI 3.1415926535897932384626 - -#define mod 1000000007 - -typedef pair pii; - -typedef pair pl; - -typedef vector vi; - -typedef vector vl; - -typedef vector vpii; - -typedef vector vpl; - -typedef vector vvi; - -typedef vector vvl; - -int find(vi &arr,int maxi){ - - int n=arr.size(); - - for(int i=n-1;i>=1;i--){ - - if(arr[i]==maxi){ - - return i; - - } - - } - - return -1; - -} - -int main() - -{ - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin >> t; - - while (t--) - - { - - //write code here - - string s; - - string ans; - - cin>>s; - - int n=s.length(); - - vi arr(n); - - fo(i,n){ - - - - } - - fo(i,n-1){ - - int maxi=*max_element(arr.begin()+1,arr.end()); - - // cout< - -#include - - - -int main() { - -std::ios_base::sync_with_stdio(false); - -std::cin.tie(nullptr); - - - -int t; - -std::cin >> t; - - - -while (t--) { - -std::string s; - -std::cin >> s; - - - -bool improved = true; - -while (improved) { - -improved = false; - - - -for (int i = 1; i < s.size(); i++) { - -if (s[i] == '0') continue; - - - -for (int j = i-1; j >= 0; j--) { - -std::string temp = s; - -temp[i]--; - -std::swap(temp[i], temp[j]); - - - -if (temp > s) { - -s = temp; - -improved = true; - -goto found_improvement; - -} - -} - -} - -found_improvement:; - -} - - - -std::cout << s << ""\n""; - -} - - - -return 0; - -}","#include - -using namespace std; - - - -#define fastio ios::sync_with_stdio(0);cin.tie(0) - - - -int main() - -{ - -fastio; - -long long t,n,i,j; - -string s; - -char cur; - -cin>>t; - -while(t--) - -{ - -cin>>s; - -n=s.size(); - -for(i=1;i=0;j--) - -{ - -if(cur<=s[j]+1) - -break; - -s[j+1]=s[j]; - -s[j]=(char)(cur-1); - -cur--; - -if(cur=='0') - -break; - -} - -} - -cout< -using namespace std; -#define ll long long -#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cerr.rdbuf(cout.rdbuf()); -#define f(i,a,b) for (ll (i)=(a); (i)<(b); (i)++) -#define rf(i,a,b) for (ll (i)=(a); (i)>=(b); (i)--) -#define vll vector -#define vvll vector -#define in(n) ll n; cin>>n; -#define sin(s) string (s); cin>>(s); -#define vin(v,n) vll (v)(n); f(i,0,n)cin>>(v)[i]; -#define all(v) (v).begin(),(v).end() -#define rall(v) (v).rbegin(),(v).rend() -#define sort(v) sort(all(v)); -#define rsort(v) sort(v) reverse(all(v)); -#define pYES cout<<""YES\n""; -#define pNO cout<<""NO\n""; -const ll mod = 1000000007; - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x << "" = ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -template -void _print(T x) { cerr << x; } -template -void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "", ""; _print(p.second); cerr << ""}""; } -template -void _print(vector v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } -template -void _print(set s) { cerr << ""{ ""; for (T i : s) { _print(i); cerr << "" ""; } cerr << ""}""; } -template -void _print(map m) { cerr << ""{ ""; for (auto i : m) { _print(i); cerr << "" ""; } cerr << ""}""; } -/* *********************Template ends here************** */ - - -void solve() { - sin(s) - ll n=s.length(); - f(i,0,n){ - // now check from i+1 to i+10 - ll bst=s[i]-'0'; - ll bstidx=i; - f(j,i+1,min(i+10,n)){ - if (s[j]-'0'-(j-i)>bst){ - bst=s[j]-'0'-(j-i); - bstidx=j; - } - } - while(bstidx>i){ - s[bstidx]--; - swap(s[bstidx],s[bstidx-1]); - bstidx--; - } - } - cout<> t; - while(t--) solve(); -}","#include -using namespace std; -#define ll long long -#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cerr.rdbuf(cout.rdbuf()); -#define f(i,a,b) for (ll (i)=(a); (i)<(b); (i)++) -#define rf(i,a,b) for (ll (i)=(a); (i)>=(b); (i)--) -#define vll vector -#define vvll vector -#define in(n) ll n; cin>>n; -#define sin(s) string (s); cin>>(s); -#define vin(v,n) vll (v)(n); f(i,0,n)cin>>(v)[i]; -#define all(v) (v).begin(),(v).end() -#define rall(v) (v).rbegin(),(v).rend() -#define sort(v) sort(all(v)); -#define rsort(v) sort(v) reverse(all(v)); -#define pYES cout<<""YES\n""; -#define pNO cout<<""NO\n""; -const ll mod = 1000000007; - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x << "" = ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -template -void _print(T x) { cerr << x; } -template -void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "", ""; _print(p.second); cerr << ""}""; } -template -void _print(vector v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } -template -void _print(set s) { cerr << ""{ ""; for (T i : s) { _print(i); cerr << "" ""; } cerr << ""}""; } -template -void _print(map m) { cerr << ""{ ""; for (auto i : m) { _print(i); cerr << "" ""; } cerr << ""}""; } -/* *********************Template ends here************** */ - - -void solve() { - sin(s) - ll n=s.length(); - f(k,0,10){ - rf(i,n-1,1){ - ll l=i-1; - ll r=i; - while(l>=0 && s[r]-s[l]>1){ - s[r]--; - swap(s[l],s[r]); - l--; r--; - } - - } - } - cout<> t; - while(t--) solve(); -}",1 -sun_jae,2050D - Digital string maximization,c++20 ,298517048,298517161,"#include -using namespace std; - -#define INF 100000000 -#define ll long long int - - - -int main(){ - int t; cin>>t; - while(t--){ - string s; - cin>>s; - int n=s.size(); - vectora; - for(int i=0;i=0 and a[j]-(j-i)>mx){ - mx= a[j]-(j-i); - indx=j; - } - } - while(indx>i){ - a[indx]--; - swap(a[indx],a[indx-1]); - indx--; - } - } - for(int i=0;i -using namespace std; - -#define INF 100000000 -#define ll long long int - - - -int main(){ - int t; cin>>t; - while(t--){ - string s; - cin>>s; - int n=s.size(); - vectora; - for(int i=0;i=0 and a[j]-(j-i)>mx){ - mx= a[j]-(j-i); - indx=j; - } - } - while(indx>i){ - a[indx]--; - swap(a[indx],a[indx-1]); - indx--; - } - } - for(int i=0;i -using namespace std; -void solve (int n){ - string s=to_string(n); - int m=s.size(); - for(int j=0; j0 && s[i-1]>t; - while(t--){ - int n; - cin>>n; - solve(n); - cout< -using namespace std; -void solve (string s){ - - int m=s.size(); - bool flag = true; - while(flag){ - flag =false; - for(int i=1; i0 && s[i-1]>t; - while(t--){ - string s; - cin>>s; - solve(s); - cout< -using namespace std; -#define int long long -#define endl '\n' -#define fi first -#define se second -#define PII pair -#define PIC pair -#define PCI pair -#define PCC pair -int fx[8]={1,-1,0,0,1,-1,-1,1}; -int fy[8]={0,0,-1,1,1,-1,1,-1}; -const int inf=1e16; -const int N=1e6+10; -const int INF=9e18; -const int mod=1e9+7; -//括号最短匹配问题,记录左括号的数量,按需匹配即可,如果需要计算,则用栈计算。 -//a ="" "" + a, 判断a字符串要加"" ""; -//a*b=n,跑两层循环不会爆,调和级数,埃式塞法 -//log2 (1e9) = 30 -// &,|的优先级比!=低要注意。 -// i % 4 + 1//范围1~~4循环 -//一个有序数组,upper_bound(r)-lower_bound(l)为区间[l,r]的个数。 -//vector>>p(n+10);再用一个map -//即可达成p[i][sa][sb]三个字符串来确定一条边的个数。 -//选择max(l,fi)和min(r,se)即可让重复的区间减少最多。 -//需要考虑分配问题的时候,可以直接判断阈值,然后再进行平均分配即可。 -//遇到最值问题直接考虑二分 -//前缀积要爆,遇到l,r就要考虑前缀和。 -//遇到不等式,把相同变量移到同一边。 -//遇到两个数要满足某个条件,则可以用map<条件,int>的方式算出组合数。 -//long long 7e18 -//遇到消除字符串特定字符,用栈堆实现 -//遇到一段长度求区间个数,利用左右区间前缀和,相减即可。 -//遇到迷宫就改建筑,end!=make_pair(1ll,1ll) -//当遇到环形问题的时候,我们可以在后面接一个数组从而达成环形条件。 -//如果遇到只能转移到后面,则我们考虑挨个转移即可。 -//质数在2e5范围内大概15间隔一个。 -//当遇到两种状态,其中一种最优,但是最后需要另一种优化,可以用dp优化一下 -//当需要进行整体最大值递归的时候,只需要定义一个全局变量进行比较即可 - - - -int n,m ; -int a[N]; - -void solve(){ - string s; - cin>>s; - for (int k=1;k<=50;k++){ - for (int i=0;i>_; - while(_--){ - solve(); - - } - - return 0; -} -/* - - - */","#include -using namespace std; -#define int long long -#define endl '\n' -#define fi first -#define se second -#define PII pair -#define PIC pair -#define PCI pair -#define PCC pair -int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1}; -int fy[8] = {0, 0, -1, 1, 1, -1, 1, -1}; -const int inf = 1e16; -const int N = 1e6 + 10; -const int INF = 9e18; -const int mod = 1e9 + 7; -//括号最短匹配问题,记录左括号的数量,按需匹配即可,如果需要计算,则用栈计算。 -//a ="" "" + a, 判断a字符串要加"" ""; -//a*b=n,跑两层循环不会爆,调和级数,埃式塞法 -//log2 (1e9) = 30 -// &,|的优先级比!=低要注意。 -// i % 4 + 1//范围1~~4循环 -//一个有序数组,upper_bound(r)-lower_bound(l)为区间[l,r]的个数。 -//vector>>p(n+10);再用一个map -//即可达成p[i][sa][sb]三个字符串来确定一条边的个数。 -//选择max(l,fi)和min(r,se)即可让重复的区间减少最多。 -//需要考虑分配问题的时候,可以直接判断阈值,然后再进行平均分配即可。 -//遇到最值问题直接考虑二分 -//前缀积要爆,遇到l,r就要考虑前缀和。 -//遇到不等式,把相同变量移到同一边。 -//遇到两个数要满足某个条件,则可以用map<条件,int>的方式算出组合数。 -//long long 7e18 -//遇到消除字符串特定字符,用栈堆实现 -//遇到一段长度求区间个数,利用左右区间前缀和,相减即可。 -//遇到迷宫就改建筑,end!=make_pair(1ll,1ll) -//当遇到环形问题的时候,我们可以在后面接一个数组从而达成环形条件。 -//如果遇到只能转移到后面,则我们考虑挨个转移即可。 -//质数在2e5范围内大概15间隔一个。 -//当遇到两种状态,其中一种最优,但是最后需要另一种优化,可以用dp优化一下 -//当需要进行整体最大值递归的时候,只需要定义一个全局变量进行比较即可 - - - -int n, m ; -char s[N]; - -void solve() -{ - string s; - cin >> s; - int sum = 0, cnt = 0, kk = 0; - for (int i = 0; i < s.size(); i++) - { - sum += s[i] - '0'; - if (s[i] == '2') cnt++; - else if (s[i] == '3') kk++; - } - if (sum % 9 == 0) cout << ""Yes"" << endl; - else - { - for (int i = 0; i <= min((int)25, cnt); i++) - { - for (int j = 0; j <= kk; j++) - { - int sum1 = sum + 2 * i + j * 6; - if (sum1 % 9 == 0) - { - cout << ""Yes"" << endl; - return ; - } - } - } - cout << ""No"" << endl; - } -} -signed main() -{ - ios::sync_with_stdio(false), cin.tie(0); - int _ = 1; - cin >> _; - while (_--) - { - solve(); - - } - - return 0; -} -/* - - - */",1 -shradheyasoni1,2050D - Digital string maximization,c++20 ,311789540,311768510,"// I AM NOT HERE TO PARTICIPATE, I AM HERE TO DOMINATE - -#define JAI ios::sync_with_stdio(false); - -#define SHREE cin.tie(NULL); - -#define RAM cout.tie(NULL); - -#include - - - -#define f(i, n, k) for (int i; i < n; i += k) - -#define pb push_back - -#define ppb pop_back - -#define int long long - -#define mp make_pair - -using namespace std; - -using vpi = vector < pair < int, int >> ; - -using pi = pair < int, int > ; - -using vi = vector < int > ; - -using mapi = map < int, int > ; - -using vvi = vector < vector < int >> ; - -#define ff first - -#define ss second - -#define all(x) x.begin(), x.end() - -#define sz(x)(int)(x).size() - -const int inf = 9e17; - -const int mod = 1e9 + 7; - -#define DEBUG(x) cerr << #x << "": "" << x << '\n' - -template < typename T, typename Y > - -istream & operator >> (istream & is, pair < T, Y > & p) - -{ - -is >> p.first >> p.second; - -return is; - -} - -template < typename T, typename Y > - -ostream & operator << (ostream & os, pair < T, Y > p) - -{ - -os << p.first << ' ' << p.second << ' '; - -return os; - -} - -template < typename T > - -istream & operator >> (istream & is, vector < T > & v) - -{ - -for (auto & i: v) - -is >> i; - -return is; - -} - -template < typename T > - -ostream & operator << (ostream & os, vector < T > v) - -{ - -for (auto & i: v) - -os << i << ' '; - -return os; - -} - - - -int power(int base, int ex, int mod) { - -int res = 1; - -while (ex > 0) { - -if (ex % 2 == 1) { - -res = (res * base) % mod; - -} - -base = (base * base) % mod; - -ex /= 2; - -} - -return res; - -} - - - -void sol() { - -string str; - -cin>>str; - - - -int n = str.length(); - - - -for(int i = 0;i str[i] - '0'){ - -if(x1 > max_x1){ - -max_x1 = x1; - -ind1 = j; - -} - -} - -} - -while(ind1 > i){ - -swap(str[ind1],str[ind1-1]); - -ind1--; - -} - -str[i] =char( max_x1 + '0'); - -} - - - - - - - -cout<> t; - - - - - -while (t--) { - - - - - -sol(); - -cout< - - - -#define f(i, n, k) for (int i; i < n; i += k) - -#define pb push_back - -#define ppb pop_back - -#define int long long - -#define mp make_pair - -using namespace std; - -using vpi = vector < pair < int, int >> ; - -using pi = pair < int, int > ; - -using vi = vector < int > ; - -using mapi = map < int, int > ; - -using vvi = vector < vector < int >> ; - -#define ff first - -#define ss second - -#define all(x) x.begin(), x.end() - -#define sz(x)(int)(x).size() - -const int inf = 9e17; - -const int mod = 1e9 + 7; - -#define DEBUG(x) cerr << #x << "": "" << x << '\n' - -template < typename T, typename Y > - -istream & operator >> (istream & is, pair < T, Y > & p) - -{ - -is >> p.first >> p.second; - -return is; - -} - -template < typename T, typename Y > - -ostream & operator << (ostream & os, pair < T, Y > p) - -{ - -os << p.first << ' ' << p.second << ' '; - -return os; - -} - -template < typename T > - -istream & operator >> (istream & is, vector < T > & v) - -{ - -for (auto & i: v) - -is >> i; - -return is; - -} - -template < typename T > - -ostream & operator << (ostream & os, vector < T > v) - -{ - -for (auto & i: v) - -os << i << ' '; - -return os; - -} - - - -int power(int base, int ex, int mod) { - -int res = 1; - -while (ex > 0) { - -if (ex % 2 == 1) { - -res = (res * base) % mod; - -} - -base = (base * base) % mod; - -ex /= 2; - -} - -return res; - -} - - - -void sol() { - -string str; - -cin>>str; - - - -int n = str.length(); - -for(int i = 0;i=n) break; - - - -x = (str[j] - '0') - (j-i); - - - -if(x > str[i] - '0'){ - -if(x > max_x){ - -max_x = x; - -ind = j; - -} - -} - -} - -str[ind] = (str[ind] - '0') -ind+i +'0'; - -swap(str[i],str[ind]); - -} - -cout<> t; - - - - - -while (t--) { - - - - - -sol(); - -cout< best: - best = int(s[j]) - (j - i) - pos = j - - while pos > i: - s[pos], s[pos - 1] = s[pos - 1], s[pos] - pos -= 1 - - s[i] = str(best) - - print(''.join(s)) - - -if __name__ == ""__main__"": - TESTS = int(input()) - for _ in range(TESTS): - solve() - print() -","n = int(input()) -for _ in range(n): - n1 = list(input()) # Convert input to a list for mutability - length = len(n1) - - for i in range(length): - best = int(n1[i]) - pos = i - - # Optimize the inner loop to minimize recalculations - for j in range(i, min(i + 9, length)): - value = int(n1[j]) - (j - i) - if value > best: - best = value - pos = j - - # Perform swaps to bring the best element to the correct position - while pos > i: - n1[pos], n1[pos - 1] = n1[pos - 1], n1[pos] - pos -= 1 - - n1[i] = str(best) - - print("""".join(n1)) -",2 -PenguinSlayer_69,2050D - Digital string maximization,python,297759536,297760945,"def Sieve(num): - l2=[] - prime = [True for i in range(num+1)] - p = 2 - while (p * p <= num): - if (prime[p] == True): - for i in range(p * p, num+1, p): - prime[i] = False - p += 1 - for p in range(2, num+1): - if prime[p]: - l2.append(p) - return((l2)) -# s = Sieve(50) - -def op(x,y): - # print(""X=="",x) - # print(""Y=="",y) - return(x+y) -class segtree(): - def __init__(self,init,func,ide): - self.n=len(init) - self.func=func - self.ide=ide - self.size=1<<(self.n-1).bit_length() - self.tree=[self.ide for i in range(2*self.size)] - for i in range(self.n): - self.tree[self.size+i]=init[i] - for i in range(self.size-1,0,-1): - self.tree[i]=self.func(self.tree[2*i], self.tree[(2*i)|1]) - - def update(self,k,x): - k+=self.size - self.tree[k]=x - - k>>=1 - while k: - self.tree[k]=self.func(self.tree[2*k],self.tree[k*2|1]) - k>>=1 - - def get(self,i): - return self.tree[i+self.size] - - def query(self,l,r): - # Include left index but not right - l+=self.size - r+=self.size - ans=0 - while l>=1 - r>>=1 - return ans - - def debug(self,s=10): - print([self.get(i) for i in range(min(self.n,s))]) - -class sortedlist: - def __init__(self, iterable=[], _load=200): - """"""Initialize sorted list instance."""""" - values = sorted(iterable) - self._len = _len = len(values) - self._load = _load - self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] - self._list_lens = [len(_list) for _list in _lists] - self._mins = [_list[0] for _list in _lists] - self._fen_tree = [] - self._rebuild = True - - def _fen_build(self): - """"""Build a fenwick tree instance."""""" - self._fen_tree[:] = self._list_lens - _fen_tree = self._fen_tree - for i in range(len(_fen_tree)): - if i | i + 1 < len(_fen_tree): - _fen_tree[i | i + 1] += _fen_tree[i] - self._rebuild = False - - def _fen_update(self, index, value): - """"""Update `fen_tree[index] += value`."""""" - if not self._rebuild: - _fen_tree = self._fen_tree - while index < len(_fen_tree): - _fen_tree[index] += value - index |= index + 1 - - def _fen_query(self, end): - """"""Return `sum(_fen_tree[:end])`."""""" - if self._rebuild: - self._fen_build() - - _fen_tree = self._fen_tree - x = 0 - while end: - x += _fen_tree[end - 1] - end &= end - 1 - return x - - def _fen_findkth(self, k): - """"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""""" - _list_lens = self._list_lens - if k < _list_lens[0]: - return 0, k - if k >= self._len - _list_lens[-1]: - return len(_list_lens) - 1, k + _list_lens[-1] - self._len - if self._rebuild: - self._fen_build() - - _fen_tree = self._fen_tree - idx = -1 - for d in reversed(range(len(_fen_tree).bit_length())): - right_idx = idx + (1 << d) - if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: - idx = right_idx - k -= _fen_tree[idx] - return idx + 1, k - - def _delete(self, pos, idx): - """"""Delete value at the given `(pos, idx)`."""""" - _lists = self._lists - _mins = self._mins - _list_lens = self._list_lens - - self._len -= 1 - self._fen_update(pos, -1) - del _lists[pos][idx] - _list_lens[pos] -= 1 - - if _list_lens[pos]: - _mins[pos] = _lists[pos][0] - else: - del _lists[pos] - del _list_lens[pos] - del _mins[pos] - self._rebuild = True - - def _loc_left(self, value): - """"""Return an index pair that corresponds to the first position of `value` in the sorted list."""""" - if not self._len: - return 0, 0 - - _lists = self._lists - _mins = self._mins - - lo, pos = -1, len(_lists) - 1 - while lo + 1 < pos: - mi = (lo + pos) >> 1 - if value <= _mins[mi]: - pos = mi - else: - lo = mi - - if pos and value <= _lists[pos - 1][-1]: - pos -= 1 - - _list = _lists[pos] - lo, idx = -1, len(_list) - while lo + 1 < idx: - mi = (lo + idx) >> 1 - if value <= _list[mi]: - idx = mi - else: - lo = mi - - return pos, idx - - def _loc_right(self, value): - """"""Return an index pair that corresponds to the last position of `value` in the sorted list."""""" - if not self._len: - return 0, 0 - - _lists = self._lists - _mins = self._mins - - pos, hi = 0, len(_lists) - while pos + 1 < hi: - mi = (pos + hi) >> 1 - if value < _mins[mi]: - hi = mi - else: - pos = mi - - _list = _lists[pos] - lo, idx = -1, len(_list) - while lo + 1 < idx: - mi = (lo + idx) >> 1 - if value < _list[mi]: - idx = mi - else: - lo = mi - - return pos, idx - - def add(self, value): - """"""Add `value` to sorted list."""""" - _load = self._load - _lists = self._lists - _mins = self._mins - _list_lens = self._list_lens - - self._len += 1 - if _lists: - pos, idx = self._loc_right(value) - self._fen_update(pos, 1) - _list = _lists[pos] - _list.insert(idx, value) - _list_lens[pos] += 1 - _mins[pos] = _list[0] - if _load + _load < len(_list): - _lists.insert(pos + 1, _list[_load:]) - _list_lens.insert(pos + 1, len(_list) - _load) - _mins.insert(pos + 1, _list[_load]) - _list_lens[pos] = _load - del _list[_load:] - self._rebuild = True - else: - _lists.append([value]) - _mins.append(value) - _list_lens.append(1) - self._rebuild = True - - def discard(self, value): - """"""Remove `value` from sorted list if it is a member."""""" - _lists = self._lists - if _lists: - pos, idx = self._loc_right(value) - if idx and _lists[pos][idx - 1] == value: - self._delete(pos, idx - 1) - - def remove(self, value): - """"""Remove `value` from sorted list; `value` must be a member."""""" - _len = self._len - self.discard(value) - if _len == self._len: - raise ValueError('{0!r} not in list'.format(value)) - - def pop(self, index=-1): - """"""Remove and return value at `index` in sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - value = self._lists[pos][idx] - self._delete(pos, idx) - return value - - def bisect_left(self, value): - """"""Return the first index to insert `value` in the sorted list."""""" - pos, idx = self._loc_left(value) - return self._fen_query(pos) + idx - - def bisect_right(self, value): - """"""Return the last index to insert `value` in the sorted list."""""" - pos, idx = self._loc_right(value) - return self._fen_query(pos) + idx - - def count(self, value): - """"""Return number of occurrences of `value` in the sorted list."""""" - return self.bisect_right(value) - self.bisect_left(value) - - def __len__(self): - """"""Return the size of the sorted list."""""" - return self._len - - def __getitem__(self, index): - """"""Lookup value at `index` in sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - return self._lists[pos][idx] - - def __delitem__(self, index): - """"""Remove value at `index` from sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - self._delete(pos, idx) - - def __contains__(self, value): - """"""Return true if `value` is an element of the sorted list."""""" - _lists = self._lists - if _lists: - pos, idx = self._loc_left(value) - return idx < len(_lists[pos]) and _lists[pos][idx] == value - return False - - def __iter__(self): - """"""Return an iterator over the sorted list."""""" - return (value for _list in self._lists for value in _list) - - def __reversed__(self): - """"""Return a reverse iterator over the sorted list."""""" - return (value for _list in reversed(self._lists) for value in reversed(_list)) - - def __repr__(self): - """"""Return string representation of sorted list."""""" - return 'SortedList({0})'.format(list(self)) - - -from collections import deque,defaultdict -g = defaultdict() -def bfs(g, start): - queue, enqueued = deque([(None, start)]), set([start]) - while queue: - parent, n = queue.popleft() - yield parent, n - # Can use a variable fin, and break if n==fin - new = set(g[n]) - enqueued - enqueued |= new - queue.extend([(n, child) for child in new]) -# list(bfs(dict,initial pt)) gives ==> [(None,start),(start,x1),(x1,x2),(x1,x3),(x2,finish)] - -class dsu: - def __init__(self, n): - self.parent = list(range(n)) - self.size = [1 for i in range(n)] - self.num_sets = n - def find(self, a): - acopy = a - while a != self.parent[a]: - a = self.parent[a] - while acopy != a: - self.parent[acopy], acopy = a, self.parent[acopy] - return a - def union(self, a, b): - a, b = self.find(a), self.find(b) - if a != b: - if self.size[a] < self.size[b]: - a, b = b, a - self.num_sets -= 1 - self.parent[b] = a - self.size[a] += self.size[b] - -# Initialize with u = dsu(No. of ele)[No.+1 for index out of range] -# Use while acopy != a loop to find tree-like properties - - -# Custom HashMap and Set for Anti-hash-table test -class CustomHashMap: - def __init__(self, type = dict, arr = []): - self.RANDOM = random.randrange(2**62) - self.dict = type([self.wrapper(i) for i in arr]) - def wrapper(self,num): - return num ^ self.RANDOM - def __setitem__(self, key, value): - self.dict[self.wrapper(key)] = value - def __getitem__(self, key): - return self.dict[self.wrapper(key)] - def __contains__(self, key): - return self.wrapper(key) in self.dict - def __iter__(self): - return iter(self.wrapper(i) for i in self.dict) - def items(self): - return [(self.wrapper(i),j) for i,j in self.dict.items()] - def __repr__(self): - return repr({self.wrapper(i):j for i,j in self.dict.items()}) -#Use akin: a = CustomHashMap(Counter,a) : {a is a LIST}) -# a.items() is a number of tuples like (2,3); len(a.items()) to get len(a) - -from random import randint -# Random number from 1 to 10^9 -RANDOM = randint(1, 10 ** 9) -class h(int): - def __init__(self, x): - int.__init__(x) - - def __hash__(self): - return super(h, self).__hash__() ^ RANDOM -# h(x) gives a changed value of x which wont hash-collide - -def pfactor(n): - ans=defaultdict(int) - s = Sieve(ceil(n**0.5)) - # print(s) - for i in s: - x = divmod(n,i) - # print(""X=="",x) - while(x[1]==0): - ans[i]+=1 - n = x[0] - x = divmod(n,i) - if(n==1): - break - if(n!=1): - ans[n]+=1 - return(ans) -# Returns a defaultdict of prime factorization - -# Calculate nCr%p -def ncr(n, r, p): - num = den = 1 - for i in range(r): - num = (num * (n - i)) % p - den = (den * (i + 1)) % p - return (num * pow(den,p - 2, p)) % p - -def factor(n): - lower,upper=[],[] - i=1 - while i*i<=n: - if n%i==0: - lower.append(i) - if i!=n//i: - upper.append(n//i) - i+=1 - return lower+upper[::-1] - - - -import random -from sys import stdin,stdout -input=lambda :stdin.readline()[:-1] -from collections import defaultdict, Counter, deque, OrderedDict -import itertools;from itertools import permutations as perms, combinations as combs,combinations_with_replacement -from bisect import bisect_left, bisect_right -from heapq import heapify, heappush, heappop, nlargest, nsmallest -import math -from functools import reduce -from math import inf,floor,ceil,comb,lcm,gcd,log2 -from operator import itemgetter - - - -def solve(): - a = list(map(int,list(str(input())))) - n = len(a) - # print(""A=="",a) - ans = [-1 for i in range(n)] - c = [] - f= 0 - for i in range(n): - if(i==0): - for j in range(min(11,n)): - c.append([a[f],f]) - f+=1 - else: - if(fv): - t= j - v = c[j][0] - else: - if(c[j][0]-c[j][1]+i>v): - t = j - v = c[j][0]-c[j][1]+i - x = c.pop(t) - ans[i] = v - - # print(""ANS=="",ans) - print(*ans,sep="""") -for _ in range(int(input())): - solve() - -","def Sieve(num): - l2=[] - prime = [True for i in range(num+1)] - p = 2 - while (p * p <= num): - if (prime[p] == True): - for i in range(p * p, num+1, p): - prime[i] = False - p += 1 - for p in range(2, num+1): - if prime[p]: - l2.append(p) - return((l2)) -# s = Sieve(50) - -def op(x,y): - # print(""X=="",x) - # print(""Y=="",y) - return(x+y) -class segtree(): - def __init__(self,init,func,ide): - self.n=len(init) - self.func=func - self.ide=ide - self.size=1<<(self.n-1).bit_length() - self.tree=[self.ide for i in range(2*self.size)] - for i in range(self.n): - self.tree[self.size+i]=init[i] - for i in range(self.size-1,0,-1): - self.tree[i]=self.func(self.tree[2*i], self.tree[(2*i)|1]) - - def update(self,k,x): - k+=self.size - self.tree[k]=x - - k>>=1 - while k: - self.tree[k]=self.func(self.tree[2*k],self.tree[k*2|1]) - k>>=1 - - def get(self,i): - return self.tree[i+self.size] - - def query(self,l,r): - # Include left index but not right - l+=self.size - r+=self.size - ans=0 - while l>=1 - r>>=1 - return ans - - def debug(self,s=10): - print([self.get(i) for i in range(min(self.n,s))]) - -class sortedlist: - def __init__(self, iterable=[], _load=200): - """"""Initialize sorted list instance."""""" - values = sorted(iterable) - self._len = _len = len(values) - self._load = _load - self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] - self._list_lens = [len(_list) for _list in _lists] - self._mins = [_list[0] for _list in _lists] - self._fen_tree = [] - self._rebuild = True - - def _fen_build(self): - """"""Build a fenwick tree instance."""""" - self._fen_tree[:] = self._list_lens - _fen_tree = self._fen_tree - for i in range(len(_fen_tree)): - if i | i + 1 < len(_fen_tree): - _fen_tree[i | i + 1] += _fen_tree[i] - self._rebuild = False - - def _fen_update(self, index, value): - """"""Update `fen_tree[index] += value`."""""" - if not self._rebuild: - _fen_tree = self._fen_tree - while index < len(_fen_tree): - _fen_tree[index] += value - index |= index + 1 - - def _fen_query(self, end): - """"""Return `sum(_fen_tree[:end])`."""""" - if self._rebuild: - self._fen_build() - - _fen_tree = self._fen_tree - x = 0 - while end: - x += _fen_tree[end - 1] - end &= end - 1 - return x - - def _fen_findkth(self, k): - """"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""""" - _list_lens = self._list_lens - if k < _list_lens[0]: - return 0, k - if k >= self._len - _list_lens[-1]: - return len(_list_lens) - 1, k + _list_lens[-1] - self._len - if self._rebuild: - self._fen_build() - - _fen_tree = self._fen_tree - idx = -1 - for d in reversed(range(len(_fen_tree).bit_length())): - right_idx = idx + (1 << d) - if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: - idx = right_idx - k -= _fen_tree[idx] - return idx + 1, k - - def _delete(self, pos, idx): - """"""Delete value at the given `(pos, idx)`."""""" - _lists = self._lists - _mins = self._mins - _list_lens = self._list_lens - - self._len -= 1 - self._fen_update(pos, -1) - del _lists[pos][idx] - _list_lens[pos] -= 1 - - if _list_lens[pos]: - _mins[pos] = _lists[pos][0] - else: - del _lists[pos] - del _list_lens[pos] - del _mins[pos] - self._rebuild = True - - def _loc_left(self, value): - """"""Return an index pair that corresponds to the first position of `value` in the sorted list."""""" - if not self._len: - return 0, 0 - - _lists = self._lists - _mins = self._mins - - lo, pos = -1, len(_lists) - 1 - while lo + 1 < pos: - mi = (lo + pos) >> 1 - if value <= _mins[mi]: - pos = mi - else: - lo = mi - - if pos and value <= _lists[pos - 1][-1]: - pos -= 1 - - _list = _lists[pos] - lo, idx = -1, len(_list) - while lo + 1 < idx: - mi = (lo + idx) >> 1 - if value <= _list[mi]: - idx = mi - else: - lo = mi - - return pos, idx - - def _loc_right(self, value): - """"""Return an index pair that corresponds to the last position of `value` in the sorted list."""""" - if not self._len: - return 0, 0 - - _lists = self._lists - _mins = self._mins - - pos, hi = 0, len(_lists) - while pos + 1 < hi: - mi = (pos + hi) >> 1 - if value < _mins[mi]: - hi = mi - else: - pos = mi - - _list = _lists[pos] - lo, idx = -1, len(_list) - while lo + 1 < idx: - mi = (lo + idx) >> 1 - if value < _list[mi]: - idx = mi - else: - lo = mi - - return pos, idx - - def add(self, value): - """"""Add `value` to sorted list."""""" - _load = self._load - _lists = self._lists - _mins = self._mins - _list_lens = self._list_lens - - self._len += 1 - if _lists: - pos, idx = self._loc_right(value) - self._fen_update(pos, 1) - _list = _lists[pos] - _list.insert(idx, value) - _list_lens[pos] += 1 - _mins[pos] = _list[0] - if _load + _load < len(_list): - _lists.insert(pos + 1, _list[_load:]) - _list_lens.insert(pos + 1, len(_list) - _load) - _mins.insert(pos + 1, _list[_load]) - _list_lens[pos] = _load - del _list[_load:] - self._rebuild = True - else: - _lists.append([value]) - _mins.append(value) - _list_lens.append(1) - self._rebuild = True - - def discard(self, value): - """"""Remove `value` from sorted list if it is a member."""""" - _lists = self._lists - if _lists: - pos, idx = self._loc_right(value) - if idx and _lists[pos][idx - 1] == value: - self._delete(pos, idx - 1) - - def remove(self, value): - """"""Remove `value` from sorted list; `value` must be a member."""""" - _len = self._len - self.discard(value) - if _len == self._len: - raise ValueError('{0!r} not in list'.format(value)) - - def pop(self, index=-1): - """"""Remove and return value at `index` in sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - value = self._lists[pos][idx] - self._delete(pos, idx) - return value - - def bisect_left(self, value): - """"""Return the first index to insert `value` in the sorted list."""""" - pos, idx = self._loc_left(value) - return self._fen_query(pos) + idx - - def bisect_right(self, value): - """"""Return the last index to insert `value` in the sorted list."""""" - pos, idx = self._loc_right(value) - return self._fen_query(pos) + idx - - def count(self, value): - """"""Return number of occurrences of `value` in the sorted list."""""" - return self.bisect_right(value) - self.bisect_left(value) - - def __len__(self): - """"""Return the size of the sorted list."""""" - return self._len - - def __getitem__(self, index): - """"""Lookup value at `index` in sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - return self._lists[pos][idx] - - def __delitem__(self, index): - """"""Remove value at `index` from sorted list."""""" - pos, idx = self._fen_findkth(self._len + index if index < 0 else index) - self._delete(pos, idx) - - def __contains__(self, value): - """"""Return true if `value` is an element of the sorted list."""""" - _lists = self._lists - if _lists: - pos, idx = self._loc_left(value) - return idx < len(_lists[pos]) and _lists[pos][idx] == value - return False - - def __iter__(self): - """"""Return an iterator over the sorted list."""""" - return (value for _list in self._lists for value in _list) - - def __reversed__(self): - """"""Return a reverse iterator over the sorted list."""""" - return (value for _list in reversed(self._lists) for value in reversed(_list)) - - def __repr__(self): - """"""Return string representation of sorted list."""""" - return 'SortedList({0})'.format(list(self)) - - -from collections import deque,defaultdict -g = defaultdict() -def bfs(g, start): - queue, enqueued = deque([(None, start)]), set([start]) - while queue: - parent, n = queue.popleft() - yield parent, n - # Can use a variable fin, and break if n==fin - new = set(g[n]) - enqueued - enqueued |= new - queue.extend([(n, child) for child in new]) -# list(bfs(dict,initial pt)) gives ==> [(None,start),(start,x1),(x1,x2),(x1,x3),(x2,finish)] - -class dsu: - def __init__(self, n): - self.parent = list(range(n)) - self.size = [1 for i in range(n)] - self.num_sets = n - def find(self, a): - acopy = a - while a != self.parent[a]: - a = self.parent[a] - while acopy != a: - self.parent[acopy], acopy = a, self.parent[acopy] - return a - def union(self, a, b): - a, b = self.find(a), self.find(b) - if a != b: - if self.size[a] < self.size[b]: - a, b = b, a - self.num_sets -= 1 - self.parent[b] = a - self.size[a] += self.size[b] - -# Initialize with u = dsu(No. of ele)[No.+1 for index out of range] -# Use while acopy != a loop to find tree-like properties - - -# Custom HashMap and Set for Anti-hash-table test -class CustomHashMap: - def __init__(self, type = dict, arr = []): - self.RANDOM = random.randrange(2**62) - self.dict = type([self.wrapper(i) for i in arr]) - def wrapper(self,num): - return num ^ self.RANDOM - def __setitem__(self, key, value): - self.dict[self.wrapper(key)] = value - def __getitem__(self, key): - return self.dict[self.wrapper(key)] - def __contains__(self, key): - return self.wrapper(key) in self.dict - def __iter__(self): - return iter(self.wrapper(i) for i in self.dict) - def items(self): - return [(self.wrapper(i),j) for i,j in self.dict.items()] - def __repr__(self): - return repr({self.wrapper(i):j for i,j in self.dict.items()}) -#Use akin: a = CustomHashMap(Counter,a) : {a is a LIST}) -# a.items() is a number of tuples like (2,3); len(a.items()) to get len(a) - -from random import randint -# Random number from 1 to 10^9 -RANDOM = randint(1, 10 ** 9) -class h(int): - def __init__(self, x): - int.__init__(x) - - def __hash__(self): - return super(h, self).__hash__() ^ RANDOM -# h(x) gives a changed value of x which wont hash-collide - -def pfactor(n): - ans=defaultdict(int) - s = Sieve(ceil(n**0.5)) - # print(s) - for i in s: - x = divmod(n,i) - # print(""X=="",x) - while(x[1]==0): - ans[i]+=1 - n = x[0] - x = divmod(n,i) - if(n==1): - break - if(n!=1): - ans[n]+=1 - return(ans) -# Returns a defaultdict of prime factorization - -# Calculate nCr%p -def ncr(n, r, p): - num = den = 1 - for i in range(r): - num = (num * (n - i)) % p - den = (den * (i + 1)) % p - return (num * pow(den,p - 2, p)) % p - -def factor(n): - lower,upper=[],[] - i=1 - while i*i<=n: - if n%i==0: - lower.append(i) - if i!=n//i: - upper.append(n//i) - i+=1 - return lower+upper[::-1] - - - -import random -from sys import stdin,stdout -input=lambda :stdin.readline()[:-1] -from collections import defaultdict, Counter, deque, OrderedDict -import itertools;from itertools import permutations as perms, combinations as combs,combinations_with_replacement -from bisect import bisect_left, bisect_right -from heapq import heapify, heappush, heappop, nlargest, nsmallest -import math -from functools import reduce -from math import inf,floor,ceil,comb,lcm,gcd,log2 -from operator import itemgetter - - - -def solve(): - a = list(map(int,list(str(input())))) - n = len(a) - # print(""A=="",a) - ans = [-1 for i in range(n)] - c = [] - f= 0 - for i in range(n): - if(i==0): - for j in range(min(10,n)): - c.append([a[f],f]) - f+=1 - else: - if(fv): - t= j - v = c[j][0] - else: - if(c[j][0]-c[j][1]+i>v): - t = j - v = c[j][0]-c[j][1]+i - x = c.pop(t) - for j in range(len(c)): - if(c[j][1] - -using namespace std; - - - -int main(){ - -int t; - -cin>>t; - -while(t--){ - -string s; - -cin>>s; - -int n = s.size(); - -for (int i = 0; i < n-1; i++) - -{ - -if(s[i]=='8' || s[i]=='9') continue; - -int best=s[i]-'0'; - -int x=i; - -for (int j = i+1; j < i+8; j++) - -{ - -if(jbest){ - -best=s[j]-'0'-(j-i); - -x=j; - -} - -} - -s[x]=best+'0'; - -while(x!=i){ - -swap(s[x],s[x-1]); - -x--; - -} - -} - -cout< - -using namespace std; - - - -int main(){ - -int t; - -cin>>t; - -while(t--){ - -string s; - -cin>>s; - -int n = s.size(); - -for (int i = 0; i < n-1; i++) - -{ - -if(s[i]=='8' || s[i]=='9') continue; - -int best=s[i]-'0'; - -int x=i; - -for (int j = i+1; j < i+9; j++) - -{ - -if(jbest){ - -best=s[j]-'0'-(j-i); - -x=j; - -} - -} - -s[x]=best+'0'; - -while(x!=i){ - -swap(s[x],s[x-1]); - -x--; - -} - -} - -cout< -#define ll long long int -#define INF (ll)1e18 -#define mod 998244353 -using namespace std; -ll pow_mod(ll a,ll b){ - ll res=1; - while(b>0){ - if(b%2) - res=(res*a)%mod; - b/=2; - a=(a*a)%mod; - } - return res; -} -int main(){ - ll t; - cin>>t; - while(t--){ - string s; - cin>>s; - int n = s.size(); - for(int i = 0 ; i < n ; i++){ - // if((s[i]-'0') == 0) { - // continue; - // } - int maxi = s[i]-'0'; - int maxi_idx = i; - int cnt = 0; - bool chk = false; - for(int j = i+1 ; j < min(i+9,n) ; j++){ - cnt++; - if(maxi < ((s[j]-'0')-cnt)){ - chk = true; - maxi = (s[j]-'0')-cnt; - maxi_idx = j; - //cout<= i ; j--){ - if(j-1 >= 0) s[j] = s[j-1]; - } - s[i] = val; - } - //cout< -#define ll long long int -#define INF (ll)1e18 -#define mod 998244353 -using namespace std; -ll pow_mod(ll a,ll b){ - ll res=1; - while(b>0){ - if(b%2) - res=(res*a)%mod; - b/=2; - a=(a*a)%mod; - } - return res; -} -int main(){ - ll t; - cin>>t; - while(t--){ - string s; - cin>>s; - int n = s.size(); - for(int i = 0 ; i < n ; i++){ - if((s[i]-'0') == 0) { - continue; - } - int maxi = s[i]-'0'; - int maxi_idx = i; - int cnt = 0; - bool chk = false; - for(int j = i+1 ; j < min(i+9,n) ; j++){ - cnt++; - if(maxi < ((s[j]-'0')-cnt)){ - chk = true; - maxi = (s[j]-'0')-cnt; - maxi_idx = j; - } - } - if(chk){ - //cout<= i ; j--){ - if(j-1 >= 0) s[j] = s[j-1]; - } - s[i] = val; - } - } - cout< - - - -using namespace std; - - - -#include - -#include - - - -using namespace __gnu_pbds; - -#define ll long long - -#define order_set tree < pair , null_type , less> , rb_tree_tag , tree_order_statistics_node_update > - -const ll MAX = 1e18; - -const int N = 2e5 + 100; - -const ll mod = 1e9 + 7; - -ll n, m, k; - -string s; - -//---------------------------------------------------------------------------------------------------- - - - -void solve() { - -cin >> s; - -n = s.size(); - -for (int i = 0; i < n; ++i) { - -ll ok = -1; - -char z = s[i]; - -for (int j = i + 1; j < min(n, n + 10); ++j) { - -if (z < (s[j] - (j - i))) { - -ok = j; - -z = (s[j] - (j - i)); - -} - -} - -if (ok > -1) { - -s[ok] = z; - -} - -for (int j = ok; j > i; j--) swap(s[j], s[j - 1]); - -} - -cout << s << '\n'; - - - - - -} - - - -//--------------------------------------------------------------------------------------------------- - -int main() { - -ios::sync_with_stdio(NULL); - -cin.tie(0); - -cout.tie(0); - -#ifndef ONLINE_JUDGE - -freopen(""input.txt"", ""r"", stdin); - -freopen(""output.txt"", ""w"", stdout); - -#endif - -int t = 1; - -cin >> t; - -for (int i = 1; i <= t; i++) { - -solve(); - -} - -return 0; - -}","#include - - - -using namespace std; - - - -#include - -#include - - - -using namespace __gnu_pbds; - -#define ll long long - -#define order_set tree < pair , null_type , less> , rb_tree_tag , tree_order_statistics_node_update > - -const ll MAX = 1e18; - -const int N = 2e5 + 100; - -const ll mod = 1e9 + 7; - -ll n, m, k; - -string s; - -//---------------------------------------------------------------------------------------------------- - - - -void solve() { - -cin >> s; - -n = s.size(); - -for (int i = 0; i < n; ++i) { - -ll ok = -1; - -char z = s[i]; - -for (int j = i + 1; j < min(n, i + 10ll); ++j) { - -if (z < (s[j] - (j - i))) { - -ok = j; - -z = (s[j] - (j - i)); - -} - -} - -if (ok > -1) { - -s[ok] = z; - -for (int j = ok; j > i; j--) swap(s[j], s[j - 1]); - -} - -} - -cout << s << '\n'; - - - - - -} - - - -//--------------------------------------------------------------------------------------------------- - -int main() { - -ios::sync_with_stdio(NULL); - -cin.tie(0); - -cout.tie(0); - -#ifndef ONLINE_JUDGE - -freopen(""input.txt"", ""r"", stdin); - -freopen(""output.txt"", ""w"", stdout); - -#endif - -int t = 1; - -cin >> t; - -for (int i = 1; i <= t; i++) { - -solve(); - -} - -return 0; - -}",2 -Satyam_Atal_605,2050E - Three Strings,c++20 ,295958839,295958988,"#include -#include -using namespace std; -// # define int long long -#define f(x, a, b) for (ll x = a; x < b; x++) -#define fm(x, a, b) for (int x = a; x > b; x--) -#define ll long long -#define pb push_back - -long long gcd(long long a, ll b) -{ - return b == 0 ? a : gcd(b, a % b); -} - -long long lcm(ll a, ll b) -{ - return (a / gcd(a, b)) * b; -} - -int help(vector>& dp,string& a,string& b,string& c,int i,int j,int n,int m, int o){ - if (i==n){ - int ans=0; - f(k,j,m){ - if (c[n+k]!=b[k]){ans+=1;} - } - return ans; - } - if (j==m){ - int ans=0; - f(k,i,n){ - if (c[m+k]!=a[k]){ans+=1;} - } - return ans; - } - if (a[i]==c[i+j]){ - if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - } - else if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - return dp[i][j]; -} - -int main() -{ - int t; - t = 1; - cin >> t; - while (t--) - { - string a,b,c; cin>>a>>b>>c; - int n=a.size(),m=b.size(),o=c.size(); - vector> dp(n,vector(m,-1)); - int ans=help(dp,a,b,c,0,0,n,m,o); - cout< -#include -using namespace std; -// # define int long long -#define f(x, a, b) for (ll x = a; x < b; x++) -#define fm(x, a, b) for (int x = a; x > b; x--) -#define ll long long -#define pb push_back - -long long gcd(long long a, ll b) -{ - return b == 0 ? a : gcd(b, a % b); -} - -long long lcm(ll a, ll b) -{ - return (a / gcd(a, b)) * b; -} - -int help(vector>& dp,string& a,string& b,string& c,int i,int j,int n,int m, int o){ - if (i==n){ - int ans=0; - f(k,j,m){ - if (c[n+k]!=b[k]){ans+=1;} - } - return ans; - } - if (j==m){ - int ans=0; - f(k,i,n){ - if (c[m+k]!=a[k]){ans+=1;} - } - return ans; - } - if (dp[i][j]!=-1){return dp[i][j];} - if (a[i]==c[i+j]){ - if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - } - else if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - return dp[i][j]; -} - -int main() -{ - int t; - t = 1; - cin >> t; - while (t--) - { - string a,b,c; cin>>a>>b>>c; - int n=a.size(),m=b.size(),o=c.size(); - vector> dp(n,vector(m,-1)); - int ans=help(dp,a,b,c,0,0,n,m,o); - cout< -using namespace std; - -#define ll long long -#define all(x) (x).begin(), (x).end() -#define f(i, n) for (int i = 0; i < n; i++) -#define trace(x) cerr << #x << "": "" << x << '\n' -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - string s; - cin >> s; - int n = s.size(); - for (int i = 0; i < n; i++) - { - char ch = s[i]; - int j = i - 1; - while (j >= 0 and s[j] - '0' < (s[j + 1] - '0') - 1) - { - s[j + 1] = s[j + 1] - 1; - swap(s[j + 1], s[j]); - j--; - } - } - cout << s << '\n'; - } -}","#include -using namespace std; - -#define ll long long -#define all(x) (x).begin(), (x).end() -#define f(i, n) for (int i = 0; i < n; i++) -#define trace(x) cerr << #x << "": "" << x << '\n' -string a, b, c; -const int N = 3e3 + 5; -int dp[N][N]; -int na, nb, nc; -int fun(int i, int j) -{ - if (i == na and j == nb) - return 0; - if (i == na) - { - int count = 0; - for (int k = j; k < nb; k++) - { - if (b[k] != c[i + k]) - count++; - } - return count; - } - if (j == nb) - { - int count = 0; - for (int k = i; k < na; k++) - { - if (a[k] != c[j + k]) - count++; - } - return count; - } - if (dp[i][j] != -1) - return dp[i][j]; - int ans; - if (a[i] == c[j + i]) - ans = fun(i + 1, j); - else - ans = 1 + fun(i + 1, j); - if (b[j] == c[i + j]) - ans = min(ans, fun(i, j + 1)); - else - ans = min(ans, 1 + fun(i, j + 1)); - return dp[i][j] = ans; -} -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while (t--) - { - cin >> a >> b >> c; - na = a.size(); - nb = b.size(); - nc = c.size(); - f(i, nc + 10) - { - f(j, nc + 10) - { - dp[i][j] = -1; - } - } - cout << fun(0, 0) << '\n'; - } -}",2 -KHF677,2050E - Three Strings,c++17 ,298458877,298450233,"#include -using namespace std; - -int main() -{ - int t; - cin>>t; - while(t--) { - string a, b, c; - cin>>a>>b>>c; - - int l = a.length(), m = b.length(), n = c.length(); - - int dp[l+1][m+1]; - dp[0][0] = 0; - - for(int i = 0; i <= l; i++) { - for(int j = 0; j <= m; j++) { - if(i == 0 && j == 0) continue; - if(i == 0) dp[i][j] = dp[i][j-1] + (b[j-1] != c[i+j-1]); - else if(j == 0) dp[i][j] = dp[i-1][j] + (a[i-1] != c[i+j-1]); - else dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i+j-1]), dp[i][j-1] + (b[j-1] != c[i+j-1])); - } - } - - cout< -using namespace std; - -int minChange(int i, int j, string a, string b, string c) { - if(i >= a.length() && j >= b.length()) return 0; - else if(i >= a.length()) return (b[j] != c[i+j]) + minChange(i, j+1, a, b, c); - else if(j >= b.length()) return (a[i] != c[i+j]) + minChange(i+1, j, a, b, c); - else return min((a[i] != c[i+j])+minChange(i+1, j, a, b, c), (b[j] != c[i+j]) + minChange(i, j+1, a, b, c)); -} - -int main() -{ - int t; - cin>>t; - while(t--) { - string a, b, c; - cin>>a>>b>>c; - cout< -using namespace std; -#define int long long -#define pb push_back -#define fi first -#define se second -const int MOD = 1e9+7; -const int maxn = 1e3 + 10; - -void solve(){ - string a,b,c; - cin >> a >> b >> c; - int na = a.length(); - int nb = b.length(); - vector> dp(maxn, vector(maxn, 1e15)); - dp[0][0] = 0; - for(int i = 0; i <= na; i++){ - for(int j = 0; j <= nb; j++){ - if(i + j == 0) continue; - if(i - 1 >= 0){ - dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i + j - 1] != a[i-1])); - } - if(j - 1 >= 0){ - dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i + j - 1] != b[j-1])); - } - } - } - - cout << dp[na][nb] << endl; -} - -int32_t main(){ - - int t=1; - cin >> t; - while(t--) solve(); - - return 0; -} -","#include -using namespace std; -#define int long long -#define pb push_back -#define fi first -#define se second -const int MOD = 1e9+7; - -void solve(){ - string a,b,c; - cin >> a >> b >> c; - int na = a.length(); - int nb = b.length(); - vector> dp(na + 1, vector(nb + 1, 1e15)); - dp[0][0] = 0; - for(int i = 0; i <= na; i++){ - for(int j = 0; j <= nb; j++){ - if(i + j == 0) continue; - if(i - 1 >= 0){ - dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i + j - 1] != a[i-1])); - } - if(j - 1 >= 0){ - dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i + j - 1] != b[j-1])); - } - } - } - - cout << dp[na][nb] << endl; -} - -int32_t main(){ - - int t=1; - cin >> t; - while(t--) solve(); - - return 0; -} -",2 -mohmmdali,2050E - Three Strings,c++20 ,297989106,297989254,"/** -* created: 2024-12-23 07:51:30 -**/ -#include -#include -#include -using namespace __gnu_pbds; -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""../debug.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -#define int long long -#define all(v) (v).begin(),(v).end() -#define allr(v) (v).rbegin(),(v).rend() -#define show(x) cout << x << endl -#define sz(x) (int)(x.size()) -#define yesno(x) cout << ((x) ? ""YES\n"" : ""NO\n"") -#define rep(i, a, b) for(int i = a; i < b; ++i) -#define rrep(i, a, b) for(int i = a; i >= b; --i) - -// order_of_key (k) : Number of items strictly smaller than k. -// find_by_order(k) : K-th element in a set (counting from zero). -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; -typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_pset; -typedef long double lld; -using ull = unsigned long long; -const int N = 200200, INF = 8e18, MOD = 1000000007; // 1000000009, 1000000023, 1000000007, 998244353 - -template bool setmin(T &a, const T &b) {return b < a ? a = b, 1 : 0;} -template bool setmax(T &a, const T &b) {return b > a ? a = b, 1 : 0;} - -void dxt(int test_case); -void pre_pro(); -signed main(){ - ios_base::sync_with_stdio(false); cin.tie(NULL); - pre_pro(); - int T = 1; - cin >> T; - for (int i = 1; i <= T; i++) { - dxt(i); - } - return 0; -} - -void pre_pro(){ -} -void dxt(int test_case){ - string a,b,c; - cin >> a >> b >> c; - int n = sz(a); - int m = sz(b); - int k = sz(c); - - int dp[n + 1][m + 1][k + 1]; - memset(dp, 0, sizeof dp); - - rep(i, 0, n + 1){ - rep(j, 0, m + 1){ - rep(l, 0, k + 1){ - if(i == 0 && j == 0 && l == 0) continue; - dp[i][j][l] = INF; - if(i > 0) setmin(dp[i][j][l], dp[i - 1][j][l] + (a[i - 1] != c[i + j - 1])); - if(j > 0) setmin(dp[i][j][l], dp[i][j - 1][l] + (b[j - 1] != c[i + j - 1])); - if(l > 0) setmin(dp[i][j][l], dp[i][j][l - 1] + (c[i + j - 1] != c[i + j - 1])); - } - } - } - show(dp[n][m][k]); -}","/** -* created: 2024-12-23 07:51:30 -**/ -#include -#include -#include -using namespace __gnu_pbds; -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""../debug.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -#define int long long -#define all(v) (v).begin(),(v).end() -#define allr(v) (v).rbegin(),(v).rend() -#define show(x) cout << x << endl -#define sz(x) (int)(x.size()) -#define yesno(x) cout << ((x) ? ""YES\n"" : ""NO\n"") -#define rep(i, a, b) for(int i = a; i < b; ++i) -#define rrep(i, a, b) for(int i = a; i >= b; --i) - -// order_of_key (k) : Number of items strictly smaller than k. -// find_by_order(k) : K-th element in a set (counting from zero). -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; -typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> ordered_pset; -typedef long double lld; -using ull = unsigned long long; -const int N = 200200, INF = 8e18, MOD = 1000000007; // 1000000009, 1000000023, 1000000007, 998244353 - -template bool setmin(T &a, const T &b) {return b < a ? a = b, 1 : 0;} -template bool setmax(T &a, const T &b) {return b > a ? a = b, 1 : 0;} - -void dxt(int test_case); -void pre_pro(); -signed main(){ - ios_base::sync_with_stdio(false); cin.tie(NULL); - pre_pro(); - int T = 1; - cin >> T; - for (int i = 1; i <= T; i++) { - dxt(i); - } - return 0; -} - -void pre_pro(){ -} -void dxt(int test_case){ - string a,b,c; - cin >> a >> b >> c; - int n = sz(a); - int m = sz(b); - int k = sz(c); - - int dp[n + 1][m + 1]; - memset(dp, 0, sizeof dp); - rep(i, 0, n + 1){ - rep(j, 0, m + 1){ - if(i == 0 && j == 0) continue; - if(i == 0){ - dp[i][j] = dp[i][j - 1] + (b[j - 1] != c[i + j - 1]); - }else if(j == 0){ - dp[i][j] = dp[i - 1][j] + (a[i - 1] != c[i + j - 1]); - }else{ - dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - } - show(dp[n][m]); -}",2 -Bhoomish_Patel,2050E - Three Strings,c++23 ,298462784,298462581,"#include -using namespace std; -#define ll long long -int mod=1e9+7; - -void solve(){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(); - int m=b.size(); - int l=c.size(); - vector>dp(n+1,vector(m+1,1e9)); - dp[0][0]=0; - for(int i=1;i<=n;i++){ - if(c[i-1]==a[i-1]){ - dp[i][0]=dp[i-1][0]; - } - else{ - dp[i][0]=dp[i-1][0]+1; - } - } - for(int i=1;i<=m;i++){ - if(c[i-1]==b[i-1]){ - dp[0][i]=dp[0][i-1]; - } - else{ - dp[0][i]=dp[0][i-1]+1; - } - } - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++){ - dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), - dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - cout<>t; - while(t--)solve(); - return 0; -}","#include -using namespace std; -#define ll long long -int mod=1e9+7; - -void solve(){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(); - int m=b.size(); - int l=c.size(); - vector>dp(n+1,vector(m+1,1e9)); - dp[0][0]=0; - for(int i=1;i<=n;i++){ - if(c[i-1]==a[i-1]){ - dp[i][0]=dp[i-1][0]; - } - else{ - dp[i][0]=dp[i-1][0]+1; - } - } - for(int i=1;i<=m;i++){ - if(c[i-1]==b[i-1]){ - dp[0][i]=dp[0][i-1]; - } - else{ - dp[0][i]=dp[0][i-1]+1; - } - } - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++){ - if(c[i+j-1]==a[i-1]){ - dp[i][j]=min(dp[i][j],dp[i-1][j]); - } - if(c[i+j-1]==b[j-1]){ - dp[i][j]=min(dp[i][j],dp[i][j-1]); - } - else{ - dp[i][j]=min(dp[i][j],min(dp[i-1][j]+1,dp[i][j-1]+1)); - } - } - } - cout<>t; - while(t--)solve(); - return 0; -}",1 -aspirers02,2050E - Three Strings,c++20 ,296126787,296126000,"// <-------GAUTAM KUMAR SHAH-------> -#include -using namespace std; -#define ll long long int -const long long mod=1e9+7; -#define loop(i,n) for(int i=0;i0;i--) -#define cin(arr,n) for(int i=0;i>arr[i]; -#define loopv(i,k,n) for(int i=k;i -#define mi map -ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod -ll mminv(ll a) {return mod_expo(a, mod-2);} -ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} -ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} -ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} -ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;} //only for prime m -ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i> &dp){ - int a1=a.size(); - int b1=b.size(); - int c1=c.size(); - - int k=i+j; - if(k==a1+b1){ - return 0; - } - if(dp[i][j]!=-1){ - return dp[i][j]; - } - int pick1=INT_MAX,npick1=INT_MAX,pick2=INT_MAX,npick2=INT_MAX; - if(a[i]==c[k] && i>t; - while(t--) - { - - string a,b,c; - cin>>a>>b>>c; - int n1=a.size(); - int n2=b.size(); - vector> dp(n1+5,vector(n2+5,-1)); - int ans=solve(a,b,c,0,0,dp); - cout< -#include -using namespace std; -#define ll long long int -const long long mod=1e9+7; -#define loop(i,n) for(int i=0;i0;i--) -#define cin(arr,n) for(int i=0;i>arr[i]; -#define loopv(i,k,n) for(int i=k;i -#define mi map -ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod -ll mminv(ll a) {return mod_expo(a, mod-2);} -ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} -ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} -ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} -ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;} //only for prime m -ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i>t; - while(t--) - { - string a,b,c; - cin>>a>>b>>c; - int ans=solve(a,b,c,0,0); - cout< -using namespace std; - -#define ll long long -#define FORI(i, n) for(ll i = 0; i < n; i++) -#define FOR(i, n) for(ll i = 1; i <= n; i++) -typedef vector < ll > vl; -typedef set < ll > setl; -#define ff first -#define ss second -#define all(v) v.begin(), v.end() -#define pll pair -#define db double -#define nll cout << ""\n"" -#define nl ""\n"" -#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); - -const ll mod = 1000007; -const int MAX = 1e3 + 5; -const int imax = 2147483647; -ll n, m, k, res; -string a, b, c; -void solve(){ - cin >> a >> b >> c; - n = a.size(); - m = b.size(); - a = '0' + a; - b = '0' + b; - c = '0' + c; - vector < vl > dp(n + 5, vl (m + 5, INT_MAX)); - dp[0][0] = 0; - FORI(i, n + 1){ - FORI(j, m + 1){ - if(!i && !j)break; - if(!i){ - dp[i][j] = dp[i][j - 1] + 1; - } - else if(!j)dp[i][j] = dp[i - 1][j] + 1; - else dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1); - if(i && c[i + j] == a[i]){ - dp[i][j] = min(dp[i][j], dp[i - 1][j]); - } - if(j && c[i + j] == b[j]){ - dp[i][j] = min(dp[i][j], dp[i][j - 1]); - } - } - } - cout << dp[n][m]; -} -signed main(){ - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - sync; - ll t = 1; - cin >> t; - FOR(i, t){ - // cout << ""Case #"" << i << "": ""; - solve(); - nll; - } -}","#include -using namespace std; - -#define ll long long -#define FORI(i, n) for(ll i = 0; i < n; i++) -#define FOR(i, n) for(ll i = 1; i <= n; i++) -typedef vector < ll > vl; -typedef set < ll > setl; -#define ff first -#define ss second -#define all(v) v.begin(), v.end() -#define pll pair -#define db double -#define nll cout << ""\n"" -#define nl ""\n"" -#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); - -const ll mod = 1000007; -const int MAX = 1e3 + 5; -const int imax = 2147483647; -ll n, m, k, res; -string a, b, c; -void solve(){ - cin >> a >> b >> c; - n = a.size(); - m = b.size(); - a = '0' + a; - b = '0' + b; - c = '0' + c; - vector < vl > dp(n + 5, vl (m + 5, INT_MAX)); - dp[0][0] = 0; - FORI(i, n + 1){ - FORI(j, m + 1){ - if(!i && !j)continue; - if(!i){ - dp[i][j] = dp[i][j - 1] + 1; - } - else if(!j)dp[i][j] = dp[i - 1][j] + 1; - else dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1); - if(i && c[i + j] == a[i]){ - dp[i][j] = min(dp[i][j], dp[i - 1][j]); - } - if(j && c[i + j] == b[j]){ - dp[i][j] = min(dp[i][j], dp[i][j - 1]); - } - } - } - cout << dp[n][m]; -} -signed main(){ - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - sync; - ll t = 1; - cin >> t; - FOR(i, t){ - // cout << ""Case #"" << i << "": ""; - solve(); - nll; - } -}",2 -deevijbansal,2050E - Three Strings,c++17 ,297649167,297649541,"#include -using namespace std; - -typedef long long ll; - -int dp(string a, string b, string c, int ia, int ib, vector> arr) -{ - if (ia == a.size() && ib == b.size()) - { - return 0; - } - - int left = INT_MAX, right = INT_MAX; - - if (ia < a.size()) - { - if (arr[ia + 1][ib] != -1) - { - left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]); - } - else - { - left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]); - } - } - if (ib < b.size()) - { - if (arr[ia][ib + 1] != -1) - { - right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]); - } - else - { - right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]); - } - } - - arr[ia][ib] = min(left, right); - return arr[ia][ib]; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - - vector> arr(a.size() + 1, vector(b.size() + 1, -1)); - - cout << dp(a, b, c, 0, 0, arr) << endl; - } - - return 0; -}","#include -using namespace std; - -typedef long long ll; - -int dp(string &a, string &b, string &c, int ia, int ib, vector> &arr) -{ - if (ia == a.size() && ib == b.size()) - { - return 0; - } - - if (arr[ia][ib] != -1) - { - return arr[ia][ib]; - } - - int left = INT_MAX, right = INT_MAX; - - if (ia < a.size()) - { - if (arr[ia + 1][ib] != -1) - { - left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]); - } - else - { - left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]); - } - } - if (ib < b.size()) - { - if (arr[ia][ib + 1] != -1) - { - right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]); - } - else - { - right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]); - } - } - - arr[ia][ib] = min(left, right); - return arr[ia][ib]; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - - vector> arr(a.size() + 1, vector(b.size() + 1, -1)); - - cout << dp(a, b, c, 0, 0, arr) << endl; - } - - return 0; -}",2 -Shekher.Rishi,2050E - Three Strings,c++23 ,295764621,295830970,"#include -using namespace std; -#define ull unsigned long long -#define int long long - -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - ull t;cin >> t; - - while (t--) { - - string a, b, c; cin >>a >> b >> c; - int l1 = a.length(),l2=b.length(),l3=c.length(); - vector prev(l3,0),curr(l3); - for (int i = 0;i < l1;i++) { - for (int j = 0;j < l3;j++) { - if (j != 0){ - if (a[i] == c[j]) curr[j] = 1 + prev[j - 1]; - else curr[j] = max(curr[j - 1], prev[j]); - } - else { - if (a[i] == c[j]) curr[j] = 1 ; - else curr[j] = prev[j]; - } - - } - prev = curr; - } - int a1 = curr[l3 - 1];string n; - int count = 0;vectorr; - for (int j = 0;j < l3;j++) { - if (curr[j] <=count) { - - n += string(1,c[j]); - } - else count = curr[j]; - } - l3 = n.size(); - vector prev1(l3, 0), curr1(l3); - for (int i = 0;i < l2;i++) { - for (int j = 0;j < l3;j++) { - if (j != 0) { - if (b[i] == n[j]) curr1[j] = 1 + prev1[j - 1]; - else curr1[j] = max(curr1[j - 1], prev1[j]); - } - else { - if (b[i] == n[j]) curr1[j] = 1; - else curr1[j] = prev1[j]; - } - - } - prev1 = curr1; - } - int a2 = curr[l3 - 1]; - cout << c.size() - a1 - a2< -using namespace std; -#define ull unsigned long long -#define int long long - -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - ull t;cin >> t; - - while (t--) { - - string a, b, c; cin >>a >> b >> c; - int x = a.length(); - int y = b.length(); - int z = c.length(); - vector> dp(x+1, vector(y+1)); - dp[0][0] = 0; - for (int i = 1;i <= x;i++) dp[i][0] = dp[i - 1][0] + (int)(a[i - 1] != c[i - 1]); - for (int j = 1;j <= y;j++) dp[0][j] = dp[0][j-1] + (int)(b[j - 1] != c[j - 1]); - for (int i = 1;i <= x;i++) { - for (int j = 1;j <= y;j++) { - if (c[i + j - 1] != a[i - 1] && c[i + j - 1] != b[j - 1]) { - dp[i][j] = min(dp[i - 1][j]+1, dp[i][j - 1]+1); - } - if (c[i + j - 1] == a[i - 1] && c[i + j - 1] != b[j - 1]) { - dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] + 1); - } - if (c[i + j - 1] != a[i - 1] && c[i + j - 1] == b[j - 1]) { - dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] ); - } - if (c[i + j - 1] == a[i - 1] && c[i + j - 1] == b[j - 1]) { - dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] ); - } - } - } - cout << dp[x][y] << endl; - - - } - return 0; -}",2 -deadnecro18,2050E - Three Strings,c++23 ,297064172,297063124,"#include -using namespace std; - -#define ll long long int - -ll power(ll a, ll b) { if (b == 0) { return 1; } ll res = power(a, b/2); if (b%2) { return res*res*a; } else { return res*res; } } - -ll lcm (ll a, ll b) { return ((a*b)/(__gcd(a,b))); } - -ll cnt = 0; - -ll func(string &a, string &b, string &c, vector > &dp, ll indexa, ll indexb, ll indexc, ll &n1, ll &n2, ll &n3) { - cnt++; - - ll r1 = 1e9; - ll r2 = 1e9; - - if (indexc == n3) { - return 0; - } - - // if (indexa == n1) { - // if (b[indexb] == c[indexc] && indexb> t; - - while(t--) { - string a,b,c; - cin >> a >> b >> c; - ll n1 = a.length(); - ll n2 = b.length(); - ll n3 = c.length(); - vector > dp(n1+1, vector (n2+1, -1)); - - ll ans = func(a,b,c,dp,0LL,0LL,0LL, n1, n2, n3); - cout << ans << endl; - } - // cout << cnt << endl; - // cerr << endl << ""Execution Took: "" << 1000 * clock() / CLOCKS_PER_SEC << "" ms."" << endl; -}","#include -using namespace std; - -#define ll long long int - -ll power(ll a, ll b) { if (b == 0) { return 1; } ll res = power(a, b/2); if (b%2) { return res*res*a; } else { return res*res; } } - -ll lcm (ll a, ll b) { return ((a*b)/(__gcd(a,b))); } - -ll cnt = 0; - -ll func(string a, string b, string c, vector > &dp, ll indexa, ll indexb, ll indexc, ll n1, ll n2 , ll n3) { - cnt++; - - ll r1 = 1e9; - ll r2 = 1e9; - - if (indexc == n3) { - return 0; - } - if (dp[indexa][indexb] != -1) { - return dp[indexa][indexb]; - } - if (indexa == n1) { - if (b[indexb] == c[indexc] && indexb> t; - - while(t--) { - string a,b,c; - cin >> a >> b >> c; - vector > dp(1001, vector (1001, -1)); - ll n1 = a.length(); - ll n2 = b.length(); - ll n3 = c.length(); - ll ans = func(a,b,c,dp,0LL,0LL,0LL, n1 , n2 , n3); - cout << ans << endl; - } - //cout << cnt << endl; -}",1 -LonggVuz,2050E - Three Strings,c++23 ,307175372,307175155,"// LonggVuz - -#include - -using namespace std; - -// ☞ Kuroba Kaito ☜ - -#define fod(i, a, b, c) for(int i=a; i<=b; i+=c) - -#define fo(i, n) for(int i=1; i<=n; i++) - -#define out(x) return cout << x, void() - -#define all(x) x.begin(), x.end() - -#define len(x) (int)x.size() - -#define el '\n' - -#define int int64_t - - - -const int mod = 1e9 + 7; - -const int oo = 1e16 + 8; - -const int mxn = 1e6 + 9; - - - -int dp[2005][2005]; - - - -void LonggVuz(){ - - string a, b, c; cin >> a >> b >> c; - - int n = len(a), m = len(b); - - a = "" "" + a; b = "" "" + b; c = "" "" + c; - - fo(i, n) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]); - - fo(i, m) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]); - - fo(i, n){ - - fo(j, m){ - - if(a[i] == b[j]){ - - if(c[i + j] == a[i]){ - - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]); - - }else dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - - }else{ - - if(a[i] == c[i + j]){ - - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1); - - }else if(b[j] == c[i + j]){ - - dp[i][j] = min(dp[i][j - 1], dp[i - 1][j] + 1); - - }else dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - - } - - } - - } - - cout << dp[n][m]; - - fo(i, n) fo(j, m) dp[i][j] = oo; - -} - - - -signed main(){ - - cin.tie(0) -> sync_with_stdio(0); - - - - int tc = 1; cin >> tc; - - while(tc--){ - - LonggVuz(); - - if(tc) cout << el; - - } - - - - cerr << ""Execution Time: "" << 0.001 * clock() << ""s\n""; - -}","// LonggVuz - -#include - -using namespace std; - -// ☞ Kuroba Kaito ☜ - -#define fod(i, a, b, c) for(int i=a; i<=b; i+=c) - -#define fo(i, n) for(int i=1; i<=n; i++) - -#define out(x) return cout << x, void() - -#define all(x) x.begin(), x.end() - -#define len(x) (int)x.size() - -#define el '\n' - -#define int int64_t - - - -const int mod = 1e9 + 7; - -const int oo = 1e16 + 8; - -const int mxn = 1e6 + 9; - - - -int dp[2005][2005]; - - - -void LonggVuz(){ - - string a, b, c; cin >> a >> b >> c; - - int n = len(a), m = len(b); - - a = "" "" + a; b = "" "" + b; c = "" "" + c; - - fo(i, n) dp[i][0] = dp[i - 1][0] + (a[i] != c[i]); - - fo(i, m) dp[0][i] = dp[0][i - 1] + (b[i] != c[i]); - - fo(i, n){ - - fo(j, m){ - - if(a[i] == b[j]){ - - if(c[i + j] == a[i]){ - - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]); - - }else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i][j - 1], dp[i - 1][j])) + 1; - - }else{ - - if(a[i] == c[i + j]){ - - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1); - - }else if(b[j] == c[i + j]){ - - dp[i][j] = min(dp[i][j - 1], dp[i - 1][j] + 1); - - }else dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - - } - - } - - } - - cout << dp[n][m]; - - fo(i, n) fo(j, m) dp[i][j] = oo; - -} - - - -signed main(){ - - cin.tie(0) -> sync_with_stdio(0); - - - - int tc = 1; cin >> tc; - - while(tc--){ - - LonggVuz(); - - if(tc) cout << el; - - } - - - - cerr << ""Execution Time: "" << 0.001 * clock() << ""s\n""; - -}",1 -Ludissey,2050E - Three Strings,c++20 ,296165299,296166218,"#include -#define int long long -#define sz(a) (int)a.size() -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(nullptr); - int t; cin >>t; - while(t--){ - string a; string b; string c; cin >> a >> b >> c; - vector> dp(sz(a)+1,vector(sz(b)+1,1e9)); - dp[0][0]=0; - for (int k = 0; k < sz(c); k++) - { - for (int i = 0; i <= min(k,sz(a)-1)+1; i++) - { - int j=(k+1)-i; - if(i>0){ - dp[i][j]=dp[i-1][j]; - if(c[k]!=a[i-1]) dp[i][j]++; - } - if(j>0){ - if(c[k]!=b[j-1]) dp[i][j]=min(dp[i][j-1]+1,dp[i][j]); - else dp[i][j]=min(dp[i][j-1],dp[i][j]); - } - } - } - cout << dp[sz(a)][sz(b)] << ""\n""; - } - return 0; -}","#include -#define int long long -#define sz(a) (int)a.size() -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(nullptr); - int t; cin >>t; - while(t--){ - string a; string b; string c; cin >> a >> b >> c; - vector> dp(sz(a)+1,vector(sz(b)+1,1e9)); - dp[0][0]=0; - for (int k = 0; k < sz(c); k++) - { - for (int i = 0; i <= min(k,sz(a)-1)+1; i++) - { - int j=(k+1)-i; - if(j>sz(b)) continue; - if(i>0){ - dp[i][j]=dp[i-1][j]; - if(c[k]!=a[i-1]) dp[i][j]++; - } - if(j>0){ - if(c[k]!=b[j-1]) dp[i][j]=min(dp[i][j-1]+1,dp[i][j]); - else dp[i][j]=min(dp[i][j-1],dp[i][j]); - } - } - } - cout << dp[sz(a)][sz(b)] << ""\n""; - } - return 0; -}",2 -bapujiiii,2050E - Three Strings,c++17 ,296113460,296113297,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define endl ""\n"" -#define float long double -#define int long long int -#define ll long long -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define mod 1000000007 -#define PI 3.141592653589793238462643383279 -#define all(v) (v).begin(), (v).end() -#define rall(v) (v).rbegin(), (v).rend() -#define pb push_back -void solve(){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(),m=b.size(),sz=c.size(); - vector> dp(sz+1,vector (n+1,1e9)); - dp[0][0]=0; - for(int i=1;i<=sz;i++){ - for(int j=0;j<=n;j++){ - if(i-j<=m && i-j>0)dp[i][j]=min(dp[i-1][j]+!(b[i-j-1]==c[i-1]),dp[i][j]); - if(j>0)dp[i][j]=min(dp[i-1][j-1]+!(a[j-1]==c[i-1]),dp[i][j]); - } - } - cout<> t; - while (t--) - { - solve(); - } - return 0; -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define endl ""\n"" -#define float long double -#define int long long int -#define ll long long -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define mod 1000000007 -#define PI 3.141592653589793238462643383279 -#define all(v) (v).begin(), (v).end() -#define rall(v) (v).rbegin(), (v).rend() -#define pb push_back -void solve(){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(),m=b.size(),sz=c.size(); - vector> dp(sz+1,vector (n+1,1e9)); - dp[0][0]=0; - for(int i=1;i<=sz;i++){ - for(int j=0;j<=n;j++){ - if(i-j<=m)dp[i][j]=min(dp[i-1][j]+!(b[i-j-1]==c[i-1]),dp[i][j]); - dp[i][j]=min(dp[i-1][j-1]+!(a[j-1]==c[i-1]),dp[i][j]); - } - } - cout<> t; - while (t--) - { - solve(); - } - return 0; -}",1 -aspirers02,2050E - Three Strings,c++20 ,296126787,296119816,"// <-------GAUTAM KUMAR SHAH-------> -#include -using namespace std; -#define ll long long int -const long long mod=1e9+7; -#define loop(i,n) for(int i=0;i0;i--) -#define cin(arr,n) for(int i=0;i>arr[i]; -#define loopv(i,k,n) for(int i=k;i -#define mi map -ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod -ll mminv(ll a) {return mod_expo(a, mod-2);} -ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} -ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} -ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} -ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;} //only for prime m -ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i> &dp){ - int a1=a.size(); - int b1=b.size(); - int c1=c.size(); - - int k=i+j; - if(k==a1+b1){ - return 0; - } - if(dp[i][j]!=-1){ - return dp[i][j]; - } - int pick1=INT_MAX,npick1=INT_MAX,pick2=INT_MAX,npick2=INT_MAX; - if(a[i]==c[k] && i>t; - while(t--) - { - - string a,b,c; - cin>>a>>b>>c; - int n1=a.size(); - int n2=b.size(); - vector> dp(n1+5,vector(n2+5,-1)); - int ans=solve(a,b,c,0,0,dp); - cout< -#include -using namespace std; -#define ll long long int -const long long mod=1e9+7; -#define loop(i,n) for(int i=0;i0;i--) -#define cin(arr,n) for(int i=0;i>arr[i]; -#define loopv(i,k,n) for(int i=k;i -#define mi map -ll mod_expo(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} // (a^b)%mod -ll mminv(ll a) {return mod_expo(a, mod-2);} -ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} -ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} -ll mod_sub(ll a, ll b) {a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} -ll mod_div(ll a, ll b) {a = a % mod; b = b % mod; return (mod_mul(a, mminv(b)) + mod) % mod;} //only for prime m -ll nCr(ll n,ll r) {if (r==0 || n==0) return 1; ll fac[n+1];fac[0]=1; for(int i = 1; i>t; - while(t--) - { - string a,b,c; - cin>>a>>b>>c; - int ans=solve(a,b,c,0,0); - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pqi priority_queue -#define pi pair -#define mi map -#define vi vector -#define vvi vector> - -using namespace std; - -int gcd(int a, int b){ - //a>b - if(b==0) return a; - return gcd(b,a%b); -} -istream &operator>>(istream &is, vector &vec) -{ -// vec.clear(); - int num; - while (is >> num) - { - vec.push_back(num); - char ch = is.peek(); - if (ch == '\n') - { - is.ignore(); - break; - } - } - return is; -} - -void print(vector v){ - for(auto it:v) cout << it <<' '; - cout < prefixSum(vector v ){ - vector ans; - int sum=0; - for (int i =0; i < v.size();i++){ - sum+=v[i]; - ans.push_back(sum); - } - return ans; -} -void print(const vector> arr) { - for (const std::vector& row : arr) { - for (int num : row) { - - std::cout << num << "" ""; - } - std::cout << std::endl; - } -} -void print (const map& sum) { - for (const auto& pair : sum) { - int key = pair.first; - const vi& values = pair.second; - - cout << ""Key: "" << key << "" -> Values: [""; - for (size_t i = 0; i < values.size(); ++i) { - cout << values[i]; - if (i < values.size() - 1) { - cout << "", ""; - } - } - cout << ""]"" << endl; - } -} -void print( vector>& cycles) { - for (const auto& cycle : cycles) { - cout << ""{ ""; - for (auto it = cycle.begin(); it != cycle.end(); ++it) { - cout << *it; - if (next(it) != cycle.end()) { - cout << "", ""; - } - } - cout << "" }"" << endl; - } -} -const int mod = 1e9 + 7; -const int N= 2e5 + 5; -int64_t fact[N]; -int64_t pw(int64_t a, int64_t b) { - int64_t r = 1; - while(b > 0) { - if(b & 1) r = (r * a) % mod; - b /= 2; - a = (a * a) % mod; - } - return r; -} -int64_t C(int64_t n, int64_t k) { - if(n < k) return 0LL; - return (fact[n] * pw((fact[n - k] * fact[k]) % mod, mod - 2)) % mod; -} - - -int modInverse(int a, int m) { - int result = 1; - int exp = m - 2; - while (exp > 0) { - if (exp % 2 == 1) { - result = (result * a) % m; - } - a = (a * a) % m; - exp /= 2; - } - return result; -} -vector getDivisors(int n) { - std::vector divisors; - - // Loop from 1 to sqrt(n) to find divisors - for (int i = 1; i <= std::sqrt(n); ++i) { - if (n % i == 0) { - divisors.push_back(i); - // If i is not equal to n / i, add the corresponding divisor - if (i != n / i) { - divisors.push_back(n / i); - } - } - } - - sort(divisors.begin(), divisors.end()); - return divisors; - -} - -int check(vi a, int d){ - int n = a.size(); - int m = 0, r = n-1, l = 0; - int spare = 0 ; - // cout << ""d=""< d){ - spare += (a[l] - d); - }else if( a[l] < d){ - spare -= (d-a[l]); - m += (d-a[l]); - while( spare < 0){ - int k = min(a[r], -1* spare); - spare += k; - a[r] -= k; - if (a[r] == 0) r--; - } - } - l++; - } - // cout << ""spare ""<< spare << endl; - return m + spare; -} - -int f (int i, int j, string a, string b, string c, vector > &dp){ - int k = i + j; - if(k == c.size()){ - return 0; - } - - if (dp[i][j] != -1) return dp[i][j]; - - int ans = INT_MAX; - - if(i < a.size()){ - - int t = f ( i+1 , j , a ,b ,c , dp); - //match - if(a[i] == c[k]){ - ans = min (ans, t); - } - //changed - ans = min ( ans, t + 1); - - } - if( j < b.size()){ - int t = f ( i , j+1 , a ,b ,c , dp); - //match - if(b[j] == c[k]){ - ans = min (ans, t); - } - //changed - ans = min ( ans, t + 1); - } - - return dp[i][j] = ans; - -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - - // dp[i][j] represents minimum operations needed when we've used - // i characters from string a and j characters from string b - vector> dp(a.size() + 1, vector(b.size() + 1, INT_MAX)); - - // Base case - when we haven't used any characters - dp[0][0] = 0; - - // Fill dp table - for(int i = 0; i <= a.size(); i++) { - for(int j = 0; j <= b.size(); j++) { - // Skip invalid states - if(dp[i][j] == INT_MAX) continue; - - int k = i + j; // position in string c - if(k == c.size()) continue; // we've formed the complete string - - // Try taking character from string a - if(i < a.size()) { - int cost = (a[i] == c[k]) ? 0 : 1; - dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost); - } - - // Try taking character from string b - if(j < b.size()) { - int cost = (b[j] == c[k]) ? 0 : 1; - dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cost); - } - } - } - - // Find answer when we've used all characters needed to form string c - int result = INT_MAX; - for(int i = 0; i <= a.size(); i++) { - for(int j = 0; j <= b.size(); j++) { - if(i + j == c.size()) { - result = min(result, dp[i][j]); - } - } - } - - cout << (result == INT_MAX ? -1 : result) << endl; -} - -int32_t main() -{ - - ios_base ::sync_with_stdio(false); - cin.tie(NULL); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - int T = 1; - -// fact[0] = 1; -// for(int64_t i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod; -// - cin >> T; - - while (T--) - { - solve(); - } - - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pqi priority_queue -#define pi pair -#define mi map -#define vi vector -#define vvi vector> - -using namespace std; - -int gcd(int a, int b){ - //a>b - if(b==0) return a; - return gcd(b,a%b); -} -istream &operator>>(istream &is, vector &vec) -{ -// vec.clear(); - int num; - while (is >> num) - { - vec.push_back(num); - char ch = is.peek(); - if (ch == '\n') - { - is.ignore(); - break; - } - } - return is; -} - -void print(vector v){ - for(auto it:v) cout << it <<' '; - cout < prefixSum(vector v ){ - vector ans; - int sum=0; - for (int i =0; i < v.size();i++){ - sum+=v[i]; - ans.push_back(sum); - } - return ans; -} -void print(const vector> arr) { - for (const std::vector& row : arr) { - for (int num : row) { - - std::cout << num << "" ""; - } - std::cout << std::endl; - } -} -void print (const map& sum) { - for (const auto& pair : sum) { - int key = pair.first; - const vi& values = pair.second; - - cout << ""Key: "" << key << "" -> Values: [""; - for (size_t i = 0; i < values.size(); ++i) { - cout << values[i]; - if (i < values.size() - 1) { - cout << "", ""; - } - } - cout << ""]"" << endl; - } -} -void print( vector>& cycles) { - for (const auto& cycle : cycles) { - cout << ""{ ""; - for (auto it = cycle.begin(); it != cycle.end(); ++it) { - cout << *it; - if (next(it) != cycle.end()) { - cout << "", ""; - } - } - cout << "" }"" << endl; - } -} -const int mod = 1e9 + 7; -const int N= 2e5 + 5; -int64_t fact[N]; -int64_t pw(int64_t a, int64_t b) { - int64_t r = 1; - while(b > 0) { - if(b & 1) r = (r * a) % mod; - b /= 2; - a = (a * a) % mod; - } - return r; -} -int64_t C(int64_t n, int64_t k) { - if(n < k) return 0LL; - return (fact[n] * pw((fact[n - k] * fact[k]) % mod, mod - 2)) % mod; -} - - -int modInverse(int a, int m) { - int result = 1; - int exp = m - 2; - while (exp > 0) { - if (exp % 2 == 1) { - result = (result * a) % m; - } - a = (a * a) % m; - exp /= 2; - } - return result; -} -vector getDivisors(int n) { - std::vector divisors; - - // Loop from 1 to sqrt(n) to find divisors - for (int i = 1; i <= std::sqrt(n); ++i) { - if (n % i == 0) { - divisors.push_back(i); - // If i is not equal to n / i, add the corresponding divisor - if (i != n / i) { - divisors.push_back(n / i); - } - } - } - - sort(divisors.begin(), divisors.end()); - return divisors; - -} - -int check(vi a, int d){ - int n = a.size(); - int m = 0, r = n-1, l = 0; - int spare = 0 ; - // cout << ""d=""< d){ - spare += (a[l] - d); - }else if( a[l] < d){ - spare -= (d-a[l]); - m += (d-a[l]); - while( spare < 0){ - int k = min(a[r], -1* spare); - spare += k; - a[r] -= k; - if (a[r] == 0) r--; - } - } - l++; - } - // cout << ""spare ""<< spare << endl; - return m + spare; -} - -int f (int i, int j, string a, string b, string c, vector > &dp){ - int k = i + j; - if(k == c.size()){ - return 0; - } - - if (dp[i][j] != -1) return dp[i][j]; - - int ans = INT_MAX; - - if(i < a.size()){ - - int t = f ( i+1 , j , a ,b ,c , dp); - //match - if(a[i] == c[k]){ - ans = min (ans, t); - } - //changed - ans = min ( ans, t + 1); - - } - if( j < b.size()){ - int t = f ( i , j+1 , a ,b ,c , dp); - //match - if(b[j] == c[k]){ - ans = min (ans, t); - } - //changed - ans = min ( ans, t + 1); - } - - return dp[i][j] = ans; - -} - -void solve() -{ - string a , b, c; - cin >> a >> b >>c; - vector > dp (a.size() + 1, vector (b.size() + 1, -1)); - cout << f(0,0,a,b,c, dp)<> T; - - while (T--) - { - solve(); - } - - return 0; -} -",1 -bananabomb141,2050E - Three Strings,python,295699329,295700205,"import math -def solve(): - a = input() - b = input() - c = input() - - n1,n2,n3 = len(a),len(b),len(c) - - dp = {} - def util(i,j,k): - if k >= n3: - return 0 - - if (i,j,k) in dp: - return dp[(i,j,k)] - - res = 1+min(util(i+1,j,k+1),util(i,j+1,k+1)) - if i 0: - solve() - t -= 1 - - - -","def solve(): - # Read input strings - s1 = input() - s2 = input() - s3 = input() - - n = len(s1) - m = len(s2) - - # If lengths don't match the requirements, it's impossible - if len(s3) != n + m: - print(-1) - return - - # Create DP table - dp = [[float('inf')] * (m + 1) for _ in range(n + 1)] - dp[0][0] = 0 # Base case: empty strings need 0 changes - - # Fill dp table - for i in range(n + 1): - for j in range(m + 1): - if i + j == 0: - continue - - # Current position in s3 we're trying to match - k = i + j - 1 - - # Try taking from s1 - if i > 0: - cost = 0 if s1[i-1] == s3[k] else 1 - dp[i][j] = min(dp[i][j], dp[i-1][j] + cost) - - # Try taking from s2 - if j > 0: - cost = 0 if s2[j-1] == s3[k] else 1 - dp[i][j] = min(dp[i][j], dp[i][j-1] + cost) - - # Answer is in dp[n][m] - ans = dp[n][m] - print(ans if ans != float('inf') else -1) - -if __name__ == '__main__': - t = int(input()) - while t > 0: - solve() - t -= 1 - - - -",2 -uraghuvamshireddy,2050E - Three Strings,c++17 ,297451556,297449563,"#include -#define ll long long int -#define MOD 1000000007 -using namespace std; -int solve(int i,int j,string& s,string &n,string& m,vector>&dp){ - if(i==n.size() && j==m.size())return 0; - if(dp[i][j]!=-1)return dp[i][j]; - int ans=INT_MAX; - if(i> t; - while (t--) { - long long a,b,c=0,k,d=0,cnt=0,sum=0,ans=0,e=1; - string s,m,n; - cin>>n>>m>>s; - vector>dp(n.size()+1,vector(m.size()+1,-1)); - cout<< solve(0,0,s,n,m,dp)< - -using namespace std; - -int dp[100001][100001]; - -int solve(int i, int j, const string& a, const string& b, const string& res) { - if (i == a.size() && j == b.size()) { - return 0; - } - if (dp[i][j] != -1) { - return dp[i][j]; - } - int ans = INT_MAX; - if (i < a.size()) { - ans = min(ans, solve(i + 1, j, a, b, res) + (a[i] != res[i + j])); - } - if (j < b.size()) { - ans = min(ans, solve(i, j + 1, a, b, res) + (b[j] != res[i + j])); - } - dp[i][j] = ans; - return dp[i][j]; -} - -int main() { - int tests; - cin >> tests; - while (tests--) { - string a, b, res; - cin >> a >> b >> res; - fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(int), -1); - cout << solve(0, 0, a, b, res) << endl; - } -} -",1 -shahriyarsami,2050E - Three Strings,c++23 ,295885365,295888260,"#include - -using namespace std; - - -#define vi vector -#define pii pair -#define ll long long -#define pb push_back -#define el ""\n"" -#define all(a) a.begin(), a.end() -#define viin(n, vctr) {vctr.resize(n); for(auto &i : vctr) cin >> i;} -#define vllin(n, vctr) {vctr.resize(n); for(auto &i : vctr) cin >> i;} -#define YES cout << ""YES\n"" -#define NO cout << ""NO\n"" -int mod = 1e9 + 7; - - - -// Remove the loop if there is no testcase -void solve(){ - - string a, b, c; cin >> a >> b >> c; - vector dp(2005, vi(2005, 0)); - int sa = a.size(), sb = b.size(); - for(int i = 1; i <= sb; i++) - dp[0][i] = dp[0][i - 1] + (c[i - 1] != b[i - 1]); - for(int i = 1; i <= sa; i++) - dp[i][0] = dp[i - 1][0] + (c[i - 1] != a[i - 1]); - for(int i = 1; i <= sa; i++) - for(int j = 1; j <= sb; j++){ - dp[i][j] = min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1])); - } - - cout << dp[sa][sb] << el; - -} - -int main(){ - #ifdef LOCAL - // accept testcase inputs from file: input - freopen(""input.txt"", ""r"", stdin); - // output stdout to file: output - freopen(""output.txt"", ""w"", stdout); - auto begin = chrono::high_resolution_clock::now(); - #else - // Make cin and cout as fast as stdio - ios::sync_with_stdio(0); - cin.tie(0); - #endif - - int tt; cin >> tt; while(tt--) - solve(); - - #ifdef LOCAL - auto end = chrono::high_resolution_clock::now(); - auto elapsed = chrono::duration_cast (end - begin); - cout << el << ""Time elapsed: "" << (double)elapsed.count() << ""ms""; - #endif - return 0; -}","#include - -using namespace std; - - -#define vi vector -#define pii pair -#define ll long long -#define pb push_back -#define el ""\n"" -#define all(a) a.begin(), a.end() -#define viin(n, vctr) {vctr.resize(n); for(auto &i : vctr) cin >> i;} -#define vllin(n, vctr) {vctr.resize(n); for(auto &i : vctr) cin >> i;} -#define YES cout << ""YES\n"" -#define NO cout << ""NO\n"" -int mod = 1e9 + 7; - - - -// Remove the loop if there is no testcase -void solve(){ - - string a, b, c; cin >> a >> b >> c; - // vector dp(2005, vi(2005, 0)); - int dp[2005][2005]; - memset(dp, 0, sizeof dp); - int sa = a.size(), sb = b.size(); - for(int i = 1; i <= sb; i++) - dp[0][i] = dp[0][i - 1] + (c[i - 1] != b[i - 1]); - for(int i = 1; i <= sa; i++) - dp[i][0] = dp[i - 1][0] + (c[i - 1] != a[i - 1]); - for(int i = 1; i <= sa; i++) - for(int j = 1; j <= sb; j++){ - dp[i][j] = min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1])); - } - - cout << dp[sa][sb] << el; - -} - -int main(){ - #ifdef LOCAL - // accept testcase inputs from file: input - freopen(""input.txt"", ""r"", stdin); - // output stdout to file: output - freopen(""output.txt"", ""w"", stdout); - auto begin = chrono::high_resolution_clock::now(); - #else - // Make cin and cout as fast as stdio - ios::sync_with_stdio(0); - cin.tie(0); - #endif - - int tt; cin >> tt; while(tt--) - solve(); - - #ifdef LOCAL - auto end = chrono::high_resolution_clock::now(); - auto elapsed = chrono::duration_cast (end - begin); - cout << el << ""Time elapsed: "" << (double)elapsed.count() << ""ms""; - #endif - return 0; -}",2 -LazyEvaluator,2050E - Three Strings,c++23 ,298410290,298409194,"#include -#include -#include -#include -using namespace std; - -int findMinChanges(string& a, string& b, string& c) { - int len_a = a.size(), len_b = b.size(), len_c = c.size(); - if (len_a + len_b != len_c) return -1; - vector> dp(len_a + 1, vector(len_b + 1, INT_MAX)); - dp[0][0] = 0; - for (int s1 = 0; s1 <= len_a; ++s1) { - for (int s2 = 0; s2 <= len_b; ++s2) { - int s3 = s1 + s2; - if (s3 > len_c) break; - if (s1 < len_a && s3 < len_c) { - dp[s1 + 1][s2] = min(dp[s1 + 1][s2], dp[s1][s2] + (a[s1] != c[s3])); - } - if (s2 < len_b && s3 < len_c) { - dp[s1][s2 + 1] = min(dp[s1][s2 + 1], dp[s1][s2] + (b[s2] != c[s3])); - } - } - } - - return dp[len_a][len_b]; -} - -void solve() { - int t;cin>>t; - while(t--){ - string a, b, c; - cin >> a >> b >> c; - - int result = findMinChanges(a, b, c); - if (result == -1) { - cout << ""Impossible to merge"" << endl; - } else { - cout << result << endl; - } - } -} -int main(){ - solve(); -} -","// Every problem you solve is a step closer to mastering -// the art of thinking. Embrace the challenge, -// because every failure is just a lesson on your way to victory - -#include -using namespace std; - -// #include // For hash policy -#include // For acos - -using namespace std; -// using namespace __gnu_pbds; // For policy-based data structures -using ll = long long; // Type alias for long long -#define int long long -#define db double -#define MOP 998244353 -#define N 2e5 + 5 -#define fr(i, a, b) for (int i = a; i >= b; i--) -#define lcm(a, b) ((a) * (b)) / __gcd(a, b) -#define inp(a, n) \ - for (int r = 0; r < n; r++) \ - cin >> a[r] -#define out(a, n) \ - for (int v = 0; v < n; v++) \ - cout << a[v] << "" "" -#define f(i, a, b) for (ll i = a; i <= b; i++) -#define u(a, b) for (int i = 0; i < a; i++) -#define s(v) sort(v.begin(), v.end()) -#define sr(v) sort(v.end(), v.begin()) -#define MOD 1000000007 -#define ci(n) cin >> n -#define co(n) cout << n << "" "" -#define si(v) v.size() -#define py cout << ""YES"" << "" "" -#define pn cout << ""NO"" << "" "" -#define F first -#define ld long double -#define S second -#define pb(v, x) v.push_back(x) -#define pob(v) v.pop_back() -#define rev(v) reverse(v.begin(), v.end()) -#define revn(v) reverse(v.end(), v.begin()) -#define d_r(v) v.erase(unique(v.begin(), v.end()), v.end()); -#define en cout << endl -#define all(v) v.begin(), v.end() -#define len(str) str.length() -#define each(it, m) for (auto &it : m) -#define y_n(ans) \ - if (ans) \ - { \ - cout << ""YES""; \ - } \ - else \ - { \ - cout << ""NO""; \ - } -#include -#include -#ifdef DEBUG -#define dbg(...) __VA_ARGS__ -#else -#define dbg(...) -#endif -#define llmin LLONG_MIN -#define llmax LLONG_MAX -template -struct y_combinator_result -{ - F fi; - template - decltype(auto) operator()(Args &&...args) const - { - return fi(*this, std::forward(args)...); - } -}; -template -decltype(auto) y_combinator(F &&fi) -{ - return y_combinator_result>{std::forward(fi)}; -} -template -using V = vector; -template -using P = pair; -template -using pqmax = priority_queue; -template -using pqmin = priority_queue, greater>; -template -using UMP = unordered_map; -template -using MP = map; -template -using SE = set; -template -using USE = unordered_set; -struct pair_hash -{ - template - std::size_t operator()(const std::pair &pair) const - { - return std::hash()(pair.first) ^ std::hash()(pair.second); - } -}; -ll add(ll a, ll b, ll MO) { return ((a % MO + b % MO) % MO); } -long long factorialDP(ll n) -{ - vector dp(n + 1, 1); - for (ll i = 2; i <= n; ++i) - { - dp[i] = (1LL * dp[i - 1] * i) % MOD; - } - return (dp[n]); -} -bool binary(vector &v, int i, int j, int k) -{ - if (i >= j) - { - return false; - } - int mid = (i + j) / 2; - bool a = false, b = false; - if (v[i] == k || v[j] == k || v[mid] == k) - { - return true; - } - if (v[mid] < k) - { - a = binary(v, mid + 1, j, k); - } - if (v[mid] > k) - { - b = binary(v, i, mid, k); - } - return a || b; -} -int ternarySearch(vector &v, int left, int right, int key) { return (right >= left) ? ((v[left + (right - left) / 3] == key) ? left + (right - left) / 3 : ((v[right - (right - left) / 3] == key) ? right - (right - left) / 3 : ((key < v[left + (right - left) / 3]) ? ternarySearch(v, left, left + (right - left) / 3 - 1, key) : ((key > v[right - (right - left) / 3]) ? ternarySearch(v, right - (right - left) / 3 + 1, right, key) : ternarySearch(v, left + (right - left) / 3 + 1, right - (right - left) / 3 - 1, key))))) : -1; } -bool palindrome(vector &v) -{ - return (v.size() == 1) ? true : [&]() - { int x = v.size() / 2; for (int t = 0; t < x; t++) { if (v[t] != v[v.size() - t - 1]) return false; } return true; }(); -} -int xor_from_1(int n) { return ((n % 4 == 0) ? n : (n % 4 == 1) ? 1 - : (n % 4 == 2) ? n + 1 - : 0); } -void subsets(vector &v, int n) -{ - for (int i = 0; i < (1 << n); i++) - { - vector ans; - for (int j = 0; j < n; j++) - if (i & (1 << j)) - ans.push_back(v[j]); - for (auto it : ans) - cout << it << "" ""; - cout << endl; - } -} -string binary_rep(int n) -{ - if (n == 0) - { - return ""0""; - } - bitset<128> binary(n); - string ans = """"; - for (size_t g = 0; g < 64; g++) - ans += binary[g] + '0'; - rev(ans); - size_t it = ans.find_first_not_of('0'); - return ans.substr(it); -} -int search(vector &v, ll target) -{ - int low = 0, high = v.size() - 1; - while (low <= high) - { - int mid = low + (high - low) / 2; - if (v[mid] < target && v[mid + 1] > target) - return v[mid]; - if (v[mid] < target) - low = mid + 1; - else - high = mid - 1; - } - return high; -} -ll max_len_string(string str) -{ - ll len = 1, ans = 1; - ll n = str.length(); - f(i, 1, n - 1) - { - if (str[i] >= str[i - 1]) - len++; - else - { - ans = max(ans, len); - len = 1; - } - ans = max(ans, len); - } - return ans; -} -void dfs(string str, vector &dp, unordered_map> &m, int n, unordered_map &visited, int node) -{ - visited[node] = 1; - if (si(m[node]) == 0) - { - dp[node] = ((str[node - 1] == 'W') ? 1 : -1); - return; - } - for (auto it : m[node]) - { - if (!visited[it]) - { - dfs(str, dp, m, n, visited, it); - dp[node] += dp[it]; - } - } - dp[node] += ((str[node - 1] == 'W') ? 1 : -1); -} -ll nextint(ll a, ll b) -{ - ll x = ceil(((double)a) / (double)b); - return x; -} -void sieveOfEratosthenes(int n, vector &prime) -{ - prime[0] = prime[1] = false; - for (int p = 2; p * p <= n; p++) - if (prime[p]) - for (int i = p * p; i <= n; i += p) - prime[i] = false; -} -long long largestPrimeFactor(long long n) -{ - long long largest = -1; - while (n % 2 == 0) - { - largest = 2; - n /= 2; - } - for (long long i = 3; i <= sqrt(n); i += 2) - { - while (n % i == 0) - { - largest = i; - n /= i; - } - } - if (n > 2) - { - largest = n; - } - return largest; -} -bool isPalindrome(const std::string &str) { return std::equal(str.begin(), str.begin() + str.size() / 2, str.rbegin()); } -// #pragma once -// struct chash { // large odd number for C -// const uint64_t C = (long long)(4e18 * acos(0)) | 71; -// ll operator()(ll x) const { return __builtin_bswap64(x*C); } -// }; -// __gnu_pbds::gp_hash_table h({},{},{},{},{1<<16}); -struct custom_hash -{ - static uint64_t splitmix64(uint64_t x) - { - // http://xorshift.di.unimi.it/splitmix64.c - 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 - size_t operator()(const pair &p) const - { - auto h1 = (*this)(static_cast(p.first)); - auto h2 = (*this)(static_cast(p.second)); - return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2)); - } - template - size_t operator()(const vector &v) const - { - size_t seed = v.size(); - for (auto &i : v) - { - seed ^= (*this)(static_cast(i)) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } - return seed; - } -}; -long long countseti(long long n, int i) -{ - long long power = 1LL << i; - long long complete_blocks = (n + 1) / (2 * power); - long long remainder = (n + 1) % (2 * power); - long long count_set = complete_blocks * power + max(0LL, remainder - power); - return count_set; -} -ll getor(const ll L, const ll R) -{ - ll ans = 0; - y_combinator([&](const auto &self, const ll l, const ll r) -> void - { - if(r - size_t operator()(const pair &p) const - { - auto hash1 = hash{}(p.first); - auto hash2 = hash{}(p.second); - return hash1 ^ hash2; - } -}; -bool prime(int n) -{ - if (n <= 1) - return false; - if (n <= 3) - return true; - if (n % 2 == 0 || n % 3 == 0) - return false; - for (int i = 5; i <= sqrt(n); i += 6) - { - if (n % i == 0 || n % (i + 2) == 0) - return false; - } - return true; -} -int VAL; -int arr[(unsigned long)N]; -struct Query -{ - int l, r; - int id; - bool operator<(const Query &other) - { - if (l / VAL == other.l / VAL) - return r < other.r; - return l / VAL < other.l / VAL; - } -}; -vector queries; -class Mo_Algorithm -{ -private: - vector ans; // answer for each queries - vector freq; // frequency of values - int cur_l, cur_r; // current left and right - ll cur_res; // current result - - Mo_Algorithm() = default; - - void add(int x) - { - /* - Every time we add x - freq[x] * freq[x] * x will become (freq[x] + 1) * (freq[x] + 1) * x - Let's subtract the latters by the formers, we have 2 * freq[x] * x + x - - similar for remove function - */ - cur_res += 2ll * freq[x] * x + x; - freq[x]++; - } - - void remove(int x) - { - cur_res -= 2ll * freq[x] * x - x; - freq[x]--; - } - - void convert(int l, int r, int id, int *arr) - { - // shifting cur_l and cur_r to the right position cur_l -> l, cur_r -> r - while (cur_l < l) - { - remove(arr[cur_l]); - cur_l++; - } - while (cur_r < r) - { - cur_r++; - add(arr[cur_r]); - } - while (cur_l > l) - { - cur_l--; - add(arr[cur_l]); - } - while (cur_r > r) - { - remove(arr[cur_r]); - cur_r--; - } - - // update result - ans[id] = cur_res; - } - -public: - Mo_Algorithm(int l, int r) : cur_l(l), cur_r(r) - { - cur_res = 0; - ans.resize(2e5, 0ll); - freq.resize(1e6 + 5, 0); - } - - void process(Query q, int *arr) - { - convert(q.l, q.r, q.id, arr); - } - - void print(int n) - { - for (int i = 0; i < n; i++) - cout << ans[i] << '\n'; - } -}; - -int KMP(const string &pattern, const string &text) -{ - int m = len(pattern); - int j = 0; - V prefix(m, 0); - f(i, 1, m - 1) - { - while (j > 0 && pattern[j] != pattern[i]) - { - j = prefix[j - 1]; - } - if (pattern[i] == pattern[j]) - { - j++; - } - prefix[i] = j; - } - int n = len(text); - j = 0; - for (int i = 0; i < n; i++) - { - while (j > 0 && text[i] != pattern[j]) - { - j = prefix[j - 1]; - } - if (text[i] == pattern[j]) - { - j++; - } - if (j == m) - { - // cout << ""Pattern found at index "" << i - m + 1 << endl; - j = prefix[j - 1]; - return 1; - } - } - return 0; -} -int nCr(int n, int m) -{ - int a = factorialDP(n); - int b = factorialDP(n - m); - int c = factorialDP(m); - int k = b * c; - int ans = a / k; - return ans; -} -class SegmentTree -{ -private: - vector tree; - int n; - void build(int node, int start, int end, int value, V &v) - { - if (start == end) - { - tree[node] = v[start]; - } - else - { - int mid = (start + end) / 2; - build(2 * node, start, mid, 0, v); - build(2 * node + 1, mid + 1, end, 0, v); - tree[node] = max(tree[2 * node], tree[2 * node + 1]); - } - } - void update(int node, int start, int end, int idx, int value, V &v) - { - if (start == end) - { - tree[node]++; - } - else - { - int mid = (start + end) / 2; - if (start <= idx && idx <= mid) - { - update(2 * node, start, mid, idx, value, v); - } - else - { - update(2 * node + 1, mid + 1, end, idx, value, v); - } - tree[node] = max(tree[2 * node], tree[2 * node + 1]); - } - } - int query(int node, int start, int end, int L, int R) - { - if (R < start || end < L) - { - return INT_MIN; - } - if (L <= start && end <= R) - { - return tree[node]; - } - int mid = (start + end) / 2; - int leftQuery = query(2 * node, start, mid, L, R); - int rightQuery = query(2 * node + 1, mid + 1, end, L, R); - return max(leftQuery, rightQuery); - } - -public: - SegmentTree(vector &arr) - { - n = arr.size(); - tree.resize(4 * n); - build(1, 0, n - 1, 0, arr); - } - void update(int l, int r) - { - update(l, r); - } - int queryma(int l, int r) - { - return query(1, 0, n - 1, l, r); - } -}; -class DSU -{ - vector parent, rank, size; - -public: - DSU(int n) : parent(n + 1), rank(n + 1, 0), size(n + 1, 1) - { - for (int i = 0; i <= n; ++i) - { - parent[i] = i; - } - } - int find(int node) - { - if (node != parent[node]) - { - parent[node] = find(parent[node]); - } - return parent[node]; - } - - void unionByRank(int u, int v) - { - int rootU = find(u); - int rootV = find(v); - - if (rootU != rootV) - { - if (rank[rootU] < rank[rootV]) - { - parent[rootU] = rootV; - } - else if (rank[rootU] > rank[rootV]) - { - parent[rootV] = rootU; - } - else - { - parent[rootU] = rootV; - rank[rootV]++; - } - } - } - void unionBySize(int u, int v) - { - int rootU = find(u); - int rootV = find(v); - - if (rootU != rootV) - { - if (size[rootU] < size[rootV]) - { - parent[rootU] = rootV; - size[rootV] += size[rootU]; - } - else - { - parent[rootV] = rootU; - size[rootU] += size[rootV]; - } - } - } - int maxi() - { - int k = *max_element(all(size)); - return k; - } -}; -int mul(int a, int b, int mod_value) -{ - return (a * 1LL * b) % mod_value; -} -int gcd(int a, int b) -{ - while (b != 0) - { - int temp = b; - b = a % b; - a = temp; - } - return a; -} -int lcmx(int a, int b) -{ - return (a / gcd(a, b)) * b; -} -long long modExp(long long base, long long exp, long long mod) -{ - long long result = 1; - while (exp > 0) - { - if (exp % 2 == 1) - { - result = (result * base) % mod; - } - base = (base * base) % mod; - exp /= 2; - } - return result; -} -struct cmp -{ - bool operator()(const pair &a, const pair &b) - { - return a.first * b.second > a.second * b.first; - } -}; -bool isPerfectSquare(int n) -{ - int root = sqrt(n); - return root * root == n; -} -int modularDivision(int x, int a, int m) -{ - int a_inv = modExp(a, m - 2, m); - return (x * a_inv) % m; -} -struct cmpx -{ - bool operator()(const pair &a, const pair &b) const - { - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first > b.first; - } -}; -bool cmpx1(const pair &a, const pair &b) -{ - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first > b.first; -} -int ans(string a,string b,string c,int s1,int s2,int s3,vector>&dp){ - if(s1==si(a)){ - int ans=0; - f(j,s3,len(c)-1){ - if(b[s2]!=c[j]){ - ans++; - } - s2++; - } - return ans; - } - if(s2==si(b)){ - int ans=0; - f(j,s3,len(c)-1){ - if(a[s1]!=c[j]){ - ans++; - } - s1++; - } - return ans; - } - if(dp[s1][s2]!=-1){ - return dp[s1][s2]; - } - int movefroma=ans(a,b,c,s1+1,s2,s3+1,dp); - if(a[s1]!=c[s3]){ - movefroma++; - } - int movefromb=ans(a,b,c,s1,s2+1,s3+1,dp); - if(b[s2]!=c[s3]){ - movefromb++; - } - return dp[s1][s2]=min(movefroma,movefromb); -} -void solve() -{ - string a,b,c;ci(a);ci(b);ci(c); - vector>dp(si(a)+1,vector(si(b)+1,-1)); - co(ans(a,b,c,0,0,0,dp)); -} -int32_t main() -{ - int t; - t = 1; - cin >> t; - f(i, 1, t) - { - solve(); - en; - } - // #ifndef ONLINE_JUDGE - // cerr << ""Time : "" << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << ""ms\n""; - // #endif -}",1 -mayankarya185,2050E - Three Strings,c++17 ,297084945,297086350,"#include -using namespace std; -#define int long long -#define inf 1e5+5 -vector> dp; -int solve(string a,string b,string c,int ind1,int ind2){ - // base case - // cout<>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n = a.size(); - int m = b.size(); - int k = c.size(); - dp = vector>(n+1,vector(m+1,-1)); - dp[n][m] = 0; - int ans = solve(a,b,c,0,0); - cout< -using namespace std; -#define int long long -#define inf 1e5+5 -vector> dp; -int solve(string a,string b,string c,int ind1,int ind2){ - // base case - // cout<>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n = a.size(); - int m = b.size(); - int k = c.size(); - dp = vector>(n+1,vector(m+1,-1)); - dp[n][m] = 0; - // int ans = solve(a,b,c,0,0); - for(int i=(n);i>=0;i--){ - for(int j=(m);j>=0;j--){ - if(i==n && j==m) continue; - int op1 = inf; - int op2 = inf; - int op3 = inf; - int op4 = inf; - if(i 0) { - String s1 = fs.nextLine(); - String s2 = fs.nextLine(); - String s3 = fs.nextLine(); - ThreeStrings d = new ThreeStrings(); - int[][] dp = new int[s1.length()][s2.length()]; - for (int i = 0; i < s1.length(); i++) { - Arrays.fill(dp[i], -1); - } - System.out.println( s3.length()-rec(0, 0, 0, s1, s2, s3, dp)); - } - } - public static int rec(int n, int i, int j, String a, String b, String c, int[][] dp) { - if (i == a.length()) { - int val = 0; - while (j < b.length()) { - if (b.charAt(j) == c.charAt(n)) { - val++; - } - j++; - n++; - } - return val; - } - if (j == b.length()) { - int val = 0; - while (i < a.length()) { - if (a.charAt(i) == c.charAt(n)) { - val++; - } - i++; - n++; - } - return val; - } - if (dp[i][j] != -1) { - return dp[i][j]; - } - int c1 = 0; - int c2 = 0; - if (a.charAt(i) == c.charAt(n)) { - c1++; - } - if (b.charAt(j) == c.charAt(n)) { - c2++; - } - int max1 = rec(n + 1, i + 1, j, a, b, c, dp) + c1; - int max2 = rec(n + 1, i, j + 1, a, b, c, dp) + c2; - dp[i][j] = Math.max(max1, max2); - return dp[i][j]; - } -} -class FastReader { - BufferedReader gt; - StringTokenizer st; - - public FastReader() { - gt = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(gt.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - String nextLine() { - String str = """"; - try { - str = gt.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - int nextInt() { - return Integer.parseInt(next()); - } - - int[] readIntArray(int n) { - int[] res = new int[n]; - for (int i = 0; i < n; i++) - res[i] = nextInt(); - return res; - } - - long nextLong() { - return Long.parseLong(next()); - } - - long[] readLongArray(int n) { - long[] res = new long[n]; - for (int i = 0; i < n; i++) - res[i] = nextLong(); - return res; - } - - String[] readStringArray(int n) { - String[] str = new String[n]; - for (int i = 0; i < n; i++) - str[i] = nextLine(); - - return str; - } - - int getGCD(int a, int b) { - if (b == 0) - return a; - else - return getGCD(b, a % b); - } -}","//package codeforcesques; -import codeforcesques.AbsoluteSorting; - -import java.util.*; -import java.io.*; -public class ThreeStrings { - int mincount=Integer.MAX_VALUE; - public static void main(String[] args) { - FastReader fs=new FastReader(); - - int t=fs.nextInt(); - - while(t-->0) - { - String s1=fs.nextLine(); - String s2=fs.nextLine(); - String s3=fs.nextLine(); - ThreeStrings d=new ThreeStrings(); - int [][]dp=new int[s1.length()][s2.length()]; - for(int i=0;i -using namespace std; -int dp[1010][1010]; -int main(){ - ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(),m=b.size(); - a="" ""+a,b="" ""+b,c="" ""+c; - for(int i=1;i<=n+2;i++) - for(int j=1;j<=m+2;j++) - dp[i][j]=1e9; - for(int i=1;i<=n;i++) - dp[i][0]=dp[i-1][0]+(a[i]!=c[i]); - for(int i=1;i<=m;i++) - dp[0][i]=dp[0][i-1]+(b[i]!=c[i]); - for(int i=1;i<=n;i++) - for(int j=1;j<=m;j++) - dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]),dp[i][j-1]+(b[j]==c[i+j])); - cout< -using namespace std; -int dp[1010][1010]; -int main(){ - ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(),m=b.size(); - //a="" ""+a,b="" ""+b,c="" ""+c; - for(int i=0;i<=n;i++) - for(int j=0;j<=m;j++) - dp[i][j]=1e9; - dp[0][0]=0; - for(int i=0;i - -using namespace std; - - - -typedef long long ll; - -#define vi vector - -#define vll vector - -#define vp vector> - -#define all(a) (a).begin(),(a).end() - -#define rep(i,a) for(int i=0;i - - - - - -int main() { ios::sync_with_stdio(0);cin.tie(0); - -int t; cin>>t; - -while (t--){ - - - - string a,b,c; cin>>a>>b>>c; - - int n =a.size(), m = b.size() ; - - vector> dp(n+1, vector(m+1,0)) ; - - - - dp[n][m]=0; - - - - for(int i=n-1;i>=0;i--){ - - if(a[i]==c[m+i])dp[i][m]=dp[i+1][m]; - - else { - - dp[i][m]=dp[i+1][m]+1; - - } - - } - - - - for(int i=m-1;i>=0;i--){ - - if(b[i]==c[n+i])dp[n][i]=dp[n][i+1]; - - else{ - - dp[n][i]= dp[n][i+1]+1; - - } - - } - - - - for(int i=n-1;i>=0;i--){ - - for(int j=m-1;j>=0;j--){ - - - - int x= 1e5,y = 1e5; - - - - if(a[i]==c[i+j])x=dp[i+1][j]; - - else{x= dp[i+1][j]+1 ;} - - - - if(b[j]==c[i+j])y=dp[i][j+1]; - - else {y= dp[i][j+1]+1;} - - - - dp[i][j] = min(x,y) ; - - - - } - - } - - - - cout<< dp[0][0] < - -using namespace std; - - - -typedef long long ll; - -#define vi vector - -#define vll vector - -#define vp vector> - -#define all(a) (a).begin(),(a).end() - -#define rep(i,a) for(int i=0;i - - - - int rec( vector> &dp, string a,string b , string c, int i, int j){ - - if(i+j>=c.size())return 0 ; - - - - // dp[i][j] == minimun changes req after index i , j ... - - - - if( dp[i][j]!=-1)return dp[i][j] ; - - - - - - int x = 1e7, y = 1e7, z= 1e7, w = 1e7 ; - - - - if(i>t; - -while (t--){ - - - - string a,b,c; cin>>a>>b>>c; - - int n =a.size(), m = b.size() ; - - vector> dp(n+1, vector(m+1,-1)) ; - - - - cout< -#include -using namespace std; -// # define int long long -#define f(x, a, b) for (ll x = a; x < b; x++) -#define fm(x, a, b) for (int x = a; x > b; x--) -#define ll long long -#define pb push_back - -long long gcd(long long a, ll b) -{ - return b == 0 ? a : gcd(b, a % b); -} - -long long lcm(ll a, ll b) -{ - return (a / gcd(a, b)) * b; -} - -int help(vector>& dp,string& a,string& b,string& c,int i,int j,int n,int m, int o){ - if (i==n){ - int ans=0; - f(k,j,m){ - if (c[n+k]!=b[k]){ans+=1;} - } - return ans; - } - if (j==m){ - int ans=0; - f(k,i,n){ - if (c[m+k]!=a[k]){ans+=1;} - } - return ans; - } - if (dp[i][j]!=-1){return dp[i][j];} - if (a[i]==c[i+j]){ - if (b[j]==c[i+j]){ - // int x=help(dp,a,b,c,i+1,j,n,m,o); - // int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=help(dp,a,b,c,i,j+1,n,m,o);; - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - } - else if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - return dp[i][j]; -} - -int main() -{ - int t; - t = 1; - cin >> t; - while (t--) - { - string a,b,c; cin>>a>>b>>c; - int n=a.size(),m=b.size(),o=c.size(); - vector> dp(n,vector(m,-1)); - int ans=help(dp,a,b,c,0,0,n,m,o); - cout< -#include -using namespace std; -// # define int long long -#define f(x, a, b) for (ll x = a; x < b; x++) -#define fm(x, a, b) for (int x = a; x > b; x--) -#define ll long long -#define pb push_back - -long long gcd(long long a, ll b) -{ - return b == 0 ? a : gcd(b, a % b); -} - -long long lcm(ll a, ll b) -{ - return (a / gcd(a, b)) * b; -} - -int help(vector>& dp,string& a,string& b,string& c,int i,int j,int n,int m, int o){ - if (i==n){ - int ans=0; - f(k,j,m){ - if (c[n+k]!=b[k]){ans+=1;} - } - return ans; - } - if (j==m){ - int ans=0; - f(k,i,n){ - if (c[m+k]!=a[k]){ans+=1;} - } - return ans; - } - if (dp[i][j]!=-1){return dp[i][j];} - if (a[i]==c[i+j]){ - if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o); - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - } - else if (b[j]==c[i+j]){ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o); - dp[i][j]=min(x,y); - } - else{ - int x=help(dp,a,b,c,i+1,j,n,m,o)+1; - int y=help(dp,a,b,c,i,j+1,n,m,o)+1; - dp[i][j]=min(x,y); - } - return dp[i][j]; -} - -int main() -{ - int t; - t = 1; - cin >> t; - while (t--) - { - string a,b,c; cin>>a>>b>>c; - int n=a.size(),m=b.size(),o=c.size(); - vector> dp(n,vector(m,-1)); - int ans=help(dp,a,b,c,0,0,n,m,o); - cout< -using namespace std; - -const int N = 1e3 + 2; -int dp[N][N] = { { 0 } }; - -string a, b, c; - -int n; // length of a -int m; // length of b - -int f(int i, int j) { - if (i == 0 && j == 0) return 0; - if (dp[i][j] != 0) return dp[i][j]; - int choose_a = INT_MAX, choose_b = INT_MAX; - if (i > 0) choose_a = (a[i - 1] == c[i + j - 1] ? 0 : 1) + f(i - 1, j); - if (j > 0) choose_b = (b[j - 1] == c[i + j - 1] ? 0 : 1) + f(i, j - 1); - return dp[i][j] = min(choose_a, choose_b); -} - -void solve() { - cin >> a >> b >> c; - n = a.length(); - m = b.length(); - memset(dp, 0, sizeof(dp)); - cout << f(n, m) << endl; -} - -int main() { - int t; - cin >> t; - while (t--) solve(); -} -","#include -using namespace std; - -const int N = 1e3 + 2; -int dp[N][N] = { { 0 } }; - -string a, b, c; - -int n; // length of a -int m; // length of b - -int f(int i, int j) { - if (i == 0 && j == 0) return 0; - if (dp[i][j] != 0) return dp[i][j]; - int choose_a = INT_MAX, choose_b = INT_MAX; - if (i > 0) choose_a = (a[i - 1] == c[i + j - 1] ? 0 : 1) + f(i - 1, j); - if (j > 0) choose_b = (b[j - 1] == c[i + j - 1] ? 0 : 1) + f(i, j - 1); - return dp[i][j] = min(choose_a, choose_b); -} - -void solve() { - cin >> a >> b >> c; - n = a.length(); - m = b.length(); - cout << f(n, m) << endl; -} - -int main() { - int t; - cin >> t; - while (t--) solve(); -} -",1 -parth190804,2050E - Three Strings,c++20 ,298790409,298788822,"//=======================^========================================================^=======================\\ - -/* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * - * * * * * * * * * * * * * * * * * * * * * * * * - -*/ - -//=======================^========================================================^=======================\\ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define test ll t;cin>>t;while(t--) -#define ll long long int -#define lld long double -#define f first -#define all(v) v.begin(),v.end() -#define s second -#define inarr ll n;cin>>n;ll arr[n+1];fi(0,n) cin>>arr[i] -#define inarrk ll n,k;cin>>n>>k;ll arr[n+1];fi(0,n) cin>>arr[i] -#define setfor for(auto it: s1) -#define parthparekh ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -#define fi(l,ans2) for(ll i = l; i < ans2; i++) -#define fj(l,ans2) for(ll j = l; j < ans2; j++) -#define fk(l,ans2) for(ll k = l; k < ans2; k++) -#define fm(l,ans2) for(ll m = l; m < ans2; m++) -#define fk(l,ans2) for(ll k = l; k < ans2; k++) -#define fir(ans2,l) for(ll i=ans2;i>=l;i--) -#define fjr(ans2,l) for(ll j=ans2;j>=l;j--) -const ll MOD=1e9+7; -const ll MOD2= 998244353; -const ll inf=1e18; -const ll N=1e6+100; -#define pb push_back -#define em emplace_back -#define yy cout<<""YES\n"" -#define YY cout<<""Yes\n"" -#define nn cout<<""NO\n"" -#define NN cout<<""No\n"" -using namespace std; - -//=======================^========================================================^======================= -// vector adj[200001]; -vector isprime(N,1); -// vector vis(200001,0),degree(200001,0),color(200001,-1),pathvis(200001,0); -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -//=======================^========================================================^======================= - -ll factorial(ll n){ - ll ans=1; - fi(1,n+1) - ans*=i; - return ans; -} - -vector decToBinary(ll n) { - vector v(32); - ll i=31; - while(n>0&&i>=0) { - v[i]=n%2; - n/=2; - i--; - } - return v; -} - -void sieve() { - isprime[0] = isprime[1] = false; - for (ll i = 2; i * i < N; ++i) { - if (isprime[i]) { - for (ll j = i * i; j < N; j += i) { - isprime[j] = false; - } - } - } -} - -bool isPrimeLarge(ll num) { - if (num < N) return isprime[num]; - if (num < 2 || (num > 2 && num % 2 == 0)) return false; - for (ll i = 2; i * i <= num; ++i) { - if (num % i == 0) return false; - } - return true; -} - -ll power(ll base,ll exponent){ - ll ans=1; - base%=MOD; - while(exponent>0) { - if(exponent&1) - ans=(ans*base)%MOD; - exponent>>=1; - base=(base*base)%MOD; - } - return ans; -} - -ll parth(vector > &dp,ll i,ll j,const string &a, const string &b, const string &c){ - if(i==a.length() && j==b.length()) - return 0; - - if(dp[i][j]!=-1) - return dp[i][j]; - - ll ans=INT_MAX,k=i+j; - if(i>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - ll n=a.length(),m=b.length(); - vector > dp(n+1,vector(m+1,-1)); - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define test ll t;cin>>t;while(t--) -#define ll long long int -#define lld long double -#define f first -#define all(v) v.begin(),v.end() -#define s second -#define inarr ll n;cin>>n;ll arr[n+1];fi(0,n) cin>>arr[i] -#define inarrk ll n,k;cin>>n>>k;ll arr[n+1];fi(0,n) cin>>arr[i] -#define setfor for(auto it: s1) -#define parthparekh ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -#define fi(l,ans2) for(ll i = l; i < ans2; i++) -#define fj(l,ans2) for(ll j = l; j < ans2; j++) -#define fk(l,ans2) for(ll k = l; k < ans2; k++) -#define fm(l,ans2) for(ll m = l; m < ans2; m++) -#define fk(l,ans2) for(ll k = l; k < ans2; k++) -#define fir(ans2,l) for(ll i=ans2;i>=l;i--) -#define fjr(ans2,l) for(ll j=ans2;j>=l;j--) -const ll MOD=1e9+7; -const ll MOD2= 998244353; -const ll inf=1e18; -const ll N=1e6+100; -#define pb push_back -#define em emplace_back -#define yy cout<<""YES\n"" -#define YY cout<<""Yes\n"" -#define nn cout<<""NO\n"" -#define NN cout<<""No\n"" -using namespace std; - -//=======================^========================================================^======================= -// vector adj[200001]; -vector isprime(N,1); -// vector vis(200001,0),degree(200001,0),color(200001,-1),pathvis(200001,0); -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -//=======================^========================================================^======================= - -ll factorial(ll n){ - ll ans=1; - fi(1,n+1) - ans*=i; - return ans; -} - -vector decToBinary(ll n) { - vector v(32); - ll i=31; - while(n>0&&i>=0) { - v[i]=n%2; - n/=2; - i--; - } - return v; -} - -void sieve() { - isprime[0] = isprime[1] = false; - for (ll i = 2; i * i < N; ++i) { - if (isprime[i]) { - for (ll j = i * i; j < N; j += i) { - isprime[j] = false; - } - } - } -} - -bool isPrimeLarge(ll num) { - if (num < N) return isprime[num]; - if (num < 2 || (num > 2 && num % 2 == 0)) return false; - for (ll i = 2; i * i <= num; ++i) { - if (num % i == 0) return false; - } - return true; -} - -ll power(ll base,ll exponent){ - ll ans=1; - base%=MOD; - while(exponent>0) { - if(exponent&1) - ans=(ans*base)%MOD; - exponent>>=1; - base=(base*base)%MOD; - } - return ans; -} - -ll parth(vector > &dp,ll i,ll j,string a,string b,string c){ - if(i==a.length() && j==b.length()) - return 0; - - if(dp[i][j]!=-1) - return dp[i][j]; - - ll ans=INT_MAX,k=i+j; - if(i>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - ll n=a.length(),m=b.length(); - vector > dp(n+1,vector(m+1,-1)); - cout< -using namespace std; -#define cin(a) for(auto i =0;i<=a.size()-1;i++) cin>>a[i]; -#define all(a) a.begin(),a.end() -#define ll long long -#define yy cout<<""Yes""< &a,int nd,int s,int e){ -// if(s==e){ -// tree[nd]=a[s]; -// return; -// } -// int mid=(s+e)/2; -// build(a,2*nd,s,mid); -// build(a,2*nd+1,mid+1,e); -// tree[nd]=__gcd(tree[2*nd],tree[2*nd+1]); -// } -// int qur(int nd,int s,int e,int l,int r){ -// //non-overlap interval -// if(l>r){ -// return 0; -// } -// if(s>r||e>a; -cin>>b; -cin>>c; -vector> dp(a.size()+1,vector (b.size()+1,LONG_LONG_MAX)); -dp[0][0]=0; -for(int i=1;i<=c.size();i++){ - for(int j=0;j<=i;j++){ - if(j>a.size()||i-j>b.size()){ - continue; - } - if(j>0){ - dp[j][i-j]=min(dp[j][i-j],dp[j-1][i-j]+(c[i-1]!=a[j-1])); - } - if(i-j>0){ - dp[j][i-j]=min(dp[j][i-j],dp[j][i-j-1]+(c[i-1]!=b[i-j-1])); - } -}} -cout<>t; -while(t--){ - solve(); -}}","#include -using namespace std; -#define cin(a) for(auto i =0;i<=a.size()-1;i++) cin>>a[i]; -#define all(a) a.begin(),a.end() -#define ll long long -#define yy cout<<""Yes""< &a,int nd,int s,int e){ -// if(s==e){ -// tree[nd]=a[s]; -// return; -// } -// int mid=(s+e)/2; -// build(a,2*nd,s,mid); -// build(a,2*nd+1,mid+1,e); -// tree[nd]=__gcd(tree[2*nd],tree[2*nd+1]); -// } -// int qur(int nd,int s,int e,int l,int r){ -// //non-overlap interval -// if(l>r){ -// return 0; -// } -// if(s>r||e>a; -cin>>b; -cin>>c; -vector> dp(a.size()+1,vector (b.size()+1,LONG_LONG_MAX)); -dp[0][0]=0; -for(int i=1;i<=c.size();i++){ - for(int j=0;j<=i;j++){ - if(j>a.size()||i-j>b.size()){ - continue; - } - if(j>0){ - dp[j][i-j]=min(dp[j][i-j],dp[j-1][i-j]+(c[i-1]!=a[j-1])); - } - if(i-j>0){ - dp[j][i-j]=min(dp[j][i-j],dp[j][i-j-1]+(c[i-1]!=b[i-j-1])); - } -}} -cout<>t -while(t--){ - solve(); -}}",1 -Mostima_Y,2050E - Three Strings,c++17 ,295966219,295966590,"#include - -using namespace std; - -typedef long long LL; -typedef pair PII; - -#define x first -#define y second - -const int N = 2e3 + 10; - -int qmi(int a, int k, int p) // 求a^k mod p -{ - int res = 1 % p; - while (k) - { - if (k & 1) res = (LL)res * a % p; - a = (LL)a * a % p; - k >>= 1; - } - return res; -} - -int n, k; -char s1[N], s2[N], t[N]; -int f[N][N]; - -void solve() -{ - cin >> s1 + 1 >> s2 + 1 >> t + 1; - int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1); - // memset(f, 0x3f, sizeof f); - // for(int i = 0; i <= l1; i ++) f[i][0] = 0; - // for(int j = 0; j <= l2; j ++) f[0][j] = 0; - - for(int i = 0; i <= l1; i ++) - for(int j = 0; j <= l2; j ++) - { - if(i == 0 && j == 0) continue; - if(i != 0) - f[i][j] = f[i - 1][j] + (s1[i] == t[i + j]); - if(j != 0) - f[i][j] = max(f[i][j], f[i][j - 1] + (s2[j] == t[i + j])); - } - cout << l1 + l2 - f[l1][l2] << endl; -} - -int main() -{ - int t; - cin >> t; - while(t --) - solve(); -}","#include - -using namespace std; - -typedef long long LL; -typedef pair PII; - -#define x first -#define y second - -const int N = 2e3 + 10; - -int qmi(int a, int k, int p) // 求a^k mod p -{ - int res = 1 % p; - while (k) - { - if (k & 1) res = (LL)res * a % p; - a = (LL)a * a % p; - k >>= 1; - } - return res; -} - -int n, k; -char s1[N], s2[N], t[N]; -int f[N][N]; - -void solve() -{ - cin >> s1 + 1 >> s2 + 1 >> t + 1; - int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1); - // memset(f, 0x3f, sizeof f); - // for(int i = 0; i <= l1; i ++) f[i][0] = 0; - // for(int j = 0; j <= l2; j ++) f[0][j] = 0; - - for(int i = 0; i <= l1; i ++) - for(int j = 0; j <= l2; j ++) - { - f[i][j] = 0; - if(i == 0 && j == 0) continue; - if(i != 0) - f[i][j] = f[i - 1][j] + (s1[i] == t[i + j]); - if(j != 0) - f[i][j] = max(f[i][j], f[i][j - 1] + (s2[j] == t[i + j])); - } - cout << l1 + l2 - f[l1][l2] << endl; -} - -int main() -{ - int t; - cin >> t; - while(t --) - solve(); -}",2 -hk.,2050E - Three Strings,c++20 ,297236504,297236975,"#include -using namespace std; -#define int long long - -int func(string& a, string& b, string& c, int i1, int i2, int j, vector>>& dp) { - if (j == c.size()) return 0; - - if (dp[i1][i2][j] != -1) return dp[i1][i2][j]; - - int mini = INT_MAX; - - if (i1 < a.size()) { - mini = min(mini, (a[i1] != c[j]) + func(a, b, c, i1+1, i2, j+1, dp)); - } - - if (i2 < b.size()) { - mini = min(mini, (b[i2] != c[j]) + func(a, b, c, i1, i2+1, j+1, dp)); - } - - return dp[i1][i2][j] = mini; -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - - int n1 = a.size(), n2 = b.size(), n3 = c.size(); - vector>> dp(n1+1, vector>(n2+1, vector(n3+1, -1))); - - int ans = func(a, b, c, 0, 0, 0, dp); - cout << ans << endl; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -#define int long long - -int func(string& a, string& b, string& c, int i1, int i2, int j, vector>& dp) { - if (j == c.size()) return 0; - - if (dp[i1][i2] != -1) return dp[i1][i2]; - - int mini = INT_MAX; - - if (i1 < a.size()) { - mini = min(mini, (a[i1] != c[j]) + func(a, b, c, i1+1, i2, j+1, dp)); - } - - if (i2 < b.size()) { - mini = min(mini, (b[i2] != c[j]) + func(a, b, c, i1, i2+1, j+1, dp)); - } - - return dp[i1][i2] = mini; -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - - int n1 = a.size(), n2 = b.size(), n3 = c.size(); - vector> dp(n1+1, vector(n2+1,-1)); - - int ans = func(a, b, c, 0, 0, 0, dp); - cout << ans << endl; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",2 -Akshat09072004,2050E - Three Strings,c++17 ,295879237,295880061,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -using namespace std; - -int solve(string a,string b,string c,int i,int j,int s,vector > >&dp){ - if(i==a.size() && j==b.size()){ - if(s==1){ - if(a[i-1]!=c[i+j+1-2]){ - return dp[i][j][s]=1; - } - return dp[i][j][s]=0; - } - if(b[j-1]!=c[i+j+1-2]){ - return dp[i][j][s]=1; - } - return dp[i][j][s]=0; - - } - if(dp[i][j][s]!=-1){ - return dp[i][j][s]; - } - if(s==1){ - int cmp=i+j+1-2; - int add=0; - if(a[i-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+solve(a,b,c,i+1,j,1,dp); - } - - if(j+1<=b.size()-1+1){ - c2=add+solve(a,b,c,i,j+1,0,dp); - } - - return dp[i][j][s]=min(c1,c2); - - } - int cmp=i+j+1-2; - int add=0; - if(b[j-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+solve(a,b,c,i+1,j,1,dp); - } - - if(j+1<=b.size()-1+1){ - c2=add+solve(a,b,c,i,j+1,0,dp); - } - - return dp[i][j][s]=min(c1,c2); - - - - - - - - -} -int solve2(string a,string b,string c){ - int n1=a.size(); - int n2=b.size(); - - vector > >dp(n1+1,vector >(n2+1,vector(2,0))); - - for(int i=a.size();i>=0;i--){ - for(int j=b.size();j>=0;j--){ - for(int s=0;s<=1;s++){ - if(i==a.size() && j==b.size()){ - if(s==1){ - if(a[i-1]!=c[i+j+1-2]){ - dp[i][j][s]=1; - } - dp[i][j][s]=0; - } - else if(b[j-1]!=c[i+j+1-2]){ - dp[i][j][s]=1; - } - else{ - dp[i][j][s]=0;} - continue; - - } - - if(s==1){ - int cmp=i+j+1-2; - int add=0; - if(a[i-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+dp[i+1][j][1]; - } - - if(j+1<=b.size()-1+1){ - c2=add+dp[i][j+1][0]; - } - - dp[i][j][s]=min(c1,c2); - - } - - else{ - int cmp=i+j+1-2; - int add=0; - if(b[j-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+dp[i+1][j][1]; - } - - if(j+1<=b.size()-1+1){ - c2=add+dp[i][j+1][0]; - } - - dp[i][j][s]=min(c1,c2); - } - - - - - - - - - } - } - } - - return dp[1][0][1]; - - - - -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t=1; - cin>>t; - while(t--){ - string a; - cin>>a; - - string b; - cin>>b; - - string c; - cin>>c; - int n1=a.size(); - int n2=b.size(); - - // vector > >dp1(n1+1,vector >(n2+1,vector(2,-1))); - // vector > >dp2(n1+1,vector >(n2+1,vector(2,-1))); - - int ans1=solve2(a,b,c); - //int ans2=solve(a,b,c,0,1,0,dp2); - - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -using namespace std; - -int solve(string &a,string &b,string &c,int i,int j,int s,vector > >&dp){ - if(i==a.size() && j==b.size()){ - if(s==1){ - if(a[i-1]!=c[i+j+1-2]){ - return dp[i][j][s]=1; - } - return dp[i][j][s]=0; - } - if(b[j-1]!=c[i+j+1-2]){ - return dp[i][j][s]=1; - } - return dp[i][j][s]=0; - - } - if(dp[i][j][s]!=-1){ - return dp[i][j][s]; - } - if(s==1){ - int cmp=i+j+1-2; - int add=0; - if(a[i-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+solve(a,b,c,i+1,j,1,dp); - } - - if(j+1<=b.size()-1+1){ - c2=add+solve(a,b,c,i,j+1,0,dp); - } - - return dp[i][j][s]=min(c1,c2); - - } - int cmp=i+j+1-2; - int add=0; - if(b[j-1]!=c[cmp]){ - add=1; - } - int c1=1e9,c2=1e9; - if(i+1<=a.size()-1+1){ - c1=add+solve(a,b,c,i+1,j,1,dp); - } - - if(j+1<=b.size()-1+1){ - c2=add+solve(a,b,c,i,j+1,0,dp); - } - - return dp[i][j][s]=min(c1,c2); - - - - - - - - -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t=1; - cin>>t; - while(t--){ - string a; - cin>>a; - - string b; - cin>>b; - - string c; - cin>>c; - int n1=a.size(); - int n2=b.size(); - - vector > >dp1(n1+1,vector >(n2+1,vector(2,-1))); - vector > >dp2(n1+1,vector >(n2+1,vector(2,-1))); - - int ans1=solve(a,b,c,1,0,1,dp1); - int ans2=solve(a,b,c,0,1,0,dp2); - - cout< -using namespace std; -#define int long long -int power(int A, int expo) -{ - if (expo == 0) - return 1; - int res = power(A, expo / 2); - if (expo % 2) - return res * res * A; - else - return res * res; -} -int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } -int fact(int x) -{ - if (x == 1 || x == 0) - return 1; - return (x * fact(x - 1)); -} -class UnionFind{ - private: vector parent,rank; - public: - UnionFind(int n){ - rank.assign(n,0); - parent.assign(n,0); - iota(parent.begin(),parent.end(),0); - } - int find(int x) { - if(parent[x] == x) - return x; - - return parent[x] = find(parent[x]); - } - - void UnionSet(int x, int y) { - int x_parent = find(x); - int y_parent = find(y); - - if(rank[x_parent] > rank[y_parent]) { - parent[y_parent] = x_parent; - } else if(rank[x_parent] < rank[y_parent]) { - parent[x_parent] = y_parent; - } else { - parent[x_parent] = y_parent; - rank[y_parent]++; - } - } -}; - -int lcm(int a, int b) { - return (a / gcd(a, b)) * b; -} -void solve() { - string a,b,c; - cin>>a>>b>>c; - int n = a.size(); - int m = b.size(); - - vector> dp(n + 1, vector(m + 1, 0)); - for (int i = 0; i <= n; ++i) { - for (int j = 0; j <= m; ++j) { - if (i == 0 && j == 0) { - dp[i][j] = 0; - } else if (i == 0) { - dp[i][j] = dp[i][j - 1] + (b[j - 1] != c[i + j - 1]); - } else if (j == 0) { - dp[i][j] = dp[i - 1][j] + (a[i - 1] != c[i + j - 1]); - } else { - dp[i][j] = min( - dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), - dp[i][j - 1] + (b[j - 1] != c[i + j - 1]) - ); - } - } - } - - cout << dp[n][m] << endl; -} - - -signed main() { -#ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; -#define int long long -int power(int A, int expo) -{ - if (expo == 0) - return 1; - int res = power(A, expo / 2); - if (expo % 2) - return res * res * A; - else - return res * res; -} -int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } -int fact(int x) -{ - if (x == 1 || x == 0) - return 1; - return (x * fact(x - 1)); -} -class UnionFind{ - private: vector parent,rank; - public: - UnionFind(int n){ - rank.assign(n,0); - parent.assign(n,0); - iota(parent.begin(),parent.end(),0); - } - int find(int x) { - if(parent[x] == x) - return x; - - return parent[x] = find(parent[x]); - } - - void UnionSet(int x, int y) { - int x_parent = find(x); - int y_parent = find(y); - - if(rank[x_parent] > rank[y_parent]) { - parent[y_parent] = x_parent; - } else if(rank[x_parent] < rank[y_parent]) { - parent[x_parent] = y_parent; - } else { - parent[x_parent] = y_parent; - rank[y_parent]++; - } - } -}; - -int lcm(int a, int b) { - return (a / gcd(a, b)) * b; -} -int dp[10001][10001]; -int solveRec(int i, int j,string &a, string &b, string &c) { - if (i == a.size() && j == b.size()) return 0; - if (dp[i][j] != -1) return dp[i][j]; - - int k = i + j; - int result = INT_MAX; - - if (i < a.size()) { - result = min(result, solveRec(i + 1, j, a, b, c) + (a[i] != c[k])); - } - - if (j < b.size()) { - result = min(result, solveRec(i, j + 1, a, b, c) + (b[j] != c[k])); - } - - return dp[i][j] = result; -} -void solve() { - string a,b,c; - cin>>a>>b>>c; - memset(dp,-1,sizeof(dp)); - cout<> t; - while (t--) { - solve(); - } - return 0; -}",1 -rudraveersingh7275467181,2050E - Three Strings,c++17 ,297652469,297650343,"#include -#include -#include -#include -#include -using namespace std; - -int minChanges(string &a, string &b, string &c) { - int n = a.length(), m = b.length(); - vector prev(m + 1, 0), curr(m + 1, 0); - - // Initialize base cases - for (int j = 0; j <= m; ++j) { - prev[j] = j; // Only use characters from `b` - } - - for (int i = 0; i <= n; ++i) { - curr[0] = i; // Only use characters from `a` - - for (int j = 0; j <= m; ++j) { - if (i == 0 && j == 0) continue; // Base case already handled - int k = i + j - 1; // Current index in `c` - - curr[j] = INT_MAX; // Initialize to a large value - - if (i > 0 && a[i - 1] == c[k]) { // Match with `a` - curr[j] = min(curr[j], prev[j]); - } else if (i > 0) { // Mismatch with `a` - curr[j] = min(curr[j], prev[j] + 1); - } - - if (j > 0 && b[j - 1] == c[k]) { // Match with `b` - curr[j] = min(curr[j], curr[j - 1]); - } else if (j > 0) { // Mismatch with `b` - curr[j] = min(curr[j], curr[j - 1] + 1); - } - } - - // Swap `prev` and `curr` - swap(prev, curr); - } - - return prev[m]; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - string a, b, c; - cin >> a >> b >> c; - cout << minChanges(a, b, c) << '\n'; - } - - return 0; -} -","#include -#include -#include -#include -using namespace std; -int minOperations(string a, string b, string c) { - int n = a.length(), m = b.length(), l = c.length(); - vector>> dp(n + 1, vector>(m + 1, vector(l + 1, INT_MAX))); - - // Base case: If i == n and j == m, cost is 0 - for (int k = 0; k <= l; ++k) { - dp[n][m][k] = 0; - } - - // Fill the DP table in reverse (bottom-up) - for (int i = n; i >= 0; --i) { - for (int j = m; j >= 0; --j) { - for (int k = l; k >= 0; --k) { - if (i == n && j == m) continue; // Already handled base case - - if (i < n && j < m) { - if (a[i] == b[j]) { - if (a[i] == c[k]) { - dp[i][j][k] = min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]); - } else { - dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]); - } - } else { - if (a[i] == c[k]) { - dp[i][j][k] = min(dp[i + 1][j][k + 1], 1 + dp[i][j + 1][k + 1]); - } else if (b[j] == c[k]) { - dp[i][j][k] = min(1 + dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]); - } else { - dp[i][j][k] = 1 + min(dp[i + 1][j][k + 1], dp[i][j + 1][k + 1]); - } - } - } else if (i < n) { - if (a[i] == c[k]) { - dp[i][j][k] = dp[i + 1][j][k + 1]; - } else { - dp[i][j][k] = 1 + dp[i + 1][j][k + 1]; - } - } else if (j < m) { - if (b[j] == c[k]) { - dp[i][j][k] = dp[i][j + 1][k + 1]; - } else { - dp[i][j][k] = 1 + dp[i][j + 1][k + 1]; - } - } - } - } - } - - return dp[0][0][0]; // Final result -} - -int main(){ - int t; - cin>>t; - while(t--){ - - string a,b,c; - cin>>a>>b>>c; - - - cout<< minOperations(a,b,c); - - cout<> t; - - while(t--){ - - string a,b; cin >> a >> b >> c; - - cout << solve(a,b) << endl; - - } - - - - return 0; - - }","#include ""bits/stdc++.h"" - -using namespace std; - - - -int solve(string a, string b, string c){ - - int arr[a.length()][b.length()]; - - for(int i=0; i> t; - - while(t--){ - - string a,b,c; cin >> a >> b >> c; - - cout << solve(a,b,c) << endl; - - } - - - - return 0; - -}",1 -moyegege,2050E - Three Strings,c++20 ,295699198,295689884,"#include -using namespace std; -using LL = long long; - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - int N = n + m; - vector dp(N + 1, vector (n + 1, 2005)); - dp[0][0] = 0; - for (int i = 1; i <= N; i++) { - for (int j = 0; j <= min(n, i); j++) { - if (j + 1 <= n) dp[i][j + 1] = min(dp[i][j + 1], - dp[i - 1][j] + (c[i - 1] != a[j])); - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != b[i - j - 1])); - } - } - int ans = dp[N][n]; - cout << ans << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}","#include -using namespace std; -using LL = long long; - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - int N = n + m; - vector dp(N + 1, vector (n + 1, 1005)); - dp[0][0] = 0; - for (int i = 1; i <= N; i++) { - for (int j = 0; j <= min(n, i); j++) { - if (j + 1 <= n) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + (c[i - 1] != a[j])); - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != b[i - j - 1])); - } - } - int ans = 1005; - for (int i = 0; i <= n; i++) { - ans = min(ans, dp[N][i]); - } - cout << ans << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}",1 -lil_giant123,2050E - Three Strings,c++23 ,297711776,297711979,"#include -typedef long long ll; -using namespace std; -map primes; -vector good={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; - -void dfs(vector&vis,char node,vector>&adj) { - for(int i=0;i>a>>b>>c; - int n=a.size(),m=b.size(); - vector> dp(n+1,vector(m+1,0)); - for(int i=1;i<=n;i++){ - dp[i][0]=dp[i-1][0]+(a[i-1]!=c[i-1]); - } - for(int i=1;i<=m;i++){ - dp[0][i]=dp[0][i-1]+(b[i-1]!=c[i-1]); - } - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++){ - dp[i][j]=min((dp[i][j-1]+(b[j-1]!=c[i+j-1])),(dp[i-1][j]+(a[i-1]!=c[i+j-1]))); - } - } - cout< -typedef long long ll; -using namespace std; -map primes; -vector good={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; - -void dfs(vector&vis,char node,vector>&adj) { - for(int i=0;i>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(),m=b.size(); - vector> dp(n+1,vector(m+1,0)); - for(int i=1;i<=n;i++){ - dp[i][0]=dp[i-1][0]+(a[i-1]!=c[i-1]); - } - for(int i=1;i<=m;i++){ - dp[0][i]=dp[0][i-1]+(b[i-1]!=c[i-1]); - } - for(int i=1;i<=n;i++){ - for(int j=1;j<=m;j++){ - dp[i][j]=min((dp[i][j-1]+(b[j-1]!=c[i+j-1])),(dp[i-1][j]+(a[i-1]!=c[i+j-1]))); - } - } - cout< -using namespace std; -int main() { - int tt; - cin >> tt; - while (tt--) { - string A, B, C; - cin >> A >> B >> C; - int nA = int(A.size()); - int nB = int(B.size()); - vector> dp(nA + 1, vector(nB + 1, nA + nB + 1)); - dp[0][0] = 0; - for (int i = 0; i <= nA; i++) { - for (int j = 0; j <= nB; j++) { - if (i < nA) { - dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (A[i] != C[i + j])); - } - if (j < nB) { - dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (B[j] != C[i + j])); - } - } - } - cout << dp[nA][nB] << endl; - } -}","#include -#include -#include -#include -using namespace std; -int main() { - int tt; - cin >> tt; - while (tt--) { - string a, b, c; - cin >> a >> b >> c; - - } -}",1 -pathfinder1729,2050E - Three Strings,c++20 ,304416514,304418620," #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - - - #include - - #include - - - - #define fastio() ios::sync_with_stdio(NULL);cin.tie(0);cout.tie(0); - - - - #define int long long int - - using namespace std ; - - // using namespace __gnu_pbds; - - // typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - - int mod = 998244353; - - - - int gcd(int a, int b) - - { - - while (a > 0 && b > 0) { - - if (a > b) { - - a = a % b; - - } - - else { - - b = b % a; - - } - - } - - if (a == 0) { - - return b; - - } - - return a; - - } - - pair overLap(pair a , pair b ) - - { - - - - int l = max(a.first, b.first); - - int r = min(a.second , b.second) ; ; - - - - if(l>r)return {-1, -1 }; - - - - return {l,r}; - - - - - - - - return {-1, -1 }; - - - - - - } - - - - - - - - int LCM(int a , int b ){ - - int ans = (a*b)/(gcd(a,b)) ; - - return ans ; - - } - - - - - - - - - - - - void print(vector &arr){ - - for(auto it : arr){ - - cout<> arr){ - - for(auto it: arr ){ - - cout<>arr){ - - for(auto it :arr){ - - for(auto itr : it){ - - cout<>arr){ - - for(auto it :arr){ - - for(auto itr : it){ - - cout< &arr){ - - for(auto it : arr){ - - cout<>&mat){ - - for(auto itr : mat){ - - - - cout< m ){ - - for(auto it : m ){ - - cout<""<>&mat){ - - for(auto it :mat){ - - cout< m ){ - - for(auto it : m ){ - - cout<""< m ){ - - for(auto it : m ){ - - cout<""< m ){ - - for(auto it : m ){ - - cout<""< > m ){ - - for(auto it : m ){ - - cout<""<arr){ - - mapmp ; - - for(auto it : arr){ - - mp[it]++ ; - - } - - vectort ; - - for(auto it : mp){ - - t.push_back(it.first) ; - - } - - for(int i =0 ; i m ){ - - for(auto it : m ){ - - cout<""<&a , vector&b ){ - - - - // if(a[1]==b[1]) - - // { - - // return a[0]>mp){ - - for(auto it : mp){ - - cout<""<<""freq-""<arr[], int s , vector&tree, vector&vis ){ - - tree.push_back(s); - - vis[s]= 1 ; - - - - - - for(auto it : arr[s]){ - - if(vis[it]==0){ - - - - get_tree(arr, it, tree, vis ); - - } - - } - - } - - - - - - - - - - - - - - - - - - - - - - - - - - int build_segment_tree(vector&tree, vector&arr,int indx , int s , int e){ - - if(s>e)return INT_MIN; - - if(s==e){ - - tree[indx]=arr[s]; - - - - return tree[indx]; - - } - - int mid = (s+e)/2 ; - - int l= build_segment_tree(tree, arr, 2*indx+1, s ,mid ) ; - - int r= build_segment_tree(tree, arr, 2*indx+2, mid+1, e ) ; - - - - tree[indx]=l&r ; - - return l&r ; - - } - - int query_segment_tree(vector&tree, vector&arr,int indx ,int s ,int e , int L ,int R ){ - - - - if(s>=L and e<=R){ - - return tree[indx]; - - } - - if(s>R || emx)return false ; - - return true ; - - } - - void print(queue>q){ - - while(!q.empty()){ - - auto it = q.front() ; - - q.pop() ; - - for(auto itr:it){ - - cout<mt){ - - for(auto it :mt){ - - cout<&arr , int i ){ - - // max heap ; - - int largest = i ; - - int l = 2*i+1 ; - - int r = 2*i+2 ; - - int n = arr.size() ; - - if(larr[i] ){ - - largest = l ; - - } - - if(rarr[largest]){ - - largest= r ; - - } - - if(largest!=i){ - - swap(arr[i], arr[largest]); - - heapify( arr, largest) ; - - } - - } - - string to_binary(int a ){ - - // std::string binary = std::bitset<8>(128).to_string(); //to binary - - // std::cout<(a).to_string() ; - - return res ; - - } - - void print(vector>>&adj){ - - int cnt =0; - - for(auto it : adj){ - - cout<""; - - cnt++ ; - - for(auto itr : it){ - - cout<<""(""<&arr){ - - int n = arr.size() ; - - int internal_nodes = (n/2)-1 ; - - for(int i = internal_nodes ; i>=0 ; i-- ){ - - heapify(arr, i) ; - - } - - //print(arr) ; - - } - - int msb(int a ){ - - for(int i =31 ; i>=0 ; i--){ - - int mask = 1<>arr, map >,int > &mp){ - - for(int i =0 ; i>arr, map >,int > &mp){ - - for(int i =0 ; i>&arr, map>, int > &mp){ - - int n = arr.size() ; - - for(int i =0 ; i<4 ; i++){ - - for(int j=0 ; jparent ; - - vectorrank ; - - public: - - DSU(int n ){ - - parent.resize(n+5) ; - - rank.resize(n+5,0) ; - - for(int i = 0 ; i<=n ; i++){ - - parent[i]=i ; - - } - - } - - int findParent(int val ){ - - if(val==parent[val]) - - return val ; - - - - return parent[val]= findParent(parent[val]); - - } - - void unionByRank(int u , int v ){ - - if(rank[u]>rank[v]){ - - parent[v]=u ; - - } - - else if(rank[u]>&mat, vector&vis, int src ){ - - vis[src]=1 ; - - //cout<>&mat, int n , int v){ - - vector >arr ; - - for(int i =1 ; i<=n ; i++){ - - int a = i; - - if(i==v)continue ; - - if(mat.find(i)!=mat.end()) - - { - - int b = mat[i].size() ; - - arr.push_back({b,a} ) ; - - } - - - - } - - sort(arr.begin(), arr.end()) ; - - reverse(arr.begin(),arr.end()) ; - - //print(arr) ; - - int v1 = arr[0][1] ; - - - - for(auto it: mat[v1]){ - - //cout<>&dp ){ - - int k = i+j ; - - if(k>=c.size())return 0 ; - - if(i>=a.size()){ - - // - - int cnt =0 ; - - while(k=b.size()){ - - int cnt =0 ; - - while(k>a>>b>>c ; - - int n = a.size() ; - - vector>dp(n, vector(n+1+n+1,-1)); - - int ans = fun(a,b, c, 0 , 0 , 0, dp) ; - - int res = -2 ; - - for(int i=0 ; i<2*n+2; i++){ - - res = max(res, dp[n-1][i]); - - } - - cout<> t; - - // t=1 ; - - - - for(int it=1;it<=t;it++) { - - - - // if(it==246){ - - - - // int n , m ; - - // cin>>n>>m ; - - // string s ="""" ; - - // for(int i =0 ; i>a ; - - // s+=a ; - - // s+='0'; - - // } - - // vectorans ; - - // for(int i = 0 ; i>x ; - - // ans.push_back(x) ; xv - - // } - - - - // cout< - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - #include - - - - #include - - #include - - - - #define fastio() ios::sync_with_stdio(NULL);cin.tie(0);cout.tie(0); - - - - #define int long long int - - using namespace std ; - - // using namespace __gnu_pbds; - - // typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - - int mod = 998244353; - - - - int gcd(int a, int b) - - { - - while (a > 0 && b > 0) { - - if (a > b) { - - a = a % b; - - } - - else { - - b = b % a; - - } - - } - - if (a == 0) { - - return b; - - } - - return a; - - } - - pair overLap(pair a , pair b ) - - { - - - - int l = max(a.first, b.first); - - int r = min(a.second , b.second) ; ; - - - - if(l>r)return {-1, -1 }; - - - - return {l,r}; - - - - - - - - return {-1, -1 }; - - - - - - } - - - - - - - - int LCM(int a , int b ){ - - int ans = (a*b)/(gcd(a,b)) ; - - return ans ; - - } - - - - - - - - - - - - void print(vector &arr){ - - for(auto it : arr){ - - cout<> arr){ - - for(auto it: arr ){ - - cout<>arr){ - - for(auto it :arr){ - - for(auto itr : it){ - - cout<>arr){ - - for(auto it :arr){ - - for(auto itr : it){ - - cout< &arr){ - - for(auto it : arr){ - - cout<>&mat){ - - for(auto itr : mat){ - - - - cout< m ){ - - for(auto it : m ){ - - cout<""<>&mat){ - - for(auto it :mat){ - - cout< m ){ - - for(auto it : m ){ - - cout<""< m ){ - - for(auto it : m ){ - - cout<""< m ){ - - for(auto it : m ){ - - cout<""< > m ){ - - for(auto it : m ){ - - cout<""<arr){ - - mapmp ; - - for(auto it : arr){ - - mp[it]++ ; - - } - - vectort ; - - for(auto it : mp){ - - t.push_back(it.first) ; - - } - - for(int i =0 ; i m ){ - - for(auto it : m ){ - - cout<""<&a , vector&b ){ - - - - // if(a[1]==b[1]) - - // { - - // return a[0]>mp){ - - for(auto it : mp){ - - cout<""<<""freq-""<arr[], int s , vector&tree, vector&vis ){ - - tree.push_back(s); - - vis[s]= 1 ; - - - - - - for(auto it : arr[s]){ - - if(vis[it]==0){ - - - - get_tree(arr, it, tree, vis ); - - } - - } - - } - - - - - - - - - - - - - - - - - - - - - - - - - - int build_segment_tree(vector&tree, vector&arr,int indx , int s , int e){ - - if(s>e)return INT_MIN; - - if(s==e){ - - tree[indx]=arr[s]; - - - - return tree[indx]; - - } - - int mid = (s+e)/2 ; - - int l= build_segment_tree(tree, arr, 2*indx+1, s ,mid ) ; - - int r= build_segment_tree(tree, arr, 2*indx+2, mid+1, e ) ; - - - - tree[indx]=l&r ; - - return l&r ; - - } - - int query_segment_tree(vector&tree, vector&arr,int indx ,int s ,int e , int L ,int R ){ - - - - if(s>=L and e<=R){ - - return tree[indx]; - - } - - if(s>R || emx)return false ; - - return true ; - - } - - void print(queue>q){ - - while(!q.empty()){ - - auto it = q.front() ; - - q.pop() ; - - for(auto itr:it){ - - cout<mt){ - - for(auto it :mt){ - - cout<&arr , int i ){ - - // max heap ; - - int largest = i ; - - int l = 2*i+1 ; - - int r = 2*i+2 ; - - int n = arr.size() ; - - if(larr[i] ){ - - largest = l ; - - } - - if(rarr[largest]){ - - largest= r ; - - } - - if(largest!=i){ - - swap(arr[i], arr[largest]); - - heapify( arr, largest) ; - - } - - } - - string to_binary(int a ){ - - // std::string binary = std::bitset<8>(128).to_string(); //to binary - - // std::cout<(a).to_string() ; - - return res ; - - } - - void print(vector>>&adj){ - - int cnt =0; - - for(auto it : adj){ - - cout<""; - - cnt++ ; - - for(auto itr : it){ - - cout<<""(""<&arr){ - - int n = arr.size() ; - - int internal_nodes = (n/2)-1 ; - - for(int i = internal_nodes ; i>=0 ; i-- ){ - - heapify(arr, i) ; - - } - - //print(arr) ; - - } - - int msb(int a ){ - - for(int i =31 ; i>=0 ; i--){ - - int mask = 1<>arr, map >,int > &mp){ - - for(int i =0 ; i>arr, map >,int > &mp){ - - for(int i =0 ; i>&arr, map>, int > &mp){ - - int n = arr.size() ; - - for(int i =0 ; i<4 ; i++){ - - for(int j=0 ; jparent ; - - vectorrank ; - - public: - - DSU(int n ){ - - parent.resize(n+5) ; - - rank.resize(n+5,0) ; - - for(int i = 0 ; i<=n ; i++){ - - parent[i]=i ; - - } - - } - - int findParent(int val ){ - - if(val==parent[val]) - - return val ; - - - - return parent[val]= findParent(parent[val]); - - } - - void unionByRank(int u , int v ){ - - if(rank[u]>rank[v]){ - - parent[v]=u ; - - } - - else if(rank[u]>&mat, vector&vis, int src ){ - - vis[src]=1 ; - - //cout<>&mat, int n , int v){ - - vector >arr ; - - for(int i =1 ; i<=n ; i++){ - - int a = i; - - if(i==v)continue ; - - if(mat.find(i)!=mat.end()) - - { - - int b = mat[i].size() ; - - arr.push_back({b,a} ) ; - - } - - - - } - - sort(arr.begin(), arr.end()) ; - - reverse(arr.begin(),arr.end()) ; - - //print(arr) ; - - int v1 = arr[0][1] ; - - - - for(auto it: mat[v1]){ - - //cout<>&dp ){ - - int k = i+j ; - - if(k>=c.size())return 0 ; - - if(i>=a.size()){ - - // - - int cnt =0 ; - - while(k=b.size()){ - - int cnt =0 ; - - while(k=a.size())return 0 ; - - if(j>=b.size() ) return 0 ; - - - - if(a[i]==b[j]){ - - return 1+ lcs(a, b, i+1, j+1 ) ; - - } - - else { - - int op1 = lcs(a,b, i+1, j ) ; - - int op2 = lcs(a, b, i,j+1 ) ; - - return max(op1,op2) ; - - } - - return 0 ; - - } - - void solve() - - { - - string a , b,c ; - - cin>>a>>b>>c ; - - int n = a.size() ; - - int m= b.size() ; - - vector>dp(n, vector(m,-1)); - - int ans = fun(a,b, c, 0 , 0 , 0, dp) ; - - cout<> t; - - // t=1 ; - - - - for(int it=1;it<=t;it++) { - - - - // if(it==246){ - - - - // int n , m ; - - // cin>>n>>m ; - - // string s ="""" ; - - // for(int i =0 ; i>a ; - - // s+=a ; - - // s+='0'; - - // } - - // vectorans ; - - // for(int i = 0 ; i>x ; - - // ans.push_back(x) ; xv - - // } - - - - // cout< - -using namespace std; - -using ll = long long; -const long long MOD = 1000000007; - -#define all(c) (c).begin(), (c).end() -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -const int MAXN = 2e5 + 10; -const ll INF = 1e18; - -int solve(int i, int j, string &a, string &b, vector> &dp) { - if (i == a.size() || j == b.size()) return 0; - if (~dp[i][j]) return dp[i][j]; - int ret = 0; - if (a[i] == b[j]) ret = max(ret, solve(i + 1, j + 1, a, b, dp) + 1); - ret = max(ret, solve(i + 1, j, a, b, dp)); - ret = max(ret, solve(i, j + 1, a, b, dp)); - return dp[i][j]= ret; -} -vector vis(MAXN); -int cnt; -void print(int i, int j, string &a, string &b, vector>&dp) { - if (i == a.size() || j == b.size()) return; - int opt = solve(i, j, a, b, dp); - if (a[i] == b[j] && opt == solve(i + 1, j + 1, a, b, dp) + 1) { - vis[i] = true; - return print(i + 1, j + 1, a, b, dp); - } - if (opt == solve(i + 1, j, a, b, dp)) return print(i + 1, j, a, b, dp); - return print(i, j + 1, a, b, dp); -} -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int tc; - cin >> tc; - while (tc--) { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - ll dp[n + 1][m + 1]; - memset(dp, n + m + 1, sizeof(dp)); - dp[0][0] = 0; - for(int i = 0; i <=n; i++){ - for(int j = 0; j <=m; j++){ - int k = i + j; - if(i < n){ - ll cnt = c[k] != a[i]; - dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt); - } - if(j < m){ - ll cnt = c[k] != b[j]; - dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt); - } - } - } - cout << dp[n][m] < - -using namespace std; - -using ll = long long; -const long long MOD = 1000000007; - -#define all(c) (c).begin(), (c).end() -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -const int MAXN = 2e5 + 10; -const ll INF = 1e18; - -int solve(int i, int j, string &a, string &b, vector> &dp) { - if (i == a.size() || j == b.size()) return 0; - if (~dp[i][j]) return dp[i][j]; - int ret = 0; - if (a[i] == b[j]) ret = max(ret, solve(i + 1, j + 1, a, b, dp) + 1); - ret = max(ret, solve(i + 1, j, a, b, dp)); - ret = max(ret, solve(i, j + 1, a, b, dp)); - return dp[i][j]= ret; -} -vector vis(MAXN); -int cnt; -void print(int i, int j, string &a, string &b, vector>&dp) { - if (i == a.size() || j == b.size()) return; - int opt = solve(i, j, a, b, dp); - if (a[i] == b[j] && opt == solve(i + 1, j + 1, a, b, dp) + 1) { - vis[i] = true; - return print(i + 1, j + 1, a, b, dp); - } - if (opt == solve(i + 1, j, a, b, dp)) return print(i + 1, j, a, b, dp); - return print(i, j + 1, a, b, dp); -} -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int tc; - cin >> tc; - while (tc--) { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - vector dp(n + 1, vector(m + 1, n + m + 1)); - dp[0][0] = 0; - for(int i = 0; i <=n; i++){ - for(int j = 0; j <=m; j++){ - int k = i + j; - if(i < n){ - int cnt = c[k] != a[i]; - dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt); - } - if(j < m){ - int cnt = c[k] != b[j]; - dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt); - } - } - } - cout << dp[n][m] < -using namespace std; -int dp[2001][2001]; -int f(string &a,string &b,string &c,int i,int j){ - if(dp[i][j]!=-1) - return dp[i][j]; - if(i==a.length()&&j==b.length()) - return dp[i][j]=0; - if(i>a.length()||j>b.length()) - return 1e5; - int min_one=INT_MAX; - if(i!=a.length()&&a[i]==c[i+j]) - min_one=min(min_one,f(a,b,c,i+1,j)); - if(j!=b.length()&&b[j]==c[i+j]) - min_one=min(min_one,f(a,b,c,i,j+1)); - min_one=min(min_one,1+min(f(a,b,c,i+1,j),f(a,b,c,i,j+1))); - return dp[i][j]=min_one; -} -int main(){ - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - for(int i=0;i<2001;i++){ - for(int j=0;j<2001;j++){ - dp[i][j]=-1; - } - } - cout< -using namespace std; -int dp[1001][1001]; -int f(string &a,string &b,string &c,int i,int j){ - if(dp[i][j]!=-1) - return dp[i][j]; - if(i==a.length()&&j==b.length()) - return dp[i][j]=0; - if(i>a.length()||j>b.length()) - return 1e5; - int min_one=INT_MAX; - if(i!=a.length()&&a[i]==c[i+j]) - min_one=min(min_one,f(a,b,c,i+1,j)); - if(j!=b.length()&&b[j]==c[i+j]) - min_one=min(min_one,f(a,b,c,i,j+1)); - min_one=min(min_one,1+min(f(a,b,c,i+1,j),f(a,b,c,i,j+1))); - return dp[i][j]=min_one; -} -int main(){ - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - for(int i=0;i<1001;i++){ - for(int j=0;j<1001;j++){ - dp[i][j]=-1; - } - } - } -}",1 -SidZRed_15,2050E - Three Strings,c++17 ,298659599,298658830,"#include -#define MOD 1000000007 -#define loop(i, a, b) for (int i = a; i < b; i++) -#define append push_back -#define vi vector -#define mi map -#define sortv(a) sort(a.begin(), a.end()) -#define int long long - -typedef unsigned long long ull; - -using namespace std; - -void fast_io() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - -// <-----------SidZRed--------------> -// <----Why are you reading this----> - -signed main() { - fast_io(); - - int t; - cin >> t; - - while (t--) { - string a, b, c; - cin >> a >> b >> c; - - int n = a.length(), m = b.length(), k = c.length(); - - // DP table: dp[x][i] -> min changes for first x chars of c using first i chars of a - vector> dp(k + 1, vector(n + 1, INT_MAX)); - dp[0][0] = 0; - - for (int x = 1; x <= k; x++) { - if (x <= m) { - dp[x][0] = dp[x - 1][0] + (c[x - 1] != b[x - 1]); - } - } - - for (int i = 1; i <= n; i++) { - if (i <= k) { - dp[i][i] = dp[i - 1][i - 1] + (c[i - 1] != a[i - 1]); - } - } - - for (int x = 1; x <= k; x++) { - for (int i = 0; i <= min(x, n); i++) { - int j = x - i; - if (j > m) continue; - - if (j > 0 && x - 1 >= 0) { - dp[x][i] = min(dp[x][i], dp[x - 1][i] + (c[x - 1] != b[j - 1])); - } - - if (i > 0 && x - 1 >= 0) { - dp[x][i] = min(dp[x][i], dp[x - 1][i - 1] + (c[x - 1] != a[i - 1])); - } - } - } - - int ans = INT_MAX; - for (int i = 0; i <= n; i++) { - ans = min(ans, dp[k][i]); - } - - cout << ans << endl; - } - return 0; -} -","#include - -#define MOD 1000000007 -#define loop(i,a,b) for(int i = a;i < b;i++) -#define append push_back -#define vi vector -#define mi map -#define sort(a) sort(a.begin(), a.end()) -#define int long long - -typedef unsigned long long ull; - -using namespace std; - -void fast_io() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - -// <-----------SidZRed--------------> -// <----Why are you reading this----> - - -signed main(){ - fast_io(); - - int t; - cin>>t; - - while(t--){ - string a, b, c; - cin>>a>>b>>c; - - vector> dp(c.length()+1, vector(a.length() + 1, INT_MAX)); - // dp[x][i] represents the minimum number of changes needed to create the first x characters of c using the first i characters of a and first x-i characters of b. - - dp[0][0] = 0; - - for(int x=1;x<=c.length();x++){ - dp[x][0] = dp[x-1][0] + (c[x-1] != b[x-1]); - } - for(int i=1;i<=a.length();i++){ - dp[i][i] = dp[i-1][i-1] + (c[i-1] != a[i-1]); - } - - for(int x=1;x<=c.length();x++){ - for(int i=1;i<=min(x, (int)a.length());i++){ - dp[x][i] = min(dp[x-1][i] + (c[x-1] != b[x-i-1]), dp[x-1][i-1] + (c[x-1] != a[i-1])); - } - } - - int ans = *min_element(dp[c.length()].begin(), dp[c.length()].end()); - cout< -using namespace std; - -#define ll long long -#define pb push_baci+j -#define ppb pop_baci+j -#define mp mai+je_pair -#define vi vector -#define vll vector - -#define pii pair -#define pll pair -#define ff first -#define ss second -#define all(v) v.begin(), v.end() - -#define rep(i, a, b) for (int i = a; i <= b; ++i) -#define repr(i, a, b) for (int i = a; i >= b; --i) -#define fori(n) for (int i = 0; i < n; ++i) - -#define mxe(v) *max_element(v.begin(),v.end()) -#define mne(v) *min_element(v.begin(),v.end()) -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) -#define Yes { cout << ""YES\n""; return; } -#define No { cout << ""NO\n""; return; } - -template void print_value(const vector& vec) { for (const auto& element : vec) cout << element << "" ""; } -template void print_value(const T& value) { cout << value << "" ""; } -template void print_value(const T& value, const Args&... args) { print_value(value); print_value(args...); } -template void print(const T& value, const Args&... args) { print_value(value, args...); cout << endl; } - -template void debug_value(const vector& vec) { cout << ""[ ""; for (const auto& element : vec) cout << element << "" ""; cout << ""] ""; } -template void debug_value(const T& value) { cout << ""# "" << value << "" ""; } -template void debug_value(const T& value, const Args&... args) { debug_value(value); debug_value(args...); } -template void debug(const T& value, const Args&... args) { debug_value(value, args...); cout << endl; } - -const int MOD = 1e9 + 7, INF = INT_MAX; - - -//------------------------Code Starts------------------------- - -int rec(string a, string b, string c, int i, int j){ - - if (i+j == c.size()) return 0; - - //come from a - int sc1; - - if (c[i+j]==a[i]){ - sc1 = rec(a,b,c,i+1,j); - } - else{ - sc1 = 1 + rec(a,b,c,i+1,j); - } - - //come from b - int sc2; - - if (c[i+j]==b[j]){ - sc2 = rec(a,b,c,i,j+1); - } - else{ - sc2 = 1 + rec(a,b,c,i,j+1); - } - - return min(sc1, sc2); - -} - - -void solve(){ - string a,b,c; cin>>a>>b>>c; - print(rec(a,b,c,0,0)); -} - - -//------------------------Code Ends--------------------------- - - -int main() { - fastio; - int T = 1; - cin >> T; - while (T--) - { - solve(); - } - return 0; -}","#include -using namespace std; - -#define ll long long -#define pb push_back -#define ppb pop_back -#define mp make_pair -#define vi vector -#define vll vector - -#define pii pair -#define pll pair -#define ff first -#define ss second -#define all(v) v.begin(), v.end() - -#define rep(i, a, b) for (int i = a; i <= b; ++i) -#define repr(i, a, b) for (int i = a; i >= b; --i) -#define fori(n) for (int i = 0; i < n; ++i) - -#define mxe(v) *max_element(v.begin(),v.end()) -#define mne(v) *min_element(v.begin(),v.end()) -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) -#define Yes { cout << ""YES\n""; return; } -#define No { cout << ""NO\n""; return; } - -template void print_value(const vector& vec) { for (const auto& element : vec) cout << element << "" ""; } -template void print_value(const T& value) { cout << value << "" ""; } -template void print_value(const T& value, const Args&... args) { print_value(value); print_value(args...); } -template void print(const T& value, const Args&... args) { print_value(value, args...); cout << endl; } - -const int MOD = 1e9 + 7, INF = INT_MAX; - -//------------------------Code Starts------------------------- - -int rec(string& a, string& b, string& c, int i, int j, vector>& dp) { - if (i + j == c.size()) return 0; - if (dp[i][j] != -1) return dp[i][j]; - - int sc1 = INF, sc2 = INF; - - if (i < a.size() && c[i + j] == a[i]) { - sc1 = rec(a, b, c, i + 1, j, dp); - } else if (i < a.size()) { - sc1 = 1 + rec(a, b, c, i + 1, j, dp); - } - - if (j < b.size() && c[i + j] == b[j]) { - sc2 = rec(a, b, c, i, j + 1, dp); - } else if (j < b.size()) { - sc2 = 1 + rec(a, b, c, i, j + 1, dp); - } - - return dp[i][j] = min(sc1, sc2); -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - vector> dp(a.size() + 1, vector(b.size() + 1, -1)); - print(rec(a, b, c, 0, 0, dp)); -} - -//------------------------Code Ends--------------------------- - -int main() { - fastio; - int T = 1; - cin >> T; - while (T--) { - solve(); - } - return 0; -} -",2 -frome,2050E - Three Strings,c++17 ,298482698,298483059,"#include -using namespace std; - -#define int long long - -void solve() { - string a, b, c; cin >> a >> b >> c; - int n = a.size(); int m = b.size(); - - vector> dp(n+1, vector(m+1, 1e9)); - dp[0][0] = 0; - for (int i = 1; i <= n; i++) { - for (int j = 0; j <= m; j++) { - bool changeA = !(a[i-1] == c[i+j-1]); - bool changeB = !(b[j-1] == c[i+j-1]); - - dp[i][j] = min(dp[i-1][j] + changeA, dp[i][j-1] + changeB); - } - } - - cout << dp[n][m] << endl; -} - -signed main() { - int t; cin >> t; - - while (t--) { - solve(); - } -} -","#include -using namespace std; - -#define int long long - -void solve() { - string a, b, c; cin >> a >> b >> c; - int n = a.size(); int m = b.size(); - - vector> dp(n+1, vector(m+1, 1e9)); - dp[0][0] = 0; - for (int i = 0; i <= n; i++) { - for (int j = 0; j <= m; j++) { - if (i < n) { - int changeA = (a[i] != c[i+j]); - dp[i+1][j] = min(dp[i+1][j], dp[i][j] + changeA); - } - - if (j < m) { - int changeB = (b[j] != c[i+j]); - dp[i][j+1] = min(dp[i][j+1], dp[i][j] + changeB); - } - } - } - - cout << dp[n][m] << endl; -} - -signed main() { - int t; cin >> t; - - while (t--) { - solve(); - } -} -",2 -isheriff,2050E - Three Strings,c++17 ,298486266,298390475,"//#include ""dec24_1.h"" - -#include -#include -#include -#include -#include - -using namespace std; - -int SolveHelper(std::vector>& dp, std::string_view string1, - std::string_view string2, std::string_view string3, int p1, - int p2, int p3) { - if (dp[p1][p2] != -1) return dp[p1][p2]; - if (p1 == string1.size()) { - if (dp[p1][p2] != -1) return dp[p1][p2]; - int count = 0; - for (int i = p2; i < string2.size(); i++) { - if (string2[i] != string3[p1 + i]) { - count++; - } - } - dp[p1][p2] = count; - return count; - } - - if (p2 == string2.size()) { - int count = 0; - for (int i = p1; i < string1.size(); i++) { - if (string1[i] != string3[p2 + i]) { - count++; - } - } - dp[p1][p2] = count; - return count; - } - int x; - if (string1[p1] == string3[p3]) { - x = SolveHelper(dp, string1, string2, string3, p1 + 1, p2, p3 + 1); - } else { - x = SolveHelper(dp, string1, string2, string3, p1 + 1, p2, p3 + 1) + 1; - } - if (string2[p2] == string3[p3]) { - x = std::min(x, - SolveHelper(dp, string1, string2, string3, p1, p2 + 1, p3 + 1)); - } else { - x = std::min(x, - SolveHelper(dp, string1, string2, string3, p1, p2 + 1, p3 + 1) + 1); - } - dp[p1][p2] = x; - return x; -} - -class Problem { - public: - Problem() = default; - int Solve(std::vector>& dp, - std::string_view string1, - std::string_view string2, - std::string_view string3) { - return SolveHelper(dp, string1, string2, string3, 0, 0, 0); - } -}; - -int main() { - int n; - cin >> n; - std::vector output; - for (int i = 0; i < n; i++) { - std::string string1, string2, string3; - Problem problem; - cin >> string1; - cin >> string2; - cin >> string3; - std::vector> matrix(string1.size() + 1, - std::vector(string2.size() + 1, - -1)); - output.push_back(problem.Solve(matrix, std::string_view(string1), - std::string_view(string2), - std::string_view(string3))); - } - for (int i = 0; i < n; i++) { - cout << output[i] << endl; - } - - return 0; -} -","#include -#include -#include - -using namespace std; - -int min_val = 1000000000; -void SolveHelper(std::string& string1, std::string& string2, - std::string& string3, int p1, int p2, int p3, int current) { - if (p3 == string3.size()) { - if (current < min_val) min_val = current; - return; - } - - if (p1 == string1.size()) { - if (string2[p2] == string3[p3]) { - SolveHelper(string1, string2, string3, p1, p2 + 1, p3 + 1, current); - } else { - SolveHelper(string1, string2, string3, p1, p2 + 1, p3 + 1, current + 1); - } - return; - } - if (p2 == string2.size()) { - if (string1[p1] == string3[p3]) { - SolveHelper(string1, string2, string3, p1 + 1, p2, p3 + 1, current); - } else { - SolveHelper(string1, string2, string3, p1 + 1, p2, p3 + 1, current + 1); - } - return; - } - - if (string1[p1] == string3[p3]) { - SolveHelper(string1, string2, string3, p1 + 1, p2, p3 + 1, current); - } - if (string2[p2] == string3[p3]) { - SolveHelper(string1, string2, string3, p1, p2 + 1, p3 + 1, current); - } - SolveHelper(string1, string2, string3, p1 + 1, p2, p3 + 1, current + 1); - SolveHelper(string1, string2, string3, p1, p2 + 1, p3 + 1, current + 1); -} - -class Problem { - public: - Problem() = default; - int Solve(std::string& string1, std::string& string2, std::string& string3) { - min_val = 1000000000; - SolveHelper(string1, string2, string3, 0, 0, 0, 0); - return min_val; - } -}; - -int main() { - /* - std::string line; - std::vector tokens; - - for (int i = 0; i < 3; i++) { - std::getline(std::cin, line); - std::istringstream iss(line); - std::string token; - - while (std::getline(iss, token, ' ')) { - tokens.push_back(token); - } - - for (const std::string& tok : tokens) { - std::cout << stoi(tok) << std::endl; - } - tokens.clear(); // Clear tokens for the next line - } - return 0; - */ - int n; - cin >> n; - std::vector output; - for (int i = 0; i < n; i++) { - std::string string1, string2, string3; - Problem problem; - cin >> string1; - cin >> string2; - cin >> string3; - output.push_back(problem.Solve(string1, string2, string3)); - } - for (int i = 0; i < n; i++) { - cout << output[i] << endl; - } - - return 0; -} -",1 -shaitanbaba,2050E - Three Strings,c++17 ,298593244,298593672,"#include -using namespace std; -typedef long long ll; -vectorv5; -long long power(long long A, long long B) -{ - if (B == 0) - return 1; - - long long res = power(A, B / 2); - - if (B % 2) - return res * res * A; - else - return res * res; -} -bool is_prime(int n){ - if(n==1){ - return 0; - } - bool b = true; - for(int i=2;i*i<=n;i++){ - if(n%i==0){ - b = false; - break; - } - } - return b; -} - void primeFactors(ll n) -{ - while(n%2==0){ - v5.push_back(2); - n=(n/2); - } - for (int i = 3; i*i <= n; i = i+2){ - while (n%i == 0){ - v5.push_back(i); - n = n/i; - } - } - if (n > 2){ - v5.push_back(n); - } -} -bool cmp(pair &a, pair &b){ - if(a.first!=b.first){ - if(a.first>b.first) return true; - return false; - } - else{ - if(a.second=0;i--){ - cout<<((n>>i)&1); - } - cout<>&dp){ - if(i==n && j==m) return 0; - if(dp[i][j]!=-1) return dp[i][j]; - int ans=c.size(); - if(i>t; -while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(); - int m=b.size(); - vector>dp(n,vector(m,-1)); - cout< -using namespace std; -typedef long long ll; -vectorv5; -long long power(long long A, long long B) -{ - if (B == 0) - return 1; - - long long res = power(A, B / 2); - - if (B % 2) - return res * res * A; - else - return res * res; -} -bool is_prime(int n){ - if(n==1){ - return 0; - } - bool b = true; - for(int i=2;i*i<=n;i++){ - if(n%i==0){ - b = false; - break; - } - } - return b; -} - void primeFactors(ll n) -{ - while(n%2==0){ - v5.push_back(2); - n=(n/2); - } - for (int i = 3; i*i <= n; i = i+2){ - while (n%i == 0){ - v5.push_back(i); - n = n/i; - } - } - if (n > 2){ - v5.push_back(n); - } -} -bool cmp(pair &a, pair &b){ - if(a.first!=b.first){ - if(a.first>b.first) return true; - return false; - } - else{ - if(a.second=0;i--){ - cout<<((n>>i)&1); - } - cout<>&dp){ - if(i==n && j==m) return 0; - if(dp[i][j]!=-1) return dp[i][j]; - int ans=c.size(); - if(i>t; -while(t--){ - string a,b,c; - cin>>a>>b>>c; - int n=a.size(); - int m=b.size(); - vector>dp(n+1,vector(m+1,-1)); - cout< -#include -#include -using namespace std; - - - - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int na = a.size(); - int nb = b.size(); - vector> dp(na + 1, vector(nb + 1, na + nb + 1)); - for (int i = 0; i <= a.size();i++) { - for (int j = 0; j <= b.size();j++) { - dp[i][j] = 1e7; - } - } - dp[0][0] = 0; - for (int i = 0; i <= a.size();i++) { - for (int j = 0; j <= b.size();j++) { - if (i == 0 && j == 0) { - dp[i][j] = 0; - } - else { - if (i == 0) { - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1])); - } - else if (j == 0) { - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1])); - } - else { - dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1]))); - } - } - } - } - cout << dp[a.size()][b.size()] << '\n'; -} -int main() { - int te; - cin >> te; - while (te--) { - solve(); - } -}","#include -#include -using namespace std; - - - - -void solve() { - char* a = new char[1005]; - char* b = new char[1005]; - char* c = new char[1005]; - cin.getline(a, 1000, '\n'); - cin.getline(b, 1000, '\n'); - cin.getline(c, 1000, '\n'); - int** dp = new int*[strlen(a) + 1]; - for (int i = 0; i <= strlen(a);i++) { - dp[i] = new int[strlen(b) + 1]; - } - for (int i = 0; i <= strlen(a);i++) { - for (int j = 0; j <= strlen(b);j++) { - dp[i][j] = 1e7; - } - } - dp[0][0] = 0; - for (int i = 0; i <= strlen(a);i++) { - for (int j = 0; j <= strlen(b);j++) { - if (i == 0 && j == 0) { - dp[i][j] = 0; - } - else { - if (i == 0) { - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1])); - } - else if (j == 0) { - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1])); - } - else { - dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1]))); - } - } - } - } - cout << dp[strlen(a)][strlen(b)] << '\n'; - for (int i = 0; i <= strlen(a);i++) { - delete[] dp[i]; - dp[i] = NULL; - } - delete[] dp; - dp = NULL; - delete[] a; - a = NULL; - delete[] b; - b = NULL; - delete[] c; - c = NULL; -} -int main() { - int te; - cin >> te; - cin.ignore(); - while (te--) { - solve(); - } -}",1 -Fatoma,2050E - Three Strings,c++20 ,298067023,298066745,"#include -#define ll long long -using namespace std; -const int md= 998244353; -const int N=200005; -const int M=1<<13; -int dx[]={0,0,-1,1}; -int dy[]={1,-1,0,0}; -string dir=""RLDU""; -vector>dp; -string a,b,c; -int n,m; -int rec(int i,int j) -{ - if(i>a.size()||j>b.size())return 1e9; - - if(i==a.size()) - { - int rem=0; - for(int k=j;k>t; - while(t--) - { - cin>>a>>b>>c; - dp=vector>(a.size()+5,vector(b.size()+5,-1)); - cout< -#define ll long long -using namespace std; -const int md= 998244353; -const int N=200005; -const int M=1<<13; -int dx[]={0,0,-1,1}; -int dy[]={1,-1,0,0}; -string dir=""RLDU""; -vector>dp; -string a,b,c; -int n,m; -int rec(int i,int j) -{ - if(i>a.size()||j>b.size())return 1e9; - - if(i==a.size()) - { - int rem=0; - for(int k=j;k>t; - while(t--) - { - cin>>a>>b>>c; - dp=vector>(a.size()+5,vector(b.size()+5,-1)); - cout< -using namespace std; - -typedef long long int lli; -const int modd = 1e9 + 7; - -#define int long long -#define F first -#define S second -#define pb push_back -#define ppb pop_back -#define all(x) begin(x), end(x) -#define allr(x) rbegin(x), rend(x) -#define rep(i, a, b) for (int i = a; i <= b; i++) -#define bac(i, a, b) for (int i = a; i >= b; i--) -#define yes ""YES"" -#define no ""NO"" -#define nl "" \n"" -#define ak(x) cout << x << ""\n""; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -template using max_heap = priority_queue; -template using min_heap = priority_queue, greater>; - - -int solve(int l,int m,int n,string &a,string &b,string &c,vector>&dp){ - if(n==0) return 0; - if(l == 0){ - // cout<<""AK:""<<""M:""<>a>>b>>c; - - int l=a.size(); - int m=b.size(); - int n=c.size(); - vector>dp(l+1,vector(m+1,-1)); - cout<> t; - - while (t--){ - solve(); - } -}","#include -using namespace std; - -typedef long long int lli; -const int modd = 1e9 + 7; - -#define int long long -#define F first -#define S second -#define pb push_back -#define ppb pop_back -#define all(x) begin(x), end(x) -#define allr(x) rbegin(x), rend(x) -#define rep(i, a, b) for (int i = a; i <= b; i++) -#define bac(i, a, b) for (int i = a; i >= b; i--) -#define yes ""YES"" -#define no ""NO"" -#define nl "" \n"" -#define ak(x) cout << x << ""\n""; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -template using max_heap = priority_queue; -template using min_heap = priority_queue, greater>; - - -void solve(){ - -} - - -int32_t main(){ - fastio(); -#ifndef ONLINE_JUDGE - // for getting input from input.txt - freopen(""input.txt"", ""r"", stdin); - // for writing output to output.txt - freopen(""output.txt"", ""w"", stdout); -#endif - - int t = 1; - cin >> t; - - while (t--){ - solve(); - } -}",1 -Salfi_Sabit,2050E - Three Strings,c++17 ,297204759,297204842,"#include -using namespace std; - -const int MAX_N = (int) 1e3; -const int INF = (int) 1e9; -int dp[MAX_N][MAX_N]; -string a, b, c; -int n, m; - -int sol (int i = 0, int j = 0) { - if (i == n and j == m) { - return 0; - } - int& ans = dp[i][j]; - if (ans != -1) { - return ans; - } - ans = INF; - int k = i + j; - if (i < n) { - ans = min(ans, sol(i + 1, j) + (a[i] != c[k])); - } - if (j < m) { - ans = min(ans, sol(i, j + 1) + (b[j] != c[k])); - } - return ans; -} - -int main () { - ios::sync_with_stdio(false); - cin.tie(0); - int tt; - cin >> tt; - while (tt--) { - cin >> a >> b >> c; - n = (int) a.size(); - m = (int) b.size(); - for (int i = 0; i <= n; ++i) { - for (int j = 0; j <= m; ++j) { - dp[i][j] = -1; - } - } - cout << sol() << '\n'; - } - return 0; -}","#include -using namespace std; - -const int MAX_N = (int) 1e3; -const int INF = (int) 1e9; -int dp[MAX_N + 1][MAX_N + 1]; -string a, b, c; -int n, m; - -int sol (int i = 0, int j = 0) { - if (i == n and j == m) { - return 0; - } - int& ans = dp[i][j]; - if (ans != -1) { - return ans; - } - ans = INF; - int k = i + j; - if (i < n) { - ans = min(ans, sol(i + 1, j) + (a[i] != c[k])); - } - if (j < m) { - ans = min(ans, sol(i, j + 1) + (b[j] != c[k])); - } - return ans; -} - -int main () { - ios::sync_with_stdio(false); - cin.tie(0); - int tt; - cin >> tt; - while (tt--) { - cin >> a >> b >> c; - n = (int) a.size(); - m = (int) b.size(); - for (int i = 0; i <= n; ++i) { - for (int j = 0; j <= m; ++j) { - dp[i][j] = -1; - } - } - cout << sol() << '\n'; - } - return 0; -}",2 -VandanRogheliya,2050E - Three Strings,c++20 ,295758333,295763640,"#include -#pragma GCC optimize(""O3"") -#pragma GCC optimize(""Ofast"") -#pragma GCC optimize(""unroll-loops"") -#pragma GCC optimize(""no-stack-protector"") -#pragma GCC optimize(""fast-math"") -#pragma GCC optimize(""trapv"") - -#include -using namespace std; - -typedef pair pii; -typedef pair pll; -typedef vector vi; -typedef vector vl; -typedef vector vvi; -typedef vector vvl; -typedef long long int ll; -typedef unsigned long long int ull; -typedef priority_queue mxhpl; -typedef priority_queue mxhpi; -typedef priority_queue, greater> mnhpl; -typedef priority_queue, greater> mnhpi; - -#define rep(i, a, b) for (int i = a; i < (b); ++i) -#define sz(x) (int)(x).size() -#define REP(i, start, end) for (ll i = start; i <= end; ++i) -#define RREP(i, end, start) for (ll i = end; i >= start; --i) -#define parr(a, n) \ - rep(i, 0, n) { \ - cout << a[i] << "" ""; \ - } \ - cout << ""\n"" -#define sarr(a, n) rep(i, 0, n) cin >> a[i] -#define pb push_back -#define F first -#define S second -#define all(a) a.begin(), a.end() -#define mset(a, x) memset(a, x, sizeof(a)) -#define ps(x, y) \ - fixed << setprecision(y) << x // cout << ps(ans, decimal places); -#define setbits(x) __builtin_popcountll(x) -#define zrobits(x) __builtin_ctzll(x) - -// DEBUGGING -void __print(int x) { - cerr << x; -} -void __print(long x) { - cerr << x; -} -void __print(long long x) { - cerr << x; -} -void __print(unsigned x) { - cerr << x; -} -void __print(unsigned long x) { - cerr << x; -} -void __print(unsigned long long x) { - cerr << x; -} -void __print(float x) { - cerr << x; -} -void __print(double x) { - cerr << x; -} -void __print(long double x) { - cerr << x; -} -void __print(char x) { - cerr << '\'' << x << '\''; -} -void __print(const char* x) { - cerr << '\""' << x << '\""'; -} -void __print(const string& x) { - cerr << '\""' << x << '\""'; -} -void __print(bool x) { - cerr << (x ? ""true"" : ""false""); -} - -template -void __print(const pair& x) { - cerr << '{'; - __print(x.first); - cerr << ','; - __print(x.second); - cerr << '}'; -} -template -void __print(const T& x) { - int f = 0; - cerr << '{'; - for (auto& i : x) - cerr << (f++ ? "","" : """"), __print(i); - cerr << ""}""; -} -void _print() { - cerr << ""]\n""; -} -template -void _print(T t, V... v) { - __print(t); - if (sizeof...(v)) cerr << "", ""; - _print(v...); -} -#ifndef ONLINE_JUDGE -#define debug(x...) \ - cerr << ""["" << #x << ""] = [""; \ - _print(x) -#else -#define debug(x...) -#endif - -// Fast IO -void IO() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); -#endif -} - -#define MOD 1000000007 - -// CODE -/*******************************************************/ -#define MX 1003 // TODO: - -ll an, bn, cn; -string a, b, c; - -ll dp[MX][MX]; - -ll recFun(ll i = 0, ll j = 0, ll k = 0, ll miss = 0) { - if (dp[i][j] != INT_MAX && miss >= dp[i][j]) return dp[i][j]; - if (i >= an) { - while (j < bn) { - if (b[j] != c[k]) miss++; - j++; - k++; - } - return dp[i][j] = miss; - } - if (j >= bn) { - while (i < an) { - if (a[i] != c[k]) miss++; - i++; - k++; - } - return dp[i][j] = miss; - } - if (k >= cn) { - return INT_MAX; - } - ll inc1 = a[i] == c[k] ? 0 : 1; - ll inc2 = b[j] == c[k] ? 0 : 1; - ll ans1 = recFun(i + 1, j, k + 1, miss + inc1); - ll ans2 = recFun(i, j + 1, k + 1, miss + inc2); - ans1 = min(ans1, ans2); - dp[i][j] = min(dp[i][j], ans1); - return dp[i][j]; -} - -void solve() { - cin >> a >> b >> c; - an = sz(a); - bn = sz(b); - cn = sz(c); - ll* begin = &dp[0][0]; - size_t size = sizeof(dp) / sizeof(**dp); - - fill_n(begin, size, INT_MAX); - - cout << recFun() << endl; -} - -int main() { - IO(); - int t = 1; - - cin >> t; - - while (t--) { - solve(); - } - return 0; -} - -/*******************************************************/ -","#include -#pragma GCC optimize(""O3"") -#pragma GCC optimize(""Ofast"") -#pragma GCC optimize(""unroll-loops"") -#pragma GCC optimize(""no-stack-protector"") -#pragma GCC optimize(""fast-math"") -#pragma GCC optimize(""trapv"") - -#include -using namespace std; - -typedef pair pii; -typedef pair pll; -typedef vector vi; -typedef vector vl; -typedef vector vvi; -typedef vector vvl; -typedef long long int ll; -typedef unsigned long long int ull; -typedef priority_queue mxhpl; -typedef priority_queue mxhpi; -typedef priority_queue, greater> mnhpl; -typedef priority_queue, greater> mnhpi; - -#define rep(i, a, b) for (int i = a; i < (b); ++i) -#define sz(x) (int)(x).size() -#define REP(i, start, end) for (ll i = start; i <= end; ++i) -#define RREP(i, end, start) for (ll i = end; i >= start; --i) -#define parr(a, n) \ - rep(i, 0, n) { \ - cout << a[i] << "" ""; \ - } \ - cout << ""\n"" -#define sarr(a, n) rep(i, 0, n) cin >> a[i] -#define pb push_back -#define F first -#define S second -#define all(a) a.begin(), a.end() -#define mset(a, x) memset(a, x, sizeof(a)) -#define ps(x, y) \ - fixed << setprecision(y) << x // cout << ps(ans, decimal places); -#define setbits(x) __builtin_popcountll(x) -#define zrobits(x) __builtin_ctzll(x) - -// DEBUGGING -void __print(int x) { - cerr << x; -} -void __print(long x) { - cerr << x; -} -void __print(long long x) { - cerr << x; -} -void __print(unsigned x) { - cerr << x; -} -void __print(unsigned long x) { - cerr << x; -} -void __print(unsigned long long x) { - cerr << x; -} -void __print(float x) { - cerr << x; -} -void __print(double x) { - cerr << x; -} -void __print(long double x) { - cerr << x; -} -void __print(char x) { - cerr << '\'' << x << '\''; -} -void __print(const char* x) { - cerr << '\""' << x << '\""'; -} -void __print(const string& x) { - cerr << '\""' << x << '\""'; -} -void __print(bool x) { - cerr << (x ? ""true"" : ""false""); -} - -template -void __print(const pair& x) { - cerr << '{'; - __print(x.first); - cerr << ','; - __print(x.second); - cerr << '}'; -} -template -void __print(const T& x) { - int f = 0; - cerr << '{'; - for (auto& i : x) - cerr << (f++ ? "","" : """"), __print(i); - cerr << ""}""; -} -void _print() { - cerr << ""]\n""; -} -template -void _print(T t, V... v) { - __print(t); - if (sizeof...(v)) cerr << "", ""; - _print(v...); -} -#ifndef ONLINE_JUDGE -#define debug(x...) \ - cerr << ""["" << #x << ""] = [""; \ - _print(x) -#else -#define debug(x...) -#endif - -// Fast IO -void IO() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); -#endif -} - -#define MOD 1000000007 - -// CODE -/*******************************************************/ -#define MX 1003 // TODO: - -ll an, bn, cn; -string a, b, c; - -ll dp[MX][MX]; - -ll recFun(ll i = 0, ll j = 0, ll k = 0) { - if (dp[i][j] != -1) return dp[i][j]; - if (i >= an && j >= bn) return 0; - ll inc1 = a[i] == c[k] ? 0 : 1; - ll inc2 = b[j] == c[k] ? 0 : 1; - ll res = MOD; - if (i < an) { - ll ans1 = recFun(i + 1, j, k + 1) + inc1; - res = min(res, ans1); - } - if (j < bn) { - ll ans2 = recFun(i, j + 1, k + 1) + inc2; - res = min(res, ans2); - } - dp[i][j] = res; - return dp[i][j]; -} - -void solve() { - cin >> a >> b >> c; - an = sz(a); - bn = sz(b); - cn = sz(c); - ll* begin = &dp[0][0]; - size_t size = sizeof(dp) / sizeof(**dp); - - fill_n(begin, size, -1); - - cout << recFun() << endl; -} - -int main() { - IO(); - int t = 1; - - cin >> t; - - while (t--) { - solve(); - } - return 0; -} - -/*******************************************************/ -",2 -JXIANG,2050E - Three Strings,c++17 ,295853889,295868474,"#include -using namespace std; - -string a, b, c; -char v[1010]; -int t, lenc, minc = 1010; -int lena, lenb; - -void dfs(int x, int i, int j) -{ - if (x > lenc - 1) - { - int cnt = 0; - for (int k = 0; k < lenc; k++) - { - if (v[k] != c[k]) - cnt++; - } - if (cnt < minc) - minc = cnt; - return; - } - if (i >lena || j > lenb) - return; - - if (i < lena) - { - v[x] = a[i]; - dfs(x + 1, i + 1, j); - } - if (j < lenb) - { - v[x] = b[j]; - dfs(x + 1, i, j + 1); - } -} - -int main() -{ - cin >> t; - while (t--) - { - cin >> a >> b >> c; - lena = a.size(); - lenb = b.size(); - lenc = c.size(); - dfs(0, 0, 0); - cout << minc << endl; - minc = 1010; - } -} -","#include -using namespace std; - -template -bool cmin(T &a, const T &b) -{ - return b < a ? a = b, 1 : 0; -} - -template -bool cmax(T &a, const T &b) -{ - return b > a ? a = b, 1 : 0; -} - -void go() -{ - string a, b, c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - vector> f(n + 1, vector(m + 1, -1)); - f[0][0] = 0; - for (int i = 0; i <= n; i++) - { - for (int j = 0; j <= m; j++) - { - if (f[i][j] == -1) - { - continue; - } - if (i + 1 <= n) - { - cmax(f[i + 1][j], f[i][j] + (a[i] == c[i + j] ? 1 : 0)); - } - if (j + 1 <= m) - { - cmax(f[i][j + 1], f[i][j] + (b[j] == c[i + j] ? 1 : 0)); - } - } - } - cout << n + m - f[n][m] << endl; -} - -int main() -{ - int caseCnt; - cin >> caseCnt; - for (int i = 1; i <= caseCnt; i++) - go(); - return 0; -}",2 -Draw_My_Solution,2050E - Three Strings,c++23 ,307332628,307344358,"#include -using namespace std; - -//#include -//mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -//indexed-set - -//#include -//using namespace __gnu_pbds; -//typedef tree,rb_tree_tag, -//tree_order_statistics_node_update> indexed_set; -//less_equal -//auto x = s.find_by_order(pos); -//int x = s.order_of_key(value) - -//gp_hash_table - -//#include -//#include -//using namespace __gnu_pbds; - -//#pragma GCC optimize(""Ofast,unroll-loops"") -//#pragma GCC target(""avx,avx2,fma"") -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -//#pragma comment(linker, ""/STACK: 2000000"") -typedef __int128 lll; - -#define ll long long -#define ld long double -#define watch(x) cout << (#x) << "" is "" << (x) << endl -#define PI 3.1415926535897932384626433832795 -#define EULER 2.7182818284590452353602874713 -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define sz(x) (int((x).size())) - -const ll mod = 1e9 + 7; -const ll INF = 1e18 ; -const ll MIN = -1e18 ; -const ll MAXII = 200005 ; - -template T gcd(T a, T b){return(b?__gcd(a,b):a);} -template T lcm(T a, T b){return(a*(b/gcd(a,b)));} -template void dbg(vector v){for (auto x : v) cout << x << "" ""; cout << endl;} -template void dbgg(pair p){cout << p.F << "" "" << p.S << endl;} - - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } -bool prime(ll a) { if (a==1) return 0; for (int i=2;i*i<=a;++i) if (a%i==0) return 0; return 1; } -ll inv(ll N) {if (N == 1) return 1; return (mod - ((mod / N) * inv(mod % N)) % mod) % mod;} -void yes() { cout<<""YES\n""; } -void no() { cout<<""NO\n""; } -//ll getRandomNumber(ll l, ll r) {return uniform_int_distribution(l, r)(rng);} -void star() { cout<<""***************************************\n""; } - - -//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); -// } -//}; -//const int mod = 1e9+7; -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; -} - -//gp_hash_table mp; - -const int N = 2e3+5; -/*vector>adj(N); -vectorvis(N); -int dfs(int i){ - vis[i]=true; - for(auto k : adj[i]){ - if(!vis[k]) dfs(k); - } -}*/ - -int n , m ; -ll dp[N][N]; -string s ; - string a , b,c; -ll ans ; -void work(int i , int j , int cost , int flag){ - int idx = i+j; - ll loc = cost; - if(flag){ - - if(s[idx]!=a[i]) loc++; - - if(dp[i][j]<=loc) return; - dp[i][j]=min(dp[i][j],loc); - - } - else { - if(s[idx]!=b[j]) loc++; - if(dp[i][j]<=loc) return; - dp[i][j]=min(dp[i][j],loc); - } - if(i>a>>b>>c; - ans = INF; - n= a.size(),m=b.size(); - a='#'+a; - b='#'+b; - c='#'+c; - s=c; - dp[0][0]=0; - for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) dp[i][j]=INF; - - work(0,0,0,1); - cout<> tc; - //memset(primes, 0, sizeof(primes)); -// sieve(); - - - while(tc--) { - solve(); - } -}","#include -using namespace std; - -//#include -//mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -//indexed-set - -//#include -//using namespace __gnu_pbds; -//typedef tree,rb_tree_tag, -//tree_order_statistics_node_update> indexed_set; -//less_equal -//auto x = s.find_by_order(pos); -//int x = s.order_of_key(value) - -//gp_hash_table - -//#include -//#include -//using namespace __gnu_pbds; - -//#pragma GCC optimize(""Ofast,unroll-loops"") -//#pragma GCC target(""avx,avx2,fma"") -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -//#pragma comment(linker, ""/STACK: 2000000"") -typedef __int128 lll; - -#define ll long long -#define ld long double -#define watch(x) cout << (#x) << "" is "" << (x) << endl -#define PI 3.1415926535897932384626433832795 -#define EULER 2.7182818284590452353602874713 -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define sz(x) (int((x).size())) - -const ll mod = 1e9 + 7; -const ll INF = 1e18 ; -const ll MIN = -1e18 ; -const ll MAXII = 200005 ; - -template T gcd(T a, T b){return(b?__gcd(a,b):a);} -template T lcm(T a, T b){return(a*(b/gcd(a,b)));} -template void dbg(vector v){for (auto x : v) cout << x << "" ""; cout << endl;} -template void dbgg(pair p){cout << p.F << "" "" << p.S << endl;} - - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } -bool prime(ll a) { if (a==1) return 0; for (int i=2;i*i<=a;++i) if (a%i==0) return 0; return 1; } -ll inv(ll N) {if (N == 1) return 1; return (mod - ((mod / N) * inv(mod % N)) % mod) % mod;} -void yes() { cout<<""YES\n""; } -void no() { cout<<""NO\n""; } -//ll getRandomNumber(ll l, ll r) {return uniform_int_distribution(l, r)(rng);} -void star() { cout<<""***************************************\n""; } - - -//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); -// } -//}; -//const int mod = 1e9+7; -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; -} - -//gp_hash_table mp; - -const int N = 2e3+5; -/*vector>adj(N); -vectorvis(N); -int dfs(int i){ - vis[i]=true; - for(auto k : adj[i]){ - if(!vis[k]) dfs(k); - } -}*/ - -int n , m ; -ll dp[N][N]; -string s ; -string a , b,c; -ll work(int i , int j ){ - int idx = i+j-1; - if(dp[i][j]!=-1) return dp[i][j]; - if(i<=n && j<=m){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =work(i+1,j)+val; - val = (b[j]!=s[idx] ? 1 :0); - ans = min(ans ,work(i,j+1)+val); - dp[i][j]=ans; - - } - else if(i<=n){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =val+work(i+1,j); - dp[i][j]=ans; - } - else if(j<=m){ - ll val = (b[j]!=s[idx] ? 1 :0); - ll ans = val+work(i,j+1); - dp[i][j]=ans; - } - else return 0; - //cout<>a>>b>>c; - n= a.size(),m=b.size(); - a='#'+a; - b='#'+b; - c='#'+c; - s=c; - for(int i=0;i<=n+2;i++) for(int j=0;j<=m+2;j++) dp[i][j]=-1; - - cout<> tc; - //memset(primes, 0, sizeof(primes)); -// sieve(); - - - while(tc--) { - solve(); - } -}4",2 -kushiluv,2050E - Three Strings,c++20 ,295380154,295380646,"#include -using namespace std; -int helper(int i , int j, string &a, string &b , string &c,vector> &dp) { - if(i + j >= c.size()){ - return dp[i][j] = 0 ; - } - int temp1 =1; - if(a[i]==c[i+j]){ - temp1--; - } - int temp2 = 1; - if(b[j] == c[i+j]){ - temp2--; - } - if(i==a.size()){ - - return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp); - } - if(j==b.size()){ - - return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp); - } - return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) ); -} -int main() -{ - - int n; - cin>>n; - - while(n--) - { - string a , b , c; - cin>>a>>b>>c; - vector> dp(a.size() + 1, vector (b.size()+1)); - cout< -using namespace std; -int helper(int i , int j, string &a, string &b , string &c,vector> &dp) { - if(dp[i][j]!=-1){ - return dp[i][j]; - } - if(i + j >= c.size()){ - return dp[i][j] = 0 ; - } - int temp1 =1; - if(a[i]==c[i+j]){ - temp1--; - } - int temp2 = 1; - if(b[j] == c[i+j]){ - temp2--; - } - if(i==a.size()){ - - return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp); - } - if(j==b.size()){ - - return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp); - } - return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) ); -} -int main() -{ - - int n; - cin>>n; - - while(n--) - { - string a , b , c; - cin>>a>>b>>c; - vector> dp(a.size() + 1, vector (b.size()+1 , -1)); - cout<0){ - String a=sc.next(); - String b=sc.next(); - String c=sc.next(); - dp=new int[a.length()+1][b.length()+1]; - - for(int i=0;i0){ - String a=sc.next(); - String b=sc.next(); - String c=sc.next(); - dp1=new int[a.length()+1][c.length()+1]; - dp2=new int[b.length()+1][c.length()+1]; - - for(int i=0;i<=a.length();i++){ - Arrays.fill(dp1[i],Integer.MAX_VALUE); - } - for(int i=0;i<=b.length();i++){ - Arrays.fill(dp2[i],Integer.MAX_VALUE); - } - System.out.println(solve(a,b,c,0,0,0)); - - } - } - public static int solve(String a,String b,String c,int i,int j,int k){ - if(i==a.length() || j==b.length()){ - return calc(a,b,c,i,j,k); - } - if(dp1[i][k]!=Integer.MAX_VALUE && dp2[j][k]!=Integer.MAX_VALUE){ - return Math.min(dp1[i][k],dp2[j][k]); - } - if(c.charAt(k)==a.charAt(i) && c.charAt(k)==b.charAt(j)){ - return Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=solve(a,b,c,i,j+1,k+1)); - - } - else if(c.charAt(k)==a.charAt(i) ){ - return Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=1+solve(a,b,c,i,j+1,k+1)); - } - else if(c.charAt(k)==b.charAt(j)){ - return Math.min(dp2[j][k]=solve(a,b,c,i,j+1,k+1),dp1[i][k]=1+solve(a,b,c,i+1,j,k+1)); - } - else return 1+Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=solve(a,b,c,i,j+1,k+1)); - } - - public static int calc(String a,String b,String c,int i,int j,int k){ - int count=0; - if(i==a.length()){ - while(j -#include -#include -char buf[2000 + 3], buf1[1000 + 3], buf2[1000 + 3]; -struct triple { - int ind1; - int ind2; - int count; -}; -int main() { - int t; - scanf(""%d"", &t); - while (t--) { - scanf("" %s %s %s"", buf1, buf2, buf); - std::string str1(buf1), str2(buf2), str(buf); - int n = str1.size(), m = str2.size(); - std::vector> dp(n + 5, std::vector (m + 5)); - dp[0][0] = 0; - for (int i = 0; i < n; i++) { - dp[i + 1][0] = dp[i][0] + (str1[i] != str[i]); - } - for (int i = 0; i < m; i++) { - dp[0][i + 1] = dp[0][i] + (str2[i] != str[i]); - } - for (int i = 1; i <= n; i++) { - for (int j = 1; j <= m; j++) { - dp[i][j] = std::min(dp[i - 1][j] + (str1[i - 1] != str[i + j - 1]), - dp[i][j - 1] + (str2[j - 1] != str[i + j - 1])); - } - } - printf(""%d\n"", dp[n][m]); - } -} -","#include -#include -#include -char buf[2000 + 3], buf1[1000 + 3], buf2[1000 + 3]; -struct triple { - int ind1; - int ind2; - int count; -}; -int main() { - int t = 1; - scanf(""%d"", &t); - while (t--) { - scanf("" %s %s %s"", buf1, buf2, buf); - std::string str1(buf1), str2(buf2), str(buf); - std::queue q; -// printf(""\n\n%s %s %s\n\n"", str1.c_str(), str2.c_str(), str.c_str()); -// if (str1.size() < str2.size()) std::swap(str1, str2); - q.push({1, 0, int(str1[0] != str[0])}); - q.push({0, 1, int(str2[0] != str[0])}); - int index = 1; - int ans = 1000'000'000; - int counter = 1; - while (!q.empty()) { - triple &cur = q.front(); bool bl1 = 1, bl2 = 1; - q.pop(); -// printf(""%d.%d %d %d -> \n"", counter++, cur.ind1, cur.ind2, cur.count); - if (cur.ind1 < str1.size()) { - q.push({cur.ind1 + 1, cur.ind2, cur.count + int(str1[cur.ind1] != str[cur.ind1 + cur.ind2])}); - bl1 = 0; - } - if (cur.ind2 < str2.size()) { - q.push({cur.ind1, cur.ind2 + 1, cur.count + int(str2[cur.ind2] != str[cur.ind1 + cur.ind2])}); - bl2 = 0; - } - if (bl1 & bl2) { - ans = std::min(ans, cur.count); -// printf(""END!!!""); - } -// printf(""\n""); - } - printf(""%d\n"", ans); - } -} -",1 -ddi4z,2050E - Three Strings,c++23 ,297647815,297648169,"/** - @author: ddi4z -*/ -#include -using namespace std; -typedef long long ll; -typedef long double ld; - -// integer vectors -typedef vector vi; -typedef vector vll; - -// vectors of vectors of integers -typedef vector vvi; -typedef vector vvll; - -// pairs of integers -typedef pair pii; -typedef pair pll; - -// vector of pairs of integers -typedef vector vpii; -typedef vector vpll; - -// stack of integers -typedef stack si; - -// stack of pairs of integers -typedef stack spii; - -#define pb push_back -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define fori(i, s, n) for(int i = s; i < n; ++i) -#define forll(i, s, n) for(ll i = s; i < n; ++i) -#define rfori(i, s, n) for(int i = s; i >= n; --i) -#define rforll(i, s, n) for(ll i = s; i >= n; --i) - -const ll MOD = 1e9 + 7; -const ll INF = 1e9; -const ld EPS = 1e-9; - -#define DBG(X) cerr << #X << "" = "" << X << endl; -#define RAYA cerr << "" ========================= "" << endl; - -// order statistics - -//#include -//#include -//typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -//ordered_set order; - - -int mod(int a, int m) {return ((a%m) + m) % m;} - -string a, b, c; - -map memo; - -ll dp(ll i,ll j){ - string s = to_string(i) + "","" + to_string(j); - if (memo.count(s)) return memo[s]; - if (i < a.size() && j == b.size()) return memo[s] = (a[i] != c[i + j]) + dp(i + 1, j); - if (i == a.size() && j < b.size()) return memo[s] = (b[j] != c[i + j]) + dp(i, j + 1); - if (i == a.size() && j == b.size()) return 0; - ll res = min((a[i] != c[i + j]) + dp(i + 1, j), - (b[j] != c[i + j]) + dp(i, j + 1)); - return memo[s] = res; -} - - -int main() { - ll TT; - scanf(""%lld"", &TT); - while(TT--) { - cin >> a >> b >> c; - memo.clear(); - printf(""%lld\n"", dp(0,0)); - } - return 0; -}","/** - @author: ddi4z -*/ -#include -using namespace std; -typedef long long ll; -typedef long double ld; - -// integer vectors -typedef vector vi; -typedef vector vll; - -// vectors of vectors of integers -typedef vector vvi; -typedef vector vvll; - -// pairs of integers -typedef pair pii; -typedef pair pll; - -// vector of pairs of integers -typedef vector vpii; -typedef vector vpll; - -// stack of integers -typedef stack si; - -// stack of pairs of integers -typedef stack spii; - -#define pb push_back -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define fori(i, s, n) for(int i = s; i < n; ++i) -#define forll(i, s, n) for(ll i = s; i < n; ++i) -#define rfori(i, s, n) for(int i = s; i >= n; --i) -#define rforll(i, s, n) for(ll i = s; i >= n; --i) - -const ll MOD = 1e9 + 7; -const ll INF = 1e9; -const ld EPS = 1e-9; - -#define DBG(X) cerr << #X << "" = "" << X << endl; -#define RAYA cerr << "" ========================= "" << endl; - -// order statistics - -//#include -//#include -//typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -//ordered_set order; - - -int mod(int a, int m) {return ((a%m) + m) % m;} - -string a, b, c; -vvll memo; - -ll dp(ll i,ll j){ - - if (memo[i][j]!=INF) return memo[i][j]; - if (i < a.size() && j == b.size()) return memo[i][j] = (a[i] != c[i + j]) + dp(i + 1, j); - if (i == a.size() && j < b.size()) return memo[i][j] = (b[j] != c[i + j]) + dp(i, j + 1); - if (i == a.size() && j == b.size()) return 0; - ll res = min((a[i] != c[i + j]) + dp(i + 1, j), - (b[j] != c[i + j]) + dp(i, j + 1)); - return memo[i][j] = res; -} - - -int main() { - ll TT; - scanf(""%lld"", &TT); - while(TT--) { - cin >> a >> b >> c; - memo.assign(a.size() + 1, vll(b.size() + 1, INF)); - - printf(""%lld\n"", dp(0,0)); - } - return 0; -}",2 -Laure-Haddad,2050E - Three Strings,c++17 ,295758255,295757916,"#include -#define int long long -using namespace std; -int dp[1005][1005]; -string a,b,c; -int solve(int i,int j) -{ - int k=i+j; - if(dp[i][j]==-1) - { - dp[i][j]=1e18; - if(i>t; - while(t--) - { - memset(dp,-1,sizeof(dp)); - cin>>a>>b>>c; - cout< -#define int long long -using namespace std; -int dp[1000][1000]; -string a,b,c; -int solve(int i,int j) -{ - int k=i+j; - if(dp[i][j]==-1) - { - dp[i][j]=1e18; - if(i>t; - while(t--) - { - memset(dp,-1,sizeof(dp)); - cin>>a>>b>>c; - cout< -#include -using namespace std; -using namespace __gnu_pbds; - -#define int long long -#define double long double -#define pii pair -#define endl '\n' -typedef tree , rb_tree_tag , tree_order_statistics_node_update> indexed_set; -typedef tree , rb_tree_tag , tree_order_statistics_node_update> indexed_multiset; -#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0) -#define vi vector -#define vpii vector -#define pb push_back -#define lb lower_bound -#define ub upper_bound -#define sz(x) (int)((x).size()) -#define all(x) (x).begin() , (x).end() -#define rall(x) (x).rbegin() , (x).rend() -#define F first -#define S second -const int mod = 1e9 + 7; -const int N = 3e3 + 5; -const int INF = (int)2e18 + 123; - -int dp[N][N]; - -void solve() -{ - string a , b , c; - cin >> a >> b >> c; - int n = sz(a) , m = sz(b); - - for(int i = 0; i < n + m; i++){ - for(int j = 0; j <= min(i + 1 , n); j++){ /// j chars of a - dp[i + 1][j] = INT_MAX; - if(i - j < m) - dp[i + 1][j] = dp[i][j] + (b[i - j] != c[i]); - if(j) - dp[i + 1][j] = min(dp[i + 1][j] , dp[i][j - 1] + (a[j - 1] != c[i])); - //cout << dp[i + 1][j] << "" ""; - } - //cout << '\n'; - } - cout << dp[n + m][n] << '\n'; -} - - -signed main(){ - _FastIO; - int T = 1; - cin >> T; - while(T--){ - solve(); - } - //system(""pause""); -} - - - - - - - - - - - - - - - - - - - - - -","/// Bismillah -#pragma GCC optimize(""O3"") -#include -#include -using namespace std; -using namespace __gnu_pbds; - -#define int long long -#define double long double -#define pii pair -#define endl '\n' -typedef tree , rb_tree_tag , tree_order_statistics_node_update> indexed_set; -typedef tree , rb_tree_tag , tree_order_statistics_node_update> indexed_multiset; -#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0) -#define vi vector -#define vpii vector -#define pb push_back -#define lb lower_bound -#define ub upper_bound -#define sz(x) (int)((x).size()) -#define all(x) (x).begin() , (x).end() -#define rall(x) (x).rbegin() , (x).rend() -#define F first -#define S second -const int mod = 1e9 + 7; -const int N = 3e3 + 5; -const int INF = (int)2e18 + 123; - -int dp[N][N]; - -void solve() -{ - string a , b , c; - cin >> a >> b >> c; - int n = sz(a) , m = sz(b); - for(int i = 0; i <= n + m + 2; i++){ - for(int j = 0; j <= n + 2; j++){ - dp[i][j] = INT_MAX; - } - } - dp[0][0] = 0; - for(int i = 0; i < n + m; i++){ - for(int j = 0; j <= min(i + 1 , n); j++){ /// j chars of a - if(i - j < m && j <= i) - dp[i + 1][j] = min(dp[i + 1][j] , dp[i][j] + (b[i - j] != c[i])); - if(j) - dp[i + 1][j] = min(dp[i + 1][j] , dp[i][j - 1] + (a[j - 1] != c[i])); - //cout << dp[i + 1][j] << "" ""; - } - //cout << '\n'; - } - cout << dp[n + m][n] << '\n'; -} - - -signed main(){ - _FastIO; - int T = 1; - cin >> T; - while(T--){ - solve(); - } - //system(""pause""); -} - - - - - - - - - - - - - - - - - - - - - -",2 -maximka111,2050E - Three Strings,c++20 ,308638344,308640436,"#include - -#include - -#include - - - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - for (; t > 0; --t) - - { - - string a, b, c; - - cin >> a >> b >> c; - - vector> ans(a.size() + 1, vector(b.size() + 1, 0)); - - for (int i = 1; i <= a.size(); ++i) - - { - - if (c[i - 1] != a[i - 1]) - - ans[i][0] = ans[i - 1][0] + 1; - - } - - for (int i = 1; i <= b.size(); ++i) - - { - - if (c[i - 1] != b[i - 1]) - - ans[0][i] = ans[0][i - 1] + 1; - - } - - for (int i = 1; i <= a.size(); ++i) - - { - - for (int j = 1; j <= b.size(); ++j) - - { - - if (a[i - 1] == c[i + j - 1]) - - ans[i][j] = ans[i - 1][j]; - - else - - ans[i][j] = ans[i - 1][j] + 1; - - if (b[j - 1] == c[i + j - 1]) - - ans[i][j] = min(ans[i][j], ans[i][j - 1]); - - else - - ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1); - - } - - } - - cout << ans[a.size()][b.size()]; - - } - -} - - - - - - - - - - - -","#include - -#include - -#include - - - -using namespace std; - - - -int main() - -{ - - int t; - - cin >> t; - - for (; t > 0; --t) - - { - - string a, b, c; - - cin >> a >> b >> c; - - vector> ans(a.size() + 1, vector(b.size() + 1, 0)); - - for (int i = 1; i <= a.size(); ++i) - - { - - if (c[i - 1] != a[i - 1]) - - ans[i][0] = ans[i - 1][0] + 1; - - else - - ans[i][0] = ans[i - 1][0]; - - } - - for (int i = 1; i <= b.size(); ++i) - - { - - if (c[i - 1] != b[i - 1]) - - ans[0][i] = ans[0][i - 1] + 1; - - else - - ans[0][i] = ans[0][i - 1]; - - } - - for (int i = 1; i <= a.size(); ++i) - - { - - for (int j = 1; j <= b.size(); ++j) - - { - - if (a[i - 1] == c[i + j - 1]) - - ans[i][j] = ans[i - 1][j]; - - else - - ans[i][j] = ans[i - 1][j] + 1; - - if (b[j - 1] == c[i + j - 1]) - - ans[i][j] = min(ans[i][j], ans[i][j - 1]); - - else - - ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1); - - } - - } - - cout << ans[a.size()][b.size()] << endl; - - } - -} - - - - - - - - - - - -",2 -viktor3,2050E - Three Strings,c++17 ,298896398,298896318,"#include -#include - -#define ll long long -#define ld long double -#define INF 1000000000 - -using namespace std; - -int main() -{ - cin.tie(nullptr); - ios_base::sync_with_stdio(false); - int t; - cin >> t; - for (int q = 0; q < t; q++) { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - a = ""`"" + a; - b = ""`"" + b; - vector> dp(n + 2, vector(m + 2, INF)); - // for (int i = 0; i < n + 2; i++) { - // dp[i][0] = 0; - // } - // for (int i = 0; i < m + 2; i++) { - // dp[0][i] = 0; - // } - dp[1][1] = 0; - int k = 0; - while (k < n + m) { - k++; - for (int i = 0; i < min(n, k) + 1; i++) { - int j = k - i; - if (j < 0 || j > m) continue; - dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j])); - } - } - // for (int i = 0; i < n + 2; i++) { - // for (int j = 0; j < m + 2; j++) { - // cout << dp[i][j] << "" ""; - // } - // cout << ""\n""; - // } - // cout << ""\n""; - cout << dp[n + 1][m + 1] << ""\n""; - } - return 0; -}","#include -#include - -#define ll long long -#define ld long double -#define INF 1000000000 - -using namespace std; - -int main() -{ - cin.tie(nullptr); - ios_base::sync_with_stdio(false); - int t; - cin >> t; - for (int q = 0; q < t; q++) { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - a = ""`"" + a; - b = ""`"" + b; - vector> dp(n + 2, vector(m + 2, INF)); - // for (int i = 0; i < n + 2; i++) { - // dp[i][0] = 0; - // } - // for (int i = 0; i < m + 2; i++) { - // dp[0][i] = 0; - // } - dp[1][1] = 0; - int k = 0; - while (k < n + m) { - k++; - for (int i = 0; i < min(n, k) + 1; i++) { - int j = k - i; - if (j < 0 || j > m) continue; - dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j])); - } - } - for (int i = 0; i < n + 2; i++) { - for (int j = 0; j < m + 2; j++) { - cout << dp[i][j] << "" ""; - } - cout << ""\n""; - } - cout << ""\n""; - cout << dp[n + 1][m + 1] << ""\n""; - } - return 0; -}",1 -minhnguyen2010,2050E - Three Strings,c++23 ,307017996,307016778,"#include - -using namespace std; - -long long t,dp[1005][1005]; - -string a,b,c; - -void solve(){ - - cin>>a>>b>>c; - - vector> v; - - int n=a.size(),m=b.size(),k=c.size(); - - a=' '+a; b=' '+b; c=' '+c; - - for(int i=1; i<=n; i++){ - - dp[i][0]=dp[i-1][0]+(a[i]!=c[i]); - - v.push_back({i,0}); - - } - - for(int i=1; i<=m; i++){ - - dp[0][i]=dp[0][i-1]+(b[i]!=c[i]); - - v.push_back({0,i}); - - } - - for(int i=1; i<=n; i++){ - - for(int j=1; j<=m; j++){ - - dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]), dp[i][j-1]+(b[j]!=c[i+j])); - - v.push_back({i,j}); v.push_back({j,i}); - - } - - } - - cout<>t; - - while(t--){ - - solve(); - - } - -}","#include - -using namespace std; - -long long t,dp[1005][1005]; - -string a,b,c; - -void solve(){ - - cin>>a>>b>>c; - - for(int i=1; i<=1003; i++){ - - for(int j=1; j<=1003; j++){ - - dp[i][j]=0; - - } - - } - - int n=a.size(),m=b.size(),k=c.size(); - - a=' '+a; b=' '+b; c=' '+c; - - for(int i=1; i<=n; i++){ - - dp[i][0]=dp[i-1][0]+(a[i]!=c[i]); - - dp[0][i]=dp[0][i-1]+(b[i]!=c[i]); - - } - - for(int i=1; i<=n; i++){ - - for(int j=1; j<=m; j++){ - - dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]), dp[i][j-1]+(b[j]!=c[i+j])); - - } - - } - - cout<>t; - - while(t--){ - - solve(); - - } - -}",1 -ksandr1v,2050E - Three Strings,c++20 ,297652707,297650763,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -long TEST = 0; -long TEST_TOTAL = 0; -namespace _IOBase { - int hook_test = 0; - int min_tot = 0; - std::stringstream hook_str; - template T read() { - T val; - std::cin >> val; - if (hook_test) { - if (TEST == hook_test&&TEST_TOTAL >= std::max(min_tot, hook_test)) { - hook_str << val; - hook_str << "" ""; - } - } - return val; - } - template void put(const T& v) { - if (hook_test) { - if (TEST_TOTAL >= std::max(min_tot, hook_test)) { - if (TEST == hook_test) { - std::cout << hook_str.str(); - hook_str = std::stringstream(); - } - return; - } - } - std::cout << v; - } - bool AutoFlash = false; -} -void Solve(); -struct ProblemData { - bool HasTestcase = true; - bool AutoFlash = false; -}; -class Timer { - using sc = std::chrono::steady_clock; - sc::time_point start; -public: - Timer() :start(sc::now()) {} - long long elapsedMs() { - return std::chrono::duration_cast(sc::now() - start).count(); - } -}; -class Starter { - void Solve2() { - TEST++; - try { Solve(); } - catch (int) {} - } - void _Start(const ProblemData& pd) { - TEST_TOTAL = pd.HasTestcase ? _IOBase::read() : 1; - for (int t = 0; t < TEST_TOTAL; t++) { - Solve2(); - } - } -public: - Starter(const ProblemData& pd) { - std::cout.precision(17); - std::cin.tie(nullptr); - std::cout.tie(nullptr); - std::ios_base::sync_with_stdio(false); - _Start(pd); - } -}; -void initialize(ProblemData& pd); -int main(int argc, char** argv) { - ProblemData pd; - initialize(pd); - _IOBase::AutoFlash = pd.AutoFlash; - Starter starter(pd); - return 0; -} -#define TT template -#define TTs template -#define TC template -static const bool _IS_VSCPP= -#ifdef _MSC_VER -true -#else -false -#endif -; -using Long = int64_t; -#ifdef __SIZEOF_INT128__ -using longw = __int128; -#else -using longw = std::ranges::range_difference_t>; -#endif -using ld = long double; -using ulong = uint64_t; -using uint = uint32_t; -constexpr Long operator""""v(unsigned long long a) { return (Long)a; } -constexpr ld operator""""v(long double a) { return a; } -#define long Long -TT concept Invoke0 = true; -TT concept Invoke1 = true; -TT concept Invoke2 = true; -TT concept TEnumerable = requires(T a) { a.begin(); a.end(); }; -TT concept TEnumerableSized = requires(T a) { a.size(); } && TEnumerable; -#define FORWARD_BY(item, item_by) std::is_rvalue_reference_v ? std::move(item) : item -#define FORWARD(x) std::forward(x) -#define DECLTYPE(x) std::decay_t -TT using TElemFromType = DECLTYPE(*std::declval().begin()); -#define TElemFromInst(v) DECLTYPE(*v.begin()) -#define _DEDUCT(t_name) \ -template t_name(T) -> t_name>; \ -template t_name(T) -> t_name>; \ -template t_name(T...) -> t_name; -#define ALL_TH this->begin(),this->end() -#define ALL(x) x.begin(),x.end() -#define _OPER_FROM(op) TThis operator op(const TThis& b) const { TThis a(*this); a op ## = b; return a; } -struct Empty {}; -#define var auto&& -constexpr Long inf = std::numeric_limits::max() / 4; -constexpr int inf_int = std::numeric_limits::max() - 10; -auto geti() { return _IOBase::read(); } -auto getc() { return _IOBase::read(); } -auto get_c() { return getc(); } -auto getd() { return _IOBase::read(); } -TT void put_raw(const T& v) { _IOBase::put(v); } -void _print_endl() { _IOBase::put('\n'); if (_IOBase::AutoFlash) std::cout.flush(); } -void put_raw(const std::string& v) { _IOBase::put(v); } -void put_raw(const TEnumerable auto& v) { - bool init = false; - for (const auto& e : v) { - if (!init) init = true; else put_raw(' '); - put_raw(e); - } -} -void put_raw_nosp(const auto& v) { put_raw(v); } -void put_raw_nosp(const TEnumerable auto& v) { for (const auto& e : v) { put_raw(e); } } -TTs void put_nosp(const T&...v) { (put_raw_nosp(v), ...); } -TTs void put(const T&...v) { - int cnt = 0; - ((put_raw(v), (++cnt != (sizeof...(v)) ? _IOBase::put(' ') : ([]() {})())), ...); -} -TTs void print(const T&...v) { put(v...); _print_endl(); } -TTs void print_nosp(const T&...v) { put_nosp(v...); _print_endl(); } -void done() { throw 1; } -TTs void done(const T&...v) { print(v...); done(); } -TTs void print_sp(const T&...v) { put(v...); put_raw(' '); } -void print_yes(bool cond) { print(cond ? ""Yes"" : ""No""); } -void done_yes(bool cond) { print(cond ? ""Yes"" : ""No""); done(); } -TTs void __READ(T&... v) { ((v = _IOBase::read()), ...); } -#define __read_cmn(x, ...) x __VA_ARGS__ ; __READ(__VA_ARGS__); -#define readi(...) __read_cmn(Long, __VA_ARGS__) -Long Sum1n(Long n) { if (n <= 0) return 0; return (n * n + n) / 2; } -Long Sumkn(Long k, Long n) { if (k > n) return 0; return Sum1n(n) - Sum1n(k - 1); } -auto Iota(Long l, Long r) { return std::ranges::iota_view(l, r + 1); } -auto Iota0(Long r) { return Iota(0, r); } -auto Iota1(Long r) { return Iota(1, r); } -auto Abs(const auto& a) { return std::abs(a); } -auto Min(const auto& a, const auto& b) { return a < b ? a : b; } -auto Max(const auto& a, const auto& b) { return a > b ? a : b; } -bool Max2(var a, const auto& b) { if (b > a) { a = b; return true; } return false; } -bool Min2(var a, const auto& b) { if (b < a) { a = b; return true; } return false; } -auto Max(var a, var b, var c, var... v) { auto res = Max(a, b); Max2(res, c); (Max2(res, v), ...); return res; } -auto Min(var a, var b, var c, var... v) { auto res = Min(a, b); Min2(res, c); (Min2(res, v), ...); return res; } -TT2 auto Swap(T& a, T2& b) { return std::swap(a, b); } -TT2 auto Sort(T& a, T2& b) { if (b < a) Swap(a, b); } -auto GCD(long a, long b) { return std::gcd(a, b); } -auto LCM(long a, long b) { return std::lcm(a, b); } -auto Log(var val, long k) { - if (k <= 1) return DECLTYPE(val) {}; - DECLTYPE(val) test = 1; - DECLTYPE(val) cnt = 0; - while (test < val) { test *= k; ++cnt; } - if (test != val) { cnt--; } - return cnt; -} -auto Log_up(var val, long k) { - if (k <= 1) return DECLTYPE(val) {}; - DECLTYPE(val) test = 1; - DECLTYPE(val) cnt = 0; - while (test < val) { test *= k; ++cnt; } - return cnt; -} -auto Pow(auto base, long exp) { - assert(exp >= 0); - decltype(base) result = 1; - for (; exp > 0; exp >>= 1) { - if (exp & 1) - result *= base; - base *= base; - } - return result; -} -auto Max(TEnumerable var v) { return *std::max_element(ALL(v)); } -auto Min(TEnumerable var t) { return *std::min_element(ALL(t)); } -auto Max(TEnumerable auto&& v, Invoke1 var f) { - auto it = v.begin(); - auto res = f(*it); - it++; - for (; it != v.end(); it++) { Max2(res, f(*it)); } - return res; -} -auto Min(TEnumerable var v, Invoke1 var f) { - auto it = v.begin(); - auto res = f(*it); - it++; - for (; it != v.end(); it++) { Min2(res, f(*it)); } - return res; -} -TC T = long > T Fact(long n) { - static std::vector stor = { 1,1 }; - if (n < stor.size()) return stor[n]; - T res = stor.back(); - long from = stor.size(); - if (n >= 400000) { - for (; from <= n; from++) { res *= from; } - } else { - for (; from <= n; from++) { - res *= from; - stor.push_back(res); - } - } - return res; -} -TC T = long> T Acomb(long k, long n) { - assert(k <= n); - return Fact(n) / Fact(n - k); -} -TC T = long > T Ccomb(long k, long n) { - assert(k <= n); - return Acomb(k, n) / Fact(k); -} -TT class _BaseCont : public T { - using TBase = T; -public: - using value_type = TBase::value_type; - using reference = TBase::reference; - using TBase::TBase; - _BaseCont(TBase&& s)noexcept : TBase(s) {} - Long size() const { return TBase::size(); } - value_type min() const { return *std::min_element(ALL_TH); } - value_type max() const { return *std::max_element(ALL_TH); } - value_type sum() const { return std::accumulate(ALL_TH, value_type{}); } -}; -TT class _BaseContList : public _BaseCont { - using TBase = _BaseCont; -public: - using value_type = TBase::value_type; - using reference = TBase::reference; - using TBase::TBase; - _BaseContList(TEnumerableSized var v) { - TBase::resize(v.size()); - int i = 0; - for (auto&& item : v) { - (*this)[i++] = FORWARD_BY(item, v); - } - } - _BaseContList(TEnumerable var v) { - for (auto&& item : v) { this->push_back(FORWARD_BY(item, v)); } - } - void reversy() { std::reverse(ALL_TH); } - bool contains(const value_type& v) { return std::find(ALL_TH, v) != this->end(); } - void replace(value_type a, value_type b) { std::replace(ALL_TH, a, b); } - void insert_at(Long i, const value_type& v) { TBase::insert(this->begin() + i, v); } - void fill(const value_type& v) { std::fill(ALL_TH, v); } - void remove_at(Long i) { if(i < this->size()) this->erase(this->begin() + i); } - bool remove_first(const value_type& val) { auto itr = std::find(ALL_TH, val); if (itr != this->end()) { this->erase(itr); return true; } return false; } - Long remove_all(const value_type& val) { - auto newEnd = std::remove(ALL_TH, val); - auto cnt = this->end() - newEnd; - this->erase(newEnd, this->end()); - return cnt; - } - value_type pop_back() { - auto res = std::move(TBase::back()); - TBase::pop_back(); - return res; - } - value_type pop_front() { - auto res = std::move(TBase::front()); - remove_at(0); - return res; - } - void push_front(const value_type& v) { - this->insert_at(0, v); - } - bool is_sorted() { return std::is_sorted(ALL_TH); } - void sort() { std::stable_sort(ALL_TH); } - void sort(Invoke2 var f) { std::stable_sort(ALL_TH, f); } - void sort_rev() { - std::stable_sort(ALL_TH, std::greater{}); - } - void set(int l, int r, const value_type& v) { - for (int i = l; i <= r; i++) { get(i) = v; } - } - reference operator[](int i) { return TBase::operator[](i); } - auto& operator[](int i) const { return TBase::operator[](i); } - value_type& get_rev(int i) { return get(this->size()-1-i); } - value_type& get(int i) { return (*this)[i]; } - value_type get_def(int i, value_type def = {}) { return i < this->size() && i >= 0 ? get(i) : def; } - void swap(int i, int j) { std::swap(get(i), get(j)); } -private: -}; -TCT = Long > class Vec : public _BaseContList> { - using TBase = _BaseContList>; -public: - using reference = TBase::reference; - using TBase::TBase; - using value_type = TBase::value_type; -}; -_DEDUCT(Vec); -TCT = Long > class Deque : public _BaseContList < std::deque> { - using TBase = _BaseContList < std::deque>; -public: - using TBase::TBase; - T pop_front() { - auto res = std::move(TBase::front()); - TBase::pop_front(); - return res; - } -}; -_DEDUCT(Deque); -TCT = long > class Cont : public Vec { - using TBase = Vec; -public: - using reference = TBase::reference; - using TBase::TBase; -public: - reference operator[](int i) { - if (i >= this->size()) { this->resize(i + 1); } - return TBase::operator[](i); - } -}; -_DEDUCT(Cont); -TCT = long > class Cont2 : public Cont { - using TBase = Cont; -public: - using TBase::TBase; - using reference = TBase::reference; -public: - reference operator[](int i) { - if (i < 0) { - return minus[-i]; - } - return TBase::operator[](i); - } -private: - Cont minus; -}; -_DEDUCT(Cont2); -auto getv(int n, Invoke0 var getter) { - Vec res(n); - for (auto i = 0; i < n; i++) { - res[i] = getter(); - } - return res; -} -auto getv(int n) { return getv(n, geti); } -auto gets_digit(int n = -1) { - if (n != -1) { - Vec res(n); - for(int i = 0; i < n; i++) { - res[i] = get_c() - '0'; - } - return res; - } - auto s = _IOBase::read(); - Vec res(s.size()); - for(int i = 0; i < s.size(); i++) { - res[i] = s[i] - '0'; - } - return res; -} -class Str : public _BaseContList { - using TBaseStr = std::string; - using TBase = _BaseContList; - using reference = TBase::reference; -public: - using TBase::TBase; - using value_type = TBase::value_type; - Str get(int l, int r) const { - if (l > r) return """"; - if (r >= size()) r = size() - 1; - return substr(l, r - l + 1); - } - void tolower() { - std::transform(begin(), end(), begin(), [](unsigned char c) { return std::tolower(c); } - ); - } -}; -Str operator"""" s(const char* _Str, size_t _Len) { - return Str{ _Str, _Len }; -} -Str gets(int n = -1) { - if (n != -1) { - Str res; - res.resize(n); - for (int i = 0; i < n; i++) { - res[i] = get_c(); - } - return res; - } - return _IOBase::read(); -} -void put_raw(const Str& v) { for (char c : v) put_raw(c); } -namespace _For_impl { - template struct ForIter { - using Iter = decltype(std::begin(std::declval())); - using Iter_end = decltype(std::end(std::declval())); - using IterRef = decltype(*std::declval()); - Long i = 0; Iter iter; Iter_end iter_end; - ForIter(T& cont) :iter(std::begin(cont)), iter_end(std::end(cont)) { } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++iter; ++i; } - bool operator!=(int) { return iter != iter_end; } - std::tuple operator*() { return { *iter, i }; } - }; - template struct ForIterRev { - using Iter = decltype(std::rbegin(std::declval())); - using Iter_end = decltype(std::rend(std::declval())); - using IterRef = decltype(*std::declval()); - Long i; Iter iter; Iter_end iter_end; - ForIterRev(T& cont) :i(cont.size()-1), iter(cont.rbegin()), iter_end(cont.rend()) { } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++iter; --i; } - bool operator!=(int) { return iter != iter_end; } - std::tuple operator*() { return { *iter, i }; } - }; - template<> struct ForIter { - Long i; Long n; - ForIter(Long c) :n(c) { i = 0; } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++i; } - bool operator!=(int) { return i != n; } - std::tuple operator*() { return { i, i }; } - }; - template auto Get_For_Handler_rev(T& v) { - return ForIterRev(v); - } - auto Get_For_Handler(Long v) { - return ForIter(v); - } - template auto Get_For_Handler(T& v) { - return ForIter(v); - } -} -#define __GET_MACRO(_0,_1,_2,_3,_4,_5,X,...) X -#define __EXPAND( x ) x -#define _fe2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler (__cont)) -#define _fer2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler_rev (__cont)) -#define _fe1(cont) _fe2(_, cont) -#define _fer1(cont) _fer2(_, cont) -#define fe(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fe2, _fe1, _0)(__VA_ARGS__)) -#define re(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fer2, _fer1, _0)(__VA_ARGS__)) -void Solve() { - auto aa = gets(); - auto bb = gets(); - auto cc = gets(); - Vec dp(2010); - fe(e, cc) { - auto dp2 = dp; - for (long cnt_a = 0; cnt_a <= 2005; cnt_a++) { - auto cnt_b = ei - cnt_a; - if (cnt_b < 0) break; - if (cnt_b < bb.size()) { - auto cur = bb[cnt_b]; - long res = cur == e ? 1 : 0; - Max2(dp2[cnt_a], dp[cnt_a] + res); - } - if (cnt_a < aa.size()) { - auto cur = aa[cnt_a]; - long res = cur == e ? 1 : 0; - Max2(dp2[cnt_a + 1], dp[cnt_a] + res); - } - } - dp = dp2; - } - print(cc.size() - dp[aa.size()]); -} -void initialize(ProblemData& pd){ - pd.HasTestcase = true; - pd.AutoFlash = false; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -long TEST = 0; -long TEST_TOTAL = 0; -namespace _IOBase { - int hook_test = 0; - int min_tot = 0; - std::stringstream hook_str; - template T read() { - T val; - std::cin >> val; - if (hook_test) { - if (TEST == hook_test&&TEST_TOTAL >= std::max(min_tot, hook_test)) { - hook_str << val; - hook_str << "" ""; - } - } - return val; - } - template void put(const T& v) { - if (hook_test) { - if (TEST_TOTAL >= std::max(min_tot, hook_test)) { - if (TEST == hook_test) { - std::cout << hook_str.str(); - hook_str = std::stringstream(); - } - return; - } - } - std::cout << v; - } - bool AutoFlash = false; -} -void Solve(); -struct ProblemData { - bool HasTestcase = true; - bool AutoFlash = false; -}; -class Timer { - using sc = std::chrono::steady_clock; - sc::time_point start; -public: - Timer() :start(sc::now()) {} - long long elapsedMs() { - return std::chrono::duration_cast(sc::now() - start).count(); - } -}; -class Starter { - void Solve2() { - TEST++; - try { Solve(); } - catch (int) {} - } - void _Start(const ProblemData& pd) { - TEST_TOTAL = pd.HasTestcase ? _IOBase::read() : 1; - for (int t = 0; t < TEST_TOTAL; t++) { - Solve2(); - } - } -public: - Starter(const ProblemData& pd) { - std::cout.precision(17); - std::cin.tie(nullptr); - std::cout.tie(nullptr); - std::ios_base::sync_with_stdio(false); - _Start(pd); - } -}; -void initialize(ProblemData& pd); -int main(int argc, char** argv) { - ProblemData pd; - initialize(pd); - _IOBase::AutoFlash = pd.AutoFlash; - Starter starter(pd); - return 0; -} -#define TT template -#define TTs template -#define TC template -static const bool _IS_VSCPP= -#ifdef _MSC_VER -true -#else -false -#endif -; -using Long = int64_t; -#ifdef __SIZEOF_INT128__ -using longw = __int128; -#else -using longw = std::ranges::range_difference_t>; -#endif -using ld = long double; -using ulong = uint64_t; -using uint = uint32_t; -constexpr Long operator""""v(unsigned long long a) { return (Long)a; } -constexpr ld operator""""v(long double a) { return a; } -#define long Long -TT concept Invoke0 = true; -TT concept Invoke1 = true; -TT concept Invoke2 = true; -TT concept TEnumerable = requires(T a) { a.begin(); a.end(); }; -TT concept TEnumerableSized = requires(T a) { a.size(); } && TEnumerable; -#define FORWARD_BY(item, item_by) std::is_rvalue_reference_v ? std::move(item) : item -#define FORWARD(x) std::forward(x) -#define DECLTYPE(x) std::decay_t -TT using TElemFromType = DECLTYPE(*std::declval().begin()); -#define TElemFromInst(v) DECLTYPE(*v.begin()) -#define _DEDUCT(t_name) \ -template t_name(T) -> t_name>; \ -template t_name(T) -> t_name>; \ -template t_name(T...) -> t_name; -#define ALL_TH this->begin(),this->end() -#define ALL(x) x.begin(),x.end() -#define _OPER_FROM(op) TThis operator op(const TThis& b) const { TThis a(*this); a op ## = b; return a; } -struct Empty {}; -#define var auto&& -constexpr Long inf = std::numeric_limits::max() / 4; -constexpr int inf_int = std::numeric_limits::max() - 10; -auto geti() { return _IOBase::read(); } -auto getc() { return _IOBase::read(); } -auto get_c() { return getc(); } -auto getd() { return _IOBase::read(); } -TT void put_raw(const T& v) { _IOBase::put(v); } -void _print_endl() { _IOBase::put('\n'); if (_IOBase::AutoFlash) std::cout.flush(); } -void put_raw(const std::string& v) { _IOBase::put(v); } -void put_raw(const TEnumerable auto& v) { - bool init = false; - for (const auto& e : v) { - if (!init) init = true; else put_raw(' '); - put_raw(e); - } -} -void put_raw_nosp(const auto& v) { put_raw(v); } -void put_raw_nosp(const TEnumerable auto& v) { for (const auto& e : v) { put_raw(e); } } -TTs void put_nosp(const T&...v) { (put_raw_nosp(v), ...); } -TTs void put(const T&...v) { - int cnt = 0; - ((put_raw(v), (++cnt != (sizeof...(v)) ? _IOBase::put(' ') : ([]() {})())), ...); -} -TTs void print(const T&...v) { put(v...); _print_endl(); } -TTs void print_nosp(const T&...v) { put_nosp(v...); _print_endl(); } -void done() { throw 1; } -TTs void done(const T&...v) { print(v...); done(); } -TTs void print_sp(const T&...v) { put(v...); put_raw(' '); } -void print_yes(bool cond) { print(cond ? ""Yes"" : ""No""); } -void done_yes(bool cond) { print(cond ? ""Yes"" : ""No""); done(); } -TTs void __READ(T&... v) { ((v = _IOBase::read()), ...); } -#define __read_cmn(x, ...) x __VA_ARGS__ ; __READ(__VA_ARGS__); -#define readi(...) __read_cmn(Long, __VA_ARGS__) -Long Sum1n(Long n) { if (n <= 0) return 0; return (n * n + n) / 2; } -Long Sumkn(Long k, Long n) { if (k > n) return 0; return Sum1n(n) - Sum1n(k - 1); } -auto Iota(Long l, Long r) { return std::ranges::iota_view(l, r + 1); } -auto Iota0(Long r) { return Iota(0, r); } -auto Iota1(Long r) { return Iota(1, r); } -auto Abs(const auto& a) { return std::abs(a); } -auto Min(const auto& a, const auto& b) { return a < b ? a : b; } -auto Max(const auto& a, const auto& b) { return a > b ? a : b; } -bool Max2(var a, const auto& b) { if (b > a) { a = b; return true; } return false; } -bool Min2(var a, const auto& b) { if (b < a) { a = b; return true; } return false; } -auto Max(var a, var b, var c, var... v) { auto res = Max(a, b); Max2(res, c); (Max2(res, v), ...); return res; } -auto Min(var a, var b, var c, var... v) { auto res = Min(a, b); Min2(res, c); (Min2(res, v), ...); return res; } -TT2 auto Swap(T& a, T2& b) { return std::swap(a, b); } -TT2 auto Sort(T& a, T2& b) { if (b < a) Swap(a, b); } -auto GCD(long a, long b) { return std::gcd(a, b); } -auto LCM(long a, long b) { return std::lcm(a, b); } -auto Log(var val, long k) { - if (k <= 1) return DECLTYPE(val) {}; - DECLTYPE(val) test = 1; - DECLTYPE(val) cnt = 0; - while (test < val) { test *= k; ++cnt; } - if (test != val) { cnt--; } - return cnt; -} -auto Log_up(var val, long k) { - if (k <= 1) return DECLTYPE(val) {}; - DECLTYPE(val) test = 1; - DECLTYPE(val) cnt = 0; - while (test < val) { test *= k; ++cnt; } - return cnt; -} -auto Pow(auto base, long exp) { - assert(exp >= 0); - decltype(base) result = 1; - for (; exp > 0; exp >>= 1) { - if (exp & 1) - result *= base; - base *= base; - } - return result; -} -auto Max(TEnumerable var v) { return *std::max_element(ALL(v)); } -auto Min(TEnumerable var t) { return *std::min_element(ALL(t)); } -auto Max(TEnumerable auto&& v, Invoke1 var f) { - auto it = v.begin(); - auto res = f(*it); - it++; - for (; it != v.end(); it++) { Max2(res, f(*it)); } - return res; -} -auto Min(TEnumerable var v, Invoke1 var f) { - auto it = v.begin(); - auto res = f(*it); - it++; - for (; it != v.end(); it++) { Min2(res, f(*it)); } - return res; -} -TC T = long > T Fact(long n) { - static std::vector stor = { 1,1 }; - if (n < stor.size()) return stor[n]; - T res = stor.back(); - long from = stor.size(); - if (n >= 400000) { - for (; from <= n; from++) { res *= from; } - } else { - for (; from <= n; from++) { - res *= from; - stor.push_back(res); - } - } - return res; -} -TC T = long> T Acomb(long k, long n) { - assert(k <= n); - return Fact(n) / Fact(n - k); -} -TC T = long > T Ccomb(long k, long n) { - assert(k <= n); - return Acomb(k, n) / Fact(k); -} -TT class _BaseCont : public T { - using TBase = T; -public: - using value_type = TBase::value_type; - using reference = TBase::reference; - using TBase::TBase; - _BaseCont(TBase&& s)noexcept : TBase(s) {} - Long size() const { return TBase::size(); } - value_type min() const { return *std::min_element(ALL_TH); } - value_type max() const { return *std::max_element(ALL_TH); } - value_type sum() const { return std::accumulate(ALL_TH, value_type{}); } -}; -TT class _BaseContList : public _BaseCont { - using TBase = _BaseCont; -public: - using value_type = TBase::value_type; - using reference = TBase::reference; - using TBase::TBase; - _BaseContList(TEnumerableSized var v) { - TBase::resize(v.size()); - int i = 0; - for (auto&& item : v) { - (*this)[i++] = FORWARD_BY(item, v); - } - } - _BaseContList(TEnumerable var v) { - for (auto&& item : v) { this->push_back(FORWARD_BY(item, v)); } - } - void reversy() { std::reverse(ALL_TH); } - bool contains(const value_type& v) { return std::find(ALL_TH, v) != this->end(); } - void replace(value_type a, value_type b) { std::replace(ALL_TH, a, b); } - void insert_at(Long i, const value_type& v) { TBase::insert(this->begin() + i, v); } - void fill(const value_type& v) { std::fill(ALL_TH, v); } - void remove_at(Long i) { if(i < this->size()) this->erase(this->begin() + i); } - bool remove_first(const value_type& val) { auto itr = std::find(ALL_TH, val); if (itr != this->end()) { this->erase(itr); return true; } return false; } - Long remove_all(const value_type& val) { - auto newEnd = std::remove(ALL_TH, val); - auto cnt = this->end() - newEnd; - this->erase(newEnd, this->end()); - return cnt; - } - value_type pop_back() { - auto res = std::move(TBase::back()); - TBase::pop_back(); - return res; - } - value_type pop_front() { - auto res = std::move(TBase::front()); - remove_at(0); - return res; - } - void push_front(const value_type& v) { - this->insert_at(0, v); - } - bool is_sorted() { return std::is_sorted(ALL_TH); } - void sort() { std::stable_sort(ALL_TH); } - void sort(Invoke2 var f) { std::stable_sort(ALL_TH, f); } - void sort_rev() { - std::stable_sort(ALL_TH, std::greater{}); - } - void set(int l, int r, const value_type& v) { - for (int i = l; i <= r; i++) { get(i) = v; } - } - reference operator[](int i) { return TBase::operator[](i); } - auto& operator[](int i) const { return TBase::operator[](i); } - value_type& get_rev(int i) { return get(this->size()-1-i); } - value_type& get(int i) { return (*this)[i]; } - value_type get_def(int i, value_type def = {}) { return i < this->size() && i >= 0 ? get(i) : def; } - void swap(int i, int j) { std::swap(get(i), get(j)); } -private: -}; -TCT = Long > class Vec : public _BaseContList> { - using TBase = _BaseContList>; -public: - using reference = TBase::reference; - using TBase::TBase; - using value_type = TBase::value_type; -}; -_DEDUCT(Vec); -TCT = Long > class Deque : public _BaseContList < std::deque> { - using TBase = _BaseContList < std::deque>; -public: - using TBase::TBase; - T pop_front() { - auto res = std::move(TBase::front()); - TBase::pop_front(); - return res; - } -}; -_DEDUCT(Deque); -TCT = long > class Cont : public Vec { - using TBase = Vec; -public: - using reference = TBase::reference; - using TBase::TBase; -public: - reference operator[](int i) { - if (i >= this->size()) { this->resize(i + 1); } - return TBase::operator[](i); - } -}; -_DEDUCT(Cont); -TCT = long > class Cont2 : public Cont { - using TBase = Cont; -public: - using TBase::TBase; - using reference = TBase::reference; -public: - reference operator[](int i) { - if (i < 0) { - return minus[-i]; - } - return TBase::operator[](i); - } -private: - Cont minus; -}; -_DEDUCT(Cont2); -auto getv(int n, Invoke0 var getter) { - Vec res(n); - for (auto i = 0; i < n; i++) { - res[i] = getter(); - } - return res; -} -auto getv(int n) { return getv(n, geti); } -auto gets_digit(int n = -1) { - if (n != -1) { - Vec res(n); - for(int i = 0; i < n; i++) { - res[i] = get_c() - '0'; - } - return res; - } - auto s = _IOBase::read(); - Vec res(s.size()); - for(int i = 0; i < s.size(); i++) { - res[i] = s[i] - '0'; - } - return res; -} -class Str : public _BaseContList { - using TBaseStr = std::string; - using TBase = _BaseContList; - using reference = TBase::reference; -public: - using TBase::TBase; - using value_type = TBase::value_type; - Str get(int l, int r) const { - if (l > r) return """"; - if (r >= size()) r = size() - 1; - return substr(l, r - l + 1); - } - void tolower() { - std::transform(begin(), end(), begin(), [](unsigned char c) { return std::tolower(c); } - ); - } -}; -Str operator"""" s(const char* _Str, size_t _Len) { - return Str{ _Str, _Len }; -} -Str gets(int n = -1) { - if (n != -1) { - Str res; - res.resize(n); - for (int i = 0; i < n; i++) { - res[i] = get_c(); - } - return res; - } - return _IOBase::read(); -} -void put_raw(const Str& v) { for (char c : v) put_raw(c); } -namespace _For_impl { - template struct ForIter { - using Iter = decltype(std::begin(std::declval())); - using Iter_end = decltype(std::end(std::declval())); - using IterRef = decltype(*std::declval()); - Long i = 0; Iter iter; Iter_end iter_end; - ForIter(T& cont) :iter(std::begin(cont)), iter_end(std::end(cont)) { } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++iter; ++i; } - bool operator!=(int) { return iter != iter_end; } - std::tuple operator*() { return { *iter, i }; } - }; - template struct ForIterRev { - using Iter = decltype(std::rbegin(std::declval())); - using Iter_end = decltype(std::rend(std::declval())); - using IterRef = decltype(*std::declval()); - Long i; Iter iter; Iter_end iter_end; - ForIterRev(T& cont) :i(cont.size()-1), iter(cont.rbegin()), iter_end(cont.rend()) { } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++iter; --i; } - bool operator!=(int) { return iter != iter_end; } - std::tuple operator*() { return { *iter, i }; } - }; - template<> struct ForIter { - Long i; Long n; - ForIter(Long c) :n(c) { i = 0; } - auto&& begin() { return std::move(*this); } - int end() { return 0; } - void operator++() { ++i; } - bool operator!=(int) { return i != n; } - std::tuple operator*() { return { i, i }; } - }; - template auto Get_For_Handler_rev(T& v) { - return ForIterRev(v); - } - auto Get_For_Handler(Long v) { - return ForIter(v); - } - template auto Get_For_Handler(T& v) { - return ForIter(v); - } -} -#define __GET_MACRO(_0,_1,_2,_3,_4,_5,X,...) X -#define __EXPAND( x ) x -#define _fe2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler (__cont)) -#define _fer2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler_rev (__cont)) -#define _fe1(cont) _fe2(_, cont) -#define _fer1(cont) _fer2(_, cont) -#define fe(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fe2, _fe1, _0)(__VA_ARGS__)) -#define re(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fer2, _fer1, _0)(__VA_ARGS__)) -void Solve() { - auto aa = gets(); - auto bb = gets(); - auto cc = gets(); - Vec dp(2010); - fe(e, cc) { - auto dp2 = dp; - for (long cnt_a = 0; cnt_a <= 2005; cnt_a++) { - auto cnt_b = ei - cnt_a; - if (cnt_b < 0) break; - if (cnt_b < bb.size()) { - auto cur = bb[cnt_b]; - long res = cur == e ? 1 : 0; - Max2(dp2[cnt_a], dp[cnt_a] + res); - } - if (cnt_a < aa.size()) { - auto cur = aa[cnt_a]; - long res = cur == e ? 1 : 0; - Max2(dp2[cnt_a + 1], dp[cnt_a] + res); - } - } - dp = dp2; - } - long max = dp.max(); - print(cc.size() - max); -} -void initialize(ProblemData& pd){ - pd.HasTestcase = true; - pd.AutoFlash = false; -} -",1 -rudraveersingh7275467181,2050E - Three Strings,c++17 ,297652469,297649869,"#include -#include -#include -#include -#include -using namespace std; - -int minChanges(string &a, string &b, string &c) { - int n = a.length(), m = b.length(); - vector prev(m + 1, 0), curr(m + 1, 0); - - // Initialize base cases - for (int j = 0; j <= m; ++j) { - prev[j] = j; // Only use characters from `b` - } - - for (int i = 0; i <= n; ++i) { - curr[0] = i; // Only use characters from `a` - - for (int j = 0; j <= m; ++j) { - if (i == 0 && j == 0) continue; // Base case already handled - int k = i + j - 1; // Current index in `c` - - curr[j] = INT_MAX; // Initialize to a large value - - if (i > 0 && a[i - 1] == c[k]) { // Match with `a` - curr[j] = min(curr[j], prev[j]); - } else if (i > 0) { // Mismatch with `a` - curr[j] = min(curr[j], prev[j] + 1); - } - - if (j > 0 && b[j - 1] == c[k]) { // Match with `b` - curr[j] = min(curr[j], curr[j - 1]); - } else if (j > 0) { // Mismatch with `b` - curr[j] = min(curr[j], curr[j - 1] + 1); - } - } - - // Swap `prev` and `curr` - swap(prev, curr); - } - - return prev[m]; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - string a, b, c; - cin >> a >> b >> c; - cout << minChanges(a, b, c) << '\n'; - } - - return 0; -} -","#include -#include -#include -using namespace std; -int f(int i,int j,int k,vector>&dp,string a,string b,string c){ - if(i==a.length()&&j==b.length()){ - return 0; - } - if(dp[i][j]!=-1)return dp[i][j]; - if(i>t; - while(t--){ - - string a,b,c; - cin>>a>>b>>c; -vector>dp(a.length()+1,vector(b.length()+1,-1)); - - cout<< f(0,0,0,dp,a,b,c); - - cout< -using namespace std; - -//#include -//mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -//indexed-set - -//#include -//using namespace __gnu_pbds; -//typedef tree,rb_tree_tag, -//tree_order_statistics_node_update> indexed_set; -//less_equal -//auto x = s.find_by_order(pos); -//int x = s.order_of_key(value) - -//gp_hash_table - -//#include -//#include -//using namespace __gnu_pbds; - -//#pragma GCC optimize(""Ofast,unroll-loops"") -//#pragma GCC target(""avx,avx2,fma"") -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -//#pragma comment(linker, ""/STACK: 2000000"") -typedef __int128 lll; - -#define ll long long -#define ld long double -#define watch(x) cout << (#x) << "" is "" << (x) << endl -#define PI 3.1415926535897932384626433832795 -#define EULER 2.7182818284590452353602874713 -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define sz(x) (int((x).size())) - -const ll mod = 1e9 + 7; -const ll INF = 1e18 ; -const ll MIN = -1e18 ; -const ll MAXII = 200005 ; - -template T gcd(T a, T b){return(b?__gcd(a,b):a);} -template T lcm(T a, T b){return(a*(b/gcd(a,b)));} -template void dbg(vector v){for (auto x : v) cout << x << "" ""; cout << endl;} -template void dbgg(pair p){cout << p.F << "" "" << p.S << endl;} - - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } -bool prime(ll a) { if (a==1) return 0; for (int i=2;i*i<=a;++i) if (a%i==0) return 0; return 1; } -ll inv(ll N) {if (N == 1) return 1; return (mod - ((mod / N) * inv(mod % N)) % mod) % mod;} -void yes() { cout<<""YES\n""; } -void no() { cout<<""NO\n""; } -//ll getRandomNumber(ll l, ll r) {return uniform_int_distribution(l, r)(rng);} -void star() { cout<<""***************************************\n""; } - - -//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); -// } -//}; -//const int mod = 1e9+7; -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; -} - -//gp_hash_table mp; - -const int N = 2e3+5; -/*vector>adj(N); -vectorvis(N); -int dfs(int i){ - vis[i]=true; - for(auto k : adj[i]){ - if(!vis[k]) dfs(k); - } -}*/ - -int n , m ; -ll dp[N][N]; -string s ; -string a , b,c; -ll work(int i , int j ){ - int idx = i+j-1; - if(dp[i][j]!=-1) return dp[i][j]; - if(i<=n && j<=m){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =work(i+1,j)+val; - val = (b[j]!=s[idx] ? 1 :0); - ans = min(ans ,work(i,j+1)+val); - dp[i][j]=ans; - - } - else if(i<=n){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =val+work(i+1,j); - dp[i][j]=ans; - } - else if(j<=m){ - ll val = (b[j]!=s[idx] ? 1 :0); - ll ans = val+work(i,j+1); - dp[i][j]=ans; - } - else return 0; - //cout<>a>>b>>c; - n= a.size(),m=b.size(); - a='#'+a; - b='#'+b; - c='#'+c; - s=c; - for(int i=0;i<=n+2;i++) for(int j=0;j<=m+2;j++) dp[i][j]=-1; - - cout<> tc; - //memset(primes, 0, sizeof(primes)); -// sieve(); - - - while(tc--) { - solve(); - } -}4","#include -using namespace std; - -//#include -//mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -//indexed-set - -//#include -//using namespace __gnu_pbds; -//typedef tree,rb_tree_tag, -//tree_order_statistics_node_update> indexed_set; -//less_equal -//auto x = s.find_by_order(pos); -//int x = s.order_of_key(value) - -//gp_hash_table - -//#include -//#include -//using namespace __gnu_pbds; - -//#pragma GCC optimize(""Ofast,unroll-loops"") -//#pragma GCC target(""avx,avx2,fma"") -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -//#pragma comment(linker, ""/STACK: 2000000"") -typedef __int128 lll; - -#define ll long long -#define ld long double -#define watch(x) cout << (#x) << "" is "" << (x) << endl -#define PI 3.1415926535897932384626433832795 -#define EULER 2.7182818284590452353602874713 -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define sz(x) (int((x).size())) - -const ll mod = 1e9 + 7; -const ll INF = 1e18 ; -const ll MIN = -1e18 ; -const ll MAXII = 200005 ; - -template T gcd(T a, T b){return(b?__gcd(a,b):a);} -template T lcm(T a, T b){return(a*(b/gcd(a,b)));} -template void dbg(vector v){for (auto x : v) cout << x << "" ""; cout << endl;} -template void dbgg(pair p){cout << p.F << "" "" << p.S << endl;} - - -string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } -string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } -bool prime(ll a) { if (a==1) return 0; for (int i=2;i*i<=a;++i) if (a%i==0) return 0; return 1; } -ll inv(ll N) {if (N == 1) return 1; return (mod - ((mod / N) * inv(mod % N)) % mod) % mod;} -void yes() { cout<<""YES\n""; } -void no() { cout<<""NO\n""; } -//ll getRandomNumber(ll l, ll r) {return uniform_int_distribution(l, r)(rng);} -void star() { cout<<""***************************************\n""; } - - -//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); -// } -//}; -//const int mod = 1e9+7; -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; -} - -//gp_hash_table mp; - -const int N = 2e3+5; -/*vector>adj(N); -vectorvis(N); -int dfs(int i){ - vis[i]=true; - for(auto k : adj[i]){ - if(!vis[k]) dfs(k); - } -}*/ - -int n , m ; -ll dp[N][N]; -string s ; -string a , b,c; -ll work(int i , int j ){ - int idx = i+j-1; - if(dp[i][j]!=-1) return dp[i][j]; - if(i<=n && j<=m){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =work(i+1,j)+val; - val = (b[j]!=s[idx] ? 1 :0); - ans = min(ans ,work(i,j+1)+val); - dp[i][j]=ans; - - } - else if(i<=n){ - ll val = (a[i]!=s[idx] ? 1 :0); - ll ans =val+work(i+1,j); - dp[i][j]=ans; - } - else if(j<=m){ - ll val = (b[j]!=s[idx] ? 1 :0); - ll ans = val+work(i,j+1); - dp[i][j]=ans; - } - else return 0; - //cout<>a>>b>>c; - n= a.size(),m=b.size(); - a='#'+a; - b='#'+b; - c='#'+c; - s=c; - for(int i=0;i<=n+2;i++) for(int j=0;j<=m+2;j++) dp[i][j]=-1; - - cout<> tc; - //memset(primes, 0, sizeof(primes)); -// sieve(); - - - while(tc--) { - solve(); - } -}",1 -trump_Fan,2050E - Three Strings,c++17 ,295977154,295978271,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; - -#define int long long -#define float double - -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define inp(x) \ - int x; \ - cin >> x; - -#define pb push_back -#define fr(i, b) for (int i = 0; i < (int)(b); i++) -#define scanarr \ - int a[n]; \ - for (int i = 0; i < n; i++) \ - cin >> a[i] -#define sz(a) (int)(a.size()) -#define all(a) a.begin(), a.end() -#define mod 1000000007 -#define lower(a, b) lower_bound((a).begin(), (a).end(), (int)(b)) -#define upper(a, b) upper_bound((a).begin(), (a).end(), (int)(b)) -#define lower_ind(a, b) lower_bound((a).begin(), (a).end(), (int)(b)) - (a).begin() -#define upper_ind(a, b) upper_bound((a).begin(), (a).end(), (int)(b)) - (a).begin() - -typedef vector vi; -typedef set si; -typedef pair pii; -typedef vector> vvi; -typedef vector> vpii; -typedef map mii; -typedef map mci; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -void solve() -{ - string a; - string b; - string c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - vector dp(n + 1, vector(m + 1, 0)); - for (int i = 1; i <= m; i++) - { - if (b[i - 1] != c[i - 1]) - { - dp[0][i] = dp[0][i - 1] + 1; - } - else - { - dp[0][i] = dp[0][i - 1]; - } - } - for (int i = 1; i <= n; i++) - { - dp[i][0] = dp[i - 1][0]; - if (a[i - 1] != c[i - 1]) - { - dp[i][0] += 1; - } - } - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= m; j++) - { - int flag = 0; - if (a[i - 1] == c[i + j - 1]) - { - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1); - flag = 1; - } - if (b[j - 1] == c[i + j - 1]) - { - if (flag == 1) - { - dp[i][j] = min(dp[i][j], dp[i][j - 1]); - } - else - { - dp[i][j] = dp[i][j - 1]; - } - } - if ((a[i - 1] != c[i + j - 1]) && (b[j - 1] != c[i + j - 1])) - { - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - } - } - } - cout << dp[n][m] << endl; -} - -signed main() -{ - fast; - int t; - cin >> t; - while (t--) - { - solve(); - } -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; - -#define int long long -#define float double - -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define inp(x) \ - int x; \ - cin >> x; - -#define pb push_back -#define fr(i, b) for (int i = 0; i < (int)(b); i++) -#define scanarr \ - int a[n]; \ - for (int i = 0; i < n; i++) \ - cin >> a[i] -#define sz(a) (int)(a.size()) -#define all(a) a.begin(), a.end() -#define mod 1000000007 -#define lower(a, b) lower_bound((a).begin(), (a).end(), (int)(b)) -#define upper(a, b) upper_bound((a).begin(), (a).end(), (int)(b)) -#define lower_ind(a, b) lower_bound((a).begin(), (a).end(), (int)(b)) - (a).begin() -#define upper_ind(a, b) upper_bound((a).begin(), (a).end(), (int)(b)) - (a).begin() - -typedef vector vi; -typedef set si; -typedef pair pii; -typedef vector> vvi; -typedef vector> vpii; -typedef map mii; -typedef map mci; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key - -void solve() -{ - string a; - string b; - string c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - vector dp(n + 1, vector(m + 1, 1e9)); - dp[0][0] = 0; - for (int i = 1; i <= m; i++) - { - if (b[i - 1] != c[i - 1]) - { - dp[0][i] = dp[0][i - 1] + 1; - } - else - { - dp[0][i] = dp[0][i - 1]; - } - } - for (int i = 1; i <= n; i++) - { - dp[i][0] = dp[i - 1][0]; - if (a[i - 1] != c[i - 1]) - { - dp[i][0] += 1; - } - } - for (int i = 1; i <= n; i++) - { - for (int j = 1; j <= m; j++) - { - if (a[i - 1] == c[i + j - 1] && b[j - 1] == c[i + j - 1]) - { - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]); - } - else if (a[i - 1] == c[i + j - 1]) - { - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1); - } - else if (b[j - 1] == c[i + j - 1]) - { - dp[i][j] = min(dp[i][j - 1], dp[i - 1][j] + 1); - } - else if (a[i - 1] != c[i + j - 1] && b[j - 1] != c[i + j - 1]) - { - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - } - } - } - cout << dp[n][m] << endl; -} - -signed main() -{ - fast; - int t; - cin >> t; - while (t--) - { - solve(); - } -}",2 -deevijbansal,2050E - Three Strings,c++17 ,297649541,297648938,"#include -using namespace std; - -typedef long long ll; - -int dp(string &a, string &b, string &c, int ia, int ib, vector> &arr) -{ - if (ia == a.size() && ib == b.size()) - { - return 0; - } - - if (arr[ia][ib] != -1) - { - return arr[ia][ib]; - } - - int left = INT_MAX, right = INT_MAX; - - if (ia < a.size()) - { - if (arr[ia + 1][ib] != -1) - { - left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]); - } - else - { - left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]); - } - } - if (ib < b.size()) - { - if (arr[ia][ib + 1] != -1) - { - right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]); - } - else - { - right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]); - } - } - - arr[ia][ib] = min(left, right); - return arr[ia][ib]; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - - vector> arr(a.size() + 1, vector(b.size() + 1, -1)); - - cout << dp(a, b, c, 0, 0, arr) << endl; - } - - return 0; -}","#include -using namespace std; - -typedef long long ll; - -int dp(string a, string b, string c, int ia, int ib, vector> arr) -{ - if (ia == a.size() && ib == b.size()) - { - return 0; - } - - int left = INT_MAX, right = INT_MAX; - - if (ia < a.size()) - { - if (arr[ia][ib] != -1) - { - left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]); - } - else - { - left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]); - } - } - if (ib < b.size()) - { - if (arr[ia][ib] != -1) - { - right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]); - } - else - { - right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]); - } - } - - arr[ia][ib] = min(left, right); - return arr[ia][ib]; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - - vector> arr(a.size() + 1, vector(b.size() + 1, -1)); - - cout << dp(a, b, c, 0, 0, arr) << endl; - } - - return 0; -}",1 -alaincr7,2050E - Three Strings,c++20 ,295659890,295652795,"#include -#define int long long -#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) -using namespace std; -int32_t main(){ - fastio(); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - //just tabulate - vector>dp((int)a.size()+1,vector((int)b.size()+1)); - for(int i=(int)b.size()-1;i>=0;i--){ - int indexc=(int)c.size()-(int)b.size()+i; - int x=0; - if(c[indexc]!=b[i]){ - x=1; - } - dp[(int)a.size()][i]=x+dp[(int)a.size()][i+1]; - } - for(int i=(int)a.size()-1;i>=0;i--){ - int indexc=(int)c.size()-(int)a.size()+i; - int x=0; - if(c[indexc]!=a[i]){ - x=1; - } - dp[i][(int)b.size()]=x+dp[i+1][(int)b.size()]; - } - for(int i=(int)a.size()-1;i>=0;i--){ - for(int j=(int)b.size()-1;j>=0;j--){ - int indexc=(int)c.size()-(int)a.size()-(int)b.size()+i+j; - int mine=INT_MAX; - if(c[indexc]!=a[i]){ - mine=min(mine,1+dp[i+1][j]); - } - else{ - mine=min(mine,dp[i+1][j]); - } - if(c[indexc]!=b[j]){ - mine=min(mine,1+dp[i][j+1]); - } - else{ - mine=min(mine,dp[i][j+1]); - } - dp[i][j]=mine; - } - } - cout< -#define int long long -#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) -using namespace std; -int dp[1001][1001]; -int solve(int indexa,int indexb,int indexc,string a,string b,string c){ - int mine=INT_MAX; - if(indexa<(int)a.size() && indexb>=(int)b.size()){ - int count=0; - int j=indexa; - for(int i=indexc;i<(int)c.size();i++){ - if(c[i]!=a[j]){ - count++; - } - j++; - } - mine=min(mine,count); - } - else if(indexa>=(int)a.size() && indexb<(int)b.size()){ - int count=0; - int j=indexb; - for(int i=indexc;i<(int)c.size();i++){ - if(c[i]!=b[j]){ - count++; - } - j++; - } - mine=min(mine,count); - } - else if(indexa<(int)a.size() && indexb<(int)b.size()){ - if(c[indexc]!=a[indexa]){ - if(dp[indexa+1][indexb]==-1){ - dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c); - } - mine=min(mine,1+dp[indexa+1][indexb]); - } - else{ - if(dp[indexa+1][indexb]==-1){ - dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c); - } - mine=min(mine,dp[indexa+1][indexb]); - } - if(c[indexc]!=b[indexb]){ - if(dp[indexa][indexb+1]==-1){ - dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c); - } - mine=min(mine,1+dp[indexa][indexb+1]); - } - else{ - if(dp[indexa][indexb+1]==-1){ - dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c); - } - mine=min(mine,dp[indexa][indexb+1]); - } - } - else{ - mine=min(mine,(int)0); - } - return mine; -} -int32_t main(){ - fastio(); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - int indexa=0,indexb=0,indexc=0; - memset(dp,-1,sizeof(dp)); - dp[indexa][indexb]=solve(indexa,indexb,indexc,a,b,c); - cout< -using namespace std; -#define lli long long int -#define ulli unsigned long long int -#define ldouble long double -#define pr pair -#define loop(i,x,n) for(long long int i=x;i=n;i--) -#define all(x) x.begin(),x.end() -#define rall(x) x.rbegin(),x.rend() -#define lop(x,m) for(auto &x:m) -#define pb push_back -#define SUM(x) accumulate(x.begin(),x.end(),0LL) -#define py cout<<""YES""< -#define deb(v) for(auto &x:v){cout<>x;v.pb(x);} -const char nl = '\n'; - - -#define PI 3.141592653589793238462 -#define set_bit __builtin_popcountll -#define MOD1 998244353 -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif -void _print(lli t) {cerr << t;} -void _print(int t) {cerr << t;} -void _print(string t) {cerr << t;} -void _print(char t) {cerr << t;} -void _print(double t) {cerr << t;} -void _print(ulli t) {cerr << t;} -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -lli powerm(lli a, lli b) -{ - lli res = 1; - while (b > 0) - { - if (b & 1 != 0) - res = (res * a) % M; - a = (a * a) % M; - b >>= 1; - } - return res; -} -lli power(lli a, lli b) -{ - lli res = 1; - while (b > 0) - { - if (b & 1 != 0) - res = (res * a) ; - a = (a * a) ; - b >>= 1; - } - return res; -} - - -lli inverse(lli a) -{ - return powerm(a, M - 2); -} - - -bool isprime(lli n){ - int f=0; - if(n<=1)return false; - for(lli i=2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; -} -bool isperfectsquare(lli x) -{ - if (x >= 0){ - lli sr = sqrt(x); - return (sr * sr == x) ; - } - return false; -} - - -lli add(lli x,lli y) -{ - return (x%M+y%M+M)%M; -} - -lli mul(lli x,lli y) -{ - return (((x%M*y%M)%M)+M)%M; -} - -lli sub(lli x,lli y) -{ - return ((x%M)-(y%M)+M+M)%M; -} -lli lcm(lli a, lli b) -{ - return ((a*b) /__gcd(a, b)) ; -} - - -lli fact[500001]; -lli inv[500001]; -void factorial() -{ - fact[0]=1; - for(int i=1; i<=500000; i++) - { - fact[i]=mul(fact[i-1],i); - } - inv[500000]=inverse(fact[500000]); - for(int i=500000; i>0; i--)inv[i-1]=mul(inv[i],i); -} -lli ncr(lli n,lli r) -{ - if(r<0)return 0; - lli ret=1; - ret=fact[n]; - ret=mul(ret,inv[r]); - ret=mul(ret,inv[n-r]); - return ret; -} - - -vector primes,siev(100000+1, 0); -void sieve(){ - for(lli i=2;i<=100000;i++){ - if(siev[i]==0){ - primes.push_back(i); - for(lli j=i*i;j<=100000;j+=i) siev[j]=1; - } - } -} -bool issorted(vi v){ - loop(i,0,v.size()-1){ - if(v[i]>v[i+1]){ - return false; - } - } - return true; -} - - -bool ispal(string s){ - lli i=0,j=s.size()-1; - while(i> dir4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; -vector> dir8 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},{1,-1},{-1,1},{1,1},{-1,-1}}; -lli sqroot(lli n) -{ - lli low = 1, high = n, res; - while (low <= high) - { - lli mid = (low + high) / 2; - if ((mid * mid) == n) - { - res = mid; - break; - } - else if ((mid * mid) > n) - { - high = mid - 1; - } - else - { - res = mid; - low = mid + 1; - } - } - return res; -} -vi sa,sb; -vector>dp; -lli slv(lli i,lli j,string &a, string &b, string &c){ - if(i>=a.size()&&j>=b.size()){ - return 0; - } - if(i>=a.size()){ - return sb[j]; - } - if(j>=b.size()){ - return sa[i]; - } - if(dp[i][j]!=-1)return dp[i][j]; - if(a[i]==c[i+j]&&b[j]==c[i+j]){ - return dp[i][j]=min(slv(i+1,j,a,b,c),slv(i+1,j,a,b,c)); - } - else if(a[i]==c[i+j]){ - return dp[i][j]=min(slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c)); - } - else if(b[j]==c[i+j]){ - return dp[i][j]=min(1+slv(i+1,j,a,b,c),slv(i,j+1,a,b,c)); - } - return dp[i][j]=min(1+slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c)); -} -void solve(){ - string a,b,c; - cin>>a>>b>>c; - dp=vector>(a.size(),vector(b.size(),-1)); - sa.resize(a.size()); - sb.resize(b.size()); - lli cc=0; - lli j=c.size()-1; - loopr(i,a.size()-1,0){ - if(a[i]!=c[j]){ - cc++; - } - j--; - sa[i]=cc; - } - cc=0; - j=c.size()-1; - loopr(i,b.size()-1,0){ - if(b[i]!=c[j]){ - cc++; - } - j--; - sb[i]=cc; - } - cout<>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define lli long long int -#define ulli unsigned long long int -#define ldouble long double -#define pr pair -#define loop(i,x,n) for(long long int i=x;i=n;i--) -#define all(x) x.begin(),x.end() -#define rall(x) x.rbegin(),x.rend() -#define lop(x,m) for(auto &x:m) -#define pb push_back -#define SUM(x) accumulate(x.begin(),x.end(),0LL) -#define py cout<<""YES""< -#define deb(v) for(auto &x:v){cout<>x;v.pb(x);} -const char nl = '\n'; - - -#define PI 3.141592653589793238462 -#define set_bit __builtin_popcountll -#define MOD1 998244353 -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif -void _print(lli t) {cerr << t;} -void _print(int t) {cerr << t;} -void _print(string t) {cerr << t;} -void _print(char t) {cerr << t;} -void _print(double t) {cerr << t;} -void _print(ulli t) {cerr << t;} -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -lli powerm(lli a, lli b) -{ - lli res = 1; - while (b > 0) - { - if (b & 1 != 0) - res = (res * a) % M; - a = (a * a) % M; - b >>= 1; - } - return res; -} -lli power(lli a, lli b) -{ - lli res = 1; - while (b > 0) - { - if (b & 1 != 0) - res = (res * a) ; - a = (a * a) ; - b >>= 1; - } - return res; -} - - -lli inverse(lli a) -{ - return powerm(a, M - 2); -} - - -bool isprime(lli n){ - int f=0; - if(n<=1)return false; - for(lli i=2;i<=sqrt(n);i++){ - if(n%i==0){ - return false; - } - } - return true; -} -bool isperfectsquare(lli x) -{ - if (x >= 0){ - lli sr = sqrt(x); - return (sr * sr == x) ; - } - return false; -} - - -lli add(lli x,lli y) -{ - return (x%M+y%M+M)%M; -} - -lli mul(lli x,lli y) -{ - return (((x%M*y%M)%M)+M)%M; -} - -lli sub(lli x,lli y) -{ - return ((x%M)-(y%M)+M+M)%M; -} -lli lcm(lli a, lli b) -{ - return ((a*b) /__gcd(a, b)) ; -} - - -lli fact[500001]; -lli inv[500001]; -void factorial() -{ - fact[0]=1; - for(int i=1; i<=500000; i++) - { - fact[i]=mul(fact[i-1],i); - } - inv[500000]=inverse(fact[500000]); - for(int i=500000; i>0; i--)inv[i-1]=mul(inv[i],i); -} -lli ncr(lli n,lli r) -{ - if(r<0)return 0; - lli ret=1; - ret=fact[n]; - ret=mul(ret,inv[r]); - ret=mul(ret,inv[n-r]); - return ret; -} - - -vector primes,siev(100000+1, 0); -void sieve(){ - for(lli i=2;i<=100000;i++){ - if(siev[i]==0){ - primes.push_back(i); - for(lli j=i*i;j<=100000;j+=i) siev[j]=1; - } - } -} -bool issorted(vi v){ - loop(i,0,v.size()-1){ - if(v[i]>v[i+1]){ - return false; - } - } - return true; -} - - -bool ispal(string s){ - lli i=0,j=s.size()-1; - while(i> dir4 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; -vector> dir8 = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},{1,-1},{-1,1},{1,1},{-1,-1}}; -lli sqroot(lli n) -{ - lli low = 1, high = n, res; - while (low <= high) - { - lli mid = (low + high) / 2; - if ((mid * mid) == n) - { - res = mid; - break; - } - else if ((mid * mid) > n) - { - high = mid - 1; - } - else - { - res = mid; - low = mid + 1; - } - } - return res; -} -vi sa,sb; -vector>dp; -lli slv(lli i,lli j,string &a, string &b, string &c){ - if(i>=a.size()&&j>=b.size()){ - return 0; - } - if(i>=a.size()){ - return sb[j]; - } - if(j>=b.size()){ - return sa[i]; - } - if(dp[i][j]!=-1)return dp[i][j]; - if(a[i]==c[i+j]&&b[j]==c[i+j]){ - return dp[i][j]=min(slv(i+1,j,a,b,c),slv(i,j+1,a,b,c)); - } - else if(a[i]==c[i+j]){ - return dp[i][j]=min(slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c)); - } - else if(b[j]==c[i+j]){ - return dp[i][j]=min(1+slv(i+1,j,a,b,c),slv(i,j+1,a,b,c)); - } - else return dp[i][j]=min(1+slv(i+1,j,a,b,c),1+slv(i,j+1,a,b,c)); -} -void solve(){ - string a,b,c; - cin>>a>>b>>c; - dp=vector>(a.size()+1,vector(b.size()+1,-1)); - sa.resize(a.size()); - sb.resize(b.size()); - lli cc=0; - lli j=c.size()-1; - loopr(i,a.size()-1,0){ - if(a[i]!=c[j]){ - cc++; - } - j--; - sa[i]=cc; - } - cc=0; - j=c.size()-1; - loopr(i,b.size()-1,0){ - if(b[i]!=c[j]){ - cc++; - } - j--; - sb[i]=cc; - } - cout<>t; - while(t--){ - solve(); - } - return 0; -}",2 -bluddyFang,2050E - Three Strings,c++20 ,298144113,298143684,"#include -#define ll long long -#define pi pair -#define vi vector -#define dd double -#define f(i,a,b) for(ll i=a;i=b;i--) -#define pb push_back -#define lcm(a, b) ((a) * (b)) / __gcd(a, b) -#define mp make_pair -#define in insert -#define fi first -#define lb lower_bound -#define ub upper_bound -#define se second -#define yes cout<<""YES"" -#define no cout<<""NO"" -#define rd(n) ll n; cin>>n; -#define all(v) (v).begin(),(v).end() -#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];} -const int mod = 1e9 + 7; -using namespace std; -#define int long long - -const int inf = 1e9; - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - vector> dp(n + 1, vector(m + 1, inf)); - dp[0][0] = 0; - for (int i = 0; i < n; i++) { - dp[i + 1][0] = dp[i][0] + (a[i] != c[i]); - } - for (int j = 0; j < m; j++) { - dp[0][j + 1] = dp[0][j] + (b[j] != c[j]); - } - for (int i = 1; i <= n; i++) { - for (int j = 1; j <= m; j++) { - dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), - dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - cout << dp[n][m] ; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t = 1; - cin >> t; - while (t--) { - solve(); - cout << endl; - } - return 0; -} -","#include -#define ll long long -#define pi pair -#define vi vector -#define dd double -#define f(i,a,b) for(ll i=a;i=b;i--) -#define pb push_back -#define lcm(a, b) ((a) * (b)) / __gcd(a, b) -#define mp make_pair -#define in insert -#define fi first -#define lb lower_bound -#define ub upper_bound -#define se second -#define yes cout<<""YES"" -#define no cout<<""NO"" -#define rd(n) ll n; cin>>n; -#define all(v) (v).begin(),(v).end() -#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];} -const int mod = 1e9 + 7; -using namespace std; -#define int long long - -int n, m; - -int fun(string a, string b, string c, int i, int j, vector>>& dp) { - if (i >= n && j >= m) return 0; - if (dp[i][j][i + j] != -1) return dp[i][j][i + j]; - int ans = 1e5; - if (i < n) { - if (a[i] != c[i + j]) { - ans = min(ans, fun(a, b, c, i + 1, j, dp) + 1); - } else { - ans = min(ans, fun(a, b, c, i + 1, j, dp)); - } - } - if (j < m) { - if (b[j] != c[i + j]) { - ans = min(ans, fun(a, b, c, i, j + 1, dp) + 1); - } else { - ans = min(ans, fun(a, b, c, i, j + 1, dp)); - } - } - return dp[i][j][i + j] = ans; -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - n = a.size(), m = b.size(); - vector>> dp(n + 1, vector>(m + 1, vector(n + m + 1, -1))); - - - cout << fun(a, b, c, 0, 0, dp); -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t = 1; - cin >> t; - while (t--) { - solve(); - cout << endl; - } - return 0; -} -",1 -bluddyFang,2050E - Three Strings,c++20 ,298144113,298143853,"#include -#define ll long long -#define pi pair -#define vi vector -#define dd double -#define f(i,a,b) for(ll i=a;i=b;i--) -#define pb push_back -#define lcm(a, b) ((a) * (b)) / __gcd(a, b) -#define mp make_pair -#define in insert -#define fi first -#define lb lower_bound -#define ub upper_bound -#define se second -#define yes cout<<""YES"" -#define no cout<<""NO"" -#define rd(n) ll n; cin>>n; -#define all(v) (v).begin(),(v).end() -#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];} -const int mod = 1e9 + 7; -using namespace std; -#define int long long - -const int inf = 1e9; - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(), m = b.size(); - vector> dp(n + 1, vector(m + 1, inf)); - dp[0][0] = 0; - for (int i = 0; i < n; i++) { - dp[i + 1][0] = dp[i][0] + (a[i] != c[i]); - } - for (int j = 0; j < m; j++) { - dp[0][j + 1] = dp[0][j] + (b[j] != c[j]); - } - for (int i = 1; i <= n; i++) { - for (int j = 1; j <= m; j++) { - dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), - dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - cout << dp[n][m] ; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t = 1; - cin >> t; - while (t--) { - solve(); - cout << endl; - } - return 0; -} -","#include -#define ll long long -#define pi pair -#define vi vector -#define dd double -#define f(i,a,b) for(ll i=a;i=b;i--) -#define pb push_back -#define lcm(a, b) ((a) * (b)) / __gcd(a, b) -#define mp make_pair -#define in insert -#define fi first -#define lb lower_bound -#define ub upper_bound -#define se second -#define yes cout<<""YES"" -#define no cout<<""NO"" -#define rd(n) ll n; cin>>n; -#define all(v) (v).begin(),(v).end() -#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];} -const int mod = 1e9 + 7; -using namespace std; -#define int long long - -int n, m; - -int fun(string a, string b, string c, int i, int j, vector>>& dp) { - if (i >= n && j >= m) return 0; - if (dp[i][j][i + j] != -1) return dp[i][j][i + j]; - int ans = 1e5; - if (i < n) { - if (a[i] != c[i + j]) { - ans = min(ans, fun(a, b, c, i + 1, j, dp) + 1); - } else { - ans = min(ans, fun(a, b, c, i + 1, j, dp)); - } - } - if (j < m) { - if (b[j] != c[i + j]) { - ans = min(ans, fun(a, b, c, i, j + 1, dp) + 1); - } else { - ans = min(ans, fun(a, b, c, i, j + 1, dp)); - } - } - return dp[i][j][i + j] = ans; -} - -void solve() { - string a, b, c; - cin >> a >> b >> c; - n = a.size(), m = b.size(); - vector>> dp(n + 1, vector>(m + 1, vector(n + m + 1, -1))); - // cout << fun(a, b, c, 0, 0, dp); - dp[0][0][0] = 0; - - for (int i = 0; i <= n; i++) { - for (int j = 0; j <= m; j++) { - for (int k = 0; k <= n + m; k++) { - if (i + j != k) continue; - if (i < n && k < n + m) { - dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + (a[i] != c[k])); - } - if (j < m && k < n + m) { - dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + (b[j] != c[k])); - } - } - } - } - - cout << dp[n][m][n + m]; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - long long t = 1; - cin >> t; - while (t--) { - solve(); - cout << endl; - } - return 0; -} -",1 -pranjalchabra1908,2050E - Three Strings,c++23 ,306791076,306791031,"// #include - -// #include - -// #include - -// using namespace std; - -// using namespace __gnu_pbds; - - - -// using ll = long long; - -// #define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -// ll dfs(string s1, string s2, string s3, ll i, ll j, vector> &dp) - -// { - -// if (i >= s1.size() && j >= s2.size()) - -// { - -// return 0; - -// } - -// ll ans = LONG_LONG_MAX; - -// if (i < s1.size()) - -// { - -// ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1); - -// } - -// if (j < s2.size()) - -// { - -// ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1)); - -// } - -// return ans; - -// } - -// void solve() - -// { - -// string s1, s2, s3; - -// cin >> s1; - -// cin >> s2; - -// cin >> s3; - -// vector> dp(s1.size(), vector(s2.size(), LONG_LONG_MAX)); - -// cout << dfs(s1, s2, s3, 0, 0, dp) << endl; - -// } - -// int main() - -// { - - - -// ios::sync_with_stdio(false); - -// cin.tie(0); - -// long long t; - -// cin >> t; - - - -// while (t--) - -// { - -// long long a, b, c; - -// // cin >> a ; - -// solve(); - -// } - - - -// return 0; - -// } - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -using ll = long long; - -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -ll dfs(string &s1, string &s2, string &s3, ll i, ll j, vector> &dp) - -{ - - - - if (dp[i][j] != -1) - - { - - return dp[i][j]; - - } - - ll ans = LONG_LONG_MAX; - - if (i < s1.size()) - - { - - // cout << ""["" << i+1 << "","" << j << ""]"" << endl; - - ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1); - - } - - if (j < s2.size()) - - { - - // cout << ""["" << i << "","" << j+1 << ""]"" << endl; - - ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1)); - - } - - dp[i][j] = ans; - - return ans; - -} - -void solve() - -{ - - string s1, s2, s3; - - cin >> s1; - - cin >> s2; - - cin >> s3; - - vector> dp(s1.size() + 1, vector(s2.size() + 1, -1)); - - dp[s1.size()][s2.size()] = 0; - - dfs(s1, s2, s3, 0, 0, dp); - - cout << dp[0][0] << endl; - -} - -int main() - -{ - - - - ios::sync_with_stdio(false); - - cin.tie(0); - - long long t; - - cin >> t; - - - - while (t--) - - { - - long long a, b, c; - - // cin >> a ; - - solve(); - - } - - - - return 0; - -} - -","// #include - -// #include - -// #include - -// using namespace std; - -// using namespace __gnu_pbds; - - - -// using ll = long long; - -// #define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -// ll dfs(string s1, string s2, string s3, ll i, ll j, vector> &dp) - -// { - -// if (i >= s1.size() && j >= s2.size()) - -// { - -// return 0; - -// } - -// ll ans = LONG_LONG_MAX; - -// if (i < s1.size()) - -// { - -// ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1); - -// } - -// if (j < s2.size()) - -// { - -// ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1)); - -// } - -// return ans; - -// } - -// void solve() - -// { - -// string s1, s2, s3; - -// cin >> s1; - -// cin >> s2; - -// cin >> s3; - -// vector> dp(s1.size(), vector(s2.size(), LONG_LONG_MAX)); - -// cout << dfs(s1, s2, s3, 0, 0, dp) << endl; - -// } - -// int main() - -// { - - - -// ios::sync_with_stdio(false); - -// cin.tie(0); - -// long long t; - -// cin >> t; - - - -// while (t--) - -// { - -// long long a, b, c; - -// // cin >> a ; - -// solve(); - -// } - - - -// return 0; - -// } - - - -#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -using ll = long long; - -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -ll dfs(string &s1, string &s2, string &s3, ll i, ll j, vector> &dp) - -{ - - - - if (dp[i][j] != -1) - - { - - return dp[i][j]; - - } - - ll ans = LONG_LONG_MAX; - - if (i < s1.size()) - - { - - cout << ""["" << i+1 << "","" << j << ""]"" << endl; - - ans = dfs(s1, s2, s3, i + 1, j, dp) + (s1[i] == s3[i + j] ? 0 : 1); - - } - - if (j < s2.size()) - - { - - cout << ""["" << i << "","" << j+1 << ""]"" << endl; - - ans = min(ans, dfs(s1, s2, s3, i, j + 1, dp) + (s2[j] == s3[i + j] ? 0 : 1)); - - } - - dp[i][j] = ans; - - return ans; - -} - -void solve() - -{ - - string s1, s2, s3; - - cin >> s1; - - cin >> s2; - - cin >> s3; - - vector> dp(s1.size() + 1, vector(s2.size() + 1, -1)); - - dp[s1.size()][s2.size()] = 0; - - dfs(s1, s2, s3, 0, 0, dp); - - cout << dp[0][0] << endl; - -} - -int main() - -{ - - - - ios::sync_with_stdio(false); - - cin.tie(0); - - long long t; - - cin >> t; - - - - while (t--) - - { - - long long a, b, c; - - // cin >> a ; - - solve(); - - } - - - - return 0; - -} - -",1 -Karim53,2050E - Three Strings,c++20 ,308702553,308702693,"#include - - - -using namespace std; - - - -void Tarsh() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - -#ifdef gamed - - freopen(""input.txt"", ""r"", stdin), freopen(""output.txt"", ""w"", stdout); - -#endif - -} - - - -typedef long long ll; - -typedef long double ld; - -typedef unsigned long long ull; - -typedef pair pii; - -typedef pair pll; - -#define yes cout<<""YES\n""; - -#define no cout<<""NO\n""; - -#define fi first - -#define se second - -#define pb push_back - -#define All(x) (x).begin(),(x).end() - -#define Ones(n) __builtin_popcount(n) - -int dx[] = {0, 0, -1, 1, -1, 1, -1, 1}; - -int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1}; - -const ll MOD = 1e9 + 7; - -const ll N = 1e3 + 5; - - - -string a, b, c; - -int dp[N][N]; - - - -int slv(int i, int j) { - - if (i == a.size() && j == b.size()) - - return 0; - - - - int &ret = dp[i][j]; - - if (~ret) - - return ret; - - - - if (i == a.size()) { - - ret = slv(i, j + 1) + (b[j] != c[i + j]); - - } - - if (j == b.size()) { - - ret = slv(i + 1, j) + (a[i] != c[i + j]); - - } else { - - ret = min(slv(i, j + 1) + (b[j] != c[i + j]), slv(i + 1, j) + (a[i] != c[i + j])); - - } - - - - return ret; - -} - - - -void solve() { - - cin >> a >> b >> c; - - - - for (int i = 0; i <= a.size(); ++i) { - - for (int j = 0; j <= b.size(); ++j) { - - dp[i][j] = -1; - - } - - } - - - - cout << slv(0, 0) << '\n'; - -} - - - - - -int main() { - - Tarsh(); - - int t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -}","#include - - - -using namespace std; - - - -void Tarsh() { - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - -#ifdef gamed - - freopen(""input.txt"", ""r"", stdin), freopen(""output.txt"", ""w"", stdout); - -#endif - -} - - - -typedef long long ll; - -typedef long double ld; - -typedef unsigned long long ull; - -typedef pair pii; - -typedef pair pll; - -#define yes cout<<""YES\n""; - -#define no cout<<""NO\n""; - -#define fi first - -#define se second - -#define pb push_back - -#define All(x) (x).begin(),(x).end() - -#define Ones(n) __builtin_popcount(n) - -int dx[] = {0, 0, -1, 1, -1, 1, -1, 1}; - -int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1}; - -const ll MOD = 1e9 + 7; - -const ll N = 1e3 + 5; - - - -string a, b, c; - -int dp[N][N]; - - - -int slv(int i, int j) { - - if (i == a.size() && j == b.size()) - - return 0; - - - - int &ret = dp[i][j]; - - if (~ret) - - return ret; - - - - if (i == a.size()) { - - ret = slv(i, j + 1) + (b[j] != c[i + j]); - - } - - else if (j == b.size()) { - - ret = slv(i + 1, j) + (a[i] != c[i + j]); - - } else { - - ret = min(slv(i, j + 1) + (b[j] != c[i + j]), slv(i + 1, j) + (a[i] != c[i + j])); - - } - - - - return ret; - -} - - - -void solve() { - - cin >> a >> b >> c; - - - - for (int i = 0; i <= a.size(); ++i) { - - for (int j = 0; j <= b.size(); ++j) { - - dp[i][j] = -1; - - } - - } - - - - cout << slv(0, 0) << '\n'; - -} - - - - - -int main() { - - Tarsh(); - - int t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -}",2 -qdd,2050E - Three Strings,c++20 ,295508159,295508590,"// qdd on Dec 08, 2024 - -#ifdef qdd -#include -#else -#include -#define dbg(...) 42 -#endif - -using namespace std; - -using i64 = long long; - -template -istream& operator>>(istream& is, vector& v) { - for (T& x : v) is >> x; - return is; -} - -template -ostream& operator<<(ostream& os, const vector& v) { - bool f = 0; - for (const T& x : v) (f ? os << ' ' : os) << x, f = 1; - return os; -} - -void sol() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - int l = c.size(); - vector> dp(n + 1, vector(m + 1, 0)); - for (int k = 1; k <= l; k++) { - for (int i = 0; i <= min(n, k); i++) { - int j = k - i; - if (j < 0 || j > m) continue; - dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; - if (i > 0 && a[i - 1] == c[k - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j]); - if (j > 0 && b[j - 1] == c[k - 1]) dp[i][j] = min(dp[i][j], dp[i][j - 1]); - } - } - cout << dp[n][m] << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - sol(); - } - return 0; -}","// qdd on Dec 08, 2024 - -#ifdef qdd -#include -#else -#include -#define dbg(...) 42 -#endif - -using namespace std; - -using i64 = long long; - -template -istream& operator>>(istream& is, vector& v) { - for (T& x : v) is >> x; - return is; -} - -template -ostream& operator<<(ostream& os, const vector& v) { - bool f = 0; - for (const T& x : v) (f ? os << ' ' : os) << x, f = 1; - return os; -} - -void sol() { - string a, b, c; - cin >> a >> b >> c; - int n = a.size(); - int m = b.size(); - int l = c.size(); - vector> dp(n + 1, vector(m + 1, 1e9)); - dp[0][0] = 0; - for (int k = 1; k <= l; k++) { - for (int i = 0; i <= min(n, k); i++) { - int j = k - i; - if (j < 0 || j > m) continue; - if (i > 0) { - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[k - 1])); - } - if (j > 0) { - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[k - 1])); - } - } - } - cout << dp[n][m] << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - sol(); - } - return 0; -}",2 -Pranay_36,2050E - Three Strings,python,295482837,295483263,"import sys -input = sys.stdin.readline - -############ ---- Input Functions ---- ############ -def inp(): - return(int(input())) -def inlt(): - return(list(map(int,input().split()))) -def insr(): - s = input() - return(list(s[:len(s) - 1])) -def invr(): - return(map(int,input().split())) - - -def count_changes(a, b, c, i, j, k, memo_arr): - if memo_arr[i][j] == -1: - if k == len(c): - memo_arr[i][j] = 0 - elif i == len(a): - ans = 0 - for count in range(len(b[j:])): - if b[j + count] != c[k+count]: - ans += 1 - memo_arr[i][j] = ans - elif j == len(b): - ans = 0 - for count in range(len(a[i:])): - if a[i + count] != c[k+count]: - ans += 1 - memo_arr[i][j] = ans - else: - case1 = count_changes(a, b, c, i+1, j, k+1, memo_arr) - if a[i] != c[k]: - case1 += 1 - case2 = count_changes(a, b, c, i, j+1, k+1, memo_arr) - if b[j] != c[k]: - case2 += 1 - memo_arr[i][j] = min(case1, case2) - - return memo_arr[i][j] - - -t = inp() -for _ in range(t): - a = insr() - b = insr() - c = insr() - - i = 0 - j = 0 - - k = 0 - memo_arr = [[-1 for _ in range(len(b)+1)] for _ in range(len(a) + 1)] - print(count_changes(a, b, c, i, j, k, memo_arr)) - -","import sys -input = sys.stdin.readline -sys.setrecursionlimit(10000) - -############ ---- Input Functions ---- ############ -def inp(): - return(int(input())) -def inlt(): - return(list(map(int,input().split()))) -def insr(): - s = input() - return(list(s[:len(s) - 1])) -def invr(): - return(map(int,input().split())) - - -def count_changes(a, b, c, i, j, k, memo_arr): - if memo_arr[i][j] == -1: - if k == len(c): - memo_arr[i][j] = 0 - elif i == len(a): - ans = 0 - for count in range(len(b[j:])): - if b[j + count] != c[k+count]: - ans += 1 - memo_arr[i][j] = ans - elif j == len(b): - ans = 0 - for count in range(len(a[i:])): - if a[i + count] != c[k+count]: - ans += 1 - memo_arr[i][j] = ans - else: - case1 = count_changes(a, b, c, i+1, j, k+1, memo_arr) - if a[i] != c[k]: - case1 += 1 - case2 = count_changes(a, b, c, i, j+1, k+1, memo_arr) - if b[j] != c[k]: - case2 += 1 - memo_arr[i][j] = min(case1, case2) - - return memo_arr[i][j] - - -t = inp() -for _ in range(t): - a = insr() - b = insr() - c = insr() - - i = 0 - j = 0 - - k = 0 - memo_arr = [[-1 for _ in range(len(b)+1)] for _ in range(len(a) + 1)] - print(count_changes(a, b, c, i, j, k, memo_arr)) - -",2 -Anandharsh275,2050E - Three Strings,c++17 ,298794352,298795528,"#include -#define int long long -using namespace std; -int helper(int index1,int index2,int index3,int n,int m,int k,string &a,string&b,string &c){ - if(index1==n&&index2==m){ - return 0; - } - int taken=INT_MAX; - int taken2=INT_MAX; - if(index1> a >> b >> c; -int n=a.size(); -int m=b.size(); -int k=c.size(); -int ans=helper(0,0,0,n,m,k,a,b,c); -cout << ans << endl; - } -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -int helper(int index1,int index2,int index3,int n,int m,int k,string &a,string&b,string &c,unordered_map&mp){ - if(index1==n&&index2==m){ - return 0; - } - int taken=INT_MAX; - int taken2=INT_MAX; - string temp=to_string(index1)+""*""+to_string(index2); - if(mp.find(temp)!=mp.end()){ - return mp[temp]; - } - if(index1> a >> b >> c; -int n=a.size(); -int m=b.size(); -int k=c.size(); -unordered_mapmp; -int ans=helper(0,0,0,n,m,k,a,b,c,mp); -cout << ans << endl; - } -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}",2 -Temptoto,2050E - Three Strings,c++17 ,297656584,297654939,"#include -#define int long long int -using namespace std; - -void solve(){ - - string a,b,c; - cin>>a>>b>>c; - - int l = a.size(), m = b.size(), n = c.size(); - vector> dp(l+2, vector(n+2, INT_MAX)); - - dp[0][0] = 0; - for(int i=1, j=0; i<=n ; i++){ - if(i<=m && b[i-1]!=c[i-1]) - j++; - dp[0][i] = j; - } - - for(int i=1 ; i<=l ; i++){ - for(int j=i ; j<=i+m ; j++){ - - int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0); - val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0)); - dp[i][j] = val; - - } - } - - // for(int i=0;i<=l;i++){ - // for(int j=0;j<=n;j++)cout<>t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long int -using namespace std; - -void solve(){ - - string a,b,c; - cin>>a>>b>>c; - - int l = a.size(), m = b.size(), n = c.size(); - vector> dp(l+2, vector(n+2, 99)); - - dp[0][0] = 0; - for(int i=0, j=0; i>t; - while(t--){ - solve(); - } - return 0; -}",1 -Abhi_Valani,2050E - Three Strings,java,295778859,295781348,"import java.io.*; -import java.lang.reflect.Array; -import java.util.*; - -public class MyClass { - public static void main(String[] args) { - FastScanner in = new FastScanner(); - PrintWriter out = new PrintWriter(System.out); - int t = in.nextInt(); - while (t-- > 0) - solve(in, out); - out.close(); - } - static long pow(long x,long n, long m) { - if(n==0) return 1; - else if(n%2==0) return pow((x*x)%m,n/2,m)%m; - else return (x*pow((x*x)%m,n/2,m))%m; - } - - static int gcd(int a,int b) { - if(b==0) return a; - else return gcd(b,a%b); - } - - static int ans; - static void findSum(int[][] a,int i, int j, int sum) { - if(i>2 || j>2) return; - findSum(a,i,j+1, a[i][j]+sum); - findSum(a,i+1,j, a[i][j]+sum); - if(i==2 && j==2) ans=Math.min(a[i][j]+sum, ans); - } - - static char[] a,b,c; - static int findMaxMatching(int i, int j, int k){ - if(k>=c.length) return 0; - int possibilityA=0,possibilityB=0,possibilityC=0; - if(i>=a.length){ - int total=0; - for (int l = j; l < b.length; l++) { - if(b[l]==c[k]){ - total++; - } - k++; - } - return total; - } - if(j>=b.length){ - int total=0; - for (int l = i; l < a.length; l++) { - if(a[l]==c[k]){ - total++; - } - k++; - } - return total; - } - if(a[i]==c[k]){ - possibilityA = 1 + findMaxMatching(i+1,j,k+1); - } - if(b[j]==c[k]){ - possibilityB = 1 + findMaxMatching(i,j+1,k+1); - } - return Math.max(possibilityA, Math.max(possibilityB, Math.max(findMaxMatching(i,j+1,k+1), findMaxMatching(i+1,j,k+1)))); - } - static void solve(FastScanner in,PrintWriter out) { - a=in.next().toCharArray(); - b=in.next().toCharArray(); - c=in.next().toCharArray(); - int max = findMaxMatching(0,0,0); - out.println(c.length-max); - } - - static class pair, V extends Comparable> implements Comparable> { - public U x; - public V y; - - public pair(U x, V y) { - this.x = x; - this.y = y; - } - - public int compareTo(pair other) { - int i = other.y.compareTo(y); - if (i != 0) return i; - return other.x.compareTo(x); - } - - public String toString() { - return x.toString() + "" "" + y.toString(); - } - - public boolean equals(Object obj) { - if (this.getClass() != obj.getClass()) return false; - pair other = (pair) obj; - return x.equals(other.x) && y.equals(other.y); - } - - public int hashCode() { - return 31 * x.hashCode() + y.hashCode(); - } - - } - - static void sort(int[] a) { - ArrayList l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l); - for (int i=0; i l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l,Collections.reverseOrder()); - for (int i=0; i 0) - solve(in, out); - out.close(); - } - static long pow(long x,long n, long m) { - if(n==0) return 1; - else if(n%2==0) return pow((x*x)%m,n/2,m)%m; - else return (x*pow((x*x)%m,n/2,m))%m; - } - - static int gcd(int a,int b) { - if(b==0) return a; - else return gcd(b,a%b); - } - - static int ans; - static void findSum(int[][] a,int i, int j, int sum) { - if(i>2 || j>2) return; - findSum(a,i,j+1, a[i][j]+sum); - findSum(a,i+1,j, a[i][j]+sum); - if(i==2 && j==2) ans=Math.min(a[i][j]+sum, ans); - } - - static char[] a,b,c; - static int A[][]; - static int findMaxMatching(int i, int j, int k){ - if(i>=a.length){ - int total=0; - for (int l = j; l < b.length; l++) { - if(b[l]==c[k]){ - total++; - } - k++; - } - return total; - } - if(j>=b.length){ - int total=0; - for (int l = i; l < a.length; l++) { - if(a[l]==c[k]){ - total++; - } - k++; - } - return total; - } - if(A[i][j]>0) return A[i][j]; - int possibilityA = findMaxMatching(i+1,j,k+1); - if(a[i]==c[k]){ - possibilityA++; - } - int possibilityB = findMaxMatching(i,j+1,k+1); - if(b[j]==c[k]){ - possibilityB++; - } - A[i][j] = Math.max(possibilityA, possibilityB); - return A[i][j]; - } - static void solve(FastScanner in,PrintWriter out) { - a=in.next().toCharArray(); - b=in.next().toCharArray(); - c=in.next().toCharArray(); - A=new int[a.length][b.length]; - int max = findMaxMatching(0,0,0); - out.println(c.length-max); - } - - static class pair, V extends Comparable> implements Comparable> { - public U x; - public V y; - - public pair(U x, V y) { - this.x = x; - this.y = y; - } - - public int compareTo(pair other) { - int i = other.y.compareTo(y); - if (i != 0) return i; - return other.x.compareTo(x); - } - - public String toString() { - return x.toString() + "" "" + y.toString(); - } - - public boolean equals(Object obj) { - if (this.getClass() != obj.getClass()) return false; - pair other = (pair) obj; - return x.equals(other.x) && y.equals(other.y); - } - - public int hashCode() { - return 31 * x.hashCode() + y.hashCode(); - } - - } - - static void sort(int[] a) { - ArrayList l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l); - for (int i=0; i l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l,Collections.reverseOrder()); - for (int i=0; i= len(c): - continue - if i > 0 and a[i - 1] == c[c_index]: - dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1) - if j > 0 and b[j - 1] == c[c_index]: - dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1) - max_matched = dp[n][m] - changes_needed = (n + m) - max_matched - results.append(changes_needed) - return results -t = 7 -test_cases = [ - (""a"", ""b"", ""cb""), - (""ab"", ""cd"", ""acbd""), - (""ab"", ""ba"", ""aabb""), - (""xxx"", ""yyy"", ""xyxyxy""), - (""a"", ""bcd"", ""decf""), - (""codes"", ""horse"", ""codeforces""), - (""egg"", ""annie"", ""egaegaeg"") -] -outputs = min_changes_needed(t, test_cases) -for output in outputs: - print(output)","def min_changes(a, b, c): - n, m = len(a), len(b) - dp = [[float('inf')] * (m + 1) for _ in range(n + 1)] - dp[0][0] = 0 - - for i in range(n + 1): - for j in range(m + 1): - if i > 0: - dp[i][j] = min(dp[i][j], dp[i-1][j] + (a[i-1] != c[i + j - 1])) - if j > 0: - dp[i][j] = min(dp[i][j], dp[i][j-1] + (b[j-1] != c[i + j - 1])) - - return dp[n][m] - -t = int(input()) -for _ in range(t): - a = input().strip() - b = input().strip() - c = input().strip() - print(min_changes(a, b, c)) -",2 -iamaroy,2050E - Three Strings,c++17 ,298131817,295337809,"#include -using namespace std; -#define ll long long -#define pb push_back -#define csb_int __builtin_popcount -#define csb_ll __builtin_popcountll -#define all(x) x.begin(),x.end() -ll f(ll i,ll j,string&a,string&b,string&c,vector>&dp){ - if(i+j==c.size()-1)return 0; - if(dp[i][j]!=-1)return dp[i][j]; - ll op=c.size(); - if(i+1 < a.size()){ - if(a[i+1]==c[i+1+j]){ - op=min(op,f(i+1,j,a,b,c,dp)); - } - if(a[i+1]!=c[i+1+j]){ - op=min(op,1+f(i+1,j,a,b,c,dp)); - } - } - if(j+1 < b.size()){ - if(b[j+1]==c[i+j+1]){ - op=min(op,f(i,j+1,a,b,c,dp)); - } - if(b[j+1]!=c[i+j+1]){ - op=min(op,1+f(i,j+1,a,b,c,dp)); - } - } - return dp[i][j]=op; -} -void ans(){ - string a,b,c; - cin>>a>>b>>c; - string a1="" ""; - a1+=a; - string b1="" ""; - b1+=b; - string c1="" ""; - c1+=c; - ll n=a1.size(),m=b1.size(); - vector>dp(n,vector(m,-1)); - cout<>t; -//ios_base::sync_with_stdio(false); -//cin.tie(NULL);cout.tie(NULL); -while(t--){ -ans(); -} -return 0; -}","#include -using namespace std; -#define ll long long -#define pb push_back -#define csb_int __builtin_popcount -#define csb_ll __builtin_popcountll -#define all(x) x.begin(),x.end() -ll f(ll i,ll j,ll k,string&a,string&b,string&c,vector>>&dp){ - if(k==c.size())return 0; - if(dp[i][j][k]!=-1)return dp[i][j][k]; - ll op=c.size(); - if(i>a>>b>>c; - ll l=a.size(); - ll n=b.size(); - ll m=c.size(); - vector>>dp(l+1,vector>(n+1,vector(m+1,0))); - for(ll i=l;i>=0;i--){ - for(ll j=n;j>=0;j--){ - for(ll k=m-1;k>=0;k--){ - ll op=c.size(); - if(i>t; -//ios_base::sync_with_stdio(false); -//cin.tie(NULL);cout.tie(NULL); -while(t--){ -ans(); -} -return 0; -}",1 -arshad739811,2050E - Three Strings,c++20 ,297179688,297179781,"#include -using namespace std; - - -// Credits to HealthyUG for the inspiration. -// Segment Tree with Point Updates and Range Queries -// Supports multiple Segment Trees with just a change in the Node and Update -// Very few changes required everytime - -template -struct SegTree { - vector tree; - vector arr; // type may change - int n; - int s; - SegTree(int a_len) { // change if type updated - vector a(a_len+5,0); - arr=a; - n = a_len+5; - s = 1; - while(s < 2 * n){ - s = s << 1; - } - tree.resize(s); - for(int i=0;i= query_index) - update(start, mid, 2 * index, query_index, u); - else - update(mid + 1, end, 2 * index + 1, query_index, u); - tree[index].merge(tree[2 * index], tree[2 * index + 1]); - } - Node query(int start, int end, int index, int left, int right) { // Never change this - if (start > right || end < left) - return Node(); - if (start >= left && end <= right) - return tree[index]; - int mid = (start + end) / 2; - Node l, r, ans; - l = query(start, mid, 2 * index, left, right); - r = query(mid + 1, end, 2 * index + 1, left, right); - ans.merge(l, r); - return ans; - } - void make_update(int index, int val) { // pass in as many parameters as required - Update new_update = Update(val); // may change - update(0, n - 1, 1, index, new_update); - } - Node make_query(int left, int right) { - return query(0, n - 1, 1, left, right); - } -}; - -struct Node1 { - long long val; // may change - Node1() { // Identity element - val = 0; // may change - } - Node1(long long p1) { // Actual Node - val = p1; // may change - } - void merge(Node1 &l, Node1 &r) { // Merge two child nodes - val = max(l.val , r.val); // may change - } -}; - -struct Update1 { - long long val; // may change - Update1(long long p1) { // Actual Update - val = p1; // may change - } - void apply(Node1 &a) { // apply update to given node - a.val = max(a.val,val); // may change - } -}; - - - - - -//Union Find Algorithm Almost O(1) for reasonable size N. O(log*N) to be precise -struct UnionFind { - int n; - vector rank; - vector parent; - // store other info as required - UnionFind(int n) { - rank.resize(n); - fill(rank.begin(), rank.end(), 0); - parent.resize(n); - for (int i = 0; i < n; i++) { - parent[i] = i; - } - } - int get(int a) { - return parent[a] = (parent[a] == a ? a : get(parent[a])); - } - void merge(int a, int b) { - a = get(a); - b = get(b); - if (a == b) { - return; - } - if (rank[a] == rank[b]) { - rank[a]++; - } - if (rank[a] > rank[b]) { - parent[b] = a; - } else { - parent[a] = b; - } - } -}; - -void ask(string s){ - cout<<1<<"" ""<>&dp){ - if(i==n && j==m){ - return 0; - } - if(dp[i][j]!=-1)return dp[i][j]; - if(i==n){ - return (b[j]!=c[i+j])+solve(a,b,c,i,j+1,n,m,dp); - } - if(j==m){ - return (a[i]!=c[i+j])+solve(a,b,c,i+1,j,n,m,dp); - } - - int takea=INT_MAX; - int takeb=INT_MAX; - takea=(a[i]!=c[i+j])+solve(a,b,c,i+1,j,n,m,dp); - takeb=(b[j]!=c[i+j])+solve(a,b,c,i,j+1,n,m,dp); - return dp[i][j]=min(takea,takeb); -} - -signed main(){ - // x^y = x + y - 2(x&y); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - vector> dp(a.length()+2,vector(b.length()+2,-1)); - int ans=solve(a,b,c,0,0,a.length(),b.length(),dp); - cout< -using namespace std; - - -// Credits to HealthyUG for the inspiration. -// Segment Tree with Point Updates and Range Queries -// Supports multiple Segment Trees with just a change in the Node and Update -// Very few changes required everytime - -template -struct SegTree { - vector tree; - vector arr; // type may change - int n; - int s; - SegTree(int a_len) { // change if type updated - vector a(a_len+5,0); - arr=a; - n = a_len+5; - s = 1; - while(s < 2 * n){ - s = s << 1; - } - tree.resize(s); - for(int i=0;i= query_index) - update(start, mid, 2 * index, query_index, u); - else - update(mid + 1, end, 2 * index + 1, query_index, u); - tree[index].merge(tree[2 * index], tree[2 * index + 1]); - } - Node query(int start, int end, int index, int left, int right) { // Never change this - if (start > right || end < left) - return Node(); - if (start >= left && end <= right) - return tree[index]; - int mid = (start + end) / 2; - Node l, r, ans; - l = query(start, mid, 2 * index, left, right); - r = query(mid + 1, end, 2 * index + 1, left, right); - ans.merge(l, r); - return ans; - } - void make_update(int index, int val) { // pass in as many parameters as required - Update new_update = Update(val); // may change - update(0, n - 1, 1, index, new_update); - } - Node make_query(int left, int right) { - return query(0, n - 1, 1, left, right); - } -}; - -struct Node1 { - long long val; // may change - Node1() { // Identity element - val = 0; // may change - } - Node1(long long p1) { // Actual Node - val = p1; // may change - } - void merge(Node1 &l, Node1 &r) { // Merge two child nodes - val = max(l.val , r.val); // may change - } -}; - -struct Update1 { - long long val; // may change - Update1(long long p1) { // Actual Update - val = p1; // may change - } - void apply(Node1 &a) { // apply update to given node - a.val = max(a.val,val); // may change - } -}; - - - - - -//Union Find Algorithm Almost O(1) for reasonable size N. O(log*N) to be precise -struct UnionFind { - int n; - vector rank; - vector parent; - // store other info as required - UnionFind(int n) { - rank.resize(n); - fill(rank.begin(), rank.end(), 0); - parent.resize(n); - for (int i = 0; i < n; i++) { - parent[i] = i; - } - } - int get(int a) { - return parent[a] = (parent[a] == a ? a : get(parent[a])); - } - void merge(int a, int b) { - a = get(a); - b = get(b); - if (a == b) { - return; - } - if (rank[a] == rank[b]) { - rank[a]++; - } - if (rank[a] > rank[b]) { - parent[b] = a; - } else { - parent[a] = b; - } - } -}; - -void ask(string s){ - cout<<1<<"" ""<>&dp){ - if(i==n && j==m){ - return 0; - } - if(dp[i][j]!=-1)return dp[i][j]; - if(i==n){ - return (b[j]!=c[i+j])+solve(a,b,c,i,j+1,n,m,dp); - } - if(j==m){ - return (a[i]!=c[i+j])+solve(a,b,c,i+1,j,n,m,dp); - } - - int takea=INT_MAX; - int takeb=INT_MAX; - takea=(a[i]!=c[i+j])+solve(a,b,c,i+1,j,n,m,dp); - takeb=(b[j]!=c[i+j])+solve(a,b,c,i,j+1,n,m,dp); - return dp[i][j]=min(takea,takeb); -} - -signed main(){ - // x^y = x + y - 2(x&y); - int t; - cin>>t; - while(t--){ - string a,b,c; - cin>>a>>b>>c; - vector> dp(a.length()+2,vector(b.length()+2,-1)); - int ans=solve(a,b,c,0,0,a.length(),b.length(),dp); - cout< -using namespace std; -typedef long long ll; -string a,b,c; -vector> dp; -int fnc(int i, int j) -{ - if(i>=a.length() && j >= b.length()) - { - return 0; - } - if(dp[i][j] != -1) - { - return dp[i][j]; - } - int x1 = 1e9; - int x2 = 1e9; - if(i < a.length()) - { - x1 = fnc(i+1,j) + (a[i] != c[i+j]); - } - if(j < b.length()) - { - x2 = fnc(i,j+1) + (b[j] != c[i+j]); - } - return dp[i][j] = min(x1,x2); -} -void solve() -{ - cin >> a >> b >> c; -vector> ddp(a.length()+1,vector (b.length()+1,-1)); -dp = ddp; - cout << fnc(0,0) << endl; -} -int32_t main(){ - int tt; - cin >> tt; - while(tt>0){ - solve(); - --tt; - } - - - //solve(); -}","#include -using namespace std; -typedef long long ll; -string a,b,c; -vector> dp(1e3+1,vector (1e3+1,-1)); -int fnc(int i, int j) -{ - if(i>=a.length() && j >= b.length()) - { - return 0; - } - if(dp[i][j] != -1) - { - return dp[i][j]; - } - int x1 = 1e9; - int x2 = 1e9; - if(i < a.length()) - { - x1 = fnc(i+1,j) + (a[i] != c[i+j]); - } - if(j < b.length()) - { - x2 = fnc(i,j+1) + (b[j] != c[i+j]); - } - return dp[i][j] = min(x1,x2); -} -void solve() -{ - cin >> a >> b >> c; -vector> ddp(1e3+1,vector (1e3+1,-1)); -dp = ddp; - cout << fnc(0,0) << endl; -} -int32_t main(){ - int tt; - cin >> tt; - while(tt>0){ - solve(); - --tt; - } - - - //solve(); -}",1 -soumojjalsen,2050E - Three Strings,c++23 ,296863608,296862242,"/* Coding the path to follow.... */ -#include -using namespace std; -#define ll long long -#define mod 1000000007 -#define gcd(m, n) __gcd(m,n) -#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) - -int f(int i, int j, int &m, int &n, string& a, string& b, string& c, vector>& dp){ - if(i == m && j == n) return 0; - - if(dp[i][j] != -1) return dp[i][j]; - - int minChanges = 1e9; - int k = i+j; - if(i < m){ - if(a[i] == c[k]) minChanges = min(minChanges, f(i+1, j, m, n, a, b, c, dp)); - else minChanges = min(minChanges, 1 + f(i+1, j, m, n, a, b, c, dp)); - } - if(j < n){ - if(b[j] == c[k]) minChanges = min(minChanges, f(i, j+1, m, n, a, b, c, dp)); - else minChanges = min(minChanges, 1 + f(i, j+1, m, n, a, b, c, dp)); - } - - return dp[i][j] = minChanges; -} - -void solve() -{ - string a, b, c; - cin >> a >> b >> c; - - int m = a.size(); - int n = b.size(); - int s = c.size(); - - // vector>> dp(m+1, vector>(n+1, vector(s+1, -1))); - vector> dp(m+1, vector(n+1, -1)); - - cout << f(0, 0, m, n, a, b, c, dp) << endl; -} -int main() { - ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - - ll test=1; - cin>>test; - while(test--) - { - solve(); - } - return 0; -} -","/* Coding the path to follow.... */ -#include -using namespace std; -#define ll long long -#define mod 1000000007 -#define gcd(m, n) __gcd(m,n) -#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) - -int f(int i, int j, int k, int &m, int &n, string& a, string& b, string& c, vector>>& dp){ - if(i == m && j == n) return 0; - - if(dp[i][j][k] != -1) return dp[i][j][k]; - - int minChanges = 1e9; - if(i < m){ - if(a[i] == c[k]) minChanges = min(minChanges, f(i+1, j, k+1, m, n, a, b, c, dp)); - else minChanges = min(minChanges, 1 + f(i+1, j, k+1, m, n, a, b, c, dp)); - } - if(j < n){ - if(b[j] == c[k]) minChanges = min(minChanges, f(i, j+1, k+1, m, n, a, b, c, dp)); - else minChanges = min(minChanges, 1 + f(i, j+1, k+1, m, n, a, b, c, dp)); - } - - return dp[i][j][k] = minChanges; -} - -void solve() -{ - string a, b, c; - cin >> a >> b >> c; - - int m = a.size(); - int n = b.size(); - int s = c.size(); - - vector>> dp(m+1, vector>(n+1, vector(s+1, -1))); - - cout << f(0, 0, 0, m, n, a, b, c, dp) << endl; -} -int main() { - ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - - ll test=1; - cin>>test; - while(test--) - { - solve(); - } - return 0; -} -",1 -Sabnaj_423,2050E - Three Strings,c++20 ,296578162,296578889,"#include -using namespace std; -#define ll long long -#define PB push_back -#define all(x) x.begin(), x.end() -#define fast ios::sync_with_stdio(false); cin.tie(0); -#define Q int tt; cin>>tt ; for(int qq=1; qq <= tt; qq++) -#define endl ""\n"" - -//PBDS start -#include -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update>//sudhu less dile uniqe element rakhbe ,,less_equal dile duplicate value rakhbe -new_data_set; -//it=s.find_by_order(k) return the iterator of k'th elemet , counting from 0(k'th index itertor) -//int cnt=s.oeder_of_key(k); return the number of elements strictly less than k - -//PBDS end - - -//Debug start -template ostream& operator<<(ostream& os, const pair& p) { return os << '(' << p.first << "", "" << p.second << ')'; } -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream& os, const T_container& v) { os << '{'; string sep; for (const T& x : v) os << sep << x, sep = "", ""; return os << '}'; } - -void dbg_out() { cerr << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#ifdef LOCAL -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) -#else -#define dbg(...) -#endif -//Debug End - - -const ll mod=998244353; -ll inf=1e18; - -long long big_mod(long long a,long long b,long long m)//[(a^b)%m] here b is very large number almost 1e9 -{ - if(b==0)return (1%m); - long long x=big_mod(a,b/2,m); - x=(x*x)%m; - if(b%2==1)x=(x*a)%m; - return x; -} - -vector>dp; - -int solve(int i,int j,string a, string b, string c) -{ - if(i>=a.size() && j>=b.size())return 0; - if(dp[i][j]!=-1)return dp[i][j]; - int ans,ans1=1e7, ans2=1e7; - if(i>a>>b>>c; - int n=a.size(),m=b.size(); - dp.assign(n+1,vector(m+1,-1)); - int ans= solve(0,0,a,b,c); - cout< -using namespace std; -#define ll long long -#define PB push_back -#define all(x) x.begin(), x.end() -#define fast ios::sync_with_stdio(false); cin.tie(0); -#define Q int tt; cin>>tt ; for(int qq=1; qq <= tt; qq++) -#define endl ""\n"" - -//PBDS start -#include -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update>//sudhu less dile uniqe element rakhbe ,,less_equal dile duplicate value rakhbe -new_data_set; -//it=s.find_by_order(k) return the iterator of k'th elemet , counting from 0(k'th index itertor) -//int cnt=s.oeder_of_key(k); return the number of elements strictly less than k - -//PBDS end - - -//Debug start -template ostream& operator<<(ostream& os, const pair& p) { return os << '(' << p.first << "", "" << p.second << ')'; } -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream& os, const T_container& v) { os << '{'; string sep; for (const T& x : v) os << sep << x, sep = "", ""; return os << '}'; } - -void dbg_out() { cerr << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#ifdef LOCAL -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) -#else -#define dbg(...) -#endif -//Debug End - - -const ll mod=998244353; -ll inf=1e18; - -long long big_mod(long long a,long long b,long long m)//[(a^b)%m] here b is very large number almost 1e9 -{ - if(b==0)return (1%m); - long long x=big_mod(a,b/2,m); - x=(x*x)%m; - if(b%2==1)x=(x*a)%m; - return x; -} - -vector>dp; - -int solve(int i,int j,string &a, string &b, string &c) -{ - if(i>=a.size() && j>=b.size())return 0; - if(dp[i][j]!=-1)return dp[i][j]; - int ans,ans1=1e7, ans2=1e7; - if(i>a>>b>>c; - int n=a.size(),m=b.size(); - dp.assign(n+1,vector(m+1,-1)); - int ans= solve(0,0,a,b,c); - cout< - -using namespace std; - -#define Fast_IO \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL); - -#define int long long int - -#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) - - - -/* *********** My code start here *********** */ - - - -int32_t main() - -{ - - Fast_IO - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - clock_t danger_close = clock(); - - - - int t; - - cin >> t; - - while (t--) - - { - - string a = """", b = """", c = """"; - - cin >> a >> b >> c; - - int x = a.size(), y = b.size(); - - int dp[x+2][y+2]; - - for(int i = 0; i <= x+1; i++) - - for(int j = 0; j <= y+1; j++) - - dp[i][j] = 0; - - for(int i = 1; i <= x; i++) - - { - - if(a[i-1] == c[i-1]) - - dp[i][0] = dp[i-1][0]; - - else - - dp[i][0] = dp[i-1][0] + 1; - - } - - for(int i = 1; i <= y; i++) - - { - - if(b[i-1] == c[i-1]) - - dp[0][i] = dp[0][i-1]; - - else - - dp[0][i] = dp[0][i-1] + 1; - - } - - for(int i = 1; i <= x; i++) - - { - - for(int j = 1; j <= y; j++) - - { - - int m1, m2; - - if(a[i-1] == c[i+j-1]) - - m1 = dp[i-1][j]; - - else - - m1 = dp[i-1][j] + 1; - - if(b[j-1] == c[i+j-1]) - - m2 = dp[i][j-1]; - - else - - m2 = dp[i][j-1] + 1; - - dp[i][j] = min(m1, m2); - - } - - } - - cout << dp[x][y] << endl; - - } - - debug(""Total Time: %.3f\n"", (double)(clock() - danger_close) / CLOCKS_PER_SEC); - - return 0; - -}","#include - -using namespace std; - -#define Fast_IO \ - - ios_base::sync_with_stdio(false); \ - - cin.tie(NULL); \ - - cout.tie(NULL); - -#define int long long int - -#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) - - - -/* *********** My code start here *********** */ - - - -int32_t main() - -{ - - Fast_IO - - - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - - clock_t danger_close = clock(); - - - - int t; - - cin >> t; - - while (t--) - - { - - string a = """", b = """", c = """"; - - cin >> a >> b >> c; - - c = "" "" + c; - - a = "" "" + a; - - b = "" "" + b; - - int x = a.size(), y = b.size(); - - int dp[x+2][y+2]; - - for(int i = 0; i <= x+1; i++) - - for(int j = 0; j <= y+1; j++) - - dp[i][j] = 0; - - for(int i = 1; i <= x; i++) - - { - - if(a[i] == c[i]) - - dp[i][0] = dp[i-1][0]; - - else - - dp[i][0] = dp[i-1][0] + 1; - - } - - for(int i = 1; i <= y; i++) - - { - - if(b[i] == c[i]) - - dp[0][i] = dp[0][i-1]; - - else - - dp[0][i] = dp[0][i-1] + 1; - - } - - for(int i = 1; i <= x; i++) - - { - - for(int j = 1; j <= y; j++) - - { - - int m1, m2; - - if(a[i] == c[i+j]) - - m1 = dp[i-1][j]; - - else - - m1 = dp[i-1][j] + 1; - - if(b[j] == c[i+j]) - - m2 = dp[i][j-1]; - - else - - m2 = dp[i][j-1] + 1; - - dp[i][j] = min(m1, m2); - - } - - } - - if(dp[x][y] > 0) - - dp[x][y]--; - - cout << dp[x][y] << endl; - - } - - debug(""Total Time: %.3f\n"", (double)(clock() - danger_close) / CLOCKS_PER_SEC); - - return 0; - -}",1 -Ram_Ratan,2050E - Three Strings,c++17 ,297017386,297015456,"#include -using namespace std; - -int diffCount(string a, string b) -{ - int count = 0; - for (int i = 0; i < a.size(); i++) - { - if (a[i] != b[i]) - count++; - } - return count; -} - -int dp_helper(string &a, string &b, string &c, int i, int j, int k, vector> &arr) -{ - if(arr[i][j]!= -1){ - return arr[i][j]; - } - if (i >= a.size() && j >= b.size()) - { - return 0; - } - if (i >= a.size()) - { - return arr[i][j] = diffCount(b.substr(j, b.size() - j), c.substr(k, c.size() - k)); - } - else if (j >= b.size()) - { - return arr[i][j] = diffCount(a.substr(i, a.size() - i), c.substr(k, c.size() - k)); - } - if(a[i]==c[k] && b[j] == c[k]){ - return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr)); - } - - else if (a[i] == c[k]) - { - return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), 1 + dp_helper(a,b,c,i,j+1,k+1, arr)); - } - else if (b[j] == c[k]) - { - return arr[i][j] = min(dp_helper(a, b, c, i, j + 1, k + 1, arr), 1 + dp_helper(a, b, c, i + 1, j, k + 1, arr)); - } - else - { - return arr[i][j] = 1 + min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr)); - } -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - - string a, b, c; - cin >> a >> b >> c; - vector> arr(1002, vector (1002, -1)); - cout << dp_helper(a, b, c, 0, 0, 0, arr)< -using namespace std; - -int diffCount(string a, string b) -{ - int count = 0; - for (int i = 0; i < a.size(); i++) - { - if (a[i] != b[i]) - count++; - } - return count; -} - -int dp_helper(string a, string b, string c, int i, int j, int k, vector> &arr) -{ - if(arr[i][j]!= -1){ - return arr[i][j]; - } - if (i >= a.size() && j >= b.size()) - { - return 0; - } - if (i >= a.size()) - { - return arr[i][j] = diffCount(b.substr(j, b.size() - j), c.substr(k, c.size() - k)); - } - else if (j >= b.size()) - { - return arr[i][j] = diffCount(a.substr(i, a.size() - i), c.substr(k, c.size() - k)); - } - if(a[i]==c[k] && b[j] == c[k]){ - return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr)); - } - - else if (a[i] == c[k]) - { - return arr[i][j] = min(dp_helper(a, b, c, i + 1, j, k + 1, arr), 1 + dp_helper(a,b,c,i,j+1,k+1, arr)); - } - else if (b[j] == c[k]) - { - return arr[i][j] = min(dp_helper(a, b, c, i, j + 1, k + 1, arr), 1 + dp_helper(a, b, c, i + 1, j, k + 1, arr)); - } - else - { - return arr[i][j] = 1 + min(dp_helper(a, b, c, i + 1, j, k + 1, arr), dp_helper(a, b, c, i, j + 1, k + 1, arr)); - } -} - -int main() -{ - int t; - cin >> t; - while (t--) - { - - string a, b, c; - cin >> a >> b >> c; - vector> arr(1000, vector (1000, -1)); - cout << dp_helper(a, b, c, 0, 0, 0, arr)< -#include -#include -#include - -using namespace std; - -int minChanges(const string& a, const string& b, const string& c) { - int n = a.size(); - int m = b.size(); - vector> dp(n + 1, vector(m + 1, 0)); - - dp[0][0] = 0; - - for (int i = 0; i < n; i++) { - dp[i + 1][0] = dp[i][0] + (a[i] != c[i]); - } - - for (int j = 0; j < m; j++) { - dp[0][j + 1] = dp[0][j] + (b[j] != c[j]); - } - - for (int i = 1; i <= n; i++) { - for (int j = 1; j <= m; j++) { - dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]), - dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - - return dp[n][m]; -} - -int main() { - int t; - cin >> t; - while (t--) { - string a, b, c; - cin >> a >> b >> c; - cout << minChanges(a, b, c) << endl; - } - return 0; -}","#include -#include -#include -#include - -using namespace std; - -int minChanges(const string& a, const string& b, const string& c) { - int n = a.size(); - int m = b.size(); - vector> dp(n + 1, vector(m + 1, 0)); - - for (int i = 0; i <= n; ++i) { - for (int j = 0; j <= m; ++j) { - int k = i + j; - if (k == c.size()) break; - - if (i < n) { - dp[i + 1][j] = dp[i][j] + (a[i] != c[k] ? 1 : 0); - } - - if (j < m) { - dp[i][j + 1] = dp[i][j] + (b[j] != c[k] ? 1 : 0); - } - } - } - - return dp[n][m]; -} - -int main() { - int t; - cin >> t; - while (t--) { - string a, b, c; - cin >> a >> b >> c; - cout << minChanges(a, b, c) << endl; - } - return 0; -}",1 -tillGM,2050E - Three Strings,c++17 ,297156728,297156524,"#include -using namespace std; - -int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector> &dp) { - if(aIndex + bIndex >= c.size()) - return 0; - - if(dp[aIndex][bIndex] != -1) - return dp[aIndex][bIndex]; - - int cIndex = aIndex + bIndex; - int mn = c.size() - cIndex + 1; - if(aIndex < a.size()) { - if(a[aIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp)); - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1); - } - if(bIndex < b.size()) { - if(b[bIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp)); - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1); - } - return dp[aIndex][bIndex] = mn; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0);cout.tie(0); - int t; - cin >> t; - while(t--) { - string a, b, c; - cin >> a >> b >> c; - - vector> dp(a.size() + 1, vector (b.size() + 1, -1)); - cout << minChange(0, 0, a, b, c, dp) << endl; - } -}","#include -using namespace std; - -int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector> &dp) { - if(aIndex + bIndex >= c.size()) - return 0; - - if(dp[aIndex][bIndex] != -1) - dp[aIndex][bIndex]; - - int cIndex = aIndex + bIndex; - int mn = c.size() - cIndex + 1; - if(aIndex < a.size()) { - if(a[aIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp)); - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1); - } - if(bIndex < b.size()) { - if(b[bIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp)); - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1); - } - return dp[aIndex][bIndex] = mn; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0);cout.tie(0); - int t; - cin >> t; - while(t--) { - string a, b, c; - cin >> a >> b >> c; - - vector> dp(a.size() + 1, vector (b.size() + 1, -1)); - cout << minChange(0, 0, a, b, c, dp) << endl; - } -}",1 -rajbir_04,2050E - Three Strings,c++17 ,298807903,298804163,"#include -using namespace std; - -#define ll long long -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(), (x).end() -#define pii pair -#define vi vector -#define vll vector -#define vpii vector -#define F first -#define S second -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -const int MOD = 1e9 + 7; -const int INF = 1e9; - -int solve(string &a,string &b,string &c,int i,int j,vector &dp){ - - // if(k>=c.size()){ - // return 0; - // } - - int k = i+j; - - if (i == a.size() && j == b.size()) - return 0; - - if(dp[i][j]!=-1){ - return dp[i][j]; - } - - int left = INT_MAX; - int right = INT_MAX; - - if(i>a>>b>>c; - - vector> dp(a.size()+1,vector (b.size()+1,-1)); - - cout<> t; - while (t--) { - solve(); - } - - return 0; -}","#include -using namespace std; - -#define ll long long -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(), (x).end() -#define pii pair -#define vi vector -#define vll vector -#define vpii vector -#define F first -#define S second -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -const int MOD = 1e9 + 7; -const int INF = 1e9; - -int solve(string a,string b,string c,int i,int j,int k,vector> &dp){ - - if(k>=c.size()){ - return 0; - } - - if(dp[i][j][k]!=-1){ - return dp[i][j][k]; - } - - int left = INT_MAX; - int right = INT_MAX; - - if(i>a>>b>>c; - - vector> dp(a.size()+1,vector (b.size()+1,vector (c.size()+1,-1))); - - cout<> t; - while (t--) { - solve(); - } - - return 0; -}",1 -eu_caue,2050E - Three Strings,c++20 ,295469744,295469781,"#include -using namespace std; -typedef long long ll; -typedef pair pii; -typedef tuple tii; -const int mod = 1e9+7; -const int maxn = 1005; -const ll inf = 0x3f3f3f3f3f3f3f3f; - -int dp[maxn][maxn]; - - -void solve(){ - string a, b, c; cin >> a >> b >> c; - int n = a.size(), m = b.size(); - for(int i = n; ~i; i--){ - for(int j = m; ~j; j--){ - if(i == n and j == m) dp[i][j] = 0; - else if (i == n) dp[i][j] = dp[i][j+1]+(c[i+j]!=b[j]); - else if (j == m) dp[i][j] = dp[i][j+1]+(c[i+j]!=a[i]); - else dp[i][j] = min(dp[i+1][j]+(c[i+j]!=a[i]),dp[i][j+1]+(c[i+j]!=b[j])); - } - } - cout << dp[0][0] << endl; -} - -int main(){ - ios_base::sync_with_stdio(false);cin.tie(NULL); - int t; cin >> t; - while(t--) - solve(); - return 0; -} - -// ""Pensa simples, joga leve, coda fofo.""","#include -using namespace std; -typedef long long ll; -typedef pair pii; -typedef tuple tii; -const int mod = 1e9+7; -const int maxn = 1005; -const ll inf = 0x3f3f3f3f3f3f3f3f; - -int dp[maxn][maxn]; - -void solve(){ - string a, b, c; cin >> a >> b >> c; - int n = a.size(), m = b.size(); - for(int i = n; ~i; i--){ - for(int j = m; ~j; j--){ - if(i == n and j == m) dp[i][j] = 0; - else if (i == n) dp[i][j] = dp[i][j+1]+(c[i+j]!=b[j]); - else if (j == m) dp[i][j] = dp[i+1][j]+(c[i+j]!=a[i]); - else dp[i][j] = min(dp[i+1][j]+(c[i+j]!=a[i]),dp[i][j+1]+(c[i+j]!=b[j])); - } - } - cout << dp[0][0] << endl; -} - -int main(){ - ios_base::sync_with_stdio(false);cin.tie(NULL); - int t; cin >> t; - while(t--) - solve(); - return 0; -} - -// ""Pensa simples, joga leve, coda fofo.""",2 -Tanishq_v010,2050E - Three Strings,c++23 ,297392762,297390685,"#include -using namespace std; - -#define int long long -#define inf 1e9 - -signed main() { - int t; - cin >> t; - while(t--) { - string a, b, c; - cin >> a >> b >> c; - int lenA = a.size(), lenB = b.size(); - vector> dp(lenA + 1, vector(lenB + 1, inf)); - dp[0][0] = 0; - for (int i = 0; i <= lenA; ++i) { - for (int j = 0; j <= lenB; ++j) { - if (i < lenA) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (a[i] != c[i + j])); - if (j < lenB) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (b[j] != c[i + j])); - } - } - cout << dp[lenA][lenB] << endl; - } - return 0; -}","#include -using namespace std; - -#define int long long - -signed main(){ - int t; - cin >> t; - while(t--) { - vector fq(26, 0); - string a, b, c; - cin >> a >> b >> c; - for(const auto& it : a) fq[it - 'a']++; - for(const auto& it : b) fq[it - 'a']++; - for(const auto& it : c) fq[it - 'a']--; - int sum = 0; - for(const auto& it : fq) sum += max(it, 0LL); - cout << sum << endl; - } - return 0; -}",1 -KalbiatAman,2050E - Three Strings,c++20 ,305354745,305358999,"#include - - - -using namespace std; - - - -#define ll long long - -#define ld long double - -#define mp make_pair - -#define F first - -#define S second - -#define pb push_back - -#define upb upper_bound - -#define lwb lower_bound - - - -const int maxn = (1 << 10); - -int n, m, dp[maxn][maxn]; - -string a, b, c; - - - -void clear_array() { - - for (int i = 0; i < 3 + n; i++) { - - fill(dp[i], dp[i] + 3 + m, 0); - - } - - a.clear(), b.clear(), c.clear(); - - n = m = 0; - -} - - - -void solve() { - - cin >> a >> b >> c; - - n = (int)(a.size()); - - m = (int)(b.size()); - - a = ""#"" + a; b = ""#"" + b; c = ""#"" + c; - - for (int i = 0; i <= n; i++) { - - for (int j = 0; j <= m; j++) { - - dp[i][j] = n + n + m + m; - - } - - } - - dp[0][0] = 0; - - for (int i = 1; i <= n; i++) { - - dp[i][0] = dp[i - 1][0]; - - if (a[i] != c[i]) dp[i][0]++; - - } - - for (int i = 1; i <= m; i++) { - - dp[0][i] = dp[0][i - 1]; - - if (b[i] != c[i]) dp[0][i]++; - - } - - for (int i = 1; i <= n; i++) { - - for (int j = 1; j <= m; j++) { - - int from_a = (a[i] == c[i + j] ? dp[i - 1][j] : dp[i - 1][j] + 1); - - int from_b = (b[j] == c[i + j] ? dp[i][j - 1] : dp[i][j - 1] + 1); - - dp[i][j] = min(from_a, from_b); - - } - - } - - cout << dp[n][m] << ""\n""; - - clear_array(); - -} - - - -void boost() { - - cin.tie(0), cout.tie(0); - - ios_base :: sync_with_stdio(false); - -} - - - -int main() { - - boost(); - - int TT; - - cin >> TT; - - while (TT--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -vector>dp; - -int fxn(string a,string b,string c,int i,int j) - -{ - - int n=c.length(); - - - - if(i+j==n)return 0; - - //if(i==a.length()||j==b.length())return 1e9; - - if(dp[i][j]!=-1)return dp[i][j]; - - int a1=1e9,b1=1e9; - - if(i>t; - - - - while(t--){ - - string a,b,c; - - cin>>a>>b>>c; - - //memset(dp,-1,sizeof(dp)); - - dp=vector>(a.length()+1,vector(b.length(),-1)); - - int z=fxn(a,b,c,0,0); - - - - cout< - - - -using namespace std; - - - -#define forn(i, n) for (int i = 0; i < int(n); i++) - -#define ll long long - -#define pii pair - -ll INF = 10000000000000000; - -ll MOD = 1000000007; - -const int N = 1 << 17; - -const int inf = 100000000; - - - -string a, b, c; - -int as, bs, cs; - -int dp[1002][1002]; - - - -int solve(int charc, int chara) { - - if(chara < 0 or chara > charc) return inf; - - if(charc == 0) return 0; - - - - - - if(dp[charc][chara] != -1) return dp[charc][chara]; - - int ans = 0; - - int charb = charc - chara; - - int x, y; - - - - - - - - if(a[chara - 1] == c[charc - 1]) - - x = solve(charc - 1, chara - 1); - - else - - x = 1 + solve(charc - 1, chara - 1); - - - - - - if(b[charb - 1] == c[charc - 1]) - - y = solve(charc - 1, chara); - - else - - y = 1 + solve(charc - 1, chara); - - - - - - ans = min(x, y); - - - - return dp[charc][chara] = ans; - -} - - - - - - - - - -void solve() { - - int i, j; - - cin >> a >> b >> c; - - as = a.size(), bs = b.size(), cs = c.size(); - - - - for(i = 0; i <= cs; i++) for(j = 0; j <= as; j++) dp[i][j] = -1; - - - - cout << solve(cs, as) << endl; - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int main() { - - #ifdef LOCAL - - freopen(""input.txt"", ""r"", stdin); - - #endif - - std::ios::sync_with_stdio(false); - - // doo(); return 0; - - - - ll t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - - - - - -/* - - - -1 1 0 - -2 4 2 - -3 9 6 - - - -*/","#include - - - -using namespace std; - - - -#define forn(i, n) for (int i = 0; i < int(n); i++) - -#define ll long long - -#define pii pair - -ll INF = 10000000000000000; - -ll MOD = 1000000007; - -const int N = 1 << 17; - -const int inf = 100000000; - - - -string a, b, c; - -int as, bs, cs; - -int dp[2002][2002]; - - - -int solve(int charc, int chara) { - - if(chara < 0 or chara > charc) return inf; - - if(charc == 0) return 0; - - - - - - if(dp[charc][chara] != -1) return dp[charc][chara]; - - int ans = 0; - - int charb = charc - chara; - - int x, y; - - - - - - - - if(a[chara - 1] == c[charc - 1]) - - x = solve(charc - 1, chara - 1); - - else - - x = 1 + solve(charc - 1, chara - 1); - - - - - - if(b[charb - 1] == c[charc - 1]) - - y = solve(charc - 1, chara); - - else - - y = 1 + solve(charc - 1, chara); - - - - - - ans = min(x, y); - - - - return dp[charc][chara] = ans; - -} - - - - - - - - - -void solve() { - - int i, j; - - cin >> a >> b >> c; - - as = a.size(), bs = b.size(), cs = c.size(); - - - - for(i = 0; i <= cs; i++) for(j = 0; j <= as; j++) dp[i][j] = -1; - - - - cout << solve(cs, as) << endl; - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int main() { - - #ifdef LOCAL - - freopen(""input.txt"", ""r"", stdin); - - #endif - - std::ios::sync_with_stdio(false); - - // doo(); return 0; - - - - ll t = 1; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - - - - - -/* - - - -1 1 0 - -2 4 2 - -3 9 6 - - - -*/",2 -sobad,2050E - Three Strings,c++17 ,297409374,297247944,"#include -#include -#include -using namespace std; - - - - -void solve() { - string a, b, c; - cin >> a >> b >> c; - int na = a.size(); - int nb = b.size(); - vector> dp(na + 1, vector(nb + 1, na + nb + 1)); - for (int i = 0; i <= a.size();i++) { - for (int j = 0; j <= b.size();j++) { - dp[i][j] = 1e7; - } - } - dp[0][0] = 0; - for (int i = 0; i <= a.size();i++) { - for (int j = 0; j <= b.size();j++) { - if (i == 0 && j == 0) { - dp[i][j] = 0; - } - else { - if (i == 0) { - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1])); - } - else if (j == 0) { - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1])); - } - else { - dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1]))); - } - } - } - } - cout << dp[a.size()][b.size()] << '\n'; -} -int main() { - int te; - cin >> te; - while (te--) { - solve(); - } -}","#include -#include -using namespace std; - - - - -void solve() { - char* a = new char[2005]; - char* b = new char[2005]; - char* c = new char[2005]; - cin.getline(a, 2000, '\n'); - cin.getline(b, 2000, '\n'); - cin.getline(c, 2000, '\n'); - int** dp = new int*[strlen(a) + 1]; - for (int i = 0; i <= strlen(a);i++) { - dp[i] = new int[strlen(b) + 1]; - } - for (int i = 0; i <= strlen(a);i++) { - for (int j = 0; j <= strlen(b);j++) { - dp[i][j] = 1e7; - } - } - dp[0][0] = 0; - for (int i = 0; i <= strlen(a);i++) { - for (int j = 0; j <= strlen(b);j++) { - if (i == 0 && j == 0) { - dp[i][j] = 0; - } - else { - if (i == 0) { - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1])); - } - else if (j == 0) { - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1])); - } - else { - dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1]))); - } - } - } - } - cout << dp[strlen(a)][strlen(b)] << '\n'; - for (int i = 0; i <= strlen(a);i++) { - delete[] dp[i]; - dp[i] = NULL; - } - delete[] dp; - dp = NULL; - delete[] a; - a = NULL; - delete[] b; - b = NULL; - delete[] c; - c = NULL; -} -int main() { - int te; - cin >> te; - cin.ignore(); - while (te--) { - solve(); - } -}",1 -sankalp_shashi,2050E - Three Strings,c++17 ,297322213,297281581,"#include -using namespace std; -#define ll long long - -// int dp[1001][1001]; -// int valid[1001][1001]; -// int t; - -// int minChangedChars(string a, string b, string c) -// { -// int i = a.size(), j = b.size(); -// if (valid[i][j] == t) -// return dp[i][j]; -// valid[i][j] = t; -// int acnt = 0, bcnt = 0; -// if (a.size() == 0) -// { -// for (int i = 0; i < c.size(); i++) -// { -// if (c[i] != b[i]) -// bcnt++; -// } -// return dp[i][j] = bcnt; -// } - -// if (b.size() == 0) -// { -// for (int i = 0; i < c.size(); i++) -// { -// if (c[i] != a[i]) -// acnt++; -// } -// return dp[i][j] = acnt; -// } -// acnt = minChangedChars(a.substr(1), b, c.substr(1)); -// if (a[0] != c[0]) -// acnt++; -// bcnt = minChangedChars(a, b.substr(1), c.substr(1)); -// if (b[0] != c[0]) -// bcnt++; -// return dp[i][j] = min(acnt, bcnt); -// } - -// dp[i][j] = min(dp[i - 1][j] + a != c, dp[i][j - 1] + b != c) - -int main() -{ - int t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - vector> dp(a.size() + 1, vector(b.size() + 1, INT_MAX)); - dp[0][0] = 0; - for (int i = 0; i <= a.size(); i++) - { - for (int j = 0; j <= b.size(); j++) - { - if (i > 0) - dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[i + j - 1])); - if (j > 0) - dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[i + j - 1])); - } - } - cout << dp[a.size()][b.size()] << endl; - // cout << minChangedChars(a, b, c) << endl; - } - return 0; -}","#include -using namespace std; -#define ll long long - -int dp[1001][1001]; - -int minChangedChars(string a, string b, string c) -{ - int i = a.size(), j = b.size(); - if (dp[i][j] != -1) - return dp[i][j]; - int acnt = 0, bcnt = 0; - if (a.size() == 0) - { - for (int i = 0; i < c.size(); i++) - { - if (c[i] != b[i]) - bcnt++; - } - return dp[i][j] = bcnt; - } - - if (b.size() == 0) - { - for (int i = 0; i < c.size(); i++) - { - if (c[i] != a[i]) - acnt++; - } - return dp[i][j] = acnt; - } - acnt = minChangedChars(a.substr(1), b, c.substr(1)); - if (a[0] != c[0]) - acnt++; - bcnt = minChangedChars(a, b.substr(1), c.substr(1)); - if (b[0] != c[0]) - bcnt++; - return dp[i][j] = min(acnt, bcnt); -} - -int main() -{ - ll t; - cin >> t; - while (t--) - { - string a, b, c; - cin >> a >> b >> c; - for (int i = 0; i <= a.size(); i++) - for (int j = 0; j <= b.size(); j++) - dp[i][j] = -1; - cout << minChangedChars(a, b, c) << endl; - } - return 0; -}",1 -Ak.24,2050E - Three Strings,python,295062374,295058068,"for _ in[1]*int(input()): - s,t,u=input(),input(),input();n,m=len(s),len(t) - inf=10**9 - d=[[inf]*(m+1)for _ in range(n+1)] - d[0][0]=0 - for i in range(n+1): - for j in range(m+1): - if i==j==0:continue - k=i+j-1 - if k>=len(u):continue - if i>0: - c=d[i-1][j]+(s[i-1]!=u[k]) - if c0: - c=d[i][j-1]+(t[j-1]!=u[k]) - if c= len(z): - return 1e9 - r = 1e9 - if i > 0: - r = min(r, f(i - 1, j) + (x[i - 1] != z[k])) - if j > 0: - r = min(r, f(i, j - 1) + (y[j - 1] != z[k])) - return r - print(int(f(n, m)))",1 -Meet_U_24,2050E - Three Strings,c++17 ,304785969,304786034,"//Jai Shree Ram - -//Author : Meet Upadhyay - -#include - -#include - -#define lli long long int - -const lli MOD=1e9+7 ; - -const lli MOD2= 998244353; - -const lli inf=1e18; - -bool sortbysec(const std::pair &a,const std::pair &b) { return (a.second < b.second); } - -lli power(lli n,lli a){ lli res=1; while(a){ if(a%2) res*=n,a--; else n*=n,a/=2;} return res;} - -lli modpower(lli n,lli a,lli p){ lli res=1; while(a){ if(a%2) res= ((res*n)%p) ,a--; else n=((n*n)%p),a/=2;} return res;} - -lli fastprime(lli a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(lli i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -lli mod_mul_inverse(lli a,lli b) {return modpower(a , b-2, b);} - -using namespace std; - - - -template - -struct ModInt { - -using uint = unsigned int; - -using ull = unsigned long long; - -using M = ModInt; - -uint v; - -ModInt(lli _v = 0) { set_norm(_v % MOD + MOD); } - -M& set_norm(uint _v) { //[0, MOD * 2)->[0, MOD) - -v = (_v < MOD) ? _v : _v - MOD; - -return *this; - -} - -explicit operator bool() const { return v != 0; } - -M operator+(const M& a) const { return M().set_norm(v + a.v); } - -M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); } - -M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); } - -M operator/(const M& a) const { return *this * a.inv(); } - -M& operator+=(const M& a) { return *this = *this + a; } - -M& operator-=(const M& a) { return *this = *this - a; } - -M& operator*=(const M& a) { return *this = *this * a; } - -M& operator/=(const M& a) { return *this = *this / a; } - -M operator-() const { return M() - *this; } - -M& operator++(int) { return *this = *this + 1; } - -M& operator--(int) { return *this = *this - 1; } - -M pow(lli n) const { - -if (n < 0) return inv().pow(-n); - -M x = *this, res = 1; - -while (n) { - -if (n & 1) res *= x; - -x *= x; - -n >>= 1; - -} - -return res; - -} - -M inv() const { - -lli a = v, b = MOD, p = 1, q = 0, t; - -while (b != 0) { - -t = a / b; - -swap(a -= t * b, b); - -swap(p -= t * q, q); - -} - -return M(p); - -} - -bool operator==(const M& a) const { return v == a.v; } - -bool operator!=(const M& a) const { return v != a.v; } - -friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; } - -static uint get_mod() { return MOD; } - -}; - -; - -using Mint = ModInt<1000000007>; - -void solve() - -{ - - string a; - - cin>>a; - - string b; - - cin>>b; - - string c; - - cin>>c; - - lli n = a.size(); - - lli m = b.size(); - - vector>dp(n+5, vector(m+5,1e14)); - - dp[0][0] = 0; - - for(lli i=0;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}","//Jai Shree Ram - -//Author : Meet Upadhyay - -#include - -#include - -#define lli long long int - -const lli MOD=1e9+7 ; - -const lli MOD2= 998244353; - -const lli inf=1e18; - -bool sortbysec(const std::pair &a,const std::pair &b) { return (a.second < b.second); } - -lli power(lli n,lli a){ lli res=1; while(a){ if(a%2) res*=n,a--; else n*=n,a/=2;} return res;} - -lli modpower(lli n,lli a,lli p){ lli res=1; while(a){ if(a%2) res= ((res*n)%p) ,a--; else n=((n*n)%p),a/=2;} return res;} - -lli fastprime(lli a){ if (a != 2 && a % 2 == 0 || a < 2) return 0; for(lli i = 3; i * i <= a; i += 2) if(a % i == 0) return 0; return 1;} - -lli mod_mul_inverse(lli a,lli b) {return modpower(a , b-2, b);} - -using namespace std; - - - -template - -struct ModInt { - -using uint = unsigned int; - -using ull = unsigned long long; - -using M = ModInt; - -uint v; - -ModInt(lli _v = 0) { set_norm(_v % MOD + MOD); } - -M& set_norm(uint _v) { //[0, MOD * 2)->[0, MOD) - -v = (_v < MOD) ? _v : _v - MOD; - -return *this; - -} - -explicit operator bool() const { return v != 0; } - -M operator+(const M& a) const { return M().set_norm(v + a.v); } - -M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); } - -M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); } - -M operator/(const M& a) const { return *this * a.inv(); } - -M& operator+=(const M& a) { return *this = *this + a; } - -M& operator-=(const M& a) { return *this = *this - a; } - -M& operator*=(const M& a) { return *this = *this * a; } - -M& operator/=(const M& a) { return *this = *this / a; } - -M operator-() const { return M() - *this; } - -M& operator++(int) { return *this = *this + 1; } - -M& operator--(int) { return *this = *this - 1; } - -M pow(lli n) const { - -if (n < 0) return inv().pow(-n); - -M x = *this, res = 1; - -while (n) { - -if (n & 1) res *= x; - -x *= x; - -n >>= 1; - -} - -return res; - -} - -M inv() const { - -lli a = v, b = MOD, p = 1, q = 0, t; - -while (b != 0) { - -t = a / b; - -swap(a -= t * b, b); - -swap(p -= t * q, q); - -} - -return M(p); - -} - -bool operator==(const M& a) const { return v == a.v; } - -bool operator!=(const M& a) const { return v != a.v; } - -friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; } - -static uint get_mod() { return MOD; } - -}; - -; - -using Mint = ModInt<1000000007>; - -void solve() - -{ - - string a; - - cin>>a; - - string b; - - cin>>b; - - string c; - - cin>>c; - - lli n = a.size(); - - lli m = b.size(); - - vector>dp(n+5, vector(m+5,1e14)); - - dp[0][0] = 0; - - for(lli i=0;i>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -}",2 -tillGM,2050E - Three Strings,c++17 ,297152127,297156728,"#include -using namespace std; - -int dp[1001][1001]; - -int minChange(int aIndex, int bIndex, string &a, string &b, string &c) { - if(aIndex + bIndex >= c.size()) - return 0; - - if(dp[aIndex][bIndex] != -1) - dp[aIndex][bIndex]; - - int cIndex = aIndex + bIndex; - int mn = c.size() - cIndex + 1; - if(aIndex < a.size()) { - if(a[aIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c)); - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c) + 1); - } - if(bIndex < b.size()) { - if(b[bIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c)); - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c) + 1); - } - return dp[aIndex][bIndex] = mn; -} - -int main() { - int t; - cin >> t; - while(t--) { - string a, b, c; - cin >> a >> b >> c; - - memset(dp, -1, sizeof dp); - cout << minChange(0, 0, a, b, c) << endl; - } -}","#include -using namespace std; - -int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector> &dp) { - if(aIndex + bIndex >= c.size()) - return 0; - - if(dp[aIndex][bIndex] != -1) - return dp[aIndex][bIndex]; - - int cIndex = aIndex + bIndex; - int mn = c.size() - cIndex + 1; - if(aIndex < a.size()) { - if(a[aIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp)); - mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1); - } - if(bIndex < b.size()) { - if(b[bIndex] == c[cIndex]) - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp)); - mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1); - } - return dp[aIndex][bIndex] = mn; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0);cout.tie(0); - int t; - cin >> t; - while(t--) { - string a, b, c; - cin >> a >> b >> c; - - vector> dp(a.size() + 1, vector (b.size() + 1, -1)); - cout << minChange(0, 0, a, b, c, dp) << endl; - } -}",2 -__TianShu__,2050E - Three Strings,c++17 ,295877264,295880791,"#include -#define MAX -using namespace std; -using ll = long long; - -int na, nb; -string a, b, c; - -/* -7 -a -b -cb -ab -cd -acbd -ab -ba -aabb -xxx -yyy -xyxyxy -a -bcd -decf -codes -horse -codeforces -egg -annie -egaegaeg -*/ - -int dfs(int p1, int p2, int i, vector>>& vis) -{ - // dfs() ----- 在当前情形下 最少还需要变几个字符 - if (vis[p1][p2][i]) { - return vis[p1][p2][i]; - } - if (i == na + nb) { - if (p1 < na) { - return vis[p1][p2][i] = (a[p1] == c[i] ? 0 : 1); - } - else { - return vis[p1][p2][i] = (b[p2] == c[i] ? 0 : 1); - } - } - int d = 0x3f3f3f3f; - if (p1 < na) { - d = dfs(p1+1, p2, i+1, vis) + (a[p1] == c[i] ? 0 : 1); - } - if (p2 < nb) { - d = min(d, dfs(p1, p2+1, i+1, vis) + (b[p2] == c[i] ? 0 : 1)); - } - return vis[p1][p2][i] = d; -} - -void solve() -{ - cin >> a >> b >> c; - na = a.length(); nb = b.length(); - vector>> vis(na + 1, vector>(nb + 1, vector(na + nb + 1, 0))); - cout << dfs(0, 0, 0, vis) << endl; -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - // freopen(""in.txt"", ""r"", stdin); - - int t; - cin >> t; - while (t--) { - solve(); - } - - system(""pause""); - return 0; -}","#include -#define MAX -using namespace std; -using ll = long long; -#define FIND(x) (vis.find(x) != vis.end()) -#define KEY(p1, p2) ((p2)*(na+1) + (p1)) -#define FINDKEY(p1, p2) (FIND(KEY((p1), (p2)))) - -int na, nb; -string a, b, c; - -/* -7 -a -b -cb -ab -cd -acbd -ab -ba -aabb -xxx -yyy -xyxyxy -a -bcd -decf -codes -horse -codeforces -egg -annie -egaegaeg -*/ - -int dfs(int p1, int p2, int i, unordered_map& vis) -{ - // dfs() ----- 在当前情形下 最少还需要变几个字符 - // i一定等于p1+p2 记忆化不需要考虑i - if (FINDKEY(p1, p2)) { - return vis[KEY(p1, p2)]; - } - if (i == na + nb - 1) { - if (p1 < na) { - return vis[KEY(p1, p2)] = (a[p1] == c[i] ? 0 : 1); - } - else { - return vis[KEY(p1, p2)] = (b[p2] == c[i] ? 0 : 1); - } - } - int d = 0x3f3f3f3f; - if (p1 < na) { - d = dfs(p1+1, p2, i+1, vis) + (a[p1] == c[i] ? 0 : 1); - } - if (p2 < nb) { - d = min(d, dfs(p1, p2+1, i+1, vis) + (b[p2] == c[i] ? 0 : 1)); - } - return vis[KEY(p1, p2)] = d; -} - -void solve() -{ - cin >> a >> b >> c; - na = a.length(); nb = b.length(); - // vector>> vis(na + 1, vector>(nb + 1, vector(na + nb + 1, 0))); - unordered_map vis; - cout << dfs(0, 0, 0, vis) << endl; -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - // freopen(""in.txt"", ""r"", stdin); - - int t; - cin >> t; - while (t--) { - solve(); - } - - system(""pause""); - return 0; -}",2 -shahkashish,2050E - Three Strings,c++20 ,295985680,296001238,"#include -using namespace std; - -vector s; - -void func(string &a, string &b, string &c, int inda, int indb) { - if (inda == a.size() && indb == b.size()) { - s.push_back(c); - return; - } - - if (inda < a.size()) { - string m = c + a[inda]; - func(a, b,m, inda + 1, indb); - } - - if (indb < b.size()) { - string n = c + b[indb]; - func(a, b,n, inda, indb + 1); - } -} - -int main() { - int t; - cin >> t; - while (t--) { - string a, b, c; - cin >> a >> b >>c; - - s.clear(); - string m =""""; - func(a, b, m, 0, 0); - - // for (auto ele : s) { - // cout << ele << endl; - // } - int final_ct =10000000; - for(auto ele :s){ - int ct = 0; - for(int i = 0 ; i < ele.size(); ++i){ - if(c[i]!=ele[i])ct++; - } - final_ct = min(ct,final_ct); - } - cout< -using namespace std; - -int main() { - int t; - cin >> t; - - while (t--) { - string a, b, c; - cin >> a >> b >> c; - - int m = a.size(), n = b.size(); - vector> dp(m + 1, vector(n + 1, INT_MAX)); - - // Base case - dp[0][0] = 0; - - // Fill DP table - for (int i = 0; i <= m; ++i) { - for (int j = 0; j <= n; ++j) { - if (i > 0) { - dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i+j-1] != a[i-1])); - } - if (j > 0) { - dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i+j-1] != b[j-1])); - } - } - } - - // Output the result for this test case - cout << dp[m][n] << endl; - } - - return 0; -} -",2 -datshroud,2052A - Adrenaline Rush,c++23 ,307031234,307017077,"#include -using namespace std; - -void solve(){ - int n; cin >> n; - vector vt(n); - for (int &i : vt) cin >> i; - vector> ans; - for (int i = 1; i < n; i++) - for (int j = i + 1; j <= n; j++) - ans.push_back({j, i}); - vector b(n + 1, false); - for (int i = n - 1; ~i; i--){ - for (int j = vt[i] - 1; j >= 1; j--){ - if (!b[j]) - ans.push_back({j, vt[i]}); - } - b[vt[i]] = true; - } - cout << ans.size() << '\n'; - for (auto &[x, y] : ans) - cout << x << ' ' << y << '\n'; -} - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - while (t--) solve(); - return 0; -}","#include -using namespace std; - -void solve(){ - int n; cin >> n; - vector vt(n); - for (int &i : vt) cin >> i; - set> ans; - // 1, 2, 3 -> 2, 1, 3 - vector form(n); - for (int i = 0; i < n; i++) - form[i] = i + 1; - for (int i = 0; i < n; i++){ - int idx = i; - for (; idx < n; idx++) - if (form[idx] == vt[i]) - break; - if (idx + 1 < n){ - ans.insert({form[idx], form[idx + 1]}); - ans.insert({form[idx + 1], form[idx]}); - } - for (int j = idx; j > i; j--){ - ans.insert({form[j], form[j - 1]}); - swap(form[j], form[j - 1]); - } - } - cout << ans.size() << '\n'; - for (auto &p : ans) - cout << p.first << "" "" << p.second << '\n'; -} - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - while (t--) solve(); - return 0; -}",1 -MasteR_BaiteR,2052A - Adrenaline Rush,c++20 ,296840139,296836703,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define int long long -#define ar(n) int a[n]; for(int i=0;i>a[i];} -#define br(n) int b[n]; for(int i=0;i>b[i];} -//stalk mt kr bkl -typedef tree,rb_tree_tag,tree_order_statistics_node_update> pbds; // find_by_order, order_of_key -// ye tree vale me first vala datatype h less means ascending order rkhna h greater se descending order hojaega, less_equal se ascending+multiple values -// XOR(l,r) can be found as XOR(0,r)⊕XOR(0,l−1) this is in O(1). -// fibonnaci me agar koi number k se modulo ho toh a,b,c sequence h agar, then c=a+b or c=(a+b)%k dono ka %k same hoga throughout -bool comp(pair p1, pair p2) { - if(p1.first > p2.first) return true; - if(p1.first < p2.first) return false; - if(p1.first == p2.first){ - if(p1.second 0) { - if (exp % 2 == 1) { - result = (result * base) % mod; - } - base = (base * base) % mod; - exp /= 2; - } - return result; -} -int modinv(int a, int mod) { - return mod_exp(a, mod - 2, mod); -} -int ap(int a,int n,int d){ - int sum=n*(2*a+(n-1)*d)/2; - return sum; -} -bool isPrime(int n) { - // 1 is not prime - if (n <= 1) return false; - - // 2 and 3 are prime numbers - if (n == 2 || n == 3) return true; - - // Check for divisibility by 2 or 3 to handle even and multiples of 3 - if (n % 2 == 0 || n % 3 == 0) return false; - - // Check divisibility from 5 to sqrt(n), skipping even numbers - for (int i = 5; i * i <= n; i += 6) { - if (n % i == 0 || n % (i + 2) == 0) { - return false; - } - } - - return true; -} -bool isSorted(vector& b) { - for (int i = 0; i < b.size() - 1; ++i) { - if (b[i] > b[i + 1]) return false; - } - return true; -} -int findMex(const int arr[], int start, int end) { - std::unordered_set elements; // To store unique elements for O(1) lookup - - // Insert all elements from the array into the set - for (int i = start; i <= end; ++i) { - elements.insert(arr[i]); - } - - int mex = 0; - // Increment mex until we find a value not in the set - while (elements.find(mex) != elements.end()) { - ++mex; - } - //int mex = findMex(arr, size); - return mex; -} -vector computeSuffixMex(const int arr[], int n) { - unordered_set seen; - vector suffixMex(n); - int mex = 0; - - for (int i = n - 1; i >= 0; --i) { - seen.insert(arr[i]); - - // Update mex to be the smallest non-negative integer not in the seen set - while (seen.find(mex) != seen.end()) { - ++mex; - } - - suffixMex[i] = mex; - } - - return suffixMex; -} -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t=1; - //cin>>t; - int modu=(1e9)+7; - while (t--) { - int n; - cin>>n; - ar(n); - vector> v; - for(int i=n;i>0;i--){ - for(int j=i-1;j>0;j--){ - v.push_back({i,j}); - } - } - vector fr(n+1,0); - for(int i=0;i -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define int long long -#define ar(n) int a[n]; for(int i=0;i>a[i];} -#define br(n) int b[n]; for(int i=0;i>b[i];} -//stalk mt kr bkl -typedef tree,rb_tree_tag,tree_order_statistics_node_update> pbds; // find_by_order, order_of_key -// ye tree vale me first vala datatype h less means ascending order rkhna h greater se descending order hojaega, less_equal se ascending+multiple values -// XOR(l,r) can be found as XOR(0,r)⊕XOR(0,l−1) this is in O(1). -// fibonnaci me agar koi number k se modulo ho toh a,b,c sequence h agar, then c=a+b or c=(a+b)%k dono ka %k same hoga throughout -bool comp(pair p1, pair p2) { - if(p1.first > p2.first) return true; - if(p1.first < p2.first) return false; - if(p1.first == p2.first){ - if(p1.second 0) { - if (exp % 2 == 1) { - result = (result * base) % mod; - } - base = (base * base) % mod; - exp /= 2; - } - return result; -} -int modinv(int a, int mod) { - return mod_exp(a, mod - 2, mod); -} -int ap(int a,int n,int d){ - int sum=n*(2*a+(n-1)*d)/2; - return sum; -} -bool isPrime(int n) { - // 1 is not prime - if (n <= 1) return false; - - // 2 and 3 are prime numbers - if (n == 2 || n == 3) return true; - - // Check for divisibility by 2 or 3 to handle even and multiples of 3 - if (n % 2 == 0 || n % 3 == 0) return false; - - // Check divisibility from 5 to sqrt(n), skipping even numbers - for (int i = 5; i * i <= n; i += 6) { - if (n % i == 0 || n % (i + 2) == 0) { - return false; - } - } - - return true; -} -bool isSorted(vector& b) { - for (int i = 0; i < b.size() - 1; ++i) { - if (b[i] > b[i + 1]) return false; - } - return true; -} -int findMex(const int arr[], int start, int end) { - std::unordered_set elements; // To store unique elements for O(1) lookup - - // Insert all elements from the array into the set - for (int i = start; i <= end; ++i) { - elements.insert(arr[i]); - } - - int mex = 0; - // Increment mex until we find a value not in the set - while (elements.find(mex) != elements.end()) { - ++mex; - } - //int mex = findMex(arr, size); - return mex; -} -vector computeSuffixMex(const int arr[], int n) { - unordered_set seen; - vector suffixMex(n); - int mex = 0; - - for (int i = n - 1; i >= 0; --i) { - seen.insert(arr[i]); - - // Update mex to be the smallest non-negative integer not in the seen set - while (seen.find(mex) != seen.end()) { - ++mex; - } - - suffixMex[i] = mex; - } - - return suffixMex; -} -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t=1; - //cin>>t; - int modu=(1e9)+7; - while (t--) { - int n; - cin>>n; - ar(n); - vector> v; - for(int i=0;i>bona; - for(int j=i+1;ja[i]){ - bona.push_back({a[j],'b'}); - }else{ - bona.push_back({a[j],'c'}); - } - } - sort(bona.rbegin(),bona.rend()); - for(int k=0;k - -/* - #include - Compete against Yourself. - Author - swayam_wish -*/ -using namespace std; - - -#define ll long long -#define pii pair -#define piii pair> -#define pis pair -#define db double - - -ll gcd(ll a, ll b) { - if (a % b == 0) return b; - return gcd(b, a % b); -} - -ll reqN(ll k){ - int cnt = 0; - - bool ok = 0; - - - while(k != 1){ - if(k%2 != 0){ - ok = 1; - } - k/=2; - cnt++; - - } - return cnt+ok; -} - -int main() { - - - int t ; - t= 1; - - - while (t--) { - - int n; - cin >> n; - - vector nums(n); - - for(int i = 0; i> nums[i]; - } - - vector> ans; - vector> seq(n+1,vector(n+1,0)); - for(int i = 0; i &a ,vector & b){ - int curr1 = seq[a[0]][a[1]]; - int curr2 = seq[b[0]][b[1]]; - - if(curr1 != curr2){ - return curr1>curr2; - } - else{ - if(a[0] == b[0]){ - return a[1]b[0]; - } - }); - cout< - -/* - #include - Compete against Yourself. - Author - swayam_wish -*/ -using namespace std; - - -#define ll long long -#define pii pair -#define piii pair> -#define pis pair -#define db double - - -ll gcd(ll a, ll b) { - if (a % b == 0) return b; - return gcd(b, a % b); -} - -ll reqN(ll k){ - int cnt = 0; - - bool ok = 0; - - - while(k != 1){ - if(k%2 != 0){ - ok = 1; - } - k/=2; - cnt++; - - } - return cnt+ok; -} - -int main() { - - - int t ; - t= 1; - - - while (t--) { - - int n; - cin >> n; - - vector nums(n); - - for(int i = 0; i> nums[i]; - } - - vector> ans; - vector> seq(n+1,vector(n+1,0)); - int cnt = 0; - for(int i = 0; i cnums(n); - for(int i = 0; i - -using namespace std; - -#define all(X) (X).begin(), (X).end() -#define sz(X) ((int)(X).size()) - -#define st first -#define nd second - -using ll = long long; -using ld = long double; -using pll = pair; - -void solvesub(int n, const vector& pos, vector& curr, vector& ans) { - int i = n - 1; - while(i > 0 && pos[curr[i]] < pos[curr[i - 1]]) { - ans.push_back({curr[i], curr[i - 1]}); - swap(curr[i], curr[i - 1]); - i--; - } - for(int j = i - 1; j >= 0; j--) { - ans.push_back({curr[i], curr[j]}); - } - for(int j = 0; j < i; j++) { - ans.push_back({curr[j], curr[i]}); - } - - cout << ""\n\n""; - for(auto v : curr) { - cout << v + 1 << "" ""; - } - cout << ""\n\n""; -} - -void solve() { - int n; - cin >> n; - vector pos(n); - for(int i = 0; i < n; i++) { - int v; - cin >> v; - v--; - pos[v] = i; - } - vector curr(n); - iota(curr.begin(), curr.end(), 0); - vector ans; - for(int i = 1; i < n; i++) { - solvesub(i + 1, pos, curr, ans); - } - - cout << ans.size() << ""\n""; - for(auto v : ans) { - cout << v.first + 1 << "" "" << v.second + 1 << ""\n""; - } -} - -int main() { - ios_base::sync_with_stdio(0); cin.tie(0); - solve(); - return 0; -}","#include - -using namespace std; - -#define all(X) (X).begin(), (X).end() -#define sz(X) ((int)(X).size()) - -#define st first -#define nd second - -using ll = long long; -using ld = long double; -using pll = pair; - -void solvesub(int n, const vector& pos, vector& curr, vector& ans) { - int i = n - 1; - while(i > 0 && pos[curr[i]] < pos[curr[i - 1]]) { - ans.push_back({curr[i], curr[i - 1]}); - swap(curr[i], curr[i - 1]); - i--; - } - for(int j = i - 1; j >= 0; j--) { - ans.push_back({curr[i], curr[j]}); - } - for(int j = 0; j < i; j++) { - ans.push_back({curr[j], curr[i]}); - } -} - -void solve() { - int n; - cin >> n; - vector pos(n); - for(int i = 0; i < n; i++) { - int v; - cin >> v; - v--; - pos[v] = i; - } - vector curr(n); - iota(curr.begin(), curr.end(), 0); - vector ans; - for(int i = 1; i < n; i++) { - solvesub(i + 1, pos, curr, ans); - } - - cout << ans.size() << ""\n""; - for(auto v : ans) { - cout << v.first + 1 << "" "" << v.second + 1 << ""\n""; - } -} - -int main() { - ios_base::sync_with_stdio(0); cin.tie(0); - solve(); - return 0; -}",2 -Atul_2301,2052A - Adrenaline Rush,c++17 ,300583474,300544431,"#include -using namespace std; -#define ll long long int -ll mod=1e9+7; - -int main() -{ -ios_base::sync_with_stdio(false); -cin.tie(NULL); - ll n; - cin>>n; - vectorfinal(n+1);unordered_mapmp; - for(ll i=1;i<=n;i++) cin>>final[i]; - for(ll i=1;i<=n;i++) - { - mp[final[i]]=i; - } - vector>ans; - for(ll i=1;i<=n-1;i++) - { - for(ll j=i+1;j<=n;j++) ans.push_back({j,i}); - } - vectorcrr(n+1); - for(ll i=n;i>=1;i--) crr[i]=n-i+1; - while(true) - { bool flag=false; - for(ll i=1;i<=n-1;i++) - { - ll a=crr[i]; ll b=crr[i+1]; -if((bmp[b]) ) {flag=true; swap(crr[i],crr[i+1]); ans.push_back({b,a});} - } - if(!flag) break; - } - cout< -using namespace std; -#define ll long long int -ll mod=1e9+7; - -int main() -{ -ios_base::sync_with_stdio(false); -cin.tie(NULL); - ll n; - cin>>n; - vectorfinal(n+1);unordered_mapmp; - for(ll i=1;i<=n;i++) cin>>final[i]; - for(ll i=1;i<=n;i++) - { - mp[final[i]]=i; - } - vector>ans; - for(ll i=1;i<=n-1;i++) - { - for(ll j=i+1;j<=n;j++) - { - if(mp[j] -using namespace std; - - -#include -#include - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - - -//------------------------------------------------// -#if __has_include(""../files/juzar_7.cpp"") -#include ""../files/juzar_7.cpp"" -#endif -#ifdef juzZ -#define deb(x) {cerr << #x << "" ""; _print(x); cerr << ""\n"";} -#else -#define deb(x) -#endif -#define rep(i, a, b) for (int i = a; i < b; i++) -#define precision(a) cout << setprecision(a) << fixed -#define MSB(x) (63 - __builtin_clzll(x)) -#define amax(a, b) a = max(a, b) -#define amin(a, b) a = min(a, b) -#define MP make_pair -#define all(a) a.begin(), a.end() -template ostream &operator<<(ostream &os, const vector a){ for (auto ele : a) os << ele << "" ""; return os;} -template istream &operator>>(istream &is, vector &a){ for (auto &ele : a) is >> ele; return is; } -typedef vector vi; typedef vector> vvi; typedef vector vl; typedef vector> vvl; typedef vector vb; typedef vector> vvb; typedef map mii; typedef map mll; typedef pair pii; typedef pair pll; typedef unsigned long long ull; typedef long double ld; typedef long long ll; -//------------------------------------------------// - - - -ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -ll binExp(ll a, ll b) {ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } -ll MOD = 1e9 + 7; - -int dx[4] = {1, 0, -1, 0}; -int dy[4] = {0, 1, 0, -1}; - - - - -void solve(int loop) -{ - int n; - cin>>n; - vector v(n+1); - for (int i=1; i>v[i]; - // int ans = 0; - set> st; - vector ini(n+1); - for (int i=1; i<=n; i++) ini[i] = i; - vector> ans; - for (int i=1; i<=n; i++) - { - int curr = v[i]; - int idx = -1; - for (int j=1; j<=n; j++) - { - if (ini[j]==curr) - { - idx = j; - break; - } - } - if (idx==i) continue; - for (int j=idx; j>i; j--) - { - ans.push_back({ini[j], ini[j-1]}); - swap(ini[j], ini[j-1]); - st.insert({min(ini[j], ini[j-1]), max(ini[j], ini[j-1])}); - } - } - for (int i=1; i> tc; - for (int loop = 1; loop <= tc; loop++) - { - // cout << ""Case #"" << loop << "": ""; - solve(loop); - // bool as = solve(); cout << (as ? ""YES\n"" : ""NO\n""); - // int as = solve(); cout << as << ""\n""; - } - return 0; -} - -/* - Wed Mar 1 19:52:06 2023 - File : C.cpp -*/ -","#include -using namespace std; - - -#include -#include - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - - - - -//------------------------------------------------// -#if __has_include(""../files/juzar_7.cpp"") -#include ""../files/juzar_7.cpp"" -#endif -#ifdef juzZ -#define deb(x) {cerr << #x << "" ""; _print(x); cerr << ""\n"";} -#else -#define deb(x) -#endif -#define rep(i, a, b) for (int i = a; i < b; i++) -#define precision(a) cout << setprecision(a) << fixed -#define MSB(x) (63 - __builtin_clzll(x)) -#define amax(a, b) a = max(a, b) -#define amin(a, b) a = min(a, b) -#define MP make_pair -#define all(a) a.begin(), a.end() -template ostream &operator<<(ostream &os, const vector a){ for (auto ele : a) os << ele << "" ""; return os;} -template istream &operator>>(istream &is, vector &a){ for (auto &ele : a) is >> ele; return is; } -typedef vector vi; typedef vector> vvi; typedef vector vl; typedef vector> vvl; typedef vector vb; typedef vector> vvb; typedef map mii; typedef map mll; typedef pair pii; typedef pair pll; typedef unsigned long long ull; typedef long double ld; typedef long long ll; -//------------------------------------------------// - - - -ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -ll binExp(ll a, ll b) {ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } -ll MOD = 1e9 + 7; - -int dx[4] = {1, 0, -1, 0}; -int dy[4] = {0, 1, 0, -1}; - - - - -void solve(int loop) -{ - int n; - cin>>n; - vector v(n+1, 0); - for (int i=1; i<=n; i++) cin>>v[i]; - reverse(v.begin()+1, v.end()); - vector ini(n+1, 0); - for (int i=1; i<=n; i++) ini[i] = i; - vector> ans; - for (int i=1; i<=n; i++) - { - int curr = v[i]; - int idx = -1; - for (int j=i; j<=n; j++) - { - if (ini[j]==curr) - { - idx = j; - break; - } - } - for (int j=idx; j>i; j--) - { - ans.push_back({ini[j], ini[j-1]}); - swap(ini[j], ini[j-1]); - } - } - reverse(v.begin()+1, v.end()); - for (int i=1; i<=n; i++) - { - int curr = v[i]; - int idx = -1; - for (int j=i; j<=n; j++) - { - if (ini[j]==curr) - { - idx = j; - break; - } - } - for (int j=idx; j>i; j--) - { - ans.push_back({ini[j], ini[j-1]}); - swap(ini[j], ini[j-1]); - } - } - cout << ans.size() << ""\n""; - for (auto it : ans) cout << it .first << "" "" << it.second << ""\n""; -} - - - - -int32_t main() -{ -// #define DEBUG_MODE -#ifndef DEBUG_MODE - ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - -#ifdef juzZ - freopen(""../files/input.txt"", ""r"", stdin); freopen(""../files/output.txt"", ""w"", stdout); freopen(""../files/error.txt"", ""w"", stderr); -#endif -#else -#ifdef juzZ - freopen(""../files/input.txt"", ""r"", stdin); -#endif -#endif - - - - - int tc = 1; - // cin >> tc; - for (int loop = 1; loop <= tc; loop++) - { - // cout << ""Case #"" << loop << "": ""; - solve(loop); - // bool as = solve(); cout << (as ? ""YES\n"" : ""NO\n""); - // int as = solve(); cout << as << ""\n""; - } - return 0; -} - -/* - Wed Mar 1 19:52:06 2023 - File : C.cpp -*/ -",2 -outof_bounds,2052A - Adrenaline Rush,c++17 ,297078657,297078472,"/*'ॐ नमः शिवाय'*/ -#include -using namespace std; -#define int long long -#define endl ""\n"" -const int mod = 1e9 + 7; - -void solve() { - int n; - cin >> n; - vector a(n), c(n); - mapind, m; - for (int i = 0; i < n; i++) { - cin >> c[i]; - ind[c[i]] = i; - } - for (int i = 0; i < n; i++) { - a[i] = i + 1; - m[a[i]] = i; - } - vector> v; - for (int i = 0; i < n; i++)a[i] = i + 1; - int i = n - 1; - int ans = 0; - while (i >= 0) { - int j = m[c[i]]; - while (j < i) { - v.push_back({a[j + 1], a[j]}); - swap(a[j], a[j + 1]); - ans++; - j++; - } - for (int i = 0; i < n; i++) { - m[a[i]] = i; - } - i--; - } - vector> temp; - for (int i = n; i >= 1; i--) { - int j = ind[i]; - while (j >= 0) { - if (c[j - 1] < i) { - v.push_back({i, c[j - 1]}); - temp.push_back({i, c[j - 1]}); - ans += 2; - } - j--; - } - } - int size = temp.size(); - for (int j = size - 1; j >= 0; j--) { - int x = temp[j].first; - int y = temp[j].second; - v.push_back({y, x}); - } - cout << ans << endl; - for (int i = 0; i < v.size(); i++) { - cout << v[i].first << "" "" << v[i].second << endl; - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - int t = 1; - //cin >> t; - while (t--) solve(); - - return 0; -}","/*'ॐ नमः शिवाय'*/ -#include -using namespace std; -#define int long long -#define endl ""\n"" -const int mod = 1e9 + 7; - -void solve() { - int n; - cin >> n; - vector a(n), c(n); - mapind, m; - for (int i = 0; i < n; i++) { - cin >> c[i]; - ind[c[i]] = i; - } - for (int i = 0; i < n; i++) { - a[i] = i + 1; - m[a[i]] = i; - } - map, int> mp; - vector> v; - for (int i = 0; i < n; i++)a[i] = i + 1; - int i = n - 1; - int ans = 0; - while (i >= 0) { - int j = m[c[i]]; - while (j < i) { - v.push_back({a[j + 1], a[j]}); - swap(a[j], a[j + 1]); - ans++; - j++; - } - for (int i = 0; i < n; i++) { - m[a[i]] = i; - } - i--; - } - vector> temp; - for (int i = n; i >= 1; i--) { - int j = ind[i]; - while (j >= 0) { - if (c[j - 1] < i) { - v.push_back({i, c[j - 1]}); - temp.push_back({i, c[j - 1]}); - ans += 2; - } - j--; - } - } - int size = temp.size(); - for (int j = size - 1; j >= 0; j--) { - int x = temp[j].first; - int y = temp[j].second; - v.push_back({y, x}); - } - cout << ans << endl; - for (int i = 0; i < v.size(); i++) { - cout << v[i].first << "" "" << v[i].second << endl; - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - int t = 1; - cin >> t; - while (t--) solve(); - - return 0; -}",1 -aditya2.7080,2052A - Adrenaline Rush,c++20 ,298291122,298288120,"#include -using namespace std; -#define ll long long -#define all(v) v.begin(), v.end() -#define LL_MAX LLONG_MAX -#define LL_MIN LLONG_MIN -#define pb push_back - - -void solve() { - int n; - cin >> n; - vector final(n); - - - for(int i = 0; i < n; i++){ - cin >> final[i] ; - } - -if(n == 1){ - cout << 0 << '\n'; - return; -} - vectorv(n); - - for(int i = n - 1; i >= 0; i--){ - v[i] = i + 1; - } - - reverse(all(v)); - vectorstore1; - vectorstore2; -int count = 0; - for(int i = 1; i <= n; i++){ - for(int j = i + 1; j <= n; j++){ - count++; - store1.push_back(j); - store2.pb(i); - - } - } - - for(int i = 0; i < n; i++){ - int j = i; - while(v[j] != final[i]){ - j++; - } - - - for(int k = j; k > i; k--){ - count++; - store1.pb(v[k]); - store2.pb(v[k - 1]); - swap(v[k],v[k - 1]); - - } - - - } -cout << count << '\n'; - for(int i = 0; i < store1.size(); i++){ - cout << store1[i] << "" "" << store2[i] << '\n'; - } - - - - -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t = 1; - // cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -#define ll long long -#define all(v) v.begin(), v.end() -#define LL_MAX LLONG_MAX -#define LL_MIN LLONG_MIN -#define pb push_back - - -void solve() { - int n; - cin >> n; - vector final(n); - - - for(int i = 0; i < n; i++){ - cin >> final[i] ; - } - -if(n == 1){ - cout << 0 << '\n'; - return; -} - vectorv(n); - - for(int i = n - 1; i >= 0; i--){ - v[i] = i + 1; - } - - reverse(all(v)); - - for(int i = 1; i <= n; i++){ - for(int j = i + 1; j <= n; j++){ - cout << j << "" "" << i << '\n'; - - } - } - - for(int i = 0; i < n; i++){ - int j = i; - while(v[j] != final[i]){ - j++; - } - - - for(int k = j; k > i; k--){ - cout << v[k] << "" "" << v[k - 1] << '\n'; - swap(v[k],v[k - 1]); - - } - - - } - - - - -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t = 1; - // cin >> t; - while (t--) { - solve(); - } - return 0; -} -",1 -ByteBlade2104,2052A - Adrenaline Rush,c++17 ,302861788,302861266,"#include -using namespace std; -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL) -#define int long long -#define mod 1000000007 - -signed main() { - int n; - cin >> n; - vector v(n); - for(int i=0; i>v[i]; - } - bool arr[n+1] = {false}; - vector> ans; - for(int i=n-1; i>=0; i--) { - arr[v[i]] = true; - for(int j=v[i]-1; j>0; j--) { - if(!arr[j]) ans.push_back({v[i],j}); - } - for(int j=1; j<=n; j++) { - if(!arr[j]) ans.push_back({j,v[i]}); - } - - } - cout< -using namespace std; -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL) -#define int long long -#define mod 1000000007 - -signed main() { - int n; - cin >> n; - vector v(n); - for(int i=0; i>v[i]; - } - bool arr[n+1] = {false}; - vector> ans; - for(int i=n-1; i>=0; i--) { - arr[v[i]] = true; - for(int j=v[i]-1; j>0; j--) { - if(!arr[j]) ans.push_back({v[i],j}); - } - for(int j=1; j<=i+1; j++) { - if(!arr[j]) ans.push_back({j,v[i]}); - } - - } - cout< -#define ll long long -using namespace std; - -int main() -{ - ll n; - cin>>n; - vectorpos(n+1); - vectorcur(n+1); - vectora(n+1); - for(ll i = 1;i<=n;i++) - { - cin>>a[i]; - pos[a[i]] = i; - cur[i] = i; - } - vector>ans; - for(ll i = 1;i<=n;i++) - { - for(ll j = 1;j pos[cur[j+1]]) - { - ans.push_back({cur[j+1],cur[j]}); - swap(cur[j+1],cur[j]); - } - } - } - cout< -#define ll long long -using namespace std; - -int main() -{ - ll n; - cin>>n; - vectora(n); - for(ll i = 0;i>a[i]; - ll m = 0; - vector>greater(n+1,vector()); - vector>smaller(n+1,vector()); - for(ll i = 0;i=0;j--) - { - cout< -using namespace std; - -#define fastIO \ - ios::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL); \ - cout.precision(numeric_limits::max_digits10); -#define int long long - -void Bankai() { - int n; - cin>>n; - vector v(n); - for(auto &i:v)cin>>i; - - vector> vk(n+1,vector(n+1,0)); - - vector rank(n+1); - vector temp(n); - for(int i=0;i> vp; - for(int i=0;irank[temp[j+1]]){ - yh=1; - //cout<> t; - // int a=fac(200000); - while (t--) { - Bankai(); - } - return 0; -}","#include -using namespace std; - -#define fastIO \ - ios::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL); \ - cout.precision(numeric_limits::max_digits10); -#define int long long - -void Bankai() { - int n; - cin>>n; - vector v(n); - for(auto &i:v)cin>>i; - - vector> vk(n+1,vector(n+1,0)); - - vector rank(n+1); - vector temp(n); - for(int i=0;i> vp; - for(int i=0;i(i+1)){ - vp.push_back({v[j],i+1}); - } - } - for(int j=n-1;j>=yh;j--){ - if(v[j]>(i+1)){ - vp.push_back({i+1,v[j]}); - } - } - for(int j=yh-2;j>=0;j--){ - if(v[j]>(i+1)){ - vp.push_back({i+1,v[j]}); - } - } - } - - cout<= 0; i--) cout << vp[i].second << "" "" << vp[i].first << endl; - -} - -int32_t main() { - fastIO; - - int t = 1; - // cin >> t; - // int a=fac(200000); - while (t--) { - Bankai(); - } - return 0; -}",2 -zFa3,2052A - Adrenaline Rush,c++17 ,302132122,302088765,"#include -#define int long long - -// macros -#define For(x) for (int i = 0; i < x; i++) -#define SORT(a) sort(a.begin(), a.end()) -#define FOR(a, b, c) for(int i = a; i < b; i += c) -#define SUM(a) accumulate(a.begin(), a.end(), 0LL) -#define MAX(a) *max_element(a.begin(), a.end()) -#define all(x) (x.begin(), x.end()) - -// syntax -#define mp make_pair - -// other macros -#define MOD (int)1e8 - -// speed -#pragma GCC optimize(""O3"") - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(NULL); - int count; - cin >> count; - vector arr(count); - vector temp(count); - For (count){ - cin >> arr[i]; - } - int counter = 0; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - if (arr[i] > arr[j]){ - counter++; - } else { - counter += 2; - } - } - } - cout << counter << ""\n""; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - cout << j + 1 << "" "" << i + 1 << ""\n""; - } - temp[i] = count - i; - } - while (temp != arr){ - for (int i = 0; i < count - 1; i++){ - int index1 = find(arr.begin(), arr.end(), temp[i]) - arr.begin(); - int index2 = find(arr.begin(), arr.end(), temp[i+1]) - arr.begin(); - if (index1 > index2){ - cout << temp[i + 1] << ' ' << temp[i] << ""\n""; - auto v = temp[i]; - temp[i] = temp[i + 1]; - temp[i + 1] = v; - } - } - } - // 4 3 2 1 - // 3 4 1 2 - // 3 4 1 2 - // 3 1 4 2 -} -","#include -#define int long long - -// macros -#define For(x) for (int i = 0; i < x; i++) -#define SORT(a) sort(a.begin(), a.end()) -#define FOR(a, b, c) for(int i = a; i < b; i += c) -#define SUM(a) accumulate(a.begin(), a.end(), 0LL) -#define MAX(a) *max_element(a.begin(), a.end()) -#define all(x) (x.begin(), x.end()) - -// syntax -#define mp make_pair - -// other macros -#define MOD (int)1e8 - -// speed -#pragma GCC optimize(""O3"") - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(NULL); - int count; - cin >> count; - vector arr(count); - For (count){ - cin >> arr[i]; - } - int counter = 0; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - if (arr[i] > arr[j]){ - counter++; - } else { - counter += 2; - } - } - } - cout << counter << ""\n""; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - cout << j + 1 << "" "" << i + 1 << ""\n""; - } - } - for (int i = 0; i < count; i++){ - for (int x = 0; x < count; x++){ - auto revIndex = count - x; - if (arr[x] != revIndex){ - // cout << revIndex; - if (arr[x] > revIndex){ - cout << arr[x-1] << "" "" << arr[x] << ""\n""; - auto v = arr[x]; - arr[x] = arr[x-1]; - arr[x-1] = v; - } else { - cout << arr[x] << "" "" << arr[x+1] << ""\n""; - - auto v = arr[x]; - arr[x] = arr[x+1]; - arr[x+1] = v; - } - } - } - } -} -",1 -"Yuzu Soft CP Team: Spasmodic_AP, Komeijizen#",2052A - Adrenaline Rush,c++17 ,300103714,300104632,"#include - -#ifndef LOCAL -#pragma GCC optimize(""Ofast,no-stack-protector,unroll-loops,fast-math"") -#endif -#define COPYRIGHT ""Copyright (c) 2024 ,yzn. All rights Reserved."" -#define longbi xjn -#define AUTHOR yzn -#define YEAR 2025 -#define kzn yzn - -#define inf (1ll<<60) - -#define fori(i, n) for (int i = 1; i <= n; i++) -#define ford(i, n,m) for (int i = n; i > m; i--) - -#define ll long long -#define int ll - -#define clr(n,m) for(int i=0;i<=m;i++)n[i]=0; -#define sinf(n,m) for(int i=0;i<=m;i++)n[i]=inf; - -#define vi vector -#define pi pair -#define vpi vector> -#define fi first -#define se second - -constexpr double eps=1e-6; -constexpr bool debug=0; -#define ID if(debug) -char abt[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; -using namespace std; -namespace IO{ - char ibuf[(1<<20)+1],*iS,*iT; - #ifndef LOCAL - #define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++) - #else - #define gh() getchar() - #endif - inline long long read(){char ch=gh();long long x=0;bool t=0;while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();return t?-x:x;} - inline void write(int x){static int sta[35];int top = 0;do{sta[top++] = x % 10, x /= 10;} while (x);while (top)putchar(sta[--top] + 48);} - const void File(bool b1,bool b2){if(b1)freopen(""out.out"",""w"",stdout);if(b2)freopen(""in.in"",""r"",stdin);} - void YN(bool b){if(b)puts(""Yes"");else puts(""No"");} -} -using namespace IO; -const int N=1e3+5; -int n,A[N]; -/* -冒泡排序...没有交换的对子互相交换一下. -*/ -vectoropt; -signed main() -{ - n=read(); - for(int i=1;i<=n;i++)A[i]=read(); - for(int i=1;iA[j+1])opt.push_back({A[j],A[j+1]}),swap(A[j],A[j+1]); - } - } - cout< - -#ifndef LOCAL -#pragma GCC optimize(""Ofast,no-stack-protector,unroll-loops,fast-math"") -#endif -#define COPYRIGHT ""Copyright (c) 2024 ,yzn. All rights Reserved."" -#define longbi xjn -#define AUTHOR yzn -#define YEAR 2025 -#define kzn yzn - -#define inf (1ll<<60) - -#define fori(i, n) for (int i = 1; i <= n; i++) -#define ford(i, n,m) for (int i = n; i > m; i--) - -#define ll long long -#define int ll - -#define clr(n,m) for(int i=0;i<=m;i++)n[i]=0; -#define sinf(n,m) for(int i=0;i<=m;i++)n[i]=inf; - -#define vi vector -#define pi pair -#define vpi vector> -#define fi first -#define se second - -constexpr double eps=1e-6; -constexpr bool debug=0; -#define ID if(debug) -char abt[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; -using namespace std; -namespace IO{ - char ibuf[(1<<20)+1],*iS,*iT; - #ifndef LOCAL - #define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<20)+1,stdin),(iS==iT?EOF:*iS++):*iS++) - #else - #define gh() getchar() - #endif - inline long long read(){char ch=gh();long long x=0;bool t=0;while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();return t?-x:x;} - inline void write(int x){static int sta[35];int top = 0;do{sta[top++] = x % 10, x /= 10;} while (x);while (top)putchar(sta[--top] + 48);} - const void File(bool b1,bool b2){if(b1)freopen(""out.out"",""w"",stdout);if(b2)freopen(""in.in"",""r"",stdin);} - void YN(bool b){if(b)puts(""Yes"");else puts(""No"");} -} -using namespace IO; -const int N=1e3+5; -int n,A[N],C[N],wp[N][N]; -pi B[N]; -/* -冒泡排序...没有交换的对子互相交换一下. -*/ -vectoropt; -signed main() -{ - n=read(); - for(int i=1;i<=n;i++)A[i]=read(),C[A[i]]=i; - - /*for(int i=1;i<=n;i++){ - for(int j=1;jA[j+1])opt.push_back({A[j],A[j+1]}),swap(A[j],A[j+1]); - } - }*/ - for(int i=1;i<=n;i++)B[i]={i,C[i]}; - for(int i=1;i<=n;i++){ - for(int j=1;jB[j+1].se)opt.push_back({B[j+1].fi,B[j].fi}),wp[B[j+1].fi][B[j].fi]=wp[B[j].fi][B[j+1].fi]=1,swap(B[j],B[j+1]); - else if(!wp[B[j].fi][B[j+1].fi])opt.push_back({B[j+1].fi,B[j].fi}),swap(B[j],B[j+1]); - } - } - for(int i=1;i -using namespace std; -#define int long long -#define all(x) (x).begin(),(x).end() -typedef pair PII; -const int N = 2e6 + 10; - -int a[N]; - -void solve() { - int n; - cin>>n; - mappos; - vectorans; - for(int i=1;i<=n;i++){ - cin>>a[i]; - pos[a[i]]=i; - } - for(int i=1;i<=n;i++){ - for(int j=pos[i];j=i+1;j--){ - swap(a[j],a[j-1]); - pos[a[j]]=j; - pos[a[j-1]]=j-1; - ans.push_back({a[j-1],a[j]}); - // for(int i=1;i<=n;i++){ - // cout<=0;i--){ - cout<> T; - while (T--) solve(); - return 0; -} -","#include -using namespace std; -#define int long long -#define all(x) (x).begin(),(x).end() -typedef pair PII; -const int N = 2e6 + 10; - -int a[N]; - -void solve() { - int n; - cin>>n; - mappos; - vectorans; - for(int i=1;i<=n;i++){ - cin>>a[i]; - pos[a[i]]=i; - } - for(int i=1;i<=n;i++){ - for(int j=pos[i];j=i+1;j--){ - swap(a[j],a[j-1]); - pos[a[j]]=j; - pos[a[j-1]]=j-1; - ans.push_back({a[j],a[j-1]}); - // for(int i=1;i<=n;i++){ - // cout<=0;i--){ - cout<> T; - while (T--) solve(); - return 0; -} -",2 -autunm_dream,2052A - Adrenaline Rush,c++23 ,301317224,301317930,"#pragma ccc optimize(3) -#pragma ccc optimize(2) -#include -using namespace std; -#define ll long long -#define re register -#define INF 0x3f3f3f3f -#define il inline -#define pb push_back -#define ft first -#define sd second -#define mp make_pair -#define pb push_back -#define P pair -//#define cin fin -//#define cout fout -//ifstream cin(""文件名.in""); -//ofstream cout(""文件名.out""); -int a[1005]; -void solve(){ - int n; - cin >> n; - vector

ans; - for(int i = 1; i <= n; ++i)cin >> a[i]; - for(int i = 1; i <= n; ++i){ - for(int j = i + 1; j <= n; ++j){ - if(a[i] < a[j]){ - ans.pb(mp(a[j], a[i])); - ans.pb(mp(a[i], a[j])); - } - else ans.pb(mp(a[i], a[j])); - } - } - cout << ans.size() << endl; - for(int i = 0; i < ans.size(); ++i)cout << ans[i].ft << ' ' << ans[i].sd << endl; -} -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - solve(); - return 0; -} - -","#pragma ccc optimize(3) -#pragma ccc optimize(2) -#include -using namespace std; -#define ll long long -#define re register -#define INF 0x3f3f3f3f -#define il inline -#define pb push_back -#define ft first -#define sd second -#define mp make_pair -#define pb push_back -#define P pair -//#define cin fin -//#define cout fout -//ifstream cin(""文件名.in""); -//ofstream cout(""文件名.out""); -int a[1005]; -bool expr[1005]; -void solve(){ - int n; - cin >> n; - vector

ans; - for(int i = 1; i <= n; ++i)cin >> a[i]; - for(int i = 1; i <= n; ++i){ - for(int j = a[i] + 1; j <= n; ++j){ - if(expr[j])continue; - ans.pb(mp(j, a[i])); - } - expr[a[i]] = 1; - for(int j = n; j >= 1; --j){ - if(expr[j])continue; - ans.pb(mp(a[i], j)); - } - } - cout << ans.size() << endl; - for(int i = 0; i < ans.size(); ++i)cout << ans[i].ft << ' ' << ans[i].sd << endl; -} -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - solve(); - return 0; -} - -",2 -Shekher.Rishi,2052A - Adrenaline Rush,c++23 ,297664079,297649786,"#include -using namespace std; -//unsigned long long mod = 998244353; -const int mod = (1e9) + 7; -#define MAXN 100000 -#define int long long -#define sort(v) sort(v.begin(), v.end()) -#define print_with_spaces(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << "" "";} -#define print_with_lines(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << ""\n"";} -#define itr(i,a,b) for (unsigned int i = a; i < b; i++) -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -#define is_possible cout << ((possible) ? ""YES\n"": ""NO\n"") -#define ull unsigned long long -#define ll long long -#define pb push_back -#define pi pair -#define pii pair -#define vi vector -#define mp make_pair -#define read(v, n) for (unsigned int i = 0; i < n; i++){cin>>v[i];} - -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int n;cin >> n; - vi a(n + 1); - for (int i = 1;i <= n;i++)cin >> a[i]; - int c = 0; - for (int i = 1;i <= n;i++) - for (int j = i + 1;j <= n;j++){ - if (a[i] > a[j])c++; -} - int ans = 0; - for (int i = 1;i <= n;i++) { - set> st; - for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]); - for (auto& p : st) { - //cout << a[i] << "" "" << p << '\n'; - ans++; - } - } - - - - cout << n*(n-1)-c << endl; - for (int i = 1;i <= n;i++) { - set> st; - for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]); - for (auto& p : st) { - cout << a[i] << "" "" << p << '\n'; - } - } - auto dfs= [&](auto &&self) { - int k = n; - while (k >= 2 && a[k - 1] > a[k])k--; - if (k == 1) return; - - if (k >= 2 && a[k-1] < a[k]) { - cout << a[k] << "" "" << a[k-1] << '\n'; - swap(a[k], a[k-1]); - self(self); - swap(a[k], a[k-1]); - cout << a[k-1] << "" "" << a[k] << '\n'; - - - } - - }; - dfs(dfs); - - - - return 0; -} -","#include -using namespace std; -//unsigned long long mod = 998244353; -const int mod = (1e9) + 7; -#define MAXN 100000 -#define int long long -#define sort(v) sort(v.begin(), v.end()) -#define print_with_spaces(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << "" "";} -#define print_with_lines(v, n) for (unsigned int i = 0; i < n; i++){cout << v[i] << ""\n"";} -#define itr(i,a,b) for (unsigned int i = a; i < b; i++) -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -#define is_possible cout << ((possible) ? ""YES\n"": ""NO\n"") -#define ull unsigned long long -#define ll long long -#define pb push_back -#define pi pair -#define pii pair -#define vi vector -#define mp make_pair -#define read(v, n) for (unsigned int i = 0; i < n; i++){cin>>v[i];} - -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int n;cin >> n; - vi a(n + 1); - for (int i = 1;i <= n;i++)cin >> a[i]; - int c = 0; - for (int i = 1;i <= n;i++) - for (int j = i + 1;j <= n;j++){ - if (a[i] > a[j])c++; -} - int ans = 0; - for (int i = 1;i <= n;i++) { - set> st; - for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]); - for (auto& p : st) { - //cout << a[i] << "" "" << p << '\n'; - ans++; - } - } - vi temp; - - for (int i = n;i >= 2;i--) { - int k = i - 1; - - while (k >= 1 && a[k] < a[i]) { - //cout << a[i] << "" "" << a[k] << '\n'; - temp.pb(a[k]); - k--; - ans += 1; - } - while (!temp.empty()) { - //cout << temp.back() << "" "" << a[i] << '\n'; - temp.pop_back(); - ans++; - } - temp.clear(); - } - - cout << ans << endl; - for (int i = 1;i <= n;i++) { - set> st; - for (int j = i + 1;j <= n;j++) if (a[i] > a[j])st.insert(a[j]); - for (auto& p : st) { - cout << a[i] << "" "" << p << '\n'; - //ans++; - } - } - for (int i = n;i >= 2;i--) { - int k = i-1; - - while (k>=1&& a[k ] < a[i]) { - cout << a[i] << "" "" << a[k] << '\n'; - temp.pb(a[k]); - k--; - //ans += 1; - } - while (!temp.empty()) { - cout << temp.back() << "" "" << a[i] << '\n'; - temp.pop_back(); - //ans++; - } - temp.clear(); - } - - - return 0; -} -",1 -ABTurjo121,2052A - Adrenaline Rush,c++20 ,297237562,297238984,"#include -using namespace std; - -int main() -{ - long long int n,t=1,i,j,m,k; - //cin >> t ; - while(t--) - { - //string s; - cin >> n ; - long long int ans=0,a[n],b[n+1]={}; - char op; - //paira[n]; - for(i=0;i> a[i] ; - ans+=max(i-i,n-a[i])+n-i-1; - } - cout << ans << ""\n"" ; - for(i=0;i0;j--) - { - if(b[j]==0&&j!=a[i]) - cout << a[i] << "" "" << j << ""\n"" ; - } - b[a[i]]++; - } - } - return 0; -}","#include -using namespace std; - -int main() -{ - long long int n,t=1,i,j,m,k; - //cin >> t ; - while(t--) - { - //string s; - cin >> n ; - long long int ans=0,a[n],b[n+1]={},x; - vectorc; - char op; - //paira[n]; - for(i=0;i> a[i] ; - x=n-a[i]; - for(j=0;ja[i]) - x--; - } - ans+=x+n-i-1; - c.push_back(a[i]); - } - cout << ans << ""\n"" ; - for(i=0;i0;j--) - { - if(b[j]==0&&j!=a[i]) - cout << a[i] << "" "" << j << ""\n"" ; - } - b[a[i]]++; - } - } - return 0; -}",2 -AsukaAlice,2052A - Adrenaline Rush,c++20 ,303588146,303589799,"#include -using namespace std; -const int N=1100; -int a[N]; -int n; -int ans; -vector>cnt; -int main() -{ - cin>>n; - for(int i=1;i<=n;i++) - { - scanf(""%d"",&a[i]); - } - if(n==1) - { - cout< -using namespace std; -const int N=1100; -int a[N],pos[N],b[N]; -int n; -int ans; -vector>cnt; -int main() -{ - cin>>n; - for(int i=1;i<=n;i++) - { - scanf(""%d"",&a[i]); - pos[a[i]]=i; - b[i]=i; - } - if(n==1) - { - cout< -using namespace std; - -#define rep(n) for (int _i_i_ = (n); _i_i_; --_i_i_) -#define mem(arr, x) memset((arr), x, sizeof (arr)) -#define mkp make_pair -#define edge(y, x, ver) for (int _i_ = h[x], y = ver[_i_]; _i_; y = ver[_i_ = nxt[_i_]]) -#define import mt19937 -#define random rnd(chrono::system_clock::now().time_since_epoch().count()) -#define setdb(v) setprecision(v) -using ll = long long; -using ull = unsigned long long; -using pii = pair; -using pll = pair; - -const int maxn = 1e3 + 5; - -int n; -int c, a[maxn], p[maxn]; - -void solve() { - cin >> n; - for (int i = 1; i <= n; ++i) { - cin >> c; - p[c] = i; - a[i] = n - i + 1; - } - vector ans; - for (int i = 1; i <= n; ++i) { - for (int j = i + 1; j <= n; ++j) { - ans.emplace_back(j, i); - } - } - for (int i = 1; i <= n; ++i) { - for (int j = n; j > i; --j) { - if (p[a[j - 1]] > p[a[j]]) { - ans.emplace_back(a[j], a[j - 1]); - swap(a[j - 1], a[j]); - } - } - } - cout << ans.size() << '\n'; - for (auto &[x, y] : ans) cout << x << ' ' << y << '\n'; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t = 1; - //cin >> t; - rep (t) { - solve(); - } - return 0; -} - -/* -+---------------------------------------------+ -|GREY|GREEN|CYAN|BLUE|PURPLE|YELLOW|ORANGE|RED| -+---------------------------------------------+ -*/","// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/contest/2052/problem/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -using namespace std; - -#define rep(n) for (int _i_i_ = (n); _i_i_; --_i_i_) -#define mem(arr, x) memset((arr), x, sizeof (arr)) -#define mkp make_pair -#define edge(y, x, ver) for (int _i_ = h[x], y = ver[_i_]; _i_; y = ver[_i_ = nxt[_i_]]) -#define import mt19937 -#define random rnd(chrono::system_clock::now().time_since_epoch().count()) -#define setdb(v) setprecision(v) -using ll = long long; -using ull = unsigned long long; -using pii = pair; -using pll = pair; - -const int maxn = 1e3 + 5; - -int n; -int c, p[maxn]; - -void solve() { - cin >> n; - for (int i = 1; i <= n; ++i) { - cin >> c; - p[c] = i; - } - vector ans; - for (int i = 1; i <= n; ++i) { - for (int j = i + 1; j <= n; ++j) { - ans.emplace_back(j, i); - if (p[i] < p[j]) ans.emplace_back(i, j); - } - } - cout << ans.size() << '\n'; - for (auto &[x, y] : ans) cout << x << ' ' << y << '\n'; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t = 1; - //cin >> t; - rep (t) { - solve(); - } - return 0; -} - -/* -+---------------------------------------------+ -|GREY|GREEN|CYAN|BLUE|PURPLE|YELLOW|ORANGE|RED| -+---------------------------------------------+ -*/",1 -qfshen,2052A - Adrenaline Rush,c++17 ,300575240,300575272,"// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - set S; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - S.insert(i); - } - - vector ans; - - for(int i = n;i >= 1;i --) { - for(int j = 1;j < a[i];j ++) { - if(S.count(j) == 0) continue; - ans.push_back({a[i], j}); - } - S.erase(a[i]); - for(auto t : S) { - ans.push_back({t, a[i]}); - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -","// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - set S; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - S.insert(i); - } - - vector ans; - - for(int i = n;i >= 1;i --) { - for(int j = a[i] - 1;j >= 1;j --) { - if(S.count(j) == 0) continue; - ans.push_back({a[i], j}); - } - S.erase(a[i]); - for(auto t : S) { - ans.push_back({t, a[i]}); - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -",2 -varundandriyal72,2052A - Adrenaline Rush,c++23 ,297011530,297013221,"#include -using namespace std; - -int main() { - int n; - cin>>n; - vectorarr(n); - unordered_mapmp; - int count = 0; - vector>cd; - for(int i = 0;i>arr[i]; - mp[arr[i]] = i+1; - } - for(int i = 1;i mp[j]) - { - count++; - cd.push_back({j,i}); - } - else - { - count += 2; - cd.push_back({j, i}); - cd.push_back({i, j}); - } - } - } - cout< -using namespace std; - -int main() { - int n; - cin >> n; - vectorarr(n); - for (auto &i : arr)cin >> i; - vector>ans; - vectorou(n); - for (int i = 0; i < n; i++)ou[i] = i + 1; - for (int i = n; i >= 2; i--) - { - for (int j = i - 1; j >= 1; j--) - { - ans.push_back({i, j}); - } - } - mapmp; - int c = 0; - for (auto i : arr) - { - mp[i] = c; - c++; - } - for (int i = n - 1; i > 0; i--) - { - int cur = i; - for (int j = n - 1; j >= mp[i] + 1; j--) - { - if (arr[j] > cur) - { - ans.push_back({cur, arr[j]}); - } - } - } - - cout << ans.size(); - cout << endl; - for (auto i : ans)cout << i.first << "" "" << i.second << endl; - - - - - return 0; -} -",2 -NikhilKumar_11,2052A - Adrenaline Rush,c++23 ,304928597,304927671,"#include -using namespace std; -#define int long long int -void print(vector &a){ - // for(auto _ : a)cerr<<_<<"" ""; - cerr<>n; - vector a(n+1); - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - int ans = 0; - vector> res; - for(int i=1;i<=n;i++){ - for(int j=1;j a[j+1]){ - //incheck(); - res.push_back({a[j],a[j+1]}); - swap(a[j],a[j+1]); - } - //print(a); - } - } - reverse(res.begin(),res.end()); - cout< -using namespace std; -#define int long long int -void print(vector &a){ - for(auto _ : a)cerr<<_<<"" ""; - cerr<>n; - vector a(n+1); - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - int ans = 0; - vector> res; - for(int i=1;i<=n;i++){ - for(int j=1;j a[j+1]){ - //incheck(); - res.push_back({a[j+1],a[j]}); - swap(a[j+1],a[j]); - } - //print(a); - } - } - cout<> t; - - while (t--) { - solve(); - } - - return 0; -}",1 -Shivaji_67,2052A - Adrenaline Rush,c++17 ,297218136,297194948,"#include -using namespace std; -#define ll long long -const ll MOD18 = 1e18; -const ll MOD9 = 1e9+7; -const ll MOD = 998244353; -#define _endl ""\n"" -#define p2(num) (1LL << (num)) -#define _ceil(a, b) (ceil((double)(a) / (b))) -#define _floor(a, b) (floor((double)(a) / (b))) -#define all(a) a.begin(),a.end() -#define LL_MAX LLONG_MAX -#define LL_MIN LLONG_MIN -#define printVec(vec) for (auto &x : (vec)) cout << x << "" ""; cout << '\n'; -#define printRev(vec) for (auto it = (vec).rbegin(); it != (vec).rend(); ++it) cout << *it << "" ""; cout << '\n'; -#define f(i,start,end) for(int i=(start);i<(end);++i) -#define fe(i,start,end) for(int i=(start);i>=(end);--i) -#define CTB(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } reverse(bin.begin(), bin.end()); return bin; }(num)) -#define CTB32(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 33) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num)) -#define CTB64(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 64) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num)) -#define getUnique(arr) ([](auto& a) { sort(begin(a), end(a)); a.erase(unique(begin(a), end(a)), end(a)); return vector(begin(a), end(a)); })(arr) -#define checkPrime(num) ((num)<=1 ? false : (num)==2 || (num)==3 ? true : (num)%2==0 || (num)%3==0 ? false : ([](int n){for(int i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}(num))) -#define intn(p1, p2) ((p2.first < p1.first ? swap(p1, p2), 0 : 0), (p2.first > p1.second ? make_pair(LL_MAX, LL_MIN) : make_pair(max(p1.first, p2.first), min(p1.second, p2.second)))) -#define pof(b, exp, MOD) ({ long long ans = 1, base = (b) % (MOD), exp_copy = (exp); while (exp_copy) { if (exp_copy % 2) ans = (ans * base) % (MOD); base = (base * base) % (MOD); exp_copy /= 2; } ans; }) -#define IS_POWER(n) ([](long long n)->bool{if(n<=1)return false;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return true;return false;}(n)) -#define LARGEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=sqrt(n);b>=2;--b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n)) -#define SMALLEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n)) - - - -// using a>=b is more favourable as compared to a-b>=0, one problem gave TLE -// vector's size is returned in unsigned int and hence in minimum and maximum functions subtracting int from size can give error -// xor donot follow distributive property over + and - , but do follow over and and or operators -// in a multiset erasing a number directly using the ms.erase(num), will remove all the occurences, while doing that ms.erase(it.find(num)) will remove just one of the occurences -// also dont remove and erase while iterating using the auto it : method in a set or multiset -void solve() { - int n;cin>>n; - vectorv(n); - sets; - f(i,0,n){ - cin>>v[i]; - s.insert(v[i]); - } - vector>ans; - f(i,0,n){ - vectorv_; - for(auto it : s){ - if(it==v[i]){ - vectorv1; - int k=it+1; - while(k<=*(s.rbegin())){ - if(s.find(k)==s.end()){k++;continue;} - ans.push_back({k,v[i]}); - v1.push_back(k); - k++; - } - fe(j,v1.size()-1,0) ans.push_back({v[i],v1[j]}); - break; - } - else v_.push_back(it); - } - fe(j,v_.size()-1,0) {ans.push_back({v[i],v_[j]});} - s.erase(v[i]); - } - cout<> test; - while (test--) solve(); -}","#include -using namespace std; -#define ll long long -const ll MOD18 = 1e18; -const ll MOD9 = 1e9+7; -const ll MOD = 998244353; -#define _endl ""\n"" -#define p2(num) (1LL << (num)) -#define _ceil(a, b) (ceil((double)(a) / (b))) -#define _floor(a, b) (floor((double)(a) / (b))) -#define all(a) a.begin(),a.end() -#define LL_MAX LLONG_MAX -#define LL_MIN LLONG_MIN -#define printVec(vec) for (auto &x : (vec)) cout << x << "" ""; cout << '\n'; -#define printRev(vec) for (auto it = (vec).rbegin(); it != (vec).rend(); ++it) cout << *it << "" ""; cout << '\n'; -#define f(i,start,end) for(int i=(start);i<(end);++i) -#define fe(i,start,end) for(int i=(start);i>=(end);--i) -#define CTB(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } reverse(bin.begin(), bin.end()); return bin; }(num)) -#define CTB32(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 33) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num)) -#define CTB64(num) ([](long long n) { vector bin; while(n > 0) { bin.push_back(n % 2); n /= 2; } while(bin.size() < 64) bin.push_back(0); reverse(bin.begin(), bin.end()); return bin; }(num)) -#define getUnique(arr) ([](auto& a) { sort(begin(a), end(a)); a.erase(unique(begin(a), end(a)), end(a)); return vector(begin(a), end(a)); })(arr) -#define checkPrime(num) ((num)<=1 ? false : (num)==2 || (num)==3 ? true : (num)%2==0 || (num)%3==0 ? false : ([](int n){for(int i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}(num))) -#define intn(p1, p2) ((p2.first < p1.first ? swap(p1, p2), 0 : 0), (p2.first > p1.second ? make_pair(LL_MAX, LL_MIN) : make_pair(max(p1.first, p2.first), min(p1.second, p2.second)))) -#define pof(b, exp, MOD) ({ long long ans = 1, base = (b) % (MOD), exp_copy = (exp); while (exp_copy) { if (exp_copy % 2) ans = (ans * base) % (MOD); base = (base * base) % (MOD); exp_copy /= 2; } ans; }) -#define IS_POWER(n) ([](long long n)->bool{if(n<=1)return false;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return true;return false;}(n)) -#define LARGEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=sqrt(n);b>=2;--b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n)) -#define SMALLEST_BASE(n) ([](long long n)->long long{if(n<=1)return -1;for(long long b=2;b<=sqrt(n);++b)for(long long k=2;pow(b,k)<=n;++k)if(pow(b,k)==n)return b;return -1;}(n)) - - - -// using a>=b is more favourable as compared to a-b>=0, one problem gave TLE -// vector's size is returned in unsigned int and hence in minimum and maximum functions subtracting int from size can give error -// xor donot follow distributive property over + and - , but do follow over and and or operators -// in a multiset erasing a number directly using the ms.erase(num), will remove all the occurences, while doing that ms.erase(it.find(num)) will remove just one of the occurences -// also dont remove and erase while iterating using the auto it : method in a set or multiset -void comp(vector>&ans,vector&v,int num){ - if(v.size()<=1) return; - vectorv1,v2; - int idx=-1; - sets; - f(i,0,v.size()){ - if(v[i]==num){ - idx=i+1; - f(j,i+1,v.size()) v2.push_back(v[j]); - break; - } - s.insert(v[i]); - v1.push_back(v[i]); - } - for(auto it : s) ans.push_back({it,num}); - if(idx==1){ - comp(ans,v2,num+1); - // v1.push_back(v[idx-1]); - // f(j,0,v2.size()){ - // v1.push_back(v2[j]); - // fe(k,v1.size()-2,0) ans.push_back({v1.back(),v1[k]}); - // f(k,0,v1.size()-1) ans.push_back({v1[k],v1.back()}); - // } - } - else{ - comp(ans,v1,num+1); - comp(ans,v2,v[idx-2]+1); - - // v1.push_back(v[idx-1]); - // f(j,0,v2.size()){ - // v1.push_back(v2[j]); - // fe(k,v1.size()-2,0) ans.push_back({v1.back(),v1[k]}); - // f(k,0,v1.size()-1) ans.push_back({v1[k],v1.back()}); - // } - } -} -void solve() { - int n;cin>>n; - vectorv(n); - mapidx; - f(i,0,n){ - cin>>v[i]; - idx[v[i]]=i+1; - } - - vector>ans; - comp(ans,v,1); - vectorv1,v2; - v1.push_back(v[0]); - f(j,1,v.size()){ - v1.push_back(v[j]); - fe(k,v1.size()-2,0) if(v1.back()>v1[k]) ans.push_back({v1.back(),v1[k]}); - f(k,0,v1.size()-1) if(v1.back()>v1[k]) ans.push_back({v1[k],v1.back()}); - } - cout<> test; - while (test--) solve(); -}",1 -operator_01:55,2052A - Adrenaline Rush,c++20 ,298348781,298348746,"//Date: 2024-12-25 08:35:32 -#include -using namespace std; -#define int long long -inline int rd() { - int s=0,m=0;char ch=getchar(); - while(!isdigit(ch)) {if(ch=='-')m=1;ch=getchar();} - while( isdigit(ch)) s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); - return m?-s:s; -} -bool MBE; -namespace SOLVER { -int n,a[1005];vector> ans; -void MAIN() { - cin>>n;for(int i=1;i<=n;i++) a[i]=rd(); - for(int i=1;ii;j--) ans.emplace_back(a[j-1],a[j]),swap(a[j-1],a[j]); - assert(a[i]==i); - } - cout<=0;i--) printf(""%lld %lld\n"",ans[i].first,ans[i].second); -} -} -bool MED; -signed main() { - //freopen("".in"",""r"",stdin);freopen("".out"",""w"",stdout); - for(int tt=1;tt;tt--) SOLVER::MAIN(); - cerr<<(&MBE-&MED)/1024<<"" KB, ""<<1000*clock()/CLOCKS_PER_SEC<<"" ms\n""; - return 0; -}","//Date: 2024-12-25 08:35:32 -#include -using namespace std; -#define int long long -inline int rd() { - int s=0,m=0;char ch=getchar(); - while(!isdigit(ch)) {if(ch=='-')m=1;ch=getchar();} - while( isdigit(ch)) s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); - return m?-s:s; -} -bool MBE; -namespace SOLVER { -int n,a[1005];vector> ans; -void MAIN() { - cin>>n;for(int i=1;i<=n;i++) a[i]=rd(); - for(int i=1;ii;j--) ans.emplace_back(a[j],a[j-1]),swap(a[j-1],a[j]); - assert(a[i]==i); - } - cout< -#include -#include -#include -#include -using namespace std; -class list -{ -public: - int val; - list* next=nullptr; -}; - -int main() { - int n = 0; - cin >> n; - vector de(n); - vector pl(n+1); - list* head=new list; - - head->next = new list; - list* now = head->next; - now->val = 1; - vector> im; - for (int i = 0; i < n; ++i) - { - cin >> de[i]; - } - for (int i = 0; i < n; ++i) - { - pl[de[i]] = i ; - } - - for (int i = 2; i <= n; ++i) - { - int first=0; - list* now = head->next; - while (now != nullptr) - { - stack aa; - if (pl[now->val] > pl[i]) - { - { - pair ppp(i, now->val); - - im.push_back(ppp); - } - if (now->next == nullptr) - { - now->next = new list; - now->next->val = i; - break; - } - } - else - { - pair ppp(i, now->val); - aa.push(now->val); - im.push_back(ppp); - if (first == 0) - { - list* nxt = new list; - nxt->val = now->val; - nxt->next = now->next; - now->val = i; - now->next = nxt; - first = 1; - } - now = now->next; - while (now->next != nullptr) - { - aa.push(now->val); - pair ppp(i, now->val); - im.push_back(ppp); - now = now->next; - } - while (!aa.empty()) - { - pair ppp(aa.top(), i); im.push_back(ppp); - aa.pop(); - } - } - if (now != nullptr) - { - { - now = now->next; - } - } - } - } - cout << im.size() << endl; - for (auto a : im) - { - cout << a.first << "" "" << a.second << endl; - } - - return 0; - } -","#include -#include -#include -#include -#include -using namespace std; -class list -{ -public: - int val; - list* next=nullptr; -}; - -int main() { - int n = 0; - cin >> n; - vector de(n); - vector pl(n+1); - list* head=new list; - - head->next = new list; - list* now = head->next; - now->val = 1; - vector> im; - for (int i = 0; i < n; ++i) - { - cin >> de[i]; - } - for (int i = 0; i < n; ++i) - { - pl[de[i]] = i ; - } - - for (int i = 2; i <= n; ++i) - { - int first=0; - list* now = head->next; - while (now != nullptr) - { - stack aa; - if (pl[now->val] > pl[i]) - { - { - pair ppp(i, now->val); - - im.push_back(ppp); - } - if (now->next == nullptr) - { - now->next = new list; - now->next->val = i; - break; - } - } - else - { - pair ppp(i, now->val); - aa.push(now->val); - im.push_back(ppp); - if (first == 0) - { - list* nxt = new list; - nxt->val = now->val; - nxt->next = now->next; - now->val = i; - now->next = nxt; - first = 1; - } - now = now->next; - now = now->next; - while (now!= nullptr) - { - aa.push(now->val); - pair ppp(i, now->val); - im.push_back(ppp); - now = now->next; - } - while (!aa.empty()) - { - pair ppp(aa.top(), i); im.push_back(ppp); - aa.pop(); - } - } - if (now != nullptr) - { - { - now = now->next; - } - } - } - } - cout << im.size() << endl; - for (auto a : im) - { - cout << a.first << "" "" << a.second << endl; - } - //cout << n * (n - 1); - return 0; - } -",2 -A7med_Sayed,2052A - Adrenaline Rush,c++20 ,307203089,307204769,"#include -using namespace std; -#define ll long long -int x[]={0,0,-1,1}; -int y[]={-1,1,0,0}; -char dir[]={'L','R','U','D'}; -using pi = pair; - -void fast() { -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - - -void solve() { - ll n; - cin>>n; - vector v(n); - for(ll i=0;i>v[i]; - } - vectorans; - for(ll i=n-1;i>=0;i--) { - for(ll j=i+1;j> T; - while (T--) { - solve(); - - } - return 0; -} -","#include -using namespace std; -#define ll long long -int x[]={0,0,-1,1}; -int y[]={-1,1,0,0}; -char dir[]={'L','R','U','D'}; -using pi = pair; - -void fast() { -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - - -void solve() { - ll n; - cin>>n; - vector ans; - map vis; - for (int i = 0; i < n; i++) { - int x; - cin >> x; - vis[x] = 1; - for (int j = x + 1; j <= n; j++) { - if (vis[j]) continue; - ans.push_back({j, x}); - } - for (int j = n; j > x; j--) { - if (vis[j]) continue; - ans.push_back({x, j}); - } - for (int j = x - 1; j; j--) { - if (vis[j]) continue; - ans.push_back({x, j}); - } - } - cout << ans.size(); - for (auto &i : ans) cout << '\n' << i.first << ' ' << i.second; - - - -} - - -int main() { - fast(); - - int T = 1; - // cin >> T; - while (T--) { - solve(); - - } - return 0; -} -",2 -testtest111ksjfrdvn,2052A - Adrenaline Rush,java,303157874,303157588,"import java.io.*; -import java.util.*; - -public class Main -{ - public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - public static StringTokenizer tokenizer; - public static void read() throws IOException { - tokenizer = new StringTokenizer(br.readLine()); - } - public static int Int() throws IOException { - if (tokenizer == null || !tokenizer.hasMoreTokens()) read(); - return Integer.parseInt(tokenizer.nextToken()); - } - public static long Long() throws IOException { - if (tokenizer == null || !tokenizer.hasMoreTokens()) read(); - return Long.parseLong(tokenizer.nextToken()); - } - public static String Str() throws IOException { - return br.readLine(); - } - - public static Character Char() throws IOException { - return (char)br.read(); - } - - public static long[] read(int n) throws IOException { - long[] a = new long[n]; - for (int i = 0; i < n; i++) { - a[i] = Long() - 1; - } - return a; - } - - //----------------------------------------------- - - public static long MOD = (long) 1e9 + 7; - public static long quickPow(long pow, long num, long MOD) { - if (pow == 0) { - return 1; - } - if (pow == 1) { - return num % MOD; - } - long half = quickPow(pow / 2, num, MOD); - long twoHalf = (half * half) % MOD; - return (twoHalf * quickPow(pow % 2, num, MOD)) % MOD; - } - - public static void remove(TreeMap map, long key) { - map.put(key, map.get(key) - 1); - if (map.get(key) == 0) map.remove(key); - } - - public static void remove(HashMap map, long key) { - map.put(key, map.get(key) - 1); - if (map.get(key) == 0) map.remove(key); - } - - public static void add(TreeMap map, long key) { - map.put(key, map.getOrDefault(key, 0L) + 1); - } - - public static void add(HashMap map, long key) { - map.put(key, map.getOrDefault(key, 0L) + 1); - } - - - - - public static void main(String[] args) throws IOException { - int T = 1; - while (T > 0) { - T--; - int n = Int(); - int[] a = new int[n]; - int[] start = new int[n]; - HashMap pos = new HashMap<>(); - for (int i = 0; i < n; i++) { - a[i] = Int(); - start[i] = i + 1; - pos.put(i + 1, i); - } - ArrayList res = new ArrayList<>(); - for (int i = n - 1; i >= 0; i--) { - int position = pos.get(a[i]); - for (int j = position; j > 0; j--) { - res.add(new int[] {start[j], start[j - 1]}); - pos.put(start[j], j - 1); - pos.put(start[j - 1], j); - int tmp = start[j]; - start[j] = start[j - 1]; - start[j - 1] = tmp; - } - } - System.out.println(res.size()); - for (int i = 0; i < res.size(); i++) { - System.out.println(res.get(i)[0] + "" "" + res.get(i)[1]); - } - } - } -}","import java.io.*; -import java.util.*; - -public class Main -{ - public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - public static StringTokenizer tokenizer; - public static void read() throws IOException { - tokenizer = new StringTokenizer(br.readLine()); - } - public static int Int() throws IOException { - if (tokenizer == null || !tokenizer.hasMoreTokens()) read(); - return Integer.parseInt(tokenizer.nextToken()); - } - public static long Long() throws IOException { - if (tokenizer == null || !tokenizer.hasMoreTokens()) read(); - return Long.parseLong(tokenizer.nextToken()); - } - public static String Str() throws IOException { - return br.readLine(); - } - - public static Character Char() throws IOException { - return (char)br.read(); - } - - public static long[] read(int n) throws IOException { - long[] a = new long[n]; - for (int i = 0; i < n; i++) { - a[i] = Long() - 1; - } - return a; - } - - //----------------------------------------------- - - public static long MOD = (long) 1e9 + 7; - public static long quickPow(long pow, long num, long MOD) { - if (pow == 0) { - return 1; - } - if (pow == 1) { - return num % MOD; - } - long half = quickPow(pow / 2, num, MOD); - long twoHalf = (half * half) % MOD; - return (twoHalf * quickPow(pow % 2, num, MOD)) % MOD; - } - - public static void remove(TreeMap map, long key) { - map.put(key, map.get(key) - 1); - if (map.get(key) == 0) map.remove(key); - } - - public static void remove(HashMap map, long key) { - map.put(key, map.get(key) - 1); - if (map.get(key) == 0) map.remove(key); - } - - public static void add(TreeMap map, long key) { - map.put(key, map.getOrDefault(key, 0L) + 1); - } - - public static void add(HashMap map, long key) { - map.put(key, map.getOrDefault(key, 0L) + 1); - } - - - - - public static void main(String[] args) throws IOException { - int T = 1; - while (T > 0) { - T--; - int n = Int(); - int[] a = new int[n]; - int[] start = new int[n]; - HashMap pos = new HashMap<>(); - for (int i = 0; i < n; i++) { - a[i] = Int(); - pos.put(a[i], i); - start[i] = i + 1; - } - ArrayList res = new ArrayList<>(); - for (int i = n - 1; i >= 0; i--) { - int position = pos.get(a[i]); - for (int j = position; j > 0; j--) { - res.add(new int[] {start[j], start[j - 1]}); - pos.put(start[j], j - 1); - pos.put(start[j - 1], j); - int tmp = start[j]; - start[j] = start[j - 1]; - start[j - 1] = tmp; - } - } - System.out.println(res.size()); - for (int i = 0; i < res.size(); i++) { - System.out.println(res.get(i)[0] + "" "" + res.get(i)[1]); - } - } - } -}",1 -akhaja_D6255,2052A - Adrenaline Rush,c++23 ,306184669,306184998,"#include -#define Akhaja ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL); -#include -#define ll long long -using namespace std; - -void init(){ - // Now its my turn -} - -void solve(){ - ll n; - cin>>n; - vectora(n); - for(ll i=0;i>a[i]; - } - set> mali; - vector> ans; - vector pos(n); - map mp; - for(ll i=0;i=idx+1;j--){ - if(mali.find({bando,pos[j]})==mali.end()){ - ans.push_back({bando,pos[j]}); - mali.insert({bando,pos[j]}); - } - } - for(ll j=idx-1;j>=0;j--){ - if(mali.find({bando,pos[j]})==mali.end()){ - ans.push_back({bando,pos[j]}); - mali.insert({bando,pos[j]}); - } - mp[bando]--; - mp[pos[j]]++; - pos[j+1]=pos[j]; - } - pos[i]=bando; - - // for(auto it:pos){ - // cout<>t; - // while(t--){ - solve(); - // } - return 0; -}","#include -#define Akhaja ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL); -#include -#define ll long long -using namespace std; - -void init(){ - // Now its my turn -} - -void solve(){ - ll n; - cin>>n; - vectora(n); - for(ll i=0;i>a[i]; - } - set> mali; - vector> ans; - vector pos(n); - map mp; - for(ll i=0;i=idx+1;j--){ - if(mali.find({bando,pos[j]})==mali.end()){ - ans.push_back({bando,pos[j]}); - mali.insert({bando,pos[j]}); - } - } - for(ll j=idx-1;j>=i;j--){ - if(mali.find({bando,pos[j]})==mali.end()){ - ans.push_back({bando,pos[j]}); - mali.insert({bando,pos[j]}); - } - mp[bando]--; - mp[pos[j]]++; - pos[j+1]=pos[j]; - } - pos[i]=bando; - - // for(auto it:pos){ - // cout<>t; - // while(t--){ - solve(); - // } - return 0; -}",2 -xhf,2052A - Adrenaline Rush,c++20 ,305895804,305896221,"#include -#include -using namespace std; - -int n; -int c[1100]; -int v[1100][1100] = {0}; -int main() -{ - - vector> ans; - cin >> n; - for (int i = 1; i <= n; i++) - cin >> c[i]; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] > c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - else if (v[c[j]][c[j + 1]] == 0) - { - ans.push_back({c[j], c[j + 1]}); - ans.push_back({c[j + 1], c[j]}); - v[c[j]][c[j + 1]] == 1; - } - } - - cout << ans.size() << endl; - for (int i = (int)ans.size() - 1; i >= 0; i--) - cout << ans[i].first << "" "" << ans[i].second << endl; - - system(""pause""); - return 0; -}","#include -#include -using namespace std; - -int n; -int c[1100]; -int v[1100][1100] = {0}; -int main() -{ - - vector> ans; - cin >> n; - for (int i = 1; i <= n; i++) - cin >> c[i]; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] < c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - } - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] > c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - } - cout << ans.size() << endl; - for (int i = (int)ans.size() - 1; i >= 0; i--) - cout << ans[i].first << "" "" << ans[i].second << endl; - - system(""pause""); - return 0; -}",2 -Zero.2,2052A - Adrenaline Rush,c++23 ,298792700,298793212,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define int long long -using namespace std; - -int cnt = 1; -void solve() { - int n; - cin >> n; - int final[n]; - vector cur(n); - for (auto& e : final) { - cin >> e; - } - for (int i = 0; i < n; i++) { - cur[i] = cnt++; - } - - cnt = 0; - /*int overtake[n + 1][n + 1]; - for (int i = 0; i <= n; i++) { - memset(overtake[i], 0, sizeof(overtake[i])); - }*/ - for (int i = 0; i < n; i++) { - int index; - for (int j = n - 1; j >= 0; j--) { - if (cur[j] == final[i]) { - index = j; - break; - } - } - for (int j = index + 1; j < n; j++) { - cout << cur[j] << ' ' << final[i] << endl; - cnt++; - } - for (int j = n - 1; j > index; j--) { - cout << final[i] << ' ' << cur[j] << endl; - cnt++; - } - for (int j = index - 1; j >= i; j--) { - cout << final[i] << ' ' << cur[j] << endl; - cnt++; - } - cur.erase(cur.begin() + index); - cur.insert(cur.begin() + i, final[i]); - } - cout << cnt; -} - -signed main() { - ios::sync_with_stdio(false); cin.tie(0); - int t = 1; - //cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define int long long -using namespace std; - -int cnt = 1; -void solve() { - int n; - cin >> n; - int final[n]; - vector cur(n); - for (auto& e : final) { - cin >> e; - } - for (int i = 0; i < n; i++) { - cur[i] = cnt++; - } - - cnt = 0; - vector res; - /*int overtake[n + 1][n + 1]; - for (int i = 0; i <= n; i++) { - memset(overtake[i], 0, sizeof(overtake[i])); - }*/ - for (int i = 0; i < n; i++) { - int index; - for (int j = n - 1; j >= 0; j--) { - if (cur[j] == final[i]) { - index = j; - break; - } - } - for (int j = index + 1; j < n; j++) { - //cout << cur[j] << ' ' << final[i] << endl; - res.push_back(cur[j]); - res.push_back(final[i]); - cnt++; - } - for (int j = n - 1; j > index; j--) { - //cout << final[i] << ' ' << cur[j] << endl; - res.push_back(final[i]); - res.push_back(cur[j]); - cnt++; - } - for (int j = index - 1; j >= i; j--) { - //cout << final[i] << ' ' << cur[j] << endl; - res.push_back(final[i]); - res.push_back(cur[j]); - cnt++; - } - cur.erase(cur.begin() + index); - cur.insert(cur.begin() + i, final[i]); - } - - cout << cnt << endl; - for (int i = 0; i < res.size(); i += 2) { - cout << res[i] << "" "" << res[i + 1] << endl; - } -} - -signed main() { - ios::sync_with_stdio(false); cin.tie(0); - int t = 1; - //cin >> t; - while (t--) { - solve(); - } - return 0; -}",2 -dhruvpansuriya05,2052A - Adrenaline Rush,c++17 ,296818367,296813817,"#include -#define ll long long int -using namespace std; -int main() -{ - ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); - int n; - cin>>n; - vector pos(n+1); - vector v(n+1); - - for (int i = 1; i <= n; i++) - { - int x; - cin>>x; - v[i] = x; - pos[x] = i; - } - - vector > ans; - - for(int i=1;i<=n;i++){ - int car = i; - stack > st1; - - for(int j = pos[car] + 1; j<=n;j++){ - if(v[j] < car){ - // cout< ""< p = st1.top(); - st1.pop(); - // cout< ""< > st; - - for(int j = pos[car]-1; j>=1; j--){ - if(v[j] < car){ - // cout< ""< p = st.top(); - st.pop(); - // cout< ""< -#define ll long long int -using namespace std; -int main() -{ - ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); - int n; - cin>>n; - vector pos(n+1); - - for (int i = 1; i <= n; i++) - { - int x; - cin>>x; - pos[x] = i; - } - - vector > ans; - - for(int i=1;i<=n;i++){ - for(int j=i+1;j<=n;j++){ - if(pos[i] < pos[j]){ - ans.push_back(make_pair(j,i)); - ans.push_back(make_pair(i,j)); - }else{ - ans.push_back(make_pair(j,i)); - } - } - } - - cout< -#include -#include - -using namespace std; - -int main() -{ - long long n, i, j; - - cin >> n; - - long long* c = new long long[n]; - - for (i = 0; i < n; i++) - { - cin >> c[i]; - } - - long long num_inverse = 0; - - for (i = 0; i < n; i++) - { - for (j = i; j < n; j++) - { - if (c[i] > c[j]) - { - num_inverse++; - } - } - } - - long long num_pass = n * (n - 1) - num_inverse; - - vector arr; - - long long* pos_arr = new long long[n + 1]; - - for (i = 0; i < n; i++) - { - arr.push_back(i + 1); - - pos_arr[i + 1] = i; - } - - cout << num_pass << endl; - - for (i = 1; i < n + 1; i++) - { - long long pos = pos_arr[c[i - 1]]; - - for (j = pos + 1; j < n; j++) - { - cout << arr[j] << "" "" << c[i - 1] << endl; - } - - for (j = n - 1; j >= i; j--) - { - if (j != pos) - { - cout << c[i - 1] << "" "" << arr[j] << endl; - } - - if (j < pos) - { - pos_arr[arr[j]]++; - } - } - - arr.erase(arr.begin() + pos); - - arr.insert(arr.begin() + pos, c[i - 1]); - - pos_arr[c[i - 1]] = i - 1; - } - - return 0; -}","#include -#include -#include - -using namespace std; - -int main() -{ - long long n, i, j; - - cin >> n; - - long long* c = new long long[n]; - - for (i = 0; i < n; i++) - { - cin >> c[i]; - } - - long long num_inverse = 0; - - for (i = 0; i < n; i++) - { - for (j = i; j < n; j++) - { - if (c[i] > c[j]) - { - num_inverse++; - } - } - } - - long long num_pass = n * (n - 1) - num_inverse; - - vector arr; - - long long* pos_arr = new long long[n + 1]; - - for (i = 0; i < n; i++) - { - arr.push_back(i + 1); - - pos_arr[i + 1] = i; - } - - cout << num_pass << endl; - - for (i = 1; i < n + 1; i++) - { - long long pos = pos_arr[c[i - 1]]; - - for (j = pos + 1; j < n + 1 - i; j++) - { - cout << arr[j] << "" "" << c[i - 1] << endl; - } - - for (j = n - i; j >= 0; j--) - { - if (j != pos) - { - cout << c[i - 1] << "" "" << arr[j] << endl; - } - - if (j > pos) - { - pos_arr[arr[j]]--; - } - } - - arr.erase(arr.begin() + pos); - } - - return 0; -}",2 -Dhruv_Garg07,2052A - Adrenaline Rush,c++20 ,296556618,296559071,"#include ""bits/stdc++.h"" -using namespace std; - -#define pb push_back -#define ll long long int -#define mp make_pair -#define MAXN 100001 - -#define sz(x) static_cast((x).size()) -#define all(x) (x).begin(), (x).end() -#define input(v) for(ll i=0;i<(long long int)v.size();i++) cin>>v[i]; -ll MOD=998244353; -void YES() {cout<<""YES""<=b) return a; - return b; -} -ll gcd(ll a,ll b) -{ - ll x1=min(a,b); - ll x2=max(a,b); - if(x1<=0) return x2; - ll x=x2%x1; - return gcd(x,x1); -} -void print(vector&v){ - ll n=(ll)v.size(); - for(ll j=0;j 0) { - if (y & 1) - res = (res * x) % p; - y = y >> 1; - x = (x * x) % p; - } - return res; -} -ll modInverse(ll n, ll p){ - return power(n, p - 2, p); -} - -void solve(){ - ll n; - cin>>n; - vectora(n); - input(a); - vector>v; - mapm; - for(ll i=0;i B, E; public: Timer () : B(), E() - { B = chrono::steady_clock::now(); } ~Timer () { E = chrono::steady_clock::now(); - cerr << ""\nDuration: "" << ((chrono::duration )(E - B)).count() << ""s\n""; } } TimerT; - #endif - // For faster Input/Output - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t = 1; - // cin>>t; - while(t--) solve(); -}","#include ""bits/stdc++.h"" -using namespace std; - -#define pb push_back -#define ll long long int -#define mp make_pair -#define MAXN 100001 - -#define sz(x) static_cast((x).size()) -#define all(x) (x).begin(), (x).end() -#define input(v) for(ll i=0;i<(long long int)v.size();i++) cin>>v[i]; -ll MOD=998244353; -void YES() {cout<<""YES""<=b) return a; - return b; -} -ll gcd(ll a,ll b) -{ - ll x1=min(a,b); - ll x2=max(a,b); - if(x1<=0) return x2; - ll x=x2%x1; - return gcd(x,x1); -} -void print(vector&v){ - ll n=(ll)v.size(); - for(ll j=0;j 0) { - if (y & 1) - res = (res * x) % p; - y = y >> 1; - x = (x * x) % p; - } - return res; -} -ll modInverse(ll n, ll p){ - return power(n, p - 2, p); -} - -void solve(){ - ll n; - cin>>n; - vectora(n); - input(a); - set>s; - mapm; - for(ll i=0;iv1; - for(ll i=1;i<=n;i++) v1.pb(i); - ll i=0; - vector>ans; - while(i=0){ - pairp={v1[i],v1[i-1]}; - if(s.find(p)!=s.end()){ - swap(v1[i-1],v1[i]); - i--; - s.erase(p); - ans.pb(p); - continue; - } - } - if(i+1p={v1[i+1],v1[i]}; - if(s.find(p)!=s.end()){ - swap(v1[i],v1[i+1]); - s.erase(p); - ans.pb(p); - continue; - } - } - i++; - } - for(auto i:ans) cout< B, E; public: Timer () : B(), E() - { B = chrono::steady_clock::now(); } ~Timer () { E = chrono::steady_clock::now(); - cerr << ""\nDuration: "" << ((chrono::duration )(E - B)).count() << ""s\n""; } } TimerT; - #endif - // For faster Input/Output - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t = 1; - // cin>>t; - while(t--) solve(); -}",2 -"CoU_Inheritance++: MD.Abdullah, RakibJoy, Mhkhan#",2052A - Adrenaline Rush,c++20 ,298959733,298958825,"//starting with the name of almighty ALLAH -// Practice is the only shortcut to improve -#include -#define ll long long -#define pb push_back -#define vc vector -#define vi vc -#define vl vc -#define mp(x,y) make_pair(x,y) -#define yes cout<<""YES""<<'\n'; -#define no cout<<""NO""<<'\n'; -#define tst int t;cin>>t;while(t--) -#define srt(v) sort(v.begin(),v.end()); -#define rsrt(v) sort(v.rbegin(),v.rend()); -#define rj ios::sync_with_stdio(false);cin.tie(0); -#define rvs(v) reverse(v.begin(),v.end()); -#define F first -#define S second -#define MOD 1000000007 -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) (a*b)/gcd(a,b) -#define PI 2*acos(0.0) -#define pii pair -#define fr(i,a,b) for(int i=a;i<=b;i++) -#define coutv(v) for(auto it:v)cout<>it; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define ld long double -#define nl '\n' -const int N = 1e5; -using namespace std; -/* #ifndef ONLINE_JUDGE -#include ""algo/debug.h"" -#else -#define dbg(x...) -#endif */ -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -int my_rand(int l, int r) -{ - return uniform_int_distribution(l, r) (rng); -} -void solve() -{ - int a; - cin >> a;; - vectorv(a + 1), in(a + 1); - for (int i = 1; i <= a; i++) - { - cin >> v[i]; - in[v[i]] = i; - } - vectoran; - for (int i = 1; i <= a; i++) - { - while (in[i] < a) - { - int nx = v[in[i] + 1]; - an.push_back({i, nx}); - swap(in[i], in[nx]); - swap(v[in[i]], v[in[nx]]); - } - while (in[i] > i) - { - int nx = v[in[i] - 1]; - an.push_back({nx, i}); - swap(in[i], in[nx]); - swap(v[in[i]], v[in[nx]]); - } - } - rvs(an) - cout << (int)an.size() << nl; - for (auto &it : an) - { - cout << it.F << ' ' << it.S << nl; - } -} -int main() -{ - /*#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif // ONLINE_JUDGE*/ - rj - //int t;cin>>t;fr(i,1,t) cout<<""Case ""< -#define ll long long -#define pb push_back -#define vc vector -#define vi vc -#define vl vc -#define mp(x,y) make_pair(x,y) -#define yes cout<<""YES""<<'\n'; -#define no cout<<""NO""<<'\n'; -#define tst int t;cin>>t;while(t--) -#define srt(v) sort(v.begin(),v.end()); -#define rsrt(v) sort(v.rbegin(),v.rend()); -#define rj ios::sync_with_stdio(false);cin.tie(0); -#define rvs(v) reverse(v.begin(),v.end()); -#define F first -#define S second -#define MOD 1000000007 -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) (a*b)/gcd(a,b) -#define PI 2*acos(0.0) -#define pii pair -#define fr(i,a,b) for(int i=a;i<=b;i++) -#define coutv(v) for(auto it:v)cout<>it; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define ld long double -#define nl '\n' -const int N = 1e5; -using namespace std; -/* #ifndef ONLINE_JUDGE -#include ""algo/debug.h"" -#else -#define dbg(x...) -#endif */ -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -int my_rand(int l, int r) -{ - return uniform_int_distribution(l, r) (rng); -} -void solve() -{ - int a; - cin >> a;; - vectorv(a + 1), in(a + 1); - for (int i = 1; i <= a; i++) - { - cin >> v[i]; - in[v[i]] = i; - } - vectoran; - for (int i = 1; i <= a; i++) - { - while (in[i] < a) - { - int nx = v[in[i] + 1]; - an.push_back({nx, i}); - swap(in[i], in[nx]); - swap(v[in[i]], v[in[nx]]); - } - while (in[i] > i) - { - int nx = v[in[i] - 1]; - an.push_back({i, nx}); - swap(in[i], in[nx]); - swap(v[in[i]], v[in[nx]]); - } - } - cout << (int)an.size() << nl; - for (auto &it : an) - { - cout << it.F << ' ' << it.S << nl; - } -} -int main() -{ - /*#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif // ONLINE_JUDGE*/ - rj - //int t;cin>>t;fr(i,1,t) cout<<""Case ""< -using namespace std; -vector> ns; -vector cur; -vector pos; -vector x; -vector> v; -bool d = false; - -void f(int it, int y, int j){ - int co = 0; - it--; - if(it != - 1){ - while((cur[it] <= j && !v[cur[it]][cur[it+1]] && !v[cur[it+1]][cur[it]]) || (d && it >= y)){ - v[cur[it+1]][cur[it]] = true; - ns.push_back({cur[it+1], cur[it]}); - swap(cur[it], cur[it+1]); - it--; - if(it == -1){ - break; - } - } - } - it++; - while(it < y){ - v[cur[it+1]][cur[it]] = true; - ns.push_back({cur[it+1], cur[it]}); - swap(cur[it], cur[it+1]); - it++; - } -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int n; cin >> n; - v.resize(n+1, vector(n+1)); - x.resize(n); - pos.resize(n+1); - for(int i = 0; i < n; i++){ - cin >> x[i]; - pos[x[i]] = i; - } - cur.resize(n); - for(int i = 0; i < n; i++){ - cur[i] = i+1; - } - for(int y = 0; y < n; y++){ - int it = 0; - for(int i = 0; i < n; i++){ - if(cur[i] == x[y]){ - it = i; - break; - } - } - for(int i = y; i <= it; i++){ - d = false; - if(i == it){ - d = true; - } - f(i, y, cur[i]); - } - } - cout << ns.size() << ""\n""; - for(int y = 0; y < ns.size(); y++){ - cout << ns[y].first << "" "" << ns[y].second << ""\n""; - } - return 0; -} - -//3 1 4 2 -//1 2 3 4 -//2 1 3 4 -//2 3 1 4 -//3 2 1 4 -//3 1 2 4 -//3 1 4 2 -//3 4 1 2 -//4 3 1 2 -//3 4 1 2 -//3 1 4 2 -","#include -using namespace std; -vector> ns; -vector cur; -vector x; - -void f(int it, int y, int j){ - int co = 0; - it--; - if(it != - 1){ - while(cur[it] <= j){ - ns.push_back({cur[it+1], cur[it]}); - swap(cur[it], cur[it+1]); - it--; - if(it == -1){ - break; - } - } - } - it++; - while(it < y){ - ns.push_back({cur[it+1], cur[it]}); - swap(cur[it], cur[it+1]); - it++; - } -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int n; cin >> n; - x.resize(n); - for(int i = 0; i < n; i++){ - cin >> x[i]; - } - cur.resize(n); - for(int i = 0; i < n; i++){ - cur[i] = i+1; - } - for(int y = 0; y < n; y++){ - int it = 0; - for(int i = 0; i < n; i++){ - if(cur[i] == x[y]){ - it = i; - break; - } - } - for(int i = y; i <= it; i++){ - f(i, y, cur[i]); - } - } - cout << ns.size() << ""\n""; - for(int i = 0; i < ns.size(); i++){ - cout << ns[i].first << "" "" << ns[i].second << ""\n""; - } - return 0; -} - -//5 -//1 2 3 -//2 3 1 -//",1 -Werdnight,2052A - Adrenaline Rush,c++23 ,300597926,300603533,"#include - -using namespace std; - -void solve(){ - int64_t n; - cin >> n; - vectorc(n); - for (int i = 0; i < n; i++){ - cin >> c[i]; - } - if (n == 1){ - cout << 0; - } - else{ - int ans = 0; - vector>matrix(n + 1, vector(n + 1, 0)); - vectorstart(n, n); - for (int i = 0; i < n; i++){ - start[i] = i + 1; - } - vector>ans_; - for (int i = 0; i < n; i++){ - while(c[i] != start[i]){ - int j = i; - while(c[j] != start[j]){ - matrix[min(start[j], start[j + 1])][max(start[j], start[j + 1])] = 1; - pairtemp; - temp.first = start[j + 1]; - temp.second = start[j]; - ans_.push_back(temp); - ans += 1; - swap(start[j], start[j + 1]); - j += 1; - } - } - } - for (int i = 1; i < n; i++){ - pairtemp; - int64_t j = i - 1; - while(j >= 0){ - if (matrix[min(c[i], c[j])][max(c[i], c[j])] == 0){ - ans += 1; - temp.first = c[i]; - temp.second = c[j]; - ans_.push_back(temp); - j -= 1; - } - else{ - break; - } - } - j += 1; - for (int64_t z = j; z < i; z++){ - ans += 1; - temp.first = c[z]; - temp.second = c[i]; - ans_.push_back(temp); - } - } - cout << ans << endl; - for (int i = 0; i < ans; i++){ - cout << ans_[i].first << ' ' << ans_[i].second << endl; - } - } -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(0), cout.tie(0), cout.precision(16); - int t = 1; - // cin >> t; - while(t--){ - solve(); - cout << endl; - } -}","#include - -using namespace std; - -void solve(){ - int64_t n; - cin >> n; - vectorc(n); - for (int i = 0; i < n; i++){ - cin >> c[i]; - } - if (n == 1){ - cout << 0; - } - else{ - int ans = 0; - vector>matrix(n + 1, vector(n + 1, 0)); - vectorstart(n, n); - for (int i = 0; i < n; i++){ - start[i] = i + 1; - } - vector>ans_; - while (start[0] != n){ - int i = 0; - int j = n - start[0]; - while (i != j){ - pairtemp; - temp.first = start[i + 1]; - temp.second = start[i]; - ans_.push_back(temp); - ans += 1; - swap(start[i], start[i + 1]); - i += 1; - } - } - for (int i = 0; i < n; i++){ - int j = 0; - while (start[j] != c[i]){ - j += 1; - } - if (j > i){ - while(j != i){ - matrix[min(start[j], start[j - 1])][max(start[j], start[j - 1])] = 1; - pairtemp; - temp.first = start[j]; - temp.second = start[j - 1]; - ans_.push_back(temp); - ans += 1; - swap(start[j], start[j - 1]); - j -= 1; - } - } - else{ - while(j != i){ - matrix[min(start[j], start[j + 1])][max(start[j], start[j + 1])] = 1; - pairtemp; - temp.first = start[j + 1]; - temp.second = start[j]; - ans_.push_back(temp); - ans += 1; - swap(start[j], start[j + 1]); - j += 1; - } - } - } - cout << ans << endl; - for (int i = 0; i < ans; i++){ - cout << ans_[i].first << ' ' << ans_[i].second << endl; - } - } -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(0), cout.tie(0), cout.precision(16); - int t = 1; - // cin >> t; - while(t--){ - solve(); - cout << endl; - } -}",2 -lakshyatyagi,2052A - Adrenaline Rush,c++23 ,300944547,300944713,"#include -#include -using namespace std; - -using ll = long long; -const ll mod = 1e9 + 7; -const ll modd = 998244353; - - -void solve() { - ll n; - cin>>n; - vectora(n), b; - for(auto&i:a) cin>>i; - b = a; - vector>v; - for(ll i = 0; ib[j+1]){ - swap(b[j], b[j+1]); - v.push_back({b[j], b[j+1]}); - } - } - } - reverse(v.begin(), v.end()); - - cout<> t; - - while (t--) solve(); - - return 0; -}","#include -#include -using namespace std; - -using ll = long long; -const ll mod = 1e9 + 7; -const ll modd = 998244353; - - -void solve() { - ll n; - cin>>n; - vectora(n), b; - for(auto&i:a) cin>>i; - b = a; - vector>v; - for(ll i = 0; ib[j+1]){ - swap(b[j], b[j+1]); - v.push_back({b[j], b[j+1]}); - } - } - } - reverse(v.begin(), v.end()); - - cout<> t; - - while (t--) solve(); - - return 0; -}",2 -aur1ga,2052A - Adrenaline Rush,c++17 ,300944864,300942639,"#include -#define ll long long -using namespace std; - -void solve(){ - int n; - cin>>n; - vector v(n); - for (int i = 0; i < n; i++) - { - cin>>v[i]; - } - - // ll cnt=0; - vector> ans; - - set s; - for (int i = 0; i < n; i++) - { - for (int j = v[i]+1; j <= n; j++) - { - if(s.find(j)!=s.end()) continue; - ans.push_back({j,v[i]}); - } - for (int j = n; j >= 1; j--) - { - if(j==v[i]) continue; - if(s.find(j)!=s.end()) continue; - ans.push_back({v[i],j}); - } - s.insert(v[i]); - } - - - cout<>t; - while(t--){ - solve(); - } - return 0; -}","#include -#define ll long long -using namespace std; - -void solve(){ - int n; - cin>>n; - vector v(n); - for (int i = 0; i < n; i++) - { - cin>>v[i]; - } - - // ll cnt=0; - vector> ans; - for (int i = 1; i <= n; i++) - { - // bool flag=true; - for (int j = 0; j < n; j++) - { - if(v[j]==i){ - // flag=false; - break; - } - if(v[j]>i){ - ans.push_back({v[j],i}); - } - else if(v[j]>t; - while(t--){ - solve(); - } - return 0; -}",1 -amit152004,2052A - Adrenaline Rush,c++17 ,298411963,298412917,"#include -using namespace std; -int main(){ - int n; - cin>>n; - vectorarr(n+1,0); - vectorbrr(n); - int cnt=0; - for(int i=0;i>brr[i]; - arr[brr[i]]=1; - for(int j=1;j>brr[i]; - arr[brr[i]]=1; - - for(int j=brr[i];j<=n;j++){ - if(arr[j]==0){ - cout< -using namespace std; -int main(){ - int n; - cin>>n; - vectorarr(n+1,0); - vectorbrr(n); - int cnt=0; - for(int i=0;i>brr[i]; - arr[brr[i]]=1; - for(int j=1;j>brr[i]; - arr[brr[i]]=1; - - for(int j=brr[i];j<=n;j++){ - if(arr[j]==0){ - cout<=brr[i];j--){ - if(arr[j]==0){ - cout<0;j--){ - if(arr[j]==0){ - cout< -#define ll long long -#define ld long double -#define eb emplace_back -#define task """" -#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); -#define nx freopen (task"".inp"",""r"",stdin), freopen (task"".out"",""w"",stdout); -#define fi first -#define se second -#define pii pair -#define tii tuple -#define all(s) s.begin(), s.end() -using namespace std; - -void solve() -{ - int n; - cin >> n; - vector c(n), mp(n + 2, 0); - for (auto &i : c) cin >> i; //thứ tự gần vạch xuất phát của từng xe - vector ans; - for (int i = n - 1; i >= 0; --i) - { - mp[c[i]] = 1; - for (int j = c[i] - 1; j > 0; --j) - if (!mp[j]) - ans.eb(c[i], j); - for (int j = n - 1; j > i; --j) - ans.eb(c[i], c[j]); - } - cout << ans.size() << '\n'; - for (auto &[u, v] : ans) - cout << u << ' ' << v << '\n'; -} - -int main() -{ - if (ifstream(task"".inp"")) nx - fast - - solve(); -} -","#include -#include -#include -#include - -using namespace std; - -int main() { - int n; - cin >> n; - - vector final_order(n); - for (int i = 0; i < n; ++i) { - cin >> final_order[i]; - } - - if (n <= 1) { - cout << 0 << endl; - return 0; - } - - vector> overtakes; - if (n == 2) { - if (final_order[0] != 1 || final_order[1] != 2) { - cout << 1 << endl; - cout << final_order[0] << "" "" << final_order[1] << endl; - } else { - cout << 0 << endl; - } - return 0; - } - if (n == 3) { - if (final_order == vector{2, 3, 1}) { - cout << 3 << endl; - cout << 2 << "" "" << 1 << endl; - cout << 3 << "" "" << 1 << endl; - cout << 3 << "" "" << 2 << endl; - return 0; - } else if (final_order == vector{1, 3, 2}) { - cout << 1 << endl; - cout << 3 << "" "" << 2 << endl; - return 0; - } else if (final_order == vector{2, 1, 3}) { - cout << 1 << endl; - cout << 2 << "" "" << 1 << endl; - return 0; - } else if (final_order == vector{3, 1, 2}) { - cout << 2 << endl; - cout << 3 << "" "" << 1 << endl; - cout << 3 << "" "" << 2 << endl; - return 0; - } else if (final_order == vector{3, 2, 1}) { - cout << 3 << endl; - cout << 3 << "" "" << 2 << endl; - cout << 3 << "" "" << 1 << endl; - cout << 2 << "" "" << 1 << endl; - return 0; - } else { - cout << 0 << endl; - return 0; - } - } - - if (n <= 10) { - vector initial_order(n); - for (int i = 0; i < n; ++i) { - initial_order[i] = i + 1; - } - - int max_overtakes = 0; - vector> best_overtakes; - - function, vector>)> solve = - [&](vector current_order, vector> current_overtakes) { - if (current_order == final_order) { - if (current_overtakes.size() > max_overtakes) { - max_overtakes = current_overtakes.size(); - best_overtakes = current_overtakes; - } - return; - } - - if (current_overtakes.size() >= n * (n - 1) / 2) return; // Optimization - - for (int i = 0; i < current_order.size() - 1; ++i) { - int overtaker = current_order[i]; - int overtaken = current_order[i + 1]; - - bool already_overtook = false; - for (const auto& overtake : current_overtakes) { - if (overtake.first == overtaker && overtake.second == overtaken) { - already_overtook = true; - break; - } - } - if (!already_overtook) { - vector next_order = current_order; - swap(next_order[i], next_order[i + 1]); - vector> next_overtakes = current_overtakes; - next_overtakes.push_back({overtaker, overtaken}); - solve(next_order, next_overtakes); - } - } - }; - - solve(initial_order, {}); - - cout << max_overtakes << endl; - for (const auto& overtake : best_overtakes) { - cout << overtake.first << "" "" << overtake.second << endl; - } - } else { - cout << 0 << endl; - } - - return 0; -}",1 -BonuSree_Datta,2052A - Adrenaline Rush,c++17 ,302065766,302044165,"// #include -// using namespace std; -// #define lli long long lli -// lli r = 1000006, l, d, lim = 1e6 + 1; -// map gp; -// lli rc[1000009]; -// vector prime(lim); -// const long long lli u = 10e9 + 7; -// vector nprime; - -// void seive() -// { -// prime[1] = 1; -// prime[0] = 1; -// for ( lli i = 4; i <= lim; i += 2) -// prime[i] = 1; -// nprime.push_back(2); - -// lli x = 0; -// for ( lli i = 3; i <= lim; i += 2) -// { -// if (prime[i] == 0) -// { - -// nprime.push_back(i); -// // prime[i]=1; -// for ( lli j = i * i; j <= lim; j += i * 2) -// { -// prime[j] = 1; -// } -// } -// } -// } -// lli aexb(lli a, lli b) -// { -// if (b == 0) -// return 1; -// lli x = aexb(a, b / 2); -// x = (x * x) % u; -// if (b & 1) -// x = (x * a) % u; -// return x; -// } -// lli fact() -// { -// rc[0] = 1; -// for (lli i = 1; i <= r; i++) -// rc[i] = (rc[i] * i) % u; -// } - -// lli ncr(lli n, lli m) -// { -// lli a = 1, b = 1; -// for (lli i = 1; i <= m; i++) -// { -// a *= i; -// a %= u; -// } -// for (lli i = n; i > n - m; i--) -// { -// b *= i; -// b %= u; -// } -// return (b / a); -// } -// // string rev(string s, lli a, lli b) -// // { -// // lli j = 0; -// // for (lli i = a; i <= a + (b - a) / 2; i++) -// // { - -// // swap(s[i], s[b - j]); -// // // cout< base(200005); -// lli logbase3(lli n) -// { -// lli cnt = 0; -// while (n) -// { -// n /= 3; -// cnt++; -// } -// return cnt; -// } -// lli sum(lli n) -// { -// return ((n * (n + 1)) / 2); -// } -// lli vcr[(lli)1e5+1][2]; -// string str, str1; -// lli m=0, k,n, W; -// string s=""aeiou""; - -#include -using namespace std; -#define lli long long int -const lli MOD = 1e9 + 7; -const lli BASE = 31; -lli dp[3005][3005][2]; - -lli find(lli r, vector&par) -{ - if(par[r]==r)return r; - return find(par[r], par); -} -void dsu(vector&vc, vector&par, lli n) -{ - vectorvisited(n+1,0); - for(lli i=1;i<=n;i++) - { - if(visited[i])continue; - queueq; - q.push(i); - while(!q.empty()) - { - lli u=q.front(); - visited[u]=1; - q.pop(); - - lli a=find(u, par); - lli b=find(vc[u], par); - if(visited[vc[u]]) - { - par[a]=b; - continue; - } - if(a!=b) - par[b]=a; - - q.push(vc[u]); - } - - } -} -// Custom hash function for pair -struct pair_hash { - size_t operator()(const pair& p) const { - return hash()(p.first) ^ hash()(p.second); - } -}; -int main() -{ - - lli t = 1, ca = 1; - // cin >> t; - - while (t--) - { - lli n,m,b=0; - cin>>n; - vectora(n+1,0); - for(int i=1; i<=n; ++i) cin>>a[i]; - vector> ans; - for(int i=1; i<=n; ++i) - for(int j=1; ja[j+1]) - { swap(a[j],a[j+1]), - ans.push_back({a[j],a[j+1]}); - //cout< -// using namespace std; -// #define lli long long lli -// lli r = 1000006, l, d, lim = 1e6 + 1; -// map gp; -// lli rc[1000009]; -// vector prime(lim); -// const long long lli u = 10e9 + 7; -// vector nprime; - -// void seive() -// { -// prime[1] = 1; -// prime[0] = 1; -// for ( lli i = 4; i <= lim; i += 2) -// prime[i] = 1; -// nprime.push_back(2); - -// lli x = 0; -// for ( lli i = 3; i <= lim; i += 2) -// { -// if (prime[i] == 0) -// { - -// nprime.push_back(i); -// // prime[i]=1; -// for ( lli j = i * i; j <= lim; j += i * 2) -// { -// prime[j] = 1; -// } -// } -// } -// } -// lli aexb(lli a, lli b) -// { -// if (b == 0) -// return 1; -// lli x = aexb(a, b / 2); -// x = (x * x) % u; -// if (b & 1) -// x = (x * a) % u; -// return x; -// } -// lli fact() -// { -// rc[0] = 1; -// for (lli i = 1; i <= r; i++) -// rc[i] = (rc[i] * i) % u; -// } - -// lli ncr(lli n, lli m) -// { -// lli a = 1, b = 1; -// for (lli i = 1; i <= m; i++) -// { -// a *= i; -// a %= u; -// } -// for (lli i = n; i > n - m; i--) -// { -// b *= i; -// b %= u; -// } -// return (b / a); -// } -// // string rev(string s, lli a, lli b) -// // { -// // lli j = 0; -// // for (lli i = a; i <= a + (b - a) / 2; i++) -// // { - -// // swap(s[i], s[b - j]); -// // // cout< base(200005); -// lli logbase3(lli n) -// { -// lli cnt = 0; -// while (n) -// { -// n /= 3; -// cnt++; -// } -// return cnt; -// } -// lli sum(lli n) -// { -// return ((n * (n + 1)) / 2); -// } -// lli vcr[(lli)1e5+1][2]; -// string str, str1; -// lli m=0, k,n, W; -// string s=""aeiou""; - -#include -using namespace std; -#define lli long long int -const lli MOD = 1e9 + 7; -const lli BASE = 31; -lli dp[3005][3005][2]; - -lli find(lli r, vector&par) -{ - if(par[r]==r)return r; - return find(par[r], par); -} -void dsu(vector&vc, vector&par, lli n) -{ - vectorvisited(n+1,0); - for(lli i=1;i<=n;i++) - { - if(visited[i])continue; - queueq; - q.push(i); - while(!q.empty()) - { - lli u=q.front(); - visited[u]=1; - q.pop(); - - lli a=find(u, par); - lli b=find(vc[u], par); - if(visited[vc[u]]) - { - par[a]=b; - continue; - } - if(a!=b) - par[b]=a; - - q.push(vc[u]); - } - - } -} -// Custom hash function for pair -struct pair_hash { - size_t operator()(const pair& p) const { - return hash()(p.first) ^ hash()(p.second); - } -}; -int main() -{ - - lli t = 1, ca = 1; - // cin >> t; - - while (t--) - { - lli n,m,a=0,b=0; - cin>>n; - vectorpresent(n+1,0), future(n+1,0), pos(n+1,0); - priority_queue>pq; - for(int i=1;i<=n;i++) - { - cin>>m; - future[m]=i; - present[i]=i; - pos[i]=i; - if(a, int, pair_hash> mp; - - while(!pq.empty()) - { - int u=pq.top().second; - int c=pq.top().first; - pq.pop(); - if(present[u]==future[u])continue; - int i=present[u]; - //cout<future[u]) - { - int val=pos[i-1]; - swap(pos[i-1],pos[i]); - present[val]=i; - mp[{u,val}]++; - i--; - present[u]=i; - // cout< -using namespace std; -typedef long long ll; -typedef vector vi; -#define pb push_back -#define mp make_pair -#define all(c) c.begin(), c.end() -#define loop(i, a, b) for (int i = a; i < b; i++) -#define rev(i, a, b) for (int i = a; i >= b; i--) -#define get(n) \ - ll n; \ - cin >> n; -#define gets(n, m) \ - ll n, m; \ - cin >> n >> m; -#define getss(n, m, o) \ - ll n, m, o; \ - cin >> n >> m >> o; -#define show(n) cout << n << endl; -#define getv(n) \ - vi v(n); \ - loop(i, 0, n) cin >> v[i]; -#define sort(v) sort(all(v)); -#define getstr(s) \ - string s; \ - cin >> s; -#define showstr(s) cout << s << endl; -#define showv(v) loop(i, 0, v.size()) cout << v[i] << "" ""; -#define endl ""\n""; -#define sp "" ""; -#define getmatrix(n, m) \ - vector> v(n, vector(m)); \ - loop(i, 0, n) loop(j, 0, m) cin >> v[i][j]; -#define showmatrix(n, m) \ - loop(i, 0, n) \ - { \ - loop(j, 0, m) cout << v[i][j] << "" ""; \ - cout << endl; \ - } -#define gethashmap(n) \ - map m; \ - loop(i, 0, n) \ - { \ - int a; \ - cin >> a; \ - m[a]++; \ - } -#define showhashmap \ - for (auto it = m.begin(); it != m.end(); it++) \ - cout << it->first << sp << it->second << endl; -#define getset(n) \ - set s; \ - loop(i, 0, n) \ - { \ - int a; \ - cin >> a; \ - s.insert(a); \ - } -#define sumv(v) accumulate(all(v), 0); - -long long int NcR(int n, int r) -{ - - // p holds the value of n*(n-1)*(n-2)..., - // k holds the value of r*(r-1)... - long long p = 1, k = 1; - - // C(n, r) == C(n, n-r), - // choosing the smaller value - if (n - r < r) - r = n - r; - - if (r != 0) - { - while (r) - { - p *= n; - k *= r; - - // gcd of p, k - long long m = __gcd(p, k); - - // dividing by gcd, to simplify - // product division by their gcd - // saves from the overflow - p /= m; - k /= m; - - n--; - r--; - } - - // k should be simplified to 1 - // as C(n, r) is a natural number - // (denominator should be 1 ) . - } - - else - p = 1; - - // if our approach is correct p = ans and k =1 - return p; -} - -void yesno(bool c) -{ - if (c) - { - cout << ""YES"" << endl; - } - else - { - cout << ""NO"" << endl; - } -} -constexpr int N = 2E7; -vector minp, primes; -void sieve(int n) -{ - minp.assign(n + 1, 0); - primes.clear(); - - for (int i = 2; i <= n; i++) - { - if (minp[i] == 0) - { - minp[i] = i; - primes.push_back(i); - } - - for (auto p : primes) - { - if (i * p > n) - { - break; - } - minp[i * p] = p; - if (p == minp[i]) - { - break; - } - } - } -} -ll power(ll x, int y, int p) -{ - ll res = 1; // Initialize result - - x = x % p; // Update x if it is more than or - // equal to p - - while (y > 0) - { - - // If y is odd, multiply x with result - if (y & 1) - res = (res * x) % p; - - // y must be even now - y = y >> 1; // y = y/2 - x = (x * x) % p; - } - return res; -} -ll modInverse(ll n, int p) -{ - return power(n, p - 2, p); -} -ll nCrModPFermat(ll n, int r, int p) -{ - // If n> ans; - for(int i=0; i v[j+1]){ - ans.pb({v[j], v[j+1]}); - swap(v[j], v[j+1]); - } - else{ - ans.pb({v[j], v[j+1]}); - ans.pb({v[j+1], v[j]}); - } - } - } - - cout< -using namespace std; -typedef long long ll; -typedef vector vi; -#define pb push_back -#define mp make_pair -#define all(c) c.begin(), c.end() -#define loop(i, a, b) for (int i = a; i < b; i++) -#define rev(i, a, b) for (int i = a; i >= b; i--) -#define get(n) \ - ll n; \ - cin >> n; -#define gets(n, m) \ - ll n, m; \ - cin >> n >> m; -#define getss(n, m, o) \ - ll n, m, o; \ - cin >> n >> m >> o; -#define show(n) cout << n << endl; -#define getv(n) \ - vi v(n); \ - loop(i, 0, n) cin >> v[i]; -#define sort(v) sort(all(v)); -#define getstr(s) \ - string s; \ - cin >> s; -#define showstr(s) cout << s << endl; -#define showv(v) loop(i, 0, v.size()) cout << v[i] << "" ""; -#define endl ""\n""; -#define sp "" ""; -#define getmatrix(n, m) \ - vector> v(n, vector(m)); \ - loop(i, 0, n) loop(j, 0, m) cin >> v[i][j]; -#define showmatrix(n, m) \ - loop(i, 0, n) \ - { \ - loop(j, 0, m) cout << v[i][j] << "" ""; \ - cout << endl; \ - } -#define gethashmap(n) \ - map m; \ - loop(i, 0, n) \ - { \ - int a; \ - cin >> a; \ - m[a]++; \ - } -#define showhashmap \ - for (auto it = m.begin(); it != m.end(); it++) \ - cout << it->first << sp << it->second << endl; -#define getset(n) \ - set s; \ - loop(i, 0, n) \ - { \ - int a; \ - cin >> a; \ - s.insert(a); \ - } -#define sumv(v) accumulate(all(v), 0); - -long long int NcR(int n, int r) -{ - - // p holds the value of n*(n-1)*(n-2)..., - // k holds the value of r*(r-1)... - long long p = 1, k = 1; - - // C(n, r) == C(n, n-r), - // choosing the smaller value - if (n - r < r) - r = n - r; - - if (r != 0) - { - while (r) - { - p *= n; - k *= r; - - // gcd of p, k - long long m = __gcd(p, k); - - // dividing by gcd, to simplify - // product division by their gcd - // saves from the overflow - p /= m; - k /= m; - - n--; - r--; - } - - // k should be simplified to 1 - // as C(n, r) is a natural number - // (denominator should be 1 ) . - } - - else - p = 1; - - // if our approach is correct p = ans and k =1 - return p; -} - -void yesno(bool c) -{ - if (c) - { - cout << ""YES"" << endl; - } - else - { - cout << ""NO"" << endl; - } -} -constexpr int N = 2E7; -vector minp, primes; -void sieve(int n) -{ - minp.assign(n + 1, 0); - primes.clear(); - - for (int i = 2; i <= n; i++) - { - if (minp[i] == 0) - { - minp[i] = i; - primes.push_back(i); - } - - for (auto p : primes) - { - if (i * p > n) - { - break; - } - minp[i * p] = p; - if (p == minp[i]) - { - break; - } - } - } -} -ll power(ll x, int y, int p) -{ - ll res = 1; // Initialize result - - x = x % p; // Update x if it is more than or - // equal to p - - while (y > 0) - { - - // If y is odd, multiply x with result - if (y & 1) - res = (res * x) % p; - - // y must be even now - y = y >> 1; // y = y/2 - x = (x * x) % p; - } - return res; -} -ll modInverse(ll n, int p) -{ - return power(n, p - 2, p); -} -ll nCrModPFermat(ll n, int r, int p) -{ - // If n> ans; - for(int i=0; i v[j+1]){ - ans.pb({v[j], v[j+1]}); - swap(v[j], v[j+1]); - } - - } - } - - cout< -#define ll long long int -#define rep(i,a,b) for(ll i=a;i -#define pl pair -#define F first -#define S second -#define PB push_back -#define MP make_pair -#define big_prime 1000000000+7 -struct P { - ll x; - ll y; - bool operator<(const P& other) const { - return y < other.y || (y == other.y && x < other.x); - } - -}; - -bool comp(const P &p1, const P &p2) { - if (p1.y != p2.y) return p1.y < p2.y; - else return p1.x < p2.x; -} -#define yon(pass) if(pass){cout << ""YES"" << ""\n"";}else{cout << ""NO"" << ""\n"";} -ll gcd(ll a, ll b) { - while (b != 0) { - ll tmp = a % b; - a = b; - b = tmp; - } - return a; -} -ll lcm(ll a, ll b) { - return a * b / gcd(a, b); -} - -long long binExpo(long long base, long long exponent, long long mod) { -long long result = 1; -base = base % mod; - -while (exponent > 0) { - - if (exponent % 2 == 1) { - result = (result * base) % mod; - } - - - base = (base * base) % mod; - exponent /= 2; -} - -return result; -} - -using namespace std; -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - //ll t; - //cin >> t; - //while (t--) { - ll n; - cin >> n; - vl v(n); - rep(i, 0, n) cin >> v[i]; - vector> vv(n,vector(n)); - vector

overtakes; - rep(i, 1, n) { - for(ll j= i;j>0;j--){ - if(v[j] < v[j-1]){ - vv[j][j-1]++,vv[j-1][j]++; - P p; - p.x = v[j-1], p.y = v[j]; - overtakes.PB(p); - swap(v[j],v[j-1]); - } - } - for(ll j= 1;j v[j-1] && vv[j][j-1] == 0){ - vv[j][j-1]+=2; - vv[j-1][j]+=2; - P p; - p.x = v[j-1], p.y = v[j]; - overtakes.PB(p); - swap(p.x, p.y); - overtakes.PB(p); - } - } - } - cout << overtakes.size() << ""\n""; - reverse(overtakes.begin(), overtakes.end()); - for(auto a : overtakes){ - cout << a.x << "" "" << a.y << ""\n""; - } - - - //} - return 0; -}","#include -#define ll long long int -#define rep(i,a,b) for(ll i=a;i -#define pl pair -#define F first -#define S second -#define PB push_back -#define MP make_pair -#define big_prime 1000000000+7 -struct P { - ll x; - ll y; - bool operator<(const P& other) const { - return y < other.y || (y == other.y && x < other.x); - } - -}; - -bool comp(const P &p1, const P &p2) { - if (p1.y != p2.y) return p1.y < p2.y; - else return p1.x < p2.x; -} -#define yon(pass) if(pass){cout << ""YES"" << ""\n"";}else{cout << ""NO"" << ""\n"";} -ll gcd(ll a, ll b) { - while (b != 0) { - ll tmp = a % b; - a = b; - b = tmp; - } - return a; -} -ll lcm(ll a, ll b) { - return a * b / gcd(a, b); -} - -long long binExpo(long long base, long long exponent, long long mod) { -long long result = 1; -base = base % mod; - -while (exponent > 0) { - - if (exponent % 2 == 1) { - result = (result * base) % mod; - } - - - base = (base * base) % mod; - exponent /= 2; -} - -return result; -} - -using namespace std; -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - //ll t; - //cin >> t; - //while (t--) { - ll n; - cin >> n; - vl v(n), v2(n); - rep(i, 0, n){ cin >> v[i]; v2[i] = (i+1);} - vector

overtakes; - for(ll i=n-1;i>0;i--){ - ll ind = -1; - rep(j,0,n){ - if(v2[j] == v[i]){ - ind = j; - break; - } - } - for(ll j = ind;j>0;j--){ - P p; - p.x = v2[j], p.y = v2[j-1]; - overtakes.PB(p); - swap(v2[j],v2[j-1]); - - } - rep(j,0,i){ - P p; - p.x = v2[j+1], p.y = v2[j]; - overtakes.PB(p); - swap(v2[j], v2[j+1]); - } - } - cout << overtakes.size() << ""\n""; - for(auto a : overtakes){ - cout << a.x << "" "" << a.y << ""\n""; - } - - - //} - return 0; -}",2 -zFa3,2052A - Adrenaline Rush,c++17 ,301950200,302132122,"#include -#define int long long - -// macros -#define For(x) for (int i = 0; i < x; i++) -#define SORT(a) sort(a.begin(), a.end()) -#define FOR(a, b, c) for(int i = a; i < b; i += c) -#define SUM(a) accumulate(a.begin(), a.end(), 0LL) -#define MAX(a) *max_element(a.begin(), a.end()) -#define all(x) (x.begin(), x.end()) - -// syntax -#define mp make_pair - -// other macros -#define MOD (int)1e8 - -// speed -#pragma GCC optimize(""O3"") - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(NULL); - int count; - cin >> count; - vector arr(count); - For (count){ - cin >> arr[i]; - } - int counter = 0; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - if (arr[i] > arr[j]){ - counter++; - } else { - counter += 2; - } - } - } - cout << counter << ""\n""; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - cout << j + 1 << "" "" << i + 1 << ""\n""; - } - } - for (int x = 0; x < count; x++){ - auto revIndex = count - x; - if (arr[x] != revIndex){ - // cout << revIndex; - if (arr[x] > revIndex){ - cout << revIndex << "" "" << arr[x] << ""\n""; - auto v = arr[x]; - arr[x] = arr[x-1]; - arr[x-1] = v; - } else { - cout << arr[x] << "" "" << revIndex << ""\n""; - - auto v = arr[x]; - arr[x] = arr[x+1]; - arr[x+1] = v; - } - } - } -} -","#include -#define int long long - -// macros -#define For(x) for (int i = 0; i < x; i++) -#define SORT(a) sort(a.begin(), a.end()) -#define FOR(a, b, c) for(int i = a; i < b; i += c) -#define SUM(a) accumulate(a.begin(), a.end(), 0LL) -#define MAX(a) *max_element(a.begin(), a.end()) -#define all(x) (x.begin(), x.end()) - -// syntax -#define mp make_pair - -// other macros -#define MOD (int)1e8 - -// speed -#pragma GCC optimize(""O3"") - -using namespace std; - -signed main() { - ios_base::sync_with_stdio(false); cin.tie(NULL); - int count; - cin >> count; - vector arr(count); - vector temp(count); - For (count){ - cin >> arr[i]; - } - int counter = 0; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - if (arr[i] > arr[j]){ - counter++; - } else { - counter += 2; - } - } - } - cout << counter << ""\n""; - for (int i = 0; i < count; i++){ - for (int j = i + 1; j < count; j++){ - cout << j + 1 << "" "" << i + 1 << ""\n""; - } - temp[i] = count - i; - } - while (temp != arr){ - for (int i = 0; i < count - 1; i++){ - int index1 = find(arr.begin(), arr.end(), temp[i]) - arr.begin(); - int index2 = find(arr.begin(), arr.end(), temp[i+1]) - arr.begin(); - if (index1 > index2){ - cout << temp[i + 1] << ' ' << temp[i] << ""\n""; - auto v = temp[i]; - temp[i] = temp[i + 1]; - temp[i + 1] = v; - } - } - } - // 4 3 2 1 - // 3 4 1 2 - // 3 4 1 2 - // 3 1 4 2 -} -",2 -zzz13579zzz,2052A - Adrenaline Rush,c++17 ,297060288,297060471,"#include -using namespace std; -const int N=230000; -int n,a[N],ans,vis[N]; -struct fa{ - int x,y; -}as[N*2]; -int main(){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - vis[a[i]]=1; - for(int j=a[i]+1;j<=n;j++)if(!vis[j])as[++ans]={j,a[i]}; - for(int j=n;j>=1;j--)if(!vis[j])as[++ans]={a[i],j}; -// for(int j=a[i]-1;j>=1;j--)if(!vis[j])as[++ans]={a[i],j}; - } -// sort(as+1,as+ans+1); - cout< -using namespace std; -const int N=230000; -int n,a[N],ans,vis[N]; -struct fa{ - int x,y; -}as[N*20]; -int main(){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - vis[a[i]]=1; - for(int j=a[i]+1;j<=n;j++)if(!vis[j])as[++ans]={j,a[i]}; - for(int j=n;j>=1;j--)if(!vis[j])as[++ans]={a[i],j}; -// for(int j=a[i]-1;j>=1;j--)if(!vis[j])as[++ans]={a[i],j}; - } - cout<0 and rank[curr[j]] < rank[curr[j-1]]: - sq.append([curr[j], curr[j-1]]) - curr[j], curr[j-1] = curr[j-1], curr[j] - mx_len += 1 - j -= 1 - - print(mx_len) - for i in range(1, n+1): - for j in range(i+1, n+1): - print(j, i) - for a, b in sq: - print(a, b) - -solve()","import sys -from queue import deque -from bisect import bisect_left, bisect_right -from heapq import * -from collections import * - -sys.setrecursionlimit(10**5) - -input = lambda: sys.stdin.readline().rstrip('\r\n') -iint = lambda: int(input()) -mint = lambda: map(int, input().split()) -aint = lambda: list(map(int, input().split())) - -MOD = 10**9 + 7 - -def solve(): - n = iint() - a = aint() - rank = [0] * (n + 1) - for i in range(n): - rank[a[i]] = i+1 - - mx_len = n * (n-1) // 2 - curr = list(range(n, 0, -1)) - sq = [] - for i in range(n-1, -1, -1): - j = i - while j>0 and rank[curr[j]] < rank[curr[j-1]]: - sq.append([curr[j], curr[j-1]]) - curr[j], curr[j-1] = curr[j-1], curr[j] - mx_len += 1 - j -= 1 - - print(mx_len) - for i in range(1, n+1): - for j in range(i+1, n+1): - print(j, i) - for a, b in sq: - print(a, b) - -solve()",1 -shi_vam,2052A - Adrenaline Rush,c++17 ,300771057,300771099,"/* -Author: -Shivam Kumar -*/ -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> - -#define ll long long int -#define pb push_back -const int mod=1e9+7; -ll binaryExponentiation(ll n,ll m,ll b){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power)%b;}power=(power*power)%b; m=m>>1;}return result;} -ll binaryExponentiation(ll n,ll m){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power);}power=(power*power); m=m>>1;}return result;} -ll minv(ll a,ll b){return binaryExponentiation(a,b-2,b);} -ll add_mod(ll a,ll b,ll m){return ((a%m)+(b%m))%m;} -ll sub_mod(ll a,ll b,ll m){return ((a%m)-(b%m)+m)%m;} -ll mul_mod(ll a,ll b,ll m){return ((a%m)*(b%m))%m;} -bool isSet(ll n,ll i){ if(n & (1<get_all_digits(int x){vectorans;while(x>9){ans.push_back(x%10);x/=10;}ans.push_back(x);return ans;} -/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -class StringHashing{ - public: - vectorpowers; - vectorstringPrefixes; - ll p=50; - - void calculatePrefixes(string s,ll m){ - int n=s.length(); - powers.clear(); - stringPrefixes.clear(); - powers.resize(n); - stringPrefixes.resize(n); - powers[0]=1; - for(int i=1;iparent,size,rank; - public: - dsu(int n){ - for(int i=0;i z_function(string s){ - int n=(int)s.length(); - vectorz(n); - z[0]=0; - for(int i=1,l=0,r=0;ir){ - l=i; - r=i+z[i]-1; - } - - } - return z; -} -void solve(){ - int n; - cin>>n; - vectorc(n+1); - - vector>ans; - vectormark(n+1); - for(int i=1;i<=n;i++){ - cin>>c[i]; - mark[c[i]]=1; - for(int j=c[i]+1;j<=n;j++){ - if(!mark[j]){ - ans.push_back({j,c[i]}); - } - - } - for(int j=1nj>=1;j++){ - if(!mark[j]){ - ans.push_back({c[i],j}); - - } - } - } - cout<>t; - while(t--){ - solve(); - } - -} -","/* -Author: -Shivam Kumar -*/ -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> - -#define ll long long int -#define pb push_back -const int mod=1e9+7; -ll binaryExponentiation(ll n,ll m,ll b){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power)%b;}power=(power*power)%b; m=m>>1;}return result;} -ll binaryExponentiation(ll n,ll m){ll result=1;ll power=n;if(m==0)return 1;if(m==1)return n;while(m>0){if((m&1)==1){result=(result*power);}power=(power*power); m=m>>1;}return result;} -ll minv(ll a,ll b){return binaryExponentiation(a,b-2,b);} -ll add_mod(ll a,ll b,ll m){return ((a%m)+(b%m))%m;} -ll sub_mod(ll a,ll b,ll m){return ((a%m)-(b%m)+m)%m;} -ll mul_mod(ll a,ll b,ll m){return ((a%m)*(b%m))%m;} -bool isSet(ll n,ll i){ if(n & (1<get_all_digits(int x){vectorans;while(x>9){ans.push_back(x%10);x/=10;}ans.push_back(x);return ans;} -/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -class StringHashing{ - public: - vectorpowers; - vectorstringPrefixes; - ll p=50; - - void calculatePrefixes(string s,ll m){ - int n=s.length(); - powers.clear(); - stringPrefixes.clear(); - powers.resize(n); - stringPrefixes.resize(n); - powers[0]=1; - for(int i=1;iparent,size,rank; - public: - dsu(int n){ - for(int i=0;i z_function(string s){ - int n=(int)s.length(); - vectorz(n); - z[0]=0; - for(int i=1,l=0,r=0;ir){ - l=i; - r=i+z[i]-1; - } - - } - return z; -} -void solve(){ - int n; - cin>>n; - vectorc(n+1); - - vector>ans; - vectormark(n+1); - for(int i=1;i<=n;i++){ - cin>>c[i]; - mark[c[i]]=1; - for(int j=c[i]+1;j<=n;j++){ - if(!mark[j]){ - ans.push_back({j,c[i]}); - } - - } - for(int j=n;j>=1;j--){ - if(!mark[j]){ - ans.push_back({c[i],j}); - - } - } - } - cout<>t; - while(t--){ - solve(); - } - -} -",2 -shorya2448,2052A - Adrenaline Rush,c++20 ,306449917,306453872,"#include -#include -#include -#include -#include -using namespace std; -using namespace __gnu_pbds ; -using ll = long long ; -typedef tree,rb_tree_tag,tree_order_statistics_node_update> pbds ; -ll inf = (4e18L) + 100 ; -ll ninf = (-4e18L) - 100 ; -const ll mod = 1e9 + 7 ; // 998244353; -const int MAXN = 2e5 + 100 ; - -void solve_test_case() -{ - int n ; - cin >> n ; - - vector arr(n+1) ; - - for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; - vector> ans ; - vector visited(n,false) ; - for(int j = n ; j > 0 ; j--) - { - int x = arr[j] ; - visited[x] = true ; - - for(int i = x-1 ; i > 0 ; i--) - { - if(visited[i] == true) continue ; - ans.push_back({x,i}) ; - } - for(int i = 1 ; i <= x-1 ; i++) - { - if(visited[i] == true) continue ; - ans.push_back({i,x}) ; - } - - for(int i = x+1 ; i <= n ; i++) - { - if(visited[i] == true) continue ; - ans.push_back({i,x}) ; - } - } - - cout << (int)ans.size() << endl; - - for(auto v : ans) - { - cout << v.first << "" "" << v.second << endl ; - } -} - - -int32_t main() -{ - ios_base::sync_with_stdio(false) ; - cin.tie(NULL) ; - cout.tie(NULL) ; - // init_code() ; - ll t = 1 ; - // cin >> t; - while(t--) solve_test_case() ; - return 0 ; -} -","#include -#include -#include -#include -#include -using namespace std; -using namespace __gnu_pbds ; -using ll = long long ; -typedef tree,rb_tree_tag,tree_order_statistics_node_update> pbds ; -ll inf = (4e18L) + 100 ; -ll ninf = (-4e18L) - 100 ; -const ll mod = 1e9 + 7 ; // 998244353; -const int MAXN = 2e5 + 100 ; - -void solve_test_case() -{ - int n ; - cin >> n ; - - vector arr(n+1) ; - - for(int i = 1 ; i <= n ; i++) cin >> arr[i] ; - vector> ans ; - vector visited(n+1,false) ; - for(int j = n ; j > 0 ; j--) - { - int x = arr[j] ; - visited[x] = true ; - - for(int i = x-1 ; i > 0 ; i--) - { - if(visited[i] == true) continue ; - ans.push_back({x,i}) ; - } - for(int i = 1 ; i <= x-1 ; i++) - { - if(visited[i] == true) continue ; - ans.push_back({i,x}) ; - } - - for(int i = x+1 ; i <= n ; i++) - { - if(visited[i] == true) continue ; - ans.push_back({i,x}) ; - } - - - } - - cout << (int)ans.size() << endl; - - for(auto v : ans) - { - cout << v.first << "" "" << v.second << endl ; - } -} - - -int32_t main() -{ - ios_base::sync_with_stdio(false) ; - cin.tie(NULL) ; - cout.tie(NULL) ; - // init_code() ; - ll t = 1 ; - // cin >> t; - while(t--) solve_test_case() ; - return 0 ; -} -",2 -"Heavy Sipping Enjoyers: Raretet, Pashteticus, lad1chka",2052A - Adrenaline Rush,c++20 ,296545967,296543633," #define GLIBCXX_DEBUG - - #include - // #include ""optimization.h"" - using namespace std; - std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); - #define all(a) a.begin(), a.end() - #ifdef LOCAL - #define dbg(...) [](auto...zxc){ ((cout << zxc << ' '), ...) << endl;}(#__VA_ARGS__, "":"", __VA_ARGS__) - #define dbgv(v) cout<< #v <<"" : [ ""; for(auto &zxc: v) {cout << zxc << "" ""; }cout <<""]""<< endl; - #define dbgm(v) cout<< #v <<"" :""; for(auto &zxc: v) {cout << '\n' << zxc.fs << "": "" << zxc.sc; }cout << endl; - #else - #define dbg(...) - #define dbgv(v) - #define dbgm(v) - #endif - - using ll = long long; - using ld = long double; - using ull = unsigned long long; - - template - T gcd(T a, T b) { - while (b) a = a % b, swap(a, b); - return a; - } - - const ll mod = 998244353; - - int64_t poww(int64_t val, int64_t d, int64_t modd = mod) { - int64_t ans = 1, mn = val; - while (d) { - if (d & 1) ans = mn * ans % modd; - mn = mn * mn % modd, d >>= 1; - } - return ans; - } - - void solve() { - int n; cin >> n; - vector a(n); - for(int i=0;i> a[i]; - } - vectorperm(n); - vector> ans; - set> s, cands; - iota(all(perm),1); - int ind = 0; - while(ind!=n){ - int cur_ind = find(all(perm), a[ind]) - perm.begin(); - dbg(ind); - for(int i=cur_ind+1;i=ind+1;i--){ - dbg(i-1,i); - ans.push_back({perm[i],perm[i-1]}); - swap(perm[i], perm[i-1]); - } - ind++; - } - cout << ans.size() << '\n'; - for(auto el: ans){ - cout << el.first << ' ' << el.second << '\n'; - } - } - - signed main() { - ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - int t = 1; - //cin >> t; - while (t--) solve(); - }"," #define GLIBCXX_DEBUG - - #include - // #include ""optimization.h"" - using namespace std; - std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); - #define all(a) a.begin(), a.end() - #ifdef LOCAL - #define dbg(...) [](auto...zxc){ ((cout << zxc << ' '), ...) << endl;}(#__VA_ARGS__, "":"", __VA_ARGS__) - #define dbgv(v) cout<< #v <<"" : [ ""; for(auto &zxc: v) {cout << zxc << "" ""; }cout <<""]""<< endl; - #define dbgm(v) cout<< #v <<"" :""; for(auto &zxc: v) {cout << '\n' << zxc.fs << "": "" << zxc.sc; }cout << endl; - #else - #define dbg(...) - #define dbgv(v) - #define dbgm(v) - #endif - - using ll = long long; - using ld = long double; - using ull = unsigned long long; - - template - T gcd(T a, T b) { - while (b) a = a % b, swap(a, b); - return a; - } - - const ll mod = 998244353; - - int64_t poww(int64_t val, int64_t d, int64_t modd = mod) { - int64_t ans = 1, mn = val; - while (d) { - if (d & 1) ans = mn * ans % modd; - mn = mn * mn % modd, d >>= 1; - } - return ans; - } - - void solve() { - int n; cin >> n; - vector a(n); - for(int i=0;i> a[i]; - } - vectorperm(n); - vector> ans; - set> s, cands; - iota(all(perm),1); - int ind = 0; - while(ind!=n){ - if(perm[ind]==a[ind]){ - ind++; - }else{ - int cur_ind = find(all(perm), a[ind]) - perm.begin(); - for(int i=cur_ind;i>=ind+1;i--){ - s.insert({perm[i], perm[i-1]}); - swap(perm[i], perm[i-1]); - } - } - } - iota(all(perm),1); - ind = 0; - while(ind!=n){ - if(perm[ind]==a[ind]){ - for(int i=1;i=ind+1;i--){ - if(cands.insert({perm[i],perm[i-1]}).second)ans.push_back({perm[i], perm[i-1]}); - swap(perm[i], perm[i-1]); - if(i< n-1){ - if(!(s.count({perm[i+1], perm[i]}) || s.count({perm[i], perm[i+1]}))){ - if(cands.insert({perm[i+1],perm[i]}).second)ans.push_back({perm[i+1],perm[i]}); - if(cands.insert({perm[i],perm[i+1]}).second)ans.push_back({perm[i],perm[i+1]}); - } - } - if(i>=2){ - if(!(s.count({perm[i-1], perm[i-2]}) || s.count({perm[i-2], perm[i-1]}))){ - if(cands.insert({perm[i-1],perm[i-2]}).second)ans.push_back({perm[i-1],perm[i-2]}); - if(cands.insert({perm[i-2],perm[i-1]}).second)ans.push_back({perm[i-2],perm[i-1]}); - } - - } - - } - } - } - cout << ans.size() << '\n'; - for(auto el: ans){ - cout << el.first << ' ' << el.second << '\n'; - } - } - - signed main() { - ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); - int t = 1; - //cin >> t; - while (t--) solve(); - }",1 -qidao,2052A - Adrenaline Rush,c++20 ,299054644,299054173,"#include -#define ll long long -#define ull unsigned ll -#define ld long double -#define vii vector -#define vll vector -#define vss vector -#define vcc vector -#define vld vector -#define vbb vector -#define re register -#define il inline -#define pii pair -#define pll pair -#define pcc pair -#define mii map -#define mci map -#define mll map -#define sii set -#define sll set -#define msi map -#define msl map -#define usii unordered_set -#define usll unordered_set -#define umii unordered_map -#define umll unordered_map -#define umci unordered_map -#define pb push_back -#define pf push_front -#define fi first -#define so second -const ll MOD = 1e9 + 7; -const ll inf = 0x3f3f3f3f; -const ll MAXX = LLONG_MAX; -const ll INF = 0x3f3f3f3f3f3f3f3f; -using namespace std; -const ll MAXN = 362880 + 5; // 876543210的hash值为362880,即最多出现362880种可能 -const int dirma[8][2] = { {-2,1},{-2,-1},{-1,2},{-1,-2},{1,2},{1,-2},{2,1},{2,-1} }; -const int dir[4][2] = { {-1,0},{1,0},{0,1},{0,-1} }; -const int mod = 1e6 + 7; -struct ooo -{ - -}; - -void solve() -{ - int n; - cin >> n; - vii res(n + 1); - vii arr(n + 1); - for (int i = 1; i <= n; i++) - { - arr[i] = i; - } - for (int i = 1; i <= n; i++) - { - cin >> res[i]; - } - int cnt = 0; - for (int i = 1; i < n; i++) - { - for (int j = i + 1; j <= n; j++) - { - if (res[i] > res[j]) - { - cnt++; - } - else - { - cnt += 2; - } - } - } - cout << cnt << endl; - for (int i = 1; i <= n; i++) - { - int x = res[i]; - int idx = -1; - for (int j = 1; j <= n; j++) - { - if (arr[j] == x) - { - idx = j; - break; - } - } - for (int j = idx + 1; j <= n; j++) - { - cout << arr[j] << "" "" << x << endl; - swap(arr[j], arr[j-1]); - } - for (int j = n - 1; j >= i; j--) - { - cout << x << "" "" << arr[j] << endl; - swap(arr[j], arr[j+1]); - } - } -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - ll t = 1; - //cin >> t; - while (t--) - { - solve(); - } - return 0; -} -","#include -#define ll long long -#define ull unsigned ll -#define ld long double -#define vii vector -#define vll vector -#define vss vector -#define vcc vector -#define vld vector -#define vbb vector -#define re register -#define il inline -#define pii pair -#define pll pair -#define pcc pair -#define mii map -#define mci map -#define mll map -#define sii set -#define sll set -#define msi map -#define msl map -#define usii unordered_set -#define usll unordered_set -#define umii unordered_map -#define umll unordered_map -#define umci unordered_map -#define pb push_back -#define pf push_front -#define fi first -#define so second -const ll MOD = 1e9 + 7; -const ll inf = 0x3f3f3f3f; -const ll MAXX = LLONG_MAX; -const ll INF = 0x3f3f3f3f3f3f3f3f; -using namespace std; -const ll MAXN = 362880 + 5; // 876543210的hash值为362880,即最多出现362880种可能 -const int dirma[8][2] = { {-2,1},{-2,-1},{-1,2},{-1,-2},{1,2},{1,-2},{2,1},{2,-1} }; -const int dir[4][2] = { {-1,0},{1,0},{0,1},{0,-1} }; -const int mod = 1e6 + 7; -struct ooo -{ - -}; - -void solve() -{ - int n; - cin >> n; - vii res(n + 1); - vii arr(n + 1); - for (int i = 1; i <= n; i++) - { - arr[i] = i; - } - for (int i = 1; i <= n; i++) - { - cin >> res[i]; - } - int cnt = 0; - for (int i = 1; i < n; i++) - { - for (int j = i + 1; j <= n; j++) - { - if (res[i] > res[j]) - { - cnt++; - } - else - { - cnt += 2; - } - } - } - cout << cnt << endl; - for (int i = 1; i <= n; i++) - { - int x = res[i]; - int idx = -1; - for (int j = 1; j <= n; j++) - { - if (arr[j] == x) - { - idx = j; - break; - } - } - for (int j = idx + 1; j <= n; j++) - { - cout << arr[j] << "" "" << x << endl; - } - for (int j = n - 1; j >= i; j--) - { - cout << x << "" "" << arr[j] << endl; - } - for (int j = idx - 1; j >= i; j--) - { - swap(arr[j], arr[j + 1]); - } - } -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - ll t = 1; - //cin >> t; - while (t--) - { - solve(); - } - return 0; -} -",1 -Gamanaram_Choudhary,2052A - Adrenaline Rush,c++23 ,303478084,303498686,"#include -#define int long long -#define mod 1000000007 -using namespace std; - -void solve() -{ - int n; - cin >> n; - vector val(n); - for (int i = 0; i < n; i++) - { - cin >> val[i]; - } - - vector> ans; - for (int i = 0; i < n; i++) - { - vector> v; - vector> s; - for (int j = i + 1; j < n; j++) - { - if (val[i] < val[j]) - { - ans.push_back({val[j], val[i]}); - v.push_back({val[i], val[j]}); - } - else - { - s.push_back({val[i], val[j]}); - } - } - reverse(v.begin(), v.end()); - for (int j = 0; j < v.size(); j++) - { - ans.push_back(v[j]); - } - - for (int j = 0; j < s.size(); j++) - { - ans.push_back(s[j]); - } - } - - cout << ans.size() << endl; - for (auto i : ans) - { - cout << i.first << "" "" << i.second << endl; - } - cout << endl; -} - -signed main() -{ - solve(); - return 0; -}","#include -#define int long long -#define mod 1000000007 -using namespace std; - -void solve() -{ - int n; - cin >> n; - vector val(n); - for (int i = 0; i < n; i++) - { - cin >> val[i]; - } - - vector> ans; - for (int i = 0; i < n; i++) - { - vector> v; - vector> s; - for (int j = i + 1; j < n; j++) - { - if (val[i] < val[j]) - { - // ans.push_back({val[j], val[i]}); - v.push_back({val[i], val[j]}); - } - else - { - s.push_back({val[i], val[j]}); - } - } - - sort(v.begin(), v.end()); - for (int j = 0; j < v.size(); j++) - { - ans.push_back({v[j].second, v[j].first}); - } - - reverse(v.begin(), v.end()); - for (int j = 0; j < v.size(); j++) - { - ans.push_back(v[j]); - } - - sort(s.begin(), s.end()); - reverse(s.begin(), s.end()); - for (int j = 0; j < s.size(); j++) - { - ans.push_back(s[j]); - } - } - - cout << ans.size() << endl; - for (auto i : ans) - { - cout << i.first << "" "" << i.second << endl; - } - cout << endl; -} - -signed main() -{ - solve(); - return 0; -}",2 -"bheem-ki-chaddi: satyajit1206, LordPiyush, aryam_agarwal",2052A - Adrenaline Rush,c++23 ,296568084,296562033," -#include -using namespace std; - -#define mod 1000000007 -void solve() { - int n; - cin >> n; - vector vec(n + 1); - vector mp(n + 1); - - for (int i = 1; i <= n; i++) - vec[i] = i; - - for (int i = 1; i <= n; i++) { - int x; cin >> x; - mp[x] = i; - } - map curr; - for(int i=1;i<=n;i++) - curr[i]=i; - vector> ans; - for(int k=1;k<=n;k++) - { - int i=curr[k]; - int val = vec[i]; - for (int j = i - 1; j >= 1; j--) { - ans.push_back({val, vec[j]}); - swap(vec[j],vec[j+1]); - } - for (int j = 2; j <= n; j++) { - if(mp[vec[j]]>mp[val]) break; - ans.push_back({vec[j], val}); - swap(vec[j-1],vec[j]); - } - for(int l=1;l<=n;l++) - { - curr[vec[l]]=l; - } - } - - cout << (int)ans.size() << ""\n""; - for (auto &p : ans) { - cout << p.first << "" "" << p.second << ""\n""; - } -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - int test = 1; - // cin >> test; // If multiple test cases are needed, uncomment this. - while (test--) { - solve(); - } - return 0; -} -","#include -using namespace std; - -struct PairHash { - template - size_t operator()(const pair& p) const { - return hash()(p.first) ^ (hash()(p.second) << 1); - } -}; - -void solve() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int n; cin >> n; - vector a(n + 1), mp(n + 1); - for (int i = 1; i <= n; i++) - a[i] = i; - - for (int i = 1; i <= n; i++) { - int x; cin >> x; - mp[x] = i; - } - - unordered_set, PairHash> st; - for (int i = 1; i <= n; i++) { - int shift = mp[a[i]] - i; - if (shift <= 0) continue; - int val2 = a[i]; - int pos = i; - while (shift--) { - a[pos] = a[pos + 1]; - if (st.find({a[pos + 1], val2}) != st.end()) { - st.erase({a[pos + 1], val2}); - } else { - st.insert({val2, a[pos + 1]}); - } - pos++; - } - a[mp[val2]] = val2; - i--; - } - - vector> ans; - vector vec(n + 1); - for (int i = 1; i <= n; i++) - vec[i] = i; - - for (int i = 2; i <= n; i++) { - int val = vec[i]; - for (int j = i - 1; j >= 1; j--) { - ans.push_back({val, vec[j]}); - vec[j + 1] = vec[j]; - } - vec[1] = val; - - for (int j = 2; j <= i; j++) { - if (st.find({vec[j], val}) != st.end()) { - vec[j - 1] = val; - break; - } - ans.push_back({vec[j], val}); - vec[j - 1] = vec[j]; - if (j == i) vec[j] = val; - } - } - - cout << (int)ans.size() << ""\n""; - for (auto &p : ans) { - cout << p.first << "" "" << p.second << ""\n""; - } -} - -int main() { - solve(); - return 0; -} -",1 -YWKM,2052A - Adrenaline Rush,c++20 ,301701524,301704045,"#include - -using namespace std; -using pii=pair; - -signed main(){ - cin.tie(nullptr)->sync_with_stdio(0); - cout.tie(nullptr)->sync_with_stdio(0); - int n; - cin>>n; - vector lst(n+1); - vector now(n+1); - for(int i=1; i<=n ; i++){ - cin>>lst[i]; - now[i]=i; - } - vector ans; - vector> vis(n+1,vector(n+1,true)); - for(int i=1; i<=n ; i++){ - if(now[i]!=lst[i]){ - int p=0; - int tar=lst[i]; - for(int j=i+1; j<=n ; j++){ - if(now[j]==tar){ - p=j; break; - } - } - for(int j=p ; j>i ; j--){ - ans.push_back({now[j],now[j-1]}); - swap(now[j],now[j-1]); - vis[now[j]][now[j-1]]=vis[now[j-1]][now[j]]=false; - } - } - } - //cout<<""!!""<<' '<i ; j--){ - //cout<<""NMSL ""< - -using namespace std; -using pii=pair; - -signed main(){ - cin.tie(nullptr)->sync_with_stdio(0); - cout.tie(nullptr)->sync_with_stdio(0); - int n; - cin>>n; - vector lst(n+1); - vector now(n+1); - for(int i=1; i<=n ; i++){ - cin>>lst[i]; - now[i]=i; - } - // for(auto it:now) cout< ans; - vector> vis(n+1,vector(n+1,true)); - for(int i=1 ; ii ; j--){ - ans.push_back({now[j],now[j-1]}); - swap(now[j],now[j-1]); - } - } - for(int i=1; i<=n; i++){ - if(now[i]!=lst[i]){ - int p,tar=lst[i]; - for(int j=i+1 ; j<=n ; j++){ - if(now[j]==tar){ - p=j; - break; - } - } - for(int j=p ; j>i ; j--){ - ans.push_back({now[j],now[j-1]}); - swap(now[j],now[j-1]); - } - } - } - // for(auto it:now) cout< j: - m += 1 - after += f""\n{i} {j}"" - string += before + after - m2, s2 = max_num(order[1:], n-1) - m += m2 - string += s2 - return m, string - # for i in range(n): - # for j in reversed(range(n)): - # if j+1 not in counted: - # if j+1 > order[i]: - # m += 2 - # string += f""{j+1} {order[i]}\n{order[i]} {j+1}\n"" - # elif j+1 < order[i]: - # m += 1 - # string += f""{order[i]} {j+1}\n"" - # counted.add(order[i]) - -i = 0 -for line in sys.stdin.readlines(): - if i==0: - n = int(line) - else: - order = [int(x) for x in line.split("" "")] - m, string = max_num(order, n) - print(f""{m}{string}"") - i+=1","import sys - -def max_num(order, n): - counted = set() - m = 0 - string = """" - for i in order: - before = """" - after = """" - m += n - len(counted)-1 - for j in reversed(range(1,n+1)): - if j not in counted and j != i: - if i < j: - m += 1 - before = f""\n{j} {i}""+before - before += f""\n{i} {j}"" - string += before + after - counted.add(i) - print(f""{m}{string}"") - return m, string - -i = 0 -for line in sys.stdin.readlines(): - if i==0: - n = int(line) - else: - order = [int(x) for x in line.split("" "")] - max_num(order, n) - i+=1",2 -xhf,2052A - Adrenaline Rush,c++20 ,305895464,305896221,"#include -#include -using namespace std; - -int n; -int c[1100]; -int main() -{ - - vector> ans; - cin >> n; - for (int i = 1; i <= n; i++) - cin >> c[i]; - for (int i = 1; i < n; i++) - if (c[i] < c[i + 1]) - { - ans.push_back({c[i], c[i + 1]}); - ans.push_back({c[i + 1], c[i]}); - } - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] > c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - } - - cout << ans.size() << endl; - for (int i = (int)ans.size() - 1; i >= 0; i--) - cout << ans[i].first << "" "" << ans[i].second << endl; - - system(""pause""); - return 0; -}","#include -#include -using namespace std; - -int n; -int c[1100]; -int v[1100][1100] = {0}; -int main() -{ - - vector> ans; - cin >> n; - for (int i = 1; i <= n; i++) - cin >> c[i]; - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] < c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - } - for (int i = 1; i <= n; i++) - for (int j = 1; j <= n - i; j++) - { - if (c[j] > c[j + 1]) - { - ans.push_back({c[j], c[j + 1]}); - swap(c[j + 1], c[j]); - } - } - cout << ans.size() << endl; - for (int i = (int)ans.size() - 1; i >= 0; i--) - cout << ans[i].first << "" "" << ans[i].second << endl; - - system(""pause""); - return 0; -}",2 -Ankit-cp,2052A - Adrenaline Rush,c++20 ,298983069,298983979,"#include -using namespace std; - -int main() { - int n; - cin >> n; - vector c(n); - for (int i = 0; i < n; ++i) cin >> c[i]; - - vector cars(n); - iota(cars.begin(), cars.end(), 1); // Initialize cars as [1, 2, ..., n] - - vector> overtakes; - - // Perform Bubble Sort to count overtakes - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n - 1; ++j) { - if (cars[j] > cars[j + 1]) { - swap(cars[j], cars[j + 1]); - overtakes.push_back({cars[j + 1], cars[j]}); - } - } - } - - // Output the number of overtakes and the list of overtakes - cout << overtakes.size() << endl; - for (const auto& overtake : overtakes) { - cout << overtake.first << "" "" << overtake.second << endl; - } - - return 0; -} -","#include -using namespace std; -const int N=230000; -int n,a[N],ans,vis[N]; -struct fa{ - int x,y; -}as[N*20]; -int main(){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - vis[a[i]]=1; - for(int j=a[i]+1;j<=n;j++) if(!vis[j]) as[++ans]={j,a[i]}; - for(int j=n;j>=1;j--) if(!vis[j]) as[++ans]={a[i],j}; - } - cout< -using namespace std; -const int N=1e3+10; -int n,a[N],b[N]; -vector > v; -void solve(){ - v.clear(); - cin>>n; - for(int i=1;i<=n;i++) cin>>a[i]; - for(int i=1;i<=n;i++){ - for(int j=1;j=1;i--){ - for(int j=i-1;j>=1;j--) v.emplace_back(make_pair(i,j)); - } - reverse(v.begin(),v.end()); - cout<>t; - while(t--) solve(); - return 0; -} -/* - - - -*/ -","#include -using namespace std; -const int N=1e3+10; -int n,a[N],b[N]; -vector > v; -void solve(){ - v.clear(); - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - b[i]=a[i]; - } - for(int i=1;i<=n;i++){ - for(int j=1;ja[j+1]){ - v.emplace_back(make_pair(a[j],a[j+1])); - swap(a[j],a[j+1]); - } - } - } - reverse(v.begin(),v.end()); - for(int i=1;i>t; - while(t--) solve(); - return 0; -} -",1 -horribleCoder,2052A - Adrenaline Rush,c++17 ,300102970,300101795,"#include -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - unordered_set bks; - for(int i=n-1;i>0;i--){ - int cur=a[i]-1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=n){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - bks.emplace(a[i]); - } - cout << ans.size(); - cout << ""\n""; - for(auto& [a,b]:ans){ - cout << a << "" "" << b << ""\n""; - } - return 0; -} -","#include -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - int back=0; - unordered_set bks; - for(int i=n-1;i>0;i--){ - int l=a[i]+i-1-back;//going all the way left&back to pos - an+=l; - int cur=back+1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=i+1){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - back++; - bks.emplace(a[i]); - } - cout << an; - cout << ""\n""; - for(auto& [a,b]:ans){ - cout << a << "" "" << b << ""\n""; - } - return 0; -} -",1 -roshan_saini_18,2052A - Adrenaline Rush,c++23 ,298056692,298065745,"#include -#include -#include -#define ll long long int -using namespace std; - -int main() { - int z; - cin>>z; - int a[z]; - int b[z]; - vector> v(z,vector (z,0)); - for(int i=0;i>a[i]; - b[i]=i+1; - } - vector> ans; - for(int i=0;ii) - { - ans.push_back({a[i],b[j-1]}); - swap(b[j],b[j-1]); - v[b[j]-1][b[j-1]-1]=1; - j--; - } - } - } - for(int i=z-1;i>=1;i--){ - int j=i-1; - while(j>=0&&v[b[i]-1][b[j]-1]==0&&v[b[j]-1][b[i]-1]==0){ - ans.push_back({b[i],b[j]}); - j--; - } - while(j -#include -#include -#define ll long long int -using namespace std; - -int main() { - int z; - cin>>z; - int a[z]; - int b[z]; - for(int i=0;i>a[i]; - b[i]=z-i; - } - vector> ans; - for(int i=z;i>=2;i--){ - for(int j=i-1;j>=1;j--){ - ans.push_back({i,j}); - } - } - for(int i=0;ii){ - ans.push_back({a[i],b[j-1]}); - swap(b[j],b[j-1]); - j--; - } - } - cout< -using namespace std; -#define int long long -#define all(x) (x).begin(),(x).end() -typedef pair PII; -const int N = 2e6 + 10; - -int a[N]; - -void solve() { - int n; - cin>>n; - mappos; - vectorans; - for(int i=1;i<=n;i++){ - cin>>a[i]; - pos[a[i]]=i; - } - for(int i=1;i<=n;i++){ - for(int j=pos[i];j=i+1;j--){ - swap(a[j],a[j-1]); - pos[a[j]]=j; - pos[a[j-1]]=j-1; - ans.push_back({j,j-1}); - // for(int i=1;i<=n;i++){ - // cout<=0;i--){ - cout<> T; - while (T--) solve(); - return 0; -} -","#include -using namespace std; -#define int long long -#define all(x) (x).begin(),(x).end() -typedef pair PII; -const int N = 2e6 + 10; - -int a[N]; - -void solve() { - int n; - cin>>n; - mappos; - vectorans; - for(int i=1;i<=n;i++){ - cin>>a[i]; - pos[a[i]]=i; - } - for(int i=1;i<=n;i++){ - for(int j=pos[i];j=i+1;j--){ - swap(a[j],a[j-1]); - pos[a[j]]=j; - pos[a[j-1]]=j-1; - ans.push_back({a[j],a[j-1]}); - // for(int i=1;i<=n;i++){ - // cout<=0;i--){ - cout<> T; - while (T--) solve(); - return 0; -} -",2 -kalp_shah_19,2052A - Adrenaline Rush,c++17 ,301113582,301242486,"#include -using namespace std; -#define int long long -#define fr(i, a, b) for (int i = a; i < b; i++) -#define vi vector -#define vc vector -#define pb push_back -#define ub(x, v) upper_bound(v.begin(), v.end(), x) -#define lb(x, v) lower_bound(v.begin(), v.end(), x) -#define lbi(x, v) lower_bound(v.begin(), v.end(), x) - v.begin() -#define ubi(x, v) upper_bound(v.begin(), v.end(), x) - v.begin() -#define all(a) (a).begin(), (a).end() -int power(int a, int b) -{ - int result = 1; - while (b) - { - if (b & 1) - result = result * a; - a = a * a; - b >>= 1; - } - return result; -} -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -signed main() -{ - fast; - { - int n; - cin >> n; - vi v(n); - fr(i, 0, n) { cin >> v[i]; } - vector> p; - map m; - fr(i, 0, n - 1) - { - fr(j, 1 + i, n) - { - if (v[i] > v[j]) - { - m[v[i]].pb(v[j]); - } - else - { - m[v[i]].pb(v[j]); - m[v[j]].pb(v[i]); - } - } - } - for (int i = n; i > 0; i--) - { - if (!m[i].empty()) - { - sort(all(m[i])); - vi temp; - for (int j = m[i].size() - 1; j >= 0; j--) - { - if (m[i][j] > i) - { - temp.pb(m[i][j]); - } - else - { - p.pb({i, m[i][j]}); - } - } - if (!temp.empty()) - { - sort(all(temp)); - fr(j, 0, temp.size()) - { - p.pb({i, temp[j]}); - } - } - } - } - cout << p.size() << endl; - fr(i, 0, p.size()) - { - cout << p[i].first << "" "" << p[i].second << endl; - } - } -} -/* -1 2 3 4 5 -5 3 2 1 4 -tot = 13 -unordered -5 3 -5 2 -5 1 -5 4 -3 2 -3 1 -4 3 -3 4 -2 1 -4 2 -2 4 -4 1 -1 4 - -if we sort -5 4 -5 3 -5 2 -5 1 -5 1 2 3 4 -4 3 -4 2 -4 1 -5 4 1 2 3 -3 2 -3 1 -3 4 -5 3 4 1 2 -2 1 -2 4 -5 3 2 4 1 -1 4 -5 3 2 1 4 - - - -2 1 -3 1 -4 1 -5 1 -2 3 4 5 1 -4 3 -4 2 - -1 4 -*/ -","#include -using namespace std; -#define int long long -#define fr(i, a, b) for (int i = a; i < b; i++) -#define vi vector -#define vc vector -#define pb push_back -#define ub(x, v) upper_bound(v.begin(), v.end(), x) -#define lb(x, v) lower_bound(v.begin(), v.end(), x) -#define lbi(x, v) lower_bound(v.begin(), v.end(), x) - v.begin() -#define ubi(x, v) upper_bound(v.begin(), v.end(), x) - v.begin() -#define all(a) (a).begin(), (a).end() -int power(int a, int b) -{ - int result = 1; - while (b) - { - if (b & 1) - result = result * a; - a = a * a; - b >>= 1; - } - return result; -} -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -signed main() -{ - fast; - { - int n; - cin >> n; - vi v(n); - fr(i, 0, n) { cin >> v[i]; } - vector> p; - set done; - map m; - fr(i, 0, n) - { - fr(j, v[i] + 1, n + 1) - { - if (done.find(j) == done.end()) - { - p.pb({j, v[i]}); - } - } - for (int j = n; j > v[i]; j--) - { - if (done.find(j) == done.end()) - { - p.pb({v[i], j}); - } - } - for (int j = v[i]-1; j > 0; j--) - { - if (done.find(j) == done.end()) - { - p.pb({v[i], j}); - } - } - done.insert(v[i]); - } - // for (int i = n; i > 1; i--) - // { - // if (!m[i].empty()) - // { - // sort(all(m[i])); - // vi temp; - // for (int j = m[i].size() - 1; j >= 0; j--) - // { - // if (m[i][j] > i) - // { - // temp.pb(m[i][j]); - // } - // else - // { - // p.pb({i, m[i][j]}); - // } - // } - // if (!temp.empty()) - // { - // sort(all(temp)); - // fr(j, 0, temp.size()) - // { - // p.pb({i, temp[j]}); - // } - // } - // } - // } - // if (!m[1].empty()) - // { - // sort(all(m[1])); - // for (int i = m[1].size() - 1; i >= 0; i--) - // { - // p.pb({1, m[1][i]}); - // } - // } - - cout << p.size() << endl; - fr(i, 0, p.size()) - { - cout << p[i].first << "" "" << p[i].second << endl; - } - } -} -/* -1 2 3 4 5 -5 3 2 1 4 -tot = 13 -unordered -5 3 -5 2 -5 1 -5 4 -3 2 -3 1 -4 3 -3 4 -2 1 -4 2 -2 4 -4 1 -1 4 - -if we sort -5 4 -5 3 -5 2 -5 1 -5 1 2 3 4 -4 3 -4 2 -4 1 -5 4 1 2 3 -3 2 -3 1 -3 4 -5 3 4 1 2 -2 1 -2 4 -5 3 2 4 1 -1 4 -5 3 2 1 4 - -3 -1 2 3 -unordered -1 2 -2 1 -1 3 -3 1 -2 3 -3 2 - ordered -3 2 -3 1 -3 1 2 -2 1 -2 3 -2 3 1 -1 3 -1 2 - -4 1 2 3 -4 1 -4 2 -4 3 -2 1 -// 1 2 -3 1 -// 1 3 -3 2 -// 2 3 - -4 3 -4 2 -4 1 -4 1 2 3 -3 2 -2 3 - -4 3 1 2 -2 1 -2 3 -4 2 3 1 - -*/ -",2 -Individuality1,2052A - Adrenaline Rush,c++23 ,300493404,300493716,"#include -using namespace std; -#define all(x) x.begin(), x.end() -#define int long long -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int a,b,d,k;; - cin>>b; - vector v;for(int i=0;i>d;v.insert(v.end(),d);} - vector c; - vector n(b); - vector> g; - for(int i=0;i=1;j--){ - if(n[j]!=1){ - g.insert(g.end(),{v[i],j}); - } - } - } - cout< -using namespace std; -#define all(x) x.begin(), x.end() -#define int long long -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int a,b,d,k;; - cin>>b; - vector v;for(int i=0;i>d;v.insert(v.end(),d);} - vector c; - vector n(b); - vector> g; - for(int i=0;i=1;j--){ - if(n[j]!=1){ - g.insert(g.end(),{v[i],j}); - } - } - } - cout< -using namespace std; -#define int long long -#define PII pair -#define tul array -#define rep(i,a,b) for(int i=a;i<=b;++i) -#define rep_(i,a,b) for(int i=a;i>=b;--i) -#define all(x) x.begin(),x.end() -#define bp(x) __builtin_popcountll(x) -#define ctz(x) __builtin_ctzll(x) -#define cy cout<<""YES""< to[N]; -int n,m,a[N],b[N]; -inline int mod(int x){ - return (x%yyx+yyx)%yyx; -} -inline int cmin(int &x,int y){ - return x>y?x=y,1:0; -} -inline int cmax(int &x,int y){ - return x t; -void bfs(){ - rep_(i,n,1) rep_(j,i-1,1) t.push_back({i,j}); - rep(i,1,n) b[i]=n-i+1; - rep(i,1,n){ - int z=1; - rep(j,1,n) if(a[i]==b[j]) z=j; - while(z>i){ - t.push_back({b[z],b[z-1]}); - swap(b[z],b[z-1]); - z--; - } - } -} -inline void solve(){ - cin>>n; - rep(i,1,n) cin>>a[i]; - bfs(); - cout<sync_with_stdio(0); - //freopen(""D://321//in.txt"",""r"",stdin); - //freopen(""D://321//out.txt"",""w"",stdout); - int _=1; - //cin>>_; - while(_--) - solve(); - return 0; -}","/* - 卫风·芄兰 -芄兰之支,童子佩觿. -虽则佩觿,能不我知? -容兮遂兮,垂带悸兮. -芄兰之叶,童子佩韘. -虽则佩韘,能不我甲? -容兮遂兮,垂带悸兮. -*/ -#pragma GCC optimize(""Ofast"") -#include -using namespace std; -#define int long long -#define PII pair -#define tul array -#define rep(i,a,b) for(int i=a;i<=b;++i) -#define rep_(i,a,b) for(int i=a;i>=b;--i) -#define all(x) x.begin(),x.end() -#define bp(x) __builtin_popcountll(x) -#define ctz(x) __builtin_ctzll(x) -#define cy cout<<""YES""< to[N]; -int n,m,a[N]; -inline int mod(int x){ - return (x%yyx+yyx)%yyx; -} -inline int cmin(int &x,int y){ - return x>y?x=y,1:0; -} -inline int cmax(int &x,int y){ - return x>n; - set s; - vector t; - rep(i,1,n) cin>>a[i]; - rep(i,1,n){ - rep(j,1,i-1){ - if(a[j]sync_with_stdio(0); - //freopen(""D://321//in.txt"",""r"",stdin); - //freopen(""D://321//out.txt"",""w"",stdout); - int _=1; - //cin>>_; - while(_--) - solve(); - return 0; -}",1 -Arvi_saleque,2052A - Adrenaline Rush,c++20 ,302157794,302159467,"#include -using namespace std; -typedef long long int ll; -const int N = 1002, M = 2e5 + 9, mod = 998244353, inf = 1e9; -void solve() { - int n; - cin >> n; - vector v(n), pos(n + 1); - for(int i = 0; i < n; i++) { - cin >> v[i]; - pos[v[i]] = i; - } - vector> vec; - for(int i = 1; i <= n; i++) { - for(int j = pos[i] - 1; j >= 0; j--) { - if(v[j] > i) { - vec.push_back({v[j], i}); - } - else { - vec.push_back({i, v[j]}); - vec.push_back({v[j], i}); - } - } - } - cout << vec.size() << ""\n""; - for(auto [x, y] : vec) { - cout << x << "" "" << y << ""\n""; - } -} -int main() { - ios_base::sync_with_stdio(0); cin.tie(0); - int t = 1, cs = 1; - //cin >> t; - while (t--) { - //cout << ""Case "" << cs++ << "": ""; - solve(); - } - return 0; -} -","#include -using namespace std; -typedef long long int ll; -const int N = 1002, M = 2e5 + 9, mod = 998244353, inf = 1e9; -void solve() { - int n; - cin >> n; - vector v(n), ans(n + 1); - for(int i = 0; i < n; i++) { - cin >> v[i]; - ans[i] = i + 1; - } - vector> vec; - for(int i = n - 1; i >= 0; i--) { - int val = v[i], pos = 0; - for(int j = 0; j < n; j++) { - if(ans[j] == val) { - pos = j; - break; - } - } - for(int j = pos - 1; j >= 0; j--) { - vec.push_back({val, ans[j]}); - } - for(int j = 0; j < pos; j++) { - vec.push_back({ans[j], val}); - } - for(int j = pos + 1; j <= i; j++) { - vec.push_back({ans[j], ans[j - 1]}); - swap(ans[j], ans[j - 1]); - } - } - cout << vec.size() << ""\n""; - for(auto [x, y] : vec) { - cout << x << "" "" << y << ""\n""; - } -} -int main() { - ios_base::sync_with_stdio(0); cin.tie(0); - int t = 1, cs = 1; - //cin >> t; - while (t--) { - //cout << ""Case "" << cs++ << "": ""; - solve(); - } - return 0; -} -",2 -PumpKIN_,2052A - Adrenaline Rush,c++20 ,297022725,297023505,"#include -using namespace std; -#define ll long long -#define endl '\n' - -void solve() -{ - ll n,val,pos;cin>>n; - vector v(n),p(n); - vector > vp; - - for(auto &i:v) cin>>i; - iota(p.begin(),p.end(),1); - - for(int i=n-1;i>=0;i--){ - val=v[i]; - for(int j=0;j=0;j--){ - vp.push_back({p[j],val}); - swap(p[j],p[j+1]); - } - for(int j=0;j>t; - while(t--){ - solve(); - } -} -","#include -using namespace std; -#define ll long long -#define endl '\n' - -void solve() -{ - ll n,val,pos;cin>>n; - vector v(n),p(n); - vector > vp; - - for(auto &i:v) cin>>i; - iota(p.begin(),p.end(),1); - - for(int i=n-1;i>=0;i--){ - val=v[i]; - for(int j=0;j=0;j--){ - vp.push_back({val,p[j]}); - swap(p[j],p[j+1]); - } - for(int j=0;j>t; - while(t--){ - solve(); - } -} -",2 -xiaoyin0,2052A - Adrenaline Rush,c++17 ,297076347,297075887,"#include -using namespace std; -using ll=long long; -ll i,j,k,t,n,m; -struct pxy -{ - ll x,y; -}; -int main() -{ - cin>>n; - ll a[n+10],b[n+10]; - mapvv; - for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i; - pxy c[2000000]; - ll q=0; - for(i=n;i>=1;i--) - { - for(j=vv[a[i]];j>1;j--) - { - c[++q].x=b[j],c[q].y=b[j-1]; - vv[b[j]]=j-1; - vv[b[j-1]]=j; - swap(b[j],b[j-1]); - } - for(j=1;j -using namespace std; -using ll=long long; -ll i,j,k,t,n,m; -struct pxy -{ - ll x,y; -}; -int main() -{ - cin>>n; - ll a[n+10],b[n+10]; - mapvv; - for(i=1;i<=n;i++)cin>>a[i],b[i]=i,vv[b[i]]=i; - pxy c[100000]; - ll q=0; - for(i=n;i>=n;i--) - { - for(j=vv[b[i]];j>1;j--) - { - c[++q].x=b[j],c[q].y=b[j-1]; - vv[b[j]]=j-1; - vv[b[j-1]]=j; - swap(b[j],b[j-1]); - } - for(j=1;j -using namespace std; -#define int long long - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -const int INF = 1e18; - -void Solve() -{ - int n; - cin >> n; - vector a(n + 1), pos(n + 1); - for(int i = 1; i <= n; i++) { - cin >> a[i]; - pos[a[i]] = i; - } - vector > overtakes; - vector current_positioning; - current_positioning.push_back(1); - for(int i = 2; i <= n; i++) { - for(int j = current_positioning.size() - 1; j >= 0; j--) { - overtakes.push_back({i, current_positioning[j]}); - } - for(int j = 0; j < current_positioning.size(); j++) { - if(pos[current_positioning[j]] < pos[i]) { - overtakes.push_back({current_positioning[j], i}); - } - else { - current_positioning.insert(current_positioning.begin() + j, i); - break; - } - } - - if(current_positioning.size() == i - 1) { - current_positioning.push_back(i); - } - - // for(int j = 0; j < current_positioning.size(); j++) { - // cout << current_positioning[j] << "" ""; - // } - // cout << ""\n""; - } - - // for(int i = 0; i < n; i++) { - // for(int j = i + 1; j < n; j++) { - // if(a[i] < a[j]) { - // overtakes.push_back({a[j], a[i]}); - // overtakes.push_back({a[i], a[j]}); - // } - // else { - // overtakes.push_back({a[i], a[j]}); - // } - // } - // } - - cout << overtakes.size() << ""\n""; - for(auto p: overtakes) { - cout << p.first << "" "" << p.second << ""\n""; - } -} - -int32_t main() -{ - auto begin = std::chrono::high_resolution_clock::now(); - ios_base::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - for(int i = 1; i <= t; i++) - { - //cout << ""Case #"" << i << "": ""; - Solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - //cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - return 0; -}","#include -using namespace std; -#define int long long - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -const int INF = 1e18; - -void Solve() -{ - int n; - cin >> n; - vector a(n); - for(int &x: a) { - cin >> x; - } - vector > overtakes; - for(int i = 0; i < n; i++) { - for(int j = i + 1; j < n; j++) { - if(a[i] < a[j]) { - overtakes.push_back({a[j], a[i]}); - overtakes.push_back({a[i], a[j]}); - } - else { - overtakes.push_back({a[i], a[j]}); - } - } - } - - cout << overtakes.size() << ""\n""; - for(auto p: overtakes) { - cout << p.first << "" "" << p.second << ""\n""; - } -} - -int32_t main() -{ - auto begin = std::chrono::high_resolution_clock::now(); - ios_base::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - for(int i = 1; i <= t; i++) - { - //cout << ""Case #"" << i << "": ""; - Solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - //cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - return 0; -}",1 -belfie123,2052A - Adrenaline Rush,c++17 ,297169769,297169228,"#include -using namespace std; -#include -#include -using namespace __gnu_pbds; - -void dbg_out() { cerr << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) - -#define rep(i,a,b) for(ll i=(a); i<(b); ++i) -#define repc(i,a,b,c) for(ll i=(a); i<(b); i+=c) -#define repn(i,a,b) for(ll i=(a); i>(b); --i) -#define trav(a,x) for(auto& a: x) -#define travm(a,x) for(const auto& [a, v]: x) -#define all(x) begin(x),end(x) -#define sz(x) (int)size(x) -#define tmod(a) ((a%MOD)+MOD)%MOD -#define tmod2(a) ((a%MOD2)+MOD2)%MOD2 -#define tmodc(a,b) ((a%b)+b)%b -#define madd(a,b) (tmod(a)+tmod(b))%MOD -#define madd2(a,b) (tmod2(a)+tmod2(b))%MOD2 -#define maddc(a,b,c) (tmodc(a,c)+tmodc(b,c))%c -#define pb push_back -#define mp make_pair -#define cauto const auto -using ll = long long; -int iINF = numeric_limits::max(); -int MOD = 1e9+7; -int MOD2 = 1e9+22; -#define int ll -using ld = long double; -using pii = pair; -using pll = pair; -using vi = vector; -using vd = vector; -using vll = vector; -using vpii = vector; - -ll lINF = numeric_limits::max(); -ll negINF = lINF+1; -double EPS = .00001; -cauto maxn = 200001; - -/* -3 1 4 2 - -4 3 >3notseen inc - -3 4 allbutseen dec -3 2 -3 1 - -2 1 >1notseen inc -4 1 - -1 4 allbutseen dec -1 2 - -4 2 allbutseen dec -*/ -void solve() -{ - int n; - cin >> n; - vi a(n+1); - rep(i,1,n+1) cin >> a[i]; - vpii moves; - vi seen(n+1); - rep(i,1,n) - { - seen[a[i]] = 1; - rep(j,a[i]+1,n+1) if(!seen[j]) moves.pb({j,a[i]}); - repn(j,n,0) if(!seen[j]) moves.pb({a[i],j}); - } - cout << sz(moves) << ""\n""; - trav(move,moves) cout << move.first << "" "" << move.second << ""\n""; -} -void pre() -{ - -} -int32_t main() -{ - ios::sync_with_stdio(false); - pre(); - int t=1; //cin >> t; - while(t--) solve(); -} -/* -When flooring double that has been divided, add .00000000001 -Careful mixing subtracting and mod! -*/","#include -using namespace std; -#include -#include -using namespace __gnu_pbds; - -void dbg_out() { cerr << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#define dbg(...) cerr << ""("" << #__VA_ARGS__ << ""):"", dbg_out(__VA_ARGS__) - -#define rep(i,a,b) for(ll i=(a); i<(b); ++i) -#define repc(i,a,b,c) for(ll i=(a); i<(b); i+=c) -#define repn(i,a,b) for(ll i=(a); i>(b); --i) -#define trav(a,x) for(auto& a: x) -#define travm(a,x) for(const auto& [a, v]: x) -#define all(x) begin(x),end(x) -#define sz(x) (int)size(x) -#define tmod(a) ((a%MOD)+MOD)%MOD -#define tmod2(a) ((a%MOD2)+MOD2)%MOD2 -#define tmodc(a,b) ((a%b)+b)%b -#define madd(a,b) (tmod(a)+tmod(b))%MOD -#define madd2(a,b) (tmod2(a)+tmod2(b))%MOD2 -#define maddc(a,b,c) (tmodc(a,c)+tmodc(b,c))%c -#define pb push_back -#define mp make_pair -#define cauto const auto -using ll = long long; -int iINF = numeric_limits::max(); -int MOD = 1e9+7; -int MOD2 = 1e9+22; -#define int ll -using ld = long double; -using pii = pair; -using pll = pair; -using vi = vector; -using vd = vector; -using vll = vector; -using vpii = vector; - -ll lINF = numeric_limits::max(); -ll negINF = lINF+1; -double EPS = .00001; -cauto maxn = 200001; - -/* -4 3 -4 2 -4 1 -3 2 -3 1 -2 1 - -1 2 -1 3 -1 4 -2 3 -2 4 -3 4 -*/ -void solve() -{ - int n; - cin >> n; - vi a(n+1); - rep(i,1,n+1) cin >> a[i]; - vpii groups; - int st = a[1]; - int sz = 1; - rep(i,2,n+1) - { - if(a[i]==st+sz) sz++; - else groups.pb({st,sz}), st = a[i], sz = 1; - } - groups.pb({st,sz}); - vpii moves; - vi seen(n+1); - rep(i,1,n+1) - { - repn(j,a[i]-1,0) if(!seen[j]) moves.pb({a[i],j}); - seen[a[i]] = 1; - } - trav(group,groups) - { - if(group.second==1) continue; - repn(i,group.first+group.second-1,group.first) repn(j,i-1,group.first-1) moves.pb({i,j}); - rep(i,group.first,group.first+group.second-1) rep(j,i+1,group.first+group.second) moves.pb({i,j}); - } - cout << sz(moves) << ""\n""; - trav(move,moves) cout << move.first << "" "" << move.second << ""\n""; -} -void pre() -{ - -} -int32_t main() -{ - ios::sync_with_stdio(false); - pre(); - int t=1; //cin >> t; - while(t--) solve(); -} -/* -When flooring double that has been divided, add .00000000001 -Careful mixing subtracting and mod! -*/",1 -Anuj0Sharma,2052A - Adrenaline Rush,c++20 ,297082191,297074327,"#include -using namespace std; -#define f(i, a) for(ll (i) = 0; (i)<(a) ;(i)++) -#define r(i, a) for (ll (i) = a-1; (i)>=0 ;(i)--) -#define F(i, a, b) for(ll (i) = (a); (i)<(b) ;(i)++) -#define R(i, a, b) for (ll (i) = (b)-1; (i)>=(a) ;(i)--) -#define pb push_back -#define lb lower_bound -#define ub upper_bound -#define ll long long int - - -void sol(){ - ll n; - cin>>n; - ll a[n+1] = {0}; - ll c[n]; - ll b[n]; - f(i, n) {cin>>b[i]; c[i] = i+1;} - vector> v; - r(i, n){ - ll vic = b[i]; - a[vic] = 1; - ll j=0; - f(k, n){if(c[k]==vic){j=k;break;}} - while(j>0){ - j--; - v.pb({c[j+1], c[j]}); - swap(c[j], c[j+1]); - } - while(j>T; while(T--) - { - sol(); - } -}","#include -using namespace std; -#define f(i, a) for(ll (i) = 0; (i)<(a) ;(i)++) -#define r(i, a) for (ll (i) = a-1; (i)>=0 ;(i)--) -#define F(i, a, b) for(ll (i) = (a); (i)<(b) ;(i)++) -#define R(i, a, b) for (ll (i) = (b)-1; (i)>=(a) ;(i)--) -#define pb push_back -#define lb lower_bound -#define ub upper_bound -#define ll long long int - - -void sol(){ - ll n; - cin>>n; - ll a[n+1] = {0}; - ll b[n]; - f(i, n) cin>>b[i]; - vector> v; - r(i, n){ - ll vic = b[i]; - a[vic] = 1; - ll j = vic-1; - while(j>0){ - // cout<>T; while(T--) - { - sol(); - } -}",1 -qfshen,2052A - Adrenaline Rush,c++17 ,300575272,300573472,"// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - set S; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - S.insert(i); - } - - vector ans; - - for(int i = n;i >= 1;i --) { - for(int j = a[i] - 1;j >= 1;j --) { - if(S.count(j) == 0) continue; - ans.push_back({a[i], j}); - } - S.erase(a[i]); - for(auto t : S) { - ans.push_back({t, a[i]}); - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -","// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - } - - vector ans; - - for(int i = n;i >= 1;i --) { - if(a[i] < i) { - for(int j = a[i] + 1;j <= i;j ++) { - ans.push_back({j, a[i]}); - } - } else { - if(i == 1) break; - ans.push_back({a[i], a[i - 1]}); - ans.push_back({a[i - 1], a[i]}); - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -",1 -mostafa133,2052A - Adrenaline Rush,c++17 ,304412402,304411984,"#include -#include -#include -typedef long long ll; -typedef long double ld; -using namespace std; -using namespace __gnu_pbds; -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define all(x) x.begin(), x.end() -#define pll pair -#define vec vector -#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -const ll mod = 998244353; -ll fpow(ll a, ll b, ll m = -1) -{ - if (m != -1) - a %= m; - ll res = 1; - while (b > 0) - { - if (b % 2 == 1) - { - if (m != -1) - res = res * a % m; - else - { - res *= a; - } - } - a = a * a; - if (m != -1) - { - a %= m; - } - b /= 2; - } - return res; -} -int main() -{ - fast; - // freopen(""pails.in"", ""r"", stdin); - // freopen(""pails.out"", ""w"", stdout); - ll t = 1; - // cin >> t; -end:; - while (t--) - { - ll n, k; - cin >> n; - vec v(n); - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - set st; - ll mx = 0; - vec ans; - for (int i = 0; i < n; i++) - { - for(int j = i - 1; j >= 0; j--) - { - swap(v[j+1], v[j]); - ans.push_back({v[j+1], v[j]}); - } - ll in = 0; - while(in < i && v[in]> v[in+1]) - { - swap(v[in], v[in+1]); - ans.push_back({v[in+1], v[in]}); - in++; - } - } - reverse(all(ans)); - cout << ans.size() << '\n'; - for (int i = 0; i < ans.size(); i++) - { - cout << ans[i].first << ' ' << ans[i].second << '\n'; - } - - } - return 0; -}","#include -#include -#include -typedef long long ll; -typedef long double ld; -using namespace std; -using namespace __gnu_pbds; -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define all(x) x.begin(), x.end() -#define pll pair -#define vec vector -#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -const ll mod = 998244353; -ll fpow(ll a, ll b, ll m = -1) -{ - if (m != -1) - a %= m; - ll res = 1; - while (b > 0) - { - if (b % 2 == 1) - { - if (m != -1) - res = res * a % m; - else - { - res *= a; - } - } - a = a * a; - if (m != -1) - { - a %= m; - } - b /= 2; - } - return res; -} -int main() -{ - fast; - // freopen(""pails.in"", ""r"", stdin); - // freopen(""pails.out"", ""w"", stdout); - ll t = 1; - // cin >> t; -end:; - while (t--) - { - ll n, k; - cin >> n; - vec v(n); - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - set st; - ll mx = 0; - vec ans; - for (int i = 0; i < n; i++) - { - for(int j = i - 1; j >= 0; j--) - { - swap(v[j+1], v[j]); - ans.push_back({v[j+1], v[j]}); - } - ll in = 0; - while(in < i && v[in]> v[in+1]) - { - swap(v[in], v[in+1]); - ans.push_back({v[in+1], v[in]}); - } - } - reverse(all(ans)); - cout << ans.size() << '\n'; - for (int i = 0; i < ans.size(); i++) - { - cout << ans[i].first << ' ' << ans[i].second << '\n'; - } - - } - return 0; -}",1 -dhanunjaygurram12340,2052A - Adrenaline Rush,c++23 ,307115098,307113238,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define N 200001 -#define M 1001 - - -using namespace std; -using ll = long long; - -int ord[M],arr[M]; -int state[M][M]; -int find(int x,int n){ - for(int i=1;i<=n;i++){ - if(arr[i] == x){ - return i; - } - } - return -1; -} - -int main(){ - int n; - cin>>n; - //ll ans = 0ll; - for(int i=0;i<=n;i++){ - for(int j=0;j<=n;j++){ - state[i][j] = 0; - } - } - for(int i=1;i<=n;i++){ - cin>>ord[i]; - arr[i] = i; - } - vector > ans; - - for(int i=1;i<=n;i++){ - if(ord[i] == arr[i]){ - continue; - } - else{ - int j = find(ord[i],n); - for(int k=j;kj;k--){ - ans.push_back(make_pair(arr[k],arr[k-1])); - swap(arr[k],arr[k-1]); - state[arr[k-1]][arr[k]] = 1; - } - for(int k=j;k>i;k--){ - ans.push_back(make_pair(arr[k],arr[k-1])); - swap(arr[k],arr[k-1]); - state[arr[k-1]][arr[k]] = 1; - - } - } - } - - for(int i=1;i i){ - while(k != i){ - ans.push_back(make_pair(arr[k],arr[k-1])); - swap(arr[k],arr[k-1]); - state[arr[k]][arr[k-1]] = 1; - k--; - } - } - } - //cout << state[3][1] << endl; - cout << ans.size() << endl; - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define N 200001 -#define M 1001 - - -using namespace std; -using ll = long long; - -int ord[M],arr[M]; -int state[M][M]; -int find(int x,int n){ - for(int i=1;i<=n;i++){ - if(arr[i] == x){ - return i; - } - } - return -1; -} - -int main(){ - int n; - cin>>n; - //ll ans = 0ll; - for(int i=0;i<=n;i++){ - for(int j=0;j<=n;j++){ - state[i][j] = 0; - } - } - for(int i=1;i<=n;i++){ - cin>>ord[i]; - arr[i] = i; - } - vector > ans; - - for(int i=1;i<=n;i++){ - if(ord[i] == arr[i]){ - continue; - } - else{ - int j = find(ord[i],n); - for(int k=j;k>i;k--){ - ans.push_back(make_pair(arr[k],arr[k-1])); - swap(arr[k],arr[k-1]); - state[arr[k-1]][arr[k]] = 1; - - } - } - } - for(int i=1;i i){ - while(k != i){ - ans.push_back(make_pair(arr[k],arr[k-1])); - swap(arr[k],arr[k-1]); - state[arr[k]][arr[k-1]] = 1; - k--; - } - } - } - cout << ans.size() << endl; - for(int i=0;i -#include - -using namespace std; - -int a[1005], cur[1005], ans[1000005], ans1[1000005]; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int n; - cin >> n; - int cnt = 0; - for(int i = 1; i <= n; i++){ - cin >> a[i]; - } - - for(int i = 1; i <= n; i++){ - cur[i] = i; - } - for(int i = n; i >= 2; i--){ - int pos = 0; - for(int j = 1; j <= n; j++){ - if(cur[j] == a[i]){ - pos = j; - break; - } - } - for(int j = pos; j >= 2; j--){ - cnt++; - ans[cnt] = cur[j]; - ans1[cnt] = cur[j - 1]; - swap(cur[j], cur[j - 1]); - } - for(int j = 1; j <= i - 1; j++){ - cnt++; - ans[cnt] = cur[j + 1]; - ans1[cnt] = cur[j]; - swap(cur[j], cur[j + 1]); - } - } - - cout << cnt << ""\n""; - for(int i = 1; i <= cnt; i++){ - cout << ans[i] << "" "" << ans1[i] << ""\n""; - } - return 0; -}","#include -#include - -using namespace std; - -int a[1005], cur[1005], ans[1005], ans1[1005]; - -int main(){ - int n; - cin >> n; - int cnt = 0; - for(int i = 1; i <= n; i++){ - cin >> a[i]; - } - - for(int i = 1; i <= n; i++){ - cur[i] = i; - } - for(int i = n; i >= 2; i--){ - int pos = 0; - for(int j = 1; j <= n; j++){ - if(cur[j] == a[i]){ - pos = j; - break; - } - } - for(int j = pos; j >= 2; j--){ - cnt++; - ans[cnt] = cur[j]; - ans1[cnt] = cur[j - 1]; - swap(cur[j], cur[j - 1]); - } - for(int j = 1; j <= i - 1; j++){ - cnt++; - ans[cnt] = cur[j + 1]; - ans1[cnt] = cur[j]; - swap(cur[j], cur[j + 1]); - } - } - - cout << cnt << ""\n""; - for(int i = 1; i <= cnt; i++){ - cout << ans[i] << "" "" << ans1[i] << ""\n""; - } - return 0; -}",1 -lolanyways,2052A - Adrenaline Rush,c++17 ,307584566,307583481,"#include -using namespace std; -#define int long long -typedef vector ve; -typedef vector vl; -typedef vector> vp; -typedef vector vc; -typedef vector vd; -#define fi first -#define se second -#define pb push_back -#define con continue -#define rep(i,a,b) for (int i=a;i=b;j--) -const double eps = 1e-6; -#define fastio \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define endl ""\n"" -signed main() -{ - fastio; - int n; - cin>>n; - ve v(n); - stacka,b; - rep(i,0,n){ - cin>>v[i]; - a.push(n-i); - } - if(n==1){ - cout<<""0""< -using namespace std; -#define int long long -typedef vector ve; -typedef vector vl; -typedef vector> vp; -typedef vector vc; -typedef vector vd; -#define fi first -#define se second -#define pb push_back -#define con continue -#define rep(i,a,b) for (int i=a;i=b;j--) -const double eps = 1e-6; -#define fastio \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define endl ""\n"" -signed main() -{ - fastio; - int n; - cin>>n; - ve v(n); - stacka,b; - rep(i,0,n){ - cin>>v[i]; - a.push(n-i); - } - res(j,n-1,0){ - while(a.top()!=v[j]){ - cout< -#include -#include - -using namespace std; -using namespace __gnu_pbds; -template using ordered_set =tree, rb_tree_tag,tree_order_statistics_node_update>; - -#define int long long -#define pb push_back -#define in insert - -#define sortva(ans) sort(ans.begin(), ans.end()); -#define sortvd(ans) sort(ans.rbegin(), ans.rend()); - -const int MOD = 1e9+7; - -void printVec(vector &ans){ - for(int i=0;i> n; - - vector v(n+1); - vector pos(n+1); - for(int i = 1; i <= n ; i++){ - cin >> v[i]; - pos[i] = i; - } - - vector> ans; - for(int i = 1; i <= n; i++){ - int idx = -1; - for(int j = 1; j <= n; j++){ - if(v[i] == pos[j]){ - idx = j; - break; - } - } - - for(int j = idx; j < n; j++){ - ans.pb({pos[j+1], pos[j]}); - swap(pos[j], pos[j+1]); - } - - for(int j = n; j > idx; j--){ - ans.pb({pos[j], pos[j-1]}); - swap(pos[j], pos[j-1]); - } - - for(int j = idx; j > i; j--){ - ans.pb({pos[j], pos[j-1]}); - swap(pos[j], pos[j-1]); - } - - } - - cout << ans.size() << ""\n""; - for(auto x : ans){ - cout << x.first << "" "" << x.second << ""\n""; - } - - -} - -int32_t main(){ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t = 1; - // cin >> t; - while(t--){solve();} - return 0; -} - - - - - - -","#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; -template using ordered_set =tree, rb_tree_tag,tree_order_statistics_node_update>; - -#define int long long -#define pb push_back -#define in insert - -#define sortva(ans) sort(ans.begin(), ans.end()); -#define sortvd(ans) sort(ans.rbegin(), ans.rend()); - -const int MOD = 1e9+7; - -void printVec(vector &ans){ - for(int i=0;i> n; - - vector v(n+1); - vector pos(n+1); - for(int i = 1; i <= n ; i++){ - cin >> v[i]; - pos[v[i]] = i; - } - - vector check(n+1); - vector posele(n+1); - for(int i = 1; i <= n ; i++){ - check[i] = i; - posele[i] = i; - } - - vector> ans; - for(int i = 1; i <= n; i++){ - if(pos[v[i]] <= check[v[i]]){ - vector> temp; - for(int j = check[v[i]] + 1; j <= n; j++){ - ans.pb({posele[j], v[i]}); - temp.pb({posele[j], v[i]}); - } - reverse(temp.begin(), temp.end()); - for(auto x : temp){ - ans.pb({x.second, x.first}); - } - for(int j = check[v[i]] - 1; j >= i; j--){ - ans.pb({v[i], posele[j]}); - check[check[j]] += 1; - } - check[v[i]] = i; - for(int j = 1; j <= n; j++){ - posele[check[j]] = j; - } - } - } - - cout << ans.size() << ""\n""; - for(auto x : ans){ - cout << x.first << "" "" << x.second << ""\n""; - } - - -} - -int32_t main(){ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t = 1; - // cin >> t; - while(t--){solve();} - return 0; -} - - - - - - -",1 -Runntime_terrorr,2052A - Adrenaline Rush,c++17 ,298432479,299033754,"#include -using namespace std; -#define ll long long -#define vll vector -#define vpll vector> -#define fl(n) for (ll i=0; i < n; i++) -#define st(v) sort(v.begin(),v.end()) -#define pb push_back - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - ll t; - t=1; - - - while (t--) { - ll n; cin >> n; - vll v(n); - fl(n)cin>>v[i]; - vpll ans; - for(int i=0;i -using namespace std; - -#define ll long long -#define vll vector -#define vpll vector> -#define fl(n) for (ll i=0; i < n; i++) -#define st(v) sort(v.begin(),v.end()) -#define pb push_back -#define el '\n' -#define mod 998244353 - -ll mod_inverse(ll a,ll m) { - ll res=1,p=m - 2; - while (p > 0) { - if (p & 1) res=(res * a)%m; - a=(a * a)%m; - p >>= 1; - } - return res; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - t=1; - while (t--) { - int n;cin>>n;vll v(n);fl(n){cin>>v[i];} vpll ans; - vll x(n);fl(n){x[i]=i+1;} - for(int i=n-1;i>=0;i--){ - - bool found=false;int a; - for(int j=n-1;j>=0;j--){ - if(found){ - // cout< -using namespace std; - -typedef pair ii; - -const int Maxn = 1005; - -int n; -vector res; - -void Solve(const vector &seq) -{ - if (seq.empty()) return; - int mn = 0; - for (int i = 0; i < seq.size(); i++) - if (seq[i] < seq[mn]) mn = i; - vector tmp; - for (int i = 0; i < seq.size(); i++) - if (i != mn) tmp.push_back(seq[i]); - Solve(tmp); - for (int i = 0; i < tmp.size(); i++) - res.push_back({tmp[i], seq[mn]}); - for (int i = int(seq.size()) - 1; i > mn; i--) - res.push_back({seq[mn], seq[i]}); -} - -int main() -{ - scanf(""%d"", &n); - vector seq; - for (int i = 1; i <= n; i++) { - int num; scanf(""%d"", &num); - seq.push_back(num); - } - Solve(seq); - printf(""%d\n"", int(res.size())); - for (int i = 0; i < res.size(); i++) - printf(""%d %d\n"", res[i].first, res[i].second); - return 0; -} -","#include -using namespace std; - -typedef pair ii; - -const int Maxn = 1005; - -int n; -int c[Maxn]; -vector res; - -void Solve(int l, int r) -{ - if (l > r) return; - int mn = l; - for (int i = l; i <= r; i++) - if (c[i] < c[mn]) mn = i; - for (int i = l; i <= r; i++) - if (i != mn) - res.push_back({c[i], c[mn]}); - Solve(l, mn - 1); - Solve(mn + 1, r); - for (int i = r; i > mn; i--) - res.push_back({c[mn], c[i]}); -} - -int main() -{ - scanf(""%d"", &n); - for (int i = 1; i <= n; i++) - scanf(""%d"", &c[i]); - Solve(1, n); - printf(""%d\n"", int(res.size())); - for (int i = 0; i < res.size(); i++) - printf(""%d %d\n"", res[i].first, res[i].second); - return 0; -} -",1 -qfshen,2052A - Adrenaline Rush,c++17 ,300574103,300575272,"// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - } - - vector ans; - - for(int i = n;i >= 1;i --) { - if(a[i] < i) { - for(int j = a[i];j < i;j ++) { - ans.push_back({a[j], a[i]}); - } - } else { - if(i == 1) break; - int idx = -1; - for(int j = i;j >= 1;j --) { - if(a[j] < j) { - idx = j + 1; - break; - } - } - if(idx == -1) idx = 1; - vector tmp; - int len = i - idx; - int cnt = 0; - while(cnt < len) { - int j = i; - for(;j > idx + cnt;j --) { - tmp.push_back({a[j], a[j - 1]}); - ans.push_back({a[j], a[j - 1]}); - swap(a[j], a[j - 1]); - - } - cnt ++; - } - reverse(tmp.begin(), tmp.end()); - for(auto t : tmp) { - ans.push_back({t.second, t.first}); - } - i = idx; - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -","// Problem: A. Adrenaline Rush -// Contest: Codeforces - 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) -// URL: https://codeforces.com/problemset/problem/2052/A -// Memory Limit: 1024 MB -// Time Limit: 3000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -typedef pair pii; -typedef pair pil; -typedef pair pli; - -const int M = 1e9+7; -const int N = 2e6 + 10; -int a[N], b[N]; -int l[N], r[N]; -char g[110][110]; -char mapp[110][110]; -bool st[110][110]; -int n, m; - -void solve() { - cin >> n; - set S; - for(int i = 1;i <= n;i ++) { - cin >> a[i]; - S.insert(i); - } - - vector ans; - - for(int i = n;i >= 1;i --) { - for(int j = a[i] - 1;j >= 1;j --) { - if(S.count(j) == 0) continue; - ans.push_back({a[i], j}); - } - S.erase(a[i]); - for(auto t : S) { - ans.push_back({t, a[i]}); - } - } - - cout << ans.size() << endl; - for(auto t : ans) { - cout << t.first << "" "" << t.second << endl; - } -} - -int main() { - ios::sync_with_stdio(false); - int t = 1; - // cin >> t; - while(t --) { - solve(); - } - return 0; -} - -",2 -jomathyc,2052A - Adrenaline Rush,c++17 ,298343379,298344472,"#include -using namespace std; -using ll=long long; -#define sig(x) (x<0?-1:1) -#define sz(x) ((int)size(x)) -#define all(x) begin(x),end(x) -#define all1(x) begin(x)+1,end(x) -#define cmax(x,y) x=max(x,y) -#define cmin(x,y) x=min(x,y) -template void vprint(T st, T nd) {auto it=st;while (next(it)!=nd){cout<<*it<<' ';it=next(it);}cout<<*it<<'\n';} -void yn(bool ans) {puts(ans?""yes"":""no"");} -template T cdiv(T a, T b) {return a/b+(sig(a)/sig(b)==1 && a%b);} -template using vec=vector; -template struct vec2:vector> {vec2()=default;vec2(int n, int m, T val=T()):vector>(n,vector(m,val)){}}; -template struct vec3:vector>> {vec3()=default;vec3(int n, int m, int k, T val=T()):vector>>(n,vector>(m,vector(k,val))){}}; -template void reset(T *arr, int l, int r, T val) {fill(arr+l,arr+r+1,val);} - -const int N=1000; -int n; -int c[N+1]; - -int cind[N+1]; - -void solve() { - for (int i=1; i<=n; ++i) { - cind[c[i]]=i; - } - - vec a(n+1); - for (int i=1; i<=n; ++i) { - a[i]=i; - } - - vec> ans; - for (int x=1; x<=n; ++x) { - int i=find(all1(a),x)-begin(a); - - // pass everyone ahead - for (int j=i-1; j>=1; --j) { - ans.push_back({a[j+1],a[j]}); - swap(a[j],a[j+1]); - } - - // let actual ahead go through - i=1; - for (int j=2; j<=n; ++j) { - // a[j] pass x? - if (cind[a[j]]=i; --k) { - ans.push_back({a[k+1],a[k]}); - swap(a[k],a[k+1]); - } - - i++; - } - } - } - - printf(""%d\n"", sz(ans)); - for (auto &[x,y]:ans) { - printf(""%d %d\n"", x,y); - } -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - cin>>n; - for (int i=1; i<=n; ++i) cin>>c[i]; - solve(); -} -","#include -using namespace std; -using ll=long long; -#define sig(x) (x<0?-1:1) -#define sz(x) ((int)size(x)) -#define all(x) begin(x),end(x) -#define all1(x) begin(x)+1,end(x) -#define cmax(x,y) x=max(x,y) -#define cmin(x,y) x=min(x,y) -template void vprint(T st, T nd) {auto it=st;while (next(it)!=nd){cout<<*it<<' ';it=next(it);}cout<<*it<<'\n';} -void yn(bool ans) {puts(ans?""yes"":""no"");} -template T cdiv(T a, T b) {return a/b+(sig(a)/sig(b)==1 && a%b);} -template using vec=vector; -template struct vec2:vector> {vec2()=default;vec2(int n, int m, T val=T()):vector>(n,vector(m,val)){}}; -template struct vec3:vector>> {vec3()=default;vec3(int n, int m, int k, T val=T()):vector>>(n,vector>(m,vector(k,val))){}}; -template void reset(T *arr, int l, int r, T val) {fill(arr+l,arr+r+1,val);} - -const int N=1000; -int n; -int c[N+1]; - -int cind[N+1]; - -void solve() { - for (int i=1; i<=n; ++i) { - cind[c[i]]=i; - } - - vec a(n+1); - for (int i=1; i<=n; ++i) { - a[i]=i; - } - - vec> ans; - for (int y=1; y<=n; ++y) { - int x=c[n-y+1]; - int i=find(all1(a),x)-begin(a); - - // pass everyone ahead - for (int j=i-1; j>=1; --j) { - ans.push_back({a[j+1],a[j]}); - swap(a[j],a[j+1]); - } - - // let actual ahead go through - i=1; - for (int j=2; j<=n; ++j) { - // a[j] pass x? - if (cind[a[j]]=i; --k) { - ans.push_back({a[k+1],a[k]}); - swap(a[k],a[k+1]); - } - - i++; - } - } - } - - printf(""%d\n"", sz(ans)); - for (auto &[x,y]:ans) { - printf(""%d %d\n"", x,y); - } -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - cin>>n; - for (int i=1; i<=n; ++i) cin>>c[i]; - solve(); -} -",2 -kalp_shah_19,2052A - Adrenaline Rush,c++17 ,301114999,301242486,"#include -using namespace std; -#define int long long -#define fr(i, a, b) for (int i = a; i < b; i++) -#define vi vector -#define vc vector -#define pb push_back -#define ub(x, v) upper_bound(v.begin(), v.end(), x) -#define lb(x, v) lower_bound(v.begin(), v.end(), x) -#define lbi(x, v) lower_bound(v.begin(), v.end(), x) - v.begin() -#define ubi(x, v) upper_bound(v.begin(), v.end(), x) - v.begin() -#define all(a) (a).begin(), (a).end() -int power(int a, int b) -{ - int result = 1; - while (b) - { - if (b & 1) - result = result * a; - a = a * a; - b >>= 1; - } - return result; -} -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -signed main() -{ - fast; - { - int n; - cin >> n; - vi v(n); - fr(i, 0, n) { cin >> v[i]; } - vector> p; - map m; - fr(i, 0, n - 1) - { - fr(j, 1 + i, n) - { - if (v[i] > v[j]) - { - m[v[i]].pb(v[j]); - } - else - { - m[v[i]].pb(v[j]); - m[v[j]].pb(v[i]); - } - } - } - for (int i = n; i > 1; i--) - { - if (!m[i].empty()) - { - sort(all(m[i])); - vi temp; - for (int j = m[i].size() - 1; j >= 0; j--) - { - if (m[i][j] > i) - { - temp.pb(m[i][j]); - } - else - { - p.pb({i, m[i][j]}); - } - } - if (!temp.empty()) - { - sort(all(temp)); - fr(j, 0, temp.size()) - { - p.pb({i, temp[j]}); - } - } - } - } - sort(all(m[1])); - for(int i = m[1].size()-1;i>=0;i--){ - p.pb({1,m[1][i]}); - } - cout << p.size() << endl; - fr(i, 0, p.size()) - { - cout << p[i].first << "" "" << p[i].second << endl; - } - } -} -/* -1 2 3 4 5 -5 3 2 1 4 -tot = 13 -unordered -5 3 -5 2 -5 1 -5 4 -3 2 -3 1 -4 3 -3 4 -2 1 -4 2 -2 4 -4 1 -1 4 - -if we sort -5 4 -5 3 -5 2 -5 1 -5 1 2 3 4 -4 3 -4 2 -4 1 -5 4 1 2 3 -3 2 -3 1 -3 4 -5 3 4 1 2 -2 1 -2 4 -5 3 2 4 1 -1 4 -5 3 2 1 4 - -3 -1 2 3 -unordered -1 2 -2 1 -1 3 -3 1 -2 3 -3 2 - ordered -3 2 -3 1 -3 1 2 -2 1 -2 3 -2 3 1 -1 3 -1 2 - -4 1 2 3 -4 1 -4 2 -4 3 -2 1 -// 1 2 -3 1 -// 1 3 -3 2 -// 2 3 - -4 3 -4 2 -4 1 -4 1 2 3 -3 2 -2 3 - -4 3 1 2 -2 1 -2 3 -4 2 3 1 - -*/ -","#include -using namespace std; -#define int long long -#define fr(i, a, b) for (int i = a; i < b; i++) -#define vi vector -#define vc vector -#define pb push_back -#define ub(x, v) upper_bound(v.begin(), v.end(), x) -#define lb(x, v) lower_bound(v.begin(), v.end(), x) -#define lbi(x, v) lower_bound(v.begin(), v.end(), x) - v.begin() -#define ubi(x, v) upper_bound(v.begin(), v.end(), x) - v.begin() -#define all(a) (a).begin(), (a).end() -int power(int a, int b) -{ - int result = 1; - while (b) - { - if (b & 1) - result = result * a; - a = a * a; - b >>= 1; - } - return result; -} -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -signed main() -{ - fast; - { - int n; - cin >> n; - vi v(n); - fr(i, 0, n) { cin >> v[i]; } - vector> p; - set done; - map m; - fr(i, 0, n) - { - fr(j, v[i] + 1, n + 1) - { - if (done.find(j) == done.end()) - { - p.pb({j, v[i]}); - } - } - for (int j = n; j > v[i]; j--) - { - if (done.find(j) == done.end()) - { - p.pb({v[i], j}); - } - } - for (int j = v[i]-1; j > 0; j--) - { - if (done.find(j) == done.end()) - { - p.pb({v[i], j}); - } - } - done.insert(v[i]); - } - // for (int i = n; i > 1; i--) - // { - // if (!m[i].empty()) - // { - // sort(all(m[i])); - // vi temp; - // for (int j = m[i].size() - 1; j >= 0; j--) - // { - // if (m[i][j] > i) - // { - // temp.pb(m[i][j]); - // } - // else - // { - // p.pb({i, m[i][j]}); - // } - // } - // if (!temp.empty()) - // { - // sort(all(temp)); - // fr(j, 0, temp.size()) - // { - // p.pb({i, temp[j]}); - // } - // } - // } - // } - // if (!m[1].empty()) - // { - // sort(all(m[1])); - // for (int i = m[1].size() - 1; i >= 0; i--) - // { - // p.pb({1, m[1][i]}); - // } - // } - - cout << p.size() << endl; - fr(i, 0, p.size()) - { - cout << p[i].first << "" "" << p[i].second << endl; - } - } -} -/* -1 2 3 4 5 -5 3 2 1 4 -tot = 13 -unordered -5 3 -5 2 -5 1 -5 4 -3 2 -3 1 -4 3 -3 4 -2 1 -4 2 -2 4 -4 1 -1 4 - -if we sort -5 4 -5 3 -5 2 -5 1 -5 1 2 3 4 -4 3 -4 2 -4 1 -5 4 1 2 3 -3 2 -3 1 -3 4 -5 3 4 1 2 -2 1 -2 4 -5 3 2 4 1 -1 4 -5 3 2 1 4 - -3 -1 2 3 -unordered -1 2 -2 1 -1 3 -3 1 -2 3 -3 2 - ordered -3 2 -3 1 -3 1 2 -2 1 -2 3 -2 3 1 -1 3 -1 2 - -4 1 2 3 -4 1 -4 2 -4 3 -2 1 -// 1 2 -3 1 -// 1 3 -3 2 -// 2 3 - -4 3 -4 2 -4 1 -4 1 2 3 -3 2 -2 3 - -4 3 1 2 -2 1 -2 3 -4 2 3 1 - -*/ -",2 -vinayak_20,2052A - Adrenaline Rush,java,297055671,297054035,"import java.util.*; -import java.io.*; - -public class A_Adrenaline_Rush { - - int mod = (int) 1e9 + 7; - - public static void main(String[] args) { - int n = sc.nextInt(); - int[] f = new int[n]; - input(f); - int[] a = new int[n]; - for(int i=0;i l = new ArrayList<>(); - for(int i=1;i0){ - int temp = a[j]; - a[j] = a[j-1]; - a[j-1] = temp; - l.add(new int[]{a[j-1],a[j]}); - j--; - } - } - for(int i=0;ii){ - int temp = a[j]; - a[j] = a[j-1]; - a[j-1] = temp; - l.add(new int[]{a[j-1],a[j]}); - j--; - } - // if(dest>0){ - // while(j long gcd(T a, T b) { - return b.longValue() == 0 ? a.longValue() : gcd(b, a.longValue() % b.longValue()); - } - - static FastReader sc = new FastReader(); - - static class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreTokens()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine().trim(); - } catch (Exception e) { - e.printStackTrace(); - } - return str; - } - } -}","import java.util.*; -import java.io.*; - -public class A_Adrenaline_Rush { - - int mod = (int) 1e9 + 7; - - public static void main(String[] args) { - int n = sc.nextInt(); - int[] f = new int[n]; - input(f); - int[] a = new int[n]; - for(int i=0;i l = new ArrayList<>(); - for(int i=0;i0 && a[j]>a[j-1]){ - int temp = a[j]; - a[j] = a[j-1]; - a[j-1] = temp; - l.add(new int[]{a[j-1],a[j]}); - j--; - } - if(dest>0){ - while(j long gcd(T a, T b) { - return b.longValue() == 0 ? a.longValue() : gcd(b, a.longValue() % b.longValue()); - } - - static FastReader sc = new FastReader(); - - static class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreTokens()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine().trim(); - } catch (Exception e) { - e.printStackTrace(); - } - return str; - } - } -}",1 -spidey_04,2052A - Adrenaline Rush,c++17 ,297030646,297021740,"/*JAI MAHAKAAL*/ - -#include - -using namespace std; - -#define int long long int -#define f first -#define s second -#define pb push_back -#define si set -#define vi vector -#define pii pair -#define vpi vector -#define vpp vector > -#define mii map -#define mpi map -#define spi set -#define endl ""\n"" -#define sz(x) ((int) x.size()) -#define all(p) p.begin(), p.end() -#define double long double -#define que_max priority_queue -#define que_min priority_queue > -#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) -#define print(a) for(auto x : a) cout << x << "" ""; cout << endl -#define print1(a) for(auto x : a) cout << x.f << "" "" << x.s << endl -#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< "" ""; cout << endl - -inline int power(int a, int b) -{ - int x = 1; - while (b) - { - if (b & 1) x *= a; - a *= a; - b >>= 1; - } - return x; -} - -template -void __f (const char* name, Arg1&& arg1) { cout << name << "" : "" << arg1 << endl; } -template -void __f (const char* names, Arg1&& arg1, Args&&... args) -{ - const char* comma = strchr (names + 1, ','); - cout.write (names, comma - names) << "" : "" << arg1 << "" | ""; __f (comma + 1, args...); -} - -const int N = 200005; - -void solve() { - int n; - cin >> n; - vi a(n), c(n); - mapind, m; - for (int i = 0; i < n; i++) { - cin >> c[i]; - ind[c[i]] = i; - } - for (int i = 0; i < n; i++) { - a[i] = i + 1; - m[a[i]] = i; - } - mpi mp; - vpi v; - for (int i = 0; i < n; i++)a[i] = i + 1; - int i = n - 1; - int ans = 0; - while (i >= 0) { - int j = m[c[i]]; - while (j < i) { - v.pb({a[j + 1], a[j]}); - swap(a[j], a[j + 1]); - int mi = min(a[j], a[j + 1]); - int ma = max(a[j], a[j + 1]); - mp[ {mi, ma}]++; - ans++; - j++; - } - for (int i = 0; i < n; i++) { - m[a[i]] = i; - } - i--; - } - vpi temp; - for (int i = n; i >= 1; i--) { - int j = ind[i]; - while (j >= 0) { - if (c[j - 1] < i) { - v.pb({i, c[j - 1]}); - temp.pb({i, c[j - 1]}); - ans += 2; - } - j--; - } - } - int size = temp.size(); - for (int j = size - 1; j >= 0; j--) { - int x = temp[j].f; - int y = temp[j].s; - v.pb({y, x}); - } - cout << ans << endl; - for (int i = 0; i < v.size(); i++) { - cout << v[i].f << "" "" << v[i].s << endl; - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - clock_t z = clock(); - - int t = 1; - //cin >> t; - while (t--) solve(); - - cerr << ""Run Time : "" << ((double)(clock() - z) / CLOCKS_PER_SEC); - - return 0; -}","/*JAI MAHAKAAL*/ - -#include - -using namespace std; - -#define int long long int -#define f first -#define s second -#define pb push_back -#define si set -#define vi vector -#define pii pair -#define vpi vector -#define vpp vector > -#define mii map -#define mpi map -#define spi set -#define endl ""\n"" -#define sz(x) ((int) x.size()) -#define all(p) p.begin(), p.end() -#define double long double -#define que_max priority_queue -#define que_min priority_queue > -#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) -#define print(a) for(auto x : a) cout << x << "" ""; cout << endl -#define print1(a) for(auto x : a) cout << x.f << "" "" << x.s << endl -#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< "" ""; cout << endl - -inline int power(int a, int b) -{ - int x = 1; - while (b) - { - if (b & 1) x *= a; - a *= a; - b >>= 1; - } - return x; -} - -template -void __f (const char* name, Arg1&& arg1) { cout << name << "" : "" << arg1 << endl; } -template -void __f (const char* names, Arg1&& arg1, Args&&... args) -{ - const char* comma = strchr (names + 1, ','); - cout.write (names, comma - names) << "" : "" << arg1 << "" | ""; __f (comma + 1, args...); -} - -const int N = 200005; - -void solve() { - int n; - cin >> n; - vi a(n), c(n); - mapind; - for (int i = 0; i < n; i++) { - cin >> c[i]; - ind[c[i]] = i; - } - mpi mp; - vpi v; - for (int i = 0; i < n; i++)a[i] = i + 1; - int ans = 0; - int i = 0; - while (i < n) { - if (a[i] == c[i]) { - i++; - continue; - } - int j = i; - int id = ind[a[i]]; - while (j < id) { - int mi = min(a[j], a[j + 1]); - int ma = max(a[j], a[j + 1]); - mp[ {mi, ma}]++; - v.pb({a[j + 1], a[j]}); - swap(a[j], a[j + 1]); - ans++; - j++; - } - } - for (int i = n - 1; i >= 0; i--) { - vpi temp; - for (int j = i - 1; j >= 0; j--) { - int mi = min(a[j], a[i]); - int ma = max(a[j], a[i]); - if (mp.find({mi, ma}) == mp.end()) { - mp[ {mi, ma}]++; - ans += 2; - temp.pb({a[i], a[j]}); - v.pb({a[i], a[j]}); - } - else break; - } - int size = temp.size(); - for (int j = size - 1; j >= 0; j--) { - int x = temp[j].f; - int y = temp[j].s; - v.pb({y, x}); - } - } - cout << ans << endl; - for (int i = 0; i < v.size(); i++) { - cout << v[i].f << "" "" << v[i].s << endl; - } -} - -int32_t main() -{ - ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - clock_t z = clock(); - - int t = 1; - //cin >> t; - while (t--) solve(); - - cerr << ""Run Time : "" << ((double)(clock() - z) / CLOCKS_PER_SEC); - - return 0; -}",1 -nskzaya,2052A - Adrenaline Rush,c++23 ,298636574,298637052,"#include -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define fix(x) fixed<; -using ll = long long; -using ld = long double; -using pii = pair; -using tiii = tuple; -const int N = 1e6 + 10; -const int mod = 1e9 + 7; - -void solve() -{ - int n;cin>>n; - auto a=vei(n+1); - for(int i=1;i<=n;i++) cin>>a[i]; - vectorf; - for(int i=1;i<=n;i++) - { - for(int j=1;ja[j+1]) - { - swap(a[j],a[j+1]); - f.push_back({a[j],a[j+1]}); - } - } - } - reverse(f.begin(),f.end()); - cout<> _; - while (_--) solve(); - return 0; -}","#include -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define fix(x) fixed<; -using ll = long long; -using ld = long double; -using pii = pair; -using tiii = tuple; -const int N = 1e6 + 10; -const int mod = 1e9 + 7; - -void solve() -{ - int n;cin>>n; - auto a=vei(n+1); - for(int i=1;i<=n;i++) cin>>a[i]; - vectorf; - for(int i=1;i<=n;i++) - { - for(int j=1;ja[j+1]) - { - swap(a[j],a[j+1]); - f.push_back({a[j],a[j+1]}); - } - } - } - reverse(f.begin(),f.end()); - cout<> _; - while (_--) solve(); - return 0; -}",2 -Catastrophe,2052A - Adrenaline Rush,c++23 ,298646462,298645974,"#include -#define INF (int)1e9 -#define EPS 1e-9 -#define PI 3.1415926535897932384626433832795 -#define MOD 1000000007 -#define sig signed -#define ll long long int -#define rep(i,s,e) for(ll i=s; i=e; i--) -#define reppr(n) for(ll i = n-1; i >= 0; i--) -#define pb push_back -#define all(x) x.begin(), x.end() -#define mp(x, y) make_pair(x, y) -using namespace std; - -// 1 2 3 - -// 3 1 2 - -// 2 3 1 - -// 1 5 3 2 4 6 - -// 6 4 2 3 5 1 - -// 1 2 3 4 5 6 - -// 6 1 2 3 4 5 ->5 - -// 6 4 1 2 3 5 ->3 - -// 6 4 2 1 3 5 ->1 - -// 6 4 2 3 1 5 ->1 - -// 6 4 2 3 5 1->1 - - -// 2 3 1 - -// 1 2 3 - -// 1 3 2 - -void solve(){ - int n; - cin>>n; - vector a(n); - - vector init(n); - repp(n) - { - cin>>a[i]; - init[i]=i+1; - } - reverse(a.begin(),a.end()); - vector> ans; - // cout<<""fe""; - // ll ans=0; - // ans+=(n*1LL*(n-1))/2; - // 1 3 2 - repp(n) - { - int val=a[i]; - int ind=-1; - rep(j,i,n) - { - if(init[j]==val) - { - ind=j; - break; - } - } - for(int k=ind;k>i;k--) - { - ans.push_back({init[k],init[k-1]}); - swap(init[k-1],init[k]); - } - } - for(int i=0;ii;k--) - { - ans.push_back({init[k],init[k-1]}); - swap(init[k-1],init[k]); - } - } - cout<> t; - - while(t--){ - solve(); - } - - return 0; -}","#include -#define INF (int)1e9 -#define EPS 1e-9 -#define PI 3.1415926535897932384626433832795 -#define MOD 1000000007 -#define sig signed -#define ll long long int -#define rep(i,s,e) for(ll i=s; i=e; i--) -#define reppr(n) for(ll i = n-1; i >= 0; i--) -#define pb push_back -#define all(x) x.begin(), x.end() -#define mp(x, y) make_pair(x, y) -using namespace std; - -// 1 2 3 - -// 3 1 2 - -// 2 3 1 - -// 1 5 3 2 4 6 - -// 6 4 2 3 5 1 - -// 1 2 3 4 5 6 - -// 6 1 2 3 4 5 ->5 - -// 6 4 1 2 3 5 ->3 - -// 6 4 2 1 3 5 ->1 - -// 6 4 2 3 1 5 ->1 - -// 6 4 2 3 5 1->1 - - -// 2 3 1 - -// 1 2 3 - -// 1 3 2 - -void solve(){ - int n; - cin>>n; - vector a(n); - - vector init(n); - repp(n) - { - cin>>a[i]; - init[i]=i+1; - } - reverse(a.begin(),a.end()); - vector> ans; - // cout<<""fe""; - // ll ans=0; - // ans+=(n*1LL*(n-1))/2; - repp(n) - { - int val=a[i]; - int ind=-1; - rep(j,i,n) - { - if(init[j]==val) - { - ind=j; - break; - } - } - for(int k=ind;k>i;k--) - { - ans.push_back({init[k-1],init[k]}); - swap(init[k-1],init[k]); - } - - } - for(int i=0;ii;k--) - { - ans.push_back({init[k-1],init[k]}); - swap(init[k-1],init[k]); - } - } - cout<> t; - - while(t--){ - solve(); - } - - return 0; -}",1 -lyj_,2052A - Adrenaline Rush,c++17 ,299741049,299741199,"#include -#include -#include -#include -#include -#include -#include -#include -#define fi first -#define se second -#define pb push_back -#define ppb pop_back -#define int long long -using namespace std; - -const int N=1100,mod=1e9+7; -int a[N],b[N]; -int s=0,n=0; -pair ans[N]; - -void go(int cur,int begin,int end) { - for (int i=begin;iend;--i) { - ans[++s]={b[i],b[i-1]}; - swap(b[i],b[i-1]); - } -} - -signed main() { - cin>>n; - for (int i=1;i<=n;++i) cin>>a[i]; - for (int i=1;i<=n;++i) b[i]=i; - for (int i=1;i<=n;++i) { - int pos; - for (int j=1;j<=n;++j) { - if (a[i]==b[j]) pos=j; - } - go(a[i],pos,i); - //cout< -#include -#include -#include -#include -#include -#include -#include -#define fi first -#define se second -#define pb push_back -#define ppb pop_back -#define int long long -using namespace std; - -const int N=1000000,mod=1e9+7; -int a[N],b[N]; -int s=0,n=0; -pair ans[N]; - -void go(int cur,int begin,int end) { - for (int i=begin;iend;--i) { - ans[++s]={b[i],b[i-1]}; - swap(b[i],b[i-1]); - } -} - -signed main() { - cin>>n; - for (int i=1;i<=n;++i) cin>>a[i]; - for (int i=1;i<=n;++i) b[i]=i; - for (int i=1;i<=n;++i) { - int pos; - for (int j=1;j<=n;++j) { - if (a[i]==b[j]) pos=j; - } - go(a[i],pos,i); - //cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int n; - cin>>n; - vector v(n) ,final_(n); - - // n = 4; - // final_ = {2,3,1,4}; - // v = {4,3,2,1}; - - for(int i=0;i>a; - final_[a-1] = i+1; - v[i] = n-i; - v[n-i] = i; - } - - // for(int i=0;i> swaps; - for(int i=n-1;i>=0;i--){ - int j = i-1; - while(v[i] != final_[i]){ - swap(v[i],v[j]); - // cout< &p:swaps) - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int n,a; - cin>>n; - - // n = 4; - vector v(n); - vector final_(n); - vector index_v(n+1); - vector index_f(n+1); - - for(int i=0;i>a; - final_[a-1] = i+1; - v[i] = n-i; - // index[n-i] = i; - } - - // final_ = {2,3,1,4}; - // final_ = {1,4,2,3}; - // v = {4,3,2,1}; - - for(int i=0;i> swaps; - for(int a = n ;a > 0 ;a--){ - while( v[index_f[a]] != a){ - int b = v[index_f[a]]; - swap(v[index_v[b]],v[index_v[b+1]]); - swaps.push_back({index_v[b+1]+1,index_v[b]+1}); - swap(index_v[b],index_v[b+1]); - // cout< &p:swaps) - cout< -#include -#include -using namespace std; -int main() -{ - int n; // number of cars - cin >> n; // taking input of number of cars - vector a(n); // array of size n to store the positions of the cars - vector b(n); // array of size n to store the positions of the cars - vector c; - for (int i = 0; i < n; i++) - { - b[i] = i + 1; // initialising the positions of the cars - } - for (int i = 0; i < n; i++) // loop to take input of the positions of the cars - { - cin >> a[i]; - } - int count = 0; // intialising counter - for(int i=1;i<=n;i++) - { - int init_position=find(b.begin(),b.end(),i)-b.begin(); - for(int j=init_position;jb[find(b.begin(),b.end(),i)-b.begin()+1] && find(a.begin(),a.end(),i) -#include -#include -using namespace std; -int main() -{ - int n; // number of cars - cin >> n; // taking input of number of cars - vector a(n); // array of size n to store the positions of the cars - vector b(n); // array of size n to store the positions of the cars - vector c; - for (int i = 0; i < n; i++) - { - b[i] = i + 1; // initialising the positions of the cars - } - for (int i = 0; i < n; i++) // loop to take input of the positions of the cars - { - cin >> a[i]; - } - int count = 0; // intialising counter - for(int i=1;i<=n;i++) - { - int init_position=find(b.begin(),b.end(),i)-b.begin(); - for(int j=init_position;jb[find(b.begin(),b.end(),i)-b.begin()+1] && find(a.begin(),a.end(),i) -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - int back=0;//inflation at back - unordered_set bks; - for(int i=n-1;i>0;i--){ - if(bks.find(i+1)!=bks.end())back--; - int l=a[i]+i-1-back;//going all the way left&back to pos - an+=l; - int cur=a[i]-1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=n){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - if(a[i] -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - unordered_set bks; - for(int i=n-1;i>0;i--){ - int cur=a[i]-1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=n){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - bks.emplace(a[i]); - } - cout << ans.size(); - cout << ""\n""; - for(auto& [a,b]:ans){ - cout << a << "" "" << b << ""\n""; - } - return 0; -} -",2 -horribleCoder,2052A - Adrenaline Rush,c++17 ,300102970,300102494,"#include -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - unordered_set bks; - for(int i=n-1;i>0;i--){ - int cur=a[i]-1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=n){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - bks.emplace(a[i]); - } - cout << ans.size(); - cout << ""\n""; - for(auto& [a,b]:ans){ - cout << a << "" "" << b << ""\n""; - } - return 0; -} -","#include -#include -#include -using namespace std; -int main(){ - int n; - cin >> n; - vector a(n); - vector> ans; - int an=0; - for(int i=0;i> j; - a[i]=j; - } - int back=0;//inflation at back - unordered_set bks; - for(int i=n-1;i>0;i--){ - if(bks.find(i+1)!=bks.end())back--; - int l=a[i]+i-1-back;//going all the way left&back to pos - an+=l; - int cur=a[i]-1; - while(cur>0){ - if(bks.find(cur)==bks.end() && cur!=a[i]){ - ans.push_back(make_pair(a[i],cur)); - cur--; - }else{ - cur--; - } - } - cur=1; - while(cur<=i+1){ - if(bks.find(cur)==bks.end()&&cur!=a[i]){ - ans.push_back(make_pair(cur,a[i])); - cur++; - }else{ - cur++; - } - } - if(a[i] -#include -#include -typedef long long ll; -typedef long double ld; -using namespace std; -using namespace __gnu_pbds; -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define all(x) x.begin(), x.end() -#define pll pair -#define vec vector -#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -const ll mod = 998244353; -ll fpow(ll a, ll b, ll m = -1) -{ - if (m != -1) - a %= m; - ll res = 1; - while (b > 0) - { - if (b % 2 == 1) - { - if (m != -1) - res = res * a % m; - else - { - res *= a; - } - } - a = a * a; - if (m != -1) - { - a %= m; - } - b /= 2; - } - return res; -} -int main() -{ - fast; - // freopen(""pails.in"", ""r"", stdin); - // freopen(""pails.out"", ""w"", stdout); - ll t = 1; - // cin >> t; -end:; - while (t--) - { - ll n, k; - cin >> n; - vec v(n); - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - set st; - ll mx = 0; - vec ans; - for (int i = 0; i < n; i++) - { - for (int j = 1; j < v[i]; j++) - { - ans.push_back({v[i], j}); - if(st.count(j)) - { - ans.push_back({j, v[i]}); - } - } - st.insert(v[i]); - } - cout << ans.size() << '\n'; - for (int i = 0; i < ans.size(); i++) - { - cout << ans[i].first << ' ' << ans[i].second << '\n'; - } - - } - return 0; -}","#include -#include -#include -typedef long long ll; -typedef long double ld; -using namespace std; -using namespace __gnu_pbds; -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define all(x) x.begin(), x.end() -#define pll pair -#define vec vector -#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) -const ll mod = 998244353; -ll fpow(ll a, ll b, ll m = -1) -{ - if (m != -1) - a %= m; - ll res = 1; - while (b > 0) - { - if (b % 2 == 1) - { - if (m != -1) - res = res * a % m; - else - { - res *= a; - } - } - a = a * a; - if (m != -1) - { - a %= m; - } - b /= 2; - } - return res; -} -int main() -{ - fast; - // freopen(""pails.in"", ""r"", stdin); - // freopen(""pails.out"", ""w"", stdout); - ll t = 1; - // cin >> t; -end:; - while (t--) - { - ll n, k; - cin >> n; - vec v(n); - for (int i = 0; i < n; i++) - { - cin >> v[i]; - } - set st; - ll mx = 0; - vec ans; - for (int i = 0; i < n; i++) - { - for(int j = i - 1; j >= 0; j--) - { - swap(v[j+1], v[j]); - ans.push_back({v[j+1], v[j]}); - } - ll in = 0; - while(in < i && v[in]> v[in+1]) - { - swap(v[in], v[in+1]); - ans.push_back({v[in+1], v[in]}); - in++; - } - } - reverse(all(ans)); - cout << ans.size() << '\n'; - for (int i = 0; i < ans.size(); i++) - { - cout << ans[i].first << ' ' << ans[i].second << '\n'; - } - - } - return 0; -}",2 -lwg,2052A - Adrenaline Rush,c++23 ,302211960,302214615,"#include -using namespace std; -#define int long long -#define double long double -#define popcount __builtin_popcount -#define fal (fa<<1) -#define far (fa<<1|1) -#define endl '\n' -int const N=2e3+5,M=2e3+5,inf=0x7fffffffffffffff,mod=998244353; -int n,m,a[N],b[N],c[N],d[N],cnt=0; -string s[5]; -bool vis=0; -void solve(){ - int i,j,k,h,t,x=0,y=0,z,ans=0,minn=inf,maxn=-inf; - cin>>n; - for(i=1;i<=n;i++){ - c[i]=i; - } - for(i=1;i<=n;i++){ - cin>>a[i]; - b[i]=a[i]; - } - for(i=n;i>=1;i--){ - int now=lower_bound(c+1,c+1+i,a[i])-c; - for(j=now;j>1;j--){ - ans++; - swap(c[j],c[j-1]); - } - for(j=1;j<=now-1;j++){ - ans++; - swap(c[j],c[j+1]); - } - for(j=now;j<=i-1;j++){ - ans++; - swap(c[j],c[j+1]); - } - } - for(i=1;i<=n;i++){ - c[i]=i; - } - cout<=1;i--){ - int now=lower_bound(c+1,c+1+i,a[i])-c; - for(j=now;j>1;j--){ - cout<>t; - t=1; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define int long long -using i64 = long long; -#define print(...) std::cerr << format(__VA_ARGS__) << std::endl -void solve() -{ - int n; - std::cin >> n; - std::vector c(n + 1), a(n + 1); - for (int i = 1; i <= n; i++) - { - a[i] = i; - std::cin >> c[i]; - } - std::vector> ttt; - for(int i = n;i>=1;i--){ - int t = c[i]; - for(int j = t+1;j<=i;j++){ - ttt.push_back(pair(a[j],a[j-1])); - // std::cout << a[j] << "" "" << a[j-1] << ""\n""; - swap(a[j],a[j-1]); - } - } - std::cout << ttt.size() << ""\n""; - for(int i = 0;i -using namespace std; - -void solve(){ - int n; cin >> n; - vector vt(n); - for (int &i : vt) cin >> i; - set> ans; - vector> vtans; - // 1, 2, 3 -> 2, 1, 3 - vector form(n); - for (int i = 0; i < n; i++) - form[i] = i + 1; - for (int i = 0; i < n; i++){ - int idx = i; - for (; idx < n; idx++) - if (form[idx] == vt[i]) - break; - if (idx + 1 < n){ - if (!ans.count({form[idx + 1], form[idx]})){ - vtans.push_back({form[idx + 1], form[idx]}); - ans.insert({form[idx + 1], form[idx]}); - } - if (!ans.count({form[idx], form[idx + 1]})){ - vtans.push_back({form[idx], form[idx + 1]}); - ans.insert({form[idx], form[idx + 1]}); - } - - } - for (int j = idx; j > i; j--){ - if (!ans.count({form[j], form[j - 1]})){ - vtans.push_back({form[j], form[j - 1]}); - ans.insert({form[j], form[j - 1]}); - } - swap(form[j], form[j - 1]); - } - } - cout << ans.size() << '\n'; - for (auto &p : vtans) - cout << p.first << "" "" << p.second << '\n'; -} - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - while (t--) solve(); - return 0; -}","#include -using namespace std; - -void solve(){ - int n; cin >> n; - vector vt(n); - for (int &i : vt) cin >> i; - vector> ans; - for (int i = 1; i < n; i++) - for (int j = i + 1; j <= n; j++) - ans.push_back({j, i}); - vector b(n + 1, false); - for (int i = n - 1; ~i; i--){ - for (int j = vt[i] - 1; j >= 1; j--){ - if (!b[j]) - ans.push_back({j, vt[i]}); - } - b[vt[i]] = true; - } - cout << ans.size() << '\n'; - for (auto &[x, y] : ans) - cout << x << ' ' << y << '\n'; -} - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - int t = 1; - // cin >> t; - while (t--) solve(); - return 0; -}",2 -Pranad,2052A - Adrenaline Rush,c++20 ,304524075,304430430,"#include -using namespace std; -using ll=long long; -using vll=vector; -using pii=pair; -using pll=pair; -#define all(v) (v).begin(),(v).end() -#define sz(v) (ll)(v).size() -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define f(i,a,b) for(ll i=(a);i<(b);i++) -#define fr(i,a,b) for(ll i=(a);i>=(b);i--) -void solve(){ - ll n;cin>>n; - vll a(n); - f(i,0,n){cin>>a[i];} - vector>ans; - vll x(n+1,0); - fr(i,n-1,0) - { - ll val=a[i]; - x[a[i]]=1; - fr(j,val-1,1) - { - if(x[j]==0){ans.pb({val,j});} - } - f(i,1,n+1) - { - if(x[i]!=1) - { - ans.pb({i,val}); - } - } - - } - cout< -using namespace std; -using ll=long long; -using vll=vector; -using pii=pair; -using pll=pair; -#define all(v) (v).begin(),(v).end() -#define sz(v) (ll)(v).size() -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define f(i,a,b) for(ll i=(a);i<(b);i++) -#define fr(i,a,b) for(ll i=(a);i>=(b);i--) - -ll ck(ll x,ll y,ll z){ - return (x-y)*(x-y) + (y-z)*(y-z) + (x-z)*(x-z); -} - -void solve(){ - ll n;cin>>n; - vll a(n); - vll hsh(n+1,0); - f(i,0,n){cin>>a[i]; - hsh[a[i]]=(i+1); - } - map,ll>m; - f(i,1,n+1) - { - ll pos=hsh[i]; - f(j,0,pos) - { - if(a[j]>i){m[{a[j],i}]++;} - } - } - // auto it=m.begin(); - // cout<<""sz""<p=it->F; - // cout<>ans; - f(i,1,n+1) - { - f(j,1,n+1) - { - if(i!=j) - { - pairnow={i,j}; - if(m[{i,j}]==0){ans.pb({i,j});} - } - } - } - cout< -#include -#include -#define ll long long int -using namespace std; - -int main() { - int z; - cin>>z; - int a[z]; - int b[z]; - vector> v(z,vector (z,0)); - for(int i=0;i>a[i]; - b[i]=i+1; - } - vector> ans; - for(int i=0;i -#include -#include -#define ll long long int -using namespace std; - -int main() { - int z; - cin>>z; - int a[z]; - int b[z]; - for(int i=0;i>a[i]; - b[i]=z-i; - } - vector> ans; - for(int i=z;i>=2;i--){ - for(int j=i-1;j>=1;j--){ - ans.push_back({i,j}); - } - } - for(int i=0;ii){ - ans.push_back({a[i],b[j-1]}); - swap(b[j],b[j-1]); - j--; - } - } - cout< -using namespace std; - -typedef long long ll; -typedef unsigned int ui; -typedef unsigned long long int ull; - -#define sim template < class c -#define ris return * this -#define dor > debug & operator << -#define eni(x) sim > typename \ - enable_if(0) x 1, debug&>::type operator<<(c i) { -sim > struct rge {c b, e; }; -sim > rge range(c i, c j) { return rge{i, j}; } -sim > auto dud(c* x) -> decltype(cerr << *x, 0); -sim > char dud(...); -struct debug { -#ifdef LOCAL -~debug() { cerr << endl; } -eni(!=) cerr << boolalpha << i; ris; } -eni(==) ris << range(begin(i), end(i)); } -sim, class b dor(pair < b, c > d) { - ris << ""("" << d.first << "", "" << d.second << "")""; -} -sim dor(rge d) { - *this << ""[""; - for (auto it = d.b; it != d.e; ++it) - *this << "", "" + 2 * (it == d.b) << *it; - ris << ""]""; -} -#else -sim dor(const c&) { ris; } -#endif -}; -#define imie(...) "" ["" << #__VA_ARGS__ "": "" << (__VA_ARGS__) << ""] "" - -// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -// ll my_rand(ll l, ll r) { -// return uniform_int_distribution(l, r) (rng); -// } - -void tcase(int Tcase) -{ - int n; - scanf(""%d"",&n); - int a[n+5], pos[n+5], b[n+5], pos2[n+5]; - for(int i = 1; i <= n; i++){ - scanf(""%d"",&a[i]); - pos[a[i]] = i; - b[i] = n+1-i; - pos2[b[i]] = i; - } - vector>v; - for(int i = 1; i <= n; i++){ - for(int j = i+1; j <= n; j++){ - v.push_back({j, i}); - } - } - int curr = 1; - while(curr < n){ - if(curr == pos[b[curr]]){ - curr++; - continue; - } - int diff = pos2[a[curr]]-curr; - int temp = b[curr+diff]; - for(int i = diff; i > 0; i--){ - v.push_back({b[curr+i], b[curr+i-1]}); - swap(b[curr+i], b[curr+i-1]); - } - for(int i = 1; i <= n; i++) pos2[b[i]] = i; - } - int siz = v.size(); - printf(""%d\n"",siz); - for(int i = 0; i < siz; i++){ - printf(""%d %d\n"",v[i].first, v[i].second); - } -} - -int main(){ - int T = 1; - //scanf(""%d"",&T); - for(int Tcase = 1; Tcase <= T; Tcase++){ - tcase(Tcase); - } -} -","#include -using namespace std; - -typedef long long ll; -typedef unsigned int ui; -typedef unsigned long long int ull; - -#define sim template < class c -#define ris return * this -#define dor > debug & operator << -#define eni(x) sim > typename \ - enable_if(0) x 1, debug&>::type operator<<(c i) { -sim > struct rge {c b, e; }; -sim > rge range(c i, c j) { return rge{i, j}; } -sim > auto dud(c* x) -> decltype(cerr << *x, 0); -sim > char dud(...); -struct debug { -#ifdef LOCAL -~debug() { cerr << endl; } -eni(!=) cerr << boolalpha << i; ris; } -eni(==) ris << range(begin(i), end(i)); } -sim, class b dor(pair < b, c > d) { - ris << ""("" << d.first << "", "" << d.second << "")""; -} -sim dor(rge d) { - *this << ""[""; - for (auto it = d.b; it != d.e; ++it) - *this << "", "" + 2 * (it == d.b) << *it; - ris << ""]""; -} -#else -sim dor(const c&) { ris; } -#endif -}; -#define imie(...) "" ["" << #__VA_ARGS__ "": "" << (__VA_ARGS__) << ""] "" - -// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -// ll my_rand(ll l, ll r) { -// return uniform_int_distribution(l, r) (rng); -// } - -void tcase(int Tcase) -{ - int n; - scanf(""%d"",&n); - int a[n+5], pos[n+5], b[n+5]; - for(int i = 1; i <= n; i++){ - scanf(""%d"",&a[i]); - pos[a[i]] = i; - b[i] = n+1-i; - } - vector>v; - for(int i = 1; i <= n; i++){ - for(int j = i+1; j <= n; j++){ - v.push_back({j, i}); - } - } - int curr = 1; - while(curr < n){ - if(curr == pos[b[curr]]){ - curr++; - continue; - } - int temp = b[curr]; - int diff = pos[temp]-curr; - for(int i = 1; i <= diff; i++){ - v.push_back({b[curr+i], temp}); - b[curr+i-1] = b[curr+i]; - } - b[curr+diff] = temp; - } - int siz = v.size(); - printf(""%d\n"",siz); - for(int i = 0; i < siz; i++){ - printf(""%d %d\n"",v[i].first, v[i].second); - } -} - -int main(){ - int T = 1; - //scanf(""%d"",&T); - for(int Tcase = 1; Tcase <= T; Tcase++){ - tcase(Tcase); - } -} -",1 -LuzZ_ShayanZ,2052A - Adrenaline Rush,c++17 ,299741801,299744711,"#include -#include -#include -using namespace std; - -#define int long long -#define nl cout< -#define vecs vector -#define ddv vector -#define ub upper_bound -#define lb lower_bound -#define prnt(v) for(auto i:v) cout<>i; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define yes cout<<""YES""<>p; a[i] = p; } - -const int N = 2e5; -const int M = 1e9+7; - -int factorials[N+1]; -int factInv[N+1]; -bool isPrime[N+1]; - -int gcd(int a,int b){ //O(logb) - if(!b) return a; - return gcd(b,a%b); -} - -int lcm(int a,int b){ //O(logb) - return (a*b/gcd(a,b)) % M; -} - -int binExp(long long a, int b) { //O(logb) - a %= M; - int ans = 1; - while (b) { - if (b & 1) ans = (ans * 1LL * a) % M; - a = (a * 1LL * a) % M; - b >>= 1; - } - return ans; -} - -int inv(int n){ //O(logM) - return binExp(n,M-2); -} - -void FACT(){ //O(N) - factorials[0] = 1; - for (int i = 1; i <= N; i++) { - factorials[i] = factorials[i - 1] * 1LL * i % M; - } -} - -void FACTINV(){ //O(N) - for (int i = 0; i <= N; i++) { - factInv[i] = inv(factorials[i]); - } -} - -void SIEVE(){ //O(NloglogN) - - //Pre-compute - - fill(isPrime, isPrime+N, true); - isPrime[0]=isPrime[1]=false; - - for(int i = 2; i <= N; ++i){ - if(isPrime[i]){ - for(int j=2*i ; j<=N ; j+=i) - isPrime[j]=false; - } - } -} - -long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N). - - // Pre-Compute before using this func. - // FACT(); - // FACTINV(); - - if (r > n) return 0; - return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M; -} - -void solve(){ - int n; - cin>>n; - vec a(n+1); - pinp(a); - - vec vis(n+1,0); - ddv ans; - - for(int i=n;i>0;--i){ - vis[a[i]] = 1; - for(int j=a[i]+1;j<=n;++j){ - if(!vis[j]){ - ans.pb({j,a[i]}); - } - } - } - - for(int i=1;i>t; - - while(t--){ - solve(); - } - - return 0; -} -","#include -#include -#include -using namespace std; - -#define int long long -#define nl cout< -#define vecs vector -#define ddv vector -#define ub upper_bound -#define lb lower_bound -#define prnt(v) for(auto i:v) cout<>i; -#define all(v) v.begin(),v.end() -#define rall(v) v.rbegin(),v.rend() -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define yes cout<<""YES""<>p; a[i] = p; } - -const int N = 2e5; -const int M = 1e9+7; - -int factorials[N+1]; -int factInv[N+1]; -bool isPrime[N+1]; - -int gcd(int a,int b){ //O(logb) - if(!b) return a; - return gcd(b,a%b); -} - -int lcm(int a,int b){ //O(logb) - return (a*b/gcd(a,b)) % M; -} - -int binExp(long long a, int b) { //O(logb) - a %= M; - int ans = 1; - while (b) { - if (b & 1) ans = (ans * 1LL * a) % M; - a = (a * 1LL * a) % M; - b >>= 1; - } - return ans; -} - -int inv(int n){ //O(logM) - return binExp(n,M-2); -} - -void FACT(){ //O(N) - factorials[0] = 1; - for (int i = 1; i <= N; i++) { - factorials[i] = factorials[i - 1] * 1LL * i % M; - } -} - -void FACTINV(){ //O(N) - for (int i = 0; i <= N; i++) { - factInv[i] = inv(factorials[i]); - } -} - -void SIEVE(){ //O(NloglogN) - - //Pre-compute - - fill(isPrime, isPrime+N, true); - isPrime[0]=isPrime[1]=false; - - for(int i = 2; i <= N; ++i){ - if(isPrime[i]){ - for(int j=2*i ; j<=N ; j+=i) - isPrime[j]=false; - } - } -} - -long long nCr(int n, int r){ //O(1) excl. Pre-Comp which is O(N). - - // Pre-Compute before using this func. - // FACT(); - // FACTINV(); - - if (r > n) return 0; - return (factorials[n] * 1LL * factInv[r] % M * factInv[n - r] % M) % M; -} - -void solve(){ - int n; - cin>>n; - vec a(n+1); - pinp(a); - - vec vis(n+1,0); - ddv ans; - - for(int i=n;i>0;--i){ - vis[a[i]] = 1; - - for(int j=a[i]-1;j>=1;--j){ - if(!vis[j]) - ans.pb({a[i],j}); - } - for(int j=1;ja[r]){ - // ++r; - // } - - // for(int i=r;i>l;--i){ - // for(int j=i-1;j>=l;--j){ - // ans.pb({a[i],a[j]}); - // } - // for(int j=l;j>t; - - while(t--){ - solve(); - } - - return 0; -} -",2 -xcjACMdxcj,2052A - Adrenaline Rush,c++17 ,300585753,300589167,"#include -#include -using namespace std; -const int N=1010; -int a[N]; -int st[N]; -int main(){ - int n; - scanf(""%d"",&n); - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - int cut=0; - for(int i=1;i<=n;i++){ - for(int j=i+1;j<=n;j++){ - if(a[i]>a[j]){ - cut++; - } - } - } - int ans=n*(n-1)-cut; - printf(""%d\n"",ans); - reverse(a+1,a+n+1); - for(int i=1;i<=n;i++){ - int p=a[i]; - for(int j=p-1;j>0;j--){ - if(st[j]) continue; - printf(""%d %d\n"",p,j); - } - for(int j=n;j>=i+1;j--){ - if(st[a[j]]) continue; - printf(""%d %d\n"",a[j],p); - } - st[p]=1; - } - return 0; -}","#include -#include -using namespace std; -const int N=1010; -int a[N]; -int b[N]; -int st[N]; -int main(){ - int n; - scanf(""%d"",&n); - for(int i=1;i<=n;i++){ - cin>>a[i]; - b[i]=i; - } - int cut=0; - for(int i=1;i<=n;i++){ - for(int j=i+1;j<=n;j++){ - if(a[i]>a[j]){ - cut++; - } - } - } - int ans=n*(n-1)-cut; - printf(""%d\n"",ans); - reverse(a+1,a+n+1); - for(int i=1;i<=n;i++){ - int p=a[i]; - for(int j=p-1;j>0;j--){ - if(st[j]) continue; - printf(""%d %d\n"",p,j); - } - st[p]=1; - for(int j=1;j<=n;j++){ - if(st[j]) continue; - printf(""%d %d\n"",j,p); - } - - } - return 0; -}",2 -"Golaby: RezaYazdi, Jalilvand.mJ, Mohammad-Reza#",2052A - Adrenaline Rush,c++17 ,296811810,296817234,"#include -using namespace std; - -typedef long long ll; -typedef pair pll; - -#define len(a) (int) a.size() - - -signed main() { - ios_base::sync_with_stdio(false); - ll n; cin >> n; - vector a(n); - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - if (n == 1) { - return cout << 0, 0; - } - - vector ans; - - for (int i = 0; i < n; i++) { - for (int j = i + 1; j < n; j++) { - if (a[i] > a[j]) { - ans.push_back({a[i], a[j]}); - } else { - ans.push_back({a[j], a[i]}); - ans.push_back({a[i], a[j]}); - } - } - } - - cout << len(ans) << '\n'; - for (auto [l, r]: ans) { - cout << l << ' ' << r << '\n'; - } - - return 0; - -} - -","#include -using namespace std; - -typedef long long ll; -typedef pair pll; - -#define len(a) (int) a.size() - - -signed main() { - ios_base::sync_with_stdio(false); - ll n; cin >> n; - vector a(n), b(n+1); - for (int i = 0; i < n; i++) { - cin >> a[i]; - b[a[i]] = i; - } - if (n == 1) { - return cout << 0, 0; - } - - - vector ans1, ans2, ans3; - - for (int i = 0; i < n; i++) { - for (int j = i + 1; j < n; j++) { - if (a[i] < a[j]) { - ans1.push_back({a[i], a[j]}); - } - } - } - - cout << (len(ans1) + (n * (n - 1)) / 2) << '\n'; - - for (int i = 1; i <= n; i++) { - for (int j = i + 1; j <= n; j++) { - cout << j << ' ' << i << '\n'; - } - } - - // vector b(n); - // iota(b.begin(), b.end(), 1); - // reverse(b.begin(), b.end()); - - // for (int i = 0; i < n; i++) { - // for (int j = i - 1; j >= 0; j--) { - // ans1.push_back({a[i], a[j]}); - // swap - // } - // } - - sort(ans1.begin(), ans1.end(), [&](pll i, pll j) { - if (b[i.first] == b[j.first]) - return i.second < j.second; - return b[i.first] < b[j.first]; - - }); - for (auto [l, r]: ans1) { - cout << l << ' ' << r << '\n'; - } - - return 0; - - -} - -",2 -KritarthSinghal,2052A - Adrenaline Rush,c++23 ,302921574,302919405,"#include -#include -#include -#include -#define mod 998244353 -#include -#include -using namespace std; - - -int main() { - int n; - cin>>n; - vector v(n); - for(int i=0;i>v[i]; - } - vector v2(n); - for(int i =0;i> ans(n*n); - int ans2=0; - for(int i =0;ii;j--) { - ans[ans2] = {v2[j],v2[j-1]}; - ans2++; - int temp = v2[j-1]; - v2[j-1] = v2[j]; - v2[j] = temp; - } - } - cout< -#include -#include -#include -#define mod 998244353 -#include -#include -using namespace std; - - -int main() { - int n; - cin>>n; - vector v(n); - for(int i=0;i>v[i]; - } - vector v2(n); - for(int i =0;i> ans(n*n); - int ans2=0; - for(int i =0;ii;j--) { - ans[ans2] = {v2[j],v2[j-1]}; - ans2++; - int temp = v2[j-1]; - v2[j-1] = v2[j]; - v2[j] = temp; - } - } - cout< -using namespace std; -#include -#define Code ios_base::sync_with_stdio(false); -#define By cin.tie(NULL); - -int main() -{ - int T; - cin >> T; - while (T--) { - int n, k; - cin>>n>>k; - vectora(n); - for(int i =0 ; i < n ; i++){ - cin>>a[i]; - } - unordered_mapmpp; - for(int i =0 ; i < n ; i++){ - mpp[a[i]]++; - } - vectorfreq; - for(auto p : mpp){ - freq.push_back(p.second); - } - sort(freq.begin(), freq.end()); - int min_req = 0 ; - int cnt = k; - int res = 0; - int m = freq.size(); - for(int i = 0 ; i < m ; i++){ - if(cnt>=freq[i]){ - cnt-=freq[i]; - } - else{ - res++; - } - } - if(res == 0 ){ - res =1 ; - } - cout< -#include -#include -using namespace std; -#define Code ios_base::sync_with_stdio(false); -#define By cin.tie(NULL); - -int main() -{ - Code By - int T; - cin >> T; - while (T--) { - int n, k; - cin >> n >> k; - vector a(n); - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - - sort(a.begin(), a.end()); - - vector freq; - int cnt = 1; - for (int i = 1; i < n; i++) { - if (a[i - 1] == a[i]) { - cnt++; - } else { - freq.push_back(cnt); - cnt = 1; - } - } - freq.push_back(cnt); - - sort(freq.begin(), freq.end()); - - int res = 0; - for (int f : freq) { - if (k >= f) { - k -= f; - } else { - res++; - } - } - if(res == 0 ){ - res =1 ; - } - cout << res << endl; - } - - return 0; -} -",2 -utkarshiitbhu1969,2057B - Gorilla and the Exam,c++23 ,307893345,307540251,"#include -using namespace std; -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vector a(n); - //set s; - - map m; - vector freq; - for(int i=0;i>a[i]; - m[a[i]]++; - - //s.insert(a[i]); - } - for (map::iterator it = m.begin(); it != m.end(); it++) { - freq.push_back(it->second); - } - sort(freq.begin(),freq.end()); - - int ans=m.size(); - for(int i=0;i=freq[i]){ - k=k-freq[i]; - ans--; - } - else { - break; - } - } - if(ans==0) cout<<""1""< -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) { - int n, k; - cin >> n >> k; - - unordered_map m; - for (int i = 0; i < n; i++) { - int num; - cin >> num; - m[num]++; - } - - - priority_queue, greater> minHeap; - for (auto& p : m) { - minHeap.push(p.second); - } - - int distinct = m.size(); - - - while (!minHeap.empty() && k >= minHeap.top()) { - k -= minHeap.top(); - minHeap.pop(); - distinct--; - } - - cout << max(1, distinct) < vint; -typedef vector vstr; -typedef pair pii; -typedef vector vii; -typedef unordered_map umap; -#define rep(i,j,k) for(int i=j;i> n >> k; - vint a(n); - rep(i,0,n) cin >> a[i]; - map mp; - rep(i,0,n) mp[a[i]] ++; - int ans = 0; - for(auto i : mp) { - if(i.second <= k) k-= i.second; - else ans++; - } - cout << max(1LL,ans) << endl; -} -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test_n = 1; - cin>>test_n; - for(int t_c = 1;t_c <= test_n;t_c ++){ - solve(); - } - return 0; -}","#include ""bits/stdc++.h"" -using namespace std; - -#define int long long -#define dub long double -typedef vector vint; -typedef vector vstr; -typedef pair pii; -typedef vector vii; -typedef unordered_map umap; -#define rep(i,j,k) for(int i=j;i> n >> k; - vint a(n); - rep(i,0,n) cin >> a[i]; - map mp; - rep(i,0,n) mp[a[i]] ++; - int ans = 0; - vii v; - for(auto i : mp) { - v.push_back({i.second , i.first}); - ans++; - } - sort(all(v)); - for(auto i : v) { - if(i.first <= k) k -= i.first , ans--; - } - cout << max(1LL,ans) << endl; -} -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test_n = 1; - cin>>test_n; - for(int t_c = 1;t_c <= test_n;t_c ++){ - solve(); - } - return 0; -}",2 -anna02,2057B - Gorilla and the Exam,c++17 ,301728676,301724821," #include - -using namespace std; - -int main() { - int t; - cin>>t; - while(t>0) { - int n,k; - cin>>n>>k; - vector v; - map st; - for(int i=0;i>x; - v.push_back(x); - st[x]++; - } - if(k==0) { - cout< v; - for(auto it:st) { - v.push_back(it.second); - } - sort(v.begin(),v.end()); - int i=0; - int m= v.size(); - while(k>0 && i - -using namespace std; - -int main() { - int t; - cin>>t; - while(t>0) { - int n,k; - cin>>n>>k; - vector v; - set st; - for(int i=0;i>x; - v.push_back(x); - st.insert(x); - } - if(k==0) { - cout< uqp; - int unqp=0; - if(v[k1-1]==v[k1]) {unqp--;} - while(k1>0) { - uqp.insert(v[k1-1]); k1--; - } - unqp+=uqp.size(); - k1=n-k; - set uqs; - int unqs=0; - if(v[k1+1]==v[k1]) {unqs--;} - while(k1 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef long long ll; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -void flash(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -#define all(a) a.begin(),a.end() -#define all_r(a) a.rbegin(),a.rend() - -// bool is_suffix(string a, string b) -// { -// reverse(a.begin(), a.end()); -// reverse(b.begin(), b.end()); - -// for(int i = 0; i < b.size(); i++) -// { -// if(a[i] != b[i]) -// return false; -// } - -// return true; -// } - -// bool ispalin(vector& v) -// { -// for(int i = 0; i < v.size() / 2; i++) -// { -// if(v[i] != v[v.size() - i - 1]) -// return false; -// } - -// return true; -// } - - - -int main(void) -{ - flash(); - - int t; - cin>>t; - - while(t--) - { - int n, k; - cin>>n>>k; - - vector v(n); - for(int i = 0; i < n; i++) - cin>>v[i]; - - sort(all(v)); - - int mx = 0; - int cnt = 1; - for(int i = 1; i < n; i++) - { - if(v[i] == v[i-1]) - cnt++; - else - { - mx = max(cnt, mx); - cnt = 1; - } - } - - for(int i = 0; i < n && k > 0; i++) - { - if(v[i] != mx) - { - v[i] = mx; - k--; - } - } - - unordered_set s; - for(int i = 0; i < n; i++) - { - s.insert(v[i]); - } - - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef long long ll; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -void flash(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -#define all(a) a.begin(),a.end() -#define all_r(a) a.rbegin(),a.rend() - -// bool is_suffix(string a, string b) -// { -// reverse(a.begin(), a.end()); -// reverse(b.begin(), b.end()); - -// for(int i = 0; i < b.size(); i++) -// { -// if(a[i] != b[i]) -// return false; -// } - -// return true; -// } - -// bool ispalin(vector& v) -// { -// for(int i = 0; i < v.size() / 2; i++) -// { -// if(v[i] != v[v.size() - i - 1]) -// return false; -// } - -// return true; -// } - - - -int main(void) -{ - flash(); - - int t; - cin>>t; - - while(t--) - { - int n, k; - cin>>n>>k; - - vector v(n); - for(int i = 0; i < n; i++) - cin>>v[i]; - - sort(all(v)); - - vector freq = {1}; - for(int i = 1; i < n; i++) - { - if(v[i] == v[i-1]) - freq.back()++; - else - freq.push_back(1); - } - - sort(all(freq)); - - bool is = false; - for(int i = 0; i < freq.size(); i++) - { - if(freq[i] > k) - { - cout< -using namespace std; -int main(){ - int t;cin>>t; - while(t--){ - long long n,k;cin>>n>>k; - vectorv(n); - mapm; - for(long long i=0;i>v[i];m[v[i]]++;} - vectora; - for(auto& [x,y]:m){a.push_back(y);} - sort(a.begin(),a.end()); - long long ans=a.size(); - for(long long i=0;i=a[i]){k-=a[i];ans--;}} - cout< -using namespace std; -int main(){ - int t;cin>>t; - while(t--){ - long long n,k;cin>>n>>k; - vectorv(n); - mapm; - for(long long i=0;i>v[i];m[v[i]]++;} - vectora; - for(auto& [x,y]:m){a.push_back(y);} - sort(a.begin(),a.end()); - long long ans=a.size(); - for(long long i=0;i=a[i]){k-=a[i];ans--;}} - cout< -using namespace std; - - -int main() { - -ios_base::sync_with_stdio(false); -cin.tie(NULL); - // your code goes here - int t; - cin>>t; - - while(t--) - { - int i,n,k,totaluniq; - cin>>n>>k; - - //int a[n]; - map mp; - - for(i=0;i>temp; - mp[temp]++; - } - - - totaluniq=mp.size(); - - if(k==0) - { - cout<=n-1) - { - cout<<1< pq; - for(auto it=mp.begin();it!=mp.end();it++) - { - pq.push_back(it->second); - } - - sort(pq.begin(), pq.end()); - int ctr=0; - - for(auto it=pq.begin(); it!=pq.end()&&ctr1; it++) - { - int freq=*it; - - if(freq+ctr<=k) - {ctr+=freq; - totaluniq--; - } - else - { - break; - } - } - - cout< -using namespace std; - -int main() { - // your code goes here - int t; - cin>>t; - - while(t--) - { - int i,n,k,totaluniq; - cin>>n>>k; - - //int a[n]; - unordered_map mp; - - for(i=0;i>t; - mp[t]++; - } - - - totaluniq=mp.size(); - - if(k==0) - { - cout<=n-1) - { - cout<<1< pq; - for(auto it=mp.begin();it!=mp.end();it++) - { - pq.push_back(it->second); - } - - sort(pq.begin(), pq.end()); - int ctr=0; - - for(auto it=pq.begin(); it!=pq.end()&&ctr1; it++) - { - int freq=*it; - - if(freq+ctr<=k) - {ctr+=freq; - totaluniq--; - } - else - { - break; - } - } - - cout< -typedef long long ll; -typedef unsigned long long ULL; -const int N=4e5 + 5; -using namespace std; -vectorvv; -void solve(){ - int a,b,sum=0; - cin>>a>>b; - setse; - mapm; - for(int i=0;i>c; - se.insert(c); - m[c]++; - } - vectorv; - for(auto i:se){ - v.push_back(m[i]); - } - sort(v.begin(),v.end()); - for(int i=0;i>t; - while(t--)solve(); - for(auto i:vv)cout< -typedef long long ll; -typedef unsigned long long ULL; -const int N=4e5 + 5; -using namespace std; -void solve(){ - int a,b,sum=0; - cin>>a>>b; - setse; - mapm; - for(int i=0;i>c; - se.insert(c); - m[c]++; - } - vectorv; - for(auto i:se){ - v.push_back(m[i]); - } - sort(v.begin(),v.end()); - for(int i=0;i>t; - while(t--)solve(); -}",1 -sagarkumar43,2057B - Gorilla and the Exam,c++20 ,301927850,301927970,"#include -using namespace std; -int arr[100002]; -void solve(){ - int n,k; - cin>>n>>k; - unordered_mapmp; - int x; - for(int i=0;i>x; - mp[x]++; - } - int size=mp.size(); - priority_queue,greater>pq; - int i=0; - for(auto it:mp){ - arr[i++]=it.second; - } - sort(arr,arr+i); - for(int j=0;j=arr[j]){ - k-=arr[j]; - size--; - } - else break; - } - if(size<=0)size=1; - cout<>t; - while(t--){ - solve(); - } - -} -","#include -using namespace std; -int arr[100002]; -mapmp; -void solve(){ - int n,k; - cin>>n>>k; - mp.clear(); - int x; - for(int i=0;i>x; - mp[x]++; - } - - int i=0; - for(auto it:mp){ - arr[i++]=it.second; - } - int size=i; - sort(arr,arr+i); - for(int j=0;j=arr[j]){ - k-=arr[j]; - size--; - } - else break; - } - if(size<=0)size=1; - cout<>t; - while(t--){ - solve(); - } - -} -",2 -SuvroDevRoy#,2057B - Gorilla and the Exam,c++23 ,301085608,301086176," #include ""bits/stdc++.h"" -using namespace std; - -#define int unsigned long long -#define dub long double -typedef vector vint; -typedef vector vstr; -typedef pair pii; -typedef vector vii; -typedef unordered_map umap; -#define rep(i,j,k) for(int i=j;i> s >> t; - n = s.size(); - m = t.size(); - vector dp(n+1,vint(m+1)); - vector pi(n+1,vint(m+1)); - rep(i,0,n+1) { - rep(j,0,m+1) { - if(i == 0 || j == 0) - dp[i][j] = 0; - else { - if(s[i-1] == t[j-1]) - dp[i][j] = dp[i-1][j-1] + 1; - else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]); - } - } - } -// cout << ""check\n""; - int res = n + m - dp[n][m]; - int ans = 1; - rep(i,0,n+1) { - rep(j,0,m+1) { - if(i == 0 || j == 0) pi[i][j] = min(i,j) + 1; - else if(dp[i][j] > dp[i-1][j-1]) { - pi[i][j] = pi[i-1][j-1]; - } - else - pi[i][j] = pi[i-1][j] + pi[i][j-1]; - } - } - cout << pi[n][m] << endl; - -} -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test_n = 1; - cin>>test_n; - for(int t_c = 1;t_c <= test_n;t_c ++){ - cout << ""Case ""< vint; -typedef vector vstr; -typedef pair pii; -typedef vector vii; -typedef unordered_map umap; -#define rep(i,j,k) for(int i=j;i> n >> k; - vint a(n); - rep(i,0,n) cin >> a[i]; - map mp; - rep(i,0,n) mp[a[i]] ++; - int ans = 0; - vii v; - for(auto i : mp) { - v.push_back({i.second , i.first}); - ans++; - } - sort(all(v)); - for(auto i : v) { - if(i.first <= k) k -= i.first , ans--; - } - cout << max(1LL,ans) << endl; -} -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int test_n = 1; - cin>>test_n; - for(int t_c = 1;t_c <= test_n;t_c ++){ - solve(); - } - return 0; -}",2 -vik2_,2057B - Gorilla and the Exam,c++17 ,302151085,302150884,"#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vector arr(n); - for(int i=0;i>arr[i]; - } - map freq; - for(int num: arr){ - freq[num]++; - } - vector counts; - for(auto &entry: freq){ - counts.push_back(entry.second); - } - sort(counts.begin(),counts.end()); - long long sum=0; - int i=0; - for(int count: counts){ - if(sum+count<=k){ - i++; - sum+=count; - } - else{ - break; - } - } - int ans=counts.size()-i; - if(ans>0){ - cout< -using namespace std; -int main() { - int t; - cin>>t; - while(t--){ - int n, k; - cin >> n >> k; - vector arr(n); - for(int i=0;i>arr[i]; - } - - unordered_map freq; - for(int num : arr){ - freq[num]++; - } - - priority_queue, greater> minHeap; - for(auto &entry : freq){ - minHeap.push(entry.second); - } - - int sum=0,removed=0; - while(!minHeap.empty() && sum + minHeap.top()<=k){ - sum+=minHeap.top(); - minHeap.pop(); - removed++; - } - int ans = minHeap.size(); - cout << (ans > 0 ? ans : 1) << endl; - } - return 0; -} -",1 -MOH_LazyCoder_HSN,2057B - Gorilla and the Exam,c++20 ,301598222,301598312,"/** - - * بسم الله الرحمن الرحيم * - - ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿ - -**/ -#include -#define ll long long -#define fi(l, r) for(ll i=l;i=l;i--) -#define fjr(r, l) for(ll j=r;j>=l;j--) -#define all(x) (x).begin(), (x).end() -#define vi vector -#define vll vector -#define vllll vector -#define vpll vector> -#define vb vector -#define pd push_back -using namespace std; - -void solving(){ - ll n,k; cin>>n>>k; - ll a[n]; - unordered_map mp; - fi(0,n) { - cin >> a[i]; - mp[a[i]]++; - } - vll counts; - for(auto e:mp ){ - counts.push_back(e.second); - } - sort(all(counts)); - ll e1=0; - ll e2=counts.size()-1; - ll res=counts.size(); - while(e1>n; - while(n--) solving(); -}","/** - - * بسم الله الرحمن الرحيم * - - ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿ - -**/ -#include -#define ll long long -#define fi(l, r) for(ll i=l;i=l;i--) -#define fjr(r, l) for(ll j=r;j>=l;j--) -#define all(x) (x).begin(), (x).end() -#define vi vector -#define vll vector -#define vllll vector -#define vpll vector> -#define vb vector -#define pd push_back -using namespace std; - -void solving(){ - ll n,k; cin>>n>>k; - ll a[n]; - map mp; - fi(0,n) { - cin >> a[i]; - mp[a[i]]++; - } - vll counts; - for(auto e:mp ){ - counts.push_back(e.second); - } - sort(all(counts)); - ll e1=0; - ll e2=counts.size()-1; - ll res=counts.size(); - while(e1>n; - while(n--) solving(); -}",2 -utkarshiitbhu1969,2057B - Gorilla and the Exam,c++23 ,307539984,307893345,"#include -using namespace std; -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vector a(n); - set s; - unordered_map m; - vector freq; - for(int i=0;i>a[i]; - m[a[i]]++; - - s.insert(a[i]); - } - for (unordered_map::iterator it = m.begin(); it != m.end(); it++) { - freq.push_back(it->second); - } - sort(freq.begin(),freq.end()); - - int ans=s.size(); - for(int i=0;i=freq[i]){ - k=k-freq[i]; - ans--; - } - else { - break; - } - } - if(ans==0) cout<<""1""< -using namespace std; -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vector a(n); - //set s; - - map m; - vector freq; - for(int i=0;i>a[i]; - m[a[i]]++; - - //s.insert(a[i]); - } - for (map::iterator it = m.begin(); it != m.end(); it++) { - freq.push_back(it->second); - } - sort(freq.begin(),freq.end()); - - int ans=m.size(); - for(int i=0;i=freq[i]){ - k=k-freq[i]; - ans--; - } - else { - break; - } - } - if(ans==0) cout<<""1""< -using namespace std; - -int main(){ - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - int temp = k; - vectorv(n); - mapm; - vectorv2(n); - for(int i=0;i>v[i]; - m[v[i]]++; - } - int max = m[v[0]]; - // int idx = v[0]; - for(auto i:m){ - if(i.second>max){ - max = i.second; - // idx = i.first; - } - // max = i.second; - } - // m[idx] = 0; - // if (temp == 0){ - - // cout<=v2[i]){ - k = k - v2[i]; - v2[i] = 0; - } - } - // k = temp; - int count = 0; - for(int i=0;i -using namespace std; - -int main(){ - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vectorv(n); - mapm; - vectorv2(n); - for(int i=0;i>v[i]; - m[v[i]]++; - } - int max = m[v[0]]; - int idx; - for(auto i:m){ - if(i.second>max){ - max = i.second; - idx = i.first; - } - // max = i.second; - } - m[idx] = 0; - for(auto i:m){ - v2.push_back(i.second); - } - sort(v2.begin(),v2.end()); - - for(int i=0;i0){ - k = k - v2[i]; - v2[i] = 0; - } - } - - int count = 0; - for(int i=0;i -using namespace std; -void solve(){ - int n,k; - cin>>n>>k; - vector nums(n,0); - for(int i=0;i>nums[i]; - } - sort(nums.begin(),nums.end()); - vectorsum={1}; - for(int i=1;i>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -auto compare = [](const pair& a, const pair& b) { - return a.second < b.second; - }; -void solve(){ - int n,k; - cin>>n>>k; - unordered_mapumap; - for(int i=0;i>num; - umap[num]++; - } - vector>pq; - for(auto const&pairs:umap){ - pq.push_back(make_pair(pairs.first,pairs.second)); - } - sort(pq.begin(),pq.end(),compare); - int i=0; - while(k>0&&pq.size()>0){ - auto top = pq[i]; - if(k>=top.second){ - k-=top.second; - pq[i++].second=0; - } - else{ - break; - } - } - int account=0; - for(int j=0;j>t; - while(t--){ - solve(); - } - return 0; -}",1 -omnicoded,2057B - Gorilla and the Exam,c++23 ,301337086,301306355,"#include -using namespace std; - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin>>t; - while(t--){ - int n; - int k; - cin>>n>>k; - vectora(n); - int i=0; - mapmp; - for(i=0;i>a[i]; - mp[a[i]]++; - } - if(n==k) - cout<<""1""<f; - int c=0; - f.reserve(n); - for(auto p:mp){ - f.push_back(p.second); - c++; - } - sort(f.begin(),f.end()); - int s=0; - int co=0; - for(i=0;ik){ - break; - } - } - cout<<(c-co)< -#include -using namespace std; - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin>>t; - while(t--){ - int n; - int k; - cin>>n>>k; - vectora(n); - int i=0; - unordered_mapmp; - for(i=0;i>a[i]; - mp[a[i]]++; - } - int c=0; - for(auto p:mp){ - c++; - } - if(c -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false), cin.tie(nullptr); - long long t; - cin >> t; - - while (t--) - { - long long n, k; - cin >> n >> k; - long long arr[n]; - - - for (long long i = 0; i < n; i++) { - cin >> arr[i]; - } - - - map freq; - for (long long num : arr) { - freq[num]++; - } - - vector>p; - for(auto it : freq) - { - p.push_back({it.second,it.first}); - } - sort(p.begin(),p.end()); - - long long count = p.size(); - for(auto it:p) - { - if(k>=it.first) - { - k-=it.first; - count--; - } - else - { - break; - } - } - if(count<=0) - cout<<1< -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false), cin.tie(nullptr); - long long t; - cin >> t; - - while (t--) - { - long long n, k; - cin >> n >> k; - long long arr[n]; - - - for (long long i = 0; i < n; i++) { - cin >> arr[i]; - } - - - unordered_map freq; - for (long long num : arr) { - freq[num]++; - } - - - priority_queue, vector>, greater>> pq; - for (const auto& entry : freq) { - pq.push({entry.second, entry.first}); - } - - - long long count = 0; - while (k > 0 && !pq.empty()) { - pair top = pq.top(); - pq.pop(); - - long long temp = min(top.first, k); - k -= temp; - - if (temp < top.first) { - pq.push({top.first - temp, top.second}); - break; - } - } - if(pq.empty()) - count = 1; - - while (!pq.empty()) { - pq.pop(); - count++; - } - - cout << count << endl; - } - - return 0; -} -",1 -Z.Karim,2057B - Gorilla and the Exam,c++23 ,301160290,301160959,"#include -#include -#include -#include -#include - -using namespace std; - -template -std::vector> sortMapByValue(const std::map &mp) { - std::vector> vec(mp.begin(), mp.end()); - - std::sort(vec.begin(), vec.end(), [](const auto &a, const auto &b) { - return a.second < b.second; // Sort in ascending order by value - }); - - return vec; -} - -int main() -{ - int t; - cin >> t; - while(t--){ - int n, k; - cin >> n >> k; - vector v; - for(int i = 0; i < n; i++){ - int x; - cin >> x; - v.push_back(x); - } - - - - std::map values; - - for(int i=0; i -#include -#include -#include -#include - -using namespace std; - -template -std::vector> sortMapByValue(const std::map &mp) { - std::vector> vec(mp.begin(), mp.end()); - - std::sort(vec.begin(), vec.end(), [](const auto &a, const auto &b) { - return a.second < b.second; // Sort in ascending order by value - }); - - return vec; -} - -int main() -{ - int t; - cin >> t; - while(t--){ - int n, k; - cin >> n >> k; - vector v; - for(int i = 0; i < n; i++){ - int x; - cin >> x; - v.push_back(x); - } - - - - std::map values; - - for(int i=0; i=v2[i].second){ - k-=v2[i].second; - v2[i].second=0; - - } - - - - } - for(int i=0; i0){ - res++; - } - } - if(res==0){ - res=1; - } - - - cout< -#include -#include -#include -using namespace std; - -int main() { -#ifdef LOCAL - freopen(""b.in"", ""r"", stdin); -#endif - ios::sync_with_stdio(false); - int T; - cin >> T; - while (T--) { - int n, k; - cin >> n >> k; - unordered_map mp; - for (int i = 0; i < n; i++) { - int x; - cin >> x; - mp[x]++; - } - vector a; - for(auto e : mp) { a.push_back(e.second); } - sort(a.begin(), a.end()); - int ans = a.size(); - a.pop_back(); - for (auto e : a) { - if (k >= e) { - k -= e; - ans --; - } else break; - } - cout << ans << endl; - } - return 0; -}","#include -#include -#include -#include -using namespace std; - -int main() { -#ifdef LOCAL - freopen(""b.in"", ""r"", stdin); -#endif - ios::sync_with_stdio(false); - int T; - cin >> T; - while (T--) { - int n, k; - cin >> n >> k; - vector a(n); - for (int i = 0; i < n; i++) { cin >> a[i]; } - sort(a.begin(), a.end()); - vector b; - int cnt = 1; - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { cnt ++; } - else { - b.push_back(cnt); - cnt = 1; - } - } - b.push_back(cnt); - sort(b.begin(), b.end()); - - int ans = b.size(); - b.pop_back(); - for (auto e : b) { - if (k >= e) { - k -= e; - ans --; - } else break; - } - cout << ans << endl; - } - return 0; -}",2 -farhanadib577,2057B - Gorilla and the Exam,c++17 ,301773954,301929344,"#include -using namespace std; - - -int return1(long long int a , long long int b){ - if((a<0 && b<0 )|| (a>0 && b>0)){ - return 1; - } - if(a==0 && b==0){ - return 0; - } - return -1; -} - -int main(){ - - unsigned int testcase; - std::cin>>testcase; - - - while(testcase--){ - int a , b; - std::unordered_maparr; - std::cin>>a>>b; - for(int i=0;i>y; - arr[y]++; - } - - std::vectorarr2; - for(auto n:arr){ - arr2.push_back(n.second); - } - - std::sort(arr2.begin() , arr2.end()); - int counter=1; - int i; - for(i=0;i - -using i64 = long long; - -void solve() { - int n, k; - std::cin >> n >> k; - std::vector a(n); - for (int i = 0; i < n; i++) { - std::cin >> a[i]; - } - std::sort(a.begin(), a.end()); - std::vector cnt = {1}; - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { - cnt.back()++; - } else { - cnt.emplace_back(1); - } - } - std::sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt[i] > k) { - std::cout << m - i << ""\n""; - return; - } - k -= cnt[i]; - } - std::cout << 1 << ""\n""; -} - -signed main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - std::cin >> t; - - while (t--) { - solve(); - } -} -",2 -barFiii,2057B - Gorilla and the Exam,c++17 ,301110433,301111597,"#include -using namespace std; - - -#define md : 1000000007; - - - -void solve(){ - int n,k; - cin >> n >> k; - - vector vec(n); - - unordered_map mp; - vectorcount = {1}; - - for(int i=0; i> vec[i]; - mp[vec[i]]++; - } - - sort(vec.begin(),vec.end()); - for(int i=1; i k) break; - i++; - k-=count[i]; - if(k == 0) break; - } - - int res = count.size()-i != 0 ? count.size()-i : 1; - - cout << res << endl; - // priority_queue, vector>, greater<> > st; - - // for(auto x: mp){ - // st.push({x.second, x.first}); - // } - - // int count = 0; - - // while(!st.empty() && k){ - // int temp = (st.top()).first; - // if(temp > k) k = 0; - // else{ - // k-=temp; - // st.pop(); - // } - // } - - // st.size() > 0 ? cout << st.size() : cout << 1 ; - // cout << endl; - - -} - - - - -int main(){ - - int t; - cin>>t; - - - while(t--) - solve(); - - return 0; -}","#include -using namespace std; - - -#define md : 1000000007; - - - -void solve(){ - int n,k; - cin >> n >> k; - - vector vec(n); - vectorcount = {1}; - - for(int i=0; i> vec[i]; - } - - sort(vec.begin(),vec.end()); - for(int i=1; i k) break; - k-=count[i++]; - } - - cout << m-i << endl; - // priority_queue, vector>, greater<> > st; - - // for(auto x: mp){ - // st.push({x.second, x.first}); - // } - - // int count = 0; - - // while(!st.empty() && k){ - // int temp = (st.top()).first; - // if(temp > k) k = 0; - // else{ - // k-=temp; - // st.pop(); - // } - // } - - // st.size() > 0 ? cout << st.size() : cout << 1 ; - // cout << endl; - - -} - - - - -int main(){ - - int t; - cin>>t; - - - while(t--) - solve(); - - return 0; -}",2 -anand_s_004,2057B - Gorilla and the Exam,c++17 ,301439675,301437155,"#include -using namespace std; -mapmp; -int main() -{ - int t; - cin>>t; - while(t--){ - long long n,m; - cin>>n>>m; - mp.clear(); - for(int i=1;i<=n;i++){ - int a; - cin>>a; - mp[a]++; - } - multisetst; - for(auto b:mp) - st.insert(b.second); - int ans=st.size(); - for(int a:st){ - if(m>=a)ans--,m-=a; - }cout< -#include -#include -using namespace std; - -int main() { - int T; // Number of test cases - cin >> T; - - while (T--) { - int n, m; - cin >> n >> m; - - vector a(n); // Input array - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - - // Sort the array to group identical values together - sort(a.begin(), a.end()); - - // Calculate frequencies of each distinct element - vector freq; - long long count = 1; // Frequency counter - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { - count++; // Increment frequency if the same value continues - } else { - freq.push_back(count); // Store frequency - count = 1; // Reset frequency counter - } - } - freq.push_back(count); // Add the last frequency - - // Sort the frequencies to handle smallest groups first - sort(freq.begin(), freq.end()); - - // Minimize the number of distinct groups - int distinct_groups = freq.size(); // Start with all groups - for (int i = 0; i < freq.size(); i++) { - if (m >= freq[i]) { - m -= freq[i]; // Use changes to eliminate this group - distinct_groups--; // Reduce the count of distinct groups - } else { - break; // No more changes can be made - } - } - - // Output the result for this test case - cout << distinct_groups << endl; - } - - return 0; -} -",1 -Yashwanth_5036,2057B - Gorilla and the Exam,other,300650581,300652027,"#include -#include - -int sort (const void* a, const void* b) { - return (*(int*)a - *(int*)b); -} - -int main() { - int x; - scanf(""%d"", &x); - - while (x--) { - int n, k; - scanf(""%d %d"", &n, &k); - - int* a = (int*)malloc(n * sizeof(int)); - int max = 0; - for (int i=0; i max) { - max = a[i]; - } - } - - int* count = (int*)calloc(max + 1, sizeof(int)); - for (int i=0; i 0) { - c[b++] = count[i]; - } - } - - qsort(c, b, sizeof(int), sort); - - int ans = b; - for (int i=0; i -#include - -int sort (const void* a, const void* b) { - return (*(int*)a - *(int*)b); -} - -int main() { - int x; - scanf(""%d"", &x); - - while (x--) { - int n, k; - scanf(""%d %d"", &n, &k); - - int* a = (int*)malloc(n * sizeof(int)); - int max = 0; - for (int i=0; i -using namespace std; -int main() { - int t ; - cin >> t; - while (t--) - { - int n; - int k; - cin >> n >> k; - int arr[n]; - for ( int i = 0 ; i < n ; i++){ - cin >> arr[i]; - } - sort(arr, arr + n); - int cnt = 1; - vector frequency; - for( int j = 1 ; j < n ; j++){ - if(arr[j]!=arr[j-1]){ - frequency.push_back(cnt); - cnt=1; - } - cnt++; - } - frequency.push_back(cnt); - sort(frequency.begin(), frequency.end()); - int ans = frequency.size(); - for( int i = 0 ; i < frequency.size() ; i++){ - if( k >= frequency[i] ) { - k -= frequency[i]; - ans--; - }else{ - break; - } - } - cout << max(ans, 1) << endl; - } - - return 0; -}","#include -using namespace std; -int main() { - int t ; - cin >> t; - while (t--) - { - int n; - int k; - cin >> n >> k; - int arr[n]; - for ( int i = 0 ; i < n ; i++){ - cin >> arr[i]; - } - sort(arr, arr + n); - int cnt = 1; - vector frequency; - for( int j = 1 ; j < n ; j++){ - if(arr[j]!=arr[j-1]){ - frequency.push_back(cnt); - cnt=0; - } - cnt++; - } - frequency.push_back(cnt); - sort(frequency.begin(), frequency.end()); - int ans = frequency.size(); - for( int i = 0 ; i < frequency.size() ; i++){ - if( k >= frequency[i] ) { - k -= frequency[i]; - ans--; - }else{ - break; - } - } - cout << max(ans, 1) << endl; - } - - return 0; -}",2 -WarsNitin,2057B - Gorilla and the Exam,python,301680514,301679469,"for q in range(int(input())): - n,k=list(map(int,input().split(' '))) - a=list(map(int,input().split(' '))) - b=set(a) - d={} - for i in b: - d[i]=0 - for i in a: - d[i]+=1 - l=[] - for i in d: - l.append(d[i]) - pre=0 - ans=len(l) - l.sort() - for i in range(len(l)): - if(pre+l[i]<=k): - pre+=l[i] - ans-=1 - print(max(ans,1))","for q in range(int(input())): - n,k=list(map(int,input().split(' '))) - a=list(map(int,input().split(' '))) - d={} - for i in range(n): - if(a[i] not in d): - d[a[i]]=1 - else: - d[a[i]]+=1 - l=[] - for i in d: - l.append(d[i]) - pre=0 - ans=len(l) - l.sort() - for i in range(len(l)): - if(pre+l[i]<=k): - pre+=l[i] - ans-=1 - print(max(ans,1)) - - -",1 -alokchoubey18,2057B - Gorilla and the Exam,c++20 ,302265193,302265890,"#include -using namespace std; - -int main(){ - int t; - cin >>t; - while(t--){ - - int n; - int k; - cin >> n >> k; - - int a; - map< int , int > mpp; - for(int i=0;i> a; - mpp[a]++; - - } - - vectorans; - - for(auto it:mpp){ - ans.push_back(it.second); - } - - sort(ans.begin(),ans.end()); - - int s= ans.size(); - int mini=s; - for(int i=0;i -using namespace std; - -int main(){ - int t; - cin >>t; - while(t--){ - - int n; - int k; - cin >> n >> k; - - int a; - map< int , int > mpp; - for(int i=0;i> a; - mpp[a]++; - - } - - vectorans; - - for(auto it:mpp){ - ans.push_back(it.second); - } - - sort(ans.begin(),ans.end()); - - int s= ans.size(); - int mini=s; - for(int i=0;i -using namespace std; -int main() { - int t; - cin >> t; - while(t--) { - int n,k; - cin >> n >> k; - long int a[n]; - map freq; - //set s; - for(int i=0;i> a[i]; - //s.insert(a[i]); - freq[a[i]]++; - } - if(k>=n-1) {cout << ""1\n"";} - else { - vector > f; - for (const auto& elem : freq) { - f.push_back(elem); - } - sort(f.begin(), f.end(), - [](const pair& a, const pair& b) { - return a.second > b.second; - }); - for(int i=0;i -using namespace std; -int main() { - int t; - cin >> t; - while(t--) { - int n,k; - cin >> n >> k; - long int a[n]; - map freq; - set s; - for(int i=0;i> a[i]; - s.insert(a[i]); - freq[a[i]]++; - } - vector > f; - for (const auto& elem : freq) { - f.push_back(elem); - } - sort(f.begin(), f.end(), - [](const pair& a, const pair& b) { - return a.second < b.second; // Compare the second element of each pair - }); - int index=0; - for(int i=0;i -using namespace std; -#define ll long long -#define yes cout<<""YES\n"" -#define no cout<<""NO\n"" - -void solve(){ - - int n,k; - cin>>n>>k; - mapm; - vectorv; - - for (int i=1; i<=n; ++i) { - int x; - cin>>x; - m[x]++; - } - - for(auto it:m) - v.push_back(it.second); - sort(v.begin(),v.end()); - int s=(int)v.size(); - - for (int i=0; i=v[i]){ - k-=v[i]; - s--; - } - else break; - } - s?cout<>t; - while(t--) - solve(); - return 0; -} -","#include -using namespace std; -#define ll long long -#define yes cout<<""YES\n"" -#define no cout<<""NO\n"" - -void solve(){ - - int n,k; - cin>>n>>k; - mapm; - vectorv; - - for (int i=1; i<=n; ++i) { - int x; - cin>>x; - m[x]++; - } - - for(auto it:m) - v.push_back(it.second); - - int s=(int)v.size(); - - for (int i=0; i=v[i]){ - k-=v[i]; - s--; - } - else break; - } - s?cout<>t; - while(t--) - solve(); - return 0; -}",1 -viralbhoi,2057B - Gorilla and the Exam,c++17 ,301620337,301620460,"#include -using namespace std; - -int main() -{ - int t; - cin>>t; - - while(t--){ - int n,k; - cin>>n>>k; - - // vector v(n); - - unordered_map mp; - int x; - for(int i=0;i>x; - mp[x]++; - } - - vector freq; - - for(auto p:mp){ - freq.push_back(p.second); - } - - sort(freq.begin(),freq.end()); - - int ans = 1; - - int i=0; - for(int i=0;i=freq[i]){ - k-=freq[i]; - }else{ - ans++; - } - } - - cout< -using namespace std; - -int main() -{ - int t; - cin>>t; - - while(t--){ - int n,k; - cin>>n>>k; - - // vector v(n); - - map mp; - int x; - for(int i=0;i>x; - mp[x]++; - } - - vector freq; - - for(auto p:mp){ - freq.push_back(p.second); - } - - sort(freq.begin(),freq.end()); - - int ans = 1; - - int i=0; - for(int i=0;i=freq[i]){ - k-=freq[i]; - }else{ - ans++; - } - } - - cout< -using namespace std; - -int main() { - int T; // Number of test cases - cin >> T; - - while (T--) { - long long n, m; - cin >> n >> m; - - vector a(n); // Array to store input numbers - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - - // Sort the array to group identical elements - sort(a.begin(), a.end()); - - vector freq; // Frequency array for unique elements - long long count = 1; // Initialize frequency counter - - // Calculate frequencies - for (int i = 1; i < n; i++) { - if (a[i] != a[i - 1]) { - freq.push_back(count); // Store frequency - count = 1; // Reset counter - } else { - count++; - } - } - freq.push_back(count); // Add the last frequency - - // Sort the frequency array - sort(freq.begin(), freq.end()); - - // Start with all distinct groups - long long distinct_groups = freq.size(); - - // Use available changes to reduce distinct groups - for (auto f : freq) { - if (m >= f) { - m -= f; // Use changes for this group - distinct_groups--; // Reduce group count - } else { - break; // No more changes can be used - } - } - - // Output the result - cout << distinct_groups << '\n'; - } - - return 0; -} -","#include -using namespace std; -mapmp; -int main() -{ - int t; - cin>>t; - while(t--){ - long long n,m; - cin>>n>>m; - mp.clear(); - for(int i=1;i<=n;i++){ - int a; - cin>>a; - mp[a]++; - } - multisetst; - for(auto b:mp) - st.insert(b.second); - int ans=st.size(); - for(int a:st){ - if(m>=a)ans--,m-=a; - }cout< -using namespace std; -using namespace chrono; - - -void solver() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int input; cin >> input; - while(input--) { - int n, k; cin >> n >> k; - map map; - int num; - for(int i = 0; i < n; i++) { - cin >> num; - map[num]++; - } - - vector vec; - for(auto ele: map) vec.push_back(ele.second); - sort(vec.begin(), vec.end()); - - int passes = vec.size(); - - for(int i = 0; k > 0 && i < vec.size() - 1; i++) { - int temp = min(vec[i], k); - vec[i] -= temp; - k -= temp; - if(vec[i] == 0) passes--; - } - - cout << passes << ""\n""; - } -} - - -int main(){ - - solver(); - -} -","#include -using namespace std; -using namespace chrono; - - -void solver() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int input; cin >> input; - while(input--) { - int n, k; cin >> n >> k; - unordered_map map; - int num; - for(int i = 0; i < n; i++) { - cin >> num; - map[num]++; - } - - vector vec; - for(auto ele: map) vec.push_back(ele.second); - sort(vec.begin(), vec.end()); - - for(int i = 0; k > 0 && i < vec.size() - 1; i++) { - int temp = min(vec[i], k); - vec[i] -= temp; - k -= temp; - vec[vec.size() - 1] += temp; - } - - int passes = 0; - for(int i = 0; i < vec.size() - 1; i++) passes += (vec[i] > 0); - cout << passes + 1 << ""\n""; - } -} - - -int main(){ - - solver(); - -} -",1 -miinmaher,2057B - Gorilla and the Exam,c++23 ,301166598,301166754,"#include -using namespace std; -int main() { - int t ; - cin >> t; - while (t--) - { - int n; - int k; - cin >> n >> k; - int arr[n]; - for ( int i = 0 ; i < n ; i++){ - cin >> arr[i]; - } - sort(arr, arr + n); - int cnt = 1; - vector frequency; - for( int j = 1 ; j < n ; j++){ - if(arr[j]!=arr[j-1]){ - frequency.push_back(cnt); - cnt=1; - } - cnt++; - } - sort(frequency.begin(), frequency.end()); - int ans = frequency.size(); - for( int i = 0 ; i*1ULL < frequency.size() ; i++){ - if( k >= frequency[i] ) { - k -= frequency[i]; - ans--; - } - } - cout << ans << endl; - } - - return 0; -}","#include -using namespace std; -int main() { - int t ; - cin >> t; - while (t--) - { - int n; - int k; - cin >> n >> k; - int arr[n]; - for ( int i = 0 ; i < n ; i++){ - cin >> arr[i]; - } - sort(arr, arr + n); - int cnt = 1; - vector frequency; - for( int j = 1 ; j < n ; j++){ - if(arr[j]!=arr[j-1]){ - frequency.push_back(cnt); - cnt=0; - } - cnt++; - } - frequency.push_back(cnt); - sort(frequency.begin(), frequency.end()); - int ans = frequency.size(); - for( int i = 0 ; i < frequency.size() ; i++){ - if( k >= frequency[i] ) { - k -= frequency[i]; - ans--; - }else{ - break; - } - } - cout << max(ans, 1) << endl; - } - - return 0; -}",2 -KAAL_79,2057B - Gorilla and the Exam,c++23 ,307588338,307582759,"#include -#include -using namespace std; -#define ll long long - -// sorting 2D MATRIX..... -// bool cmp(vector &a, vector &b) -// { -// ll ans1=accumulate(a.begin(),a.end(),0ll); -// ll ans2=accumulate(b.begin(),b.end(),0ll); -// if(ans1==ans2) -// { -// for (int i = 0; i < a.size(); ++i) -// { -// if(a[i]!=b[i]) -// { -// return a[i]>b[i]; -// } -// } -// } -// return ans1>ans2; -// } - -// void solve() { -// int t; -// cin >> t; -// while (t--) { -// string s; -// cin >> s; -// int n = s.length(); - -// // Option 1: ""((((...))))"" -// string t1 = string(n, '(') + string(n, ')'); - -// // Option 2: ""()()()()"" -// string t2 = """"; -// for (int i = 0; i < n; i++) t2 += ""()""; - -// // If s is not found as a substring, print it -// if (t1.find(s) == string::npos) { -// cout << ""YES\n"" << t1 << ""\n""; -// } else if (t2.find(s) == string::npos) { -// cout << ""YES\n"" << t2 << ""\n""; -// } else { -// cout << ""NO\n""; -// } -// } -// } - -void solve() -{ - int t; cin>>t; - while(t--) - { - int n,k; cin>>n>>k; - vectorv(n); - map m; - for (int i = 0; i < n; ++i) - { - cin>>v[i]; - m[v[i]]++; - } - vectorfreq; - for(auto it: m) - { - freq.push_back(it.second); - } - sort(freq.begin(),freq.end()); - ll idx=0; - for (int i = 0; i < freq.size(); ++i) - { - if(freq[i]<=k) - { - k-=freq[i]; - idx=i+1; - } - else break; - } - ll ans=(freq.size()-idx); - cout< -#include -using namespace std; -#define ll long long - -// sorting 2D MATRIX..... -// bool cmp(vector &a, vector &b) -// { -// ll ans1=accumulate(a.begin(),a.end(),0ll); -// ll ans2=accumulate(b.begin(),b.end(),0ll); -// if(ans1==ans2) -// { -// for (int i = 0; i < a.size(); ++i) -// { -// if(a[i]!=b[i]) -// { -// return a[i]>b[i]; -// } -// } -// } -// return ans1>ans2; -// } - -// void solve() { -// int t; -// cin >> t; -// while (t--) { -// string s; -// cin >> s; -// int n = s.length(); - -// // Option 1: ""((((...))))"" -// string t1 = string(n, '(') + string(n, ')'); - -// // Option 2: ""()()()()"" -// string t2 = """"; -// for (int i = 0; i < n; i++) t2 += ""()""; - -// // If s is not found as a substring, print it -// if (t1.find(s) == string::npos) { -// cout << ""YES\n"" << t1 << ""\n""; -// } else if (t2.find(s) == string::npos) { -// cout << ""YES\n"" << t2 << ""\n""; -// } else { -// cout << ""NO\n""; -// } -// } -// } - -void solve() -{ - int t; cin>>t; - while(t--) - { - int n,k; cin>>n>>k; - vectorv(n); - map m; - for (int i = 0; i < n; ++i) - { - cin>>v[i]; - m[v[i]]++; - } - ll cheak=INT_MIN; - for(auto it: m) - { - cheak=max(cheak,(it).second); - } - if(n==1) cout<<1< -using namespace std; - -int main(void) -{ - int T; - cin >> T; - while(T--) - { - int n,k; - cin >> n >> k; - vector a(n); - for(int i=0;i> a[i]; - } - sort(a.begin(),a.end()); - vector cnt={1}; - for(int i=1;i -using namespace std; - -int main(void) -{ - int T; - cin >> T; - while(T--) - { - int n,k; - cin >> n >> k; - vector a(n); - for(int i=0;i> a[i]; - } - sort(a.begin(),a.end()); - vector cnt={1}; - for(int i=1;i=0) cout << 1 << endl; - } -}",2 -krishna_Gopal,2057B - Gorilla and the Exam,c++17 ,300635124,300762826,"#include -#include -using namespace std; -int main() { - int t; // number of test cases - cin >> t; - while (t--) { - int n, k; - cin>>n>>k; - vector a(n); - map n2r; - for(int i = 0; i>a[i]; - n2r[a[i]] += 1; - } - vector f; - for(auto pr : n2r){ - f.push_back(pr.second); - } - sort(f.begin(), f.end(), greater()); - int ans = 0; - if(k == 0){ - cout< -#include -using namespace std; -int main() { - int t; // number of test cases - cin >> t; - while (t--) { - int n, k; - cin>>n>>k; - vector a(n); - - for(int i = 0; i>a[i]; - } - sort(a.begin(), a.end()); - vector fq; - fq.push_back(1); - for(int i = 1; i k){ - cout< -using namespace std; -typedef long long LL; -const int mod=1e9+7; -void solve(){ - int n,k;cin>>n>>k; - vectora(n); - vectorcnt={1}; - for(int i=0;i>a[i]; - } - sort(a.begin(),a.end()); - for(int i=1;ik){ - cout<>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -typedef long long LL; -const int mod=1e9+7; -void solve(){ - int n,k;cin>>n>>k; - vectora(n); - vectorcnt(n); - for(int i=0;i>a[i]; - } - if(k>=n)cout<<1<<'\n'; - else{ - sort(a.begin(),a.end()); - int j=0; - for(int i=0;i=cnt[i]){ - k-=cnt[i]; - ans--; - } - } - cout<>t; - while(t--){ - solve(); - } - return 0; -}",1 -Raltoos,2057B - Gorilla and the Exam,c++20 ,304839396,304842412,"#include -#define int long long -using namespace std; - -void solve() -{ - int n, k; - cin >> n >> k; - - unordered_map mp; - for(int i = 0; i < n; i++) { - int el; - cin >> el; - - mp[el]++; - } - - if(k == n || k == n-1){ - cout << 1 << '\n'; - return ; - } - - vector a; - for(auto [i, cnt] : mp){ - a.push_back(cnt); - } - - sort(a.begin(), a.end()); - - int cnt = 0; - for(int i = 0; i < a.size(); i++){ - - if(k <= 0) { - cnt++; - continue; - } - - if(a[i] >= k){ - a[i] -= k; - k = 0; - }else{ - k -= a[i]; - a[i] = 0; - } - - if(a[i] != 0) { - cnt++; - } - } - - cout << cnt << '\n'; -} - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t = 1; - cin >> t; - - while (t--) - { - solve(); - } - - return 0; -}","#include -#define int long long -using namespace std; - -void solve() -{ - int n, k; - cin >> n >> k; - - vector a(n, 0); - for(int i = 0; i < n; i++) { - cin >> a[i]; - } - - if(k == n || k == n-1){ - cout << 1 << '\n'; - return ; - } - - sort(a.begin(), a.end()); - vector b = {1}; - for(int i = 1; i < n; i++){ - if(a[i] == a[i-1]){ - b.back()++; - }else b.push_back(1); - } - - sort(b.begin(), b.end()); - - int cnt = 0; - for(int i = 0; i < b.size(); i++){ - - if(k <= 0) { - cnt++; - continue; - } - - if(b[i] >= k){ - b[i] -= k; - k = 0; - }else{ - k -= b[i]; - b[i] = 0; - } - - if(b[i] != 0) { - cnt++; - } - } - - cout << cnt << '\n'; -} - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t = 1; - cin >> t; - - while (t--) - { - solve(); - } - - return 0; -}",2 -geipepe,2057B - Gorilla and the Exam,c++20 ,300624121,300624951,"#include - -using namespace std; -using ll = long long; - -int main() -{ - int t; - cin >> t; - - while(t --) - { - int n,m; - - unordered_map cnt; - vector> s; - - cin >> n >> m; - int idx = 0; - - for(int i = 0;i> a; - if(cnt[a] == 0) - { - cnt[a] = idx+1; - s.push_back({0,a}); - idx ++; - } - s[cnt[a] - 1].first ++; - } - - sort(s.begin(),s.begin()+idx); - - - int idx2 = 0; - - int ans = 0; - while(idx2 < idx && m > 0) - { - if(m >= s[idx2].first) - { - m -= s[idx2].first; - s[idx2 ++].first = 0; - } - } - - for(int i = 0;i - -using namespace std; -using ll = long long; - -int main() -{ - int t; - cin >> t; - - while(t --) - { - int n,m; - - map cnt; - vector> s; - - cin >> n >> m; - int idx = 0; - - for(int i = 0;i> a; - if(cnt[a] == 0) - { - cnt[a] = idx+1; - s.push_back({0,a}); - idx ++; - } - s[cnt[a] - 1].first ++; - } - - sort(s.begin(),s.end()); - int idx2 = 0; - - int ans = 0; - while(idx2 < idx && m > 0) - { - if(m >= s[idx2].first) - { - m -= s[idx2].first; - s[idx2].first = 0; - } - idx2 ++; - } - - for(int i = 0;i -using namespace std; -typedef long long ll; -typedef pair PII; -const int N=1e5+10; -int n,k; -void solve(){ - scanf(""%d%d"",&n,&k); - map mp; - int mx=0; - for(int i=1;i<=n;i++){ - int x; - scanf(""%d"",&x); - mp[x]++; - } - vector v; - for(auto &a:mp) v.push_back(a.second); - sort(v.begin(),v.end()); - for(int i=0;i -using namespace std; -typedef long long ll; -typedef pair PII; -const int N=1e5+10; -int n,k; -void solve(){ - scanf(""%d%d"",&n,&k); - map mp; - int mx=0; - for(int i=1;i<=n;i++){ - int x; - scanf(""%d"",&x); - mp[x]++; - } - vector v; - for(auto &a:mp) v.push_back(a.second); - sort(v.begin(),v.end()); - int m=v.size(); - for(int i=0;i> expert - - -/* - - - $$$$$$$$ $$$ $$ $$ $$$ $$ $$ $$$$$$$$ - $$ $$ $$ $$ $$ $$ $$ $$$$ $$ $$ - $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ - $$ $$ $$$$$$$ $$ $$$$$$$ $$ $$ $$ $$ - $$ $$ $$ $$ $$ $$ $$ $$ $$$$ $$ - $$$$$$ $$ $$ $$ $$ $$ $$ $$ $$ - - -*/ - - -#include -using namespace std; - -#define endl ""\n"" -#define spc "" "" -#define no cout << ""NO"" << endl; -#define yes cout << ""Yes"" << endl; -#define retno cout << ""No"" << endl; return; -#define retyes cout << ""Yes"" << endl; return; -#define ll long long -#define int long long -#define lli long long int -#define vi vector -#define vvi vector> -#define vl vector -#define vll vector -#define vs vector -#define pb push_back -#define pii pair -#define vpii vector> -// #define mp make_pair -#define mii map -#define umii unordered_map -#define maxHeap priority_queue -#define minHeap priority_queue, greater> -#define setbits(x) __builtin_popcountll(x) -#define zrobits(x) __builtin_ctzll(x) -#define inf 1e18 -#define all(x) x.begin(), x.end() -#define ps(x, y) fixed << setprecision(y) << x -#define mk(arr, n, type) type *arr = new type[n]; -#define w(x) \ - int x; \ - cin >> x; \ - while (x--) -#define debug(x) cout << #x << "" : "" << x << endl; -#define fast_io \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define fr(a,b) for(auto i=a;i(q)?(p):(q)) -#define min(p,q)((p)<(q)?(p):(q)) -#define INF (( 1LL << 62 )-( 1LL << 31 )) /*Without overflow a large number*/ -#define MOD 1000000007 -#define SUM(x) accumulate(x.begin(), x.end(), 0LL) -#define debugMp(mp) for(auto i : mp) {cout << i.first << "" -> ""; for(auto val : i.second) cout << val << "" ""; cout << endl;} -// Traverse 2D matrix -#define debugM(arr) \ - fr(0, arr.size()) { \ - frj(0, arr[0].size()) \ - cout << arr[i][j] << "" ""; \ - cout << endl; \ - } - - - -// ================================== take ip/op like vector,pairs directly!================================== -template istream &operator>>(istream &cin,pair &a) { return cin>>a.first>>a.second; } -template istream &operator>>(istream &cin,vector &a) { for (auto &x:a) cin>>x; return cin; } -template ostream &operator<<(ostream &cout,const pair &a) { return cout< ostream &operator<<(ostream &cout,const vector> &a) { for (auto &x:a) cout< ostream &operator<<(ostream &cout,const vector &a) { int n=a.size(); if (!n) return cout; cout< diff = end_time-start_time; - cerr<<""Time Taken : ""< -// #include -// using namespace __gnu_pbds; - -// // #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -// // eg: ordered_set st; - -// // oset s: s.find_by_order(k): Kth element in 's', s.order_of_key(k): number of items strictly less than k -// template using oset =tree, rb_tree_tag,tree_order_statistics_node_update>; -// // eg: oset st; -// // --------------------------------------------------------------END of ordered_set headers - -// --------------------------------------------- SIEVE -pair sieve(int n) -{ - vector vis(n+1, true); - for (int p = 2; p * p <= n; p++) { - if (vis[p] == true) { - for (int i = p * p; i <= n; i += p) - vis[i] = false; - } - } - vector prime; - for (int p = 2; p <= n; p++) - if (vis[p]) - prime.push_back(p); - return {vis, prime}; -} - -// ----------------------------------------GCD -int gcd(int a, int b) { - if (b == 0) return a; - else return gcd(b, a % b); -} - -int lcm(int a, int b) { - return a*b / gcd(a, b); -} - -// ------------------------------- custom hash -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); - } -}; - -// ------------------------------------------------------------------------------------------------------------------------------ - -// // to lower -// cout << char('A' | (1<<5)) << endl; -// cout << char('D' | ' ') << endl; - -// // to upper -// cout << char('b' & '_') << endl; -// cout << char('a' & (~(1<<5))) << endl; - -/* -// The Diplomat, the fall of the house of usher, daily dose of sunshine, blue eye samurai - - SPIDER-MAN: ACROSS THE SPIDER-VERSE - -- - Mindhunter, jamtara, ocean 11, 12, 13, - Movies - The pale blue eye, seven - series - 1899, kaleidoscope - andhadhun - Murder in mahim - castle - Mentalist - True detecative s1 - dark - Narcos - Lupin, Suzha - The vortex, Parking, Spycraft, Manifest (flight 828) - Under the bridge - sherlock, eric, hannibal - The gentlemen, - puss in boots -*/ -// Mr. Robot, The Matrix, Source Code, Blackhat, Silicon Valley, The Internship - -int getHash(string &s) { - int p = 31, m = 1e9+7; - int power = 1, hash = 0; - for(int i = 0; i < len(s); i++) { - hash = (hash + ((s[i]-'a'+1) * power)) % m; - power = (power * p) % m; - } - - return hash; -} - -// arcjet -> rate limiting -void jayant() { - int i, j, k, n, m, sum = 0; - - string s; - // copy(arr.begin(), arr.end(), std::ostream_iterator(std::cout, "" "")); - // cout << ((double)clock() / CLOCKS_PER_SEC) << endl; - - cin >> n >> k; - vi arr(n); - cin >> arr; - - unordered_map mp; - for(auto i : arr) mp[i]++; - - vpii temp; - for(auto i : mp) { - temp.pb({i.second, i.first}); - } - sortV(temp); - - i = 0; - while(i < len(temp)-1) { - if(k >= temp[i].first) k -= temp[i++].first; - else break; - } - - cout << len(temp)-i << endl; - -} - -// ---------------------------------------------- MAIN AREA ----------------------------------------------------------------- - -int32_t main() -{ - cin.tie(NULL); - cout.tie(NULL); - ios_base::sync_with_stdio(false); - - // if reads input from file - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - - int t = 1; - - cin >> t; - - while(t--) { - jayant(); - } - getExecutionTime(); - return 0; -} - -// sudo docker exec -it redis-stack-server redis-cli","// inevitable -->> expert - - -/* - - - $$$$$$$$ $$$ $$ $$ $$$ $$ $$ $$$$$$$$ - $$ $$ $$ $$ $$ $$ $$ $$$$ $$ $$ - $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ - $$ $$ $$$$$$$ $$ $$$$$$$ $$ $$ $$ $$ - $$ $$ $$ $$ $$ $$ $$ $$ $$$$ $$ - $$$$$$ $$ $$ $$ $$ $$ $$ $$ $$ - - -*/ - - -#include -using namespace std; - -#define endl ""\n"" -#define spc "" "" -#define no cout << ""NO"" << endl; -#define yes cout << ""Yes"" << endl; -#define retno cout << ""No"" << endl; return; -#define retyes cout << ""Yes"" << endl; return; -#define ll long long -#define int long long -#define lli long long int -#define vi vector -#define vvi vector> -#define vl vector -#define vll vector -#define vs vector -#define pb push_back -#define pii pair -#define vpii vector> -// #define mp make_pair -#define mii map -#define umii unordered_map -#define maxHeap priority_queue -#define minHeap priority_queue, greater> -#define setbits(x) __builtin_popcountll(x) -#define zrobits(x) __builtin_ctzll(x) -#define inf 1e18 -#define all(x) x.begin(), x.end() -#define ps(x, y) fixed << setprecision(y) << x -#define mk(arr, n, type) type *arr = new type[n]; -#define w(x) \ - int x; \ - cin >> x; \ - while (x--) -#define debug(x) cout << #x << "" : "" << x << endl; -#define fast_io \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define fr(a,b) for(auto i=a;i(q)?(p):(q)) -#define min(p,q)((p)<(q)?(p):(q)) -#define INF (( 1LL << 62 )-( 1LL << 31 )) /*Without overflow a large number*/ -#define MOD 1000000007 -#define SUM(x) accumulate(x.begin(), x.end(), 0LL) -#define debugMp(mp) for(auto i : mp) {cout << i.first << "" -> ""; for(auto val : i.second) cout << val << "" ""; cout << endl;} -// Traverse 2D matrix -#define debugM(arr) \ - fr(0, arr.size()) { \ - frj(0, arr[0].size()) \ - cout << arr[i][j] << "" ""; \ - cout << endl; \ - } - - - -// ================================== take ip/op like vector,pairs directly!================================== -template istream &operator>>(istream &cin,pair &a) { return cin>>a.first>>a.second; } -template istream &operator>>(istream &cin,vector &a) { for (auto &x:a) cin>>x; return cin; } -template ostream &operator<<(ostream &cout,const pair &a) { return cout< ostream &operator<<(ostream &cout,const vector> &a) { for (auto &x:a) cout< ostream &operator<<(ostream &cout,const vector &a) { int n=a.size(); if (!n) return cout; cout< diff = end_time-start_time; - cerr<<""Time Taken : ""< -// #include -// using namespace __gnu_pbds; - -// // #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -// // eg: ordered_set st; - -// // oset s: s.find_by_order(k): Kth element in 's', s.order_of_key(k): number of items strictly less than k -// template using oset =tree, rb_tree_tag,tree_order_statistics_node_update>; -// // eg: oset st; -// // --------------------------------------------------------------END of ordered_set headers - -// --------------------------------------------- SIEVE -pair sieve(int n) -{ - vector vis(n+1, true); - for (int p = 2; p * p <= n; p++) { - if (vis[p] == true) { - for (int i = p * p; i <= n; i += p) - vis[i] = false; - } - } - vector prime; - for (int p = 2; p <= n; p++) - if (vis[p]) - prime.push_back(p); - return {vis, prime}; -} - -// ----------------------------------------GCD -int gcd(int a, int b) { - if (b == 0) return a; - else return gcd(b, a % b); -} - -int lcm(int a, int b) { - return a*b / gcd(a, b); -} - -// ------------------------------- custom hash -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); - } -}; - -// ------------------------------------------------------------------------------------------------------------------------------ - -// // to lower -// cout << char('A' | (1<<5)) << endl; -// cout << char('D' | ' ') << endl; - -// // to upper -// cout << char('b' & '_') << endl; -// cout << char('a' & (~(1<<5))) << endl; - -/* -// The Diplomat, the fall of the house of usher, daily dose of sunshine, blue eye samurai - - SPIDER-MAN: ACROSS THE SPIDER-VERSE - -- - Mindhunter, jamtara, ocean 11, 12, 13, - Movies - The pale blue eye, seven - series - 1899, kaleidoscope - andhadhun - Murder in mahim - castle - Mentalist - True detecative s1 - dark - Narcos - Lupin, Suzha - The vortex, Parking, Spycraft, Manifest (flight 828) - Under the bridge - sherlock, eric, hannibal - The gentlemen, - puss in boots -*/ -// Mr. Robot, The Matrix, Source Code, Blackhat, Silicon Valley, The Internship - -int getHash(string &s) { - int p = 31, m = 1e9+7; - int power = 1, hash = 0; - for(int i = 0; i < len(s); i++) { - hash = (hash + ((s[i]-'a'+1) * power)) % m; - power = (power * p) % m; - } - - return hash; -} - -// arcjet -> rate limiting -void jayant() { - int i, j, k, n, m, sum = 0; - - string s; - // copy(arr.begin(), arr.end(), std::ostream_iterator(std::cout, "" "")); - // cout << ((double)clock() / CLOCKS_PER_SEC) << endl; - - cin >> n >> k; - vi arr(n); - cin >> arr; - - map mp; - for(auto i : arr) mp[i]++; - - vpii temp; - for(auto i : mp) { - temp.pb({i.second, i.first}); - } - sortV(temp); - - i = 0; - while(i < len(temp)-1) { - if(k >= temp[i].first) k -= temp[i++].first; - else break; - } - - cout << len(temp)-i << endl; - -} - -// ---------------------------------------------- MAIN AREA ----------------------------------------------------------------- - -int32_t main() -{ - cin.tie(NULL); - cout.tie(NULL); - ios_base::sync_with_stdio(false); - - // if reads input from file - // freopen(""input.txt"",""r"",stdin); - // freopen(""output.txt"",""w"",stdout); - - int t = 1; - - cin >> t; - - while(t--) { - jayant(); - } - getExecutionTime(); - return 0; -} - -// sudo docker exec -it redis-stack-server redis-cli",2 -Srichakra_D,2057B - Gorilla and the Exam,python,302113180,302111720,"import sys -from collections import Counter - -input = sys.stdin.readline -output = sys.stdout.write -str_input = lambda: input().strip() -int_input = lambda: int(input()) -multi_int_input = lambda: map(int, input().split()) -list_input = lambda: list(map(int, input().split())) -P1 = lambda X: result_array.append(f""{X}\n"") -P2 = lambda X,Y: result_array.append(f""{X} {Y}\n"") -P3 = lambda X,Y,Z: result_array.append(f""{X} {Y} {Z}\n"") -PA = lambda X: result_array.append(f""{' '.join(map(str,X))}\n"") - - -def solve(test_case): - N,K = multi_int_input() - arr = list_input() - - check = Counter() - for i in arr: - check[str(i)] += 1 - check = sorted(check.values(),reverse=True) - - while check: - if check[-1] <= K: - K -= check.pop() - else: - break - - P1(max(1,len(check))) - - -tc = 1 -tc = int_input() -result_array = [] -for test_case in range(1,tc+1): - solve(test_case) -output(''.join(result_array))","import sys -from collections import Counter - -input = sys.stdin.readline -output = sys.stdout.write -str_input = lambda: input().strip() -int_input = lambda: int(input()) -multi_int_input = lambda: map(int, input().split()) -list_input = lambda: list(map(int, input().split())) -P1 = lambda X: result_array.append(f""{X}\n"") -P2 = lambda X,Y: result_array.append(f""{X} {Y}\n"") -P3 = lambda X,Y,Z: result_array.append(f""{X} {Y} {Z}\n"") -PA = lambda X: result_array.append(f""{' '.join(map(str,X))}\n"") - - -def solve(test_case): - N,K = multi_int_input() - arr = list_input() - - check = sorted(Counter(arr).values(),reverse=True) - - while check: - if check[-1] <= K: - K -= check.pop() - else: - break - - P1(max(1,len(check))) - - -tc = 1 -tc = int_input() -result_array = [] -for test_case in range(1,tc+1): - solve(test_case) -output(''.join(result_array))",1 -Calcifer077,2057B - Gorilla and the Exam,java,302107880,302107011,"// Gorilla and the exam - -import java.util.*; - -public class _2057B { - public static void sovle(int k, int arr[]) { - Arrays.sort(arr); - List cnt = new ArrayList<>(); - cnt.add(1); - for (int i = 1; i < arr.length; i++) { - if (arr[i] == arr[i - 1]) { - cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1); - } else { - cnt.add(1); - } - } - - Collections.sort(cnt); - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt.get(i) > k) { - System.out.println(m - i); - return; - } - k -= cnt.get(i); - } - System.out.println(1); - } - - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int t = sc.nextInt(); - while (t > 0) { - int n = sc.nextInt(); - int k = sc.nextInt(); - - int arr[] = new int[n]; - - for (int i = 0; i < n; i++) { - arr[i] = sc.nextInt(); - } - - sovle(k, arr); - - t--; - } - sc.close(); - } -}","// Gorilla and the exam - -import java.util.*; - -public class _2057B { - public static void sovle(int k, int arr[]) { - Arrays.sort(arr); - List cnt = new ArrayList<>(); - cnt.add(1); - for (int i = 1; i < arr.length; i++) { - if (arr[i] == arr[i - 1]) { - cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1); - } else { - cnt.add(1); - } - } - - Collections.sort(cnt); - for (int i = 0; i < cnt.size(); i++) { - System.out.println(cnt.get(i)); - } - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt.get(i) > k) { - System.out.println(m - i); - return; - } - k -= cnt.get(i); - } - System.out.println(1); - } - - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int t = sc.nextInt(); - while (t > 0) { - int n = sc.nextInt(); - int k = sc.nextInt(); - - int arr[] = new int[n]; - - for (int i = 0; i < n; i++) { - arr[i] = sc.nextInt(); - } - - sovle(k, arr); - - t--; - } - sc.close(); - } -}",1 -bahab,2057B - Gorilla and the Exam,c++20 ,306617792,306615966,"// -// Created by bahab on 7/24/2024. -// -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#ifndef ONLINE_JUDGE -#endif - -const long long mod=1e9+7; -const long long MOD=998244353; -#define ll long long -#define endl '\n' -#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) -#define F first -#define S second -#define INF 1e18+5 -#define yes cout<<""YES""<0){if(b&1)res=(res*a);a=((a)*(a));b/=2;}return res;} -ll gcd(ll a,ll b){return b==0 ? a:gcd(b,a%b);} -ll lcm(ll a,ll b){return (a/gcd(a,b))*b;} -ll comb(ll n, ll k) { - if (k > n) return 0; - if (k == 0 || k == n) return 1; - if (k == 1) return n; - ll result = 1; - for (ll i = 1; i <= k; ++i) { result *= (n - i + 1) / i; } - return result; -} -// ----------------------------------------------------------------------- - -void solve(){ - int n, k; cin >> n >> k; - vector arr(n); - for (int i = 0 ; i < n ; i ++) - cin >> arr[i]; - sort(all(arr)); - vector mp = {1}; - for (int i = 1 ; i < n ; i ++){ - if (arr[i] == arr[i - 1]) - mp.back()++; - else mp.pb(1); - } - sort(all(mp)); -// show(mp); cout << endl; - int sz = mp.size(), ind = 0; - for (int i = 0 ; i < sz ; i ++){ - if (mp[i] > k){ - break; - } - else { - ind++; - k -= mp[i]; - } - } - cout << max(sz - ind, 1) << endl; -} -// ----------------------------------------------------------------------- - -int main (){ - FAST; - int tc = 1; - cin >> tc; - while (tc --) - solve(); -}","// -// Created by bahab on 7/24/2024. -// -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -#ifndef ONLINE_JUDGE -#endif - -const long long mod=1e9+7; -const long long MOD=998244353; -#define ll long long -#define endl '\n' -#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) -#define F first -#define S second -#define INF 1e18+5 -#define yes cout<<""YES""<0){if(b&1)res=(res*a);a=((a)*(a));b/=2;}return res;} -ll gcd(ll a,ll b){return b==0 ? a:gcd(b,a%b);} -ll lcm(ll a,ll b){return (a/gcd(a,b))*b;} -ll comb(ll n, ll k) { - if (k > n) return 0; - if (k == 0 || k == n) return 1; - if (k == 1) return n; - ll result = 1; - for (ll i = 1; i <= k; ++i) { result *= (n - i + 1) / i; } - return result; -} -// ----------------------------------------------------------------------- - -void solve(){ - int n, k; cin >> n >> k; - vector arr(n); - vector> p; - unordered_map mp; - for (int i = 0; i < n ; i++){ - cin >> arr[i]; - mp[arr[i]]++; - } - int sz = mp.size(); - vector pref(sz + 1); - for (auto it : mp){ - p.emplace_back(it.second, it.first); - } - sort(all(p)); -// for (auto iter : p) cout << iter.F << "" , "" << iter.S << "" || ""; -// cout << endl; - for (int i = 1 ; i <= mp.size(); i ++){ - pref[i] = pref[i - 1] + p[i - 1].first; - } -// show(pref); -// cout << endl; - int ind = lower_bound(all(pref), k) - pref.begin(); - if (pref[ind] > k){ - ind--; - } - cout << max(sz - ind, 1) << endl; -} -// ----------------------------------------------------------------------- - -int main (){ - FAST; - int tc = 1; - cin >> tc; - while (tc --) - solve(); -}",1 -rickeypandya,2057B - Gorilla and the Exam,c++23 ,301086448,301086640,"#include -#include -#include -#include -using namespace std; -int main(){ - int t ; cin>>t; - while(t--){ - int n , k ; cin>>n>>k ; - vector a ; - map m ; - for(int i = 0 ; i< n ; i++) { - int x ; cin>>x ; - a.push_back(x); - m[x]++ ; - } - vector x ; - for(auto i : m){ - x.push_back(i.second); - } - sort(x.begin() , x.end()); - int ans = x.size(); - for(auto i : x){ - if(k >= i){ - ans--; - k-=i; - } - } - cout< -#include -#include -#include -using namespace std; -int main(){ - int t ; cin>>t; - while(t--){ - int n , k ; cin>>n>>k ; - vector a ; - map m ; - for(int i = 0 ; i< n ; i++) { - int x ; cin>>x ; - a.push_back(x); - m[x]++ ; - } - vector x ; - for(auto i : m){ - x.push_back(i.second); - } - sort(x.begin() , x.end()); - int ans = x.size(); - for(auto i : x){ - if(k >= i){ - ans--; - k-=i; - } - } - cout< -using namespace std; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n, k; - cin >> n >> k; - int a[n]; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - sort(a, a + n); - int y = a[0]; - int countt = 1; - int b[n] = {0}; - for (int i = 1; i < n; i++) - { - if(y == a[i]) - { - countt++; - } - else - { - b[countt - 1]++; - y = a[i]; - countt = 1; - } - } - b[countt - 1]++; - int ans = 0; - for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++) - { - ans += b[i]; - } - // cout << ans << endl; - for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++) - { - if(k == 0) - { - break; - } - if(k < b[i]*(i+1)) - { - ans -= k/(i+1); - k = 0; - } - else - { - k -= b[i]*(i+1); - ans -= b[i]; - } - } - if(ans == 0) - { - ans = 1; - } - cout << ans << endl; - } - return 0; -}","#include -using namespace std; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n, k; - cin >> n >> k; - int a[n]; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - sort(a, a + n); - int y = a[0]; - int countt = 1; - int b[n] = {0}; - for (int i = 1; i < n; i++) - { - if(y == a[i]) - { - countt++; - } - else - { - b[countt - 1]++; - y = a[i]; - countt = 1; - } - } - b[countt - 1]++; - int ans = 0; - for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++) - { - ans += b[i]; - } - // cout << ans << endl; - for (int i = 0; i < int(sizeof(b) / sizeof(int)); i++) - { - if(k == 0) - { - break; - } - if(k < b[i]) - { - ans -= k; - } - else - { - k -= b[i]*(i+1); - ans -= b[i]; - } - } - if(ans == 0) - { - ans = 1; - } - cout << ans << endl; - } - return 0; -}",1 -sarwadnyacode,2057B - Gorilla and the Exam,java,304945545,304945444," - - - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; - -public class TestFile { - public static void main(String[]args) { - Scanner scanner = new Scanner(System.in); - int t = scanner.nextInt(); - while( t-- > 0) { - int n = scanner.nextInt(); - int k = scanner.nextInt(); - int[] arr = new int[n]; - HashMap map = new HashMap(); - for(int i=0;i list = new ArrayList(); - for(Map.Entry elEntry : map.entrySet()) { - list.add(elEntry.getValue()); - } - list.sort(null); - //System.out.println(list); - int count = 1; - for(int i=0;i= list.get(i)) { - k -= list.get(i); - list.set(i, 0); - } else { - count = list.size() - i; - break; - } - } - System.out.println(count); - } - scanner.close(); - } - -} -"," - - - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; - -public class TestFile { - public static void main(String[]args) { - Scanner scanner = new Scanner(System.in); - int t = scanner.nextInt(); - while( t-- > 0) { - int n = scanner.nextInt(); - int k = scanner.nextInt(); - int[] arr = new int[n]; - HashMap map = new HashMap(); - for(int i=0;i list = new ArrayList(); - for(Map.Entry elEntry : map.entrySet()) { - list.add(elEntry.getValue()); - } - list.sort(null); - System.out.println(list); - int count = 1; - for(int i=0;i= list.get(i)) { - k -= list.get(i); - list.set(i, 0); - } else { - count = list.size() - i; - break; - } - } - System.out.println(count); - } - scanner.close(); - } - -} -",1 -vatsanant,2057B - Gorilla and the Exam,c++23 ,301614948,301615961,"/* - * Gorrila and the Exam - * 18.01.24 - */ -#include -#include -#include -#include - -using namespace std; - -// calc total subarrays with same element -> calc subarrays whose sum of lenth is equal to p -> subtract -int solve(int n, int k, vector& a){ - - - unordered_map mp; - for(int i = 0; i < a.size(); i++){ - mp[a[i]]++; - } - vector fq; - for(auto& a: mp){ - fq.push_back(a.second); - } - - sort(fq.begin(), fq.end()); - int m = fq.size(); - int ans = 0; - for(int i = 0; i < m-1; i++){ - if(fq[i] > k){ - return m - i; - k = 0; - } - else { - k -= fq[i]; - } - } - return 1; - -} - -int main(){ - int tc; - cin >> tc; - while(tc--){ - int n, k; - cin >> n >> k; - vector a(n); - for(int i = 0; i < n; i++) cin >> a[i]; - int ans = solve(n, k, a); - cout << ans << endl; - } - - return 0; -} -","/* - * Gorrila and the Exam - * 18.01.24 - */ -#include -#include -#include -#include - -using namespace std; - -// calc total subarrays with same element -> calc subarrays whose sum of lenth is equal to p -> subtract -int solve(int n, int k, vector& a){ - -/* - unordered_map mp; - for(int i = 0; i < a.size(); i++){ - mp[a[i]]++; - } - - Using a vector instead of unordered_map is more efficient - due to reduced overhead and better memory locality, avoiding hash collision -*/ - sort(a.begin(), a.end()); - vector cnt = {1}; - - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { - cnt.back()++; - } else { - cnt.emplace_back(1); - } - } - - sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - int ans = 0; - for(int i = 0; i < m-1; i++){ - if(cnt[i] > k){ - return m - i; - k = 0; - } - else { - k -= cnt[i]; - } - } - return 1; - -} - -int main(){ - int tc; - cin >> tc; - while(tc--){ - int n, k; - cin >> n >> k; - vector a(n); - for(int i = 0; i < n; i++) cin >> a[i]; - int ans = solve(n, k, a); - cout << ans << endl; - } - - return 0; -} -",2 -gauravandbhagat,2057B - Gorilla and the Exam,c++17 ,301344188,301344380,"#include -using namespace std; - -int solve(){ - int n,k; - vector a; - cin>>n>>k; - for(int i = 0;i>x; - a.push_back(x); - } - priority_queue,greater> pq; - map mp; - for(auto x : a){ - mp[x]++; - } - int ele = mp.size(); - if(ele >= k){ - return 1; - } - for(auto x : mp){ - pq.push(x.second); - } - while(k>=pq.top()){ - int p = pq.top(); - pq.pop(); - k -= p; - } - return pq.size(); -} - - int main(){ - int t; - cin>>t; - while(t--){ - int ans = solve(); - cout< -using namespace std; - -int solve(){ - int n,k; - vector a; - cin>>n>>k; - for(int i = 0;i>x; - a.push_back(x); - } - priority_queue,greater> pq; - map mp; - for(auto x : a){ - mp[x]++; - } - for(auto x : mp){ - pq.push(x.second); - } - while(!pq.empty() && k>=pq.top()){ - int p = pq.top(); - pq.pop(); - k -= p; - } - return pq.empty() ? 1 : pq.size(); -} - - int main(){ - int t; - cin>>t; - while(t--){ - int ans = solve(); - cout< -#include -#include -using namespace std; -void solve() -{ - int n,k;cin>>n>>k; - vectora(n); - for(int i=0;i>a[i]; - } - sort(a.begin(),a.end()); - vectorb(1,1); - for(int i=1;ik) - { - cout<>t; - while(t--) - { - solve(); - } - return 0; -} -","#include -#include -#include -using namespace std; -void solve() -{ - int n,k;cin>>n>>k; - vectora(n); - for(int i=0;i>a[i]; - } - sort(a.begin(),a.end()); - vectorb(1,1); - for(int i=1;ik) - { - cout<>t; - while(t--) - { - solve(); - } - return 0; -} -",1 -luoqinxing,2057B - Gorilla and the Exam,c++20 ,301382450,301383286,"#include -#include -#include -#include -#include -#include -using namespace std; -void solve() { - int t; - cin >> t; - while (t--) { - int n, k; - cin >> n >> k; - vector q(n); - unordered_mapq1; - for (int i = 0; i < n; i++) { - cin >> q[i]; - q1[q[i]]++; - } - vectorq2; - for (const auto x : q1) { - q2.push_back(x.second); - } - int a = q2.size(); - sort(q2.begin(), q2.end()); - for (int i = 0; i < q2.size(), i++) { - if (q2[i] <= k) { - k -= q2[i]; - a--; - } - } - cout << max(1, a) << endl; - } -} -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - solve(); - return 0; -}","#include -using namespace std; -#define int long long -#define all(x) x.begin(),x.end() -const int mod = 1e9+10; -int n,m,q,k; -void solve(){ - cin>>n>>k; - vectorv(n); - mapmp; - for (int i =0;i>v[i]; - mp[v[i]]++; - } - int cnt =0; - vector>pa; - for (auto i:mp) { - pa.push_back({i.second,i.first}); - } - sort(all(pa)); - for (int i =0;i>t; - while(t--){ - solve(); - } -}",2 -VenuManikanta,2057B - Gorilla and the Exam,c++23 ,301210385,301209720,"#include -using namespace std; -// #define int long long - -int32_t main() -{ - int t; - cin>>t; - while(t--) { - int n,k; cin>>n>>k; - map fq; - for(int i=0;i>x; - fq[x]++; - } - vector v; - for(auto& x : fq) { - v.push_back(x.second); - } - sort(v.begin(),v.end(), greater ()); - while(k > 0 && !v.empty()) { - if(v.back() > k) - break; - k -= v.back(); - v.pop_back(); - } - cout << max((int)v.size(), 1) << endl; - } - return 0; -}","#include -using namespace std; -#define int long long - -int32_t main() -{ - int t; - cin>>t; - while(t--) { - int n,k; cin>>n>>k; - unordered_map fq; - for(int i=0;i>x; - fq[x]++; - } - vector v; - for(auto& x : fq) { - v.push_back(x.second); - } - sort(v.begin(),v.end(), greater ()); - while(k > 0) { - if(v.back() <= k) { - k -= v.back(); - v.pop_back(); - } - } - cout << max((int)v.size(), 1LL) << endl; - } - return 0; -}",1 -DigvijayChavan,2057B - Gorilla and the Exam,c++17 ,301123505,301123707,"#include - -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned; -// using u128 = unsigned __int128; - -void solve() { - std::unordered_map cnt; - std::vector data; - int n, k; - std::cin >> n >> k; - - for(int i = 0; i < n; ++i){ - int x; - std::cin >> x; - cnt[x]++; - } - - - for(auto [x, c] : cnt){ - data.push_back(c); - } - - std::sort(data.begin(), data.end()); - - int i = 0; - - int ans = data.size(); - - for(int i = 0; i < data.size()-1; ++i){ - if(k >= data[i]){ - k -= data[i]; - ans--; - } - } - - std::cout << ans << std::endl; -} - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t; - std::cin >> t; - - while (t--) { - solve(); - } - - return 0; -}","#include - -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned; -//using u128 = unsigned __int128; - -void solve() { - int n, k; - std::cin >> n >> k; - - std::map cnt; - for (int i = 0; i < n; i++) { - int a; - std::cin >> a; - cnt[a]++; - } - - std::vector c; - for (auto [_, x] : cnt) { - c.push_back(x); - } - std::sort(c.begin(), c.end()); - int ans = c.size(); - for (int i = 0; i < c.size() - 1; i++) { - if (k >= c[i]) { - ans--; - k -= c[i]; - } - } - std::cout << ans << ""\n""; -} - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t; - std::cin >> t; - - while (t--) { - solve(); - } - - return 0; -}",2 -gggxxxyyy,2057B - Gorilla and the Exam,c++20 ,301547093,301549269,"#include -#include -using namespace std; -#define ll long long -int main(){ - int t;cin>>t; - while(t--){ - int n,k;cin>>n>>k; - int st[n],sp[n]={0}; - for(int i=0;i>st[i]; - } - sort(st,st+n); - int p=0; - sp[0]=1; - for(int i=1;i0&&p>=0){ - k=k-sp[ss-p]; - p--; - } - p++; - if(p<=1) p=1; - cout< -#include -using namespace std; -#define ll long long -int main(){ - int t;cin>>t; - while(t--){ - int n,k;cin>>n>>k; - int st[n],sp[n]={0}; - for(int i=0;i>st[i]; - } - sort(st,st+n); - int p=0; - sp[0]=1; - for(int i=1;i0){ - if(p==0){ - break; - } - if(k>=sp[ss-p]){ - k=k-sp[ss-p]; - } - else{ - break; - } - p--; - } - if(p<=1) p=1; - cout< -#include -#include -using namespace std; -int main() { - map times; - int t,n,k,num,st=0; - cin >>t; - for (int i=0;i>n>>k; - for (int j=0;j>num; - if (times[num]==0) { - times[num]=1; - st++; } - else times[num]++; - } - multiset s; - for (auto &pair : times) { - s.insert(pair.second); - } - for (int x:s){ - if (x>k) break; - else { - k=k-x; - st--; - } - } - if (st!=0)cout < -#include -#include -using namespace std; -int main() { - map times; - int t,n,k,num,st=0; - cin >>t; - for (int i=0;i>n>>k; - for (int j=0;j>num; - if (times[num]==0) { - times[num]=1; - st++; } - else times[num]++; - } - multiset s; - for (auto &pair : times) { - s.insert(pair.second); - } - for (int x:s){ - if ((x>k)||((x==1)&&(k==1))) break; - else { - k=k-x; - st--; - } - } - - cout < -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int tc; cin >> tc; - for(int t = 0; t < tc; t++){ - int n, m; cin >> n >> m; - vector nums; - for(int i = 0; i < n; i++){ int x; cin >> x; nums.push_back(x); } - vector freq; - sort(nums.begin(), nums.end()); - int last = -1, f = 0; - for(int n : nums){ - if(last == -1){ last = n; f++; } - else if(last == n){ f++; } - else{ last = n; freq.push_back(f); f = 1;} - } - freq.push_back(f); - sort(freq.begin(), freq.end()); - int i = 0; - while(i < freq.size()-1){ - if(m < freq[i]){ break; } - m -= freq[i]; i++; - } - cout << freq.size() - i << '\n'; - } -}","#include -using namespace std; - -int main(){ - int tc; cin >> tc; - for(int t = 0; t < tc; t++){ - int n, m; cin >> n >> m; - unordered_map nums; - for(int i = 0; i < n; i++){ int x; cin >> x; nums[x]++; } - vector freq; - int i = 0, removed = 0, greatest = 0; - for(auto& [key, val] : nums){ freq.push_back(val); greatest = max(greatest, val); } - bool runThrough = false; - while(i < freq.size()){ - if(m < freq[i]){ i++; continue; } - if(freq[i] == greatest){ if(!runThrough){ runThrough = true; i++; continue; } } - m -= freq[i]; removed++; i++; - } - cout << freq.size() - removed << '\n'; - } -}",1 -dev_davda,2057B - Gorilla and the Exam,c++20 ,301248126,301250631,"# include -using namespace std; -# define no cout <<""NO"" << endl -# define yes cout << ""YES""<< endl -# define ll long long int -# define flp(i,k,n) for(ll i = k;i=n;i--) -# define i(a) ll a;cin >> a; -# define ic(i) char i;cin >> i; -# define ia(a,n) ll a[n];for(ll i=0;i> a[i]; -# define ica(a,n) char a[n];for(ll i=0;i> a[i]; -# define is(s) string s;cin >> s; -# define mod 1000000007 -# define dv 1000000000 - - -// bool isPrime(int n) -// { -// if (n <= 1) -// return false; - -// for (int i = 2; i <= sqrt(n); i++) -// if (n % i == 0) -// return false; - -// return true; -// } - - - -// void dfs(ll node,ll iter,int ind,vector>>& v,set &s,ll &sum){ -// s.insert(node); -// // cout << ""node-->"" << node <<"" iter-->"" << iter<< endl; -// ll w=0; -// while(!v[node-1].empty()){ -// ll u=iter; -// ll t1=v[node-1].front().first; -// ll t2=v[node-1].front().second; -// // cout << t1 << "" "" << t2 << endl; -// if(s.find(t1)!=s.end()){ -// v[node-1].pop(); -// continue; -// } -// else{ -// if(t2""<< iter << "" sum"" << sum<< endl; -// dfs(t1,u,t2,v,s,sum); -// } -// v[node-1].pop(); -// } -// } - - -// bool comp(pair p1 ,pair p2){ -// if(p1.second==p2.second)return p1.first>p2.first; -// else return p1.second < p2.second; -// } - - -void solve(){ - i(n); - i(k); - ia(arr,n); - - map m; - flp(i,0,n){ - m[arr[i]]++; - } - - ll a[m.size()]; - int j=0; - for(auto i:m){ - a[j++]=i.second; - } - sort(a,a+m.size()); - if(k==0){ - cout << m.size() << endl; - return; - } - flp(i,0,m.size()){ - if(k<=0){ - cout << m.size()-i << endl; - return; - } - else{ - k-=a[i]; - } - } - cout << 1 << endl; -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - ll t=1; - cin >> t; - while(t--)solve(); -}","# include -using namespace std; -# define no cout <<""NO"" << endl -# define yes cout << ""YES""<< endl -# define ll long long int -# define flp(i,k,n) for(ll i = k;i=n;i--) -# define i(a) ll a;cin >> a; -# define ic(i) char i;cin >> i; -# define ia(a,n) ll a[n];for(ll i=0;i> a[i]; -# define ica(a,n) char a[n];for(ll i=0;i> a[i]; -# define is(s) string s;cin >> s; -# define mod 1000000007 -# define dv 1000000000 - - -// bool isPrime(int n) -// { -// if (n <= 1) -// return false; - -// for (int i = 2; i <= sqrt(n); i++) -// if (n % i == 0) -// return false; - -// return true; -// } - - - -// void dfs(ll node,ll iter,int ind,vector>>& v,set &s,ll &sum){ -// s.insert(node); -// // cout << ""node-->"" << node <<"" iter-->"" << iter<< endl; -// ll w=0; -// while(!v[node-1].empty()){ -// ll u=iter; -// ll t1=v[node-1].front().first; -// ll t2=v[node-1].front().second; -// // cout << t1 << "" "" << t2 << endl; -// if(s.find(t1)!=s.end()){ -// v[node-1].pop(); -// continue; -// } -// else{ -// if(t2""<< iter << "" sum"" << sum<< endl; -// dfs(t1,u,t2,v,s,sum); -// } -// v[node-1].pop(); -// } -// } - - -// bool comp(pair p1 ,pair p2){ -// if(p1.second==p2.second)return p1.first>p2.first; -// else return p1.second < p2.second; -// } - - -void solve(){ - i(n); - i(k); - ia(arr,n); - - map mp; - flp(i,0,n){ - mp[arr[i]]++; - } - vector v; - for(auto i:mp){ - v.push_back(i.second); - } - int l = v.size(); - sort(v.begin(),v.end()); - if(k>=n){ - cout << 1 << endl; - return; - } - else{ - flp(i,0,l){ - if(k-v[i]>=0){ - k-=v[i]; - } - else{ - cout << l-i << endl; - return; - } - } - } - -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - ll t=1; - cin >> t; - while(t--)solve(); -}",2 -pratik_2024,2057B - Gorilla and the Exam,c++17 ,301704012,301703810,"#include -#include -using namespace std; - -int solve() -{ - int n, k, num; - cin >> n >> k; - - map mp; - - for (int i = 0; i < n; i++) - { - cin >> num; - mp[num]++; - } - - vector arr; - for (auto it : mp) - { - int first = it.first; - int second = it.second; - - arr.push_back(second); - } - - sort(arr.begin(), arr.end()); - - int ans = (int)mp.size(); - for (int i = 0; i < arr.size(); i++) - { - if (k - arr[i] >= 0) - { - k = k - arr[i]; - ans--; - } - else - break; - } - return max(ans, 1); -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) - cout << solve() << endl; - - return 0; -}","#include -#include -using namespace std; - -int solve() -{ - int n, k, num; - cin >> n >> k; - - unordered_map mp; - - for (int i = 0; i < n; i++) - { - cin >> num; - mp[num]++; - } - - vector arr; - for (auto it : mp) - { - int first = it.first; - int second = it.second; - - arr.push_back(second); - } - - sort(arr.begin(), arr.end()); - - int ans = (int)mp.size(); - for (int i = 0; i < n; i++) - { - if (k - arr[i] >= 0) - { - k = k - arr[i]; - ans--; - } - else - break; - } - return max(ans, 1); -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) - cout << solve() << endl; - - return 0; -}",1 -arupratandey,2057B - Gorilla and the Exam,c++17 ,301551746,301552200,"#include -using namespace std; -#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define fraction(a) cout.unsetf(ios::floatfield);cout.precision(a);cout.setf(ios::fixed,ios::floatfield); -#define ll long long -#define endl '\n' -#define gap "" "" -#define bug(a) cerr<< #a << "" : "" << a <>t; while(t--) -#define pb push_back -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) ((a*b)/(__gcd(a,b))) -const ll mod = 1000000007; -const double pi= acos(-1); -const int n=2*(1e5+10); -int main() -{ - optimize() - tc - { - ll n,k; - cin>>n>>k; - vectorv(n),v1; - ll i; - mapcnt; - for(i=0;i>v[i]; - cnt[v[i]]++; - } - ll n1=cnt.size(); - //bug(n1); - ll c1=0; - for(auto u:cnt){ - v1.pb(u.second); - } - sort(all(v1)); - for(i=0;i -using namespace std; -#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define fraction(a) cout.unsetf(ios::floatfield);cout.precision(a);cout.setf(ios::fixed,ios::floatfield); -#define ll long long -#define endl '\n' -#define gap "" "" -#define bug(a) cerr<< #a << "" : "" << a <>t; while(t--) -#define pb push_back -#define gcd(a,b) __gcd(a,b) -#define lcm(a,b) ((a*b)/(__gcd(a,b))) -const ll mod = 1000000007; -const double pi= acos(-1); -const int n=2*(1e5+10); -int main() -{ - optimize() - tc - { - ll n,k; - cin>>n>>k; - vectorv(n),v1; - ll i; - mapcnt; - for(i=0;i>v[i]; - cnt[v[i]]++; - } - ll n1=cnt.size(); - //bug(n1); - ll c1=0; - for(auto u:cnt){ - v1.pb(u.second); - } - sort(all(v1)); - for(i=0;i -using namespace std; -#define ll long long -#define all(v) (v).begin(), (v).end() -#define pb push_back -#define mp make_pair -const ll MOD = 1e9 + 7; -const ll INF = 1e18; - -int main() -{ - ll t; - cin >> t; - while (t--) - { - int n, k; - cin >> n >> k; - vector a(n); - unordered_map mpp; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - mpp[a[i]]++; - - } - int count = 0; - int maxi = 1e10; - vector freq; - for (auto it : mpp) - { - count++; - maxi = max(maxi, it.second); - freq.push_back(it.second); - } - sort(freq.begin(), freq.end()); - for (int i = 0; i < freq.size(); i++) - { - if (freq[i] <= k) - { - k -= freq[i]; - count--; - } - if(k<0) break; - } - if (count == 0) - cout << 1 << endl; - else - cout << count << endl; - } - return 0; -}","#include -using namespace std; -#define ll long long -#define all(v) (v).begin(), (v).end() -#define pb push_back -#define mp make_pair -const ll MOD = 1e9 + 7; -const ll INF = 1e18; - -int main() -{ - ll t; - cin >> t; - while (t--) - { - int n, k; - cin >> n >> k; - int x; - map mpp; - for (int i = 0; i < n; i++) - { - cin >> x; - mpp[x]++; - - } - int count = 0; - vector freq; - for (auto it : mpp) - { - count++; - freq.push_back(it.second); - } - sort(freq.begin(), freq.end()); - for (int i = 0; i < freq.size(); i++) - { - if (freq[i] <= k) - { - k -= freq[i]; - count--; - } - if(k<0) break; - } - if (count == 0) - cout << 1 << endl; - else - cout << count << endl; - } - return 0; -}",2 -myselfsahilkhan092,2057B - Gorilla and the Exam,c++23 ,302104397,302103094,"#include -using namespace std; - -int main(){ - int t,n,k; - long long a; - vector nums; - cin>>t; - while(t--){ - cin>>n>>k; - nums.resize(n); - map mp; - set> st; - for(int i=0;i>nums[i]; - mp[nums[i]]++; - } - for(auto it : mp){ - st.insert({it.second,it.first}); - } - - - while(k){ - auto it=*st.begin(); - if(k -using namespace std; - -int main(){ - int t,n,k,a; - vector nums; - cin>>t; - while(t--){ - cin>>n>>k; - nums.resize(n); - map mp; - set> st; - for(int i=0;i>nums[i]; - mp[nums[i]]++; - } - for(auto it : mp){ - st.insert({it.second,it.first}); - } - - - while(k){ - auto it=*st.begin(); - st.erase(st.begin()); - if(k -using namespace std; - -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define ll long long - -void solve() { - int n, k; - cin >> n >> k; - vector a(n); - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - - sort(a.begin(), a.end()); - vector cnt = {1}; - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { - cnt.back()++; - } else { - cnt.emplace_back(1); - } - } - sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt[i] > k) { - cout << m - i << ""\n""; - return; - } - k -= cnt[i]; - } - cout << 1 << ""\n""; -} - -int main() { - fast_io; - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; - -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define ll long long - -int main() { - fast_io; - int t; - cin >> t; - while (t--) { - int n, k; - cin >> n >> k; - vector arr(n); - for (int i = 0; i < n; ++i) { - cin >> arr[i]; - } - - // Step 1: Calculate frequencies - int max_val = *max_element(arr.begin(), arr.end()); - vector freq(max_val + 1, 0); - for (int num : arr) { - freq[num]++; - } - - // Step 2: Remove zeros and sort frequencies - vector counts; - for (int count : freq) { - if (count > 0) { - counts.push_back(count); - } - } - sort(counts.begin(), counts.end()); // Sort by frequency (ascending) - - // Step 3: Use k to reduce frequencies - for (int i = 0; i < counts.size() && k > 0; ++i) { - if (k >= counts[i]) { - k -= counts[i]; // Use all occurrences of this element - counts[i] = 0; // Mark as removed - } else { - counts[i] -= k; // Reduce remaining frequency - k = 0; // All of k is used - } - } - - // Step 4: Count remaining distinct elements - int cnt = 0; - for (int count : counts) { - if (count > 0) { - cnt++; - } - } - - // If no distinct elements are left, output 1 - cout << (cnt == 0 ? 1 : cnt) << endl; - } - - return 0; -} -",1 -Rishi_Sunkari,2057B - Gorilla and the Exam,c++17 ,301348746,302028918,"#include -using namespace std; -typedef long long ll; -#define nl ""\n"" -#define yes cout<<""YES\n"" -#define no cout<<""NO\n"" -#define mp make_pair -constexpr int mod=(int)2*1e5+7; -bool ct=false; - -inline void solve(){ - int n,k; - cin>>n>>k; - vectorv(n); - unordered_mapm; - vectors; - for(auto it:v){ - cin>>it; - m[it]++; - } - for(auto it:m){ - s.push_back(it.second); - } - sort(s.begin(),s.end()); - int ans=k; - int c=0; - for(int i=0;i>t; - while(t--) solve(); - return 0; -} -/* /\_/\ -* (= ._.) -* / > \> - 你好, - 操你 母狗!! -*/ -","#include -using namespace std; -typedef long long ll; - - -int solve(){ - int n,k,temp; - cin>>n>>k; - map m; - - for(int i=0;i>temp; - m[temp]++; - } - vector v; - for(auto x:m){ - v.push_back(x.second); - } - sort(v.begin(),v.end()); - int ans=v.size(); - // cout<<""ans ""<>testCase; - while(testCase--){ - solve(); - } - return 0; -}",2 -shicj,2057B - Gorilla and the Exam,c++17 ,301375169,301371442,"#include -#define int long long -using namespace std; -mapmp; -vectornum; -int n,m,idt,x; -void solve(){ - mp.clear(); - num.clear(); - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - mp[x]++; - } - for(auto _:mp){ - num.push_back(_.second); - } - sort(num.begin(),num.end()); - bool flag=false; - int s=num.size(); - for(int i=0;i=num[i]){ - m-=num[i]; - } - else{ - printf(""%lld\n"",s-i); - flag=true; - return; - } - } - printf(""1\n""); -} -signed main(){ -#ifdef USE_FILE_IO - freopen(""code.in"",""r"",stdin); - freopen(""code.out"",""w"",stdout); -#endif - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -unordered_mapmp; -int tot[200005]; -int n,m,idt,x; -void solve(){ - idt=0; - mp.clear(); - for(int i=1;i<=n;i++){ - tot[i]=0; - } - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - if(mp[x]==0){ - mp[x]=++idt; - } - x=mp[x]; - tot[x]++; - } - int ans=idt; - sort(tot+1,tot+idt+1); - for(int i=1;i>t; - while(t--){ - solve(); - } - return 0; -}",1 -Coder738,2057B - Gorilla and the Exam,c++20 ,301675867,301675981,"#include -#define ll long long -using namespace std; - -ll t, n, k, x, ans; -set a; -multiset b; -priority_queue , greater> pq; - -int main() { - cin >> t; - for(ll T = 1; T <= t; T++) { - cin >> n >> k; - a.clear(); - b.clear(); - for(ll i = 1; i <= n; i++) { - cin >> x; - a.insert(x); - b.insert(x); - } - ans = a.size(); - pq = priority_queue , greater>(); - for(ll i : a) { - pq.push(b.count(i)); - cout << i << ""/"" << b.count(i) << "" ""; - } - cout << ""\n""; - while(pq.size() > 1) { - if(k >= pq.top()) { - k -= pq.top(); - ans--; - pq.pop(); - } else break; - } - cout << ans << ""\n\n""; - } -}","#include -#define ll long long -using namespace std; - -ll t, n, k, x, ans; -set a; -multiset b; -priority_queue , greater> pq; - -int main() { - cin >> t; - for(ll T = 1; T <= t; T++) { - cin >> n >> k; - a.clear(); - b.clear(); - for(ll i = 1; i <= n; i++) { - cin >> x; - a.insert(x); - b.insert(x); - } - ans = a.size(); - pq = priority_queue , greater>(); - for(ll i : a) { - pq.push(b.count(i)); - } - while(pq.size() > 1) { - if(k >= pq.top()) { - k -= pq.top(); - ans--; - pq.pop(); - } else break; - } - cout << ans << ""\n""; - } -}",2 -snehaaa_02,2057B - Gorilla and the Exam,c++17 ,301525762,301513811,"#include -using namespace std; - -void solve(){ - int n, k; - cin>>n>>k; - vector v(n), f; - map m; - for(int i = 0; i < n; i++){ - cin>>v[i]; - m[v[i]]++; - } - if(k >= n){ - cout<<1< k) ct++; - else f.push_back(it.second); - } - sort(f.begin(), f.end()); - for(int j = 0; j < f.size(); j++){ - if(k >= f[j]) { - k -= f[j]; - } - else ct++; - } - cout<>t; - while(t--) solve(); -}","#include -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin>>t; - while(t--){ - int n, k; - cin>>n>>k; - vector v(n); - set s; - int mini = INT_MAX, cm = INT_MAX; - int p = 0; - for(int i = 0; i < n; i++){ - int a; - cin>>a; - v[i] = a; - if(k == 0){ - s.insert(a); - } - else if(k == 1){ - mini = min(mini, a); - s.insert(mini); - } - } - if(k > 1){ - for(int i = 0; i < n; i+=k){ - cm = v[i]; - for(int j = 1; j < k; j++){ - if(j+i > n) break; - cm = min(cm, v[(j+i)]); - } - s.insert(cm); - } - } - cout< -using namespace std; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define int long long -#define MOD 1000000007 - - -signed main() { - fastio(); - int test; - cin >> test; - - - while (test--) { - int n,m,k; - cin >>n>>k; - unordered_mapmp; - int y=0,ans=0; - - vector a(n),ele; - for (int i = 0; i < n; i++) { - cin>>a[i]; - } - sort(a.begin(),a.end()); - int c=1; - for (int i = 1; i < n; i++) { - if(a[i]==a[i-1]){ - c++; - } - else{ - ele.push_back(c); - c=1; - } - } - ele.push_back(c); - sort(ele.begin(),ele.end()); - int i=0; - while(i -using namespace std; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define int long long -#define MOD 1000000007 - - -signed main() { - fastio(); - int test; - cin >> test; - - - while (test--) { - int n,m,k; - cin >>n>>k; - unordered_mapmp; - int y=0,ans=0; - - vector a(n),ele; - for (int i = 0; i < n; i++) { - cin>>a[i]; - } - sort(a.begin(),a.end()); - int c=1; - for (int i = 1; i < n; i++) { - if(a[i]==a[i-1]){ - c++; - } - else{ - ele.push_back(c); - c=1; - } - } - sort(ele.begin(),ele.end()); - int i=0; - while(i -using namespace std; -int main(){ - int t;cin>>t; - while(t--){ - long long n,m=0,j,count=1,k,x;cin>>n>>k; - vectorv(n),a(n);sets; - for(long long i=0;i>v[i];}sort(v.begin(),v.end()); - for(long long i=0;i=0;i--){ - if(v[i]!=x){k--;} - if(k==0){j=i;break;} - }*/ - if(m>k||m==1){m=0;} - for(long long i=0;i -using namespace std; -int main(){ - int t;cin>>t; - while(t--){ - long long n,k;cin>>n>>k; - vectorv(n); - mapm; - for(long long i=0;i>v[i];m[v[i]]++;} - vectora; - for(auto& [x,y]:m){a.push_back(y);} - sort(a.begin(),a.end()); - long long ans=a.size(); - for(long long i=0;i=a[i]){k-=a[i];ans--;}} - cout< -#include -using namespace std; -int main(){ - int t; - cin>>t; - unordered_mapmp; - while(t--){ - int n,k; - cin>>n>>k; - int a[]; - mp.clear(); - for(int i=0; i>a[i]; - mp[a[i]]++; - } - multisetst; - for(auto b:mp){ - st.push(b.second); - } - int ans = st.size(); - for(auto a : st){ - if(k>=a){ - ans--; - m-=a; - } - } - cout< -using namespace std; -mapmp; -int main() -{ - int t; - cin>>t; - while(t--){ - long long n,m; - cin>>n>>m; - mp.clear(); - for(int i=1;i<=n;i++){ - int a; - cin>>a; - mp[a]++; - } - multisetst; - for(auto b:mp) - st.insert(b.second); - int ans=st.size(); - for(int a:st){ - if(m>=a)ans--,m-=a; - }cout< -using namespace std; -using namespace chrono; - - -void solver() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int input; cin >> input; - while(input--) { - int n, k; cin >> n >> k; - map map; - int num; - for(int i = 0; i < n; i++) { - cin >> num; - map[num]++; - } - - vector vec; - for(auto ele: map) vec.push_back(ele.second); - sort(vec.begin(), vec.end()); - - int passes = vec.size(); - - for(int i = 0; k > 0 && i < vec.size() - 1; i++) { - int temp = min(vec[i], k); - vec[i] -= temp; - k -= temp; - if(vec[i] == 0) passes--; - } - - cout << passes << ""\n""; - } -} - - -int main(){ - - solver(); - -} -","#include -using namespace std; -using namespace chrono; - - -void solver() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int input; cin >> input; - while(input--) { - int n, k; cin >> n >> k; - unordered_map map; - int num; - for(int i = 0; i < n; i++) { - cin >> num; - map[num]++; - } - - vector vec; - for(auto ele: map) vec.push_back(ele.second); - sort(vec.begin(), vec.end()); - - int passes = vec.size(); - - for(int i = 0; k > 0 && i < vec.size() - 1; i++) { - if(k >= vec[i]) { - k -= vec[i]; - vec[i] = 0; - passes--; - } - else break; - } - - cout << passes << ""\n""; - } -} - - -int main(){ - - solver(); -; -} -",1 -achechi15,2057B - Gorilla and the Exam,c++20 ,307638122,307638377,"#include - -typedef long long ll; -using namespace std; - -// 1,2,3,4,5,6,7,8 -//1,4,9,16,25,36,49 - -#define NMAX (4*100005) - - -void solve() { - int n, k; cin >> n >> k; - map mp; - for (int i = 0; i < n; i++) { - int aux; cin >> aux; - mp[aux]++; - } - - int arr[n]; - fill(arr, arr+n, INT_MAX); - int i = 0; - for (auto [first, second] : mp) { - // cout << second << "" ""; - arr[i] = second; - i++; - } - // cout << endl << "" -> ""; - sort(arr, arr+n); - for (int i = 0; i < n; i++) { - if (arr[i] <= k) { - k = k-arr[i]; - } else { - cout << mp.size() - i << endl; - return; - } - } - cout << 1 << endl; - -} - -int main() { - int t; cin >> t; - while (t--) solve(); - return 0; -}","#include - -typedef long long ll; -using namespace std; - -// 1,2,3,4,5,6,7,8 -//1,4,9,16,25,36,49 - -#define NMAX (4*100005) - - -void solve() { - int n, k; cin >> n >> k; - map mp; - for (int i = 0; i < n; i++) { - int aux; cin >> aux; - mp[aux]++; - } - - int arr[n]; - fill(arr, arr+n, INT_MAX); - int i = 0; - for (auto [first, second] : mp) { - // cout << second << "" ""; - arr[i] = second; - i++; - } - // cout << endl << "" -> ""; - sort(arr, arr+n); - for (int i = 0; i < n; i++) { - if (arr[i] <= k) { - k = k-arr[i]; - } else { - if (mp.size() - i == 0) cout << 1 << endl; - else cout << mp.size() - i << endl; - return; - } - } - cout << 1 << endl; - -} - -int main() { - int t; cin >> t; - while (t--) solve(); - return 0; -}",2 -S1rajum_Mun1r,2057B - Gorilla and the Exam,c++20 ,307676590,307674065,"#include -using namespace std; - -// Fast I/O -#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) - -// Input/Output file setup for debugging -#ifndef ONLINE_JUDGE - #define FILE_IO freopen(""input.txt"", ""r"", stdin); freopen(""output.txt"", ""w"", stdout);freopen(""error.txt"", ""w"", stderr) -#else - #define FILE_IO -#endif - -// Type Definitions -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -#define sz(x) (ll)(x).size() -#define vii vector -#define vll vector -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl - -// Constants -const ll MOD = 1e9 + 7; // Modular arithmetic constant - -// Debugging Macro (Prints variable values during local testing) -#ifndef ONLINE_JUDGE - #define debug(x) cerr << #x << "" = "" << x << endl - #define debugv(v) cerr << #v << "" = ""; for (auto i : v) cerr << i << "" ""; cerr << endl -#else - #define debug(x) - #define debugv(x) -#endif - -// Utility Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } -ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } -ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } -ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -// Main problem-solving function -void solve() { - int n,k; - cin >> n >> k; - map mp; - for(int i = 0; i < n; ++i){ - int x; - cin >> x; - mp[x]++; - } - - priority_queue, vector>, greater<>> pq; - - for(auto &a: mp){ - pq.push({a.ss,a.ff}); - } - while(k > 0 && !pq.empty()){ - auto [f,s] = pq.top(); - pq.pop(); - if(k >= f){ - k -= f; - } - else{ - pq.push({f-k,s}); - k = 0; - } - } - cout << max(1,(int)sz(pq)) << endl; - - -} - -int main() { - // File and Fast I/O Setup - FAST_IO; - FILE_IO; - - // Number of test cases - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -","#include -using namespace std; - -// Fast I/O -#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) - -// Input/Output file setup for debugging -#ifndef ONLINE_JUDGE - #define FILE_IO freopen(""input.txt"", ""r"", stdin); freopen(""output.txt"", ""w"", stdout);freopen(""error.txt"", ""w"", stderr) -#else - #define FILE_IO -#endif - -// Type Definitions -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -#define sz(x) (ll)(x).size() -#define vii vector -#define vll vector -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl - -// Constants -const ll MOD = 1e9 + 7; // Modular arithmetic constant - -// Debugging Macro (Prints variable values during local testing) -#ifndef ONLINE_JUDGE - #define debug(x) cerr << #x << "" = "" << x << endl - #define debugv(v) cerr << #v << "" = ""; for (auto i : v) cerr << i << "" ""; cerr << endl -#else - #define debug(x) - #define debugv(x) -#endif - -// Utility Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } -ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } -ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } -ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -// Main problem-solving function -void solve() { - int n,k; - cin >> n >> k; - vii v(n); - for(int &a: v) cin >> a; - sort(all(v)); - set st; - for(int i = k; i < n; ++i){ - st.insert(v[i]); - } - cout << ((sz(st) > 0)? sz(st): 1) << endl; - -} - -int main() { - // File and Fast I/O Setup - FAST_IO; - FILE_IO; - - // Number of test cases - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -",1 --sHaHiN_01,2057B - Gorilla and the Exam,c++20 ,301146192,301107410,"#include -using namespace std; -#define endl '\n' -#define ll long long -#define optimize() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -int main(){ - optimize(); - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - int arr[n]; - mapmp; - for(int i=0;i>arr[i]; - mp[arr[i]]++; - } - vectorv; - for(auto u:mp)v.push_back(u.second); - sort(v.begin(),v.end()); - int cnt=v.size(); - for(auto u:v) - { - if(u<=k) - { - cnt--; - k=k-u; - } - } - cout< -using namespace std; -#define endlb'\n' -#define ll long long -#define optimize() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -int main(){ - optimize(); - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vectorarr(n); - unordered_mapfreq_map; - for(int i=0;i>arr[i]; - freq_map[arr[i]]++; - } - vector>freq_vec; - for(auto&entry:freq_map){ - freq_vec.push_back(entry); - } - sort(freq_vec.begin(),freq_vec.end(),[](pair&a,pair&b){ - return a.second -using namespace std; -#define ll long long -int main() -{ - int t; - cin>>t; - while(t--){ - int n, k; - cin>>n>>k; - vector vec; - for(int i=0; i>x; - vec.push_back(x); - } - map mp; - for(int i=0; i> kv; - for(auto i:mp){ - vector ins(2); - ins[0] = i.second; - ins[1] = i.first; - kv.push_back(ins); - } - sort(kv.begin(), kv.end()); - int i=0; - while(k>0 && i=kv[i][0]){ - k-=kv[i][0]; - i++; - } - else{ - break; - } - } - if(i == kv.size()) cout<<1< -using namespace std; -#define ll long long -int main() -{ - int t; - cin>>t; - while(t--){ - int n, k; - cin>>n>>k; - vector vec; - for(int i=0; i>x; - vec.push_back(x); - } - map mp; - for(int i=0; i> kv; - for(auto i:mp){ - vector ins(2); - ins[0] = i.second; - ins[1] = i.first; - kv.push_back(ins); - } - sort(kv.begin(), kv.end()); - int i=0; - while(k>0 && i=kv[i][0]){ - k-=kv[i][0]; - i++; - } - } - if(i == kv.size()) cout<<1< -#include -#include -#include -#define int long long -using namespace std; -// 不需要将 大的数字 保存下来 - -signed main() { - int t; // 测试用例数量 - cin >> t; - while (t--) { - int n, k; // 数组长度和最多替换次数 - cin >> n >> k; - - vector a(n); - - // 读取输入并统计频率 - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - sort(a.begin(), a.end()); - // 将频率提取为 vector 并按频率排序 - vectorcnt = {1}; - for (int i = 1; i < n; i++) { - if (a[i] == a[i - 1]) { - cnt.back()++; - } - else { - cnt.emplace_back(1); - } - } - sort(cnt.begin(), cnt.end()); - // 计算可以移除的不同数字的数量 - int removed = 0; - for (int d : cnt) { - if (k >= d) { - k -= d; - removed++; - } - else { - break; // 如果 k 不足以替换当前频率,直接退出 - } - } - - // 计算答案 - int c = cnt.size() - removed; - int ans = max(c , 1LL) ; - cout << ans << endl; - } - return 0; -}","#include -#include -#include -#include -#include -#define int long long -using namespace std; - -signed main() { - int t; // 测试用例数量 - cin >> t; - while (t--) { - priority_queue, greater>pq; - int n, k; // 数组长度和最多替换次数 - cin >> n >> k; - unordered_map freq; // 统计频率 - vector a(n); - - // 读取输入并统计频率 - for (int i = 0; i < n; i++) { - cin >> a[i]; - freq[a[i]]++; - } - - // 将频率提取为 vector 并按频率排序 - vector counts; - for (auto& p : freq) { - pq.push(p.second); - } - /*sort(counts.begin(), counts.end());*/ - - // 计算可以移除的不同数字的数量 - int removed = 0; - - while (k > 0) { - int l = pq.top(); - k -= l; - pq.pop(); - if (k >= 0)removed++; - } - - // 计算答案 - - int ans = max((int)freq.size() - removed, 1LL); - cout << ans << endl; - } - return 0; -}",1 -_scj_,2057B - Gorilla and the Exam,c++23 ,301374912,301375071,"#include -#define int long long -using namespace std; -mapmp; -vectornum; -int n,m,idt,x; -void solve(){ - mp.clear(); - num.clear(); - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - mp[x]++; - } - for(auto _:mp){ - num.push_back(_.second); - } - // sort(num.begin(),num.end()); - // int ans=num.size(); - // for(auto i:num){ - // if(m<=0)break; - // if(i<=m){ - // m-=i; - // } - // ans--; - // } - // printf(""%lld\n"",max(ans,1ll)); - bool flag=false; - int s=num.size(); - for(int i=0;i=num[i]) - m-=num[i]; - else{ - printf(""%lld\n"",s-i); - flag=true; - break; - } - } - if(!flag){ - printf(""1\n""); - } -} -signed main(){ -#ifdef USE_FILE_IO - freopen(""code.in"",""r"",stdin); - freopen(""code.out"",""w"",stdout); -#endif - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -mapmp; -vectornum; -int n,m,idt,x; -void solve(){ - mp.clear(); - num.clear(); - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - mp[x]++; - } - for(auto _:mp){ - num.push_back(_.second); - } - sort(num.begin(),num.end()); - // int ans=num.size(); - // for(auto i:num){ - // if(m<=0)break; - // if(i<=m){ - // m-=i; - // } - // ans--; - // } - // printf(""%lld\n"",max(ans,1ll)); - bool flag=false; - int s=num.size(); - for(int i=0;i=num[i]){ - m-=num[i]; - } - else{ - printf(""%lld\n"",s-i); - flag=true; - return; - } - } - printf(""1\n""); -} -signed main(){ -#ifdef USE_FILE_IO - freopen(""code.in"",""r"",stdin); - freopen(""code.out"",""w"",stdout); -#endif - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",2 -zhentaozhang4,2057B - Gorilla and the Exam,c++17 ,301074768,301072744,"#include -using namespace std; - -int assign_smallest_to_largest(vector> &lis, int k, int n){ - int i = 0; - int current_most = lis.back().first; - int cnt = 0; - // cout << ""current_most ""< 0){ - cnt++; - } - } - return cnt; -} - -map m; -vector> lis; -int main(){ - ios::sync_with_stdio(false); // 取消同步流 - cin.tie(0); // 解绑cin与cout - cout.tie(0); // 解绑cout与cin - int t, n, k; - cin >> t; - - for(int i = 0; i < t; i++){ - cin >> n >> k; - for(int j = 0; j < n; j++){ - int x; - cin >> x; - m[x]++; - } - // cout << ""msize: ""<first, i->second)); - //cout << ""data pushed: ""<first << "" "" << i->second << endl; - } - // cout << ""data size: ""< &a, const pair &b){ - return a.second < b.second; - }); - - cout << assign_smallest_to_largest(lis, k, n) << endl; - // cout << ""lis size"" << lis.size() << endl; - m.clear(); - } - - - - return 0; -}","#include -using namespace std; - -int assign_smallest_to_largest(vector> &lis, int k, int n){ - int i = 0; - int current_most = lis.back().first; - int cnt = 0; - // cout << ""current_most ""< 0){ - cnt++; - } - } - return cnt; -} - -unordered_map m; -vector> lis; -int main(){ - ios::sync_with_stdio(false); // 取消同步流 - cin.tie(0); // 解绑cin与cout - cout.tie(0); // 解绑cout与cin - int t, n, k; - cin >> t; - - for(int i = 0; i < t; i++){ - cin >> n >> k; - for(int j = 0; j < n; j++){ - int x; - cin >> x; - m[x]++; - } - // cout << ""msize: ""<first, i->second)); - //cout << ""data pushed: ""<first << "" "" << i->second << endl; - } - // cout << ""data size: ""< &a, const pair &b){ - return a.second < b.second; - }); - - cout << assign_smallest_to_largest(lis, k, n) << endl; - // cout << ""lis size"" << lis.size() << endl; - m.clear(); - } - - - - return 0; -}",1 -ahmed-07,2057B - Gorilla and the Exam,c++23 ,304889332,304890161,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef long long ll; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -void flash(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -#define all(a) a.begin(),a.end() -#define all_r(a) a.rbegin(),a.rend() - -// bool is_suffix(string a, string b) -// { -// reverse(a.begin(), a.end()); -// reverse(b.begin(), b.end()); - -// for(int i = 0; i < b.size(); i++) -// { -// if(a[i] != b[i]) -// return false; -// } - -// return true; -// } - -// bool ispalin(vector& v) -// { -// for(int i = 0; i < v.size() / 2; i++) -// { -// if(v[i] != v[v.size() - i - 1]) -// return false; -// } - -// return true; -// } - - - -int main(void) -{ - flash(); - - int t; - cin>>t; - - while(t--) - { - int n, k; - cin>>n>>k; - - vector v(n); - for(int i = 0; i < n; i++) - cin>>v[i]; - - sort(all(v)); - - int mx = 0; - int mxn = v[0]; - int cnt = 1; - for(int i = 1; i < n; i++) - { - if(v[i] == v[i-1]) - cnt++; - else - { - if(mx < cnt) - { - mx = cnt; - cnt = 1; - mxn = v[i-1]; - } - } - } - - for(int i = 0; i < n && k > 0; i++) - { - if(v[i] != mxn) - { - v[i] = mxn; - k--; - } - } - - unordered_set s; - for(int i = 0; i < n; i++) - { - s.insert(v[i]); - } - - cout< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef long long ll; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -void flash(void) -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -#define all(a) a.begin(),a.end() -#define all_r(a) a.rbegin(),a.rend() - -// bool is_suffix(string a, string b) -// { -// reverse(a.begin(), a.end()); -// reverse(b.begin(), b.end()); - -// for(int i = 0; i < b.size(); i++) -// { -// if(a[i] != b[i]) -// return false; -// } - -// return true; -// } - -// bool ispalin(vector& v) -// { -// for(int i = 0; i < v.size() / 2; i++) -// { -// if(v[i] != v[v.size() - i - 1]) -// return false; -// } - -// return true; -// } - - - -int main(void) -{ - flash(); - - int t; - cin>>t; - - while(t--) - { - int n, k; - cin>>n>>k; - - vector v(n); - for(int i = 0; i < n; i++) - cin>>v[i]; - - sort(all(v)); - - vector freq = {1}; - for(int i = 1; i < n; i++) - { - if(v[i] == v[i-1]) - freq.back()++; - else - freq.push_back(1); - } - - sort(all(freq)); - - bool is = false; - for(int i = 0; i < freq.size(); i++) - { - if(freq[i] > k) - { - cout< -#define int long long -using namespace std; -mapmp; -vectornum; -int n,m,idt,x; -void solve(){ - mp.clear(); - num.clear(); - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - mp[x]++; - } - for(auto _:mp){ - num.push_back(_.second); - } - sort(num.begin(),num.end()); - bool flag=false; - int s=num.size(); - for(int i=0;i=num[i]){ - m-=num[i]; - } - else{ - printf(""%lld\n"",s-i); - flag=true; - return; - } - } - printf(""1\n""); -} -signed main(){ -#ifdef USE_FILE_IO - freopen(""code.in"",""r"",stdin); - freopen(""code.out"",""w"",stdout); -#endif - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -unordered_mapmp; -vectornum; -int n,m,idt,x; -void solve(){ - idt=0; - mp.clear(); - num.clear(); - scanf(""%lld%lld"",&n,&m); - for(int i=1;i<=n;i++){ - scanf(""%lld"",&x); - mp[x]++; - } - for(auto _:mp){ - num.push_back(_.second); - } - sort(num.begin(),num.end()); - int ans=num.size(); - for(auto i:num){ - if(m<=0)break; - if(i<=m){ - m-=i; - } - ans--; - } - printf(""%lld\n"",max(ans,1ll)); -} -signed main(){ -#ifdef USE_FILE_IO - freopen(""code.in"",""r"",stdin); - freopen(""code.out"",""w"",stdout); -#endif - int t; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",1 -Holanda2103,2057B - Gorilla and the Exam,c++17 ,306581836,306581205,"#include - -#define sz(x) (int)(x).size() -#define all(x) (x).begin(),(x).end() -#define rep(i, a, b) for (int i = a; i < (b); i++) -#define rev(i, a, b) for (int i = a; i >= (b); i--) -#define fr first -#define sc second -#define pb push_back -#define endl ""\n"" - -template inline void chmin(T& a, U b) { if (a > b) a = b; } -template inline void chmax(T& a, U b) { if (a < b) a = b; } - -using namespace std; - -typedef long long ll; -typedef pair pii; -typedef pair pll; - -//void reset() {} - -void solve_task() { - int n,k;cin >> n >> k; - vector a(n); - map cnt; - - rep(i,0,n) { - cin >> a[i]; - cnt[a[i]]++; - } - - sort(all(a),[&](int x,int y) { - if(cnt[x] == cnt[y]) return x < y; - return cnt[x] < cnt[y]; - }); - - rep(i,0,k) a[i] = a[n - 1]; - - sort(all(a)); - int ans = 1; - rep(i,1,n) ans += (a[i] != a[i - 1]); - cout << ans << endl; -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int tc = 1;cin >> tc; - while(tc--) solve_task(); - - return 0; -}","#include - -#define sz(x) (int)(x).size() -#define all(x) (x).begin(),(x).end() -#define rep(i, a, b) for (int i = a; i < (b); i++) -#define rev(i, a, b) for (int i = a; i >= (b); i--) -#define fr first -#define sc second -#define pb push_back -#define endl ""\n"" - -template inline void chmin(T& a, U b) { if (a > b) a = b; } -template inline void chmax(T& a, U b) { if (a < b) a = b; } - -using namespace std; - -typedef long long ll; -typedef pair pii; -typedef pair pll; - -//void reset() {} - -void solve_task() { - int n,k;cin >> n >> k; - vector a(n); - map cnt; - - rep(i,0,n) { - cin >> a[i]; - cnt[a[i]]++; - } - - sort(all(a),[&](int x,int y) { - return cnt[x] <= cnt[y]; - }); - - rep(i,0,k) { - cnt[a[i]]--; - a[i] = a[n - 1]; - cnt[a[i]]++; - } - - sort(all(a)); - int ans = 1; - rep(i,1,n) ans += (a[i] != a[i - 1]); - cout << ans << endl; -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int tc = 1;cin >> tc; - while(tc--) solve_task(); - - return 0; -}",1 -xuhaoy,2057B - Gorilla and the Exam,c++23 ,305387898,305387091,"#include - -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t, n, k; - cin >> t; - while (t--) { - cin >> n >> k; - vector nums(n); - for (int &i: nums) { - cin >> i; - } - if (k > n - 1) { - cout << 1 << endl; - continue; - } - sort(nums.begin(), nums.end()); - vector cnt{1}; - int ans = 0; - for (int i = 1; i < n; ++i) { - if (nums[i] == nums[i - 1]) { - ++cnt.back(); - } else { - cnt.emplace_back(1); - } - } - sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - for (int i = 0; i < m - 1; ++i) { - if (cnt[i] > k) { - ans = m - i; - break; - } - k -= cnt[i]; - } - cout << max(ans, 1) << endl; - } -} -","#include - -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t, n, k; - cin >> t; - while (t--) { - cin >> n >> k; - unordered_map nums; - int num; - for (int i = 0; i < n; ++i) { - cin >> num; - ++nums[num]; - } - if (k > n - 1) { - cout << 1 << endl; - continue; - } - vector> data; - for (auto &[k, v]: nums) { - data.push_back({v, k}); - } - sort(data.begin(), data.end()); - int ans = data.size(); - for (int i = 0; i < data.size(); ++i) { - if (k < 1) break; - int sub = min(data[i][0], k); - data[i][0] -= sub; - if (data[i][0] == 0) { - --ans; - k -= sub; - } else { - break; - } - } - cout << max(ans, 1) << endl; - } -} -",1 -Sobolanu303,2057B - Gorilla and the Exam,c++20 ,301160179,301159735,"#include -#define all(x) x.begin(), x.end() -typedef unsigned long long ull; - -/* -stole from editorial, my intuition was correct about it being -""base state of ans is the num of unique elements, to get minimum value of f(a) we reduce -the number of unique elements"", just that my implementation was incorrect. -*/ - -int main() -{ - std::ios::sync_with_stdio(false); std::cin.tie(0); - - int t{}; - std::cin >> t; - while (t--) - { - int n{}, k{}; - std::cin >> n >> k; - - std::vector v(n); - for(auto& x : v) std::cin >> x; - - std::sort(all(v)); - std::vector cnt = {1}; - for (int i = 1; i < n; i++) - { - if (v[i] == v[i - 1]) - cnt.back()++; - else - cnt.emplace_back(1); - } - std::sort(all(cnt)); - int m = cnt.size(); bool chk{false}; - for (int i = 0; i < m - 1; i++) - { - if (cnt[i] > k) - { - std::cout << m - i << ""\n""; - chk = true; - break; - } - k -= cnt[i]; - } - if(!chk) - std::cout << 1 << ""\n""; - } -} -","#include -#define all(x) x.begin(), x.end() -typedef unsigned long long ull; - -int main() -{ - std::ios::sync_with_stdio(false); std::cin.tie(0); - - int t{}; - std::cin >> t; - while (t--) - { - int n{}, k{}; - std::cin >> n >> k; - - std::vector v(n); - for(auto& x : v) std::cin >> x; - - std::map cnt{}; - for (int num : v) - cnt[num]++; - - int ans = std::set(all(v)).size(); - std::vector> pairs(cnt.begin(), cnt.end()); - std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b) - { - return a.second < b.second; - }); - - for(int i = 0; i < pairs.size(); i++) - { - if(k <= 0) - break; - else - { - ans--; - k -= pairs[i].second; - } - } - - if(ans == 0) - std::cout << 1 << '\n'; - else - std::cout << ans << '\n'; - } -} -",1 -user_is_dead,2057B - Gorilla and the Exam,c++23 ,306793495,306793712,"#include -using namespace std; - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - auto __solve=[&](int test){ - int n,k; - cin>>n>>k; - map mp; - for(int i=0;i>x; - mp[x]++; - } - int size=mp.size(); - if(k>=n){ - cout<<1<<'\n'; - return; - } - vector v(size); - int ind=0,cnt=0; - for(auto it:mp){ - v[ind]=it.second; - ind++; - } - sort(v.begin(),v.end()); - for(int i=0;i=v[i]){ - k-=v[i]; - cnt++; - } - else{ - break; - } - } - - cout<>t; - while(t--){ - __solve(t); - } - return 0; -} -","#include -using namespace std; - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - auto __solve=[&](int test){ - int n,k; - cin>>n>>k; - map mp; - for(int i=0;i>x; - mp[x]++; - } - - if(k>=n){ - cout<<1<<'\n'; - return; - } - int ans=0; - for(auto &it:mp){ - ans+=(it.second+1)/2; - } - - ans-=k; - cout<>t; - while(t--){ - __solve(t); - } - return 0; -}",2 -yuechen,2057B - Gorilla and the Exam,c++20 ,304724888,304722275,"#include // Hello 2025 B -#include -#include -#include -#include -#define ll long long -using namespace std; - -void solve() { - int n, k; - cin >> n >> k; - vector a; - map mp; - for (int i = 0; i < n; i++) { - int num; - cin >> num; - mp[num]++; - } - for (auto i : mp) { - a.push_back(i.second); - } - sort(a.begin(), a.end()); - int ans = a.size(); - int l = 0, r = a.size() - 1; - while (k > 0 && l < r) { - if (a[l] <= a[r]) { - k -= a[l]; - l++, ans--; - } - else { - k -= a[r]; - r--, ans--; - } - } - if (k < 0) ans++; - cout << ans << endl; -} - -int main() -{ - int t; - cin >> t; - while (t--) - solve(); - - return 0; -}","#include // Hello 2025 B -#include -#include -#include -#define ll long long -using namespace std; - -void solve() { - int n, k; - cin >> n >> k; - vector a; - map mp; - for (int i = 0; i < n; i++) { - int num; - cin >> num; - mp[num]++; - } - for (auto i : mp) { - a.push_back(i.second); - } - int ans = a.size(); - int l = 0, r = a.size() - 1; - while (k > 0 && l < r) { - if (a[l] <= a[r]) { - k -= a[l]; - l++, ans--; - } - else { - k -= a[r]; - r--, ans--; - } - } - if (k < 0) ans++; - cout << ans << endl; -} - -int main() -{ - int t; - cin >> t; - while (t--) - solve(); - - return 0; -}",1 -zhentaozhang4,2057B - Gorilla and the Exam,c++17 ,301069991,301074768,"#include -using namespace std; - -int assign_smallest_to_largest(vector> &lis, int k){ - int i = 0; - int current_most = lis.back().first; - int cnt = 0; - // cout << ""current_most ""< 0){ - cnt++; - } - } - return cnt; -} - -int main(){ - int t, n, k; - cin >> t; - unordered_map m; - for(int i = 0; i < t; i++){ - cin >> n >> k; - for(int j = 0; j < n; j++){ - int x; - cin >> x; - m[x]++; - } - // cout << ""msize: ""<> lis(m.begin(), m.end()); - for (auto i = m.begin(); i != m.end(); i++) - { - lis.push_back(make_pair(i->first, i->second)); - // cout << ""data pushed: ""<first << "" "" << i->second << endl; - } - // cout << ""data size: ""< &a, const pair &b){ - return a.second < b.second; - }); - - cout << assign_smallest_to_largest(lis, k) << endl; - m.clear(); - } - - - - return 0; -}","#include -using namespace std; - -int assign_smallest_to_largest(vector> &lis, int k, int n){ - int i = 0; - int current_most = lis.back().first; - int cnt = 0; - // cout << ""current_most ""< 0){ - cnt++; - } - } - return cnt; -} - -map m; -vector> lis; -int main(){ - ios::sync_with_stdio(false); // 取消同步流 - cin.tie(0); // 解绑cin与cout - cout.tie(0); // 解绑cout与cin - int t, n, k; - cin >> t; - - for(int i = 0; i < t; i++){ - cin >> n >> k; - for(int j = 0; j < n; j++){ - int x; - cin >> x; - m[x]++; - } - // cout << ""msize: ""<first, i->second)); - //cout << ""data pushed: ""<first << "" "" << i->second << endl; - } - // cout << ""data size: ""< &a, const pair &b){ - return a.second < b.second; - }); - - cout << assign_smallest_to_largest(lis, k, n) << endl; - // cout << ""lis size"" << lis.size() << endl; - m.clear(); - } - - - - return 0; -}",2 -JXIANG,2057B - Gorilla and the Exam,c++17 ,301174902,301176317,"#include -using namespace std; -typedef pair PII; - -bool cmp(PII &a, PII &b) -{ - return a.second < b.second; -} - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n, k; - cin >> n >> k; - unordered_map _map; - for (int i = 1; i <= n; i++) - { - int key; - cin >> key; - _map[key]++; - } - vector vec(_map.begin(), _map.end()); - sort(vec.begin(), vec.end(), cmp); - int sum = vec[0].second, step = vec.size(), index = 1; - while (sum <= k && step > 1) - { - step--; - sum += vec[index++].second; - } - cout << step << endl; - } -}","#include -using namespace std; -typedef pair PII; - -bool cmp(PII &a, PII &b) -{ - return a.second < b.second; -} - -int main() -{ - int t; - cin >> t; - - while (t--) - { - int n, k; - cin >> n >> k; - map _map; - for (int i = 1; i <= n; i++) - { - int key; - cin >> key; - _map[key]++; - } - vector vec(_map.begin(), _map.end()); - sort(vec.begin(), vec.end(), cmp); - int sum = vec[0].second, step = vec.size(), index = 1; - while (sum <= k && step > 1) - { - step--; - sum += vec[index++].second; - } - cout << step << endl; - } -}",2 -biekanwo,2057B - Gorilla and the Exam,c++17 ,304863761,304866230,"#include -#define int long long -using namespace std; -const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7; -/*int primes[N];bool st[N];int cnt=0; -void getpri(int n) -{ - for(int i=2;i<=n; i++) - { - if(!st[i]) primes[cnt++] = i; - for(int j=0; primes[j] <= n/i; j++) - { - st[primes[j]*i]=true; - if(i%primes[j]==0) break; - } - } -}*/ -int qsm(int n,int m)/*n^m*/ -{ - int res=1; - while(m) - { - if(m&1) - res=res*n%mod; - n=n*n%mod; - m>>=1; - } - return res; -} -mapmp,mpp; -void solve() -{ - mp.clear(); - int n,k; - cin>>n>>k; - if(n==k){cout<<1<s; - setp; - for(int i=0;i>a[i]; - if(mp[a[i]]==0)cnt++,p.insert(a[i]); - mp[a[i]]++; - - }//求种类数; - - for(auto l=p.begin();l!=p.end();l++) - { - s.push_back(mp[*l]); - }//把元素个数取出来 - - sort(s.begin(),s.end());//排序 - - for(int i=0;i=s[i])k-=s[i],cnt--; - } - cout<>T; - while(T--) - { - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -const int N = 2e5 + 10,INF=0x3f3f3f3f,mod= 1e9 + 7; -/*int primes[N];bool st[N];int cnt=0; -void getpri(int n) -{ - for(int i=2;i<=n; i++) - { - if(!st[i]) primes[cnt++] = i; - for(int j=0; primes[j] <= n/i; j++) - { - st[primes[j]*i]=true; - if(i%primes[j]==0) break; - } - } -}*/ -int qsm(int n,int m)/*n^m*/ -{ - int res=1; - while(m) - { - if(m&1) - res=res*n%mod; - n=n*n%mod; - m>>=1; - } - return res; -} -mapmp,mpp; -void solve() -{ - mp.clear(); - int n,k; - cin>>n>>k; - int cnt=0; - int a[N] = {0}; - vectorp; - for(int i=0;i>a[i]; - if(mp[a[i]]==0)cnt++; - mp[a[i]]++; - - }//求种类数; - - for(auto x:mp) - { - p.push_back(x.second); - }//取出来种类数; - - sort(p.begin(),p.end()); - - for(int i=0;i=p[i])k-=p[i],cnt--; - } - cout<>T; - while(T--) - { - solve(); - } - return 0; -}",2 -BandoTesting,2057B - Gorilla and the Exam,python,301652773,301653588,"if __name__ == ""__main__"": - tc = 0 - tc = int(input()) - lres = [] - for i in range(tc): - nkRaw = input() - n = int(nkRaw.split("" "")[0]) - k = int(nkRaw.split("" "")[1]) - minimum = 0 - maximum = 1 - arrayRaw = input() - array = arrayRaw.split("" "") - diccionario = {} - for num in range(int(n)): - if(array[num] not in diccionario): - diccionario[array[num]] = 1 - else: - diccionario[array[num]] += 1; - if(k >= len(diccionario)): - lres.append(1) - break - else: - sorted(diccionario.values()) - lista_diccionario = diccionario.values() - aux = 0 - for num in lista_diccionario: - if(num <= k): - k -= num - aux += 1 - lres.append(len(lista_diccionario) - aux) - for res in lres: - print(res) - - - -# end main","if __name__ == ""__main__"": - tc = 0 - tc = int(input()) - lres = [] - for i in range(tc): - nkRaw = input() - n = int(nkRaw.split("" "")[0]) - k = int(nkRaw.split("" "")[1]) - minimum = 0 - maximum = 1 - arrayRaw = input() - array = arrayRaw.split("" "") - diccionario = {} - for num in range(int(n)): - if(array[num] not in diccionario): - diccionario[array[num]] = 1 - else: - diccionario[array[num]] += 1; - if(k >= n): - lres.append(1) - else: - lista_diccionario = sorted(diccionario.values()) - aux = 0 - for num in lista_diccionario: - if(num <= k): - k -= num - aux += 1 - else: - break - lres.append(len(lista_diccionario) - aux) - for res in lres: - print(res) -#end",2 -Kartavya_Suryawanshi,2057B - Gorilla and the Exam,c++17 ,306105853,306103477,"#include -using namespace std; - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - int n, k; - cin >> n >> k; - map freq; - - // Count occurrences - for (int i = 0; i < n; i++) { - int temp; - cin >> temp; - freq[temp]++; - } - - // Extract frequencies and sort them - vector counts; - for (auto &[num, count] : freq) { - counts.push_back(count); - } - sort(counts.begin(), counts.end()); - - int ans = counts.size(); - int i = 0; - - // Greedily remove smallest frequency elements - while (i < counts.size() && k >= counts[i]) { - k -= counts[i]; - ans--; - i++; - } - - cout << max(1, ans) << ""\n""; - } - return 0; -}","#include -using namespace std; - -int main() { - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - int ans=0; - unordered_map m; - for(int i=0;i>temp; - m[temp]+=1; - } - vector v; - for(auto i:m){ - v.push_back(i.second); - } - sort(v.begin(),v.end()); - ans=v.size(); - for(auto i:v){ - cout< - -using namespace std; - -int f(vector& b) { - int n = b.size(); - if (n == 0) return 0; - - vector dp(n + 1, INT_MAX); - dp[0] = 0; - - for (int i = 1; i <= n; ++i) { - int min_val = INT_MAX; - for (int j = i; j > 0; --j) { - min_val = min(min_val, b[j - 1]); - dp[i] = min(dp[i], dp[j - 1] + 1); - } - } - - return dp[n]; -} - -int main() { - int t; - cin >> t; - for(int i = 0; i < t; i++) { - int n; - cin >> n; - int k; - cin >> k; - vector a; - for (int j = 0; j < n; ++j) { - int x; - cin >> x; - a.push_back(x); - } - - // Example usage of f(b) - cout << f(a) << endl;} - - return 0; -}","#include -using namespace std; - -void solve() { - int t; - cin >> t; - while (t--) { - int n, k; - cin >> n >> k; - vector a(n); - map freq; - - for (int i = 0; i < n; ++i) { - cin >> a[i]; - freq[a[i]]++; - } - - if (n == k) { - // If n == k, we can include all elements - cout << 1 << endl; - continue; - } - - vector counts; - for (const auto& pair : freq) { - counts.push_back(pair.second); - } - - sort(counts.begin(), counts.end()); - - int removable = 0; - int total = 0; - for (int count : counts) { - if (total + count <= k) { - total += count; - removable++; - } else { - break; - } - } - - int result = freq.size() - removable; - cout << result << endl; - } -} - -int main() { - solve(); - return 0; -} -",2 -CSK_13,2057B - Gorilla and the Exam,c++17 ,301381159,301387164,"#include -using namespace std; -int main() { - int t;cin >> t; - while(t--){ - int n;cin >> n; - int k;cin >> k; - vector v(n); - unordered_map m; - for(int i=0;i> v[i]; - m[v[i]]++; - } - vector a; - for(auto m:m){ - a.push_back(m.second); - } - sort(a.begin(),a.end()); - int count=0; - for(int i=0;i -using namespace std; - -void solve() { - int n, k; - cin >> n >> k; - vector v(n); - for (int i = 0; i < n; i++) { - cin >> v[i]; - } - sort(v.begin(), v.end()); - vector cnt = {1}; - for (int i = 1; i < n; i++) { - if (v[i] == v[i - 1]) { - cnt.back()++; - } else { - cnt.push_back(1); - } - } - sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt[i] > k) { - cout << m - i << ""\n""; - return; - } - k -= cnt[i]; - } - cout << 1 << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",2 -smas,2057B - Gorilla and the Exam,c++23 ,301102924,301102678,"#include - -using namespace std; - -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned; -using u128 = unsigned __int128; - -void solve() { - int n, k; - cin >> n >> k; - - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - - map freqMap; - for (int i = 0; i < n; ++i) { - freqMap[a[i]]++; - } - - vector > freq(freqMap.begin(), freqMap.end()); - sort(freq.begin(), freq.end(), [](const auto &left, const auto &right) { - return left.second < right.second; - }); - - int ans = freq.size(); - for (const auto &[_, count]: freq) { - if (k == 0) break; - if (count <= k) { - k -= count; - --ans; - } - } - - if (ans == 0) ++ans; - - cout << ans << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -","#include - -using namespace std; - -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned; -using u128 = unsigned __int128; - -void solve() { - int n, k; - cin >> n >> k; - - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - - unordered_map freqMap; - for (int i = 0; i < n; ++i) { - freqMap[a[i]]++; - } - - vector > freq(freqMap.begin(), freqMap.end()); - sort(freq.begin(), freq.end(), [](const auto &left, const auto &right) { - return left.second < right.second; - }); - - int ans = freq.size(); - for (const auto &[_, count]: freq) { - if (k == 0) break; - if (count <= k) { - k -= count; - --ans; - } - } - - if (ans == 0) ++ans; - - cout << ans << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -",1 -Ronaldo_by,2057B - Gorilla and the Exam,c++20 ,300770129,300769957,"#include -using namespace std; -int main(){ - - int t ; - cin>>t; - while(t--) - { - int n ,k; - cin>>n>>k; - int temp ; - mapmp; - for(int i= 0 ; i>temp; - mp[temp]++; - } - - vectorv; - for(auto it : mp) - v.push_back(it.second); - sort(v.begin(),v.end()); - int ans = v.size(); - - for(int i = 0 ; i -using namespace std; -int main(){ - - int t ; - cin>>t; - while(t--) - { - int n ,k; - cin>>n>>k; - int temp ; - mapmp; - for(int i= 0 ; i>temp; - mp[temp]++; - } - - vectorv; - for(auto &it : mp) - v.push_back(it.second); - sort(begin(v),end(v)); - int ans = v.size(); - - for(int i = 0 ; i -#include -#include -#include -using namespace std; - -int main(){ - std::ios_base::sync_with_stdio(false); - std::cin.tie(nullptr); - int c; cin >> c; - while(c--){ - int n, k; - cin >> n >> k; - vector arr; - for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);} - // put into groups that can be removed together - // minimize groups - // groups are contigous seperated by lower numbers - // for each number store group (what information about the group. indexes? l and r of range. ) - // we need to store the amount of members of each group, and an arr of the locations (and thus the range) - vector numArr; - unordered_map numNums; - for (int i : arr){ - if (numNums.count(i)) { - (numNums[i] += 1); - } else { - numNums[i] = 1; - numArr.push_back(i); - - - } - } - vector amtNums; - for (int i : numArr){amtNums.push_back(numNums[i]);} - sort(amtNums.begin(), amtNums.end()); - int groupsRmed = 0; - for (int i : amtNums){ - k -= i; - if (k < 0){ - break; - } else { - groupsRmed++; - - - } - } - int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1; - cout << res << ""\n""; - - - - - - - - - } -} -","#include -#include -#include -#include -using namespace std; - -int main(){ - std::ios_base::sync_with_stdio(false); - std::cin.tie(nullptr); - int c; cin >> c; - while(c--){ - int n, k; - cin >> n >> k; - vector arr; - for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);} - - - sort(arr.begin(), arr.end()); - // apearances, num - vector> numUnique; - int currApperances = 0; - int last = arr[0]; - for (int i : arr){ - if (i == last){ - currApperances++; - } else { - numUnique.emplace_back(currApperances, last); - currApperances = 1; - last = i; - } - } - numUnique.emplace_back(currApperances, last); - - sort(numUnique.begin(), numUnique.end()); - int removals = 0; - for (pair i : numUnique){ - k -= i.first; - if (k < 0){ - break; - } - else{ - removals++; - } - } - int res = (size(numUnique) - removals != 0) ? size(numUnique) - removals : 1; - cout << res << ""\n""; - - - - } -} -",2 -oguzhesenli94,2057B - Gorilla and the Exam,c++20 ,301154660,301154886,"#include -using namespace std; -bool comp(paira,pairb){ - if(a.second>t; - while(t--){ - int n,k; - cin>>n>>k; - int l[n]; - vector>m; - for(int i=0;i>l[i]; - } - sort(l,l+n); - int say=1; - for(int i=1;i<=n;i++){ - if(l[i]==l[i-1]){ - say++; - } - else{ - m.push_back({l[i-1],say}); - say=1; - } - - } - - sort(m.begin(),m.end(),comp); - for(auto& p:m){ - if(k==0){ - break; - } - if(k>=p.second){ - k-=p.second; - p.second=0; - - } - else{ - p.second-=k; - k=0; - break; - } - } - int cvb=0; - for(pairp:m){ - // cout< -using namespace std; -bool comp(paira,pairb){ - if(a.second>t; - while(t--){ - int n,k; - cin>>n>>k; - int l[n]; - vector>m; - for(int i=0;i>l[i]; - } - sort(l,l+n); - int say=1; - for(int i=1;i=p.second){ - k-=p.second; - p.second=0; - - } - else{ - p.second-=k; - k=0; - break; - } - } - int cvb=0; - for(pairp:m){ - // cout< -using namespace std; -int main() { - int t;cin >> t; - while(t--){ - int n;cin >> n; - int k;cin >> k; - vector v(n); - unordered_map m; - for(int i=0;i> v[i]; - m[v[i]]++; - } - vector a; - for(auto m:m){ - a.push_back(m.second); - } - sort(a.begin(),a.end()); - int flag=0; - for(int i=0;i -using namespace std; - -void solve() { - int n, k; - cin >> n >> k; - vector v(n); - for (int i = 0; i < n; i++) { - cin >> v[i]; - } - sort(v.begin(), v.end()); - vector cnt = {1}; - for (int i = 1; i < n; i++) { - if (v[i] == v[i - 1]) { - cnt.back()++; - } else { - cnt.push_back(1); - } - } - sort(cnt.begin(), cnt.end()); - int m = cnt.size(); - for (int i = 0; i < m - 1; i++) { - if (cnt[i] > k) { - cout << m - i << ""\n""; - return; - } - k -= cnt[i]; - } - cout << 1 << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",2 -Naitikshah,2057B - Gorilla and the Exam,python,301317398,301285562,"n = int(input()) -for _ in range(n): - m, k = map(int, input().split()) - arr = list(map(int, input().split())) - arr.sort() - freqencies = list() - count = 0 - prev = arr[0] - for i in arr: - if i == prev: - count+=1 - else: - prev = i - freqencies.append(count) - count = 1 - freqencies.append(count) - freqencies.sort(reverse=True) - remove = 0 - # print(freqencies, k) - while len(freqencies) > 1 and remove + freqencies[-1] <= k: - remove += freqencies.pop() - print(len(freqencies)) -","n = int(input()) -for _ in range(n): - m, k = map(int, input().split()) - arr = list(map(int, input().split())) - from collections import Counter - freqencies = sorted(Counter(arr).values(), reverse=True) - remove = 0 - # print(freqencies, k) - while len(freqencies) > 1 and remove + freqencies[-1] <= k: - remove += freqencies.pop() - print(len(freqencies)) -",1 -MOH_LazyCoder_HSN,2057B - Gorilla and the Exam,c++20 ,301598312,301597412,"/** - - * بسم الله الرحمن الرحيم * - - ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿ - -**/ -#include -#define ll long long -#define fi(l, r) for(ll i=l;i=l;i--) -#define fjr(r, l) for(ll j=r;j>=l;j--) -#define all(x) (x).begin(), (x).end() -#define vi vector -#define vll vector -#define vllll vector -#define vpll vector> -#define vb vector -#define pd push_back -using namespace std; - -void solving(){ - ll n,k; cin>>n>>k; - ll a[n]; - map mp; - fi(0,n) { - cin >> a[i]; - mp[a[i]]++; - } - vll counts; - for(auto e:mp ){ - counts.push_back(e.second); - } - sort(all(counts)); - ll e1=0; - ll e2=counts.size()-1; - ll res=counts.size(); - while(e1>n; - while(n--) solving(); -}","/** - - * بسم الله الرحمن الرحيم * - - ﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿ - -**/ -#include -#define ll long long -#define fi(l, r) for(ll i=l;i=l;i--) -#define fjr(r, l) for(ll j=r;j>=l;j--) -#define all(x) (x).begin(), (x).end() -#define vi vector -#define vll vector -#define vllll vector -#define vpll vector> -#define vb vector -#define pd push_back -using namespace std; - -void solving(){ - ll n,k; cin>>n>>k; - ll a[n]; - unordered_map mp; - fi(0,n) { - cin >> a[i]; - mp[a[i]]++; - } - vll counts; - for(auto e:mp ){ - counts.push_back(e.second); - } - sort(all(counts)); - ll e1=0; - ll e2=counts.size()-1; - ll res=counts.size(); - while(e1>n; - while(n--) solving(); -}",1 -swastika07,2057B - Gorilla and the Exam,c++17 ,301118179,301113863,"#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - vectora(n); - mapmapping; - for(int i=0;i>a[i]; - mapping[a[i]]++; - } - vectorfreq; - for(auto i:mapping){ - freq.push_back(i.second); - } - - sort(freq.begin(),freq.end()); - for(int i=0;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n,k; - cin>>n>>k; - mapmapping; - for(int i=0;i>x; - mapping[x]++; - } - int maxi=INT_MIN; - int key=-1; - for(auto i:mapping){ - if(i.second>maxi){ - maxi=i.second; - key=i.first; - } - } - int count=0; - for(auto &i:mapping){ - if(i.first!=key&&i.second<=k){ - int x=i.second; - i.second=0; - k=k-x; - mapping[key]+=x; - - }else if(i.first!=key&&i.second>k){ - mapping[key]+=k; - i.second=i.second-k; - k=0; - } - if(k==0){ - break; - } - } - for(auto i:mapping){ - if(i.second!=0){ - count++; - } - } - cout< -using namespace std; - - -#define md : 1000000007; - - - -void solve(){ - int n,k; - cin >> n >> k; - - vector vec(n); - - unordered_map mp; - vectorcount = {1}; - - for(int i=0; i> vec[i]; - mp[vec[i]]++; - } - - sort(vec.begin(),vec.end()); - for(int i=1; i k) break; - k-=count[i++]; - if(k == 0) break; - } - - int res = count.size()-i != 0 ? count.size()-i : 1; - - cout << res << endl; - // priority_queue, vector>, greater<> > st; - - // for(auto x: mp){ - // st.push({x.second, x.first}); - // } - - // int count = 0; - - // while(!st.empty() && k){ - // int temp = (st.top()).first; - // if(temp > k) k = 0; - // else{ - // k-=temp; - // st.pop(); - // } - // } - - // st.size() > 0 ? cout << st.size() : cout << 1 ; - // cout << endl; - - -} - - - - -int main(){ - - int t; - cin>>t; - - - while(t--) - solve(); - - return 0; -}","#include -using namespace std; - - -#define md : 1000000007; - - - -void solve(){ - int n,k; - cin >> n >> k; - - vector vec(n); - vectorcount = {1}; - - for(int i=0; i> vec[i]; - } - - sort(vec.begin(),vec.end()); - for(int i=1; i k) break; - k-=count[i++]; - } - - cout << m-i << endl; - // priority_queue, vector>, greater<> > st; - - // for(auto x: mp){ - // st.push({x.second, x.first}); - // } - - // int count = 0; - - // while(!st.empty() && k){ - // int temp = (st.top()).first; - // if(temp > k) k = 0; - // else{ - // k-=temp; - // st.pop(); - // } - // } - - // st.size() > 0 ? cout << st.size() : cout << 1 ; - // cout << endl; - - -} - - - - -int main(){ - - int t; - cin>>t; - - - while(t--) - solve(); - - return 0; -}",2 -veyis_112,2057B - Gorilla and the Exam,c++17 ,306040279,306040477,"#include -using namespace std; -using ll=long long; -int d[1000001]; -int maks=1000001; -int main() -{ - ll t; - cin>>t; - while(t--) - { - ll n,k; - cin>>n>>k; - ll a[n]; - vectorv; - for(ll i=0;i>a[i]; - } - sort(a,a+n); - ll say=1; - for(ll i=0;i=1) - sa++; - } - cout< -using namespace std; -using ll=long long; -int d[1000001]; -int maks=1000001; -int main() -{ - ll t; - cin>>t; - while(t--) - { - ll n,k; - cin>>n>>k; - ll a[n]; - vectorv; - for(ll i=0;i>a[i]; - } - sort(a,a+n); - ll say=1; - for(ll i=0;i=1) - sa++; - } - if(sa!=0) - cout<r): - a=i - break - - num=1<<(a-1) - rbin=bin(r)[2:] - - - - # i=a-2 - # while(num-1r): - # num+=(1<=l and num!=r): - o=1 - break - - elif(num-2>=l): - o=2 - break - - if(o==1): - out=[num-1,num,num+1] - else: - out=[num-2,num-1,num] - print(*out) - - - - - - - - - -"," -import sys,random,bisect,math -from collections import deque,defaultdict -from heapq import heapify,heappop,heappush -from itertools import permutations - -input = lambda :sys.stdin.readline().rstrip() -mi = lambda :map(int,input().split()) -li = lambda :list(mi()) - -for _ in range(int(input())): - l,r=mi() - a=-1 - for i in range(31): - if(1<r): - a=i - break - - num=1<<(a-1) - - if(num>l and num<=r): - # if(num==r): - # out=[num,num-1,num-2] - # elif(num==l+1): - # out=[l,l+1,l+2] - if(num==l+1): - out=[l,l+1,l+2] - else: - out=[num,num-1,num-2] - else: - out=[r,r-1,r-2] - print(*out) - - - - - -",1 -Krish_P03,2057C - Trip to the Olympiad,c++17 ,301118735,301127427,"#include -//#include -//#include -//#include -//using namespace __gnu_pbds; -using namespace std; -#define ull unsigned long long -#define ll long long -#define f(i,a,b) for(ll i=a;i=b;i--) -#define all(v) v.begin(), v.end() -#define vec vector -#define pb push_back -#define Raftaar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define MEX LONG_LONG_MAX -//typedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_set; -/* - - -*/ - - - -void solve(){ - ll l,r; - cin>>l>>r; - ll a = l; - ll b = r; - - ll c=0; - rf(i,30,0){ - ll mask=(1<r){ - if(l==r){ - c=l; - } - else{ - c=l+1; - } - } - cout<>t; - while(t--){ - solve(); - } - return 0; -} -","#include -//#include -//#include -//#include -//using namespace __gnu_pbds; -using namespace std; -#define ull unsigned long long -#define ll long long -#define f(i,a,b) for(ll i=a;i=b;i--) -#define all(v) v.begin(), v.end() -#define vec vector -#define pb push_back -#define Raftaar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define MEX LONG_LONG_MAX -//typedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_set; -/* - - -*/ - - - -void solve(){ - ll l,r; - cin>>l>>r; - ll prev=0; - ll a,b,c; - rf(i,30,0){ - ll p=0,q=0; - if(l & (1ll<>t; - while(t--){ - solve(); - } - return 0; -} -",2 -Absurdist_,2057C - Trip to the Olympiad,c++23 ,306873034,306873814,"//#pragma GCC optimize(""Ofast"") -//#pragma GCC optimize(""Ofast,no-stack-protector,unroll-loops,fast-math"") -//#pragma GCC target(""sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native"") -#include -using namespace std; -#define int long long -#define double long double -const int N=2e5+7; - -void solved(){ - int l,r;cin>>l>>r; - int flag=0; - int a=0,b=0,c=0; - for(int i=30;i>=0;i--){ - int x=(l>>i)&1; - int y=(r>>i)&1; - int t=(1ll<>_; - while(_--)solved(); -} -","//#pragma GCC optimize(""Ofast"") -//#pragma GCC optimize(""Ofast,no-stack-protector,unroll-loops,fast-math"") -//#pragma GCC target(""sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native"") -#include -using namespace std; -#define int long long -#define double long double -const int N=2e5+7; - -void solved(){ - int l,r;cin>>l>>r; - int flag=0; - int a=0,b=0,c=0; - for(int i=30;i>=0;i--){ - int x=(l>>i)&1; - int y=(r>>i)&1; - int t=(1ll<>_; - while(_--)solved(); -} -",2 -rehack,2057C - Trip to the Olympiad,other,300247325,300289364,"use std::io; - -fn main() { - // Read the number of test cases - let mut input = String::new(); - io::stdin() - .read_line(&mut input) - .expect(""Failed to read line""); - let t: usize = input - .trim() - .parse() - .expect(""Failed to parse number of test cases""); - - // Initialize a vector to hold the test cases - let mut test_cases = Vec::new(); - - // Read each test case - for _ in 0..t { - input.clear(); - io::stdin() - .read_line(&mut input) - .expect(""Failed to read line""); - let nums: Vec = input - .trim() - .split_whitespace() - .map(|x| x.parse().expect(""Failed to parse number"")) - .collect(); - - if nums.len() == 2 { - test_cases.push((nums[0], nums[1])); - } else { - panic!(""Each test case must contain exactly two numbers""); - } - } - - // Process each test case - for (l, r) in test_cases { - // Replace this with your desired processing logic - //println!(""Processing range: {} to {}"", l, r); - - /* - let l_bin = to_binary(l); - let r_bin = to_binary(r); - println!(""The binary representation of {} is {}"", l, l_bin); - println!(""The binary representation of {} is {}"", r, r_bin); - let mut diff: u32 = r - l; - let diff_bin = to_binary(diff); - println!(""The binary representation of {} is {}"", diff, diff_bin); - */ - - let (mut pow2_bin, mut pow2) = max_power_of_2(l); - //println!(""pow2: {}, pow2_bin: {}"", pow2, pow2_bin); - - let upper = r - pow2; - let lower = l - pow2; - //println!(""lower: {}, upper: {}"", lower, upper); - let up_bin = to_binary(upper); - - //println!(""upper: {} upper bin: {}"", upper, up_bin); - - let inv_bin = invert_bits(&up_bin); - //println!(""The inverted binary is {}"", inv_bin); - let mut inv = binary_to_u32(&inv_bin).unwrap(); - //println!(""inv: {}"", inv); - - let mut c: u32 = pow2 + inv; - if inv == 0 { - c = l + 1; - } - - println!(""{} {} {}"", l, c, r); - //println!(""------""); - } -} - -fn to_binary(n: u32) -> String { - format!(""{:b}"", n) -} - -fn invert_bits(binary: &str) -> String { - binary - .chars() - .map(|c| if c == '0' { '1' } else { '0' }) - .collect() -} - -fn binary_to_u32(binary: &str) -> Option { - u32::from_str_radix(binary, 2).ok() -} - -fn max_power_of_2(l: u32) -> (String, u32) { - if l == 0 { - return (""0"".to_string(), 0); - } - - // Find the largest power of 2 less than or equal to l - let pow2 = 1 << (31 - l.leading_zeros()); - - // Convert the value to a binary string - let binary_representation = format!(""{:b}"", pow2); - - // Return the binary string and u32 value - (binary_representation, pow2) -} -","use std::io; - -fn main() { - // Read the number of test cases - let mut input = String::new(); - io::stdin() - .read_line(&mut input) - .expect(""Failed to read line""); - let t: usize = input - .trim() - .parse() - .expect(""Failed to parse number of test cases""); - - // Initialize a vector to hold the test cases - let mut test_cases = Vec::new(); - - // Read each test case - for _ in 0..t { - input.clear(); - io::stdin() - .read_line(&mut input) - .expect(""Failed to read line""); - let nums: Vec = input - .trim() - .split_whitespace() - .map(|x| x.parse().expect(""Failed to parse number"")) - .collect(); - - if nums.len() == 2 { - test_cases.push((nums[0], nums[1])); - } else { - panic!(""Each test case must contain exactly two numbers""); - } - } - - // Process each test case - for (l, r) in test_cases { - // Replace this with your desired processing logic - //println!(""Processing range: {} to {}"", l, r); - - /* - Attempt 1 - let l_bin = to_binary(l); - let r_bin = to_binary(r); - println!(""The binary representation of {} is {}"", l, l_bin); - println!(""The binary representation of {} is {}"", r, r_bin); - let mut diff: u32 = r - l; - let diff_bin = to_binary(diff); - println!(""The binary representation of {} is {}"", diff, diff_bin); - */ - - /* - Attempt 2 - - let (mut pow2_bin, mut pow2) = max_power_of_2(l); - //println!(""pow2: {}, pow2_bin: {}"", pow2, pow2_bin); - - let (_, pow2r) = max_power_of_2(r); - if pow2 < pow2r { - pow2 = l; - } - - let upper = r - pow2; - let lower = l - pow2; - //println!(""lower: {}, upper: {}"", lower, upper); - let up_bin = to_binary(upper); - - //println!(""upper: {} upper bin: {}"", upper, up_bin); - - let inv_bin = invert_bits(&up_bin); - //println!(""The inverted binary is {}"", inv_bin); - let mut inv = binary_to_u32(&inv_bin).unwrap(); - //println!(""inv: {}"", inv); - - let mut c: u32 = pow2 + inv; - if inv == 0 { - c = l + 1; - } - */ - - /* - Attempt 3. After reading editorial - I kind of had that insight (two insights), but could not connect the two - */ - - let mut l_bin = to_binary(l); - let r_bin = to_binary(r); - - // make it same length to compare - l_bin = pad_binary(&l_bin, &r_bin); - //println!(""l_bin: {}, r_bin: {}"", l_bin, r_bin); - - let n = l_bin.len(); - let mut k = n - 1; - for i in 0..n { - if l_bin.chars().nth(i) != r_bin.chars().nth(i) { - break; - } - k -= 1; - } - //println!(""most significant bit pos with difference: {}"", k); - - let mut prefix: String = (&l_bin[0..n - k - 1]).to_string(); - //println!(""prefix: {}"", prefix); - - // append zeros: - for i in 0..k + 1 { - prefix.push('0'); - } - - //println!(""after padding, prefix becomes: {}"", prefix); - let base = binary_to_u32(&prefix).unwrap(); - //println!(""base additive: {}"", base); - - let num1 = base + (1 << k); // 2^k - let num2 = num1 - 1; - let mut num3 = num1 + 1; - if num3 > r { - num3 = l; - } - - println!(""{} {} {}"", num1, num2, num3); - //println!(""------""); - } -} - -fn pad_binary(l_bin: &str, r_bin: &str) -> String { - let l_len = l_bin.len(); - let r_len = r_bin.len(); - - if l_len < r_len { - let padding = ""0"".repeat(r_len - l_len); - format!(""{}{}"", padding, l_bin) - } else { - l_bin.to_string() // Return l_bin as is if it's already the same length or longer - } -} - -fn to_binary(n: u32) -> String { - format!(""{:b}"", n) -} - -fn invert_bits(binary: &str) -> String { - binary - .chars() - .map(|c| if c == '0' { '1' } else { '0' }) - .collect() -} - -fn binary_to_u32(binary: &str) -> Option { - u32::from_str_radix(binary, 2).ok() -} - -fn max_power_of_2(l: u32) -> (String, u32) { - if l == 0 { - return (""0"".to_string(), 0); - } - - // Find the largest power of 2 less than or equal to l - let pow2 = 1 << (31 - l.leading_zeros()); - - // Convert the value to a binary string - let binary_representation = format!(""{:b}"", pow2); - - // Return the binary string and u32 value - (binary_representation, pow2) -} -",2 -ffmoon,2057C - Trip to the Olympiad,c++17 ,303488529,303491314,"#include -#define fi first -#define se second - -using namespace std; - -using ll = long long; -using pii = pair; -using pll = pair; - -int t; -int l, r; - -void solve() { - cin >> l >> r; - int x = r; - - int k = 0; - for (int i = 0; i <= 30; i++) { - if (x & (1 << i)) { - k = i; - } - } - int y = 0; - for (int i = 0; i <= k; i++) { - if ((x & (1 << i)) == 0) { - y |= (1 << i); - } - } - - if (y < l) - y |= l; - - if (y + 1 >= r) { - cout << x << "" "" << y << "" "" << y - 1 << ""\n""; - } else { - cout << x << "" "" << y << "" "" << y + 1 << ""\n""; - } -} - -int main() { - cin >> t; - while (t--) solve(); -} -","#include -#define fi first -#define se second - -using namespace std; - -using ll = long long; -using pii = pair; -using pll = pair; - -int t; -int l, r; - -void solve() { - cin >> l >> r; - // int x = r; - - int k = 0; - for (int i = 0; i <= 30; i++) { - if (r & (1 << i)) { - k = i; - } - } - int base = 0; - int start = -1; - for (int i = k; i >= 0; i--) { - if ((r & (1 << i)) != 0 && (l & (1 < r) { - z = y - 1; - } else { - z = x + 1; - } - - cout << x << "" "" << y << "" "" << z << ""\n""; - -} - -int main() { - cin >> t; - while (t--) solve(); -} -",2 -Mohamed_Ayman_12,2057C - Trip to the Olympiad,c++20 ,300630779,300630418,"#include -using namespace std; -#define ll long long - -void solve(){ - ll l, r; - cin >> l >> r; - ll ans = 0; - ll firstNum = 0, secondNum = 0; - for (int i = 30; i >= 0; i--) { - int b1 = 0, b2 = 0; - if ((1 << i) & r) { - b1 = 1; - } - if ((1 << i) & l) { - b2 = 1; - } - - if (b1 == b2) { - ans += b1 * (1 << i); - } else { - firstNum += ans + (1 << i); - secondNum += firstNum - 1; - break; - } - } - for (ll i = l; i <= r; i++) { - if (i != firstNum && i != secondNum) { - cout << i << "" "" << firstNum << "" "" << secondNum << '\n'; - break; - } - } -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - int t = 1; - cin>>t; - while(t--){ - solve(); - } -}","#include -using namespace std; -#define ll long long - -void solve(){ - ll l, r; - cin >> l >> r; - ll ans = 0; - ll firstNum = 0, secondNum = 0; - for (int i = 30; i >= 0; i--) { - int b1 = 0, b2 = 0; - if ((1 << i) & r) { - b1 = 1; - } - if ((1 << i) & l) { - b2 = 1; - } - - if (b1 == b2) { - ans += b1 * (1 << i); - } else { - firstNum += ans + (1 << i); - secondNum += firstNum - 1; - break; - } - } - for (ll i = l; i < r; i++) { - if (i != firstNum && i != secondNum) { - cout << i << "" "" << firstNum << "" "" << secondNum << '\n'; - break; - } - } -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(nullptr); cout.tie(nullptr); - int t = 1; - cin>>t; - while(t--){ - solve(); - } -}",1 -ffmoon,2057C - Trip to the Olympiad,c++17 ,303491314,303488581,"#include -#define fi first -#define se second - -using namespace std; - -using ll = long long; -using pii = pair; -using pll = pair; - -int t; -int l, r; - -void solve() { - cin >> l >> r; - // int x = r; - - int k = 0; - for (int i = 0; i <= 30; i++) { - if (r & (1 << i)) { - k = i; - } - } - int base = 0; - int start = -1; - for (int i = k; i >= 0; i--) { - if ((r & (1 << i)) != 0 && (l & (1 < r) { - z = y - 1; - } else { - z = x + 1; - } - - cout << x << "" "" << y << "" "" << z << ""\n""; - -} - -int main() { - cin >> t; - while (t--) solve(); -} -","#include -#define fi first -#define se second - -using namespace std; - -using ll = long long; -using pii = pair; -using pll = pair; - -int t; -int l, r; - -void solve() { - cin >> l >> r; - int x = r; - - int k = 0; - for (int i = 0; i <= 30; i++) { - if (x & (1 << i)) { - k = i; - } - } - int y = 0; - for (int i = 0; i <= k; i++) { - if ((x & (1 << i)) == 0) { - y |= (1 << i); - } - } - - // if (y < l) - y |= l; - - if (y + 1 >= r) { - cout << x << "" "" << y << "" "" << y - 1 << ""\n""; - } else { - cout << x << "" "" << y << "" "" << y + 1 << ""\n""; - } -} - -int main() { - cin >> t; - while (t--) solve(); -} -",1 -T20WC2024Winners#,2057C - Trip to the Olympiad,c++17 ,301007192,301010975,"#include -using namespace std; - - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define inf 1e9 -#define nline ""\n"" -#define pb push_back -#define ppb pop_back -// #define mp make_pair -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -#define rep(i,a,b) for(int i{a};i, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - -//01111 -//10000 -// - - - -void solve() { - ll l = 0 , r = 0; - cin >> l >> r; - ll y = 1; - int bit = 0; - while (y <= r) { - y = y * 2; - bit++; - } - bit--; - ll val = (1LL << bit); - if (val > l && val <= r) { - cout << val << "" "" << val - 1 << "" ""; - if (l == val - 1) { - cout << r << nline; - } - else cout << l << nline; - } - else { - cout << l << "" "" << l + 1 << "" "" << r << nline; - return; - } -} - - -int main() { -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); - freopen(""output.txt"", ""w"", stdout); - freopen(""input.txt"", ""r"", stdin); -#endif - fastio(); - int t{1}; - cin >> t; - while (t--) solve(); -}","#include -using namespace std; - - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define inf 1e9 -#define nline ""\n"" -#define pb push_back -#define ppb pop_back -// #define mp make_pair -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -#define rep(i,a,b) for(int i{a};i, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - -//01111 -//10000 -// - - - -void solve() { - ll l = 0 , r = 0; - cin >> l >> r; - ll y = 1; - int bit = 0; - while (y <= r) { - y = y * 2; - bit++; - } - bit--; - ll val = (1LL << bit); - if (val > l && val <= r) { - cout << val << "" "" << val - 1 << "" ""; - if (l == val - 1) { - cout << r << nline; - } - else cout << l << nline; - } - else { - int bit = 0; - for (int i = 30; i >= 0; i--) { - int lbit = ((l & (1LL << i)) != 0); - int rbit = ((r & (1LL << i)) != 0); - if (lbit != rbit) { - bit = i; - break; - } - } - ll y = (l >> bit); - y <<= bit; - debug(y) - debug(bit) - debug(1LL << bit) - ll gg = (1LL << bit) + y; - debug(gg) - cout << gg << "" "" << gg - 1 << "" ""; - if (gg - 1 == l ) { - cout << r << nline; - } - else cout << l << nline; - } -} -// 1000100 -// 1100010 - -int main() { -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); - freopen(""output.txt"", ""w"", stdout); - freopen(""input.txt"", ""r"", stdin); -#endif - fastio(); - int t{1}; - cin >> t; - while (t--) solve(); -}",2 -IacobTudor,2057C - Trip to the Olympiad,c++17 ,301630479,301629795,"#include -using namespace std; -ifstream fin(""window.in""); -ofstream fout(""window.out""); -void solve(){ - int l,r; - cin>>l>>r; - int b(30),prc(0); - while(((1<>t; - while(t--)solve(); - return 0; -} -","#include -using namespace std; -ifstream fin(""window.in""); -ofstream fout(""window.out""); -void solve(){ - int l,r; - cin>>l>>r; - int b(30); - while(((1<>t; - while(t--)solve(); - return 0; -} -",1 -Ellipse,2057C - Trip to the Olympiad,c++23 ,305031621,304923740,"#include - -using namespace std; - -#define ll long long -#define ld long double -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define pb push_back - -ll inf = 1e18, mod = 1e9 + 7; - -ll gcd(ll a, ll b) { - while (a != 0 && b != 0) { - if (a > b) { - a %= b; - } - else { - b %= a; - } - } - return a + b; -} - -ll lcm(ll a, ll b) { - return (a * b) / gcd(a, b); -} - -ll binpow(ll base, ll p) { - if (p == 0) return 1; - else if (p % 2) return binpow(base, p - 1) * base; - else return binpow(base, p / 2) * binpow(base, p / 2); -} - -void solve() { - ll l, r; - cin >> l >> r; - ll cnt = 1, sz = 1; - while (cnt * 2 <= r) { - sz++; - cnt *= 2; - } - cnt = 1; - ll sz1 = 0; - while (cnt * 2 <= l) { - cnt *= 2; - sz1++; - } - vector bit, bit1; - for (int i = 0; i < sz; ++i) { - if (r & (1 << i)) bit.pb(1); - else bit.pb(0); - } - ll s = 0; - for (int i = 0; i < bit.size(); ++i) { - if (!bit[i]) { - bit1.pb(1); - s += (1 << i); - } - else bit1.pb(0); - } - if (s >= l) { - if (s & 1) { - if (s - 1 < l) { - cout << r << "" "" << s << "" "" << s + 1 << ""\n""; - } - else { - cout << r << "" "" << s << "" "" << s - 1 << ""\n""; - } - } - else { - if (s + 1 >= r) { - cout << r << "" "" << s << "" "" << s - 1 << ""\n""; - } - else { - cout << r << "" "" << s << "" "" << s + 1 << ""\n""; - } - } - } - else { - for (int i = sz1; i >= 0; --i) { - if (!bit1[i] && s + (1 << i) <= r) { - s += (1 << i); - if (s >= l) break; - } - } - if (s & 1) { - if (s - 1 < l) { - cout << r << "" "" << s << "" "" << s + 1 << ""\n""; - } - else { - cout << r << "" "" << s << "" "" << s - 1 << ""\n""; - } - } - else { - if (s + 1 >= r) { - cout << r << "" "" << s << "" "" << s - 1 << ""\n""; - } - else { - cout << r << "" "" << s << "" "" << s + 1 << ""\n""; - } - } - } -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t = 1; - cin >> t; - while (t--) { - solve(); - } -}","#include - -using namespace std; -#define int long long -#define ull unsigned long long int -#define dl double long -#define all(x) x.begin(), x.end() -#define ss second -#define ff first -const int N = 2 * 1e5 + 10; -const int M = 1e9 + 7; -#define Priyanshu_Mishra - -Priyanshu_Mishra - -void solve() -{ - int l, r; - cin >> l >> r; - int x = log2(r); - if ((1ll << (x - 1)) >= l + 1) { - cout << (1ll << (x)) << "" "" << (1ll << (x - 1)) << "" "" << (1ll << (x - 1)) - 1 << endl; - return; - } - int a=(1ll<= 0; y--) { - if(((1ll< l) { - temp-=(1ll << y); - } - else b+=(1ll<> testcases; - while (testcases--) - { - solve(); - #ifdef Priyanshu_Mishra - cerr << ""\nTime elapsed: "" << 1000.0 * clock() / CLOCKS_PER_SEC << "" ms\n""; - #endif - } - return 0; -}",1 -surewordnewnew,2057C - Trip to the Olympiad,c++23 ,300838093,300837315,"#include -using namespace std; -using i64 = long long; -int T, l, r; -void solve() { - cin >> l >> r; - bitset <32> x(l), y(r), ans(0); - int tp = 31; - for (; ~tp; tp --) if (x[tp] ^ y[tp]) break; - for (int i = 31; i > tp; i --) ans[i] = x[i]; - for (int i = tp; ~i; i --) { - if (!(x[i] ^ y[i])) ans[i] = x[i] ^ 1; - } - for (int i = tp; ~i; i --) { - if (x[i] ^ y[i]) { - ans[i] = 1; - if (ans.to_ulong() >= y.to_ulong()) ans[i] = 0; - } - } - int a = x.to_ulong(), b = ans.to_ulong(), c = y.to_ulong(); - cout << a << ' ' << b << ' ' << c << '\n'; -} -int32_t main() { - cin.tie(NULL) -> sync_with_stdio(false); - for (cin >> T; T --; ) solve(); - return 0; -}","#include -using namespace std; -int ls, rs; -inline void slove() { - int l, r; cin >> l >> r; - int steps = 0, ans = 0; - while (r >> steps) { - ls = l >> steps & 1, rs = r >> steps & 1; - if (ls != rs) - if ((ans | (1 << steps)) <= r)ans |= (1 << steps); - if (ls == rs) - ans |= ((ls ^ 1) << steps); - steps++; - } - cout << l<<"" ""<< ans<<"" "" << r << endl; -} -int main() { - int T; cin >> T; - while (T--) { - slove(); - } - return 0; -}",1 -debjit81,2057C - Trip to the Olympiad,c++23 ,305906597,305906097,"#include - -using i64 = long long; - -void solve() { - int l, r; - std::cin >> l >> r; - - int a = l, c = r, b = 0; - bool ok = false; - int pos; - for (int i = 30; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - pos = i; - break; - } - } - - for (int i = 30; i > pos; i --) { - int x = a >> i & 1; - b += x << i; - } - - for (int i = pos; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - if (b + (1 << i) < c) { - b += 1 << i; - } - } else { - b += (!x) << i; - } - } - - std::cout << a << "" "" << b << "" "" << c << ""\n""; -} - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - std::cout << std::fixed << std::setprecision(20); - - int T = 1; - std::cin >> T; - - while (T --) { - solve(); - } - - return 0; -}","// Author: Debjit Saha - -#include -using namespace std; -#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); -#define int long long -#define lld long double -// #define ll long long -#define endl '\n' -#define tab '\t' -#define all(a) a.begin(), a.end() -#define vi vector -#define vp vector> -#define vvi vector> -#define vb vector -#define vs vector -#define mii map -#define rep(n) for(int i=0;i> l >> r; - - int sum = 0, p = 32, one = 1; - while(p > 0) { - int a = (l>>p) % 2; - int b = (r>>p) % 2; - if(a ^ b) { - sum += (one<> t; - while(t--) - solve(); - return 0; -}",1 -Sereinsky,2057C - Trip to the Olympiad,c++17 ,301179053,301180290,"#include -using namespace std; - -#define pb push_back -#define endl ""\n"" -#define all(x) (x).begin(),(x).end() -#define x first -#define y second -#define int long long -typedef pair pii; -typedef double db; -typedef long long LL; -const int N = 1e6+10; - - - -void solve(){ - int l, r; - cin >> l >> r; - int op = 1; - for (int i = 1 ; i <= 30; i ++){ - op *= 2; - } - while(op){ - if(r / op && l / op == 0 ){ - if(r != op){ - cout << op + 1 << "" "" << op << "" "" << op - 1 << endl; - } - else { - cout << op << "" "" << op - 1 << "" "" << op - 2 << endl; - } - return ; - } - op /= 2; - } - -} - - - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cin.tie(0); - - int _ = 1; - cin>>_; - while(_--) - { - solve(); - } - - return 0; -} -","#include -using namespace std; - -#define pb push_back -#define endl ""\n"" -#define all(x) (x).begin(),(x).end() -#define x first -#define y second -#define int long long -typedef pair pii; -typedef double db; -typedef long long LL; -const int N = 1e6+10; - - - -void solve(){ - int l, r; - cin >> l >> r; - int op = 1; - for (int i = 1 ; i <= 30; i ++){ - op *= 2; - } - int t = r; - while(op){ - if(r / op && (l / op) == 0 ){ - //cout << ""h"" << endl; - t /= op * 2; - t *= op * 2; - if(r != op){ - op += t; - cout << op + 1<< "" "" << op << "" "" << op - 1 << endl; - } - else { - op += t; - cout << op << "" "" << op - 1 << "" "" << op - 2 << endl; - } - return ; - } - if(r /op && l / op){ - r %= op; - l %= op; - } - //cout << op << "" "" << r / op << "" "" << (l / op) << endl; - op /= 2; - } - -} - - - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cin.tie(0); - - int _ = 1; - cin>>_; - while(_--) - { - solve(); - } - - return 0; -} -",2 -VALiiANT,2057C - Trip to the Olympiad,c++17 ,301062907,301048531,"#include -using namespace std; -#define int long long -#define eb emplace_back - -int mod=1e9+7; - -int32_t main(){ - int t; - cin>>t; - - while(t--){ - int l,r; - cin>>l>>r; - int x,z, ans=0; - - for(int i=30; i>=0; i--){ - int b1=0, b2=0; - - if(l & (1LL<=l; i--){ - if(i!=x && i!=x-1){ - z=i; - break; - } - } - - cout< -using namespace std; -#define int long long -#define eb emplace_back - -int mod=1e9+7; - -int32_t main(){ - int t; - cin>>t; - - while(t--){ - int l,r; - cin>>l>>r; - int x,z; - - for(int i=r; i>=l; i--){ - if((i & i-1)==0){ - x=i; - break; - } - } - - for(int i=r; i>=l; i--){ - if(i!=x && i!=x-1){ - z=i; - break; - } - } - - cout< -// Including tree_order_statistics_node_update -#include -#include -// visit this link to study it in a proper way : -// https://codeforces.com/blog/entry/11080 -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> -// use less_equal for multiset and less for set ^ -// Find by order and order of key -// cout<< *X.find_by_order(k) <> l >> r; - int k = 31 - __builtin_clz( l ^ r ); - int a = ( l | ( (1 << k) - 1 )); - int b = a + 1; - int c = ( a == l ? r : l ); - cout << a << "" "" << b << "" "" << c << endl; -} - -signed main() { - auto begin = std::chrono::high_resolution_clock::now(); - - // std::ifstream file(""matrix.txt""); // Replace ""input.txt"" with your file name - // std::cerr << ""Error opening file!"" << std::endl; - // return 1; - // } - - // std::string line; - - // while (std::getline(file, line)) { // Read the file line by line - // std::stringstream ss(line); // Create a stringstream from the line - // std::string num; - - // // Split the line by commas and extract integers - // while (std::getline(ss, num, ',')) { - // all.push_back(std::stoi(num)); // Convert the string to an integer and store it - // } - // } - - // file.close(); - - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - while (t--) { - solve(); - // cout << ""-----"" << endl; - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - return 0; -} -","#include ""bits/stdc++.h"" -using namespace std; -#include -// Including tree_order_statistics_node_update -#include -#include -// visit this link to study it in a proper way : -// https://codeforces.com/blog/entry/11080 -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> -// use less_equal for multiset and less for set ^ -// Find by order and order of key -// cout<< *X.find_by_order(k) <> l >> r; - cout << r << "" "" << l << "" "" << (l + r )/ 2 << endl; -} - -signed main() { - auto begin = std::chrono::high_resolution_clock::now(); - - // std::ifstream file(""matrix.txt""); // Replace ""input.txt"" with your file name - // std::cerr << ""Error opening file!"" << std::endl; - // return 1; - // } - - // std::string line; - - // while (std::getline(file, line)) { // Read the file line by line - // std::stringstream ss(line); // Create a stringstream from the line - // std::string num; - - // // Split the line by commas and extract integers - // while (std::getline(ss, num, ',')) { - // all.push_back(std::stoi(num)); // Convert the string to an integer and store it - // } - // } - - // file.close(); - - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - while (t--) { - solve(); - // cout << ""-----"" << endl; - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - return 0; -}",1 -YWKM,2057C - Trip to the Olympiad,c++20 ,301224292,301222864,"#include -#define int long long - -using namespace std; -using ll=long long; - -void solve(){ - int l,r; - cin>>l>>r; - if(r-l+1==3){ - cout< ans[3]; - for(int i=30 ; i>=0; i--){ - if((r&(1<>i)&1); - ans[1].push_back((r>>i)&1); - ans[2].push_back((r>>i)&1); - } - } - bool flag=true; - for(int i=p-1 ; i>=0; i--){ - if((l&(1< res(3); - for(int i=0,j=30 ; i<=30; i++,j--){ - for(int k=0; k<3 ; k++){ - res[k]+=(ll)(ans[k][i]<sync_with_stdio(0); - cout.tie(nullptr)->sync_with_stdio(0); - int t; - cin>>t; - while(t--) solve(); -}","#include -#define int long long - -using namespace std; -using ll=long long; - -void solve(){ - int l,r; - cin>>l>>r; - int p=-1; - vector ans[3]; - for(int i=30 ; i>=0; i--){ - if((r&(1<=0; i--){ - if((l&(1< res(3); - for(int i=0,j=30 ; i<=30; i++,j--){ - for(int k=0; k<3 ; k++){ - res[k]+=(ll)(ans[k][i]<sync_with_stdio(0); - cout.tie(nullptr)->sync_with_stdio(0); - int t; - cin>>t; - while(t--) solve(); -}",1 -intangible,2057C - Trip to the Olympiad,c++20 ,300974636,300970342,"#include - -using i64 = long long; - -void solve() { - int l, r; - std::cin >> l >> r; - int k = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l); - std::cout << a << "" "" << b << "" "" << c << ""\n""; -} - -signed main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - std::cin >> t; - - while (t--) { - solve(); - } -}","#include -#include -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> indexed_set; -#define ln '\n' -#define ull unsigned long long -#define ll long long -#define vll vector -#define pll pair -#define ff first -#define vpll vector> -#define pii pair -#define ld long double -#define ss second -using namespace std; - - -void setIO(const string io=""a""){ - freopen((io+"".in"").c_str(),""r"",stdin) ; - freopen((io+"".out"").c_str(),""w"",stdout) ; -} -void f(ll a,ll b,ll c){ - cout << (a^b) + (a^c) + (b^c) << ln ; -} - -void solve(){ - ll l , r ; cin >> l >> r ; - ll n = log2(r)+1 ; - string s1 = """" ; for(ll i=0;i>= 1ll ; i-- ; - } - string s2 = """" ; for(ll i=0;i>= 1ll ; i-- ; - } - string s3 = """" ; for(ll i=0;i r ) { - pow-- ; continue ; - } - else if (val3 + (1ll<> t ; - for(ll i=1;i<=t;i++){ - //cout << ""Case "" << i << "": "" ; - solve() ; - } - return 0; -} - - - -",1 -__stoic,2057C - Trip to the Olympiad,c++23 ,300601755,300601474,"#include -using namespace std; - - -void __solve(){ - int l,r; - cin>>l>>r; - int k=31- __builtin_clz(l^r); - int a=l|((1<>t; - while(t--){ - __solve(); - } - - return 0; -}","#include -using namespace std; - - -void __solve(){ - int l,r; - cin>>l>>r; - int k=31- __builtin_clz(l^r); - int a=l|(1<>t; - while(t--){ - __solve(); - } - - return 0; -}",1 -fewffee,2057C - Trip to the Olympiad,c++23 ,305084645,305084142,"#include - -#define int long long -#define debug(x) std::cerr<<""The ""<<#x<<"" = ""<> l >> r; - int now = 0; - for (int i = 30; i >= 0; i--) { - if ((l >> i & 1) != (r >> i & 1)) { - int x = (1LL << i) - 1, y = 0; - x += now, y += now + (1LL << i); - std::cout << x << "" "" << y << "" "" << ((x != l && y != l) ? l : r) << '\n'; - return ; - } - now += ((l >> i & 1) ? (1LL << i) : 0); - } -} - -signed main() { - std::ios::sync_with_stdio(false), - std::cin.tie(0), - std::cout.tie(0); - int T = 1; - std::cin >> T; - while (T--) { - solve(); - } - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define ll long long -unordered_setsett; -int main() -{ - ll t; - cin>>t; - for(ll k1=1;k1<=t;k1++) - { - ll i,j,k,cnt1=0,cnt2=0,l,r; - cin>>l>>r; - ll base=r; - while(base>0) base/=2,cnt1++; - for(i=cnt1;i>=1;i--) - { - base=pow(2,i-1); - ll x=r/base; - x*=base; - if(x>l) - { - if(x!=r) cout< -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define ll long long -// const ll MOD = 998244353 ; -// inline ll mul(ll a1, ll a2) { return ((a1 * a2) % MOD); } -// inline ll sum(ll a1, ll a2) { return ((a1 + a2) % MOD); } -// inline ll sub(ll a1, ll a2) { return ((a1 - a2 + MOD) % MOD); } -int main() { - IOS - int test ; - cin>>test; - while(test--) { - ll l , r ; - cin>>l>>r; - ll z = 1 , x = l ^ r ; - while( x % z == 0 ) { - z *= 2 ; - } - z /= 2 ; - x = z ; - z *= (r/z) ; - if(z<=l) { - z +=x ; - } - ll a1 = z , a2 = z - 1 , a3; - ll max = -1 ; - for( int i = l ; i <= r ; i++ ) { - if ((i==a1)or(i==a2)) { - continue ; - } - if ((i^a1)+(i^a2)>max) { - max = i^a1 + i^a2 ; - a3 = i ; - } - } - cout< -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define ll long long -// const ll MOD = 998244353 ; -// inline ll mul(ll a1, ll a2) { return ((a1 * a2) % MOD); } -// inline ll sum(ll a1, ll a2) { return ((a1 + a2) % MOD); } -// inline ll sub(ll a1, ll a2) { return ((a1 - a2 + MOD) % MOD); } -int main() { - IOS - int test ; - cin>>test; - while(test--) { - ll l , r ; - cin>>l>>r; - ll z = 1 , x = l ^ r ; - int k = 31 - __builtin_clz(l ^ r); - z = 1 << k ; - ll a1 = l | (z-1) , a2 = a1 + 1 , a3 ; - if(a1 == l) { - a3 = r ; - }else { - a3 = l ; - } - cout<= t: - l -= t - r -= t - rm += t - t //= 2 - - if l < t - 1: - print(l + rm, t - 1 + rm, r + rm) - elif l == t - 1: - print(l + rm, t + rm, r + rm) - - -if __name__ == ""__main__"": - tests = int(input()) - for _ in range(tests): - Solution().solve() -","def read_list(): - return list(map(int, input().split())) - - -def f(a, b, c): - return (a ^ b) + (b ^ c) + (c ^ a) - - -class Solution: - def solve(self): - l, r = tuple(read_list()) - L = l - R = r - lb = [] - rb = [] - for _ in range(32): - lb.append(l % 2) - l //= 2 - rb.append(r % 2) - r //= 2 - for i in range(31, -1, -1): - if lb[i] != rb[i]: - assert lb[i] == 0 and rb[i] == 1 - X = L | ((1 << i) - 1) - if L < X: - print(L, X, X + 1) - else: - print(X, X + 1, X + 2) - break - - -if __name__ == ""__main__"": - tests = int(input()) - for _ in range(tests): - Solution().solve() -",2 -perseus999,2057C - Trip to the Olympiad,c++23 ,303498925,303498499,"#include -using namespace std; -#define ll long long -#define MOD 1000000007 - -#ifdef LOCAL -#include ""algo/debug.h"" -#else -#define debug(...) 42 -#endif -const int N = 1e8 ; -int main() { - -ios_base::sync_with_stdio(false); cin.tie(NULL); - -ll tt ; cin >> tt ; - -while(tt--) { - - ll l , r ; cin >> l >> r ; - - ll a = 0 , b = 0 ; - ll ind = -1 ; - for( int i = 30 ; i >= 0 ; i--) { - - if((l & (1 << i)) != (r & (1 << i)) ) { - ind = i ; break; - } - if(l & (1 << i)) { - a += (1 << i) ; - b = a; - } - } - a += (1 << ind) ; - ind--; - for( int i = ind ; i >= 0; i--) { - b += (1 << i) ; - } - ll c ; - for( int i = l ; i <= r ; i++) { - if(i != a && i != b) { - c = i ; break; - } - } - cout << a << "" "" << b << "" "" << c << ""\n"" ; - } -} - -","#include -using namespace std; -#define ll long long -#define MOD 1000000007 - -#ifdef LOCAL -#include ""algo/debug.h"" -#else -#define debug(...) 42 -#endif -const int N = 1e8 ; -int main() { - -ios_base::sync_with_stdio(false); cin.tie(NULL); - -ll tt ; cin >> tt ; - -while(tt--) { - - ll l , r ; cin >> l >> r ; - - ll a = 0 , b = 0 , c = 0 ; - ll ind = -1 ; - for( int i = 30 ; i >= 0 ; i--) { - - if((l & (1 << i)) != (r & (1 << i)) ) { - ind = i ; break; - } - if(l & (1 << i)) { - a += (1 << i) ; - c = b = a; - } - } - a += (1 << ind) ; - ind--; - for( int i = ind ; i >= 0; i--) { - b += (1 << i) ; - if(i) c += (1 << i) ; - } - cout << a << "" "" << b << "" "" << c << ""\n"" ; - } -} - -",1 -vs_run,2057C - Trip to the Olympiad,c++23 ,304510994,304510534,"#include - -using namespace std; -#define ll long long -#define ull unsigned long long -#define vi vector -#define vll vector -#define vpi vector> -#define vpll vector> -#define mapi map -#define mapll map -#define yes cout << ""YES\n"" -#define no cout<<""NO\n"" -#define fori_n for(int i = 0; i> t; - while(t--){ - ll l, r; - cin >> l >> r; - ll x = round(powl(2, (ll)log2l(r))); - ll y = x, sum = 0; - while(y){ - if(sum+y-1>=l && sum+y>=l && sum+y<=r){ - break; - } - if(sum+y<=r) - sum+=y; - y/=2; - } - x = sum+y-1; - y+=sum; - ll z; - if(r==y){ - z = r-2; - } - else z = r; - cout << x << "" "" << y << "" "" << z << endl; - } - return 0; -}","#include -#define ll long long -#define endl '\n' -#define int long long -using namespace std; - - - -void solve() { - int l, r; - cin >> l >> r; - int idx = -1; - int mid = 0; - for (int i=30;i>=1;i--) { - int a = l & (1 << i); - int b = r & (1 << i); - if (a == b) { - idx = i; - if (a > 0) mid += (1 << i); - } else { - break; - } - } - mid += (1 << (idx-1)); - if (mid - 1 == l) { - cout << l << "" "" << mid + 1 << "" "" << mid << endl; - } else { - cout << l << "" "" << mid - 1 << "" "" << mid << endl; - } - -// int mid = 1; -// while (mid * 2 <= r) { -// mid = mid * 2; -// } -// if (l + 1 < mid) { -// cout << l << "" "" << mid - 1 << "" "" << mid << endl; -// } else if (l == mid - 1) { -// cout << l << "" "" << mid << "" "" << r << endl; -// } else { -// // l >= mid -// -// cout << endl; -// } -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",1 -Owv,2057C - Trip to the Olympiad,c++23 ,307414839,307408527,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#define ll long long -#define LOG2(n) __lg(n) -#define SET_BIT_COUNTLL(x) __builtin_popcountll(x) -#define SET_BIT_COUNT(x) __builtin_popcount(x) -#define FAST ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); -#define all(v) v.begin(),v.end() -#define allr(v) v.rbegin(),v.rend() -#define lp(var,inti,size) for(int var = inti ; var < size ; var ++) -#define fori(size) for(ll i=0; i < (size); i++) -#define foril(size) for(ll i=(size-1); i >= 0; --i) -#define forj(size) for(ll j=0; j < (size); j++) -#define fork(size) for(ll k=0; k < (size); k+= 1) -#define forl(size) for(ll l=0; l < (size); l+= 1) -const float pi = 3.14; -const long long oo = 9223372036854775807; -using namespace std; -#define oo 1e9 -#define pb push_back -#define endll ""\n"" -#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) -#define mp make_pair -#define yes cout<<""YES""< pii; -typedef pair ppi; -typedef vector vec; -void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - -vector fibNumbers(1e7, 1); - -set primeo; - - - -ll dpadep(vec &dpadepo, ll fo) { - if (fo > 1000)return 0; - else { - dpadepo.push_back(fo); - dpadep(dpadepo, fo * 10 + 7); - return dpadep(dpadepo, fo * 10 + 4); - } - -} -void TT() { - - long long n, t, m = 0, c = 0, sum = 0, real_sum = 0, c_sofar = 0, sum_sofar = 0; ll a, b = 1, k, r, l, ans = 0; - string sl,sr; - cin >>l>>r; - vec x; t = l; - map lolo; - while (l) { - if (l % 2)sl = sl+""1"" ; - else sl = sl +""0"" ; - l = l/ 2; - } - while (r) { - if (r % 2)sr = sr+""1""; - else sr = sr +""0"" ; - r = r / 2; - } - if (sr.length() > sl.length()) { - if (((1 << sr.length() - 1) - 1) != t) cout << (1 << sr.length() - 1) << "" "" << (1 << sr.length() - 1) - 1 << "" "" << t << endl; - else cout << t << "" "" << t + 1 << "" "" << t + 2< n) { QWE - cout << n << endl;; - } - else if (a) { - ans = n - 1 - b+a; - ans /= a; - cout <> n; - ll s = 0; - while (n--) { TT(); } -} -// Owvx -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#define ll long long -#define LOG2(n) __lg(n) -#define SET_BIT_COUNTLL(x) __builtin_popcountll(x) -#define SET_BIT_COUNT(x) __builtin_popcount(x) -#define FAST ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); -#define all(v) v.begin(),v.end() -#define allr(v) v.rbegin(),v.rend() -#define lp(var,inti,size) for(int var = inti ; var < size ; var ++) -#define fori(size) for(ll i=0; i < (size); i++) -#define foril(size) for(ll i=(size-1); i >= 0; --i) -#define forj(size) for(ll j=0; j < (size); j++) -#define fork(size) for(ll k=0; k < (size); k+= 1) -#define forl(size) for(ll l=0; l < (size); l+= 1) -const float pi = 3.14; -const long long oo = 9223372036854775807; -using namespace std; -#define oo 1e9 -#define pb push_back -#define endll ""\n"" -#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) -#define mp make_pair -#define yes cout<<""YES""< pii; -typedef pair ppi; -typedef vector vec; -void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - -vector fibNumbers(1e7, 1); - -set primeo; - - - -ll dpadep(vec &dpadepo, ll fo) { - if (fo > 1000)return 0; - else { - dpadepo.push_back(fo); - dpadep(dpadepo, fo * 10 + 7); - return dpadep(dpadepo, fo * 10 + 4); - } - -} -void TT() { - - long long n, t, m = 0, c = 0, sum = 0, real_sum = 0, c_sofar = 0, sum_sofar = 0; ll a, b = 1, k, r, l, ans = 0; - string sl,sr; - cin >>l>>r; - vec x; t = l; - map lolo; - while (l) { - if (l % 2)sl = ""1"" + sl; - else sl = ""0"" + sl; - l = l/ 2; - } - while (r) { - if (r % 2)sr = ""1"" + sr; - else sr = ""0"" + sr; - r = r / 2; - } - if (sr.length() > sl.length()) { - if (((1 << sr.length() - 1) - 1) != t) cout << (1 << sr.length() - 1) << "" "" << (1 << sr.length() - 1) - 1 << "" "" << t << endl; - else cout << t << "" "" << t + 1 << "" "" << t + 2< n) { QWE - cout << n << endl;; - } - else if (a) { - ans = n - 1 - b+a; - ans /= a; - cout <> n; - ll s = 0; - while (n--) { TT(); } -} -// Owvx -",1 -Manojkumar2412,2057C - Trip to the Olympiad,c++17 ,300788287,300528315,"// Source: https://usaco.guide/general/io - -#include -using namespace std; - - - - -void solve(){ - int l,r; - cin>>l>>r; - int k= 31 - __builtin_clz(r^l); - int a= l | ((1<>t; - while(t--){ - solve(); - } -} -","#include -using namespace std; -#define int long long -#define vi vector -#define vii vector> -#define pb push_back -#define endl '\n' -#define fora(a) for(auto i:a)cout< tree, lazy; - int n; - -public: - SegmentTree(int size) { - n = size; - tree.resize(4 * n, 0); - lazy.resize(4 * n, 0); - } - - void build(vector& arr, int start, int end, int node) { - if (start == end) { - tree[node] = arr[start]; - return; - } - - int mid = (start + end) / 2; - build(arr, start, mid, 2 * node + 1); - build(arr, mid + 1, end, 2 * node + 2); - tree[node] = tree[2 * node + 1] + tree[2 * node + 2]; - } - - void updateRange(int start, int end, int l, int r, int value, int node) { - if (lazy[node] != 0) { - tree[node] += (end - start + 1) * lazy[node]; - if (start != end) { - lazy[2 * node + 1] += lazy[node]; - lazy[2 * node + 2] += lazy[node]; - } - lazy[node] = 0; - } - - if (start > end || start > r || end < l) { - return; - } - - if (start >= l && end <= r) { - tree[node] += (end - start + 1) * value; - if (start != end) { - lazy[2 * node + 1] += value; - lazy[2 * node + 2] += value; - } - return; - } - - int mid = (start + end) / 2; - updateRange(start, mid, l, r, value, 2 * node + 1); - updateRange(mid + 1, end, l, r, value, 2 * node + 2); - tree[node] = tree[2 * node + 1] + tree[2 * node + 2]; - } - - int queryRange(int start, int end, int l, int r, int node) { - if (start > end || start > r || end < l) { - return 0; - } - - if (lazy[node] != 0) { - tree[node] += (end - start + 1) * lazy[node]; - if (start != end) { - lazy[2 * node + 1] += lazy[node]; - lazy[2 * node + 2] += lazy[node]; - } - lazy[node] = 0; - } - - if (start >= l && end <= r) { - return tree[node]; - } - - int mid = (start + end) / 2; - int left = queryRange(start, mid, l, r, 2 * node + 1); - int right = queryRange(mid + 1, end, l, r, 2 * node + 2); - return left + right; - } - - void updateRange(int l, int r, int value) { - updateRange(0, n - 1, l, r, value, 0); - } - - int queryRange(int l, int r) { - return queryRange(0, n - 1, l, r, 0); - } -}; - -class Manacher { -public: - string longestPalindrome(string s) { - string t=""$""; - for(char i: s){ - t+='#'; - t+=i; - } - t+=""#@""; - int n=t.size(); - int main_palindrome_center=1, main_palindrome_right_bound=1; - vector palindrome_length(n,0); - for(int i=1;i gives difference then reduce that from c which makes c-(i-c) - // c-i+c => 2*c -i - int mirror_character_index= main_palindrome_center*2 - i; - - if(i< main_palindrome_right_bound){ - // if i is inside the boundary, then atleast guarentee length should be - // palindrome_length of mirror but it may exceeds the right boundary - // so remove the string beyond the right boundary by - palindrome_length[i]= min( - palindrome_length[mirror_character_index], - main_palindrome_right_bound-i); - } - - while( - t[i + (palindrome_length[i]+1)] == t[i- (palindrome_length[i]+1)] - ){ - palindrome_length[i]++; - } - - if((i+ palindrome_length[i]) > main_palindrome_right_bound){ - main_palindrome_right_bound = palindrome_length[i]+i; - main_palindrome_center = i; - } - } - int max_length=0, index=0; - for(int i=1;i0){ - if(b&1) - res=res%MOD*1ll*(a%MOD)%MOD; - a=a%MOD*1ll*(a%MOD)%MOD; - b>>=1; - } - return res; -} -template -T nxt() { - T x; - cin >> x; - return x; -} - -void solve(){ - int l,r; - cin>>l>>r; - int k= 31- __builtin_clz(r); - int a= 1<>test; - for(int i=1;i<=test;i++){ - // cout<<""case #""< -using namespace std; -void solve() -{ -long long l,r; -cin>>l>>r; -long long ans=0; -long long a,b,c; -for(int i=30;i>=0;i--){ - long long b1 = (l&(1<> t; - // cout< -using namespace std; -void solve() -{ -long long l,r; -cin>>l>>r; -long long ans=0; -long long a,b,c; -for(int i=30;i>=0;i--){ - long long b1=0,b2=0; - if(l&(1LL<=l;i--){ - if(i!=a && i!=b) { - c= i; - break; - } - -} -cout<> t; - // cout< -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define ll long long -// const ll MOD = 998244353 ; -// inline ll mul(ll a1, ll a2) { return ((a1 * a2) % MOD); } -// inline ll sum(ll a1, ll a2) { return ((a1 + a2) % MOD); } -// inline ll sub(ll a1, ll a2) { return ((a1 - a2 + MOD) % MOD); } -int main() { - IOS - int test ; - cin>>test; - while(test--) { - ll l , r ; - cin>>l>>r; - ll z = 1 , x = l ^ r ; - int k = 31 - __builtin_clz(l ^ r); - z = 1 << k ; - ll a1 = l | (z-1) , a2 = a1 + 1 , a3 ; - if(a1 == l) { - a3 = r ; - }else { - a3 = l ; - } - cout< -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define ll long long -// const ll MOD = 998244353 ; -// inline ll mul(ll a1, ll a2) { return ((a1 * a2) % MOD); } -// inline ll sum(ll a1, ll a2) { return ((a1 + a2) % MOD); } -// inline ll sub(ll a1, ll a2) { return ((a1 - a2 + MOD) % MOD); } -int main() { - IOS - int test ; - cin>>test; - while(test--) { - ll l , r ; - cin>>l>>r; - ll z = 1 , x = l ^ r ; - while( x % z == 0 ) { - z *= 2 ; - } - z /= 2 ; - ll a1 = l | (z-1) , a2 = a1 + 1 , a3; - ll max = -1 ; - for( int i = l ; i <= r ; i++ ) { - if ((i==a1)or(i==a2)) { - continue ; - } - if ((i^a1)+(i^a2)>max) { - max = i^a1 + i^a2 ; - a3 = i ; - } - } - cout< -using namespace std; -#define PB push_back -#define MP make_pair -#define fst first -#define scd second - -typedef long long ll; -typedef pair pii; -typedef pair pll; -using vi = vector; -using vl = vector; -const ll INF = 1e18 + 7; -const int N = 5e6 + 7; -const int M = 5e8 + 7; -const int modN = 998244353; -mt19937_64 rng(time(0)); - -ll a[N]; - -void solve(){ - ll l, r; - cin >> l >> r; - ll num = log2(r); - ll cur = 1ll << num; - num--; - while(cur <= l && num >= 0){ - if(cur + (1ll << num) <= r) - cur += (1ll << num); - num--; - } - cout << cur << "" "" << cur - 1 << "" ""; - if(cur != r) - cout << r << ""\n""; - else - cout << l << ""\n""; -} -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - ll T; - cin >> T; - while(T--) - solve(); - return 0; -} -","#include -using namespace std; -#define PB push_back -#define MP make_pair -#define fst first -#define scd second - -typedef long long ll; -typedef pair pii; -typedef pair pll; -using vi = vector; -using vl = vector; -const ll INF = 1e18 + 7; -const int N = 5e6 + 7; -const int M = 5e8 + 7; -const int modN = 998244353; -mt19937_64 rng(time(0)); - -ll a[N]; - -void solve(){ - ll l, r; - cin >> l >> r; - ll num = log2(r); - ll cur = 1ll << num; - num--; - while((cur + 1ll << num) <= l && num >= 0){ - if(cur + (1ll << num) <= r) - cur += (1ll << num); - num--; - } - cout << cur << "" "" << cur - 1 << "" ""; - if(cur != r) - cout << r << ""\n""; - else - cout << l << ""\n""; -} -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - ll T; - cin >> T; - while(T--) - solve(); - return 0; -} -",1 -Ninja_Hattori,2057C - Trip to the Olympiad,c++20 ,302026092,302028612,"#include -using namespace std; -#define int long long -int mod = 1e9+7; -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -#define srt(x) sort(x.begin(),x.end()); -#define print(x) for(int i = 0;i> l >> r; - int j = 0; - int a = 0 , b = 0, c = 0; - for(int i = 30;i>=0;i--){ - if((l&(1<=0;i--){ - a<<=1; - a+=1; - } - b <<= 1; - b+=1; - for(int i = j-1;i>=0;i--){ - b<<=1; - } - for(int i = l;i<=r;i++){ - if(a!=i && b!=i){ - c = i; - break; - } - } - cout<> _t; - while(_t--){ - solve(); - } - - return 0; -} - -","#include -using namespace std; -#define int long long -int mod = 1e9+7; -#define yes cout<<""YES\n""; -#define no cout<<""NO\n""; -#define srt(x) sort(x.begin(),x.end()); -#define print(x) for(int i = 0;i> l >> r; - int j = 0; - int a = 0 , b = 0, c = 0; - for(int i = 30;i>=0;i--){ - if((l&(1<=0;i--){ - x<<=1; - x+=1; - } - a+=x; - b+=(1<<(j)); - for(int i = l;i<=r;i++){ - if(a!=i && b!=i){ - c = i; - break; - } - } - cout<> _t; - while(_t--){ - solve(); - } - - return 0; -} - -",2 -zuba37,2057C - Trip to the Olympiad,python,307347965,307348775,"for _ in range(int(input())): - b, a = map(int, input().split()) - k = (1 << ((a^b).bit_length()-1)) - 1 - print(b | k, b | k, a & (~k))","for _ in range(int(input())): - b, a = map(int, input().split()) - k = (1 << ((a^b).bit_length()-1)) - 1 - if (b|k == b): - m = (b|k)+2 - else: - m = (b | k) -1 - print(b | k, m, (b | k) +1)",2 -ZYC1118#,2057C - Trip to the Olympiad,c++17 ,300244680,300243329,"#include -using namespace std; -#define int long long -#define rep(i ,a ,b) for(int i =a;i<=b;++i) -#define endl '\n' -#define debug(a) cout<<#a<<'='< pii; -int ksm(int a , int b){ - int res = 1; - while(b){ - if(b&1) res = res * a ; - b >>= 1; - a = a * a ; - } - return res; -} -void solve(){ - int l , r; - cin>>l>>r; - int cnt = 0; - - if(r - l == 2){ - cout<>_; - while(_--)solve(); - return 0; -}","#include -using namespace std; -#define int long long -#define rep(i ,a ,b) for(int i =a;i<=b;++i) -#define endl '\n' -#define debug(a) cout<<#a<<'='< pii; -int ksm(int a , int b){ - int res = 1; - while(b){ - if(b&1) res = res * a ; - b >>= 1; - a = a * a ; - } - return res; -} -void solve(){ - int l , r; - cin>>l>>r; - int cnt = 0; - int ans = 0; - while(1){ - if(ksm(2 , cnt) <= r){ - ans = ksm(2 , cnt); - cnt++; - } - else{ - break; - } - - } - - if(ans -2 >= l){ - cout<= 5){ - cout<>_; - while(_--)solve(); - return 0; -}",1 -ChengyunSun#,2057C - Trip to the Olympiad,c++17 ,301249652,301249429,"#include -using namespace std; -int T,l,r,x; -int main(){ - ios::sync_with_stdio(0); - cin.tie(0);cout.tie(0); - cin>>T;while(T--){ - cin>>l>>r; - for(int i=29;i;i--) - if(((l>>i)^(r>>i))&1){ - x=(r>>i|1)< -using namespace std; -int T,l,r,x; -int main(){ - ios::sync_with_stdio(0); - cin.tie(0);cout.tie(0); - cin>>T;while(T--){ - cin>>l>>r; - for(int i=29;i;i--) - if(((l>>i)^(r>>i))&1){ - x=(r>>i|1)<>t; - while(t--){ - int l,r; - cin >> l >> r; - int temp = 0; - for(int i = 30; i >= 0; i--){ - if(((l>>i)&1))temp^=(1< -using namespace std; -#define ll long long - -int main(){ - ll t; - cin>>t; - while(t--){ - ll l,r; - cin>>l>>r; - ll a,b,c; - ll ans=0; - for(int i=30;i>=0;i--){ - ll b1=0; - ll b2=0; - if(l & (1ll << i)) - b1=1; - if(r & (1ll << i)) - b2=1; - if(b1==b2){ - ans+=b1*(1ll < -using namespace std; - -int reverseBits(int n) -{ - int rev = 0; - while (n > 0) { - rev <<= 1; - - if (n & 1 == 1) - rev ^= 1; - n >>= 1; - } - - return rev; -} - -int main(){ - int t; - cin>>t; - while(t--){ - int a,b; - cin>>a>>b; - int c=a+reverseBits(a^b); - cout< // includes cin to read from stdin and cout to write to stdout -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -///LLONG_MAX,INT_MA -#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;i++) -#define REP(i,n) FOR(i,0,(n)-1) -#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--) -#define sz size() -#define FORA(i,c) REP(i,size(c)) - -#define itype(c) __typeof((c).begin()) -#define FORE(e,c) for(itype(c) e=(c).begin();e!=(c).end();e++) -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(),(x).end() -#define SORT(x) sort(all(x)) -#define REVERSE(x) reverse(all(x)) -#define CLEAR(x,c) memset(x,c,sizeof(x)) -#define amfor(Iterator, Container) for ( auto Iterator = begin(Container); (Iterator) != end(Container); ++(Iterator) ) -#define ramfor(Iterator, Container) for ( auto Iterator = Container.rbegin(); (Iterator) != Container.rend(); ++(Iterator) ) -template inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); } -#define NP(nn,ta,a,tb,b) struct nn : pair { nn():pair(){}; nn(ta pa,tb pb):pair(pa,pb){} ta& a(){return first;} tb& b(){return second;} }; -template inline void checkmin(T &a, T b) { if (b < a) a = b; }//asigna en a el minimo -template inline void checkmax(T &a, T b) { if (b > a) a = b; }//asigna en a el maximo - - -typedef long long ll; -using namespace std; // since cin and cout are both in namespace std, this saves some text -typedef vector vll; -typedef vector> vvll; - -int cc; -void Solve() -{ - int l, r; - cin >> l >> r; - int mask = 1 << 30; - while (mask != 0 && (l & mask) ==( r & mask) ) { - mask >>= 1; - } - int a = mask; - int b = mask - 1; - int c; - if (a < r) - c = a + 1; - else - c = b - 1; - cout << a << "" "" << b << "" "" << c; -} -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - cout << std::setprecision(15); - cout << std::fixed; - cin >> cc; - REP(i, cc) - { - Solve(); - cout << endl; - } - return 0; -}"," -#include // includes cin to read from stdin and cout to write to stdout -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -///LLONG_MAX,INT_MA -#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;i++) -#define REP(i,n) FOR(i,0,(n)-1) -#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;i--) -#define sz size() -#define FORA(i,c) REP(i,size(c)) - -#define itype(c) __typeof((c).begin()) -#define FORE(e,c) for(itype(c) e=(c).begin();e!=(c).end();e++) -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(),(x).end() -#define SORT(x) sort(all(x)) -#define REVERSE(x) reverse(all(x)) -#define CLEAR(x,c) memset(x,c,sizeof(x)) -#define amfor(Iterator, Container) for ( auto Iterator = begin(Container); (Iterator) != end(Container); ++(Iterator) ) -#define ramfor(Iterator, Container) for ( auto Iterator = Container.rbegin(); (Iterator) != Container.rend(); ++(Iterator) ) -template inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); } -#define NP(nn,ta,a,tb,b) struct nn : pair { nn():pair(){}; nn(ta pa,tb pb):pair(pa,pb){} ta& a(){return first;} tb& b(){return second;} }; -template inline void checkmin(T &a, T b) { if (b < a) a = b; }//asigna en a el minimo -template inline void checkmax(T &a, T b) { if (b > a) a = b; }//asigna en a el maximo - - -typedef long long ll; -using namespace std; // since cin and cout are both in namespace std, this saves some text -typedef vector vll; -typedef vector> vvll; - -int cc; -void Solve() -{ - int l, r; - cin >> l >> r; - int mask = 1 << 30; - int res = 0; - while (mask != 0 && (l & mask) ==( r & mask) ) { - mask >>= 1; - res |= (l & mask); - } - int a = mask+res; - int b = mask - 1+res; - int c; - if (a < r) - c = a + 1; - else - c = b - 1; - cout << a << "" "" << b << "" "" << c; -} -int main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - cout << std::setprecision(15); - cout << std::fixed; - cin >> cc; - REP(i, cc) - { - Solve(); - cout << endl; - } - return 0; -}",2 -Arkanec,2057C - Trip to the Olympiad,c++17 ,301986607,301987819,"#include - -using namespace std; - -void inline solve() { - int l, r; - cin >> l >> r; - int a = 0, b = 0, c = 0; - for (int mask = 1 << 30; mask > 0; mask >>= 1) { - // cout << ""A "" << a << ' ' << b << ' ' << c << ' ' << mask << '\n'; - if ((l & mask) == (r & mask)) { - a |= (l & mask); - b |= (l & mask); - c |= (l & mask); - } else { - a |= mask; - b |= mask-2; - c |= mask-1; - break; - } - } - cout << a << ' ' << b << ' ' << c << '\n'; - cout << (a ^ b) + (a ^ c) + (b ^ c) << '\n'; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - int t = 1; - cin >> t; - while (t--) solve(); - - return 0; -}","#include - -using namespace std; - -void inline solve() { - int l, r; - cin >> l >> r; - int a = 0, b = 0, c = 0; - for (int mask = 1 << 30; mask > 0; mask >>= 1) { - // cout << ""A "" << a << ' ' << b << ' ' << c << ' ' << mask << '\n'; - if ((l & mask) == (r & mask)) { - a |= (l & mask); - b |= (l & mask); - c |= (l & mask); - } else { - a |= mask; - b |= mask-1; - if (b - 1 >= l) c = b-1; - else c = a + 1; - break; - } - } - cout << a << ' ' << b << ' ' << c << '\n'; - // cout << (a ^ b) + (a ^ c) + (b ^ c) << '\n'; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - int t = 1; - cin >> t; - while (t--) solve(); - - return 0; -}",2 -kknives,2057C - Trip to the Olympiad,c++17 ,302208682,302207017,"#include -#ifdef DEBUG -constexpr bool debug = true; -#else -constexpr bool debug = false; -#endif -using namespace std; -using u64 = uint64_t; -using i64 = int64_t; -using u32 = uint32_t; - -int main() { - int tc; - cin >> tc; - while (tc--) { - u32 l,r; cin >> l >> r; - int k = 31 - __builtin_clz(l^r); - u32 x = l | ((1< -#ifdef DEBUG -constexpr bool debug = true; -#else -constexpr bool debug = false; -#endif -using namespace std; -using u64 = uint64_t; -using i64 = int64_t; -using u32 = uint32_t; - -int main() { - int tc; - cin >> tc; - while (tc--) { - u32 l,r; cin >> l >> r; - u32 x = 1 << (31 - __builtin_clz(r)); - u32 y = x - 1; - u32 z = 0; - for (auto i = l; i <= r; i++) { - if (i != x and i != y){ - z = i; - break; - } - } - if constexpr (debug) { - u32 max = (1 << (32 - __builtin_clz(r))) -1; - max <<= 1; - printf(""%u %u | "", max, (x^y)+(y^z)+(x^z)); - } - printf(""%u %u %u\n"", x, y, z); - } -} -",1 -anon_kun,2057C - Trip to the Olympiad,c++20 ,301156791,301156195,"#include - -using namespace std; - -#define int int64_t -#define ar array - -void solve() { - int l,r; cin >> l >> r; - int k = 0; - for (int i = 0; i <= 30; i++) { - if (((l^r)>>i) & 1) k = i; - } - int x = r & ((1 << 31) - (1 << k)); - if (r == x) cout << l << ' ' << x << ' ' << x-1 << '\n'; - else cout << r << ' ' << x << ' ' << x-1 << '\n'; -} - -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t = 1; cin >> t; - while (t--) { - solve(); - } -}","#include - -using namespace std; - -#define int int64_t -#define ar array - -void solve() { - int l,r; cin >> l >> r; - int k = -1; - for (int i = 0; i <= 30; i++) { - if ((l^r)>>i & 1) k = i; - } - int x = r & (1 << 31 - 1 << k); - if (r = x) cout << l << ' ' << x << ' ' << x-1 << '\n'; - else if (l == x) cout << r << ' ' << x << ' ' << x-1 << '\n'; -} - -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t = 1; cin >> t; - while (t--) { - solve(); - } -}",1 -Arav205,2057C - Trip to the Olympiad,c++17 ,300305114,300305249,"#include -#define ll long long -using namespace std; - -const ll mod = 1e9 + 7; - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - ll l, r; - cin >> l >> r; - - ll ans1 = l; - ll ans2 = 0; - ll ans3 = r; - ll msb = -1; - - - for (ll i = 0; i < 60; i++) { - if ((r & (1LL << i)) != 0) { - msb = i; - } - } - - - for (ll i = msb; i >= 0; i--) { - if ((r & (1LL << i)) != 0 && (l & (1LL << i)) == 0) { - ll temp = ans2; - temp = ans2 | (1LL << i); - if (r == temp) { - ans2 = l; - for (int j = i - 1; j >= 0; j--) { - if ((l & (1LL << j)) == 0) { - ans2 = ans2 | (1LL << j); - } - } - } else { - ans2 = ans2 | (1LL << i); - for(int j=i-1;j>=0;j--) - { - if ((r & (1LL << i)) == 0 && (l & (1LL << i)) == 0) - { - ans1=ans1|(1LL< -#define ll long long -using namespace std; - -const ll mod = 1e9 + 7; - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - ll l, r; - cin >> l >> r; - - ll ans1 = l; - ll ans2 = 0; - ll ans3 = r; - ll msb = -1; - - - for (ll i = 0; i < 60; i++) { - if ((r & (1LL << i)) != 0) { - msb = i; - } - } - - - for (ll i = msb; i >= 0; i--) { - if ((r & (1LL << i)) != 0 && (l & (1LL << i)) == 0) { - ll temp = ans2; - temp = ans2 | (1LL << i); - if (r == temp) { - ans2 = l; - for (int j = i - 1; j >= 0; j--) { - if ((l & (1LL << j)) == 0) { - ans2 = ans2 | (1LL << j); - } - } - } else { - ans2 = ans2 | (1LL << i); - for(int j=i-1;j>=0;j--) - { - if ((r & (1LL << j)) == 0 && (l & (1LL << j)) == 0) - { - ans1=ans1|(1LL< -using namespace std; -#define endl '\n' -using lli = long long; -lli mod = 1e9 + 7; -#define int lli - -void solve(){ - int l,r; - cin>>l>>r; - int ltemp = l; - int rtemp = r; - - int ans = -1; - int i=0; - while(l || r){ - if((l&1)!=(r&1)){ - ans = max(ans, i); - } - l=l>>1; - r=r>>1; - i++; - } - - //cout<>t; - while(t--){ - solve(); - } - -}","#include -using namespace std; -#define endl '\n' -using lli = long long; -lli mod = 1e9 + 7; -#define int lli - -void solve(){ - int l,r; - cin>>l>>r; - int ltemp = l; - int rtemp = r; - - int ans = -1; - int i=0; - while(l || r){ - if((l&1)!=(r&1)){ - ans = max(ans, i); - } - l=l>>1; - r=r>>1; - i++; - } - - //cout<ans; i--){ - if((rtemp>>i)&1){ - num1|=(1<>t; - while(t--){ - solve(); - } - -}",2 -AceTaffy258,2057C - Trip to the Olympiad,c++20 ,300842146,300842428,"#include -#pragma optimzie(2) -#define ll long long -using namespace std; - -int l,r; -int main() { - ios::sync_with_stdio(false); - cin.tie(NULL), cout.tie(NULL); - int T;cin>>T; - while(T--){ - cin>>l>>r; - int a,b,c; - for(int i=30;i>=0;i--){ - int p=1< -#pragma optimzie(2) -#define ll long long -using namespace std; - -int l,r; -int main() { - ios::sync_with_stdio(false); - cin.tie(NULL), cout.tie(NULL); - int T;cin>>T; - while(T--){ - cin>>l>>r; - int a=0,b=0,c=0; - for(int i=30;i>=0;i--){ - int p=1< -#include -#include -#define pb push_back -#define INF 0x3f3f3f3f -#define LINF 0x3f3f3f3f3f3f3f3f -#define endl '\n' -#define ll long long -#define f first -#define fin cin -#define fout cout -#define s second -#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) -#define debug(x) cout << ""DEBUG "" << x << endl -#define debug2(x, y) cout << ""DEBUG "" << x << "" "" << y << endl -#define debug3(x, y, z) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< endl -#define debug4(x, y, z, o) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< "" "" << o << endl -#define all(x) x.begin(), x.end() -#define left esquerda -#define lb lower_bound -#define right direita -using namespace std; -void setIO(string s) { -ios_base::sync_with_stdio(0); cin.tie(0); -freopen((s+"".in"").c_str(),""r"",stdin); -freopen((s+"".out"").c_str( ),""w"",stdout); -} -typedef pair pii; -typedef vector> mat; -typedef pair pis; -const ll mod = 1e9 + 7, MAXN = 2e5 + 5; -typedef vector vi; -typedef pair> piii; - -void solve() { - ll l, r; - cin >> l >> r; - - ll last = 1; - while(last * 2 <= r) - last *= 2; - - if(last - 1 >= l && last + 1 <= r) { - cout << last - 1 << "" "" << last << "" "" << last + 1 << endl; - return; - } - - if(last == r) { - cout << l << "" "" << last - 1 << "" "" << last << endl; - return; - } - - if(last == l) { - cout << r << "" "" << r << "" "" << l << endl; - } - - - ll aux = last; - for(int i = 30; i >= 0 ; i--) - if(aux + (1ll << i) <= r && !(r & (1<> ct; - while(ct--) - solve(); -}","#include -#include -#include -#define pb push_back -#define INF 0x3f3f3f3f -#define LINF 0x3f3f3f3f3f3f3f3f -#define endl '\n' -#define ll long long -#define f first -#define fin cin -#define fout cout -#define s second -#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) -#define debug(x) cout << ""DEBUG "" << x << endl -#define debug2(x, y) cout << ""DEBUG "" << x << "" "" << y << endl -#define debug3(x, y, z) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< endl -#define debug4(x, y, z, o) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< "" "" << o << endl -#define all(x) x.begin(), x.end() -#define left esquerda -#define lb lower_bound -#define right direita -using namespace std; -void setIO(string s) { -ios_base::sync_with_stdio(0); cin.tie(0); -freopen((s+"".in"").c_str(),""r"",stdin); -freopen((s+"".out"").c_str( ),""w"",stdout); -} -typedef pair pii; -typedef vector> mat; -typedef pair pis; -const ll mod = 1e9 + 7, MAXN = 2e5 + 5; -typedef vector vi; -typedef pair> piii; - -void solve() { - ll l, r; - cin >> l >> r; - - ll last = 1; - while(last * 2 <= r) - last *= 2; - - int aux = last; - while(true) { - if( (last & r) && !(last & l)) { - aux += last; - break; - } - last /= 2; - } - - cout << aux-1 << "" "" << aux << "" "" << aux + 2 << endl; - -} - -int32_t main() { - int ct; - cin >> ct; - while(ct--) - solve(); -}",2 -who_kn0ws,2057C - Trip to the Olympiad,c++17 ,307463116,307380904,"#include -using namespace std; -#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); -#define ll long long -#define e '\n' -#define pb push_back -#define yes ""yes"" -#define no ""no"" -#define F first -#define S second -//#define srt(a) sort(a,a+n) -//#define srt(v) s5ort(v.begin(),v.end()) -//#define srt(u) sort(u.begin(),u.end()) -#define loop for(i=1;i<=n;i++) -const int mod=1e9+7; -const int MOD=998244353; -const int lx=1e5+25; -//pairp[222222]; -//mapmp; -//typedef pair pi; -//sort(p,p+n,greater>());-sort vector pair decending order -//priority_queue,greater>pq; -//priority_queue,greater>pq;-minheap -//priority_queue>pq; -//s.erase(position,length) - -void solve(){ - ll l, r, c1=0; - cin>>l>>r; - - vectorv, v1, v2, v3; - for(int i=0; i<=30; i++){ - v.pb(pow(2,i)); - } - - ll a, b, c, n = v.size(); - a = r; - mapmp; - for(int i=n-1; i>=0; i--){ - if(a >= v[i]){ - v1.pb(1); - a-=v[i]; - mp[v[i]]++; - } - else - v1.pb(0); - } - b = l, c1=0; - for(int i=n-1; i>=0; i--){ - if(b >= v[i]){ - v2.pb(1); - b-=v[i]; - mp[v[i]]++; - } - else - v2.pb(0); - } - a = 0, b = 0; - reverse(v.begin(), v.end()); - for(int i=0; ia) - c = a+1; - else - c = b-1; - - cout<>test; - while(test--){ - solve(); - } - return 0; -} - -// **Number Theory*** - -// sort(a+1,a+n+1); -// long long gcd=a[1]; -// for(int i=2;i<=n;i++){ -// gcd = __gcd(a[i],gcd); -// } -// cout<>n; -// p=stoi(t); -// std:: string s = std::to_string(n); -// cout< -using namespace std; -#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); -#define ll long long -#define e '\n' -#define pb push_back -#define yes ""yes"" -#define no ""no"" -#define F first -#define S second -//#define srt(a) sort(a,a+n) -//#define srt(v) s5ort(v.begin(),v.end()) -//#define srt(u) sort(u.begin(),u.end()) -#define loop for(i=1;i<=n;i++) -const int mod=1e9+7; -const int MOD=998244353; -const int lx=1e5+25; -//pairp[222222]; -//mapmp; -//typedef pair pi; -//sort(p,p+n,greater>());-sort vector pair decending order -//priority_queue,greater>pq; -//priority_queue,greater>pq;-minheap -//priority_queue>pq; -//s.erase(position,length) - -void solve(){ - ll l, r, c1=0; - cin>>l>>r; - - vectorv, v1, v2, v3; - for(int i=0; i<=30; i++){ - v.pb(pow(2,i)); - } - - //reverse(v.begin(), v.end()); - ll a, b, c, n = v.size(); - a = r; - mapmp; - for(int i=n-1; i>=0; i--){ - if(a >= v[i]){ - v1.pb(1); - a-=v[i]; - mp[v[i]]++; - c1++; - } - else if(c1>0) - v1.pb(0); - } - b = l, c1=0; - for(int i=n-1; i>=0; i--){ - if(b >= v[i]){ - v2.pb(1); - b-=v[i]; - mp[v[i]]++; - c1++; - } - else if(c1>0) - v2.pb(0); - } - - - ll x = l+1, y = r-1; - c1=0, c=0; - for(int i=n-1; i>=0; i--){ - if(mp[v[i]] == 0){ - if(v[i]>=x && v[i]<=y){ - x-=v[i], y-=v[i]; - v3.pb(1); - c+=v[i]; - } - else - v3.pb(0); - - } - else if(mp[v[i]]>0){ - ll sum=0; - for(int j=i-1; j>=0; j--) - sum+=v[j]; - if(sum>=x && sum<=y) - v3.pb(0); - else{ - if(v[i]<=x && v[i]<=y){ - x-=v[i], y-=v[i]; - v3.pb(1); - c+=v[i]; - } - else - v3.pb(0); - } - } - - //cout<>test; - while(test--){ - solve(); - } - return 0; -} - -// **Number Theory*** - -// sort(a+1,a+n+1); -// long long gcd=a[1]; -// for(int i=2;i<=n;i++){ -// gcd = __gcd(a[i],gcd); -// } -// cout<>n; -// p=stoi(t); -// std:: string s = std::to_string(n); -// cout< -using namespace std; -#define int long long -int t,l,r; -void work() -{ - for(int w = (1ll << 30);w >= 1;w >>= 1) - if((l & w) != (r & w)) { - int x = r / w * w; - cout<>t; - while(t--) cin>>l>>r,work(); - - return 0; -}","#include -using namespace std; -#define int long long -int t,l,r; -void work() -{ - for(int w = (1ll << 30);w >= 1;w >>= 1) - if((l & w) != (r & w)) { - int x = r / w * w; - cout<>t; - while(t--) cin>>l>>r,work(); - - return 0; -}",1 -SmHaInT,2057C - Trip to the Olympiad,c++23 ,300807286,300806178,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -//#define int long long -#define ll long long -#define PA pair -#define MAXN 100100 - - -void solve() { - ll l, r; cin >> l >> r; - - int k = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l); - cout << a << "" "" << b << "" "" << c << ""\n""; -} - -signed main() { - int t = 1; cin >> t; - while (t--) { - solve(); - } -} - -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -//#define int long long -#define ll long long -#define PA pair -#define MAXN 100100 - - -void solve() { - ll l, r; cin >> l >> r; - ll b = l; - - functioncheck = [&](ll num)->bool { - return num >= l && num <= r; - }; - - bool w = false; - for (int i = 30; i >= 0; i--) { - if ((l & (1 << i)) != (r & (1 << i))) { - - } - else { - if(check(b^(1<> t; - while (t--) { - solve(); - } -} - -",1 -KurisuMakise,2057C - Trip to the Olympiad,c++17 ,306844917,306844757,"// by iodwad -#include - -using namespace std; - -void Solve() { - int l, r, k; cin >> l >> r; - for (int i = 30; ~i; --i) { - if ((l ^ r) & (1 << i)) { - k = i; - break; - } - } - int a, b, c; - int tmp = (l >> k + 1) << k + 1; - a = (1 << k) - 1 + tmp; b = a + 1; c = l; - if (a == c) c = r; - printf(""%d %d %d\n"", a, b, c); -} - -int main() { - int cases; cin >> cases; - while (cases--) { - Solve(); - } - return 0; -}","// by iodwad -#include - -using namespace std; - -void Solve() { - int l, r, k; cin >> l >> r; - for (int i = 30; ~i; --i) { - if ((l ^ r) & (1 << i)) { - k = i; - break; - } - } - int a, b, c; - int tmp = (l >> k + 1) << k + 1; - a = (1 << k) - 1 + tmp; b = a + 1; c = l; - if (a == c) c = r; - printf(""%d %d %d\n"", a, b, c); -} - -int main() { - int cases; cin >> cases; - while (cases--) { - Solve(); - } - return 0; -} -/",1 -academicRothko,2057C - Trip to the Olympiad,c++23 ,300902701,300902562,"#include -using namespace std; - -void solve() { - int l, r; - cin >> l >> r; - - // Find the highest bit where l and r differ. - // __builtin_clz(x) gives the number of leading zeros in x, - // so 31 - __builtin_clz(l ^ r) is the position of that highest differing bit (0-based). - int k = 31 - __builtin_clz(l ^ r); - - // Construct a by setting all bits below k to 1 in l. - int a = l | ((1 << k) - 1); - - // Then b is just a+1, and c is the opposite endpoint if a == l, else c = l. - int b = a + 1; - int c = (a == l ? r : l); - - // If b > r (edge case), simply pick the top three distinct values near r. - // This handles the case where a+1 might exceed r. - if (b > r) { - a = r - 2; - b = r - 1; - c = r; - } - - cout << a << "" "" << b << "" "" << c << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - long long l, r; - cin >> l >> r; - - // Gather at most the last 8 numbers in [l, r]. - long long start = max(l, r - 7); - vector cand; - for (long long x = start; x <= r; x++) { - cand.push_back(x); - } - - // Brute force all distinct triples among these candidates. - long long bestVal = -1; - array bestTriple = {l, l+1, l+2}; // just a valid placeholder - int sz = (int)cand.size(); - for (int i = 0; i < sz; i++) { - for (int j = i + 1; j < sz; j++) { - for (int k = j + 1; k < sz; k++) { - long long a = cand[i], b = cand[j], c = cand[k]; - long long val = (a ^ b) + (b ^ c) + (a ^ c); - if (val > bestVal) { - bestVal = val; - bestTriple = {a, b, c}; - } - } - } - } - - // Output any triple that maximizes the expression. - cout << bestTriple[0] << "" "" - << bestTriple[1] << "" "" - << bestTriple[2] << ""\n""; - } - return 0; -} -",1 -shashankraj1907,2057C - Trip to the Olympiad,c++23 ,300627176,300626860,"#include -using namespace std; -typedef vector vi; -#define ll long long -#define mp make_pair -#define yes cout << ""YES"" << ""\n"" -#define no cout << ""NO"" << ""\n"" - -void solve() { - ll l,r; - cin>>l>>r; - int k = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l); - std::cout << a << "" "" << b << "" "" << c << ""\n""; -} - - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t=1; - cin>>t; - while(t--) solve(); - return 0; -}","#include -using namespace std; -typedef vector vi; -#define ll long long -#define mp make_pair -#define yes cout << ""YES"" << ""\n"" -#define no cout << ""NO"" << ""\n"" - -string decimalToBinary(ll decimal_number){ - bitset<64> binary(decimal_number); - return binary.to_string(); -} - -ll binaryToDecimal(string &binary_string){ - bitset<64> binary(binary_string); - return binary.to_ullong(); -} - -void solve() { - ll l,r; - cin>>l>>r; - string a,b; - a = decimalToBinary(l); - b = decimalToBinary(r); - ll x,y,z; - for(ll i=0; i>t; - while(t--) solve(); - return 0; -}",1 -sheyigang,2057C - Trip to the Olympiad,c++20 ,301692150,301694145,"#include -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -#define endl '\n' -#define INT __int128 -#define N 100010 - -using namespace std; -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned int; - -int lowbit(int t) -{ - return t * -t; -} - -void sol() -{ - int l, r; - cin >> l >> r; - int t = l ^ r; - while(t != lowbit(t)) - t -= lowbit(t); - t |= l; - int a, b, c; - a = t, b = t - 1, c = r; - while(c == a || c == b) c --; - cout << a << ' ' << b << ' ' << c << endl; -} - -int main() -{ - IOS; - int t = 1; - cin >> t; - while(t--) - sol(); - return 0; -}","#include -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -//#define endl '\n' -#define INT __int128 -#define N 100010 - -using namespace std; -using i64 = long long; -using u64 = unsigned long long; -using u32 = unsigned int; - -int lowbit(int t) -{ - return t & -t; -} - -void sol() -{ - int l, r; - cin >> l >> r; - int t = l ^ r; -// cout << t << endl; - while(t != lowbit(t)) - t -= lowbit(t); -// cout << t << endl; - t = (l / t * t) | t; -// cout << t << endl; - int a, b, c; - a = t, b = t - 1, c = r; - while(c == a || c == b) c --; - cout << a << ' ' << b << ' ' << c << endl; -} - -int main() -{ - IOS; - int t = 1; - cin >> t; - while(t--) - sol(); - return 0; -}",2 -seone7,2057C - Trip to the Olympiad,c++23 ,301269344,301265131,"#pragma GCC optimize(""Ofast,unroll-loops,no-stack-protector,fast-math,inline"") -#include -using namespace std; - -using ll = int64_t; -using ull = uint64_t; -using uint = uint32_t; -using i8 = int8_t; -using u8 = uint8_t; -using ish = int16_t; -using ush = uint16_t; - -const ll MOD = 1e9 + 7; -const ll OMOD = 998'244'353; - -inline namespace IO { -#define SFINAE(x, ...) \ - template struct x : std::false_type {}; \ - template struct x> : std::true_type {} - -SFINAE(DefaultI, decltype(std::cin >> std::declval())); -SFINAE(DefaultO, decltype(std::cout << std::declval())); -SFINAE(IsTuple, typename std::tuple_size::type); -SFINAE(Iterable, decltype(std::begin(std::declval()))); - -template struct Reader { - template void Impl(T &t) { - if constexpr (DefaultI::value) - is >> t; - else if constexpr (Iterable::value) { - for (auto &x : t) - Impl(x); - } else if constexpr (IsTuple::value) { - std::apply([this](auto &...args) { (Impl(args), ...); }, t); - } else - static_assert(IsTuple::value, ""No matching type for read""); - } - template void read(Ts &...ts) { ((Impl(ts)), ...); } -}; - -template void re(Ts &...ts) { Reader{}.read(ts...); } -#define def(t, args...) \ - t args; \ - re(args); - -template struct Writer { - string comma() const { return debug ? "","" : """"; } - template constexpr char Space(const T &) const { - return print_nd && (Iterable::value or IsTuple::value) ? '\n' : ' '; - } - template void Impl(T const &t) const { - if constexpr (DefaultO::value) - os << t; - else if constexpr (Iterable::value) { - if (debug) - os << '{'; - int i = 0; - for (auto &&x : t) - ((i++) ? (os << comma() << Space(x), Impl(x)) : Impl(x)); - if (debug) - os << '}'; - } else if constexpr (IsTuple::value) { - if (debug) - os << '('; - std::apply( - [this](auto const &...args) { - int i = 0; - (((i++) ? (os << comma() << "" "", Impl(args)) : Impl(args)), ...); - }, - t); - if (debug) - os << ')'; - } else - static_assert(IsTuple::value, ""No matching type for print""); - } - template void ImplWrapper(T const &t) const { - if (debug) - os << ""\033[0;31m""; - Impl(t); - if (debug) - os << ""\033[0m""; - } - template void print(Ts const &...ts) const { ((Impl(ts)), ...); } - template - void print_with_sep(const std::string &sep, F const &f, Ts const &...ts) const { - ImplWrapper(f), ((os << sep, ImplWrapper(ts)), ...), os << '\n'; - } - void print_with_sep(const std::string &) const { os << '\n'; } -}; - -template void pr(Ts const &...ts) { Writer{}.print(ts...); } -template void ps(Ts const &...ts) { Writer{}.print_with_sep("" "", ts...); } -} // namespace IO - -inline namespace Debug { -template void err(Args... args) { - Writer{}.print_with_sep("" | "", args...); -} -template void errn(Args... args) { - Writer{}.print_with_sep("" | "", args...); -} - -void err_prefix(string func, int line, string args) { - cerr << ""\033[0;31m\u001b[1mDEBUG\033[0m"" - << "" | "" - << ""\u001b[34m"" << func << ""\033[0m"" - << "":"" - << ""\u001b[34m"" << line << ""\033[0m"" - << "" - "" - << ""["" << args << ""] = ""; -} - -#ifdef LOCAL -#define clg(args...) err_prefix(__FUNCTION__, __LINE__, #args), err(args) -#else -#define clg(...) -#endif - -} // namespace Debug - -void solve() { - int L, r; - cin >> L >> r; - string h = bitset<32>(r).to_string(); - string l = bitset<32>(L).to_string(); - char ans[33]; - ans[32] = '\0'; - bool f = true; - bool f2 = true; - bool f3 = false; - for (int i = 0; i < 32; ++i) { - if (f) { - if (h[i] == l[i]) { - ans[i] = h[i]; - } else { - f = false; - --i; - } - } else { - if (f2) { - if ((h[i + 1] == l[i + 1] && h[i + 1] == '1') || (h[i + 1] == '1' && l[i + 1] == '0')) { - ans[i] = '1'; - ans[i + 1] = '0'; - ++i; - f3 = true; - f2 = false; - continue; - } else if (h[i + 1] == l[i + 1] && h[i + 1] == '0') { - ans[i] = '0'; - ans[i + 1] = '1'; - ++i; - f3 = true; - f2 = false; - continue; - } else { - bool isallzero = true; - for (int j = i + 1; j < 32; ++j) { - if (h[j] == '0') { - } else { - isallzero = false; - break; - } - } - if (isallzero) { - ans[i] = '0'; - for (int j = i + 1; j < 32; ++j) { - ans[j] = '1'; - } - pr(L, "" ""); - pr(stol(ans, nullptr, 2)); - pr("" "", r); - ps(); - return; - } else { - ans[i] = '1'; - for (int j = i + 1; j < 32; ++j) { - ans[j] = '0'; - } - for (int j = i + 1; j < 32; ++j) { - l[j] = '1'; - } - ps(stol(h, nullptr, 2), stol(ans, nullptr, 2), stol(l, nullptr, 2)); - return; - } - } - } - if (f3) { - if (h[i] == l[i] && h[i] == '1') { - ans[i] = '0'; - } else { - ans[i] = '1'; - } - } - } - } - ps(L, stol(ans, nullptr, 2), r); -} - -int main() { -#if defined(LOCAL) - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios::sync_with_stdio(0); - cin.tie(0); - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - return 0; -}","#pragma GCC optimize(""Ofast,unroll-loops,no-stack-protector,fast-math,inline"") -#include -using namespace std; - -using ll = int64_t; -using ull = uint64_t; -using uint = uint32_t; -using i8 = int8_t; -using u8 = uint8_t; -using ish = int16_t; -using ush = uint16_t; - -const ll MOD = 1e9 + 7; -const ll OMOD = 998'244'353; - -inline namespace IO { -#define SFINAE(x, ...) \ - template struct x : std::false_type {}; \ - template struct x> : std::true_type {} - -SFINAE(DefaultI, decltype(std::cin >> std::declval())); -SFINAE(DefaultO, decltype(std::cout << std::declval())); -SFINAE(IsTuple, typename std::tuple_size::type); -SFINAE(Iterable, decltype(std::begin(std::declval()))); - -template struct Reader { - template void Impl(T &t) { - if constexpr (DefaultI::value) - is >> t; - else if constexpr (Iterable::value) { - for (auto &x : t) - Impl(x); - } else if constexpr (IsTuple::value) { - std::apply([this](auto &...args) { (Impl(args), ...); }, t); - } else - static_assert(IsTuple::value, ""No matching type for read""); - } - template void read(Ts &...ts) { ((Impl(ts)), ...); } -}; - -template void re(Ts &...ts) { Reader{}.read(ts...); } -#define def(t, args...) \ - t args; \ - re(args); - -template struct Writer { - string comma() const { return debug ? "","" : """"; } - template constexpr char Space(const T &) const { - return print_nd && (Iterable::value or IsTuple::value) ? '\n' : ' '; - } - template void Impl(T const &t) const { - if constexpr (DefaultO::value) - os << t; - else if constexpr (Iterable::value) { - if (debug) - os << '{'; - int i = 0; - for (auto &&x : t) - ((i++) ? (os << comma() << Space(x), Impl(x)) : Impl(x)); - if (debug) - os << '}'; - } else if constexpr (IsTuple::value) { - if (debug) - os << '('; - std::apply( - [this](auto const &...args) { - int i = 0; - (((i++) ? (os << comma() << "" "", Impl(args)) : Impl(args)), ...); - }, - t); - if (debug) - os << ')'; - } else - static_assert(IsTuple::value, ""No matching type for print""); - } - template void ImplWrapper(T const &t) const { - if (debug) - os << ""\033[0;31m""; - Impl(t); - if (debug) - os << ""\033[0m""; - } - template void print(Ts const &...ts) const { ((Impl(ts)), ...); } - template - void print_with_sep(const std::string &sep, F const &f, Ts const &...ts) const { - ImplWrapper(f), ((os << sep, ImplWrapper(ts)), ...), os << '\n'; - } - void print_with_sep(const std::string &) const { os << '\n'; } -}; - -template void pr(Ts const &...ts) { Writer{}.print(ts...); } -template void ps(Ts const &...ts) { Writer{}.print_with_sep("" "", ts...); } -} // namespace IO - -inline namespace Debug { -template void err(Args... args) { - Writer{}.print_with_sep("" | "", args...); -} -template void errn(Args... args) { - Writer{}.print_with_sep("" | "", args...); -} - -void err_prefix(string func, int line, string args) { - cerr << ""\033[0;31m\u001b[1mDEBUG\033[0m"" - << "" | "" - << ""\u001b[34m"" << func << ""\033[0m"" - << "":"" - << ""\u001b[34m"" << line << ""\033[0m"" - << "" - "" - << ""["" << args << ""] = ""; -} - -#ifdef LOCAL -#define clg(args...) err_prefix(__FUNCTION__, __LINE__, #args), err(args) -#else -#define clg(...) -#endif - -} // namespace Debug - -void solve() { - int L, r; - cin >> L >> r; - string h = bitset<32>(r).to_string(); - string l = bitset<32>(L).to_string(); - char ans[32]; - bool f = true; - bool f2 = true; - bool f3 = false; - for (int i = 0; i < 32; ++i) { - if (f) { - if (h[i] == l[i]) { - ans[i] = h[i]; - } - } else { - f = false; - if (f2) { - if ((h[i + 1] == l[i + 1] && h[i + 1] == '1') || (h[i + 1] == '1' && l[i + 1] == '0')) { - ans[i] = '1'; - ans[i + 1] = '0'; - ++i; - f3 = true; - f2 = false; - } else if (h[i + 1] == l[i + 1] && h[i + 1] == '0') { - ans[i] = '1'; - ans[i + 1] = '0'; - ++i; - f3 = true; - f2 = false; - } else { - bool isallzero = true; - for (int j = i + 1; j < 32; ++j) { - if (h[j] == '0') { - } else { - isallzero = false; - break; - } - } - if (isallzero) { - ans[i] = '0'; - for (int j = i + 1; j < 32; ++j) { - ans[i] = '1'; - } - pr(l, "" ""); - pr(stol(ans, nullptr, 2)); - pr("" "", r); - ps(); - return; - } else { - ans[i] = '1'; - for (int j = i + 1; j < 32; ++j) { - ans[i] = '0'; - } - for (int j = i + 1; j < 32; ++j) { - l[i] = '1'; - } - ps(stol(h, nullptr, 2), stol(ans, nullptr, 2), stol(l, nullptr, 2)); - return; - } - } - } - if (f3) { - if (h[i] == l[i] && h[i] == '1') { - ans[i] = '0'; - } else { - ans[i] = '1'; - } - } - } - } - ps(L, stol(ans, nullptr, 2), r); -} - -int main() { -#if defined(LOCAL) - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios::sync_with_stdio(0); - cin.tie(0); - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - return 0; -}",1 -TianTianChaoFangDe,2057C - Trip to the Olympiad,c++20 ,300308290,300309161,"// Problem: C. Trip to the Olympiad -// Contest: Codeforces - Hello 2025 -// URL: https://codeforces.com/contest/2057/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -#define int long long -#define inf 2e18 -#define ull unsigned long long -#define ls o << 1 -#define rs o << 1 | 1 - -using namespace std; - -const int N = 2e5 + 9; - -void solve() -{ - int l, r;cin >> l >> r; - - int suml = 0, sumr = 0; - - int tmp = l; - while(tmp) { - suml ++; - tmp >>= 1; - } - - tmp = r; - while(tmp) { - sumr ++; - tmp >>= 1; - } - - int a = 0, b = 0, c = 0; - if(sumr > suml) { - a = 1ll << (sumr - 1); - b = a - 1; - c = l; - while(c == a || c == b)c ++; - } else { - int idx; - for(idx = sumr;idx >= 1;idx --) { - a = (a | (1ll << (idx - 1))); - if((r & (1ll << (idx - 1))) != (l & (1ll << (idx - 1)))) - break; - } - - a = (a | (1ll << (idx - 1))); - b = a - 1; - c = l; - while(c == a || c == b)c ++; - } - - cout << a << ' ' << b << ' ' << c << '\n'; -} - -signed main() -{ - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int t = 1;cin >> t; - while(t --)solve(); - - return 0; -} - - -/* -What you want is what you love, so fight for it! -*/ -","// Problem: C. Trip to the Olympiad -// Contest: Codeforces - Hello 2025 -// URL: https://codeforces.com/contest/2057/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -#define int long long -#define inf 2e18 -#define ull unsigned long long -#define ls o << 1 -#define rs o << 1 | 1 - -using namespace std; - -const int N = 2e5 + 9; - -void solve() -{ - int l, r;cin >> l >> r; - - int suml = 0, sumr = 0; - - int tmp = l; - while(tmp) { - suml ++; - tmp >>= 1; - } - - tmp = r; - while(tmp) { - sumr ++; - tmp >>= 1; - } - - int a = 0, b = 0, c = 0; - if(sumr > suml) { - a = 1ll << (sumr - 1); - b = a - 1; - c = l; - while(c == a || c == b)c ++; - } else { - int idx; - for(idx = sumr;idx >= 1;idx --) { - a = (a | (r & (1ll << (idx - 1)))); - if((r & (1ll << (idx - 1))) != (l & (1ll << (idx - 1)))) - break; - } - - a = (a | (1ll << (idx - 1))); - b = a - 1; - c = l; - while(c == a || c == b)c ++; - } - - cout << a << ' ' << b << ' ' << c << '\n'; -} - -signed main() -{ - ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); - - int t = 1;cin >> t; - while(t --)solve(); - - return 0; -} - - -/* -What you want is what you love, so fight for it! -*/ -",2 -Jkel,2057C - Trip to the Olympiad,c++23 ,306668499,306667831,"#include -#define int long long -using namespace std; -#define bug(BUG) cout << ""bug:# "" << (BUG) << endl -#define bug2(BUG1, BUG2) cout << ""bug:# "" << (BUG1) << "" "" << (BUG2) << endl -#define bug3(BUG1, BUG2, BUG3) cout << ""bug:# "" << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl -#define bugv(VEC) \ - { \ - for (auto Vec : VEC) \ - cout << Vec << ' '; \ - cout << '\n'; \ - } - -void _(); -signed main() -{ - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - cout << fixed << setprecision(10); - int T = 1; - cin >> T; - while (T--) - _(); - return 0; -} - -void _() -{ - int l, r; - cin >> l >> r; - int a = 0, b = 0, c = 0; - int hi = 32; - for (;; hi--) - { - int r_bit = r >> hi & 1, l_bit = l >> hi & 1; - if (r_bit - l_bit) - break; - else if (l_bit) - { - a |= 1 << hi, b |= 1 << hi, c |= 1 << hi; - } - } - c |= 1 << hi; - b = c - 1; - a = b - 1 < l ? c + 1 : b - 1; - cout << a << ' ' << b << ' ' << c << '\n'; -} -// void _() -// { -// int a, b, c; -// cin >> a >> b >> c; -// cout << (a ^ b) + (b ^ c) + (a ^ c) << '\n'; -// }","#include -#define int long long -using namespace std; -#define bug(BUG) cout << ""bug:# "" << (BUG) << endl -#define bug2(BUG1, BUG2) cout << ""bug:# "" << (BUG1) << "" "" << (BUG2) << endl -#define bug3(BUG1, BUG2, BUG3) cout << ""bug:# "" << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl -#define bugv(VEC) \ - { \ - for (auto Vec : VEC) \ - cout << Vec << ' '; \ - cout << '\n'; \ - } - -void _(); -signed main() -{ - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - cout << fixed << setprecision(10); - int T = 1; - cin >> T; - while (T--) - _(); - return 0; -} - -void _() -{ - int l, r; - cin >> l >> r; - int a = 0, b = 0, c = 0; - int hi = 32; - for (;; hi--) - { - int r_bit = r >> hi & 1, l_bit = l >> hi & 1; - if (r_bit - l_bit) - break; - else if (l_bit) - { - a |= 1 << hi, b |= 1 << hi, c |= 1 << hi; - } - } - c |= 1 << hi; - b = c - 1; - a = b - 1; - cout << a << ' ' << b << ' ' << c << '\n'; -} -// void _() -// { -// int a, b, c; -// cin >> a >> b >> c; -// cout << (a ^ b) + (b ^ c) + (a ^ c) << '\n'; -// }",1 -HYMonkey,2057C - Trip to the Olympiad,c++23 ,301224306,301223605,"// #define ONLINE_JUDGE 1 -// clang-format off -#include -using namespace std; -using ll = long long; using ull = unsigned long long; using pll = pair; -#define all(a) (a).begin(),(a).end() -#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) -const ll N = 2e6 + 10; -#ifdef ONLINE_JUDGE -#define dbg(x) -#else -#define dbg(x) cerr << #x << ""=="" << (x) << '\n' << flush; -#endif -template void input(T &...a) { (cin >> ... >> a); } -template bool chmax(T &a, const U b) {return a bool chmin(T &a, const U b) {return a>b?a=b,true:false; } -// clang-format on -bool gbit(ll n, ll k) { return (n >> k) & 1; } -void solve() -{ - LL(l, r); - vector ans(3); - ll now = 0; - ll base = 0; - for (ll k = 30; k >= 0; k--) - { - if (gbit(l, k) != gbit(r, k)) - { - now = k; - break; - } - base |= (gbit(l, k) << k); - } - ll a = (1 << now), b = a - 1; - a |= base, b |= base; - ll c = (b - 1 >= l ? b - 1 : a + 1); - cout << a << ' ' << b << ' ' << c << '\n'; -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - ll T = 1; - cin >> T; - while (T--) solve(); - return 0; -}","// #define ONLINE_JUDGE 1 -// clang-format off -#include -using namespace std; -using ll = long long; using ull = unsigned long long; using pll = pair; -#define all(a) (a).begin(),(a).end() -#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) -const ll N = 2e6 + 10; -#ifdef ONLINE_JUDGE -#define dbg(x) -#else -#define dbg(x) cerr << #x << ""=="" << (x) << '\n' << flush; -#endif -template void input(T &...a) { (cin >> ... >> a); } -template bool chmax(T &a, const U b) {return a bool chmin(T &a, const U b) {return a>b?a=b,true:false; } -// clang-format on -bool gbit(ll n, ll k) { return (n >> k) & 1; } -void solve() -{ - LL(l, r); - vector ans(3); - ll now = 0; - for (ll k = 30; k >= 0; k--) - { - if (gbit(l, k) != gbit(r, k)) - { - now = k; - break; - } - } - ll a = (1 << now), b = a - 1, c = (b - 1 >= l ? b - 1 : a + 1); - cout << a << ' ' << b << ' ' << c << '\n'; -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - ll T = 1; - cin >> T; - while (T--) solve(); - return 0; -}",1 -Shrey09,2057C - Trip to the Olympiad,c++17 ,300557686,300557588,"#include -using namespace std; -#define int long long - -int32_t main() -{ - int t; - cin>>t; - while(t--){ - int l,r; - cin>>l>>r; - if(r-l==2){ - cout<val){ - int a=(x+1)*val; - if(a-2>=l){ - cout<=l){ - cout< -using namespace std; -#define int long long - -int32_t main() -{ - int t; - cin>>t; - while(t--){ - int l,r; - cin>>l>>r; - if(r-l==2){ - cout<val){ - int a=(x+1)*val; - if(a-2>=l){ - cout<=l){ - cout< -#include -#include - -using namespace std; -using namespace chrono; - -using namespace __gnu_pbds; - - -template -using orderedSet = tree, rb_tree_tag, tree_order_statistics_node_update>; -template -using orderedMultiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// find_by_order(k) -> iterator at k -// order_of_key(k) -> number of items that are strictly smaller than k - - -#define FASTIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD1 1000000007 -#define MOD9 998244353 -#define INF 1e9 -#define INF1 1e18 -#define endl ""\n"" -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define lb lower_bound -#define ub upper_bound -#define fcout cout< vi; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector > vvi; -typedef vector vpii; -typedef vector vpll; -template using PQ = priority_queue; -template using QP = priority_queue, greater>; -// ---------------------------------------------------------------------------------- - -// ---------------------------------- OPERATOR OVERLOADING --------------------------------------- -template -istream& operator>>(istream &istream, vector &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &x : v) cout << x << "" ""; return ostream; } -template -istream& operator>>(istream &istream, pair &p) { return (istream >> p.ff >> p.ss); } -template -ostream& operator<<(ostream &ostream, const pair &p) { return (ostream << p.ff << "" "" << p.ss); } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -// ------------------------------------------------------------------------------------------------ - - -// ------------------------------------------ DEBUG ------------------------------------------------ -#ifndef ONLINE_JUDGE -#define debug(x...) cerr <<__func__<<"":""<<__LINE__<<"" ["" << #x << ""] = ""; _print(x); cerr << endl; -#define HERE cerr <<__func__<<"":""<<__LINE__<<"" [ here ] ""; cerr << endl; -#else -#define debug(x...) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(vector > v) {cerr << ""{ ""; for (vector i : v) {cerr << ""[ ""; for (T j : i) {_print(j); cerr << "" "";}; cerr << ""] "";} cerr << ""}"";} -template void _print(vector < pair > vp) {cerr << ""{ ""; for (pair i : vp) {cerr << ""[ ""; ""{""; _print(i.ff); cerr << "",""; _print(i.ss); cerr << "" ] "";} cerr << ""}"";} -template void _print(stack st) {cerr << ""[ ""; while (!st.empty()) {_print(st.top()); st.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(queue q) {cerr << ""[ ""; while (!q.empty()) {_print(q.front()); q.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(deque dq) {cerr << ""[ ""; while (!dq.empty()) {_print(dq.front()); dq.pop_front(); cerr << "" "";} cerr << ""]"";} -template void _print(PQ pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(QP pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -//--------------------------------------------------------------------------------------------------- - -void solve() { - - //solution starts from here - ll l, r; - cin >> l >> r; - int mx = 0; - for (int i = 0; i < 32; i++) { - if ((r & (1LL << i)) && (l & (1LL << i)) == 0) mx = i; - } - int a = 0; - for (int i = mx; i < 32; i++) { - a |= ((1LL << i) & r); - } - if (r >= a + 1) { - cout << a << "" "" << a + 1 << "" "" << a - 1 << endl; - debug((a^(a+1)) + ((a+1)^(a-1)) + ((a-1)^a)) - } - else { - cout << a << "" "" << a - 1 << "" "" << a - 2 << endl; - debug((a^(a-1)) + ((a-1)^(a-2)) +((a-2)^(a))) - - } -} - -int main() { - -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); -#endif - - FASTIO(); - auto start1 = high_resolution_clock::now(); - int t = 1; - cin >> t; - int T = t; - while (t--) - { - #ifndef ONLINE_JUDGE - cerr<<""Test ""<<(T-t)<<"" :""<(stop1 - start1); -#ifndef ONLINE_JUDGE - cerr << ""Time elapsed : "" << (duration . count() / 1000000) << '.' << (duration . count() % 1000000) << endl; -#endif - -}","import java.util.*; - -public class Main { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int test = sc.nextInt(); - for (int z = 0; z < test; z++) { - - long l = sc.nextInt(); - long r = sc.nextInt(); - long one = l; - long two; - long three; - long i =1; - if((r-l+1)==3) { - two=l+1; - three=l+2; - } else { - while (i<=r) { - i=i*2; - } - if(i/2<=l){ - if((r-l+1) >=6 ){ - two= r-3; - three=r; - - - }else{ - two= r-1; - three= r; - one = r-2; - } - - } - else{ - three=i/2; - two=three-1; - } - - } - - System.out.println(one+"" ""+two+"" ""+three); - - - - } - } -}",2 -linjunye_#,2057C - Trip to the Olympiad,c++17 ,300782659,300781017,"#include -#define int long long -using namespace std; -const int N=100010; -int l,r; -int a[3]; -void solve(){ - memset(a,0,sizeof(a)); - cin>>l>>r; - int res=0; - while(1){ - if(r-l==2){ - cout<>T; - while(T--)solve(); - return 0; -}","#include -#define int long long -using namespace std; -const int N=100010; -int l,r; -int a[3]; -void solve(){ - memset(a,0,sizeof(a)); - cin>>l>>r; - for(int i=30;i>=0;i--){ - sort(a,a+3); - int x=1<r)continue; - if(a[2]+x<=l){ - a[0]+=x; - a[1]+=x; - a[2]+=x; - continue; - } - a[0]+=x; - if(a[1]>T; - while(T--)solve(); - return 0; -} -",1 -Man25,2057C - Trip to the Olympiad,c++17 ,300832396,300832012,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; - //find_by order()->iterator of indexed element, order_of_key()-> number of elements strictly less than x -#define lli long long int -typedef tree < lli, null_type , less_equal , rb_tree_tag , tree_order_statistics_node_update > ordered_set; - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -#define endl '\n' -using pii=pair; -#define MP make_pair -#define F first -#define ld long double -#define S second -#define all(o) o.begin(),o.end() -lli M=1e9+7; -using mll = map; -using vi = vector; -using vvi = vector>; -using vpii = vector; -#define yes cout<<""YES""< -#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define deb(x) cout << #x << ""="" << x << ""\n"" -#define deb2(x, y) cout << #x << ""="" << x << "","" << #y << ""="" << y << ""\n"" -#define pb push_back -#define mid (l+r)/2 -#define lb lower_bound -#define ub upper_bound -template T gcd(T a, T b){return (b==0)?a:gcd(b,a%b);} -template T bin_pow(T b, T p, T m){T x = 1;while(p){if(p&1)x=(x*b)%m;b=(b*b)%m;p=p>>1;}return x;} -//---- Debugger ---- // -#define debarr(a,n) cout<<#a<<"" : "";for(int i=0;iostream& operator <<(ostream& os, const pair& p) {return os << ""("" << p.first << "", "" << p.second << "")"";} -template ostream& operator <<(ostream& os, const vector& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const unordered_set& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const unordered_map& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const set& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const multiset& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const map& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template void dbs(string str, T t) {cerr << str << "" : "" << t << ""\n"";} -template void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << "" : "" << t << "",""; dbs(str.substr(idx + 1), s...);} -template void prc(T a, T b) {cerr << ""[""; for (T i = a; i != b; ++i) {if (i != a) cerr << "", ""; cerr << *i;} cerr << ""]\n"";} -lli fact[1000100],inv_fact[1000100]; -lli nCr(lli n,lli r){if(r>n || n<0 ||r<0)return 0;lli d=(inv_fact[r]*inv_fact[n-r])%M; lli f=(fact[n]*d)%M;return f;} -lli nPr(lli n,lli r){return (nCr(n,r)*fact[r])%M;} -lli n,m,x,k,tt,q,p,y,h,w,l,r,d; -lli lcm(lli a,lli b){ - return (a*b/__gcd(a,b)); -} -#undef mid -vi arr,brr; -vvi g,div1; - - - -lli solve(lli n1,lli m1){ - cin>>l>>r; - - lli posl=-1,posr=-1; - for(lli i=30;i>=0;i--){ - if(((l>>i)&1LL) && (posl==-1)){ - posl=i; - } - if(((r>>i)&1LL) && (posr==-1)){ - posr=i; - } - } - - if(abs(posr-posl)>=2){ - cout<<(1LL<=0;i--){ - lli nr=(r>>i)&1LL,nl=(l>>i)&1LL; - if(nr==1 && nl==0){ - lli num=(1LL<(fact[i],M-2,M); - // } -// deb(nCr(5,2)); - -// div1.resize(1001000); -// for(lli i=1;i<1001000;i++){ -// for(lli j=i;j<1001000;j+=i){ -// div1[j].pb(i); -// } -// } - -// pr(div1[10]); - - - -cin>>tt; -// tt=1; -// lli cnt=1; - while(tt--){ - solve(0,0); - - } - -}","#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - //find_by order()->iterator of indexed element, order_of_key()-> number of elements strictly less than x -#define lli long long int -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; - -mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); - -#define endl '\n' -using pii=pair; -#define MP make_pair -#define F first -#define ld long double -#define S second -#define all(o) o.begin(),o.end() -lli M=998244353; -using mll = map; -using vi = vector; -using vvi = vector>; -using vpii = vector; -#define yes cout<<""YES""< -#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define deb(x) cout << #x << ""="" << x << ""\n"" -#define deb2(x, y) cout << #x << ""="" << x << "","" << #y << ""="" << y << ""\n"" -#define pb push_back -#define mid (l+r)/2 -#define lb lower_bound -#define ub upper_bound -#define fr(i, a, b) for (lli i = a; i < b; i++) -#define rev(i, a, b) for (lli i = a; i >= b; i--) -template T gcd(T a, T b){return (b==0)?a:gcd(b,a%b);} -template T bin_pow(T b, T p, T m){T x = 1;while(p){if(p&1)x=(x*b)%m;b=(b*b)%m;p=p>>1;}return x;} -//---- Debugger ---- // -#define debarr(a,n) cout<<#a<<"" : "";for(int i=0;iostream& operator <<(ostream& os, const pair& p) {return os << ""("" << p.first << "", "" << p.second << "")"";} -template ostream& operator <<(ostream& os, const vector& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const unordered_set& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const unordered_map& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const set& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const multiset& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template ostream& operator <<(ostream& os, const map& p) {os << ""[ ""; for (auto& it : p) os << it << "" ""; return os << ""]"";} -template void dbs(string str, T t) {cerr << str << "" : "" << t << ""\n"";} -template void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << "" : "" << t << "",""; dbs(str.substr(idx + 1), s...);} -template void prc(T a, T b) {cerr << ""[""; for (T i = a; i != b; ++i) {if (i != a) cerr << "", ""; cerr << *i;} cerr << ""]\n"";} -lli fact[1000100],inv_fact[1000100]; -lli nCr(lli n,lli r){if(r>n || n<0 ||r<0)return 0;lli d=(inv_fact[r]*inv_fact[n-r])%M; lli f=(fact[n]*d)%M;return f;} -lli nPr(lli n,lli r){return (nCr(n,r)*fact[r])%M;} -lli n,m,x,k,tt,q,p,y,h,w,l,r,d; -lli lcm(lli a,lli b){ - return (a*b/__gcd(a,b)); -} - -vvi arr,brr; -vvi g,pref,pref1,ans; -string str; -map mp; - -lli rec(lli lvl,lli i,lli j,lli sum,lli rsum,lli csum){ - // deb2(i,j); - - - auto [dx,dy]=mp[str[lvl]]; - lli ni=i+dx,nj=j+dy; - - lli ff=0; - if(ni==n-1 && nj==m-1){ - if(str[lvl]=='R'){ - lli num1=sum-pref1[0][m-1]; - lli num2=sum-(pref[n-1][0]+rsum); - ans[ni][nj]=num1; - return num1==num2; - } - else{ - lli num1=sum-pref[n-1][0]; - lli num2=sum-(pref[0][m-1]+csum); - ans[ni][nj]=num1; - return num1==num2; - } - } - else{ - if(str[lvl]=='R'){ - if(str[lvl+1]=='R'){ - ans[ni][nj]=sum-pref1[0][nj]; - ff=rec(lvl+1,ni,nj,sum,rsum+ans[ni][nj],0); - } - else - if(str[lvl+1]=='D'){ - ans[ni][nj]=sum-(pref[ni][0]+rsum); - ff=rec(lvl+1,ni,nj,sum,0,ans[ni][nj]); - } - } - else{ - if(str[lvl+1]=='D'){ - ans[ni][nj]=sum-pref[ni][0]; - ff=rec(lvl+1,ni,nj,sum,0,csum+ans[ni][nj]); - } - else - if(str[lvl+1]=='R'){ - ans[ni][nj]=sum-(pref1[0][nj]+csum); - ff=rec(lvl+1,ni,nj,sum,ans[ni][nj],0); - } - } - } - - return ff; - -} - - -lli solve(lli n1,lli m1){ - cin>>n>>m; - pref.assign(n,vi(m,0)); - pref1.assign(n,vi(m,0)); - ans.assign(n,vi(m,0)); - arr.assign(n,vi(m,0)); - cin>>str; - - for(int i=0;i>arr[i][j]; - ans[i][j]=arr[i][j]; - } - } - - for(int i=0;i=0;j--){ - pref[i][j]=arr[i][j]; - if(j+1=0;i--){ - pref1[i][j]=arr[i][j]; - if(i+1(fact[i],M-2,M); -// } -// deb(nCr(5,2)); - -// div1.assign(1000100,0); - -// for(lli i=1;i<1000100;i++){ -// for(lli j=i;j<1000100;j+=i){ -// div1[j]++; -// } -// } - -// deb(div1[2]); -mp['D']=MP(1,0); -mp['R']=MP(0,1); - - -cin>>tt; -// tt=1; -// lli cnt=1; - while(tt--){ - solve(0,0); - } - -}",1 -krisshhh,2057C - Trip to the Olympiad,c++23 ,301201842,301201287,"/*Author : KRISH JHA */ -/*scholar id : 2312119*/ - -#include -using namespace std; - -#define endl ""\n"" -#define allv v.begin() , v.end() -#define rallv v.rbegin() , v.rend() -#define yes cout<<""YES\n"" -#define no cout<<""NO\n"" - -/********************************************** Debug Code **************************************************/ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } -template -void __print(const A &x); -template -void __print(const pair &p); -template -void __print(const tuple &t); -template -void __print(stack s); -template -void __print(queue q); -template -void __print(priority_queue q); -template -void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""), __print(i); - first = false; - } - cerr << '}'; -} -template -void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} -template -void __print(const tuple &t) { - bool first = true; - cerr << '('; - apply([&first](const auto &...args) { ((cerr << (first ? """" : "",""), __print(args), first = false), ...); }, t); - cerr << ')'; -} -template -void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} -template -void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -template -void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -void _print() { cerr << ""]\n""; } -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} -#ifndef ONLINE_JUDGE -#define debug(...) cerr << ""Line:"" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = [""; _print(__VA_ARGS__) -#else -#define debug(...) -#endif -/****************************************** Debug Code Ends ***************************************************************************************/ - - -int gcd(int a , int b){if(a == 0) return b;return gcd( b % a , a);} - -bool comp(pair a , pair b){ - return a.first > b.first; -} - -int findmax(int a , int b){if(a > b) return a;else return b;} - -#define int long long - -/********************************************* Code starts from here *************************************************/ - -void solve(){ - - int l , r; - cin >> l >> r; - - if(r - l + 1 == 3){ - cout << l << ' ' << l + 1 << ' ' << r << ' ' << endl; - return; - } - - int a = 0 , b = 0 , c = 0; - for(int i = 29 ; i >= 0; i--){ - if((l & (1 << i)) != (r & (1 << i))){ - a |= (1 << i); - break; - } - else{ - a |= (l & (1 << i)); - } - } - - b = a - 1; - - for(int i = l ;i <= r ; i++){ - if(i != a && i != b) { - c = i; - break; - } - } - - cout << a << ' ' << b << ' ' << c << endl; - -} - -signed main() { - - #ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); - #endif - - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - - // int t = 1; - - int t; - cin >> t; - for(int i = 1; i <= t; i++) { - solve(); - } - return 0; - -}","/*Author : KRISH JHA */ -/*scholar id : 2312119*/ - -#include -using namespace std; - -#define endl ""\n"" -#define allv v.begin() , v.end() -#define rallv v.rbegin() , v.rend() -#define yes cout<<""YES\n"" -#define no cout<<""NO\n"" - -/********************************************** Debug Code **************************************************/ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } -template -void __print(const A &x); -template -void __print(const pair &p); -template -void __print(const tuple &t); -template -void __print(stack s); -template -void __print(queue q); -template -void __print(priority_queue q); -template -void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""), __print(i); - first = false; - } - cerr << '}'; -} -template -void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} -template -void __print(const tuple &t) { - bool first = true; - cerr << '('; - apply([&first](const auto &...args) { ((cerr << (first ? """" : "",""), __print(args), first = false), ...); }, t); - cerr << ')'; -} -template -void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} -template -void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -template -void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -void _print() { cerr << ""]\n""; } -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} -#ifndef ONLINE_JUDGE -#define debug(...) cerr << ""Line:"" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = [""; _print(__VA_ARGS__) -#else -#define debug(...) -#endif -/****************************************** Debug Code Ends ***************************************************************************************/ - - -int gcd(int a , int b){if(a == 0) return b;return gcd( b % a , a);} - -bool comp(pair a , pair b){ - return a.first > b.first; -} - -int findmax(int a , int b){if(a > b) return a;else return b;} - -#define int long long - -/********************************************* Code starts from here *************************************************/ - -void solve(){ - - int l , r; - cin >> l >> r; - - if(r - l + 1 == 3){ - cout << l << ' ' << l + 1 << ' ' << r << ' ' << endl; - return; - } - - int a = 0 , b = 0 , c = 0; - for(int i = 29 ; i >= 0; i--){ - if((l & (1 << i)) != (r & (1 << i))){ - a |= (1 << i); - break; - } - } - - b = a - 1; - - for(int i = l ;i <= r ; i++){ - if(i != a && i != b) { - c = i; - break; - } - } - - cout << a << ' ' << b << ' ' << c << endl; - -} - -signed main() { - - #ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); - #endif - - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - - // int t = 1; - - int t; - cin >> t; - for(int i = 1; i <= t; i++) { - solve(); - } - return 0; - -}",1 -aguss,2057C - Trip to the Olympiad,c++17 ,301152757,301152926,"#include - -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() - -#define dbg(x) cerr << #x << "": "" << x << '\n'; -#define dbgv(v) cerr << #v << "": ""; for(auto &el : v) cerr << el << "" ""; cerr << '\n'; - -using namespace std; -using ll = long long; - -const ll MOD = 1e9 + 7; -const ll INF = 1e18 + 5; - -void solve(){ - int l, r; - cin >> l >> r; - int log = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << log) - 1), b = a + 1, c = (a == l ? r : r); - cout << a << "" "" << b << "" "" << c << ""\n""; -} -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t; - cin >> t; - while(t--){ - solve(); - } -} -","#include - -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() - -#define dbg(x) cerr << #x << "": "" << x << '\n'; -#define dbgv(v) cerr << #v << "": ""; for(auto &el : v) cerr << el << "" ""; cerr << '\n'; - -using namespace std; -using ll = long long; - -const ll MOD = 1e9 + 7; -const ll INF = 1e18 + 5; - -void solve(){ - int l, r; - cin >> l >> r; - int log = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << log) - 1), b = a + 1, c = (a == l ? r : l); - cout << a << "" "" << b << "" "" << c << ""\n""; -} -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t; - cin >> t; - while(t--){ - solve(); - } -} -",2 -Armaan_912,2057C - Trip to the Olympiad,c++17 ,300300937,300302405,"#include -#define lli long long -#define endl ""\n"" -#define vi vector -#define vpi vector> -#define vvi vector> -#define fo(i, a, n) for(lli i = a; i=a; i--) -#define nay {cout << ""No\n""; return;} -#define yay {cout << ""Yes\n""; return;} -#define vin(v) for(auto&x:v)cin>>x; -#define print(v) for(auto x:v) cout<> l >> r; - lli a = 0, b = 0; - for (int i=30; i>=0; i--) { - lli b1 = l & (1ll << i); - lli b2 = r & (1ll << i); - if (b1 == b2) { - b += b1 * (1ll << i); - } - else { - b += (1ll << i); - a = b-1; - break; - } - } - lli c; - if (l<=a-1 && r>=a-1) c = a-1; - else c = b+1; - cout << a << "" "" << b << "" "" << c << endl; -} - -int main() { - int t; cin >> t; - while (t--) { - solve(); - } -}","#include -#define lli long long -#define endl ""\n"" -#define vi vector -#define vpi vector> -#define vvi vector> -#define fo(i, a, n) for(lli i = a; i=a; i--) -#define nay {cout << ""No\n""; return;} -#define yay {cout << ""Yes\n""; return;} -#define vin(v) for(auto&x:v)cin>>x; -#define print(v) for(auto x:v) cout<> l >> r; - lli a = 0, b = 0; - for (int i=30; i>=0; i--) { - lli b1=0, b2=0; - if (l & (1ll << i)) b1 = 1; - if (r & (1ll << i)) b2 = 1; - if (b1 == b2) { - b += b1 * (1ll << i); - } - else { - b += (1ll << i); - a = b-1; - break; - } - } - lli c; - if (l<=a-1 && r>=a-1) c = a-1; - else c = b+1; - cout << a << "" "" << b << "" "" << c << endl; -} - -int main() { - int t; cin >> t; - while (t--) { - solve(); - } -}",2 -sujayawale125,2057C - Trip to the Olympiad,c++23 ,300260088,300259993,"#include -using namespace std; -#define int long long int - -void sol1(){ - int a,b,c, ans=0, i=0; cin>>a>>b; - vector>vp; - unordered_mapmp; - while(a--){cin>>c; mp[c]++;} - for(auto &b: mp){vp.push_back({b.second, b.first});} - sort(vp.begin(), vp.end()); - while(b>0 and i0){ans++;} - } - cout<>a>>b; - for(int i=30; i>=0; i--){ - int a1=0,a2=0; - if(a&(1ll<>t; - while(t--){ - // sol1(); - sol2(); - } - - return 0; -}","#include -using namespace std; -#define int long long int - -void sol1(){ - int a,b,c, ans=0, i=0; cin>>a>>b; - vector>vp; - unordered_mapmp; - while(a--){cin>>c; mp[c]++;} - for(auto &b: mp){vp.push_back({b.second, b.first});} - sort(vp.begin(), vp.end()); - while(b>0 and i0){ans++;} - } - cout<>a>>b; - for(int i=30; i>=0; i++){ - int a1=0,a2=0; - if(a&(1ll<>t; - while(t--){ - // sol1(); - sol2(); - } - - return 0; -}",1 -exercise_everyday,2057C - Trip to the Olympiad,c++20 ,300977179,300978967,"#include -using namespace std; -void solve(){ - int l,r; - cin>>l>>r; - int x=0,y=0; - for(int i=30;i>=0;i--){ - if(((1<>t; - while(t--) solve(); - return 0; -}","#include -using namespace std; -#define int long long -void solve(){ - int l,r; - cin>>l>>r; - int x=0,y=0; - for(int i=30;i>=0;i--){ - if(((r>>i)&1)!=((l>>i)&1)){ - x+=(1<>i&1); - y+=(1<>i&1); - // cout<>t; - while(t--) solve(); - return 0; -}",2 -Aditya2004,2057C - Trip to the Olympiad,c++17 ,304812509,304811648,"#include -using namespace std; -#define int long long -#define ii pair -#define iii pair -#define fi first -#define se second -#define inf 1e16 -int tc, l, r; -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - if(fopen(""main.inp"",""r"")) { - freopen(""main.inp"", ""r"", stdin); - freopen(""main.out"", ""w"", stdout); - } - cin >> tc; - while(tc--) { - cin >> l >> r; - int a = 0, b = 0, c = 0; - for(int j = 30; j >= 0; j--) { - if((r&(1< -using namespace std; -int mod=1e9+7; -long long power(long long x,int y) -{ - long long res=1; - while(y>0) - { - int r=y%2; - if(r==1) - { - res=res*x; - } - y=y/2; - x=x*x; - } - return res; -} -int main() { - int t; - cin>>t; - while(t--) - { - long long low,l,high,h; - cin>>low>>high; - l=low; - h=high; - vectorv1(35,0),v2(35,0); - int j=32; - // long long p=1; - while(high>0) - { - int r1=high%2; - int r2=low%2; - v1[j]=r1; - v2[j]=r2; - j--; - - high=high/2; - low=low/2; - - } - // cout<low) - { - cout<low&&num2 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#define ll long long -#define LOG2(n) __lg(n) -#define SET_BIT_COUNTLL(x) __builtin_popcountll(x) -#define SET_BIT_COUNT(x) __builtin_popcount(x) -#define FAST ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); -#define all(v) v.begin(),v.end() -#define allr(v) v.rbegin(),v.rend() -#define lp(var,inti,size) for(int var = inti ; var < size ; var ++) -#define fori(size) for(ll i=0; i < (size); i++) -#define foril(size) for(ll i=(size-1); i >= 0; --i) -#define forj(size) for(ll j=0; j < (size); j++) -#define fork(size) for(ll k=0; k < (size); k+= 1) -#define forl(size) for(ll l=0; l < (size); l+= 1) -const float pi = 3.14; -const long long oo = 9223372036854775807; -using namespace std; -#define oo 1e9 -#define pb push_back -#define endll ""\n"" -#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) -#define mp make_pair -#define yes cout<<""YES""< pii; -typedef pair ppi; -typedef vector vec; -void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - -vector fibNumbers(1e7, 1); - -set primeo; - - - -ll dpadep(vec &dpadepo, ll fo) { - if (fo > 1000)return 0; - else { - dpadepo.push_back(fo); - dpadep(dpadepo, fo * 10 + 7); - return dpadep(dpadepo, fo * 10 + 4); - } - -} -void TT() { - - long long n, t, m = 0, c = 0, sum = 0, real_sum = 0, c_sofar = 0, sum_sofar = 0; ll a, b = 1, k, r, l, ans = 0; - string sl,sr; - cin >>l>>r; - vec x; t = l; - map lolo; - while (l) { - if (l % 2)sl = sl+""1"" ; - else sl = sl +""0"" ; - l = l/ 2; - } - while (r) { - if (r % 2)sr = sr+""1""; - else sr = sr +""0"" ; - r = r / 2; - } - if (sr.length() > sl.length()) { - if (((1 << sr.length() - 1) - 1) != t) cout << (1 << sr.length() - 1) << "" "" << (1 << sr.length() - 1) - 1 << "" "" << t << endl; - else cout << t << "" "" << t + 1 << "" "" << t + 2< n) { QWE - cout << n << endl;; - } - else if (a) { - ans = n - 1 - b+a; - ans /= a; - cout <> n; - ll s = 0; - while (n--) { TT(); } -} -// Owvx -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#define ll long long -#define LOG2(n) __lg(n) -#define SET_BIT_COUNTLL(x) __builtin_popcountll(x) -#define SET_BIT_COUNT(x) __builtin_popcount(x) -#define FAST ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); -#define all(v) v.begin(),v.end() -#define allr(v) v.rbegin(),v.rend() -#define lp(var,inti,size) for(int var = inti ; var < size ; var ++) -#define fori(size) for(ll i=0; i < (size); i++) -#define foril(size) for(ll i=(size-1); i >= 0; --i) -#define forj(size) for(ll j=0; j < (size); j++) -#define fork(size) for(ll k=0; k < (size); k+= 1) -#define forl(size) for(ll l=0; l < (size); l+= 1) -const float pi = 3.14; -const long long oo = 9223372036854775807; -using namespace std; -#define oo 1e9 -#define pb push_back -#define endll ""\n"" -#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) -#define mp make_pair -#define yes cout<<""YES""< pii; -typedef pair ppi; -typedef vector vec; -void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } - -vector fibNumbers(1e7, 1); - -set primeo; - - - -ll dpadep(vec &dpadepo, ll fo) { - if (fo > 1000)return 0; - else { - dpadepo.push_back(fo); - dpadep(dpadepo, fo * 10 + 7); - return dpadep(dpadepo, fo * 10 + 4); - } - -} -void TT() { - - long long n, t, m = 0, c = 0, sum = 0, real_sum = 0, c_sofar = 0, sum_sofar = 0; ll a, b = 1, k, r, l, ans = 0; - string sl,sr; - cin >>l>>r; - vec x; t = l; - map lolo; - while (l) { - if (l % 2)sl = ""1"" + sl; - else sl = ""0"" + sl; - l = l/ 2; - } - while (r) { - if (r % 2)sr = ""1"" + sr; - else sr = ""0"" + sr; - r = r / 2; - } - if (sr.length() > sl.length())cout<<(1<< sr.length()-1)<<"" "" << (1 << sr.length() - 1) - 1 << "" "" << t << endl; - else { - c = sr.size()-1; - while (sr[c] == sl[c])c--; - cout << (1 << c) << "" "" << (1 << c) - 1 << "" "" << t << endl; - - } - -} - - -/* if (b > n) { QWE - cout << n << endl;; - } - else if (a) { - ans = n - 1 - b+a; - ans /= a; - cout <> n; - ll s = 0; - while (n--) { TT(); } -} -// Owvx -",1 -class_codrr,2057C - Trip to the Olympiad,c++23 ,300559943,300562770,"#include -using namespace std; -#define lli long long int -int main() -{ - lli t; - cin >> t; - while (t--) - { - lli left, right; - cin >> left >> right; - // if leading_zeros_left==leading_zeros_right-->choose one number as first odd second number as right and greedy approach to choose third - // else -->first number as (set bit 1 after min leading zeros and all zeros after that ->and seoond num as first-1 and greedy to choose third) - // cout << __builtin_clzll(left) << "" "" << __builtin_clzll(right) << endl; - if (__builtin_clzll(left) == __builtin_clzll(right)) - { - lli first = right; - lli second; - for (lli i = left; i < right; i++) - { - if (i % 2 != 0) - { - second = i; - break; - } - } - lli maxi = -1; - lli third; - for (lli i = left; i <= right; i++) - { - if (i != first && i != second) - { - if (((first ^ i) + (second ^ i)) > maxi) - { - maxi = (first ^ i) + (second ^ i); - third = i; - } - } - } - cout << first << "" "" << second << "" "" << third << endl; - // cout << (first ^ second) + maxi << endl; - // cout << (123 ^ 118) + (123 ^ 121) + (121 ^ 118) << endl; - } - else - { - lli max_leading = __builtin_clzll(right); - bitset<64> b; - b[63 - max_leading] = 1; - lli first = b.to_ullong(); - lli second = first - 1; - lli maxi = -1; - lli third; - for (lli i = left; i <= right; i++) - { - if (i != first && i != second) - { - if (((first ^ i) + (second ^ i)) > maxi) - { - maxi = (first ^ i) + (second ^ i); - third = i; - break; - } - } - } - cout << first << "" "" << second << "" "" << third << endl; - } - } -}","#include -using namespace std; -#define lli long long int -int main() -{ - lli t; - cin >> t; - while (t--) - { - lli left, right; - cin >> left >> right; - // if leading_zeros_left==leading_zeros_right-->choose one number as first odd second number as right and greedy approach to choose third - // else -->first number as (set bit 1 after min leading zeros and all zeros after that ->and seoond num as first-1 and greedy to choose third) - // cout << __builtin_clzll(left) << "" "" << __builtin_clzll(right) << endl; - if (__builtin_clzll(left) == __builtin_clzll(right)) - { - // cout << ""came here"" << endl; - lli first_difference = __builtin_clzll(left ^ right); - bitset<64> b(left); - b[63 - first_difference] = 1; - for (lli i = 0; i < 63 - first_difference; i++) - { - b[i] = 0; - } - bitset<64> b1(left); - for (lli i = 0; i < 63 - first_difference; i++) - { - b1[i] = 1; - } - b1[63 - first_difference] = 0; - lli first = b.to_ullong(); - lli second = b1.to_ullong(); - lli third; - for (lli i = left; i <= right; i++) - { - if (i != first && i != second) - { - third = i; - break; - } - } - cout << first << "" "" << second << "" "" << third << endl; - } - else - { - lli max_leading = __builtin_clzll(right); - bitset<64> b; - b[63 - max_leading] = 1; - lli first = b.to_ullong(); - lli second = first - 1; - lli maxi = -1; - lli third; - for (lli i = left; i <= right; i++) - { - if (i != first && i != second) - { - if (((first ^ i) + (second ^ i)) > maxi) - { - maxi = (first ^ i) + (second ^ i); - third = i; - break; - } - } - } - cout << first << "" "" << second << "" "" << third << endl; - } - } -}",2 -SergiiGolovko,2057C - Trip to the Olympiad,c++17 ,300769649,300769340,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define DEBUG false -using namespace std; - - -void debug(string s) { - if (DEBUG) cout << s << endl; -} - -void debug(int s) { - if (DEBUG) cout << s << endl; -} - -void debug(vector > & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - for (int j = 0; j != v[i].size(); ++j) { - cout << v[i][j] << "" ""; - } - cout << endl; - } -} - -//flat debug of vector of vectors -void fdebug(vector > & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - for (int j = 0; j != v[i].size(); ++j) { - cout << v[i][j]; - if (j != v[i].size() - 1) { - cout << "" ""; - } - } - cout << ""; ""; - } - cout << endl; -} - - -void debug(vector & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - cout << v[i] << "" ""; - } - cout << endl; -} - - -class Solution { - int l, r; -public: - void init() { - cin >> l >> r; - } - - ll solve() { - init(); - int a = 0; - int b = 0; - int c = 0; - - for (int i = 30; i >= 0; --i) { - int li = (l >> i) & 1; - int ri = (r >> i) & 1; - if (li != ri) { - if (r > (1 << i)) { - a += (1 << i) + 1; - b += (1 << i); - c += (1 << i) - 1; - } else { - a += (1 << i); - b += (1 << i) - 1; - c += (1 << i) - 2; - } - break; - } else if (li == 1) { - a += (1 << i); - b += (1 << i); - c += (1 << i); - l -= (1 << i); - r -= (1 << i); - } - } - - cout << a << "" "" << b << "" "" << c << endl; - return 0; - } - -}; - - -signed main() -{ - std::ios_base::sync_with_stdio (false); - std::cin.tie(NULL); - int n; - cin >> n; - Solution sol; - for(int i = 1; i != n + 1; ++i) { - //cout << fixed << setprecision(0) << sol.solve() << ""\n""; - sol.solve(); - } - - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define DEBUG false -using namespace std; - - -void debug(string s) { - if (DEBUG) cout << s << endl; -} - -void debug(int s) { - if (DEBUG) cout << s << endl; -} - -void debug(vector > & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - for (int j = 0; j != v[i].size(); ++j) { - cout << v[i][j] << "" ""; - } - cout << endl; - } -} - -//flat debug of vector of vectors -void fdebug(vector > & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - for (int j = 0; j != v[i].size(); ++j) { - cout << v[i][j]; - if (j != v[i].size() - 1) { - cout << "" ""; - } - } - cout << ""; ""; - } - cout << endl; -} - - -void debug(vector & v) { - if (!DEBUG) return; - for (int i = 0; i != v.size(); ++i) { - cout << v[i] << "" ""; - } - cout << endl; -} - - -class Solution { - int l, r; -public: - void init() { - cin >> l >> r; - } - - ll solve() { - init(); - int a = 0; - int b = 0; - int c = 0; - - for (int i = 30; i >= 0; --i) { - int li = (l >> i) & 1; - int ri = (r >> i) & 1; - if (li != ri) { - if (r > (1 << i)) { - a += (1 << i) + 1; - b += (1 << i); - c += (1 << i) - 1; - } else { - a += (1 << i); - b += (1 << i) - 1; - c += (1 << i) - 2; - } - } else if (li == 1) { - a += (1 << i); - b += (1 << i); - c += (1 << i); - } - } - - cout << a << "" "" << b << "" "" << c << endl; - return 0; - } - -}; - - -signed main() -{ - std::ios_base::sync_with_stdio (false); - std::cin.tie(NULL); - int n; - cin >> n; - Solution sol; - for(int i = 1; i != n + 1; ++i) { - //cout << fixed << setprecision(0) << sol.solve() << ""\n""; - sol.solve(); - } - - return 0; -} -",1 -manideep2004,2057C - Trip to the Olympiad,c++20 ,300799134,300801259,"#include -using namespace std; -#define vii vector> -#define vi vector -#define pb push_back -#define int long long -#define double long double -#define fi first -#define se second -#define s(v) sort(v.begin(), v.end()) -#define r(v) reverse(v.begin(), v.end()) -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL); -void solve() -{ - int l, r; - cin >> l >> r; - bool flag = 0; - int a = 0, b = 0, c = 0; - for (int i = 31; i >= 0; i--) - { - int l_bit = (l & (1LL << i)) > 0; - int r_bit = (r & (1LL << i)) > 0; - if (l_bit == r_bit && !flag) - { - if (l_bit) - { - a |= (1LL << i); - b |= (1LL << i); - c |= (1LL << i); - } - } - else - { - if (flag == 0) - { - flag = 1; - a |= (1LL << i); - } - else - { - b |= (1LL << i); - } - } - } - cout << a << "" "" << b << "" "" << c << endl; -} -int32_t main() -{ - fast int t; - cin >> t; - while (t--) - solve(); - return 0; -}","#include -using namespace std; -#define vii vector> -#define vi vector -#define pb push_back -#define int long long -#define double long double -#define fi first -#define se second -#define s(v) sort(v.begin(), v.end()) -#define r(v) reverse(v.begin(), v.end()) -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL); -void solve() -{ - int l, r; - cin >> l >> r; - bool flag = 0; - int a = 0, b = 0, c = 0; - for (int i = 31; i >= 0; i--) - { - int l_bit = (l & (1LL << i)) > 0; - int r_bit = (r & (1LL << i)) > 0; - if (l_bit == r_bit && !flag) - { - if (l_bit) - { - a |= (1LL << i); - b |= (1LL << i); - c |= (1LL << i); - } - } - else - { - if (flag == 0) - { - flag = 1; - a |= (1LL << i); - c |= (1LL << i); - } - else - { - b |= (1LL << i); - // c |= (1LL << i); - } - } - } - for (int i = l; i <= r; i++) - { - if (i != a && i != b) - { - cout << a << "" "" << b << "" "" << i << endl; - return; - } - } -} -int32_t main() -{ - fast int t; - cin >> t; - while (t--) - solve(); - return 0; -}",2 -zhentaozhang4,2057C - Trip to the Olympiad,c++17 ,301178559,301177944,"#include -using namespace std; - -int get_highest_diff_bin_bit(int l, int r){ - int diff = (l ^ r); - int cnt = 0; - while(diff){ - diff >>= 1; - cnt++; - } - return cnt; -} - -int get_bit_num(int n){ - int cnt = 0; - while(n){ - n >>= 1; - cnt++; - } - return cnt; -} - -int rand_from_l_to_r(int l, int r, int first, int second){ - int res = rand() % (r - l + 1) + l; - // cout << ""l: ""<> k ; - for (int i=0; i< k; i++){ - cin >> l >> r; - //cout << two_sum << endl; - int first = l >> (get_highest_diff_bin_bit(l, r)-1); - // cout << ""prefix:"" << first << endl; - first <<= (get_highest_diff_bin_bit(l, r)-1); - - int mask = (1 << (get_highest_diff_bin_bit(l, r)-1)) - 1; - - first |= mask; - - int second = r >> (get_highest_diff_bin_bit(l, r)-1); - // cout << ""prefix:"" << second << endl; - second <<= (get_highest_diff_bin_bit(l, r)-1); - - int third = rand_from_l_to_r(l, r, first, second); - cout << first << "" "" << second << "" "" << third << endl; - } - - return 0; -}","#include -using namespace std; - -int get_highest_diff_bin_bit(int l, int r){ - int diff = (l ^ r); - int cnt = 0; - while(diff){ - diff >>= 1; - cnt++; - } - return cnt; -} - -int get_bit_num(int n){ - int cnt = 0; - while(n){ - n >>= 1; - cnt++; - } - return cnt; -} - - -int main(){ - int k,l,r; - cin >> k ; - for (int i=0; i< k; i++){ - cin >> l >> r; - //cout << two_sum << endl; - int first = l >> (get_highest_diff_bin_bit(l, r)-1); - // cout << ""prefix:"" << first << endl; - first <<= (get_highest_diff_bin_bit(l, r)-1); - - int mask = (1 << (get_highest_diff_bin_bit(l, r)-1)) - 1; - - first |= mask; - - int second = r >> (get_highest_diff_bin_bit(l, r)-1); - // cout << ""prefix:"" << second << endl; - second <<= (get_highest_diff_bin_bit(l, r)-1); - - int third = l+1; - cout << first << "" "" << second << "" "" << third << endl; - } - - return 0; -}",1 -nitu_sherawat,2057C - Trip to the Olympiad,c++17 ,306197145,306201109,"#include -using namespace std; -#define int long long int - -#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) - -void solve(int t) { - int l,r; - cin>>l>>r; - - int max_val = l; - - for(int i=0;i<30;i++){ - int num = pow(2,i); - if(num>=l&&num<=r) max_val=max(max_val,num); - } - - // If-else case - int a,b,c; - - if(max_val==l){ - - a=l; - b=l+1; - c=r; - - }else if(max_val==r){ - - a=r; - b=r-1; - c=l; - - }else{ - - a=max_val; - b=a-1; - int check1 = (a^r)+(b^r); - int check2 = (a^l)+(b^l); - if(check1>check2) c=r; - else c=l; - if(b==l) c=r; - - } - cout<> t; - - for (int i = 0; i < t; i++) { - solve(i); - } - return 0; -}","#include -using namespace std; -#define int long long int - -#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) - -void solve(int t) { - // int l,r; - // cin>>l>>r; - - // int max_val = l; - - // for(int i=0;i<30;i++){ - // int num = pow(2,i); - // if(num>=l&&num<=r) max_val=max(max_val,num); - // } - - // // If-else case - // int a,b,c; - - // if(max_val==l){ - - // a=l; - // c=r; - // int num1 = -1; - - // for(int i=l+1;icheck2) c=r; - // else c=l; - // if(b==l) c=r; - - // } - // cout<> l >> r; - int k = 31 - __builtin_clz(l ^ r); // Trailing zeroes of l^r - int a =(pow(2,k) - 1); - a=a|l; - int b = a + 1; - int c = (a == l ? r : l); - cout << a << "" "" << b << "" "" << c << ""\n""; -} - -signed main() { - fastio(); - - #ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif - - int t; t = 1; - cin >> t; - - for (int i = 0; i < t; i++) { - solve(i); - } - return 0; -} - -",2 -minecraftbucuo,2057C - Trip to the Olympiad,c++23 ,300947022,300942705,"#include -using namespace std; - -int main() { - int t, l, r; - cin >> t; - while (t--) { - cin >> l >> r; - int a = l | ((1 << (int)(log2(l ^ r))) - 1); - int b = a + 1; - int c = (b == r ? l : r); - cout << a << ' ' << b << ' ' << c << endl; - } - return 0; -}","#include -using namespace std; - -int main() { - int t, l, r; - cin >> t; - while (t--) { - cin >> l >> r; - int a = 1 << ((int)log2(r)); - int b = (a - 1 >= l ? a - 1 : a + 1); - int c = (a == r ? l : r); - cout << a << ' ' << b << ' ' << c << endl; - } - return 0; -}",1 -Paras7,2057C - Trip to the Olympiad,c++17 ,303656480,303656957,"#include -using namespace std; - -#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> -// #define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> - -typedef long long int ll; -typedef long double ld; - -const ld eps = 1e-9; -const int mod = 1000000007; -const ll inf = 1e18; -const int N1 = 2e5 + 10; - -int main() -{ - ios::sync_with_stdio(0); - cin.tie(0); - // mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); - // auto start = chrono::high_resolution_clock::now(); - - // code here. dont use mbinpow,binpow,right, fact and isprime as function names - // (1/b)%M is (b^(M-2))%M - - ll tt; - cin >> tt; - while (tt--) - { - int l, r; - cin >> l >> r; - - int k = 0; - for(int i=0;i<30;i++){ - if((l&(1<> k) << k; - int val2 = val1 - 1; - int val3; - for (int i = l; i < min(l + 3, r);i++){ - if(i!=val1 && i!=val2){ - val3 = i; - break; - } - } - - cout << val1 << "" "" << val2 << "" "" << val3 << '\n'; - } - -}","#include -using namespace std; - -#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> -// #define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> - -typedef long long int ll; -typedef long double ld; - -const ld eps = 1e-9; -const int mod = 1000000007; -const ll inf = 1e18; -const int N1 = 2e5 + 10; - -int main() -{ - ios::sync_with_stdio(0); - cin.tie(0); - // mt19937 rng((unsigned int)chrono::steady_clock::now().time_since_epoch().count()); - // auto start = chrono::high_resolution_clock::now(); - - // code here. dont use mbinpow,binpow,right, fact and isprime as function names - // (1/b)%M is (b^(M-2))%M - - ll tt; - cin >> tt; - while (tt--) - { - int l, r; - cin >> l >> r; - - int k = 0; - for(int i=0;i<30;i++){ - if((l&(1<> k) << k; - int val2 = val1 - 1; - int val3; - for (int i = l; i <= min(l + 2, r);i++){ - if(i!=val1 && i!=val2){ - val3 = i; - break; - } - } - - cout << val1 << "" "" << val2 << "" "" << val3 << '\n'; - } - -}",2 -Om_Prakash416,2057C - Trip to the Olympiad,c++17 ,305576812,305576345,"#include -using namespace std; - -#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define int long long -#define pb push_back -#define all(v) v.begin(), v.end() -#define pii pair -#define vi vector -#define inp for(int i=0;i>arr[i] -#define vll vector -#define vvi vector > -#define vpii vector -#define mp make_pair -#define f first -#define s second - -const int MOD = 1e9 + 7; -const int INF = 1e9; - -// Function to print a vector -template -void printVector(const vector& v) { - for (const auto& element : v) { - cout << element << ' '; - } - cout << endl; -} - -// Function to print a set -template -void printSet(const set& s) { - for (const auto& element : s) { - cout << element << ' '; - } - cout << endl; -} - -// Function to print a map -template -void printMap(const map& m) { - for (const auto& [key, value] : m) { - cout << key << "" -> "" << value << endl; - } -} -void func(int a,int b,int c){ - cout<<(a^b)+(b^c)+(c^a)<>l>>r; - int msd = log2(r); - vector a1,a2; - for(int i=msd ;i>=0;i--){ - if(l & (1LL << i)){ - a1.pb(1); - } - else a1.pb(0); - if(r & (1LL << i)){ - a2.pb(1); - } - else a2.pb(0); - } - int num = 0; - reverse(all(a1)); - reverse(all(a2)); - bool flag = true,flag2 = true; - for(int i=msd;i>=0;i--){ - if(a1[i] == a2[i] && flag){ - num += (1LL << i)*a1[i]; - } - else{ - if(flag){ - // num += (1LL << i); - flag = false; - } - else{ - if(a1[i] == 0 && flag2){ - num += (1LL << i); - flag2 = false; - continue; - } - if(a1[i] != a2[i] || a1[i] == 0 && a2[i] == 0) - num += (1LL << i); - } - } - // if(i == msd && a1[i] == a2[i] && a1[i] == 1){ - // num = l; - // break; - // } - // else if(a1[i] == a2[i] && a1[i] == 0) num += (1LL << i); - // else if(a1[i] != a2[i]) num += (1LL << i); - // cout<""; - cout<> t; // Uncomment if multiple test cases - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - - -void solution() { - int l, r; - cin >> l >> r; - int x = (l ^ r); - int ind = 0; - while(pow(2, ind) <= x)ind++; // 16 8 4 2 0 - // cout << ind << endl; - --ind; - int y = pow(2, ind); - int a = (l | (y - 1) ); - int b = a + 1; - int c = l; - if(a == l)c = r; - cout << a << "" "" << b << "" "" << c << endl; - - -} - - -int main() { - - int t; - cin >> t; - while(t--) { - solution(); - } -}",1 -Anmol_yadav,2057C - Trip to the Olympiad,c++20 ,304889393,304888693,"#include -#include -#include - -using namespace std; -using namespace chrono; - -using namespace __gnu_pbds; - - -template -using orderedSet = tree, rb_tree_tag, tree_order_statistics_node_update>; -template -using orderedMultiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// find_by_order(k) -> iterator at k -// order_of_key(k) -> number of items that are strictly smaller than k - - -#define FASTIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD1 1000000007 -#define MOD9 998244353 -#define INF 1e9 -#define INF1 1e18 -#define endl ""\n"" -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define lb lower_bound -#define ub upper_bound -#define fcout cout< vi; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector > vvi; -typedef vector vpii; -typedef vector vpll; -template using PQ = priority_queue; -template using QP = priority_queue, greater>; -// ---------------------------------------------------------------------------------- - -// ---------------------------------- OPERATOR OVERLOADING --------------------------------------- -template -istream& operator>>(istream &istream, vector &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &x : v) cout << x << "" ""; return ostream; } -template -istream& operator>>(istream &istream, pair &p) { return (istream >> p.ff >> p.ss); } -template -ostream& operator<<(ostream &ostream, const pair &p) { return (ostream << p.ff << "" "" << p.ss); } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -// ------------------------------------------------------------------------------------------------ - - -// ------------------------------------------ DEBUG ------------------------------------------------ -#ifndef ONLINE_JUDGE -#define debug(x...) cerr <<__func__<<"":""<<__LINE__<<"" ["" << #x << ""] = ""; _print(x); cerr << endl; -#define HERE cerr <<__func__<<"":""<<__LINE__<<"" [ here ] ""; cerr << endl; -#else -#define debug(x...) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(vector > v) {cerr << ""{ ""; for (vector i : v) {cerr << ""[ ""; for (T j : i) {_print(j); cerr << "" "";}; cerr << ""] "";} cerr << ""}"";} -template void _print(vector < pair > vp) {cerr << ""{ ""; for (pair i : vp) {cerr << ""[ ""; ""{""; _print(i.ff); cerr << "",""; _print(i.ss); cerr << "" ] "";} cerr << ""}"";} -template void _print(stack st) {cerr << ""[ ""; while (!st.empty()) {_print(st.top()); st.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(queue q) {cerr << ""[ ""; while (!q.empty()) {_print(q.front()); q.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(deque dq) {cerr << ""[ ""; while (!dq.empty()) {_print(dq.front()); dq.pop_front(); cerr << "" "";} cerr << ""]"";} -template void _print(PQ pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(QP pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -//--------------------------------------------------------------------------------------------------- - -void solve() { - - //solution starts from here - ll l, r; - cin >> l >> r; - int mx = 0; - for (int i = 0; i < 32; i++) { - if ((r & (1LL << i)) && (l & (1LL << i)) == 0) mx = i; - } - int a = 0; - for (int i = mx; i < 32; i++) { - a |= ((1LL << i) & r); - } - debug(2*(a^(a-1))) - cout << a << "" "" << a - 1 << "" "" << a<< endl; -} - -int main() { - -#ifndef ONLINE_JUDGE - freopen(""error.txt"", ""w"", stderr); -#endif - - FASTIO(); - auto start1 = high_resolution_clock::now(); - int t = 1; - cin >> t; - int T = t; - while (t--) - { - #ifndef ONLINE_JUDGE - cerr<<""Test ""<<(T-t)<<"" :""<(stop1 - start1); -#ifndef ONLINE_JUDGE - cerr << ""Time elapsed : "" << (duration . count() / 1000000) << '.' << (duration . count() % 1000000) << endl; -#endif - -}","#include -#define int long long -using namespace std; - - - -void Solve() -{ - - int a, b; - cin >> a >> b; -if(a > b) swap(a,b); -bitset<52> bitsA(a); -bitset<52> bitsB(b); -string sA; -string sB; -int index = -1; -for(int i = 51 ; i >= 0 ; i--){ - if(bitsA[i] != bitsB[i]){ - index = i; - break; - } -} -string ans; - -for(int i = index - 1 ; i >= 0 ; i--){ - if(bitsA[i] == bitsB[i] && bitsA[i] == '0'){ - index = i; - ans += '1'; - break; - } - else{ - if (bitsA[i] != bitsB[i]) ans += '1'; - else ans += '0'; - } -} - - -for(int i = index ; i >= 0 ; i--){ - sA += bitsA[i] + '0'; - sB += bitsB[i] + '0'; - ans += !(bitsA[i] & bitsB[i]) + '0'; -} - -ans[0] = '0'; -if(ans > sA){ - -} -else{ - ans[0] = '1'; -} - - - -bitset<52> bitsC(a); - -for(int i = 0 ; i <= index ; i++){ - bitsC[i] = ans[index - i] -'0'; -} -cout<> t; - for(int i = 0 ; i -using namespace std; -#define int long long -const int mod = 1e9 + 7; - -int32_t main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t--) - { - int l, r; - cin >> l >> r; - int a = 0, b = 0, c; - int k = 31; - - while (k >= 0) - { - if ((r & (1 << k)) == (l & (1 << k))) - { - if (l & (1 << k)) - { - a |= (1 << k); - b |= (1 << k); - } - - k--; - } - else - { - a |= (1 << k); - break; - } - } - k--; - - while (k >= 0) - { - if (!(l & (1 << k))) - { - while (k >= 0) - { - if (!(l & (1 << k))) - b |= (1 << k); - k--; - } - break; - } - b |= (1 << k); - k--; - } - if (b != l) - cout << a << "" "" << b << "" "" << l << endl; - else - cout << a << "" "" << b << "" "" << r << endl; - } - return 0; -} -","#include -using namespace std; -#define int long long -const int mod = 1e9 + 7; - -int32_t main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t--) - { - int l,r; - cin>>l>>r; - int a=0,b=0,c; - int k=31; - if((r-l+1)==3) - { - cout<=0) - { - if((r&(1<=0) - { - if(!(l&(1<=0) - { - if(!(l&(1< -#include -#include //ÓÃtree -using namespace std; -namespace pbds = __gnu_pbds; -template -using pbdstree = pbds::tree,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>; -#define int long long -using ll = long long; -template -using Qmin = priority_queue, greater>; -template -using Qmax = priority_queue; -#define rep(i, a, b) for(int i = a; i <= (b); ++i) -#define frep(i, a, b) for(int i = a; i < (b); ++i) -#define drep(i, a, b) for(int i = a; i >= (b); --i) -// #define ls (p << 1) -// #define rs (p << 1 | 1) -// #define mid ((l + r) >> 1) -const int MAXN = 200010; -const int MOD = 998244353; -// const int INF = 0x3f3f3f3f; -const int INF = 1e15; -int get(int x, int k){ - return (x >> k) & 1; -} -void solve(){ - int l, r; - cin >> l >> r; - int ans = 0; - int i = 30; - while(i >= 0){ - if(get(l, i) != get(r, i)) break; - --i; - } - int x = (r >> i) << i; - int y = x - 1; - int z = x == r ? y - 1 : x + 1; - cout << x << "" "" << y << "" "" << z << endl; - return; -} -signed main(){ - // cout << (965321865 ^ 375544086) + (965321865 ^ 12551794) + (375544086 ^ 12551794) << endl; - ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - int _t = 1; - cin >> _t; - while(_t--){ - solve(); - } - return 0; -}","#include -#include -#include //ÓÃtree -using namespace std; -namespace pbds = __gnu_pbds; -template -using pbdstree = pbds::tree,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>; -#define int long long -using ll = long long; -template -using Qmin = priority_queue, greater>; -template -using Qmax = priority_queue; -#define rep(i, a, b) for(int i = a; i <= (b); ++i) -#define frep(i, a, b) for(int i = a; i < (b); ++i) -#define drep(i, a, b) for(int i = a; i >= (b); --i) -// #define ls (p << 1) -// #define rs (p << 1 | 1) -// #define mid ((l + r) >> 1) -const int MAXN = 200010; -const int MOD = 998244353; -// const int INF = 0x3f3f3f3f; -const int INF = 1e15; -int get(int x, int k){ - return (x >> k) & 1; -} -void solve(){ - int l, r; - cin >> l >> r; - int ans = 0; - int i = 30; - while(i >= 0){ - if(get(l, i) != get(r, i)) break; - --i; - } - r = (r >> i) << i; - l = l + (1 << i) - 1; - cout << r << "" "" << r << "" "" << l << endl; - return; -} -signed main(){ - // cout << (965321865 ^ 375544086) + (965321865 ^ 12551794) + (375544086 ^ 12551794) << endl; - ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - int _t = 1; - cin >> _t; - while(_t--){ - solve(); - } - return 0; -}",1 -Btech_Griever,2057C - Trip to the Olympiad,c++20 ,301282620,301273774,"#include -using namespace std; - -#define fo(i, n) for (i = 0; i < n; i++) -#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define all(x) x.begin(), x.end() -#define sortall(x) sort(all(x)) -#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) -typedef pair pii; -typedef pair pl; -typedef vector vi; -typedef vector vl; -typedef vector vpii; -typedef vector vpl; -typedef vector vvi; -typedef vector vvl; -typedef unordered_map umpl; -typedef unordered_map umpi; -typedef map mpl; -typedef map mpi; -typedef priority_queue pql; -typedef priority_queue pqi; -typedef priority_queue, greater> minpql; -typedef priority_queue, greater> minpqi; -typedef stack stl; -typedef stack sti; -const ll mod = 1'000'000'007; -const ll N = 3e5, M = N; -vpii dir = {{1,0},{-1,0},{0,1},{0,-1}}; -vpii dir1 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}}; -//======================= - -vi g[N]; - -ll logB2(ll n) -{ - ll count=0; - while (n>0) - { - n/=2; - count++; - } - return count; -} - -ll XNOR(ll a, ll b) -{ - ll numOfBits = logB2(max(a, b)); - ll mask = (1 << numOfBits) - 1; - ll xnor = ~(a ^ b); - return xnor & mask; -} -void solve() -{ - ll n, i, j, k, m; - ll l,r; - cin>>l>>r; - ll a=l; - ll b=r; - ll count=0; - while (a!=b) - { - a/=2; - b/=2; - count++; - } - ll num=a; - num=num<> t; - while (t--) - { - solve(); - } - // solve(); - return 0; -} -","#include -using namespace std; - -#define fo(i, n) for (i = 0; i < n; i++) -#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) -#define ll long long -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define all(x) x.begin(), x.end() -#define sortall(x) sort(all(x)) -#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) -typedef pair pii; -typedef pair pl; -typedef vector vi; -typedef vector vl; -typedef vector vpii; -typedef vector vpl; -typedef vector vvi; -typedef vector vvl; -typedef unordered_map umpl; -typedef unordered_map umpi; -typedef map mpl; -typedef map mpi; -typedef priority_queue pql; -typedef priority_queue pqi; -typedef priority_queue, greater> minpql; -typedef priority_queue, greater> minpqi; -typedef stack stl; -typedef stack sti; -const ll mod = 1'000'000'007; -const ll N = 3e5, M = N; -vpii dir = {{1,0},{-1,0},{0,1},{0,-1}}; -vpii dir1 = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}}; -//======================= - -vi g[N]; - -ll logB2(ll n) -{ - ll count=0; - while (n>0) - { - n/=2; - count++; - } - return count; -} - -ll XNOR(ll a, ll b) -{ - ll numOfBits = logB2(max(a, b)); - ll mask = (1 << numOfBits) - 1; - ll xnor = ~(a ^ b); - return xnor & mask; -} -void solve() -{ - ll n, i, j, k, m; - ll l,r; - cin>>l>>r; - // if(temp+1 <=r) - // { - // if(temp-1>=l) - // { - // // cout<=r) - // { - // num/=2; - // } - // if(num<=l) - // { - // num*=2; - // } - // // ll temp=logB2(l); - // // temp=pow(2, (temp-1)); - // // num=temp; - // // if(num==r) - // // { - // // num/=2; - // // } - // ll f=l; - // ll s=r; - // // // cout<0 || r>0) - // // { - // // ll bit1=l&1; - // // ll bit2=r&1; - // // l=l/2; - // // r=r/2; - // // if(r==0 && l==0 ) - // // { - // // break; - // // } - // // if(bit1==bit2) - // // { - // // if(bit1==0) - // // { - // // num=num|(1<=r) - // { - // num/=2; - // } - // if(num<=l) - // { - // num*=2; - // } - // cout<=l+1) - { - cout<=l+1) - { - cout<> t; - while (t--) - { - solve(); - } - // solve(); - return 0; -} -",1 -darshanjk,2057C - Trip to the Olympiad,c++17 ,300532776,300527838,"#include -using namespace std; -#define int long long -void solve(){ -int l,r; -cin>>l>>r; -int temp=l^r; -int cnt=0; -while(temp!=0){temp>>=1;cnt++;} -cnt--; -//most significant differing in l,r bit is off -int a=((1ll<1 b is always valid -int c=(a==l?r:l); // if a is l then b=l+1 so c can be from l+2 as r-l>1 -cout<>t; - while (t--) { - solve(); - } -}","#include -using namespace std; -#define int long long -void solve(){ -int l,r; -cin>>l>>r; -int temp=r; -int cnt=0; -while(temp!=0){temp>>=1;cnt++;} -cnt--; -int a=1ll<1 -cout<>t; - while (t--) { - solve(); - } -}",1 -Ahmed_Ghazal,2057C - Trip to the Olympiad,c++20 ,301210317,301209343,"#include - -using namespace std; - -#define int long long - -int msb(int n) { - - // calculate the number - // of leading zeroes - int k = __builtin_clz(n); - - // To return the value - // of the number with set - // bit at (31 - k)-th position - // assuming 32 bits are used - return 1 << (31 - k); -} - -void solve() { - int l, r, r1; - cin >> l >> r, r1 = r; - while (true) { - if (msb(l) != msb(r)) { - int a, b, c; - for (int i = 0; i < 35; ++i) { - if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) { - int x = r1 & ((1ll << (i + 1)) - 1); - a = (r1 - x + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1); - break; - } - } - cout << a << ' ' << b << ' ' << c; - return; - } - r ^= msb(r); - l ^= msb(l); - } - -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t = 1; - cin >> t; - while (t--) { - solve(); - if (t) - cout << '\n'; - } -}","#include - -using namespace std; - -#define int long long - -int msb(int n) { - - // calculate the number - // of leading zeroes - int k = __builtin_clz(n); - - // To return the value - // of the number with set - // bit at (31 - k)-th position - // assuming 32 bits are used - return 1 << (31 - k); -} - -void solve() { - int l, r, r1; - cin >> l >> r, r1 = r; - while (true) { - if (msb(l) != msb(r)) { - int a, b, c; - for (int i = 0; i < 35; ++i) { - if ((msb(r) <= (1ll << i)) && (r1 & (1ll << i))) { - a = (r1 - (1ll << i) + msb(r)), b = a - 1, c = (a == r1 ? a - 2 : r1); - break; - } - } - cout << a << ' ' << b << ' ' << c; - return; - } - r ^= msb(r); - l ^= msb(l); - } - -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t = 1; - cin >> t; - while (t--) { - solve(); - if (t) - cout << '\n'; - } -}",1 -ayush_saxena_15022002,2057C - Trip to the Olympiad,c++17 ,305043694,305043120,"#include -#include -#include -#define pb push_back -#define INF 0x3f3f3f3f -#define LINF 0x3f3f3f3f3f3f3f3f -#define endl '\n' -#define ll long long -#define f first -#define fin cin -#define fout cout -#define s second -#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) -#define debug(x) cout << ""DEBUG "" << x << endl -#define debug2(x, y) cout << ""DEBUG "" << x << "" "" << y << endl -#define debug3(x, y, z) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< endl -#define debug4(x, y, z, o) cout << ""DEBUG "" << x << "" "" << y << "" "" << z<< "" "" << o << endl -#define all(x) x.begin(), x.end() -#define left esquerda -#define lb lower_bound -#define right direita -using namespace std; -void setIO(string s) { -ios_base::sync_with_stdio(0); cin.tie(0); -freopen((s+"".in"").c_str(),""r"",stdin); -freopen((s+"".out"").c_str( ),""w"",stdout); -} -typedef pair pii; -typedef vector> mat; -typedef pair pis; -const ll mod = 1e9 + 7, MAXN = 2e5 + 5; -typedef vector vi; -typedef pair> piii; - -void solve() { - ll l, r; - cin >> l >> r; - - ll last = 1; - while(last * 2 <= r) - last *= 2; - - int aux = last; - while(true) { - if( (last & r) && !(last & l)) { - aux += last; - break; - } - last /= 2; - } - - cout << aux-1 << "" "" << aux << "" "" << aux + 2 << endl; - -} - -int32_t main() { - int ct; - cin >> ct; - while(ct--) - solve(); -}","#include -using namespace std; - - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define nline ""\n"" -#define pb push_back -#define ppb pop_back -#define mp make_pair -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() - - -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; - -ll gcd(ll a, ll b){ - return (b==0)?a:gcd(b, a%b); -} - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - - - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - -void solve(){ - ll l, r; - cin >> l >> r; - - ll a=0, b=0, c=l; - for( ll i=29; i>=0; i-- ){ - if( (l & (1<> t; - for ( int i = 0; i < t; i++ ) - solve(); - return 0; -}",1 -nils_,2057C - Trip to the Olympiad,c++23 ,303451476,303451410,"#include -using namespace std; -#define endl '\n' -#define int long long - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int t; cin >> t; - while(t--) { - int l, r; cin >> l >> r; - - int a=0, b=0, c=0, k=0; - for(int i=30;i>=0;i--) { - if((l&(1LL< -using namespace std; -#define endl '\n' -#define int long long - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int t; cin >> t; - while(t--) { - int l, r; cin >> l >> r; - - int a=0, b=0, c=0, k=0; - for(int i=30;i>=0;i--) { - if((l&(1LL< - -using i64 = long long; - -void solve() { - int l, r; - std::cin >> l >> r; - - int a = l, c = r, b = 0; - int pos; - for (int i = 31; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - pos = i; - break; - } - } - - for (int i = 31; i > pos; i --) { - int x = a >> i & 1; - b += x * 1 << i; - } - - for (int i = pos; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y == 0) { - b += (!x) << i; - } - } - - for (int i = pos; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - if (b + (1 << i) < c) { - b += 1 << i; - } - } - } - - std::cout << a << "" "" << b << "" "" << c << ""\n""; -} - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - std::cout << std::fixed << std::setprecision(20); - - int T = 1; - std::cin >> T; - - while (T --) { - solve(); - } - - return 0; -}","#include - -using i64 = long long; - -void solve() { - i64 l, r; - std::cin >> l >> r; - - i64 a = l, c = r, b = 0; - int pos; - for (int i = 32; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - pos = i; - break; - } - } - - for (int i = 32; i > pos; i --) { - int x = a >> i & 1; - b += x << i; - } - - for (int i = pos; i >= 0; i --) { - int x = a >> i & 1; - int y = c >> i & 1; - if (x ^ y) { - if (b + (1 << i) < c) { - b += 1ll << i; - } - } else { - b += (!x) * 1ll << i; - } - } - - std::cout << a << "" "" << b << "" "" << c << ""\n""; -} - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - std::cout << std::fixed << std::setprecision(20); - - int T = 1; - std::cin >> T; - - while (T --) { - solve(); - } - - return 0; -}",1 -Pangbai,2057C - Trip to the Olympiad,c++20 ,300241325,300240724,"#include -using namespace std; -using ll = long long; - -#define pb push_back - -const int maxn = 2e5 + 10; -int l, r; - -void solve(){ - cin>>l>>r; - int a = 0; - int b = 0; - int c = 0; - for(int i = 29; i >= 0; i--){ - if((1 << i) > r) continue; - int x = ((r >> i) & 1); - int y = ((l >> i) & 1); - if(x == y && x == 1){ - a += (1 << i); - b += (1 << i); - } - else if(x != y){ - a += (1 << i); - b += ((1 << i) - 1); - break; - } - } - c = l; - while(c == b || c == a) c++; - cout<>T; - while(T--){ - solve(); - } - return 0; -} -","#include -using namespace std; -using ll = long long; - -#define pb push_back - -const int maxn = 2e5 + 10; -int l, r; - -void solve(){ - cin>>l>>r; - int a = 0; - int b = 0; - int c = 0; - for(int i = 29; i >= 0; i--){ - if((1 << i) > r) continue; - int x = ((r >> i) & 1); - int y = ((l >> i) & 1); - if(x == y){ - a += (1 << i); - b += (1 << i); - } - else{ - a += (1 << i); - b += ((1 << i) - 1); - break; - } - } - c = l; - while(c == b || c == a) c++; - cout<>T; - while(T--){ - solve(); - } - return 0; -} -",1 -ritik108,2057C - Trip to the Olympiad,c++17 ,301062464,301062833,"//****************************************************************** -// Author: Ritik Arora -#include -using namespace std; -#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ll long long int - -#include // Common file -using namespace __gnu_pbds; -typedef tree, rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key - -#define nline '\n' -#define inf LLONG_MAX -ll mod1 = 1e9 + 7; -ll mod2 = 998244353; - -ll expo(ll a, ll b, ll mod) -{ - ll res = 1; - while (b > 0) - { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return res; -} - -vector sieve(int n) -{ - int *arr = new int[n + 1](); - vector vect; - for (int i = 2; i <= n; i++) - if (arr[i] == 0) - { - vect.push_back(i); - for (int j = 2 * i; j <= n; j += i) - arr[j] = 1; - } - return vect; -} - -ll inverseMod(ll n, ll mod) { return expo(n, mod - 2, mod); } -ll mod_mul(ll a, ll b, ll m) -{ - a = a % m; - b = b % m; - return (((a * b) % m) + m) % m; -} -ll mod_div(ll a, ll b, ll m) -{ - a = a % m; - b = b % m; - return (mod_mul(a, inverseMod(b, m), m) + m) % m; -} // only for prime m - -#define yes cout<<""YES""<> l >> r; - ll fix = 0; - ll start = int(log2(r)); - - for (int i = start; i >= 0;i--) - { - ll a = (r >> i) & 1; - ll b = (l >> i) & 1; - if(a) - { - ll wt = (1 << i); - - if(b){ - fix += wt; - r -= wt; - l -= wt; - } - else{ - ll a = fix + wt; - ll b = fix + wt - 1; - if(a+1<=r) - { - cout << a << "" "" << b << "" "" << a + 1 << endl; - } - else{ - cout << a << "" "" << b << "" "" << b - 1 << endl; - } - return; - } - } - } - -} -int main() -{ - // unordered_map mp; - // StringHash hash(word); - // hash.substrHash(idx1,idx2)==hash.substrHash(idx3,idx4); - // Trie* T = new Trie(); - // string ritik=""ritik""; - // T->insertNode(ritik); - // #ifndef ONLINE_JUDGE - // freopen(""Error.txt"", ""w"", stderr); - // #endif - fastio(); - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}","//****************************************************************** -// Author: Ritik Arora -#include -using namespace std; -#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) - -#define ll long long int - -#include // Common file -using namespace __gnu_pbds; -typedef tree, rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key - -#define nline '\n' -#define inf LLONG_MAX -ll mod1 = 1e9 + 7; -ll mod2 = 998244353; - -ll expo(ll a, ll b, ll mod) -{ - ll res = 1; - while (b > 0) - { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return res; -} - -vector sieve(int n) -{ - int *arr = new int[n + 1](); - vector vect; - for (int i = 2; i <= n; i++) - if (arr[i] == 0) - { - vect.push_back(i); - for (int j = 2 * i; j <= n; j += i) - arr[j] = 1; - } - return vect; -} - -ll inverseMod(ll n, ll mod) { return expo(n, mod - 2, mod); } -ll mod_mul(ll a, ll b, ll m) -{ - a = a % m; - b = b % m; - return (((a * b) % m) + m) % m; -} -ll mod_div(ll a, ll b, ll m) -{ - a = a % m; - b = b % m; - return (mod_mul(a, inverseMod(b, m), m) + m) % m; -} // only for prime m - -#define yes cout<<""YES""<> l >> r; - ll fix = 0; - ll start = int(log2(r)); - - for (int i = start; i >= 0;i--) - { - ll a = (r >> i) & 1; - ll b = (l >> i) & 1; - if(a) - { - ll wt = (1 << i); - - if(b){ - fix += wt; - r -= wt; - l -= wt; - } - else{ - ll a = fix + wt; - ll b = fix + wt - 1; - if(wt+1<=r) - { - cout << a << "" "" << b << "" "" << a + 1 << endl; - } - else{ - cout << a << "" "" << b << "" "" << b - 1 << endl; - } - return; - } - } - } - -} -int main() -{ - // unordered_map mp; - // StringHash hash(word); - // hash.substrHash(idx1,idx2)==hash.substrHash(idx3,idx4); - // Trie* T = new Trie(); - // string ritik=""ritik""; - // T->insertNode(ritik); - // #ifndef ONLINE_JUDGE - // freopen(""Error.txt"", ""w"", stderr); - // #endif - fastio(); - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}",2 -Istiaque_ahmed,2057C - Trip to the Olympiad,c++23 ,300374133,300368366,"/******************************************* - @b |I|s|t|i|a|q|u|e| |A|h|m|e|d| |A|r|i|k| -********************************************/ -#pragma GCC optimize(""O3"") -#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define static_assert(...) ; -#include -using u_bitset = tr2::dynamic_bitset<__uint128_t>; -using l_bitset = tr2::dynamic_bitset<__int128_t>; -void __print(int x) { cerr << x; } -#define bigll __int128_t -#define bigull __uint128_t -#define ll int_fast64_t -#define ull uint_fast64_t -#define ld long double -#define pi acos(-1) -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define IOS \ - ios::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -#define FileIO \ - freopen(""input.txt"", ""r"", stdin); \ - freopen(""output.txt"", ""w"", stdout) -///@b decltype and const -const int MOD = 1e9 + 7, dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; -///@b debug -struct _ -{ - ios_base::Init i; - _() - { - cin.sync_with_stdio(0); - cin.tie(0); - cout << fixed << setprecision(10); - } -} ___; -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } - -template -void __print(const pair &x) -{ - cerr << '{'; - __print(x.first); - cerr << ','; - __print(x.second); - cerr << '}'; -} -template -void __print(const T &x) -{ - int f = 0; - cerr << '{'; - for (auto &i : x) - cerr << (f++ ? "","" : """"), __print(i); - cerr << ""}""; -} -void _print() { cerr << ""]\n""; } -template -void _print(T t, V... v) -{ - __print(t); - if (sizeof...(v)) - cerr << "", ""; - _print(v...); -} -#ifndef ONLINE_JUDGE -#define debug(x...) \ - cerr << ""["" << #x << ""] = [""; \ - _print(x) -#else -#define debug(x...) -#endif - -template -using ht = gp_hash_table; - -///@b PBDS -// template -// using o_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_set_g = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_multiset_g = tree, rb_tree_tag, tree_order_statistics_node_update>; - -bool f(ll l, ll r) -{ -} - -inline void solve() -{ - ll l, r; - cin >> l >> r; - ll x = l ^ r; - bitset<32> b(x); - ll msb = 32; - for (ll i = 31; i >= 0; i--) - { - if (b[i]) - { - msb = i; - break; - } - } - // cout << << endl; - bitset<32> a(l); - bitset<32> ans; - for (int i = 32; i > msb; i--) - { - ans[i] = a[i]; - } - ans[msb] = 1; - for (int i = msb - 1; i >= 0; i--) - { - ans[i] = 0; - } - ll res = ans.to_ullong(); - for (ll i = l; i <= r; i++) - { - if (i != res and i != res - 1) - { - cout << res << "" "" << res - 1 << "" "" << i << ""\n""; - return; - } - } -} - -auto main() -> int32_t -{ - IOS; - int t = 1, cs = 1; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}","/******************************************* - @b |I|s|t|i|a|q|u|e| |A|h|m|e|d| |A|r|i|k| -********************************************/ -#pragma GCC optimize(""O3"") -#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define static_assert(...) ; -#include -using u_bitset = tr2::dynamic_bitset<__uint128_t>; -using l_bitset = tr2::dynamic_bitset<__int128_t>; -void __print(int x) { cerr << x; } -#define bigll __int128_t -#define bigull __uint128_t -#define ll int_fast64_t -#define ull uint_fast64_t -#define ld long double -#define pi acos(-1) -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define IOS \ - ios::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -#define FileIO \ - freopen(""input.txt"", ""r"", stdin); \ - freopen(""output.txt"", ""w"", stdout) -///@b decltype and const -const int MOD = 1e9 + 7, dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; -///@b debug -struct _ -{ - ios_base::Init i; - _() - { - cin.sync_with_stdio(0); - cin.tie(0); - cout << fixed << setprecision(10); - } -} ___; -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } - -template -void __print(const pair &x) -{ - cerr << '{'; - __print(x.first); - cerr << ','; - __print(x.second); - cerr << '}'; -} -template -void __print(const T &x) -{ - int f = 0; - cerr << '{'; - for (auto &i : x) - cerr << (f++ ? "","" : """"), __print(i); - cerr << ""}""; -} -void _print() { cerr << ""]\n""; } -template -void _print(T t, V... v) -{ - __print(t); - if (sizeof...(v)) - cerr << "", ""; - _print(v...); -} -#ifndef ONLINE_JUDGE -#define debug(x...) \ - cerr << ""["" << #x << ""] = [""; \ - _print(x) -#else -#define debug(x...) -#endif - -template -using ht = gp_hash_table; - -///@b PBDS -// template -// using o_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_set_g = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using o_multiset_g = tree, rb_tree_tag, tree_order_statistics_node_update>; - -void mxTrioXor(ll l, ll r) -{ - array ans = {0, 0, 0}; - ll mx = 0; - for (ll i = l; i <= r; i++) - { - for (ll j = i + 1; j <= r; j++) - { - for (ll k = j + 1; k <= r; k++) - { - if ((i ^ j ^ k) > mx) - { - mx = i ^ j ^ k; - ans = {i, j, k}; - } - } - } - } - - for (ll i = l; i <= r; i++) - { - for (ll j = i + 1; j <= r; j++) - { - for (ll k = j + 1; k <= r; k++) - { - if ((i ^ j ^ k) == mx) - { - cout << i << "" "" << j << "" "" << k << endl; - } - } - } - } - cout << mx << ""\n""; -} - -inline void solve() -{ - ll l, r; - cin >> l >> r; - bitset<32> b(l ^ r), rbit(r); - bitset<32> ans; - ll mx = (1ll << 30); - while (mx > r) - { - mx >>= 1; - } - for (ll i = l; i <= r; i++) - { - if (i != mx and i != (mx - 1)) - { - cout << mx << "" "" << mx - 1 << "" "" << i << ""\n""; - return; - } - } -} - -auto main() -> int32_t -{ - IOS; - int t = 1, cs = 1; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}",1 -Mahadeva,2057C - Trip to the Olympiad,c++20 ,302210655,300962518,"/* This was created by Ravinder Dathak. - * Codeforces id by name of Mahadeva. - * On 04-04-2024. - * As proof that the following code is my own and authenticate. -*/ - -#include -#include -#include -#include -#include - -using namespace std; - -//Uncomment during contest. -#define int long long int -#define double long double float - -#define input(n) for(int i=0;i<(int)n;i++) - -//uncomment during practice. Plz take care of int and long long int. -//typedef long long int ll; -//typedef long double ld; - -const int Mod= 1e9+7; - -//uncomment to use AutoCp and before any submission. -// #define ONLINE_JUDGE - -void solve(){ - int l,r; - cin>>l>>r; - int k; - for(int i=30;i>=0;i--){ - if((l>>i)^(r>>i)){ - k=i; - break; - } - } - int a=l|((1<> t; - while (t--) { - solve(); - } - return 0; -}","/* This was created by Ravinder Dathak. - * Codeforces id by name of Mahadeva. - * On 04-04-2024. - * As proof that the following code is my own and authenticate. -*/ - -#include -#include -#include -#include -#include - -using namespace std; - -//Uncomment during contest. -#define int long long int -#define double long double float - -#define input(n) for(int i=0;i<(int)n;i++) - -//uncomment during practice. Plz take care of int and long long int. -//typedef long long int ll; -//typedef long double ld; - -const int Mod= 1e9+7; - -//uncomment to use AutoCp and before any submission. -// #define ONLINE_JUDGE - -void solve(){ - int l,r; - cin>>l>>r; - if(l==0){ - cout<=0;i--){ - if( ((r>>i)&1) == 0 )ans+=(1<> t; - while (t--) { - solve(); - } - return 0; -}",1 -pikachu_fun,2057C - Trip to the Olympiad,c++23 ,300523967,300524102,"#include -#define _fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define pb(e) push_back(e) -#define all(x) (x).begin(), (x).end() -#define allr(x) (x).rbegin(), (x).rend() -#define endl '\n' - -using namespace std; -using i64 = long long; -using PII = pair; -const int INF = 0x3f3f3f3f; -void fun() -{ - int n,m; - cin >> n >> m; - int k = 31 - __builtin_clz(n ^ m); - int a = n | (1 << k - 1); - int b = a + 1; - int c = (a == n ? m : n); - cout << a << ' ' << b << ' ' << c << endl; -} -int main() { - int t; - cin >> t; - while(t -- ) fun(); - return 0; -}","#include -#define _fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define pb(e) push_back(e) -#define all(x) (x).begin(), (x).end() -#define allr(x) (x).rbegin(), (x).rend() -#define endl '\n' - -using namespace std; -using i64 = long long; -using PII = pair; -const int INF = 0x3f3f3f3f; -void fun() -{ - int n,m; - cin >> n >> m; - int k = 31 - __builtin_clz(n ^ m); - int a = n | ((1 << k) - 1); - int b = a + 1; - int c = (a == n ? m : n); - cout << a << ' ' << b << ' ' << c << endl; -} -int main() { - int t; - cin >> t; - while(t -- ) fun(); - return 0; -}",2 -TsaaQiif,2057C - Trip to the Olympiad,c++20 ,300818625,300818934,"#include ""bits/stdc++.h"" -using namespace std; -void solve(){ - int batas_min,batas_max; - cin>>batas_min>>batas_max; - int k=31- __builtin_clz(batas_min^batas_max); - int a = l | ((1 << k) - 1); - int b = a + 1; - int c = (a == l ? batas_max : l); - cout<>t; - while(t--){ - solve(); - } -}","#include ""bits/stdc++.h"" -using namespace std; -void solve(){ - int batas_min,batas_max; - cin>>batas_min>>batas_max; - int k=31- __builtin_clz(batas_min^batas_max); - int a = batas_min | ((1 << k) - 1); - int b = a + 1; - int c = (a == batas_min ? batas_max : batas_min); - cout<>t; - while(t--){ - solve(); - } -}",2 -JatinSai,2057C - Trip to the Olympiad,c++20 ,300293642,300291954,"#include - -using namespace std; -#define int long long int -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) { - int l, r; - cin >> l >> r; - int k = 31 - __builtin_clz(l ^ r); - int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l); - cout << a << "" "" << b << "" "" << c << ""\n""; - - } - // your code goes here - -}","#include - -using namespace std; -#define int long long int -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t; - cin >> t; - while (t--) { - int l, r; - cin >> l >> r; - int a = 0, b = 0, c = 0, pos; - for (int i = 30; i >= 0; i--) { - int bit = (1 << i); - if ((l & b) != (r & b)) { - pos = i; - break; - } - } - - a = l | ((1 << pos) - 1); - b = a + 1; - c = r; - - if (c == a || c == b) { - c--; - } - if (c == a || c == b) { - c--; - } - cout << a << "" "" << b << "" "" << c << ""\n""; - - } - // your code goes here - -}",1 -ha_ha_,2057C - Trip to the Olympiad,c++20 ,306654609,306654464,"#include -#include -#include -#include - -using namespace std; - -int l, r; - -int main() -{ - int T; - scanf(""%d"", &T); - while (T --) - { - scanf(""%d%d"", &l, &r); - int t = l ^ r; - int start; - for (int i = 30; i >= 0; i --) - if (t >> i & 1) - { - start = i; - break; - } - // cout << ""start:"" << start << endl; - int a = 0, b = 0, c = 0; - if ((t >> (start - 1)) == 1) - { - a = (1 << start), b = (1 << start) - 1; - a = a + (l >> start << start), b = b + (l >> start << start); - for (int i = l; i <= r; i ++) - if (i != a && i != b) - { - c = i; - break; - } - } - else - { - a = (1 << start), b = (1 << (start - 1)); - for (int i = start - 2; i >= 0; i --) - { - if (t >> i & 1) - { - if (l >> i & 1) b = b + (1 << i); - else a = a + (1 << i); - } - else - { - b = b + (1 << i); - } - } - a = a + (l >> start << start), b = b + (l >> start << start); - for (int i = l; i <= r; i ++) - if (i != a && i != b) - { - c = i; - break; - } - } - // cout << ""start:"" << start << endl; - printf(""%d %d %d\n"", a, b, c); - // printf(""%d\n"", (a ^ b) + (a ^ c) + (b ^ c)); - // printf(""%d\n"", (123 ^ 121) + (123 ^ 118) + (121 ^ 118));//123 121 118 - } - - return 0; -}","#include -#include -#include -#include - -using namespace std; - -int l, r; - -int main() -{ - int T; - scanf(""%d"", &T); - while (T --) - { - scanf(""%d%d"", &l, &r); - int t = l ^ r; - int start; - for (int i = 30; i >= 0; i --) - if (t >> i & 1) - { - start = i; - break; - } - // cout << ""start:"" << start << endl; - int a = 0, b = 0, c = 0; - if ((t >> (start - 1)) == 1) - { - a = (1 << start), b = (1 << start) - 1; - for (int i = l; i <= r; i ++) - if (i != a && i != b) - { - c = i; - break; - } - } - else - { - a = (1 << start), b = (1 << (start - 1)); - for (int i = start - 2; i >= 0; i --) - { - if (t >> i & 1) - { - if (l >> i & 1) b = b + (1 << i); - else a = a + (1 << i); - } - else - { - b = b + (1 << i); - } - } - for (int i = l; i <= r; i ++) - if (i != a && i != b) - { - c = i; - break; - } - } - // cout << ""start:"" << start << endl; - a = a + (l >> start << start), b = b + (l >> start << start); - printf(""%d %d %d\n"", a, b, c); - // printf(""%d\n"", (a ^ b) + (a ^ c) + (b ^ c)); - // printf(""%d\n"", (123 ^ 121) + (123 ^ 118) + (121 ^ 118));//123 121 118 - } - - return 0; -}",1 -outlast_NATE,2057C - Trip to the Olympiad,c++23 ,300238665,300238095,"#include -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""DEBUG.h"" -#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) -#endif - -#define first_in_out ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); -#define ll long long int -#define double long double -#define print(a) for(auto x : a) cout << x << "" ""; -#define printpair(a) for(auto x : a) cout << x.first << "" "" << x.second<<""\n""; - - - -void solve() - -{ - ll l, r; - cin >> l >> r; - ll a = 0, b = 0, c = 0; - int f = 0; - for (int j = 30; j >= 0; j--) - { - ll p = (1ll << j); - - if (f) { - b += p; - continue; - } - - - if ((l & p) == (r & p)) { - if ((l & p)) - a += p, b += p; - } - else if ((l & p) != (r & p)) { - a += p; - f = 1; - } - - } - - c = l; - - while (c == a or c == b) - c++; - - cout << a << "" "" << b << "" "" << c << ""\n""; -} - - -int main() -{ - first_in_out - - int t = 1; - cin >> t; - - while (t--) - solve(); - -} - -","#include -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""DEBUG.h"" -#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) -#endif - -#define first_in_out ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); -#define ll long long int -#define double long double -#define print(a) for(auto x : a) cout << x << "" ""; -#define printpair(a) for(auto x : a) cout << x.first << "" "" << x.second<<""\n""; - - - -void solve() - -{ - ll l, r; - cin >> l >> r; - ll a = 0, b = 0, c = 0; - int f = 0; - for (int j = 30; j >= 0; j--) - { - ll p = (1ll << j); - - if (f) { - b += p; - continue; - } - - - if ((l & p) == (r & p)) { - if ((l & p)) - a += p, b += p; - } - else if ((l & p) != (r & p)) { - a += p; - f = 1; - } - - } - - c = b; - - cout << a << "" "" << b << "" "" << c << ""\n""; -} - - -int main() -{ - first_in_out - - int t = 1; - cin >> t; - - while (t--) - solve(); - -} - -",1 -maherkh,2057C - Trip to the Olympiad,c++17 ,301620700,301620452,"/* - __ __ _ _ _____ _ _ - | \/ | /\ | | | | __ \ /\ | \ | | - | \ / | / \ | |__| | |__) | / \ | \| | - | |\/| | / /\ \ | __ | _ / / /\ \ | . ` | - | | | |/ ____ \| | | | | \ \ / ____ \| |\ | - |_| |_/_/ \_\_| |_|_| \_\/_/ \_\_| \_| - */ -#include -#include // Include cmath for M_PI -#ifndef M_PI -#define M_PI 3.14159265358979323846 // Define M_PI if not already defined -#endif -typedef long long ll; -ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } -ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -#define all(x) (x).begin(), (x).end() -#define pb push_back -#define ull unsigned long long -#define endl ""\n"" -using namespace std; -/* -pair t[4*MAXN]; - -pair combine(pair a, pair b) { - if (a.first > b.first) - return a; - if (b.first > a.first) - return b; - return make_pair(a.first, a.second + b.second); -} - -void build(int a[], int v, int tl, int tr) { - if (tl == tr) { - t[v] = make_pair(a[tl], 1); - } else { - int tm = (tl + tr) / 2; - build(a, v*2, tl, tm); - build(a, v*2+1, tm+1, tr); - t[v] = combine(t[v*2], t[v*2+1]); - } -} - -pair get_max(int v, int tl, int tr, int l, int r) { - if (l > r) - return make_pair(-INF, 0); - if (l == tl && r == tr) - return t[v]; - int tm = (tl + tr) / 2; - return combine(get_max(v*2, tl, tm, l, min(r, tm)), - get_max(v*2+1, tm+1, tr, max(l, tm+1), r)); -} - -void update(int v, int tl, int tr, int pos, int new_val) { - if (tl == tr) { - t[v] = make_pair(new_val, 1); - } else { - int tm = (tl + tr) / 2; - if (pos <= tm) - update(v*2, tl, tm, pos, new_val); - else - update(v*2+1, tm+1, tr, pos, new_val); - t[v] = combine(t[v*2], t[v*2+1]); - } -} -*/ - -template -void pop_front(std::vector &v) -{ - if (v.size() > 0) - { - v.erase(v.begin()); - } -} -const int MOD = 1e9 + 7; -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; -} -bool sortFirst(const pair &a, const pair &b) -{ - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first < b.first; -} - -void solve() -{ - ll l, r; - cin >> l >> r; - int i = 31; - bool t = false; - bool tt = false; - for (; i >= 0; i--) - { - if ((1LL << i) & l) - { - t = true; - } - if ((1LL << i) & r) - { - tt = true; - } - if (t && tt) - { - break; - } - } - int j = i; - for (; j >= 0; j--) - { - if (((1LL << j) & l) && !((1LL << j) & r)) - { - break; - } - } - ll k = 31 - __builtin_clz(l ^ r); - ll a = l | ((1LL << k) - 1); - ll b = a + 1; - ll c = l; - if (a == l) - { - c = r; - } - cout << a << "" "" << b << "" "" << c << endl; -} - -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); -#endif - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - - while (t--) - { - solve(); - } - - return 0; -}","/* - __ __ _ _ _____ _ _ - | \/ | /\ | | | | __ \ /\ | \ | | - | \ / | / \ | |__| | |__) | / \ | \| | - | |\/| | / /\ \ | __ | _ / / /\ \ | . ` | - | | | |/ ____ \| | | | | \ \ / ____ \| |\ | - |_| |_/_/ \_\_| |_|_| \_\/_/ \_\_| \_| - */ -#include -#include // Include cmath for M_PI -#ifndef M_PI -#define M_PI 3.14159265358979323846 // Define M_PI if not already defined -#endif -typedef long long ll; -ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } -ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -#define all(x) (x).begin(), (x).end() -#define pb push_back -#define ull unsigned long long -#define endl ""\n"" -using namespace std; -/* -pair t[4*MAXN]; - -pair combine(pair a, pair b) { - if (a.first > b.first) - return a; - if (b.first > a.first) - return b; - return make_pair(a.first, a.second + b.second); -} - -void build(int a[], int v, int tl, int tr) { - if (tl == tr) { - t[v] = make_pair(a[tl], 1); - } else { - int tm = (tl + tr) / 2; - build(a, v*2, tl, tm); - build(a, v*2+1, tm+1, tr); - t[v] = combine(t[v*2], t[v*2+1]); - } -} - -pair get_max(int v, int tl, int tr, int l, int r) { - if (l > r) - return make_pair(-INF, 0); - if (l == tl && r == tr) - return t[v]; - int tm = (tl + tr) / 2; - return combine(get_max(v*2, tl, tm, l, min(r, tm)), - get_max(v*2+1, tm+1, tr, max(l, tm+1), r)); -} - -void update(int v, int tl, int tr, int pos, int new_val) { - if (tl == tr) { - t[v] = make_pair(new_val, 1); - } else { - int tm = (tl + tr) / 2; - if (pos <= tm) - update(v*2, tl, tm, pos, new_val); - else - update(v*2+1, tm+1, tr, pos, new_val); - t[v] = combine(t[v*2], t[v*2+1]); - } -} -*/ - -template -void pop_front(std::vector &v) -{ - if (v.size() > 0) - { - v.erase(v.begin()); - } -} -const int MOD = 1e9 + 7; -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; -} -bool sortFirst(const pair &a, const pair &b) -{ - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first < b.first; -} - -void solve() -{ - ll l, r; - cin >> l >> r; - int i = 31; - bool t = false; - bool tt = false; - for (; i >= 0; i--) - { - if ((1LL << i) & l) - { - t = true; - } - if ((1LL << i) & r) - { - tt = true; - } - if (t && tt) - { - break; - } - } - int j = i; - for (; j >= 0; j--) - { - if (((1LL << j) & l) && !((1LL << j) & r)) - { - break; - } - } - ll k = 31 - __builtin_clz(l ^ r); - ll a = l | (1LL << (k - 1)); - ll b = a + 1; - ll c = l; - if (b == l) - { - c = r; - } - cout << a << "" "" << b << "" "" << c << endl; -} - -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); -#endif - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - - while (t--) - { - solve(); - } - - return 0; -}",1 -Aditya2004,2057C - Trip to the Olympiad,c++17 ,304812443,304812509,"#include -using namespace std; -int mod=1e9+7; -long long power(long long x,int y) -{ - long long res=1; - while(y>0) - { - int r=y%2; - if(r==1) - { - res=res*x; - } - y=y/2; - x=x*x; - } - return res; -} -int main() { - int t; - cin>>t; - while(t--) - { - long long low,l,high,h; - cin>>low>>high; - l=low; - h=high; - vectorv1(35,0),v2(35,0); - int j=32; - // long long p=1; - while(high>0) - { - int r1=high%2; - int r2=low%2; - v1[j]=r1; - v2[j]=r2; - j--; - - high=high/2; - low=low/2; - - } - // cout<l) - { - cout<l&&num2 -using namespace std; -#define int long long -#define ii pair -#define iii pair -#define fi first -#define se second -#define inf 1e16 -int tc, l, r; -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - if(fopen(""main.inp"",""r"")) { - freopen(""main.inp"", ""r"", stdin); - freopen(""main.out"", ""w"", stdout); - } - cin >> tc; - while(tc--) { - cin >> l >> r; - int a = 0, b = 0, c = 0; - for(int j = 30; j >= 0; j--) { - if((r&(1< -#include -using namespace std; -#define int long long int -#define ll long long int -#define ld long double -#define endl '\n' -#define loopi(n) for(int i=0;i>l>>r; - int a,b,c; - int ans = 0; - a = 0; - b = 0; - c = 1; - for(int i=30;i>=0;i--){ - int b1 = 0; - int b2 = 0; - - if(l&(1ll << i)){ - b1 = 1; - } - if(r&(1ll << i)){ - b2 = 1; - } - if(b1==b2){ - ans += b1*(1ll << i); - } - else{ - a = ans + (1ll<>t; - - while(t--){ - - solve(); - - } - return 0; -} - - -","//जय सिया राम -// Author : **Aditya Raj** - -#include -#include -using namespace std; -#define int long long int -#define ll long long int -#define ld long double -#define endl '\n' -#define loopi(n) for(int i=0;i>l>>r; - int a,b,c; - int ans = 0; - a = 0; - b = 0; - c = 0; - for(int i=30;i>=0;i--){ - int b1 = 0; - int b2 = 0; - - if(l&(1ll << i)){ - b1 = 1; - } - if(r&(1ll << i)){ - b2 = 1; - } - if(b1==b2){ - ans += b1*(1ll << i); - } - else{ - a = ans + (1ll<>t; - - while(t--){ - - solve(); - - } - return 0; -} - - -",2 -legendav007,2057C - Trip to the Olympiad,c++23 ,301729864,301729493,"/* ॐ हं हनुमते नमः */ - -#include -//#include ""debugging.h"" -#include -#include -using namespace __gnu_pbds; -using namespace std; -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define ll long long -const int mod = 1000000007; -#define pb push_back -#define s second -#define f first -#define mp make_pair -#define rep(i,a,b) for(int i = a ; i<=b ; i++) -#define vi vector -#define vvi vector> -#define vll vector -#define vvll vector> -#define vpi vector> -#define Sort(a) sort(a.begin() , a.end()) -#define Max(a) *max_element(a.begin() , a.end()) -#define Min(a) *min_element(a.begin() , a.end()) -/***************************************************************************************************************************************************************/ - -int binexpo(ll a, ll b, ll m = mod){ ll res = 1; a%=m; while(b>0){ if(b&1){ res= (res*a)%m; } a = (a*a)%m; b>>=1; } return res; } -int gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} -int lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -int modInverse(ll a, ll m) { return binexpo(a, m - 2, m); } -int modAdd(ll a, ll b, int m) { return ((a % m) + (b % m)) % m; } -int modMul(ll a, ll b, int m) { return ((a % m) * (b % m)) % m; } -int modSub(ll a, ll b, int m) { return ((a % m) - (b % m) + m) % m; } -int modDiv(ll a, ll b, int m) { return (modMul(a, modInverse(b, m), m) + m) % m; } -bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } -int nCr(int n, int r) { if (r > n - r) r = n - r; int ans = 1; for (int i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } -int nCrModP(int n, int r, int p = mod) { if (r > n - r) r = n - r; int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } -int nPr(int n, int r) { int ans = 1; for (int i = 0; i < r; i++) ans *= (n - i); return ans; } -int nPrModP(int n, int r, int p = mod) { int ans = 1; for (int i = 0; i < r; i++) ans = (ans * (n - i)) % p; return ans; } -int log(int num , int base){int ans = 0; while(num){num /= base;ans++;} return ans;} -int countSetBits(int x){int ans = 0;while(x){ans += (x&1);x >>= 1;}return ans;} -/***************************************************************************************************************************************************************/ -/*Always High on CP*/ - -void legend(){ - int l , r;cin>>l>>r; - int a = 0; - int b = 0; - for(int i = 30 ; i>=0 ; i--){ - int bit1 = (l&(1<>t; - while(t--){ - legend(); - } - return 0; -}","/* ॐ हं हनुमते नमः */ - -#include -//#include ""debugging.h"" -#include -#include -using namespace __gnu_pbds; -using namespace std; -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define ll long long -const int mod = 1000000007; -#define pb push_back -#define s second -#define f first -#define mp make_pair -#define rep(i,a,b) for(int i = a ; i<=b ; i++) -#define vi vector -#define vvi vector> -#define vll vector -#define vvll vector> -#define vpi vector> -#define Sort(a) sort(a.begin() , a.end()) -#define Max(a) *max_element(a.begin() , a.end()) -#define Min(a) *min_element(a.begin() , a.end()) -/***************************************************************************************************************************************************************/ - -int binexpo(ll a, ll b, ll m = mod){ ll res = 1; a%=m; while(b>0){ if(b&1){ res= (res*a)%m; } a = (a*a)%m; b>>=1; } return res; } -int gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b);} -int lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -int modInverse(ll a, ll m) { return binexpo(a, m - 2, m); } -int modAdd(ll a, ll b, int m) { return ((a % m) + (b % m)) % m; } -int modMul(ll a, ll b, int m) { return ((a % m) * (b % m)) % m; } -int modSub(ll a, ll b, int m) { return ((a % m) - (b % m) + m) % m; } -int modDiv(ll a, ll b, int m) { return (modMul(a, modInverse(b, m), m) + m) % m; } -bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } -int nCr(int n, int r) { if (r > n - r) r = n - r; int ans = 1; for (int i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } -int nCrModP(int n, int r, int p = mod) { if (r > n - r) r = n - r; int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } -int nPr(int n, int r) { int ans = 1; for (int i = 0; i < r; i++) ans *= (n - i); return ans; } -int nPrModP(int n, int r, int p = mod) { int ans = 1; for (int i = 0; i < r; i++) ans = (ans * (n - i)) % p; return ans; } -int log(int num , int base){int ans = 0; while(num){num /= base;ans++;} return ans;} -int countSetBits(int x){int ans = 0;while(x){ans += (x&1);x >>= 1;}return ans;} -/***************************************************************************************************************************************************************/ -/*Always High on CP*/ - -void legend(){ - int l , r;cin>>l>>r; - int a = 0; - int b = 0; - for(int i = 30 ; i>=0 ; i--){ - int bit1 = (l&(1<>t; - while(t--){ - legend(); - } - return 0; -}",1 -_adarsh_01,2057C - Trip to the Olympiad,c++20 ,301907378,301907185,"#include -using namespace std; -typedef long long ll; -const int mod=1e9+7; -void solve(){ - ll l,r; - cin>>l>>r; - ll ans=0; - ll a=0,b=0,c=0; - for(ll i=30;i>=0;i--){ - ll curr=(1ll<> t; - while(t--) - solve(); - return 0; -}","#include -using namespace std; -typedef long long ll; -const int mod=1e9+7; -void solve(){ - ll l,r; - cin>>l>>r; - ll ans=0; - ll a=0,b=0,c=0; - for(ll i=30;i>=0;i--){ - ll curr=(1ll<> t; - while(t--) - solve(); - return 0; -}",1 -TuanHLH6,2057C - Trip to the Olympiad,python,301045145,301046266,"t=int(input()) -for ii in range (0,t): - l,r=list(map(int, input().split())) - c=0 - sr=bin(r)[2:] - t =len(sr) - 1 - sl=bin(l)[2:] - k=len(sl)-1 - sl=""0""*(t-k)+sl - n=t - while t>=0: - d=n-t - e=int(sr[d]) + int(sl[d]) - if e==1 or e==2: - if c+2**t<=l+1 or l*2==2**t: - c+=2**t - else: - if c+2**t> i) & 1) ^ ((r >> i) & 1): - k = i - break - a = (1 << k) - 1 | l - b = a + 1 - c = r if a == l else l - print(a, b, c) - - -",2 -wkr111,2057C - Trip to the Olympiad,c++17 ,301056252,301040592,"#include -using namespace std; -#define int long long -#define endl '\n' -#define close ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) - -void solved() -{ - int l,r; - cin>>l>>r; - int k = (l^r); - bitset<31>b(k); - int ans = 0; - for(int i = 0;i<=30;i++) - { - if(b[i] == 1) - { - ans = i; - } - } - int result = l | ((1 << ans) - 1 ); - cout<>T; - while(T--) - { - solved(); - } -}","#include -using namespace std; -#define int long long -#define endl '\n' -#define close ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) - -void solved() -{ - int l, r; - cin >> l >> r; - bitset<30> right(r); - bitset<30> left(l); - bitset<30> ans; - setst; - for (int i = 0; i < 30; i++) { - if (right[i] == 1 && left[i] == 1) { - ans[i] = 0; - } - else if (right[i] == 0 && left[i] == 0) { - ans[i] = 1; - } - else - { - st.insert(i); - } - } - - int k = ans.to_ulong(); - - while(!(k != l && k != r && k >= l && k <= r)) - { - if(st.empty()) - { - break; - } - ans[*(st.begin())] = 1; - st.erase(st.begin()); - k = ans.to_ulong(); - } - cout<> T; - while (T--) { - solved(); - } - return 0; -} -",1 -Chris_Bumstead,2057C - Trip to the Olympiad,c++20 ,303576667,303492700,"#include - -using namespace std; -using ll = long long; - -void solve(){ - ll a=0,b=0,c=0; - ll l,r; - ll ans = 0; - cin >> l >> r; - for(int i=31;i>=0;i--){ - int b1 = 0, b2 = 0; - if(l&(1ll<> t; - while(t--) solve(); -}","#include -using namespace std; - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - long long l, r; - cin >> l >> r; - - long long m = 0; - if (r > 0) { - m = 63 - __builtin_clzll(r); - } - long long a = (1LL << m); - if (a > r || a < l) { - a = r; - } - long long b = (a - 1); - if (b < l) { - b = r - 1; - } - if (b == a) { - b = a - 1; - } - long long c = l; - if (c == a || c == b) { - c = l + 1; - if (c == a || c == b) c++; - } - - cout << a << "" "" << b << "" "" << c << ""\n""; - } - return 0; -}",1 -anon_kun,2057C - Trip to the Olympiad,c++20 ,301156791,301156543,"#include - -using namespace std; - -#define int int64_t -#define ar array - -void solve() { - int l,r; cin >> l >> r; - int k = 0; - for (int i = 0; i <= 30; i++) { - if (((l^r)>>i) & 1) k = i; - } - int x = r & ((1 << 31) - (1 << k)); - if (r == x) cout << l << ' ' << x << ' ' << x-1 << '\n'; - else cout << r << ' ' << x << ' ' << x-1 << '\n'; -} - -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t = 1; cin >> t; - while (t--) { - solve(); - } -}","#include - -using namespace std; - -#define int int64_t -#define ar array - -void solve() { - int l,r; cin >> l >> r; - int k = 0; - for (int i = 1; i <= 30; i++) { - if (((l^r)>>i) & 1) k = i-1; - } - int x = r & ((1 << 31) - (1 << k)); - if (r == x) cout << l << ' ' << x << ' ' << x-1 << '\n'; - else cout << r << ' ' << x << ' ' << x-1 << '\n'; -} - -int32_t main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int t = 1; cin >> t; - while (t--) { - solve(); - } -}",1 -Cyanberry,2057C - Trip to the Olympiad,c++17 ,301167213,301051320,"#include -using namespace std; -#define int long long -int mod = 1e9+7; - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - int total, l, r; - cin>>total; - for (int cap = 0; cap < total; ++cap) { - cin>>l>>r; - int diff = 0, inv = 0; - for (int i = 30; i >= 0; --i) { - //cout<<'-'<= 0; --j) { - //cout<= (l & (1< -using namespace std; -#define int long long -int mod = 1e9+7; - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - int total, l, r; - cin>>total; - for (int cap = 0; cap < total; ++cap) { - cin>>l>>r; - int diff = 0, inv = 0; - for (int i = 30; i >= 0; --i) { - //cout<<'-'<= 0; --j) { - if ((r & (1<= (l & (1< -using namespace std; -typedef long long ll; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vectora(n); - for(int i=0;i>a[i]; - } - int sheng=0; - int jiang=0; - for(int i=0;ia[i+1]){ - jiang++; - } - if(a[i]=sheng){ - cout<<""NO""< -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int a[n+1]; - int y=1; - for(int i=1;i<=n;i++){ - cin>>a[i]; - if(i>1) - a[i]-=a[i-1]; - if(a[i]<0) - y=0; - } - if(y==1)cout<<""YES""< - -using namespace std; - - - -typedef long long ll; - -typedef unsigned long long ull; - - - -#define entf cout << endl - -#define ent cout << ""\n"" - -#define REP(i, a, b) for (int i = a; i < b; ++i) - -#define REPV(i, a, b) for (int i = a; i >= b; --i) - -#define MOD 1000000007 - -#define PRINT(x) cout << x << endl - -#define d(x) cerr << #x << "" = "" << x << endl // Pass a variable name and it will print it with the value - - - -#define TESTCASES true - - - -void solve(int tt) { - -int n; - -cin >> n; - - - -int val; - -vector a; - -a.reserve(n); - -REP(i, 0, n){ - -cin >> val; - -a.push_back(val); - -} - -if(a[0] > a[1]) { - -cout << ""NO"" << endl; - -return; - -} - - - -bool ans = true; - -for(int i = 0; i < n -1; i++) { - -if(a[i] > a[i+1]) { - -ans = false; - -break; - -} - -int diff = min(a[i], a[i+1]); - -a[i+1] -= a[i]; - -a[i] -= a[i]; - -} - - - -cout << (ans ? ""YES"": ""NO"") << endl; - -} - - - -int main() { - -ios::sync_with_stdio(0); - -cin.tie(0); - - - -if (TESTCASES) { - -int tt; cin >> tt; - -REP(i, 1, tt+1) { - -solve(i); - -} - -} else solve(1); - - - -return 0; - -}","#include - -using namespace std; - - - -typedef long long ll; - -typedef unsigned long long ull; - - - -#define entf cout << endl - -#define ent cout << ""\n"" - -#define REP(i, a, b) for (int i = a; i < b; ++i) - -#define REPV(i, a, b) for (int i = a; i >= b; --i) - -#define MOD 1000000007 - -#define PRINT(x) cout << x << endl - -#define d(x) cerr << #x << "" = "" << x << endl // Pass a variable name and it will print it with the value - - - -#define TESTCASES true - - - -void solve(int tt) { - -int n; - -cin >> n; - - - -int val; - -vector a; - -a.reserve(n); - -REP(i, 0, n){ - -cin >> val; - -a.push_back(val); - -} - -// if(a[0] > a[1]) { - -// cout << ""NO"" << endl; - -// return; - -// } - - - -bool ans = true; - -for(int i = 0; i < n -2; i++) { - -if(a[i] > a[i+1]) { - -ans = false; - -break; - -} - -a[i+1] -= a[i]; - -a[i] -= a[i]; - -} - - - -cout << (ans ? ""YES"": ""NO"") << endl; - - - - - -} - - - -int main() { - -ios::sync_with_stdio(0); - -cin.tie(0); - - - -if (TESTCASES) { - -int tt; cin >> tt; - -REP(i, 1, tt+1) { - -solve(i); - -} - -} else solve(1); - - - -return 0; - -}",1 -Tys11,2060D - Subtract Min Sort,c++23 ,306466662,306467003,"#include -using namespace std; - -int numFib(vector& v, int i) { - - int totalFib = 0; - totalFib = (i == v[0] + v[1]) ? totalFib + 1 : totalFib; - totalFib = (v[2] == i + v[1]) ? totalFib + 1 : totalFib; - totalFib = (v[3] == i + v[2]) ? totalFib + 1 : totalFib; - - return totalFib; - -} -int main() { - - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin>>t; - - while (t--) { - - int n; - cin>>n; - vector v(n); - - for (int i = 0; i < n; i++) cin>>v[i]; - - bool valid = true; - int minNum = INT_MAX; - - for (int i = 0; i < n - 1; i++) { - if (i > 0 && v[i-1] > v[i]) { - valid = false; - break; - } - - minNum = min(v[i], v[i-1]); - v[i] -= minNum; - v[i-1] -= minNum; - } - - if (valid && v[v.size() - 1] >= v[v.size() - 2]) { - cout << ""YES\n""; - } else { - cout << ""NO\n""; - } - - } - - return 0; -} -","#include -using namespace std; - -int main() { - - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin>>t; - - while (t--) { - - int n; - cin>>n; - vector v(n); - - for (int i = 0; i < n; i++) cin>>v[i]; - - bool valid = true; - int minNum = INT_MAX; - - for (int i = 1; i < n; i++) { - - if (v[i-1] > v[i]) { - valid = false; - break; - } - minNum = min(v[i], v[i-1]); - v[i] -= minNum; - v[i-1] -= minNum; - } - - if (valid && v[v.size() - 1] >= v[v.size() - 2]) { - cout << ""YES\n""; - } else { - cout << ""NO\n""; - } - - } - - return 0; -} -",2 -Mostafa_Salah1#,2060D - Subtract Min Sort,c++20 ,307644337,307642857,"#include - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; - -int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; - - - -void Mostafa() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - -} - -void solve(){ - - int n; cin>>n; - - vector a(n); - - for(int i=0; i>a[i]; - - for (int i = 0; i < n-1; ++i) { - - int mn = min(a[i], a[i+1]); - - a[i] -= mn; - - a[i+1] -= mn; - - } - - if(is_sorted(a.begin(), a.end())) cout<<""YES\n""; - - else cout<<""NO\n""; - -} - -int main() { - - Mostafa(); - - int t; cin>>t; - - while(t--) { - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; - -int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; - - - -void Mostafa() { - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout.tie(nullptr); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - -} - -void solve(){ - - int n; cin>>n; - - vector a(n); - - for(int i=0; i>a[i]; - - for (int i = 1; i < n; i+=2) { - - if(a[i] < a[i-1]) { - - cout<<""NO\n""; - - return; - - } - - } - - cout<<""YES\n""; - -} - -int main() { - - Mostafa(); - - int t; cin>>t; - - while(t--) { - - solve(); - - } - - return 0; - -} - -",1 -pixel_pirate,2060D - Subtract Min Sort,c++17 ,306588083,306654580,"#include -using namespace std; - -int main(){ - int t; - cin >> t; - while(t--){ - long long n; - cin >> n; - vector v(n); - for(long i=0 ;i> v[i]; - } - - for(long long i =0 ; i -using namespace std; - -int main(){ - long long t; - cin >> t; - while(t--){ - long long n; - cin >> n; - vector v(n); - for(long i=0 ;i> v[i]; - } - - for(long long i =0 ; i - -using namespace std; - -typedef long long ll; - - - - - -void solve(){ - - ll n; cin>>n; - - vector v(n); - - for(int i=0;i>v[i]; - - if(is_sorted(v.begin(),v.end())){ - - cout<<""YES""< diff(n-1); - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - // solve(); - -} - - - -","#include - -using namespace std; - -typedef long long ll; - - - - - -void solve(){ - - ll n; cin>>n; - - vector v(n); - - for(int i=0;i>v[i]; - - // if(is_sorted(v.begin(),v.end())){ - - // cout<<""YES""<>t; - - while(t--){ - - solve(); - - } - - // solve(); - -} - - - -",2 -Kshitij_g,2060D - Subtract Min Sort,c++23 ,302951933,302995312,"#include -#define al(c) c.begin(),c.end() -#define sz(c) ll(c.size()) -#define ll long long -#define tr(a,it) for(auto it=a.begin(); it!=a.end(); it++) -#define present(c, x)(c.find(x) != c.end()) -#define cpresent(c, x)(find(al(c), x) != c.end()) -#define vi vector -#define vll vector -#define vvll vector -#define vpii vector> -#define vpll vector> -#define vvpll vector -#define pll pair -#define inf 1e18 -#define MOD 1000000007 -#define moda 998244353 -#define MAXN 1 -#define loop(i,s,e) for(ll i=s; i=e; i--) -#define newl cout << endl - -using namespace std; - -///////////////////////////////////////////////////////////////////////////////////// - -// DEBUG GG - -#define debug(x) \ - cout << #x << "" ""; \ - _print(x); \ - cout << endl; - -void _print(int x) { - cout << x; -} - -void _print(char x) { - cout << x; -} - -void _print(string s) { - cout << s; -} - -void _print(ll x) { - cout << x; -} - -void _print(bool a) { - cout << a; -} - -template -void _print(pair p); -template -void _print(vector v); -template -void _print(set v); -template -void _print(map v); -template -void _print(multiset v); -template -void _print(pair p) { - cout << ""{""; - _print(p.first); - cout << "",""; - _print(p.second); - cout << ""}""; -} -template -void _print(vector v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(set st) { - cout << ""[ ""; - for (T i : st) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(multiset v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(map v) { - cout << ""[ ""; - for (auto i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -///////////////////////////////////////////////////////////////////////////////////// - -ll cyclen(ll i, ll n) { - return (i % n + (i % n == 0) * n); -} - -ll power(ll a, ll b, ll mod) { - ll p = 1; - while(b > 0) { - if(b & 1) - p = (p * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return p; -} - -ll gcd(ll a, ll b) { - if(!(a % b)) return b; - return gcd(b, a % b); -} - -ll inv_mod(ll n, ll mod) { - ll pow = mod - 2; - return power(n, pow, mod); -} - -ll MSB(ll n) -{ - ll b = 0; - while (n) { - b++; - n /= 2; - } - return b; -} - -void solve(int tc) { - ll n; - cin>>n; - vll a(n); - loop(i,0,n){ - cin>>a[i]; - } - loop(i,0,n-1){ - if(a[i] < a[i+1]){ - a[i+1] = a[i+1] - a[i]; - a[i] = 0; - } - } - loop(i,0,n-1){ - if(a[i] > a[i+1]){ - cout<<""NO""<> t; - int tc = 0; - while (t--) { - tc++; - solve(tc); - } - - return 0; -} -","#include -#define al(c) c.begin(),c.end() -#define sz(c) ll(c.size()) -#define ll long long -#define tr(a,it) for(auto it=a.begin(); it!=a.end(); it++) -#define present(c, x)(c.find(x) != c.end()) -#define cpresent(c, x)(find(al(c), x) != c.end()) -#define vi vector -#define vll vector -#define vvll vector -#define vpii vector> -#define vpll vector> -#define vvpll vector -#define pll pair -#define inf 1e18 -#define MOD 1000000007 -#define moda 998244353 -#define MAXN 1 -#define loop(i,s,e) for(ll i=s; i=e; i--) -#define newl cout << endl - -using namespace std; - -///////////////////////////////////////////////////////////////////////////////////// - -// DEBUG GG - -#define debug(x) \ - cout << #x << "" ""; \ - _print(x); \ - cout << endl; - -void _print(int x) { - cout << x; -} - -void _print(char x) { - cout << x; -} - -void _print(string s) { - cout << s; -} - -void _print(ll x) { - cout << x; -} - -void _print(bool a) { - cout << a; -} - -template -void _print(pair p); -template -void _print(vector v); -template -void _print(set v); -template -void _print(map v); -template -void _print(multiset v); -template -void _print(pair p) { - cout << ""{""; - _print(p.first); - cout << "",""; - _print(p.second); - cout << ""}""; -} -template -void _print(vector v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(set st) { - cout << ""[ ""; - for (T i : st) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(multiset v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(map v) { - cout << ""[ ""; - for (auto i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -///////////////////////////////////////////////////////////////////////////////////// - -ll cyclen(ll i, ll n) { - return (i % n + (i % n == 0) * n); -} - -ll power(ll a, ll b, ll mod) { - ll p = 1; - while(b > 0) { - if(b & 1) - p = (p * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return p; -} - -ll gcd(ll a, ll b) { - if(!(a % b)) return b; - return gcd(b, a % b); -} - -ll inv_mod(ll n, ll mod) { - ll pow = mod - 2; - return power(n, pow, mod); -} - -ll MSB(ll n) -{ - ll b = 0; - while (n) { - b++; - n /= 2; - } - return b; -} - -void solve(int tc) { - ll n; - cin>>n; - vll a(n); - loop(i,0,n){ - cin>>a[i]; - } - loop(i,0,n-1){ - if(a[i] < a[i+1]){ - a[i+1] = a[i+1] - a[i]; - a[i] = 0; - } - else{ - a[i] = a[i] - a[i+1]; - a[i+1] = 0; - } - } - loop(i,0,n-1){ - if(a[i] > a[i+1]){ - cout<<""NO""<> t; - int tc = 0; - while (t--) { - tc++; - solve(tc); - } - - return 0; -} -",2 -countless,2060D - Subtract Min Sort,c++17 ,309295961,309296138,"#include - - - -using namespace std; - - - -#define endl ""\n"" - -#define int long long - - - -void s1() { - - int n; cin >> n; - - vector a(n); - - - - for (int i = 0; i < n; i++) { - - cin >> a[i]; - - } - - - - if (a[0] > a[1]) { - - cout << ""NO"" << endl; - - return; - - } - - - - bool flag = true; - - for (int i = 0; i < n - 1; i++) { - - if (a[i] > a[i + 1]) { - - flag = false; - - break; - - } - - } - - - - if (flag) { - - cout << ""YES"" << endl; - - return; - - } - - - - int sdd = 0, dup = a[0]; - - for (int i = 1; i < n; i++) { - - if (a[i] != dup) { - - sdd = i - 1; - - break; - - } - - } - - - - // if (sdd != 0 && a[sdd] > a[sdd + 1]) { - - // sdd++; - - // } - - - - // cerr << sdd << endl; - - - - for (int i = sdd; i < n - 1; i++) { - - if (a[i] > a[i + 1]) { - - // cout << i << endl; - - cout << ""NO"" << endl; - - return; - - } - - - - int temp = min(a[i], a[i + 1]); - - a[i] -= temp; - - a[i + 1] -= temp; - - // cout << a[i] << "" "" << a[i + 1] << endl; - - } - - - - cout << ""YES"" << endl; - - return; - -} - - - -signed main() { - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; cin >> t; - - while (t--) { - - s1(); - - } - - - - // s1(); - - - - return 0; - -}","#include - - - -using namespace std; - - - -#define endl ""\n"" - -#define int long long - - - -void s1() { - - int n; cin >> n; - - vector a(n); - - - - for (int i = 0; i < n; i++) { - - cin >> a[i]; - - } - - - - if (a[0] > a[1]) { - - cout << ""NO"" << endl; - - return; - - } - - - - bool flag = true; - - for (int i = 0; i < n - 1; i++) { - - if (a[i] > a[i + 1]) { - - flag = false; - - break; - - } - - } - - - - if (flag) { - - cout << ""YES"" << endl; - - return; - - } - - - - int sdd = 0, dup = a[0]; - - for (int i = 1; i < n; i++) { - - if (a[i] != dup) { - - sdd = i - 1; - - break; - - } - - } - - - - if (sdd > 0 && sdd % 2 == 1) sdd--; - - - - // if (sdd != 0 && a[sdd] > a[sdd + 1]) { - - // sdd++; - - // } - - - - // cerr << sdd << endl; - - - - for (int i = sdd; i < n - 1; i++) { - - if (a[i] > a[i + 1]) { - - // cout << i << endl; - - cout << ""NO"" << endl; - - return; - - } - - - - int temp = min(a[i], a[i + 1]); - - a[i] -= temp; - - a[i + 1] -= temp; - - // cout << a[i] << "" "" << a[i + 1] << endl; - - } - - - - cout << ""YES"" << endl; - - return; - -} - - - -signed main() { - - ios::sync_with_stdio(0); - - cin.tie(0); - - - - int t; cin >> t; - - while (t--) { - - s1(); - - } - - - - // s1(); - - - - return 0; - -}",2 -UJJWAL_KAUSHAL,2060D - Subtract Min Sort,c++20 ,308960717,308968022,"#include -using namespace std; -#define int long long -#define ll int -#define lli long long int -#define vi vector -#define vll vector -#define rev(all) reverse(v.begin(),v.end()) -#define pb push_back - -void solve() -{ - ll n; - cin >> n; - vll v(n); - for(int i = 0; i> v[i]; - - ll f = 0,c = 0; - for(int i = n-1; i>0; i--) - { - if(v[i] < v[i-1] && v[i-1] - v[i] == 1) - { - - } - else - { - c = 1; - break; - } - } - - if(c == 0) - { - cout << ""NO\n""; - return; - } - for(int i = 0; i> t; - while(t--) - { - solve(); - } -}","#include -using namespace std; -#define int long long -#define ll int -#define lli long long int -#define vi vector -#define vll vector -#define rev(all) reverse(v.begin(),v.end()) -#define pb push_back - -void solve() -{ - ll n; - cin >> n; - vll ve(n); - for (ll &i : ve) cin >> i; - ll j = 0; - for (ll i = 1; i < n; i++) { - if (ve[i-1] > ve[i]) j = i; - } - if (j == 0) { - cout << ""YES\n""; - return; - } - auto fop = [&](ll i) { - ll minN = min(ve[i], ve[i+1]); - ve[i] -= minN; - ve[i+1] -= minN; - }; - for (ll i = 0; i < j; i++) { - fop(i); - } - cout << (is_sorted(ve.begin(), ve.end()) ? ""YES"" : ""NO"") << '\n'; -} -int32_t main() -{ - ll t = 1; - cin >> t; - while(t--) - { - solve(); - } -}",2 -Ahmed_AL-Jebali#,2060D - Subtract Min Sort,c++23 ,316447990,316446878,"/* - - - -وَهُوَ مَعَكُمْ أَيْنَ مَا كُنْتُم - -_ _ _ _ _ _ - -/ \ | | | | | | | | (_) - -/ \ | | |FREE| | | ___ | |__ __ _ | | _ - -/ / \ \ | | |PALESTINE| _ | | / _ \ | '_ \ / _` | | | | | - -/ __ __ \ | |____ | |__| | | __/ | |_) | | (_| | | | | | - -/_/ \_\ |______| \____/ \___| |_.__/ \__,_| |_| |_| - - - -*/ - - - -#include - -using namespace std; - -#define all(v) v.begin(), v.end() - - - -#define endl '\n' - -#define int long long - -void tracking(vector v) { - -for (int i = 0; i < v.size(); i++) { - -cout << v[i] << "" ""; - -} - -cout << endl; - -} - -void Input(vector &v) { - -for (int &x : v) { - -cin >> x; - -} - -} - - - -#define posative(a) max(a, 0LL); - -#define FAST \ - -ios_base::sync_with_stdio(0); \ - -cin.tie(nullptr); \ - -cout.tie(nullptr); - -#define fileIO \ - -freopen(""input.txt"", ""r"", stdin); \ - -freopen(""output.txt"", ""w"", stdout) - - - -//----------------------------------------------------------------------------------------------------------------------------------- - - - -void solve() { - -int n; - -cin >> n; - -vector a(n); - -vector case1(n); - -vector case2(n); - -for (int i = 0; i < n; i++) { - -cin >> a[i]; - -} - -case2 = a; - -for (int i = 1; i < n; i++) { - -int mn = min(case2[i], case2[i - 1]); - -case2[i - 1] -= mn; - -case2[i] -= mn; - -} - -for (int i = 1; i < n; i++) { - -if (!(case2[i] >= case2[i - 1])) { - -cout << ""NO"" << endl; - -return; - -} - -} - -cout << ""YES"" << endl; - -} - - - -signed main() { - -FAST; - -#ifndef ONLINE_JUDGE - -fileIO; - -#endif - -int t = 1; - -cin >> t; - -for (int i = 1; i <= t; i++) { - -// cout<<""Case ""< - -using namespace std; - -#define all(v) v.begin(), v.end() - - - -#define endl '\n' - -#define int long long - -void tracking(vector v) { - -for (int i = 0; i < v.size(); i++) { - -cout << v[i] << "" ""; - -} - -cout << endl; - -} - -void Input(vector &v) { - -for (int &x : v) { - -cin >> x; - -} - -} - - - -#define posative(a) max(a, 0LL); - -#define FAST \ - -ios_base::sync_with_stdio(0); \ - -cin.tie(nullptr); \ - -cout.tie(nullptr); - -#define fileIO \ - -freopen(""input.txt"", ""r"", stdin); \ - -freopen(""output.txt"", ""w"", stdout) - - - -//----------------------------------------------------------------------------------------------------------------------------------- - -void solve() { - -int n; - -cin >> n; - -vector a(n); - -for (int &x : a) - -cin >> x; - - - -for (int i = 0; i < n; i += 2) { - -if (a[i] > a[i + 1]) { - -cout << ""NO\n""; - -return; - -} - -} - -cout << ""YES\n""; - -} - -signed main() { - -FAST; - -#ifndef ONLINE_JUDGE - -fileIO; - -#endif - -int t = 1; - -cin >> t; - -for (int i = 1; i <= t; i++) { - -// cout<<""Case ""< - -#define ll long long - -using namespace std; - - - -void solve(){ - -int n; - -cin>>n; - - - -vectortemp(n); - -for(int i=0;i>temp[i]; - - - -for(int i=0;itemp[i+1]){ - -cout<<""NO""<0;i-=2){ - -if(temp[i]> t; - - - -while(t--) - -solve(); - - - -return 0; - -}","#include - -#define ll long long - -using namespace std; - - - -void solve(){ - -int n; - -cin>>n; - - - -vectortemp(n); - -for(int i=0;i>temp[i]; - - - -for(int i=0;i> t; - - - -while(t--) - -solve(); - - - -return 0; - -}",2 -wwaterr313,2060D - Subtract Min Sort,c++20 ,302969937,302968637,"#include -using namespace std; -#define ll long long -#define pb push_back -#define beoli ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -int t,n;int a[1000069];int x; -int main(){ - beoli - cin>>t; - while(t--){ - cin>>n; - for(int i=0;i>a[i]; - } - for(int i=0;i0){ - cout<<""NO""< -using namespace std; -#define ll long long -#define pb push_back -#define beoli ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); - -int t,n;int a[1000069];int x; -int main(){ - beoli - cin>>t; - while(t--){ - cin>>n; - for(int i=0;i>a[i]; - } - for(int i=1;ia[i-1]){ - cout<<""YES""< - -using namespace std; - -using ll = long long; - - - -int main(){ - - int t; cin >> t; - - while(t--){ - - int n; cin >> n; - - ll a[n]; - - for(int i=0; i> a[i]; - - } - - ll k = a[1] - a[0]; - - ll sum=0; - - if(k < 0) cout << ""NO"" << endl; - - else{ - - for(int i=2; i= k){ - - sum += 1; - - k = a[i] - k; - - } - - } - - if(sum == n-2){ - - cout << ""YES"" << endl; - - } - - else cout << ""NO"" << endl; - - } - - - - - - } - -}","#include - -using namespace std; - -using ll = long long; - - - -int main(){ - - int t; cin >> t; - - while(t--){ - - int n; cin >> n; - - ll a[n]; - - for(int i=0; i> a[i]; - - } - - ll k = a[1] - a[0]; - - ll sum=0; - - if(k < 0) cout << ""NO"" << endl; - - else{ - - for(int i=2; i k){ - - sum += 1; - - k = a[i] - k; - - } - - } - - if(sum == n-2){ - - cout << ""YES"" << endl; - - } - - else cout << ""NO"" << endl; - - } - - - - - - } - -}",1 -Wang1119#,2060D - Subtract Min Sort,c++20 ,310826810,310826741,"#include - -using namespace std; - -void solve(){ - - int n,t=0; - - cin>>n; - - int a[n]; - - for (int i=0;i>a[i]; - - } - - for (int i=0;ia[i+1]){ - - t=1; - - break; - - } - - a[i]-=mi; - - a[i+1]-=mi; - - } - - if (t==1){ - - cout<<""NO""<>T; - - while (T--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -void solve(){ - - int n,t=0; - - cin>>n; - - int a[n]; - - for (int i=0;i>a[i]; - - } - - for (int i=0;ia[i+1]){ - - t=1; - - break; - - } - - if (a[i+2]<=a[i+1]){ - - a[i]-=mi; - - a[i+1]-=mi; - - } - - } - - if (t==1){ - - cout<<""NO""<>T; - - while (T--){ - - solve(); - - } - - return 0; - -}",1 -simaqingace,2060D - Subtract Min Sort,python,304850669,304851986,"t = int(input()) -for i in range(t): - n = int(input()) - nums = list(map(int, input().split())) - left = 0 - right = 2 - check = True - while right < n: - if nums[left] > nums[left+1]: - check = False - break - elif nums[right] < nums[left+1]: - nums[left+1] -= nums[left] - nums[left] = 0 - left += 1 - right += 1 - else: - left += 1 - right += 1 - - if check: - print('Yes') - else: - print('No') - - - - - - -","t = int(input()) -for i in range(t): - n = int(input()) - nums = list(map(int, input().split())) - left = 0 - check = True - while left < n-1: - if nums[left] > nums[left+1]: - check = False - break - else: - nums[left+1] -= nums[left] - nums[left] = 0 - left += 1 - - - if check: - print('Yes') - else: - print('No') - - - - - - -",2 -AY_ayman00,2060D - Subtract Min Sort,c++23 ,309004018,309003841,"#include - -#include - -#include - -using namespace std; - - - -int main(){ - - int t; cin >> t; - - - - while(t--){ - - int n; cin >> n; - - int arr[n+1]; arr[0]=0; - - string answer = ""YES""; - - for(int i = 1; i <= n; i++) cin >> arr[i]; - - for(int i = 2; i <= n; i++){ - - if(arr[i] < abs(arr[i-1] - arr[i-2])) { - - answer = ""NO""; break; - - } else arr[i-1] = abs(arr[i-1] - arr[i-2]); - - } - - - - cout << answer << ""\n""; - - - - - - } - -}","#include - -#include - -#include - -using namespace std; - - - -int main(){ - - int t; cin >> t; - - - - while(t--){ - - int n; cin >> n; - - int arr[n+1]; arr[0]=0; - - string answer = ""YES""; - - for(int i = 1; i <= n; i++) cin >> arr[i]; - - for(int i = 2; i <= n; i++){ - - if(arr[i] < abs(arr[i-1] - arr[i-2])) { - - answer = ""NO""; break; - - } - - } - - - - cout << answer << ""\n""; - - - - - - } - -}",1 -Huangzy797,2060D - Subtract Min Sort,c++20 ,307498861,307497998,"#include -using namespace std; -void solve() -{ - int n; - cin>>n; - vectora(n+1); - for(int i=1;i<=n;i++)\ - { - cin>>a[i]; - } - for(int i=1;i0){ - cout<<""NO""<=0)cout<<""YES""<>t; - while(t--) - { - solve(); - } - return 0; -}","#include -using namespace std; -void solve() -{ - int n; - cin>>n; - vectora(n+1); - for(int i=1;i<=n;i++)\ - { - cin>>a[i]; - } - for(int i=1;i0){ - cout<<""NO""<0)cout<<""YES""<>t; - while(t--) - { - solve(); - } - return 0; -}",1 -AtOM__07,2060D - Subtract Min Sort,c++23 ,307665200,307665357,"#include - -using namespace std; - -#define all(a) a.begin(),a.end() - -#define allr(a) a.rbegin(),a.rend() - -#define ll long long - -const ll mod = 1000000007; - - - -void solve() - -{ - - int n; - - cin>>n; - - vector v(n); - - for(auto &it:v) cin>>it; - - - - if(v[0] >= v[1]){ - - cout << ""NO"" << endl; - - return ; - - } - - - - for(int i = 0; i < n-1; i++){ - - int sub = min(v[i],v[i+1]); - - v[i]-=sub; - - v[i+1]-=sub; - - } - - - - int f = 1; - - for(int i = 0; i < n-1; i++){ - - if(v[i] > v[i+1]) f = 0; - - } - - if(f) cout << ""YES"" << endl; - - else cout << ""NO"" << endl; - -} - - - -int main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - - - int t = 1; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - -#define all(a) a.begin(),a.end() - -#define allr(a) a.rbegin(),a.rend() - -#define ll long long - -const ll mod = 1000000007; - - - -void solve() - -{ - - int n; - - cin>>n; - - vector v(n); - - for(auto &it:v) cin>>it; - - - - if(v[0] > v[1]){ - - cout << ""NO"" << endl; - - return ; - - } - - - - for(int i = 0; i < n-1; i++){ - - int sub = min(v[i],v[i+1]); - - v[i]-=sub; - - v[i+1]-=sub; - - } - - - - int f = 1; - - for(int i = 0; i < n-1; i++){ - - if(v[i] > v[i+1]) f = 0; - - } - - if(f) cout << ""YES"" << endl; - - else cout << ""NO"" << endl; - -} - - - -int main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - - - int t = 1; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}",2 -Zoror,2060D - Subtract Min Sort,c++23 ,307451181,307438646,"/* In the Name of ALLAH, the most gracious, the most merciful */ -/* Watch the solve video on -> youtube.com/@MythologicalCoding */ -#include -using namespace std; -#define nl endl -#define ll long long -#define cy cout<<""YES""<& v, ll e) { auto it =find(all(v),e); - if(it!=v.end()){return distance(v.begin(),it);}return -1; } -ll gcd(ll a,ll b) { if(b==0)return a;return gcd(b,a%b); }//__gcd -ll lcm(ll a,ll b) { return(1LL*a*b)/__gcd(a, b); } -ll sumFrom_IToJ(ll i,ll j) { return((j - i + 1LL)*(i + j))/2; } -bool sorta_2nd(const pair&a,const pair&b) - { return(a.second0) && (n&(n-1))==0; } - -void solve() { - ll n;cin>>n; - vectorv(n); - - for(auto &i:v) - cin>>i; - - if(is_sorted(all(v))) - { - cy;return; - } - ll b=0,ix=1; - for(ll i=1;iv[i]) - b=i; - } - // dis(b); - for(ll i=0;i> T; - for (int i = 1; i <= T; i++) { - //cout << ""Case "" << i << "": ""; - solve(); - } - return 0; -} -","/* In the Name of ALLAH, the most gracious, the most merciful */ -/* Watch the solve video on -> youtube.com/@MythologicalCoding */ -#include -using namespace std; -#define nl endl -#define ll long long -#define cy cout<<""YES""<& v, ll e) { auto it =find(all(v),e); - if(it!=v.end()){return distance(v.begin(),it);}return -1; } -ll gcd(ll a,ll b) { if(b==0)return a;return gcd(b,a%b); }//__gcd -ll lcm(ll a,ll b) { return(1LL*a*b)/__gcd(a, b); } -ll sumFrom_IToJ(ll i,ll j) { return((j - i + 1LL)*(i + j))/2; } -bool sorta_2nd(const pair&a,const pair&b) - { return(a.second0) && (n&(n-1))==0; } - -void solve() { - ll n;cin>>n; - vectorv(n); - - for(auto &i:v) - cin>>i; - - if(v[0]==*max_element(all(v))) - cn; - else cy; - -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int T = 1; - cin >> T; - for (int i = 1; i <= T; i++) { - //cout << ""Case "" << i << "": ""; - solve(); - } - return 0; -} -",1 -ngp11,2060D - Subtract Min Sort,c++17 ,309328811,309329382,"#include - -using namespace std; - - - -void solve() - -{ - - int n; cin >> n; - - vector a(n); - - for(int i = 0 ; i < n; i++) cin >> a[i]; - - for(int i = n-2; i >= 1; i--) { - - if(a[i] > a[i+1]) { - - int jar = a[i] - a[i+1]; - - a[i] -= jar; - - if(a[i-1] - jar < 0) { - - cout << ""no\n""; return; - - } - - a[i-1] -= jar; - - i--; - - } - - } - - for(int i = 0; i < n-1; i++) { - - if(a[i] > a[i+1]) { - - cout << ""no\n""; return; - - } - - } - - cout << ""yes\n""; - -} - - - -int main() - -{ - - ios::sync_with_stdio(false); cin.tie(0); - - int t; cin >> t; - - while(t--) solve(); - - return 0; - -}","#include - -using namespace std; - - - -void solve() - -{ - - int n; cin >> n; - - vector a(n); - - for(int i = 0 ; i < n; i++) cin >> a[i]; - - for(int i = n-2; i >= 1; i--) { - - if(a[i] > a[i+1]) { - - int jar = a[i] - a[i+1]; - - a[i] -= jar; - - if(a[i-1] - jar < 0) { - - cout << ""no\n""; return; - - } - - a[i-1] -= jar; - - } - - } - - for(int i = 0; i < n-1; i++) { - - if(a[i] > a[i+1]) { - - cout << ""no\n""; return; - - } - - } - - cout << ""yes\n""; - -} - - - -int main() - -{ - - ios::sync_with_stdio(false); cin.tie(0); - - int t; cin >> t; - - while(t--) solve(); - - return 0; - -}",2 -Aldrago,2060D - Subtract Min Sort,c++23 ,316002434,316003075,"#include - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define vll vector - - - -int main() - -{ - -ios_base::sync_with_stdio(false); - -cin.tie(nullptr); - -cout.tie(nullptr); - - - -int t; - -cin>>t; - -while(t--) - -{ - -int n,diff; - -string ans=""YES""; - -cin>>n; - -int arr[n]; - -for (int i = 0; i < n; i++) - -{ - -cin>>arr[i]; - -} - - - -for (int i = 0; i < n-1; i++) - -{ - -diff=min(arr[i],arr[i+1]); - -arr[i] = arr[i]-diff; - -arr[i+1]= arr[i+1] - diff; - - - -if ((arr[i]>0) || (arr[i+1] == 0)) - -{ - -ans=""NO""; - -break; - -} - -} - - - -// for (int i = 0; i < n; i++) - -// { - -// cout< - -using namespace std; - - - -#define ll long long - -#define vi vector - -#define vll vector - - - -int main() - -{ - -ios_base::sync_with_stdio(false); - -cin.tie(nullptr); - -cout.tie(nullptr); - - - -int t; - -cin>>t; - -while(t--) - -{ - -int n,diff; - -string ans=""YES""; - -cin>>n; - -int arr[n]; - -for (int i = 0; i < n; i++) - -{ - -cin>>arr[i]; - -} - - - -for (int i = 0; i < n-1; i++) - -{ - -diff=min(arr[i],arr[i+1]); - -arr[i] = arr[i]-diff; - -arr[i+1]= arr[i+1] - diff; - - - -if ((arr[i]>0) && (arr[i+1] == 0)) - -{ - -ans=""NO""; - -break; - -} - -} - - - -// for (int i = 0; i < n; i++) - -// { - -// cout< - -using namespace std; - - - -int main() { - -int t; - -cin >> t; - -while (t--) { - -int n; - -cin>>n; - -vectorv(n); - -for(int i=0;i>v[i]; - -} - -bool valid = true; - -for(int i=0;i - -using namespace std; - - - -int main() { - -int t; - -cin >> t; - -while (t--) { - -int n; - -cin>>n; - -vectorv(n); - -for(int i=0;i>v[i]; - -} - -bool valid = true; - -for(int i=0;i -using namespace std; -const int N=2e5+10; -typedef long long ll; -ll n,a[N]; -void solve(){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - int flag=0; - for(int i=1;i>_; - while(_--){ - solve(); - } - return 0; -}","#include -using namespace std; -const int N=2e5+10; -typedef long long ll; -ll n,a[N]; -void solve(){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - for(int i=1;ia[i+1]){ - cout<<""NO""<>_; - while(_--){ - solve(); - } - return 0; -}",2 -nishant2526,2060D - Subtract Min Sort,c++17 ,305017355,305027301,"#include -using namespace std; -#define ll long long -const int mod=1e9+7; -int dx[8]={-1,0,0,1,-1,-1,1,1}; -int dy[8]={0,-1,1,0,-1,1,-1,1}; - -void nishant2526(){ - int n; - cin>>n; - vector arr(n); - for(int i=0;i>arr[i]; - } - for(int i=0;i> tt; - while (tt--) - { - nishant2526(); - } - - return 0; -} -","#include -using namespace std; -#define ll long long -const int mod=1e9+7; -int dx[8]={-1,0,0,1,-1,-1,1,1}; -int dy[8]={0,-1,1,0,-1,1,-1,1}; - -void nishant2526(){ - int n; - cin>>n; - vector arr(n); - for(int i=0;i>arr[i]; - } - for(int i=1;iarr[i]){ - cout<<""NO""<> tt; - while (tt--) - { - nishant2526(); - } - - return 0; -} -",2 -naPHYSICbal31,2060D - Subtract Min Sort,c++17 ,302811159,302811117,"#include -using namespace std; -#define loop(i,a,b) for(int i = a; i < b; i += 1) -#define ll long long -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - label: - while(t--) - { - int n; - cin >> n; - vector arr(n); - loop(i,0,n) cin >> arr[i]; - int dif = arr[1]-arr[0]; - if(dif < 0) - { - cout << ""NO"" << endl; - goto label; - } - loop(i,2,n) - { - dif = arr[i]-dif; - if(dif < 0) - { - cout << ""NO"" << endl; - goto label; - } - } - cout << ""YES""<< endl; - } -}","#include -using namespace std; -#define loop(i,a,b) for(int i = a; i < b; i += 1) -#define ll long long -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - label: - while(t--) - { - int n; - cin >> n; - vector arr(n); - loop(i,0,n) cin >> arr[i]; - int dif = arr[1]-arr[0]; - loop(i,2,n) - { - dif = arr[i]-dif; - if(dif < 0) - { - cout << ""NO"" << endl; - goto label; - } - } - cout << ""YES""<< endl; - } -}",1 -agarwal_shaleen,2060D - Subtract Min Sort,c++17 ,305031318,305029490,"#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin >> n; - vector a; - int flag=0; - for(int i=0;i> x; - a.push_back(x); - } - if(a[0]>a[1]) { - cout<<""NO""<a[i+1]){ - cout<<""NO""< -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin >> n; - vector a; - int flag=0; - for(int i=0;i> x; - a.push_back(x); - } - if(a[0]>a[1]) { - cout<<""NO""<a[i+1]){ - int x = min(a[i],a[i-1]); - if((a[i]-x)>a[i+1]){ - cout<<""NO""< -using namespace std; -#define int long long -signed main(){ - ios_base::sync_with_stdio(0); - cin.tie(0);cout.tie(0); - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int arr[n]; - for(int i=0;i>arr[i]; - } - int flag=0; - for(int i=0;i -using namespace std; -int MOD=1e9+7; - -void solve(){ - int n; - cin>>n; - vector v(n); - bool sorted = true; - for(int i = 0; i>a; - v[i] = a; - if(i > 0 && v[i-1] > v[i]){ - sorted = false; - } - } - if(sorted){ - cout<<""YES""< v[1]){ - cout<<""NO""< v[i+1]){ - b = 0; - break; - }else{ - v[i+1] -= v[i]; - } - } - if(b == 1){ - cout<<""YES""<> T; - while (T--) - { - solve(); - } - - return 0; -}",1 -M.N0ThinG,2060D - Subtract Min Sort,c++17 ,307006847,307039648,"#include -using namespace std; - -#define X first -#define Y second -#define pb push_back -#define pii pair -#define spacce cerr << ""===="" << endl -const int maxn = 2e5 + 5; -const int INF = 1e9; -const int MOD = 998244353; -void solve() -{ - int n; - cin >> n; - int a[n]; - for(int i = 0; i < n; i++) - cin>>a[i]; - for(int i = 0; i < n-2; i++) - { - if(a[i] > a[i+1] && a[i+1] > a[i+2]) - { - cout << ""NO"" << endl; - return; - } - } - cout << ""YES"" << endl; -} - -int32_t main() -{ - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - bool tc = 1; - int ttt = tc ? (cin >> ttt, ttt) : 1; - - while(ttt--) - solve(), spacce; - - return 0; -} - - - -// _ __ ________ _ _____ -// / |/ /__/_ __/ / (_)__ / ___/ -// / / _ \/ / / _ \/ / _ \/ (_ / -// /_/|_/\___/_/ /_//_/_/_//_/\___/ is real. -// - -","#include -using namespace std; - -#define X first -#define Y second -#define pb push_back -#define pii pair -#define spacce cerr << ""===="" << endl -const int maxn = 2e5 + 5; -const int INF = 1e9; -const int MOD = 998244353; -void solve() -{ - int n; - cin >> n; - int a[n]; - for(int i = 0; i < n; i++) - cin>>a[i]; - for(int i = 0; i < n-1; i++) - { - if(a[i] > a[i+1]) - { - cout << ""NO"" << endl; - return; - } - a[i+1] -= a[i]; - a[i] = 0; - } - cout << ""YES"" << endl; -} - -int32_t main() -{ - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - bool tc = 1; - int ttt = tc ? (cin >> ttt, ttt) : 1; - - while(ttt--) - solve(), spacce; - - return 0; -} - - - -// _ __ ________ _ _____ -// / |/ /__/_ __/ / (_)__ / ___/ -// / / _ \/ / / _ \/ / _ \/ (_ / -// /_/|_/\___/_/ /_//_/_/_//_/\___/ is real. -// -",2 -mintu_m07,2060D - Subtract Min Sort,python,303604835,303604480,"def solve(): - import sys - - input_data = sys.stdin.read().strip().split() - t = int(input_data[0]) - index = 1 - - results = [] - for _ in range(t): - n = int(input_data[index]) - index += 1 - - # Read the array of integers - a = list(map(int, input_data[index:index+n])) - index += n - - # Perform the ""subtract min"" operation in a single left-to-right pass - for i in range(n - 1): - if a[i] <= a[i + 1]: - # Subtract a[i] from a[i+1], and make a[i] zero - a[i+1] -= a[i] - a[i] = 0 - - # Check if the final array is non-decreasing - if all(a[i] <= a[i+1] for i in range(n-1)): - results.append(""YES"") - else: - results.append(""NO"") - - # Output one result per test case - print(""\n"".join(results)) - -solve() -","def solve(): - import sys - input_data = sys.stdin.read().strip().split() - - t = int(input_data[0]) - idx = 1 - answers = [] - - for _ in range(t): - n = int(input_data[idx]); idx += 1 - a = list(map(int, input_data[idx: idx+n])) - idx += n - - # Single pass from left to right - for i in range(n-1): - if a[i] <= a[i+1]: - # Subtract a[i] from a[i+1], set a[i] to 0 - a[i+1] -= a[i] - a[i] = 0 - - # Check if final array is non-decreasing - possible = all(a[i] <= a[i+1] for i in range(n-1)) - answers.append(""YES"" if possible else ""NO"") - - print(""\n"".join(answers)) -",1 -hyt2021,2060D - Subtract Min Sort,c++20 ,304640368,304641441,"#include -using namespace std; -typedef long long ll; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - vector a(n + 1); - for(int i = 0; i < n; i++) - { - cin >> a[i]; - } - for(int i = 0; i < n - 1; i++) - { - if(a[i] <= a[i + 1]) - { - int t = min(a[i], a[i + 1]); - a[i] -= t; - a[i + 1] -= t; - } - } - cout << (is_sorted(a.begin(), a.end()) ? ""YES"" : ""NO""); - cout << endl; - } - return 0; -} - -","#include -using namespace std; -typedef long long ll; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - vector a(n + 1); - for(int i = 0; i < n; i++) - { - cin >> a[i]; - } - for(int i = 0; i < n - 1; i++) - { - if(a[i] <= a[i + 1]) - { - int t = min(a[i], a[i + 1]); - a[i] -= t; - a[i + 1] -= t; - } - } - bool f = 1; - for(int i = 0; i < n - 1; i++) - { - if(a[i + 1] < a[i]) - f = 0; - } - if(f) cout << ""YES""; - else cout << ""NO""; - cout << endl; - } - return 0; -} - -",2 -nanqing,2060D - Subtract Min Sort,c++23 ,313221733,313221083,"#include - -using namespace std; - -const int N=2e5+10; - - - -void solve() - -{ - -int n; - -cin>>n; - -int a[N]; - -for(int i=0;i>a[i]; - -} - -for(int i=1;i>t; - -while(t--) - -{ - -solve(); - -} - -return 0; - -}","#include - -using namespace std; - -const int N=2e5+10; - - - -void solve() - -{ - -int n; - -cin>>n; - -int a[N]; - -for(int i=0;i>a[i]; - -} - -int flag=1; - -int flag1=0; - -int mn=1e9+10; - -int i=1; - -while(ia[i]) - -{ - -if(flag1) - -{ - -if(q>=a[i-2]) - -{ - -i++; - -mn=min(q,a[i-2]); - -a[i-1]-=mn; - -a[i-2]-=mn; - -} - -else - -{ - -flag=0; - -break; - -} - -} - -else - -{ - -flag=0; - -break; - -} - -} - -else - -{ - -flag1=1; - -a[i-1]-mn; - -a[i]-=mn; - -i+=2; - -} - -} - -if(flag) cout<<""YES\n""; - -else cout<<""NO\n""; - -} - - - -int main() - -{ - -ios::sync_with_stdio(0); - -cin.tie(0); - -int t; - -cin>>t; - -while(t--) - -{ - -solve(); - -} - -return 0; - -}",1 -NahomH,2060D - Subtract Min Sort,python,308072061,308076197,"import sys,random,cmath - -from math import inf,factorial,gcd - -from collections import defaultdict, Counter - - - -xors = random.randint(1, 1000000000) - -con = lambda x: x^xors - -number = lambda: int(sys.stdin.readline().strip()) - -numbers = lambda: list(map(int, sys.stdin.readline().strip().split())) - -words = lambda: sys.stdin.readline().strip().split() - -word = lambda: sys.stdin.readline().strip() - -yn = lambda condition: 'YES' if condition else 'NO' - - - -def solve(): - - n = number() - - nums = numbers() - - arr = [0] - - for i in range(1,len(nums)): - - if nums[i] - nums[i-1] >= 0: - - if i>1: - - arr.append(nums[i]-arr[-1]) - - arr[-1] = 0 - - else: - - arr.append(nums[i]-nums[0]) - - elif len(arr) < 2 or arr[-1] > nums[i]: - - print('NO') - - return - - else: - - arr.append(nums[i]-arr[-1]) - - arr[-2] = 0 - - print('YES') - - - - return - - - -test_cases = number() - -for _ in range(test_cases): - - solve() - -","import sys,random,cmath - -from math import inf,factorial,gcd - -from collections import defaultdict, Counter - - - -xors = random.randint(1, 1000000000) - -con = lambda x: x^xors - -number = lambda: int(sys.stdin.readline().strip()) - -numbers = lambda: list(map(int, sys.stdin.readline().strip().split())) - -words = lambda: sys.stdin.readline().strip().split() - -word = lambda: sys.stdin.readline().strip() - -yn = lambda condition: 'YES' if condition else 'NO' - - - -def solve(): - - n = number() - - nums = numbers() - - arr = [0] - - for i in range(1,len(nums)): - - if nums[i] >= nums[i-1]: - - if i>1: - - arr.append(nums[i]-arr[-1]) - - arr[-2] = 0 - - else: - - arr.append(nums[i]-nums[i-1]) - - elif i < 2 or arr[-1] > nums[i]: - - print('NO') - - return - - else: - - arr.append(nums[i]-arr[-1]) - - arr[-2] = 0 - - print('YES') - - - - return - - - -test_cases = number() - -for _ in range(test_cases): - - solve() - -",2 -micha77,2060D - Subtract Min Sort,c++17 ,304043469,304062055,"#include -using namespace std; -#define ull unsigned long long -#define ll long long -#define ld long double -#define uld unsigned long double -#define all(x) (x).begin(), (x).end() -#define dsort(x) sort(all(x), greater<>()) -#define rev(x) reverse(all(x)) -#define uniq(x) (x).erase(unique(all(x)), (x).end()) -#define ff first -#define ss second -#define vec vector -#define uset unordered_set -#define umap unordered_map -#define ummap unordered_multimap -#define pb push_back -#define pf push_front -#define str string -ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} -ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);} - - - -int main() { - cin.tie(0)->sync_with_stdio(0); - - - int t; - cin >> t; - while(t--) { - int n; - cin>>n; - vec a(n); - vec id{}; - for(int i=0;i>a[i]; - if(i>0&&a[i]=0;i--) { - if(a[i]==0) { - int m=min(a[i+1],a[i+2]); - a[i+1]-=m; - a[i+2]-=m; - break; - } else if(i==0) { - int m=min(a[i],a[i+1]); - a[i]-=m; - a[i+1]-=m; - break; - } - } - if(a[idx]<=a[idx+1]) id.erase(id.begin()); - } - - if(!no) cout<<""YES""<<""\n""; - - // for(int i: a) cout << i << "" ""; - // cout << ""\n""; - - } - - return 0; -}","#include -using namespace std; -#define ull unsigned long long -#define ll long long -#define ld long double -#define uld unsigned long double -#define all(x) (x).begin(), (x).end() -#define dsort(x) sort(all(x), greater<>()) -#define rev(x) reverse(all(x)) -#define uniq(x) (x).erase(unique(all(x)), (x).end()) -#define ff first -#define ss second -#define vec vector -#define uset unordered_set -#define umap unordered_map -#define ummap unordered_multimap -#define pb push_back -#define pf push_front -#define str string -ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} -ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);} - - - -int main() { - cin.tie(0)->sync_with_stdio(0); - - - int t; - cin >> t; - while(t--) { - int n; - cin>>n; - vec a(n); - for(int i=0;i>a[i]; - if(i>0) { - int m=min(a[i-1],a[i]); - a[i-1]-=m; - a[i]-=m; - } - } - - bool no=false; - for(int i=0;ia[i+1]) { - no=true; - break; - } - } - if(!no) cout<<""YES\n""; - else cout<<""NO\n""; - - } - - - return 0; -}",2 -PalestinianTornado#,2060D - Subtract Min Sort,c++17 ,304050217,304049427,"#include - -using namespace std; - -#define debug(x) cout << '[' << #x << "" is: "" << x << ""] "" << endl; -#define imod(a , n) (a % n + n ) % n - -#define fastio ios_base::sync_with_stdio(false);cin.tie(0); -#define inF freopen(""ladder.in"",""r"",stdin ); -#define outF freopen(""ladder.out"" , ""w"" , stdout ) ; -#define sor(v) sort(v.begin() , v.end()); -//#define print(v) for(auto f : v ) cout << f << "" "" ; -#define rsor(v) sort(v.rbegin() , v.rend()); -#define rev(v) reverse(v.begin() , v.end()); -#define scan(v) for(auto &it : v)cin >> it ; - -#define logar(x , y) log(x) / log(y) -#define __sum(n) n * (n + 1) / 2 -#define __lcm(a , b) a / __gcd(a , b) * b -#define pii pair -#define ll long long -#define int ll -#define matrix vector> -#define pii pair - -const int di[] = {1 , -1 , 0 , 0}; -const int dj[] = {0 , 0 , 1 , -1}; - -const int mod = 1e9 + 7; -const int N = 1e6 + 6 ; - -int check(int a1 ,int a2 ,int a3 ,int a4 ,int a5){ - - - return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ; - - -} - -int32_t main() - -{ //inF; - //inF;outF; - fastio; - - int t ; - cin >> t ; - - while(t--){ - - int n ; - cin >> n ; - - vector v(n); - for(auto &it : v)cin >> it ; - if(v[1] < v[0])cout << ""NO""; - else { - string ans = ""YES""; - int mn = min(v[1] , v[0]); - v[1] -= mn , v[0] -= mn ; - - - for(int i = 2 ; i < n ; i ++){ - if(v[i] < v[i - 1]){ - v[i - 1] -= min(v[i - 1] , v[i - 2]); - - } - if(v[i] < v[i - 1]){ - ans = ""NO""; - break; - } - - mn = min(v[i] , v[i-1]); - v[i]-=mn,v[i-1]-=mn; - - } - cout << ans ; - } - - - cout << '\n'; - } - -} - - -","#include - -using namespace std; - -#define debug(x) cout << '[' << #x << "" is: "" << x << ""] "" << endl; -#define imod(a , n) (a % n + n ) % n - -#define fastio ios_base::sync_with_stdio(false);cin.tie(0); -#define inF freopen(""ladder.in"",""r"",stdin ); -#define outF freopen(""ladder.out"" , ""w"" , stdout ) ; -#define sor(v) sort(v.begin() , v.end()); -//#define print(v) for(auto f : v ) cout << f << "" "" ; -#define rsor(v) sort(v.rbegin() , v.rend()); -#define rev(v) reverse(v.begin() , v.end()); -#define scan(v) for(auto &it : v)cin >> it ; - -#define logar(x , y) log(x) / log(y) -#define __sum(n) n * (n + 1) / 2 -#define __lcm(a , b) a / __gcd(a , b) * b -#define pii pair -#define ll long long -#define int ll -#define matrix vector> -#define pii pair - -const int di[] = {1 , -1 , 0 , 0}; -const int dj[] = {0 , 0 , 1 , -1}; - -const int mod = 1e9 + 7; -const int N = 1e6 + 6 ; - -int check(int a1 ,int a2 ,int a3 ,int a4 ,int a5){ - - - return (a1 + a2 == a3) + (a2 + a3 == a4 )+ (a3 + a4 == a5) ; - - -} - -int32_t main() - -{ //inF; - //inF;outF; - fastio; - - int t ; - cin >> t ; - - while(t--){ - - int n ; - cin >> n ; - - vector v(n); - for(auto &it : v)cin >> it ; - if(v[1] < v[0])cout << ""NO""; - else { - string ans = ""YES""; - for(int i = 2 ; i < n ; i ++){ - if(v[i] < v[i - 1]){ - v[i - 1] -= min(v[i - 1] , v[i - 2]); - - } - if(v[i] < v[i - 1]){ - ans = ""NO""; - break; - } - } - cout << ans ; - } - - - cout << '\n'; - } - -} - - -",1 -Flowfier,2060D - Subtract Min Sort,c++17 ,313563792,313564384,"#include - -using namespace std; - -#define endl '\n' - -#define ll long long - - - -void solve() { - -int n; - -cin >> n; - -vector a(n + 1, 0); - -bool is_no = false; - -for (int i = 1;i <= n;i++) cin >> a[i]; - -for (int i = 1;i <= n - 1;i++) { - -if (i == 1) { - -if (a[i + 1] >= a[i]) continue; - -else { - -is_no = true; - -break; - -} - -} - -else { - -if (a[i + 1] >= abs(a[i] - a[i - 1])) continue; - -else { - -is_no = true; - -break; - -} - -} - -} - -if (!is_no) cout << ""YES"" << endl; - -else cout << ""NO"" << endl; - -} - - - -int main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int t; - -cin >> t; - -while (t--) solve(); - -return 0; - -}","#include - -using namespace std; - -#define endl '\n' - -#define ll long long - - - -void solve() { - -int n; - -cin >> n; - -vector a(n + 1, 0); - -bool is_no = false; - -for (int i = 1;i <= n;i++) cin >> a[i]; - -for (int i = 1;i <= n - 1;i++) { - -if (a[i + 1] >= a[i]) { - -a[i + 1] = a[i + 1] - a[i]; - -a[i] = 0; - -continue; - -} - -else { - -is_no = true; - -break; - -} - -} - -if (!is_no) cout << ""YES"" << endl; - -else cout << ""NO"" << endl; - -} - - - -int main() { - -ios::sync_with_stdio(false); - -cin.tie(nullptr); - -int t; - -cin >> t; - -while (t--) solve(); - -return 0; - -}",2 -Aditya_Metkar,2060D - Subtract Min Sort,python,303195953,303195857,"for _ in range(int(input())): - - n = int(input()) - nums = list(map(int,input().split())) - - ok = True - - for i in range(n-1): - if nums[i]>nums[i+1]: - ok = False - break - nums[i+1]-=nums[i] - - if ok: - print(""YES"") - else: - print(""NO"")","for _ in range(int(input())): - - n = int(input()) - nums = map(int,input().split()) - - ok = True - - for i in range(n-1): - if nums[i]>nums[i+1]: - ok = False - break - nums[i+1]-=nums[i] - - if ok: - print(""YES"") - else: - print(""NO"")",1 -Kaustubh_Srivastava,2060D - Subtract Min Sort,c++20 ,304553575,304553912,"#include -#include -#include - -using namespace std; - -int main() -{ - int t; - cin >> t; - - while(t--) - { - int n; - cin >> n; - int d[n]; - for(int i = 0; i < n; i++) - cin >> d[i]; - - bool fl = 1; - for(int i = 0; i < n; i+=2) - { - if(d[i] > d[i+1])fl = 0; - } - if(fl) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - } -}","#include -#include -#include - -using namespace std; - -int main() -{ - int t; - cin >> t; - - while(t--) - { - int n; - cin >> n; - int d[n]; - for(int i = 0; i < n; i++) - cin >> d[i]; - - bool fl = 1; - for(int i = 0; i < n; i+=2) - { - if(i == n-1)break; - if(d[i] > d[i+1])fl = 0; - } - if(fl) - cout << ""YES"" << endl; - else - cout << ""NO"" << endl; - } -}",2 -Code-by-Uday,2060D - Subtract Min Sort,c++23 ,308540672,308541307,"#include - -#define ll long long - -using namespace std; - -int main(){ - - int t;cin>>t; - - while(t--){ - - ll n;cin>>n; - - string ans=""YES""; - - ll a[n]; - - for(ll i=041;i>a[i]; - - if(i>=1){ - - if(a[i]>=a[i-1]){ - - a[i]-=a[i-1]; - - a[i-1]=0; - - } - - } - - } - - - - - - for(ll i=0;ia[i+1]){ - - ans=""NO""; - - break; - - } - - } - - cout< - -#define ll long long - -using namespace std; - -int main(){ - - int t;cin>>t; - - while(t--){ - - ll n;cin>>n; - - string ans=""YES""; - - ll a[n]; - - for(ll i=0;i>a[i]; - - if(i>=1){ - - if(a[i]>=a[i-1]){ - - a[i]-=a[i-1]; - - a[i-1]=0; - - } - - } - - } - - - - - - for(ll i=0;ia[i+1]){ - - ans=""NO""; - - break; - - } - - } - - cout< -using namespace std; -typedef long long ll; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - vector a(n + 1); - for(int i = 0; i < n; i++) - { - cin >> a[i]; - } - for(int i = 0; i < n - 1; i++) - { - if(a[i] <= a[i + 1]) - { - int t = min(a[i], a[i + 1]); - a[i] -= t; - a[i + 1] -= t; - } - } - bool f = 1; - for(int i = 0; i < n - 1; i++) - { - if(a[i + 1] < a[i]) - f = 0; - } - if(f) cout << ""YES""; - else cout << ""NO""; - cout << endl; - } - return 0; -} - -","#include -using namespace std; -typedef long long ll; -int main() -{ - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - vector a(n + 1); - for(int i = 0; i < n; i++) - { - cin >> a[i]; - } - for(int i = 0; i < n - 1; i++) - { - if(a[i] <= a[i + 1]) - { - a[i] -= min(a[i], a[i + 1]); - a[i + 1] -= min(a[i], a[i + 1]); - } - } - cout << (is_sorted(a.begin(), a.end())) ? ""YES"" : ""NO""; - cout << endl; - } - return 0; -} - -",1 -kushkushali,2060D - Subtract Min Sort,c++20 ,309016140,309016835,"#include ""bits/stdc++.h"" - -using namespace std; - -using ll= long long int; - -#define f(i,a,b) for(ll i=a;i<(ll)(b);i++) - -#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i) - -#define pb push_back - -#define vi vector - -void solve(){ - -ll n;cin>>n; - -vi v(n); - -f(i,0,n){ - - cin>>v[i]; - -} - -if(n==2){ - - if(v[0]>v[1]) - - cout<<""no""<v[i+1]&&v[i+1]>v[i+2]){ - - modda=1;break;} - -} - -if(modda) - -cout<<""no""<>t;while(t--){ - - solve(); - -}}","#include ""bits/stdc++.h"" - -using namespace std; - -using ll= long long int; - -#define f(i,a,b) for(ll i=a;i<(ll)(b);i++) - -#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i) - -#define pb push_back - -#define vi vector - -void solve(){ - -ll n;cin>>n; - -vi v(n); - -f(i,0,n){ - - cin>>v[i]; - -}int modda=0; - - f(i,0,n-1){ - - if(v[i]>v[i+1]){ - - modda=1;break;} - - v[i+1]=v[i+1]-min(v[i],v[i+1]); - - } - - if(modda) - - cout<<""no""<>t;while(t--){ - - solve(); - -}}",2 -nooobofcode69,2060D - Subtract Min Sort,c++23 ,314658349,314746575,"#include - -using namespace std; - - - -void solve() { - -int n; - -cin >> n; - -vector a(n); - -for(int &x : a) cin >> x; - - - -int down = 0; - -for(int i = 0; i < n - 1; ++i) { - -if(a[i] > a[i+1]) { - -down++; - -if(down > 1) break; - -} - -else down=0; - - - -} - -if(n==2 & a[1]>=a[0])cout<<""YES""<> t; - -while (t--) solve(); - -} - -","#include - -using namespace std; - -#define ll long long - -void solve() - -{ - -ll n;cin>>n;vectorv(n); - -for(auto &x:v)cin>>x; - -for(ll i=0;iv[i+1]) {cout<<""NO""<<'\n';return;} - -v[i+1]-=v[i]; - -v[i]=0; - -} - -for(ll i=0;iv[i+1]){cout<<""NO""<<'\n';return;}} - -cout<<""YES""<<'\n'; - -} - -int main() - -{ - -ll t; - -cin>>t; - -while(t--) solve(); - -return 0; - -}",2 -AbdoMatrix,2060D - Subtract Min Sort,c++17 ,304956011,304955117,"#include - -#define ll long long -#define ull unsigned long long -#define dbl double -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -constexpr dbl PI = 3.14159265359; -constexpr ll mod = 1e9 + 7; - -using namespace std; - -void solve() { - int n; - cin >> n; - - int j = 0; - vector vec(n); - for (int i = 0; i < n; ++i) { - cin >> vec[i]; - if (i > 0 && vec[i] < vec[i - 1]) j = i; - } - if (j == 0) { - cout << ""YES\n""; - return; - } - - for (int i = 0; i < j; ++i) { - ll minN = min(vec[i], vec[i+1]); - vec[i] -= minN; - vec[i+1] -= minN; - } - - cout << (is_sorted(vec.begin(), vec.end()) ? ""YES"" : ""NO"") << '\n'; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}","#include - -#define ll long long -#define ull unsigned long long -#define dbl double -#define yes cout << ""YES\n"" -#define no cout << ""NO\n"" -constexpr dbl PI = 3.14159265359; -constexpr ll mod = 1e9 + 7; - -using namespace std; - -void solve() { - int n; - cin >> n; - - vector vec(n); - for (int i = 0; i < n; ++i) { - cin >> vec[i]; - } - - if (vec[0] > vec[1]) { - cout << ""NO\n""; - return; - } - if (vec[n - 2] > vec[n - 1]) { - cout << ""NO\n""; - return; - } - cout << ""YES\n""; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}",1 -ImNoob0550,2060D - Subtract Min Sort,c++23 ,304417795,304416926,"#include -#define ll long long -using namespace std; -int main() -{ - // freopen(""TALENT.INP"",""r"",stdin); - // freopen(""TALENT.OUT"",""w"",stdout); - ios_base::sync_with_stdio(0); - cin.tie(0); - ll t; - cin >> t; - for(ll u=1;u<=t;u++) - { - ll n; - cin >> n; - ll a[n+1]; - for(ll i=1;i<=n;i++) - { - cin >> a[i]; - } - bool check=false; - for(ll i=1;ia[i+1]) - { - check=true; - break; - } - else - { - a[i+1]-=a[i]; - a[i]=0; - } - } - if(check==true) - { - cout << ""NO""; - } - else - { - cout << ""YES""; - } - cout << '\n'; - } - return 0; -}","#include -#define ll long long -using namespace std; -int main() -{ - // freopen(""TALENT.INP"",""r"",stdin); - // freopen(""TALENT.OUT"",""w"",stdout); - ios_base::sync_with_stdio(0); - cin.tie(0); - ll t; - cin >> t; - for(ll u=1;u<=t;u++) - { - ll n; - cin >> n; - ll a[n+1]; - ll maxA=0; - ll minA=1e18; - for(ll i=1;i<=n;i++) - { - cin >> a[i]; - maxA=max(maxA,a[i]); - minA=min(minA,a[i]); - } - if(maxA==a[1] or minA==a[n]) - { - cout << ""NO""; - } - else - { - cout << ""YES""; - } - cout << '\n'; - } - return 0; -}",1 -DedSecAlpha,2060D - Subtract Min Sort,c++20 ,307044827,307044314,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define DedSec ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define ll long long -#define ld long double -#define pii pair -#define pll pair -#define fi first -#define se second -#define all(x) (x).begin(), (x).end() -#define in(x,n) for(int i=0;i<(n);i++) cin>>(x)[i] -#define out(x,n) for(int z=0;z<(n);z++) cout<<(x)[z]<<"" \n""[z==(n)-1] -#define clr(x) memset((x), 0, sizeof (x)) -#define nom(x) ((x) - '0') -int dr[] = {-1,1,0,0, -1,-1,1, 1}; -int dc[] = {0,0,1,-1, 1, -1, 1, -1}; -template -using ordered_set = tree,rb_tree_tag,tree_order_statistics_node_update>; -template -using multi_ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -void solve(){ - int n; cin >> n; - vectora(n); in(a, n); - if(a[1] < a[0]) return cout << ""NO\n"", void(); - a[1] -= min(a[1], a[0]); - for(int i = 2; i < n; i++){ - if(a[i] < a[i - 1]){ - return cout << ""NO\n"", void(); - } - a[i] -= min(a[i], a[i - 1]); - } - cout << ""YES\n""; -} - -int main(){ - DedSec -// freopen(""input.txt"",""r"",stdin); -// freopen(""output.txt"",""w"",stdout); - int t=1; - cin>>t; - while (t--) solve(); -// for(int i = 1; i <= t; i++) solve(i); - return 0; -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define DedSec ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define ll long long -#define ld long double -#define pii pair -#define pll pair -#define fi first -#define se second -#define all(x) (x).begin(), (x).end() -#define in(x,n) for(int i=0;i<(n);i++) cin>>(x)[i] -#define out(x,n) for(int z=0;z<(n);z++) cout<<(x)[z]<<"" \n""[z==(n)-1] -#define clr(x) memset((x), 0, sizeof (x)) -#define nom(x) ((x) - '0') -int dr[] = {-1,1,0,0, -1,-1,1, 1}; -int dc[] = {0,0,1,-1, 1, -1, 1, -1}; -template -using ordered_set = tree,rb_tree_tag,tree_order_statistics_node_update>; -template -using multi_ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -void solve(){ - int n; cin >> n; - vectora(n); in(a, n); - if(a[1] < a[0]) return cout << ""NO\n"", void(); - for(int i = 2; i < n; i++){ - if(a[i] < a[i - 1]){ - a[i - 1] -= min(a[i - 1], a[i - 2]); - if(a[i] < a[i - 1]) return cout << ""NO\n"", void(); - } - } - cout << ""YES\n""; -} - -int main(){ - DedSec -// freopen(""input.txt"",""r"",stdin); -// freopen(""output.txt"",""w"",stdout); - int t=1; - cin>>t; - while (t--) solve(); -// for(int i = 1; i <= t; i++) solve(i); - return 0; -}",1 -ive_sound_vocaloid#,2060D - Subtract Min Sort,c++17 ,309592140,309594399,"#include - -using namespace std; - - - - - -void solve(){ - - int n; - - cin>>n; - - vectora(n); - - for(int i=0;i>a[i]; - - int last=0; - - int p=0; - - int ans=1; - - int gap; - - while(p=last){ - - gap=a[p]-last; - - last=a[p]; - - } - - else if(a[p]>=gap){ - - last=gap; - - gap=a[p]-last; - - } - - else ans=0; - - p++; - - } - - cout<<(ans?""YES\n"":""NO\n""); - -} - -int main(){ - - int t; - - cin>>t; - - while(t--) solve(); - - return 0; - -} - -","//#include - -//using namespace std; - -// - -// - -//void solve(){ - -// int n; - -// cin>>n; - -// vectora(n); - -// for(int i=0;i>a[i]; - -// int last=0; - -// int p=0; - -// int ans=1; - -// int gap; - -// while(p=last){ - -// gap=a[p]-last; - -// last=a[p]; - -// } - -// else if(a[p]>=gap){ - -// last=gap; - -// gap=a[p]-last; - -// } - -// else ans=0; - -// p++; - -// } - -// cout<<(ans?""YES\n"":""NO\n""); - -//} - -//int main(){ - -// int t; - -// cin>>t; - -// while(t--) solve(); - -// return 0; - -//} - - - -#include - -using namespace std; - - - - - -void solve(){ - - int n; - - cin>>n; - - vectora(n); - - for(int i=0;i>a[i]; - - int ans=1; - - vectorv; - - for(int i=0;i=v.back()){ - - int t=a[i]-v.back(); - - v.clear(); - - v.push_back(t); - -// v.push_back(a[i]); - - } - - else ans=0; - -// else{ - -// int tt=v.back()-v.front(); - -// if(a[i]>=tt){ - -// v.clear(); - -// v.push_back(tt); - -// v.push_back(a[i]); - -// } - -// else{ - -// ans=0; - -// } - -// } - - } - - cout<<(ans?""YES\n"":""NO\n""); - -} - -int main(){ - - int t=1; - - cin>>t; - - while(t--) solve(); - - return 0; - -} - -",2 -AC_sahER,2060D - Subtract Min Sort,c++23 ,304056270,304055540,"#ifndef LOCAL -#pragma GCC optimize(""O3"") -#endif - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -const int inf = 1'000'000'007; -const ll llinf = 1'000'000'000'000'000'007LL; - - -void precalc() { - -} - -void solve() { - int n; - cin >> n; - vector arr(n); - for (auto &i : arr) { - cin >> i; - } - for (int i = 1; i < n; i++) { - int val = min(arr[i], arr[i - 1]); - arr[i] -= val; - arr[i - 1] -= val; - } - for (int i = 1; i < n; i++) { - if (arr[i] < arr[i - 1]) { - cout << ""NO""; - return; - } - } - cout << ""YES""; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cin.sync_with_stdio(false); - cout.sync_with_stdio(false); - srand(time(0)); - cout.precision(10); - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#else - // freopen(""fragmentation.in"", ""r"", stdin); - // freopen(""fragmentation.out"", ""w"", stdout); -#endif - - clock_t start_time = clock(); - precalc(); -#ifdef LOCAL - cerr << ""Precalc spent "" << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << "" seconds\n""; -#endif - - int tt = 1; - cin >> tt; - for (int i = 0; i < tt; i++) { - start_time = clock(); - solve(); - cout << ""\n""; -#ifdef LOCAL - cerr << ""Testcase #"" << i + 1 << "" spent "" << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << "" seconds\n""; -#endif - } - return 0; -}","#ifndef LOCAL -#pragma GCC optimize(""O3"") -#endif - -#include - -using namespace std; - -typedef long long ll; -typedef long double ld; - -const int inf = 1'000'000'007; -const ll llinf = 1'000'000'000'000'000'007LL; - - -void precalc() { - -} - -void solve() { - int n; - cin >> n; - vector arr(n); - for (auto &i : arr) { - cin >> i; - } - if (arr[0] > arr[1]) { - cout << ""NO""; - return; - } - for (int i = 1; i + 1 < n; i++) { - if (arr[i] > arr[i + 1]) { - arr[i] -= arr[i - 1]; - } - if (arr[i] > arr[i + 1]) { - cout << ""NO""; - return; - } - } - - cout << ""YES""; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cin.sync_with_stdio(false); - cout.sync_with_stdio(false); - srand(time(0)); - cout.precision(10); - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#else - // freopen(""fragmentation.in"", ""r"", stdin); - // freopen(""fragmentation.out"", ""w"", stdout); -#endif - - clock_t start_time = clock(); - precalc(); -#ifdef LOCAL - cerr << ""Precalc spent "" << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << "" seconds\n""; -#endif - - int tt = 1; - cin >> tt; - for (int i = 0; i < tt; i++) { - start_time = clock(); - solve(); - cout << ""\n""; -#ifdef LOCAL - cerr << ""Testcase #"" << i + 1 << "" spent "" << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << "" seconds\n""; -#endif - } - return 0; -}",1 -kataki#,2060D - Subtract Min Sort,c++17 ,316452651,316453621,"#include - -using namespace std; - - - -// Header files, namespaces, - -// macros as defined above - -#include - -#include - -using namespace __gnu_pbds; - - - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> - - - -using ll = long long; - -using ull = unsigned long long; - - - -#define pb(v) push_back(v) - -#define all(v) (v).begin(), (v).end() - -#define rall(v) (v).rbegin(), (v).rend() - -#define MSET(c, v) memset(c, v, sizeof(c)) - -#define debug(x) cout << #x << "" is "" << x << endl - - - -const int NEGINF = 0xC0C0C0C0; - -const int NULO = -1; - -const double EPS = 1e-10; - -const ll mod = 1e9 + 7; - -const ll llInf = 4e17; - -const int inf = 2e9; - - - -int dy[] = {0,1,-1,0}; - -int dx[] = {1,0,0,-1}; - - - -template - -std::pair operator+(const std::pair & l,const std::pair & r) { - -return {l.first+r.first,l.second+r.second}; - -} - - - -const int maxn = 2e5 + 100; - - - -ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } - - - -int a[maxn]; - -void solveTestCase(int test) { - - - -int n; - -cin >> n; - -for(int i = 1; i <= n; i++) { - -cin >> a[i]; - -} - -int last = a[n]; - -for(int i = 1; i <= n - 2; i++) { - -if(a[i] > last) { - -if(a[i] > a[i + 1]) { - -cout << ""NO"" << endl; - -return; - -} else { - -a[i + 1] -= a[i]; - -a[i] = 0; - -//cout << a[i] << "" "" << a[i + 1] << endl; - -} - -} - -} - -cout << ""YES"" << endl; - -// for(int i = 1; i <= n; i++) { - -// cout << a[i] << "" ""; - -// } - -// cout << endl; - -} - - - -int main() { - -ios::sync_with_stdio(false); - -int test = 1; - -cin >> test; - -for (int t = 1; t <= test; t++) { - -solveTestCase(t); - -} - - - -return 0; - -}","#include - -using namespace std; - - - -// Header files, namespaces, - -// macros as defined above - -#include - -#include - -using namespace __gnu_pbds; - - - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> - - - -using ll = long long; - -using ull = unsigned long long; - - - -#define pb(v) push_back(v) - -#define all(v) (v).begin(), (v).end() - -#define rall(v) (v).rbegin(), (v).rend() - -#define MSET(c, v) memset(c, v, sizeof(c)) - -#define debug(x) cout << #x << "" is "" << x << endl - - - -const int NEGINF = 0xC0C0C0C0; - -const int NULO = -1; - -const double EPS = 1e-10; - -const ll mod = 1e9 + 7; - -const ll llInf = 4e17; - -const int inf = 2e9; - - - -int dy[] = {0,1,-1,0}; - -int dx[] = {1,0,0,-1}; - - - -template - -std::pair operator+(const std::pair & l,const std::pair & r) { - -return {l.first+r.first,l.second+r.second}; - -} - - - -const int maxn = 2e5 + 100; - - - -ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } - - - -ll a[maxn]; - -void solveTestCase(int test) { - - - -int n; - -cin >> n; - -for(int i = 1; i <= n; i++) { - -cin >> a[i]; - -} - -bool ok = true; - -for(int i = 1; i <= n - 1; i++) { - -if(a[i] > a[i + 1]) { - -ok = false; - -break; - -} else { - -a[i + 1] -= a[i]; - -a[i] = 0; - -} - -} - -cout << (ok ? ""YES"" : ""NO"") << endl; - -} - - - -int main() { - -ios::sync_with_stdio(false); - -int test = 1; - -cin >> test; - -for (int t = 1; t <= test; t++) { - -solveTestCase(t); - -} - - - -return 0; - -}",2 -WannaSl33p,2060D - Subtract Min Sort,c++23 ,308397507,308399528,"#include - -using namespace std; - - - -#define int long long int - -#define endl ""\n"" - -#define fori(a, n) for(int i = a; i < n; i++) - -#define vi vector - - - -void solve() { - - - - - - int n; cin >> n; - - - - vi a(n); - - - - for(auto &x : a) { - - cin >> x; - - } - - - - for(int i = 0; i < n; i += 2) { - - if(a[i] > a[i + 1]) { - - cout << ""NO"" << endl; - - return; - - } - - } - - - - - - - - cout << ""YES"" << endl; - - - - return; - -} - - - -signed main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); cout.tie(NULL); - - - - int t = 1; - - cin >> t; - - - - while(t--) - - solve(); - - - - return 0; - -}","#include - -using namespace std; - - - -#define int long long int - -#define endl ""\n"" - -#define fori(a, n) for(int i = a; i < n; i++) - -#define vi vector - - - -void solve() { - - - - - - int n; cin >> n; - - - - bool flag = true; - - deque dq(n); - - - - for(auto &x : dq) - - cin >> x; - - - - while((int)dq.size() > 1) { - - if(dq[0] > dq[1]) { - - flag = false; - - break; - - } else if(dq[0] < dq[1]) { - - dq[1] -= dq[0]; - - dq.pop_front(); - - } else { - - dq.pop_front(); - - dq.pop_front(); - - } - - } - - - - cout << (flag ? ""YES"" : ""NO""); - - cout << endl; - - - - return; - -} - - - -signed main() { - - - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); cout.tie(NULL); - - - - int t = 1; - - cin >> t; - - - - while(t--) - - solve(); - - - - return 0; - -}",2 -jagannadhasuri,2060D - Subtract Min Sort,c++17 ,311616118,311627482,"#include - - - -using namespace std; - - - -bool is(int * a, int n) { - -for(int i = 0; i < n - 1; i++) { - -if(a[i] < a[i + 1]) { - -a[i + 1] = a[i + 1] - a[i]; - -a[i] = 0; - -} - - - -else { - -return false; - -} - -} - - - -return true; - -} - - - -int main() { - -int t; - -cin>>t; - - - -while(t--) { - -int n; - -cin>>n; - - - -int arr[n]; - - - -for(int i = 0; i < n ; i++) { - -cin>>arr[i]; - -} - - - -if(is(arr, n)) { - -cout<<""yes""; - -} - - - -else { - -cout<<""no""; - -} - -} - -return 0; - -}","#include - - - -using namespace std; - - - -bool is(int * a, int n) { - -for(int i = 0; i < n - 1; i++) { - -if(a[i] <= a[i + 1]) { - -a[i + 1] = a[i + 1] - a[i]; - -a[i] = 0; - -} - - - -else { - -return false; - -} - -} - - - -return true; - -} - - - -int main() { - -int t; - -cin>>t; - - - -while(t--) { - -int n; - -cin>>n; - - - -int arr[n]; - - - -for(int i = 0; i < n ; i++) { - -cin>>arr[i]; - -} - - - -if(is(arr, n)) { - -cout<<""yes""; - -} - - - -else { - -cout<<""no""; - -} - -cout<<""\n""; - -} - -return 0; - -}",2 -tammmmmy,2060D - Subtract Min Sort,c++20 ,303806892,303807995,"#include ""bits/stdc++.h"" -using namespace std; -#include ""vector"" -#include ""map"" -#include ""set"" -#include ""queue"" -#include ""stack"" -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define nline ""\n"" -#define pb push_back -#define ppb pop_back -#define mp make_pair -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() - -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; -// typedef tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -int main() { -fastio(); -int tc;cin>>tc; -while(tc--){ - int n;cin>>n; - vector a(n); - for(int i=0;i>a[i]; - - - int f=1; - - for(int i=n-2;i>=0;i--){ - if(a[i]<=a[i+1])continue; - if(i==0){ - f=0;break; - } - int t=min(a[i],a[i-1]); - a[i-1]-=t; - a[i]-=t; - - if(a[i-1]>a[i+1]){ - f=0;break; - } - } - if(f)cout<<""YES""<, null_type, less>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -int main() { -fastio(); -int tc;cin>>tc; -while(tc--){ - int n;cin>>n; - vector a(n); - for(int i=0;i>a[i]; - - -int f=1; -for(int i=1;i -using namespace std; -typedef long long ll; -#define all(a) a.begin(), a.end() -typedef vector vll; -#define life ios_base::sync_with_stdio(false); -#define saver cin.tie(0); -#define f first -#define s second -#define nxt cout << endl; -const int mod = 1e9 + 7; -const int N = 1e5 + 10; -#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) -#define rep0(i, a) rep(i, 0, a) -#define pb push_back - -int main() -{ - life saver int t; - cin >> t; - while (t--) - { - - int n; - cin >> n; - vll a(n); - rep0(i, n) - { - cin >> a[i]; - } - - if (a[0] >= a[1]) - { - cout << ""NO"" << endl; - } - else - { - cout << ""YES"" << endl; - } - } - - return 0; -}","#include -using namespace std; -typedef long long ll; -#define all(a) a.begin(), a.end() -typedef vector vll; -#define life ios_base::sync_with_stdio(false); -#define saver cin.tie(0); -#define f first -#define s second -#define nxt cout << endl; -const int mod = 1e9 + 7; -const int N = 1e5 + 10; -#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) -#define rep0(i, a) rep(i, 0, a) -#define pb push_back - -int main() -{ - life saver int t; - cin >> t; - while (t--) - { - - int n; - cin >> n; - vll a(n); - bool flag = true; - rep0(i, n) - { - cin >> a[i]; - } - - ll d = a[0]; - rep(i, 1, n) - { - if (d > a[i]) - { - flag = false; - break; - } - else - { - d = a[i] - d; - } - } - if (flag) - { - cout << ""YES"" << endl; - } - else - { - cout << ""NO"" << endl; - } - } - - return 0; -}",2 -im.m0hd,2060D - Subtract Min Sort,python,307172161,307173803,"# -*- coding: utf-8 -*- -"""""" -Created on Fri Feb 21 21:15:24 2025 - -@author: hp -"""""" - -case = input() - -ans = [] -for i in range(int(case)): - value = input() - v = input().split() - if True: - answer = 0 - for j in range(len(v)): - if j < int(value)-1: - answer = int(v[j+1]) - int(v[j]) - - if answer >=0: - ans.append(""yes"") - - else: - ans.append(""no"") - - -for m in ans: - print(m) - - - - ","# -*- coding: utf-8 -*- -"""""" -Created on Fri Feb 21 21:15:24 2025 - -@author: hp -"""""" - -case = input() - -ans = [] -for i in range(int(case)): - value = input() - v = input().split() - if int(len(v)) == int(value): - flag = 1 - answer = 0 - for j in range(len(v)): - if j < int(value)-1: - if j == 0: - answer = int(v[j+1]) - int(v[j]) - else: - answer = int(v[j+1]) - answer - - if answer < 0: - flag=-1 - - if flag == 1: - ans.append(""yes"") - - else: - ans.append(""no"") - - -for m in ans: - print(m) - - - - ",2 -Eyadooz1,2060D - Subtract Min Sort,c++20 ,305123463,305123689,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace __gnu_pbds; -using namespace std; - -#define endl '\n' -#define mod 1000000007 -#define INF 0x3f3f3f3f - -#pragma GCC optimize(""O3,Ofast,unroll-loops"") -#pragma GCC target(""avx2,sse3,sse4,avx"") -#pragma GCC target(""popcnt"") - -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef pair ipair; - -static inline int read() -{ - int x = 0;char ch = getchar(); - while (ch < '0' || ch>'9') ch = getchar(); - while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); - return x; -} - -static inline void print(const int &x) { - if (x > 9)print(x / 10); - putchar('0' + x % 10); -} - -int main() -{ - cin.tie(0) -> sync_with_stdio(0); - - int t; - - cin >> t; - - while(t--) - { - int n; - - cin >> n; - - int list[n]; - for(int i = 0;i < n;cin >> list[i++]); - - for(int i = 1;i < n;i++) - { - int x = min(list[i], list[i-1]); - - list[i] -= x; - list[i - 1] -= x; - } - - bool f = 1; - for(int i = 0;i < n;i++) - { - if(list[i] > list[i + 1]) f = 0; - } - - cout << (f ? ""YES\n"" : ""NO\n""); - } -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace __gnu_pbds; -using namespace std; - -#define endl '\n' -#define mod 1000000007 -#define INF 0x3f3f3f3f - -#pragma GCC optimize(""O3,Ofast,unroll-loops"") -#pragma GCC target(""avx2,sse3,sse4,avx"") -#pragma GCC target(""popcnt"") - -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef pair ipair; - -static inline int read() -{ - int x = 0;char ch = getchar(); - while (ch < '0' || ch>'9') ch = getchar(); - while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); - return x; -} - -static inline void print(const int &x) { - if (x > 9)print(x / 10); - putchar('0' + x % 10); -} - -int main() -{ - cin.tie(0) -> sync_with_stdio(0); - - int t; - - cin >> t; - - while(t--) - { - int n; - - cin >> n; - - int list[n]; - for(int i = 0;i < n;cin >> list[i++]); - - for(int i = 1;i < n;i++) - { - int x = min(list[i], list[i-1]); - - list[i] -= x; - list[i - 1] -= x; - } - - bool f = 1; - for(int i = 0;i < n-1;i++) - { - if(list[i] > list[i + 1]) f = 0; - } - - cout << (f ? ""YES\n"" : ""NO\n""); - } -} -",2 -lce4113#,2060D - Subtract Min Sort,c++17 ,304893100,304893802,"// Codeforces Round 998: Problem D - -#include -using namespace std; - -#define int long long -#define f first -#define s second - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) cin >> x; - if (a[0] > a[1]) { - cout << ""NO\n""; - return; - } - for (int i = 1; i < n; i++) { - if (a[i] > a[i - 1] && (i - 2 < 0 || a[i - 1] > a[i - 2])) { - a[i] -= a[i - 1], a[i - 1] = 0; - } - } - - for (int i = 1; i < n; i++) { - if (a[i] < a[i - 1]) { - cout << ""NO\n""; - return; - } - } - - cout << ""YES\n""; -} - -int32_t main() { - cin.tie(0)->sync_with_stdio(0); - int t = 1; - cin >> t; - while (t--) solve(); -}","// Codeforces Round 998: Problem D - -#include -using namespace std; - -#define int long long -#define f first -#define s second - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) cin >> x; - if (a[0] > a[1]) { - cout << ""NO\n""; - return; - } - for (int i = 1; i < n; i++) { - if (a[i] >= a[i - 1] && (i == 1 || a[i - 2] == 0)) { - a[i] -= a[i - 1], a[i - 1] = 0; - } - } - - // for (auto x : a) cout << x << ' '; - // cout << '\n'; - - for (int i = 1; i < n; i++) { - if (a[i] < a[i - 1]) { - cout << ""NO\n""; - return; - } - } - - cout << ""YES\n""; -} - -int32_t main() { - cin.tie(0)->sync_with_stdio(0); - int t = 1; - cin >> t; - while (t--) solve(); -}",2 -adarshtiwari0111,2060D - Subtract Min Sort,c++17 ,314846440,314846704,"#include - -using namespace std; - -void solve(){ - -int n; - -cin>>n; - -int arr[n]; - -for(int i=0 ; i>arr[i]; - -} - -int k=arr[0]; - -for(int i=1 ; i>t; - -while(t--){ - -solve(); - -} - -return 0; - -}","#include - -using namespace std; - -void solve(){ - -int n; - -cin>>n; - -int arr[n]; - -for(int i=0 ; i>arr[i]; - -} - -int k=arr[0]; - -for(int i=1 ; i>t; - -while(t--){ - -solve(); - -} - -return 0; - -}",2 -ArchiT_0x1,2060D - Subtract Min Sort,c++20 ,304338462,304338769,"#include -using namespace std; -#define int long long -int power(int A, int expo) -{ - if (expo == 0) - return 1; - int res = power(A, expo / 2); - if (expo % 2) - return res * res * A; - else - return res * res; -} -int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } -int factorial(int x) -{ - if (x == 1 || x == 0) - return 1; - return (x * factorial(x - 1)); -} -class UnionFind{ - private: vector parent,rank; - public: - UnionFind(int n){ - rank.assign(n,0); - parent.assign(n,0); - iota(parent.begin(),parent.end(),0); - } - int find(int x) { - if(parent[x] == x) - return x; - - return parent[x] = find(parent[x]); - } - - void UnionSet(int x, int y) { - int x_parent = find(x); - int y_parent = find(y); - - if(rank[x_parent] > rank[y_parent]) { - parent[y_parent] = x_parent; - } else if(rank[x_parent] < rank[y_parent]) { - parent[x_parent] = y_parent; - } else { - parent[x_parent] = y_parent; - rank[y_parent]++; - } - } -}; - -int lcm(int a, int b) { - return (a / gcd(a, b)) * b; -} - -int dx[] = {-1, 1, 0, 0}; -int dy[] = {0, 0, -1, 1}; - -void solve() { - int n; - cin>>n; - vector v(n); - for(int i=0;i>v[i]; - } - for(int i=1;i0) cnt++; - } - if(cnt>1){ - cout<<""No\n""; - } - else{ - cout<<""Yes\n""; - } -} - -signed main() { -#ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -#define int long long -int power(int A, int expo) -{ - if (expo == 0) - return 1; - int res = power(A, expo / 2); - if (expo % 2) - return res * res * A; - else - return res * res; -} -int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } -int factorial(int x) -{ - if (x == 1 || x == 0) - return 1; - return (x * factorial(x - 1)); -} -class UnionFind{ - private: vector parent,rank; - public: - UnionFind(int n){ - rank.assign(n,0); - parent.assign(n,0); - iota(parent.begin(),parent.end(),0); - } - int find(int x) { - if(parent[x] == x) - return x; - - return parent[x] = find(parent[x]); - } - - void UnionSet(int x, int y) { - int x_parent = find(x); - int y_parent = find(y); - - if(rank[x_parent] > rank[y_parent]) { - parent[y_parent] = x_parent; - } else if(rank[x_parent] < rank[y_parent]) { - parent[x_parent] = y_parent; - } else { - parent[x_parent] = y_parent; - rank[y_parent]++; - } - } -}; - -int lcm(int a, int b) { - return (a / gcd(a, b)) * b; -} - -int dx[] = {-1, 1, 0, 0}; -int dy[] = {0, 0, -1, 1}; - -void solve() { - int n; - cin>>n; - vector v(n); - for(int i=0;i>v[i]; - } - for(int i=0;iv[i+1]){ - cout<<""No\n""; - return; - } - } - cout<<""Yes\n""; -} - -signed main() { -#ifndef ONLINE_JUDGE - freopen(""input1.txt"", ""r"", stdin); - freopen(""output1.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -",2 -JattzzKun,2060D - Subtract Min Sort,c++17 ,314409933,314411127,"#include - -using namespace std; - -int main(){ - -int t; cin>>t; - -while(t--){ - -int n; cin>>n; - -vector v(n); - -for(auto &i: v) cin>>i; - -if(v[n-1]>v[n-2]) cout<<""YES""< - -using namespace std; - -int main(){ - -long long t; cin>>t; - -while(t--){ - -long long n; cin>>n; - -vector v(n); - -for(auto &i: v) cin>>i; - -long long j = 0; - -for(long long i = 1; iv[i]) j = i; - -} - -if(j == 0) cout<<""YES""< -#include -#include -#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) -#define ll long long -#define pb push_back -#define eb emplace_back -#define endl '\n' - -using namespace std; - -const int MOD = 1000000007; - -#ifdef KRISHNA -#include ""handle_debug.hpp"" -#define debug(...) \ - cout << '['; \ - debug_print(#_VA_ARGS, VA_ARGS_); \ - cout << ""]\n""; -#else -#define debug(...) -#endif - -ll gcd(ll a, ll b) -{ - while (b) - { - ll t = a % b; - a = b; - b = t; - } - return a; -} - -bool isPrime(ll n) -{ - if (n <= 1) - { - return false; - } - for (int i = 2; i <= sqrt(n); i++) - { - if (n % i == 0) - { - return false; - } - } - return true; -} - -int isSubstring(string s1, string s2) -{ - if (s2.find(s1) != string::npos) - return s2.find(s1); - return -1; -} - -ll fac(ll n) -{ - ll f = 1; - if (n == 0 || n == 1) - return 1; - else - { - for (ll i = 2; i <= n; i++) - { - f *= i; - } - return f; - } -} - -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vector vec(n,0); - for(int i=0; i>vec[i]; - } - int flag=1; - for (int i = 0; i < n-1; i+=2) - { - if(vec[i+1] -#include -#include -#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) -#define ll long long -#define pb push_back -#define eb emplace_back -#define endl '\n' - -using namespace std; - -const int MOD = 1000000007; - -#ifdef KRISHNA -#include ""handle_debug.hpp"" -#define debug(...) \ - cout << '['; \ - debug_print(#_VA_ARGS, VA_ARGS_); \ - cout << ""]\n""; -#else -#define debug(...) -#endif - -ll gcd(ll a, ll b) -{ - while (b) - { - ll t = a % b; - a = b; - b = t; - } - return a; -} - -bool isPrime(ll n) -{ - if (n <= 1) - { - return false; - } - for (int i = 2; i <= sqrt(n); i++) - { - if (n % i == 0) - { - return false; - } - } - return true; -} - -int isSubstring(string s1, string s2) -{ - if (s2.find(s1) != string::npos) - return s2.find(s1); - return -1; -} - -ll fac(ll n) -{ - ll f = 1; - if (n == 0 || n == 1) - return 1; - else - { - for (ll i = 2; i <= n; i++) - { - f *= i; - } - return f; - } -} - -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vector vec(n,0); - for(int i=0; i>vec[i]; - } - int flag=1; - for (int i = 0; i < n-1; i++) - { - int k=min(vec[i], vec[i+1]); - vec[i]=vec[i]-k; - vec[i+1]=vec[i+1]-k; - - if(vec[i]>vec[i+1]){ - flag=0; - break; - } - } - - if(flag) cout<<""YES""< -#include -#include -#include - - -using namespace std; -using ll = long long; - -template -void cl(vector &vec,ll a,ll b){ - ll min_ = min(vec[a],vec[b]); - vec[a]-=min_; - vec[b]-=min_; -}; -template -void ret(vector &vec1){ - // checker for sorted - int is_sorted_ = 0; - for(ll j = 0; j < vec1.size(); ++j){ - - if(vec1[j]<=vec1[j + 1]){ - cl(vec1,j,j+1); - } - } - - cout << (is_sorted(ve.begin(), ve.end()) ? ""YES"" : ""NO"") << '\n'; -} - - - - -int main(){ - cin.tie(nullptr) -> sync_with_stdio(false); - ll n; - cin >> n; - - for(ll s = 0; s < n; s++){ - ll sn; - cin >> sn; - vector vec(sn); - for (ll &t : vec){ - cin >> t; - } - ret(vec); - - - } - return 0; - - -}","#include -#include -#include -#include - - -using namespace std; -using ll = long long; - -template -void cl(vector &vec,ll a,ll b){ - ll min_ = min(vec[a],vec[b]); - vec[a]-=min_; - vec[b]-=min_; -} -template -void ret(vector &vec1){ - // checker for sorted - - for(ll j = 0; j < vec1.size()-1; ++j){ - - if(vec1[j]<=vec1[j + 1]){ - cl(vec1,j,j+1); - } - } - - cout << (is_sorted(vec1.begin(), vec1.end()) ? ""YES"" : ""NO"") << '\n'; -} - - - - -int main(){ - cin.tie(nullptr) -> sync_with_stdio(false); - ll n; - cin >> n; - - for(ll s = 0; s < n; s++){ - ll sn; - cin >> sn; - vector vec(sn); - for (ll &t : vec){ - cin >> t; - } - ret(vec); - - - } - return 0; - - -}",2 -wings_of_demon#,2060D - Subtract Min Sort,c++17 ,303652223,303651564,"#include -#include // Common file -#include -#include // for less - -using namespace __gnu_pbds; -using namespace std; - -typedef long long ll; -typedef double long dl; -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; - -ll n,k; -string sa,sb; -vector a,p; -//vector> ca; -ll mod = 1e9 + 7; -ll fact[200005]; - -ll powN(ll x, ll y); -ll getNcR(ll n, ll r); -ll ansSparseQuery(vector>& sparseTable,int l, int r); -vector> getSparseTable(vector& arr); -void initFact(); -void initArr(vector& arr, ll n); - -map mp; - -bool solve() -{ - if(a[0] > a[1]) return false; - ll x = 0; - for(int i = 1; i>ts; - //initFact(); - while(ts--) - { - cin>>n; - initArr(a,n); - //cin>>sa; - //initArr(p,n-1); - //initArr(c,n); - cout<<(solve() ? ""YES\n"" : ""NO\n""); - - //cout<& arr, ll n){ - arr.clear(); - arr.resize(n); - for(int i=0;i>arr[i]; -} - -ll powN(ll x, ll y){ - ll res = 1; // Initialize result - - x = x % mod; // Update x if it is more than or - // equal to p - - if (x == 0) return 0; // In case x is divisible by p; - - while (y > 0) - { - // If y is odd, multiply x with result - if (y & 1) - res = (res*x) % mod; - - // y must be even now - y = y>>1; // y = y/2 - x = (x*x) % mod; - } - return res; -} - -ll getNcR(ll n, ll r) -{ - if(n < r) return 0; - return (fact[n] * powN((fact[n - r] * fact[r]) % mod, mod - 2)) % mod; -} - -ll ansSparseQuery(vector>& sparseTable,int l, int r) -{ - int j = log2(r-l+1); - - return __gcd(sparseTable[l][j], sparseTable[r - (1<> getSparseTable(vector& arr) -{ - ll n = arr.size(); - if(n == 0) return {{}}; - vector> sparseTable(n,vector(log2(n)+1)); - for(int i = 0; i -#include // Common file -#include -#include // for less - -using namespace __gnu_pbds; -using namespace std; - -typedef long long ll; -typedef double long dl; -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; - -ll n,k; -string sa,sb; -vector a,p; -//vector> ca; -ll mod = 1e9 + 7; -ll fact[200005]; - -ll powN(ll x, ll y); -ll getNcR(ll n, ll r); -ll ansSparseQuery(vector>& sparseTable,int l, int r); -vector> getSparseTable(vector& arr); -void initFact(); -void initArr(vector& arr, ll n); - -map mp; - -bool solve() -{ - if(a[0] > a[1]) return false; - ll x = 0; - for(int i = 2; i>ts; - //initFact(); - while(ts--) - { - cin>>n; - initArr(a,n); - //cin>>sa; - //initArr(p,n-1); - //initArr(c,n); - cout<<(solve() ? ""YES\n"" : ""NO\n""); - - //cout<& arr, ll n){ - arr.clear(); - arr.resize(n); - for(int i=0;i>arr[i]; -} - -ll powN(ll x, ll y){ - ll res = 1; // Initialize result - - x = x % mod; // Update x if it is more than or - // equal to p - - if (x == 0) return 0; // In case x is divisible by p; - - while (y > 0) - { - // If y is odd, multiply x with result - if (y & 1) - res = (res*x) % mod; - - // y must be even now - y = y>>1; // y = y/2 - x = (x*x) % mod; - } - return res; -} - -ll getNcR(ll n, ll r) -{ - if(n < r) return 0; - return (fact[n] * powN((fact[n - r] * fact[r]) % mod, mod - 2)) % mod; -} - -ll ansSparseQuery(vector>& sparseTable,int l, int r) -{ - int j = log2(r-l+1); - - return __gcd(sparseTable[l][j], sparseTable[r - (1<> getSparseTable(vector& arr) -{ - ll n = arr.size(); - if(n == 0) return {{}}; - vector> sparseTable(n,vector(log2(n)+1)); - for(int i = 0; i -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - long long t; - cin>>t; - while(t--){ - long long n,i,j; - cin>>n; - int arr[200005]; - for( i=0;i>arr[i]; - } - int x=0; - for( j=0;jarr[j+1]) x=1; - arr[j+1]-=arr[j]; - } - if(x==0) cout << ""YES\n""; - else cout<<""NO\n""; - } - return 0; -}","//~imran~ - -#include -using namespace std; - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vectorv(n); - for(int i=0;i>v[i]; - } - if (is_sorted(v.begin(), v.end())) { - cout << ""YES\n""; - continue; - } - int x=0,y=0; - for(int j=0;j -using namespace std; -typedef long long ll; - -void solve() { - ll n; - cin >> n; - vector a(n); - for(int i = 0; i < n; i++) cin >> a[i]; - for(int i = n - 2; i > 0; i--){ - ll d = min(a[i], a[i-1]); - if(d == 0) continue; - ll k = (abs(a[i+1] - a[i]) + d - 1) / d; - if(a[i] > a[i+1]){ - a[i] -= (k * d); - a[i-1] -= (k * d); - // cout << ""k""; - } - // cout << a[i] << "" ""; - } - bool ok = true; - for(int i = 1; i < n; i++){ - // cout << a[i] << "" ""; - if(a[i] < a[i-1]) ok = false; - } - if(ok) cout << ""YES\n""; - else cout << ""NO\n""; -} - -int32_t main() { - ios_base::sync_with_stdio(0); cin.tie(0); - int t = 1, st = clock(); - cin >> t; - while(t--){ - solve(); - } - // cerr << ""[Time : "" << 1000 * (clock() - st) / CLOCKS_PER_SEC << "" ms]\n""; - return 0; -}","#include -using namespace std; -typedef long long ll; - -void solve() { - ll n; - cin >> n; - vector a(n); - for(int i = 0; i < n; i++) cin >> a[i]; - for(int i = 0; i < n - 1; i++){ - ll d = min(a[i], a[i+1]); - a[i] -= d; - a[i+1] -= d; - } - bool ok = true; - for(int i = 1; i < n; i++){ - // cout << a[i] << "" ""; - if(a[i] < a[i-1]) ok = false; - } - if(ok) cout << ""YES\n""; - else cout << ""NO\n""; -} - -int32_t main() { - ios_base::sync_with_stdio(0); cin.tie(0); - int t = 1, st = clock(); - cin >> t; - while(t--){ - solve(); - } - // cerr << ""[Time : "" << 1000 * (clock() - st) / CLOCKS_PER_SEC << "" ms]\n""; - return 0; -}",2 -newplayer27,2060D - Subtract Min Sort,c++23 ,306794163,306796064,"// Bluntforces ;) - -#include -using namespace std; -#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -typedef long long int ll; - -void solve() { - int n; cin >>n; - vector a(n); - for(int i=0;i>a[i]; - } - for(int i=0;ia[i+1]){ - cout <<""NO""<=(n/2)-1) continue; - if(a[i] a[i+2]){ - cout <<""NO""<> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; -#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -typedef long long int ll; - -void solve() { - int n; - cin >> n; - deque a(n); - for(int i=0;i>a[i]; - } - - while(a.size()>1){ - if(a[0]>a[1]){ - cout <<""NO""<> t; - while (t--) { - solve(); - } - return 0; -} -",2 -Ni_Hao_a#,2060D - Subtract Min Sort,c++23 ,304657818,304658000,"/***************************************** -备注: -******************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -typedef unsigned long long ull; -#define int ll -const int MAXN = 2e6 + 10; -const int MR = 10 + 5; -const int INF = 0x3f3f3f3f; -const int MOD = 1e9 + 7; -const int _ = 0; -const bool debug = false; -#define check(x)cout << #x << "" === "" << x << endl; - -inline int read() -{ - int s = 0, f = 1; - char x = getchar(); - while(x < '0' || x > '9') - { - if(x == '-')f = -1; - x = getchar(); - } - while(x >= '0' && x <= '9') - { - s = s * 10 + x - '0'; - x = getchar(); - } - return s * f; -} - -void print(int x) -{ - printf(""%d"", &x); -} -int n, a[MAXN]; -void solve() -{ - cin >> n; - for(int i = 1; i <= n; i++)cin >> a[i]; - for(int i = 1; i < n; i++) - { - int x = min(a[i], a[i + 1]); - a[i] -= x, a[i + 1] -= x; - } - for(int i = 1; i <= n; i++)cout << a[i] << ' '; - puts(""""); - bool flag = true; - for(int i = n; i >= 2; i--) - { - if(a[i] < a[i - 1])flag = false; - } - if(flag)puts(""YES""); - else puts(""NO""); -} -signed main() -{ - // int start = clock(); - int T;cin >> T; - while(T--)solve(); - // printf(""%.3lf"", clock() - start); - return ~~(0^_^0); -}","/***************************************** -备注: -******************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -typedef unsigned long long ull; -#define int ll -const int MAXN = 2e6 + 10; -const int MR = 10 + 5; -const int INF = 0x3f3f3f3f; -const int MOD = 1e9 + 7; -const int _ = 0; -const bool debug = false; -#define check(x)cout << #x << "" === "" << x << endl; - -inline int read() -{ - int s = 0, f = 1; - char x = getchar(); - while(x < '0' || x > '9') - { - if(x == '-')f = -1; - x = getchar(); - } - while(x >= '0' && x <= '9') - { - s = s * 10 + x - '0'; - x = getchar(); - } - return s * f; -} - -void print(int x) -{ - printf(""%d"", &x); -} -int n, a[MAXN]; -void solve() -{ - cin >> n; - for(int i = 1; i <= n; i++)cin >> a[i]; - for(int i = 1; i < n; i++) - { - int x = min(a[i], a[i + 1]); - a[i] -= x, a[i + 1] -= x; - } - bool flag = true; - for(int i = n; i >= 2; i--) - { - if(a[i] < a[i - 1])flag = false; - } - if(flag)puts(""YES""); - else puts(""NO""); -} -signed main() -{ - // int start = clock(); - int T;cin >> T; - while(T--)solve(); - // printf(""%.3lf"", clock() - start); - return ~~(0^_^0); -}",2 -Dikshith_200,2060D - Subtract Min Sort,c++17 ,307412366,307418300,"#include -using namespace std; -typedef long long ll; - -int main() -{ - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - int a[n]; - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - - if (a[0] > a[1]) - { - cout << ""NO"" << ""\n""; - continue; - } - int flag = 0; - for (int i = 0; i < n; i += 2) - { - if (a[i] >= a[i + 1]) - { - flag = 1; - break; - } - } - - if (flag) - { - cout << ""NO"" << ""\n""; - } - else - { - cout << ""YES"" << ""\n""; - } - } -}","#include -using namespace std; -typedef long long ll; - -int main() -{ - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - int a[n + 1]; - for (int i = 1; i <= n; i++) - { - cin >> a[i]; - } - - int mini; - for (int i = 1; i < n; i++) - { - mini = min(a[i], a[i + 1]); - a[i] -= mini; - a[i + 1] -= mini; - } - int flag = 0; - - for (int i = 1; i < n; i++) - { - if (a[i] > a[i + 1]) - { - flag = 1; - break; - } - } - - if (flag) - { - cout << ""NO"" << ""\n""; - } - else - { - cout << ""YES"" << ""\n""; - } - } -}",2 -DarshOo_Shalan,2060D - Subtract Min Sort,c++20 ,302795622,302798860,"#include -using namespace std; -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> ordered_set; -// find_by_order, order_of_key -#define all(v) v.begin(), v.end() -#define ll long long -#define en cout << endl; -#define memo(arr, val) memset(arr, val, sizeof(arr)) -#define int long long -#define f first -#define s second -#define sz(s) (int)(s).size() -#define rep(i, st, ed) for (int i = st; i < ed; i++) - -bool valid(int i, int j, int n, int m) { - return i < n && i >= 0 && j < m && j >= 0; -} - -int inf = 1e18; - -void Sh3lan() { - ios::sync_with_stdio(0); - cin.tie(NULL); - cout.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""errors.txt"", ""w"", stderr); - -#endif -} - -int mod = 1e9 + 7; - -int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; } - -int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; } - -int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; } - -int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } - -int LCM(int a, int b) { return a / GCD(a, b) * b; } - -int fast(int a, int m) { - if (m == 0) return 1; - int x = fast(a, m / 2); - x = mul(x, x); - if (m & 1) x = mul(x, a); - return x % mod; -} - -int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; -int dy[] = {0, 0, 1, -1, 1, -1, -1, 1}; -const int N = 2e3 + 5; - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &i: a) cin >> i; - if (n == 2 && a[0] > a[1]) { - cout << ""NO"" << endl; - return; - } - bool ok = false; - for (int i = 1; i < n - 1; i++) { - if (a[i] > a[i + 1] && a[i] < a[i - 1]) { - ok = true; - } - } - if (ok) { - cout << ""NO"" << endl; - } else { - cout << ""YES"" << endl; - } -} - -signed main() { - Sh3lan(); - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include - -using namespace std; - -#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -#define ll long long -#define vii vector -#define vib vector -#define vil vector -#define vis vector -#define pp pair -#define all(d) d.begin(), d.end() -#define py cout << ""YES\n"" -#define pm cout << ""-1\n"" -#define pn cout << ""NO\n"" -#define setit(v, name) ::memset(name, v, sizeof(name)) -#define inf 1e5 -#define sz(v) ((int)(v.size())) -#define GRAPH vector> -#define ceill(a, b) (((a) + (b) - 1) / b) -#define tests ll t; cin >> t; while (t--) -const double EPS = 1e-9; -ll mod = 1073741824; -const double pi = 3.14159265358979323846; -const int dx8[8] = {1, 0, -1, 0, -1, -1, 1, 1}; -const int dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1}; -int dr[] = {+0, +0, +1, -1}; -int dc[] ={+1, -1, +0, +0}; -template -istream& operator>>(istream &istream, vector &v){for (auto &it : v)cin >> it;return istream;} - - - -void solve(){ - int n; - cin >> n ; - - vii arr(n + 1 , 0); - - for(int i =1 ;i <= n; i++){ - cin >> arr[i]; - } - - for(int i = 1 ; i < n; i++){ - if(arr[i + 1] < arr[i]){ - int mn = min(arr[i] , arr[i - 1]); - arr[i] -= mn; - arr[i - 1] -= mn; - - if(arr[i + 1] <= arr[i]){ - cout << ""NO\n""; - return ; - } - } - } - - cout << ""YES\n""; - return ; -} - -int main(){ - - fast - tests - solve(); -} - -",2 -bprk52524,2060D - Subtract Min Sort,c++23 ,303970084,303968149,"#include -using namespace std; -void solve(){ - int n; - cin>>n; - int arr[n]; - for(int i=0;i>arr[i]; - } - for(int i=1;iarr[i+1]){ - b++; - } - } - - if(b!=0){ - cout<<""NO""<>t; - while(t--){ - solve(); - } -}","#include -using namespace std; -void solve(){ - int n; - cin>>n; - int arr[n]; - for(int i=0;i>arr[i]; - } - if(arr[0]>=arr[1]){ - cout<<""NO""<>t; - while(t--){ - solve(); - } -}",1 -musadiq136,2060D - Subtract Min Sort,c++17 ,307315815,307316131,"#include -#include -#include - -#define vi vector -#define vll vector -#define ll long long - -using namespace std; -char ln = '\n'; - -void solve() -{ - int n ;cin >> n; - vi a(n); - for(int& i :a) - { - cin >> i; - } - for(int i = 0; i < n-1 ; i++) - { - if(a[i] > a[i+1] && i==0) - { - cout << ""No"" < a[i+1]) - { - cout << ""No"" <> t; - while(t--) solve(); -}","#include -#include -#include - -#define vi vector -#define vll vector -#define ll long long - -using namespace std; -char ln = '\n'; - -void solve() -{ - int n ;cin >> n; - vi a(n); - for(int& i :a) - { - cin >> i; - } - for(int i = 0; i < n-1 ; i++) - { - if(a[i] > a[i+1] && i==0) - { - cout << ""No"" < a[i+1]) - { - cout << ""No"" <> t; - while(t--) solve(); -}",2 -siddhi_singh,2060D - Subtract Min Sort,c++23 ,304010300,304010611,"#include -using namespace std; -#define ll long long -#define printarr(arr, n) for(int i=0; i>t; - while(t--) { - int n; - cin>>n; - vector arr(n); - for(int i=0; i>arr[i]; - } - int isnd=1; - for(int i=1; iarr[1]) isnd=0; - } - - if(isnd==1) ha - else na - - } -}","#include -using namespace std; -#define ll long long -#define printarr(arr, n) for(int i=0; i>t; - while(t--) { - int n; - cin>>n; - vector arr(n); - for(int i=0; i>arr[i]; - } - int isnd=1; - for(int i=1; iarr[1]) isnd=0; - } - - if(isnd==1) ha - else na - - } -}",2 -Adddd,2060D - Subtract Min Sort,c++23 ,309976330,309974384,"#include - -using namespace std; - -#define int long long - - - -void solve() - -{ - - int n;cin>>n; - - vector a(n); - - for(int i=0;i>a[i]; - - for(int i=1;ia[i]) - - { - - cout<<""NO""<>T; - - while(T--) solve(); - - return 0; - -}","#include - -using namespace std; - -#define int long long - - - -void solve() - -{ - - int n;cin>>n; - - vector a(n); - - for(int i=0;i>a[i]; - - for(int i=0;ia[i+1]&&a[i+1]>a[i+2]) - - { - - cout<<""NO""<>T; - - while(T--) solve(); - - return 0; - -}",1 -qarazhvn,2060D - Subtract Min Sort,c++17 ,303642980,303642213,"#include - -using namespace std; -int t, a[200009], n; - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - cin >> t; - - while(t--){ - cin >> n; - for(int i = 0; i < n; i++){ - cin >> a[i]; - } - for(int i = 0; i < n - 1; i++){ - int k = min(a[i], a[i + 1]); - a[i] -= k; - a[i + 1] -= k; - } - - cout << (is_sorted(a, a + n) ? ""YES\n"" : ""NO\n""); - } - - return 0; -}","#include - -using namespace std; - - -int main() { - int t; - cin >> t; - - while(t--){ - int n, p = 0; - int a[n]; - cin >> n; - - for(int i = 0; i < n; i++){ - cin >> a[i]; - } - - for(int i = 0; i < n - 1; i++){ - int k = min(a[i], a[i + 1]); - a[i] -= k; - a[i + 1] -= k; - } - - cout << (is_sorted(a, a + n) ? ""YES\n"" : ""NO\n""); - } - - return 0; -}",1 -lce4113#,2060D - Subtract Min Sort,c++17 ,304893606,304893802,"// Codeforces Round 998: Problem D - -#include -using namespace std; - -#define int long long -#define f first -#define s second - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) cin >> x; - if (a[0] > a[1]) { - cout << ""NO\n""; - return; - } - for (int i = 1; i < n; i++) { - if (a[i] > a[i - 1] && (i == 1 || a[i - 2] == 0)) { - a[i] -= a[i - 1], a[i - 1] = 0; - } - } - - // for (auto x : a) cout << x << ' '; - // cout << '\n'; - - for (int i = 1; i < n; i++) { - if (a[i] < a[i - 1]) { - cout << ""NO\n""; - return; - } - } - - cout << ""YES\n""; -} - -int32_t main() { - cin.tie(0)->sync_with_stdio(0); - int t = 1; - cin >> t; - while (t--) solve(); -}","// Codeforces Round 998: Problem D - -#include -using namespace std; - -#define int long long -#define f first -#define s second - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) cin >> x; - if (a[0] > a[1]) { - cout << ""NO\n""; - return; - } - for (int i = 1; i < n; i++) { - if (a[i] >= a[i - 1] && (i == 1 || a[i - 2] == 0)) { - a[i] -= a[i - 1], a[i - 1] = 0; - } - } - - // for (auto x : a) cout << x << ' '; - // cout << '\n'; - - for (int i = 1; i < n; i++) { - if (a[i] < a[i - 1]) { - cout << ""NO\n""; - return; - } - } - - cout << ""YES\n""; -} - -int32_t main() { - cin.tie(0)->sync_with_stdio(0); - int t = 1; - cin >> t; - while (t--) solve(); -}",2 -Zeeshan9173,2060D - Subtract Min Sort,c++23 ,309546805,309545778,"#include - -using namespace std; - - - -void minSub(int *arr, int i) - -{ - - int j = i; - - while (arr[j]>0 && j>0) - - { - - j--; - - } - - for (; j < i - 1; j++) - - { - - - - int mi = min(arr[j], arr[j + 1]); - - arr[j] = arr[j] - mi; - - arr[j + 1] = arr[j + 1] - mi; - - } - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cout.tie(NULL); - - cin.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - { - - int n, i; - - cin >> n; - - - - int arr[n]; - - - - for (int j = 0; j < n; j++) - - { - - cin >> arr[j]; - - } - - bool isPossible = true; - - for (i = 0; i < n - 1; i++) - - { - - if(arr[i] > arr[i + 1]) - - { - - minSub(arr, i + 1); - - if (arr[i] > arr[i + 1]) - - { - - isPossible = false; - - break; - - } - - } - - } - - if (isPossible) - - { - - cout<< ""YES""< - -using namespace std; - - - -void minSub(int *arr, int i) - -{ - - for (int j = 0; j < i - 1; j++) - - { - - if (arr[j]>0 && arr[j + 1]> 0 ) - - { - - int mi = min(arr[j], arr[j + 1]); - - arr[j] = arr[j] - mi; - - arr[j + 1] = arr[j + 1] - mi; - - } - - } - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cout.tie(NULL); - - cin.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - { - - int n, i; - - cin >> n; - - - - int arr[n]; - - - - for (int j = 0; j < n; j++) - - { - - cin >> arr[j]; - - } - - bool isPossible = true; - - for (i = 0; i < n - 1; i++) - - { - - if(arr[i] > arr[i + 1]) - - { - - minSub(arr, i + 1); - - if (arr[i] > arr[i + 1]) - - { - - isPossible = false; - - break; - - } - - } - - } - - if (isPossible) - - { - - cout<< ""YES""< -using namespace std; -#define int long long - - -signed main() { - ios::sync_with_stdio(false); cin.tie(0); - - int tt; cin >> tt; - while(tt--){ - int n; cin >> n; - vector a (n); - for(int i = 0; i < n; i++) cin >> a[i]; - string ans = ""YES\n""; - for(int i = 1; i < n; i += 2){ - if(a[i] < a[i - 1]){ - ans = ""NO\n""; - break; - } - } - if(n % 2){ - if(a[n - 1] < a[n - 2] - a[n - 3]) ans = ""NO\n""; - } - cout << ans; - } - - - - return 0; -} -","#include -using namespace std; -#define int long long - - -signed main() { - ios::sync_with_stdio(false); cin.tie(0); - - int tt; cin >> tt; - while(tt--){ - int n; cin >> n; - vector a (n); - for(int i = 0; i < n; i++) cin >> a[i]; - for(int i = 1; i < n; i++){ - int mn = min(a[i] , a[i - 1]); - a[i] -= mn; - a[i - 1] -= mn; - } - - if(is_sorted(a.begin() , a.end())) cout << ""YES\n""; - else cout << ""NO\n""; - } - - return 0; -} -",2 -AY_ayman00,2060D - Subtract Min Sort,c++23 ,309004018,309003963,"#include - -#include - -#include - -using namespace std; - - - -int main(){ - - int t; cin >> t; - - - - while(t--){ - - int n; cin >> n; - - int arr[n+1]; arr[0]=0; - - string answer = ""YES""; - - for(int i = 1; i <= n; i++) cin >> arr[i]; - - for(int i = 2; i <= n; i++){ - - if(arr[i] < abs(arr[i-1] - arr[i-2])) { - - answer = ""NO""; break; - - } else arr[i-1] = abs(arr[i-1] - arr[i-2]); - - } - - - - cout << answer << ""\n""; - - - - - - } - -}","#include - -#include - -#include - -using namespace std; - - - -int main(){ - - int t; cin >> t; - - - - while(t--){ - - int n; cin >> n; - - int arr[n+1]; arr[0]=0; - - string answer = ""YES""; - - for(int i = 1; i <= n; i++) cin >> arr[i]; - - for(int i = 2; i <= n; i++){ - - if(arr[i] < abs(arr[i-1] - arr[i-2])) { - - arr[i-1] = abs(arr[i-1] - arr[i-2]); - - answer = ""NO""; break; - - } - - } - - - - cout << answer << ""\n""; - - - - - - } - -}",1 -akamikado,2060D - Subtract Min Sort,python,304388294,304386323,"for _ in range(int(input())): - n = int(input()) - a = list(map(int, input().split())) - - for i in range(n-1): - temp = min(a[i], a[i+1]) - a[i] -= temp - a[i+1] -= temp - - possible = True - for i in range(n-1): - if a[i] > a[i+1]: - possible = False - break - - if possible: - print(""YES"") - else: - print(""NO"") -","for _ in range(int(input())): - n = int(input()) - a = list(map(int, input().split())) - - possible = True - for i in range(n-1): - if a[i] - a[i + 1] > 0 and i % 2 == 0: - possible = False - break - - if possible: - print(""YES"") - else: - print(""NO"") -",1 -Exceptional_handling18,2060D - Subtract Min Sort,c++20 ,304007366,304002280,"#include -#define no ""NO"" -#define nl ""\n"" -#define yes ""YES"" -#define pb push_back -#define ll long long int -#define all(a) sort(a.begin(),a.end()) -#define allr(a) sort(a.rbegin(),a.rend()) -#define rev(a) reverse(a.begin(),a.end()) -#define Code_By_exception ios::sync_with_stdio(false); cin.tie(0); -using namespace std; - -void solution() -{ - ll n,tmp; - cin>>n; - vectorv(n); - for(ll i=0;i>v[i]; - for(ll i=0;iv[i+1]){ - cout<>tc; - while(tc--) - { - solution(); - } - return 0; -} -","#include -#define no ""NO"" -#define nl ""\n"" -#define yes ""YES"" -#define pb push_back -#define ll long long int -#define all(a) sort(a.begin(),a.end()) -#define allr(a) sort(a.rbegin(),a.rend()) -#define rev(a) reverse(a.begin(),a.end()) -#define Code_By_exception ios::sync_with_stdio(false); cin.tie(0); -using namespace std; - -void solution() -{ - int n; - cin>>n; - vectorv(n); - for(ll i=0;i>v[i]; - int x=0; - for(int i=1;i=v[i]) - x++; - } - if(x==(n-1)){cout<>tc; - while(tc--) - { - solution(); - } - return 0; -} -",1 -hardikr249,2060D - Subtract Min Sort,java,303381863,303382063,"import java.util.*; - -public class bit { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int t = sc.nextInt(); - while (t-- > 0) { - int n = sc.nextInt(); - int arr[] = new int[n]; - for(int i=0;iarr[1]){ - System.out.println(""NO""); - continue; - } - for(int i=0;iarr[i+1]){ - System.out.println(i); - ans = ""NO""; - break; - }else{ - arr[i+1]-=arr[i]; - arr[i]-=arr[i]; - } - } - System.out.println(ans); - - } - } -} - - -","import java.util.*; - -public class bit { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int t = sc.nextInt(); - while (t-- > 0) { - int n = sc.nextInt(); - int arr[] = new int[n]; - for(int i=0;iarr[1]){ - System.out.println(""NO""); - continue; - } - for(int i=0;iarr[i+1]){ - ans = ""NO""; - break; - }else{ - arr[i+1]-=arr[i]; - arr[i]-=arr[i]; - } - } - System.out.println(ans); - - } - } -} - - -",2 -pR67,2060D - Subtract Min Sort,c++17 ,302873569,302873191,"#include -using namespace std; - -void sub(){ - int n; - cin >> n; - - vector arr(n); - for(int i = 0; i < n; i++){ - cin >> arr[i]; - } - - // Try to make the array non-decreasing using the subtraction operation - for(int i = 0; i < n - 1; i++){ - int diff = min(arr[i], arr[i + 1]); - arr[i] -= diff; - arr[i + 1] -= diff; - } - - // Check if the array is now sorted in non-decreasing order - for(int i = 0; i < n - 1; i++){ - if(arr[i] > arr[i + 1]){ - cout << ""No"" << endl; - return; - } - } - - cout << ""Yes"" << endl; -} - -int main(){ - int t; - cin >> t; - - while(t--){ - sub(); - } - - return 0; -}","#include -using namespace std; - -void sub(){ - int n; - cin >> n; - - vector arr(n); - for(int i = 0; i < n; i++){ - cin >> arr[i]; - } - - // Try to make the array non-decreasing using the subtraction operation - for(int i = 0; i < n - 1; i++){ - int diff = min(arr[i], arr[i + 1]); - arr[i] -= diff; - arr[i + 1] -= diff; - } - - // Check if the array is now sorted in non-decreasing order - for(int i = 0; i < n - 1; i++){ - if(arr[i] > arr[i + 1]){ - cout << ""No"" << endl; - return; - } - } - - cout << ""Yes"" << endl; -} - -int main(){ - int t; - cin >> t; - - while(t--){ - sub(); - } - - return 0; -}",1 -johyy,2060D - Subtract Min Sort,c++20 ,315969758,315983319,"#include - - - -using namespace std; - - - -void noTimeLimit() - -{ - -cin.tie(0); - -cin.sync_with_stdio(0); - -cout.tie(0); - -cout.sync_with_stdio(0); - -} - -#define ll long long - -#define ss string - -#define dd double - -#define yes ""YES"" - -#define v vector - - - -#define no ""NO"" - -#define el ""\n"" - -#define fr(x, i, n) for (ll i = x; i < n; i++) - -#define frr(i, n) for (ll i = n - 1; i >= 0; i--) - -#define all(a) a.begin(), a.end() - -#define allr(a) a.rbegin(), a.rend() - -#define pi 3.141592653589793238462643383279502884197 - -#define ee 2.718281828459045 - -const ll mod = 1e9 + 7; - -int inf = 1e9; - - - -void solve() - -{ - -int n; - -cin >> n; - -vector a(n); - -fr(0, i, n) cin >> a[i]; - -bool f = 1; - -if (a[0] == *max_element(all(a))) - -return void(cout << no); - -fr(1, i, n - 1) - -{ - -if ((a[i] > a[i + 1] and a[i] < a[i - 1]) or (a[i] > a[i + 1] and a[i] - a[i + 1] > a[i - 1]) or (a[i] > a[i - 1] and a[i] - a[i - 1] > a[i + 1])) - -f = 0; - -} - -if (f) - -cout << yes; - -else - -cout << no; - -} - - - -int main() - -{ - -// freopen(""input.txt"", ""r"", stdin); - -// freopen(""output.txt"", ""w"", stdout); - -noTimeLimit(); - -int testCase = 1; - -cin >> testCase; - -while (testCase--) - -{ - -solve(); - -cout << el; - -} - -return 0; - -}","#include - - - -using namespace std; - - - -void noTimeLimit() - -{ - -cin.tie(0); - -cin.sync_with_stdio(0); - -cout.tie(0); - -cout.sync_with_stdio(0); - -} - -#define ll long long - -#define ss string - -#define dd double - -#define yes ""YES"" - -#define v vector - - - -#define no ""NO"" - -#define el ""\n"" - -#define fr(x, i, n) for (ll i = x; i < n; i++) - -#define frr(i, n) for (ll i = n - 1; i >= 0; i--) - -#define all(a) a.begin(), a.end() - -#define allr(a) a.rbegin(), a.rend() - -#define pi 3.141592653589793238462643383279502884197 - -#define ee 2.718281828459045 - -const ll mod = 1e9 + 7; - -int inf = 1e9; - - - -void solve() - -{ - -int n; - -cin >> n; - -vector a(n); - -fr(0, i, n) cin >> a[i]; - -fr(1, i, n) - -{ - -int minn = min(a[i], a[i - 1]); - -a[i] -= minn, a[i - 1] -= minn; - -} - -bool f = 1; - -fr(0, i, n - 1) - -{ - -if (a[i] > a[i + 1]) - -f = 0; - -} - -if (f) - -cout << yes; - -else - -cout << no; - -} - - - -int main() - -{ - -// freopen(""input.txt"", ""r"", stdin); - -// freopen(""output.txt"", ""w"", stdout); - -noTimeLimit(); - -int testCase = 1; - -cin >> testCase; - -while (testCase--) - -{ - -solve(); - -cout << el; - -} - -return 0; - -}",2 -Satyam_yadav,2060D - Subtract Min Sort,c++17 ,312698887,312736845,"#include - -#define ll long long - -#define mod 1000000007 - -using namespace std; - - - -int main() { - -#ifndef ONLINE_JUDGE - -freopen(""input.txt"", ""r"", stdin); - -freopen(""output.txt"", ""w"", stdout); - -#endif - -// your code goes here - -int t; - -cin>>t; - -while(t--){ - -int n; - -cin>>n; - -vectorv(n); - -for(int i=0; i>v[i]; - -} - -if(v[0]>=v[1]){ - -cout<<""YES""< - -#define ll long long - -#define mod 1000000007 - -using namespace std; - - - -int main() { - -#ifndef ONLINE_JUDGE - -freopen(""input.txt"", ""r"", stdin); - -freopen(""output.txt"", ""w"", stdout); - -#endif - -// your code goes here - -int t; - -cin>>t; - -while(t--){ - -int n; - -cin>>n; - -vectorv(n); - -for(int i=0; i>v[i]; - -} - -if(v[0]>v[1]){ - -cout<<""NO""<v[i+1]){ - -flag=false; - -break; - -}else{ - -v[i+1]-=v[i]; - -} - -} - -if(flag){ - -cout<<""YES""< -#include -#include -#include -#include ""algorithm"" - -using namespace std; - -#define int long long - - -void solve() { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - for (int i = 1; i < n; ++i) { - if (a[i - 1] > a[i]) { - cout << ""nO\n""; - return; - } - int t = min(a[i], a[i - 1]); - a[i - 1] -= t; - a[i] -= t; - } - cout << ""YeS\n""; -} - - - - -signed main() { - int t; - cin >> t; - while (t--) { - solve(); - } -}","#include -#include -#include -#include -#include ""algorithm"" - -using namespace std; - -#define int long long - - -void solve() { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - if (a[n - 2] > a[n - 1] && a[1] > a[2]) { - cout << ""nO\n""; - } else { - cout << ""yEs\n""; - } -} - - - - -signed main() { - int t; - cin >> t; - while (t--) { - solve(); - } -}",1 -Hadi_hh,2060D - Subtract Min Sort,c++23 ,308635241,308634799,"#include - -#include - -#include - -typedef long long ll; - -const ll INF = 1e18; - -const int P = 1e9 + 7; - -const ll N = 1e12; - -std::unordered_set cubes; - -templateT min(const std::vector&v) { - - return *min_element(v.begin(),v.end()); - -} - -templateT max(const std::vector&v) { - - return *max_element(v.begin(),v.end()); - -} - -templateT sum(const std::vector&v) { - - return accumulate(v.begin(),v.end(),T(0)); - -} - -#define f(i,a,b) for(ll i = a;i < b;i++) - -#define frev(i,a,b) for(ll i = a;i >= b;i--) - -#define input(a) for(auto &x:a) std::cin>>x - -typedef std::vector ve; - -void run_case() { - - ll n; - - std::cin >> n; - - ll list[n]; - - for(int i =0; i < n; i++){ - - std::cin >> list[i]; - - } - - for(int i =0; i < n-1; i++){ - - if(list[i] <= list[i+1]){ - - list[i+1]-=list[i]; - - list[i]=0; - - } - - } - - /*for(int i =0; i < n; i++){ - - std::cout << list[i] << "" ""; - - } - - std::cout << ""\n"";*/ - - for(int i =0; i < n-1; i++){ - - if(list[i]>list[i+1]){ - - std::cout << ""NO\n""; - - return; - - } - - } - - std::cout << ""YES\n""; - -} - -int main() { - - std::ios::sync_with_stdio(false); - - std::cin.tie(nullptr); - - std::cout.tie(nullptr); - - ll t; - - //t = 1; - - std::cin >> t; - - while(t--) { - - run_case(); - - } - -}","#include - -#include - -#include - -typedef long long ll; - -const ll INF = 1e18; - -const int P = 1e9 + 7; - -const ll N = 1e12; - -std::unordered_set cubes; - -templateT min(const std::vector&v) { - - return *min_element(v.begin(),v.end()); - -} - -templateT max(const std::vector&v) { - - return *max_element(v.begin(),v.end()); - -} - -templateT sum(const std::vector&v) { - - return accumulate(v.begin(),v.end(),T(0)); - -} - -#define f(i,a,b) for(ll i = a;i < b;i++) - -#define frev(i,a,b) for(ll i = a;i >= b;i--) - -#define input(a) for(auto &x:a) std::cin>>x - -typedef std::vector ve; - -void run_case() { - - ll n; - - std::cin >> n; - - ll list[n]; - - for(int i =0; i < n; i++){ - - std::cin >> list[i]; - - } - - for(int i =0; i < n-1; i++){ - - if(list[i] < list[i+1]){ - - list[i+1]-=list[i]; - - list[i]=0; - - - - //std::cout << list[i] << "" "" << list[i+1] << ""\n""; - - } - - } - - for(int i =0; i < n-1; i++){ - - if(list[i]>list[i+1]){ - - std::cout << ""NO\n""; - - return; - - } - - } - - std::cout << ""YES\n""; - -} - -int main() { - - std::ios::sync_with_stdio(false); - - std::cin.tie(nullptr); - - std::cout.tie(nullptr); - - ll t; - - //t = 1; - - std::cin >> t; - - while(t--) { - - run_case(); - - } - -}",1 -professor_kumar,2060D - Subtract Min Sort,c++20 ,307280002,307278567,"// Problem: D. Subtract Min Sort -// Contest: Codeforces - Codeforces Round 998 (Div. 3) -// URL: https://codeforces.com/problemset/problem/2060/D -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -#include -#include - -using namespace std; - -#define int long long -// #define ll long long -#define ld long double -#define lld long long double - -///////////////////////////////////////////////////////////////////////////////////// - -#define debug(x) \ - cout << #x << "" ""; \ - _print(x); \ - cout << en; - -void _print(int x) { cout << x; } - -void _print(char x) { cout << x; } - -void _print(string s) { cout << s; } - -void _print(bool a) { cout << a; } - -template -void _print(pair p); -template -void _print(vector v); -template -void _print(set v); -template -void _print(map v); -template -void _print(multiset v); -template -void _print(pair p) { - cout << ""{""; - _print(p.first); - cout << "",""; - _print(p.second); - cout << ""}""; -} -template -void _print(vector v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(set st) { - cout << ""[ ""; - for (T i : st) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(multiset v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(map v) { - cout << ""[ ""; - for (auto i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -/////////////////////////////////////////////////////////////////// - -// #define int long long -// #define ld long double -// #define lld long long double -#define ff first -#define ss second -#define yes cout << ""YES"" -#define no cout << ""NO"" -#define fl(i, a, b) for (int i = a; i < b; i++) -#define rep(i, a, b) for (int i = a; i <= b; i++) -#define pii pair -#define vi vector -#define vvi vector> -#define vs vector -#define vpii vector> -#define mii map -#define pb push_back -#define ppb push_back -#define div(a, b) (a) / (b) -#define all(x) (x).begin(), (x).end() -#define allr(x) (x).rbegin(), (x).rend() -#define ceil(a, b) (a + b - 1) / b -#define input(a, n) fl(i, 1, n) cin >> a[i] -#define intake(a, n) \ - int n; \ - cin >> n; \ - vector a(n); \ - for (int i = 0; i < n; i++) cin >> a[i] -#define intake2(a, n, k) \ - int n, k; \ - cin >> n >> k; \ - vector a(n); \ - for (int i = 0; i < n; i++) cin >> a[i] -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define pq priority_queue -#define out(a) \ - for (int i = 0; i < a.size(); i++) cout << a[i] << "" ""; \ - cout << ""\n"" -#define en ""\n"" -// #define sp <<"" "" -#define sorti(a) sort(a.begin(), a.end()) -#define sortd(a) sort(a.rbegin(), a.rend()) -#define get_sum(a) accumulate(a.begin(), a.end(), 0LL) -#define get_max(a) *max_element(a.begin(), a.end()) -#define get_min(a) *min_element(a.begin(), a.end()) -#define get_max_pos(v) max_element(v.begin(), v.end()) - v.begin() -#define get_min_pos(v) min_element(v.begin(), v.end()) - v.begin() -#define sz(x) ((int)(x).size()) -#define setbits(x) __builtin_popcountll(x) -const int modd = 1000000007; -const ld eps = 1e-6, pi = 3.14159265358979323846264338327950; - -int gcd(int a, int b) { return __gcd(a, b); } - -int binexpo(int a, int b, int mod) { - int res = 1; - while (b > 0) { - if (b & 1) res = (res * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return res; -} - -int Find_gcd_Extended(int a, int b, int* x, int* y) { - // Base Case - if (a == 0) { - *x = 0, *y = 1; - return b; - } - - // Storing results of recursive call - int x1, y1; - int gcd = Find_gcd_Extended(b % a, a, &x1, &y1); - - /* - After recursive call, update the values - of x and y - */ - *x = y1 - (b / a) * x1; - *y = x1; - - return gcd; -} - -int modinv(int a, int m) { - int x, y; - int g = Find_gcd_Extended(a, m, &x, &y); - - /* - If the gcd value doesn't matches - to 1, then inverse doesn't exist - */ - if (g != 1) { - return -1; - // cout << ""sdf""; - } else { - /* - m is added once more to handle - negative values - */ - int res = (x % m + m) % m; - // cout< isPrime(1000001); -void sieve() { - for (int i = 0; i <= 1000001; i++) { - isPrime[i] = 1; - } - isPrime[0] = isPrime[1] = 0; - - for (int i = 2; i * i <= 1000000; i++) { - if (isPrime[i] == true) { - for (int j = i * i; j <= 1000000; j += i) { - isPrime[j] = false; - } - } - } -} - -//-----spf------ -// SPF[i] => smallest prime number that divides i - -vector spf(1000001); -void findspf() { - for (int i = 0; i <= 1e6; i++) { - spf[i] = i; - } - - for (int i = 2; i * i <= 1e6; i++) { - if (spf[i] == i) { - for (int j = i * i; j <= 1e6; j += i) { - if (spf[j] == j) { - spf[j] = i; - } - } - } - } -} - -int madd(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a + b) % m + m) % m); -} - -int mmul(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a * b) % m + m) % m); -} - -int msub(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a - b) % m + m) % m); -} - -int mdiv(int a, int b, int m) { - a = a % m; - b = b % m; - return ((mmul(a, modinv(b, m), m) + m) % m); -} - -// string hashing - -pair mod = {1e9 + 7, 1e9 + 9}; -vector> pref_hash; -vector> power_pref; -void createHashfn(int n, string& s) { - pref_hash.resize(n); - power_pref.resize(n); - pref_hash[0] = {s[0] - 'a' + 1, s[0] - 'a' + 1}; - power_pref[0] = {1, 1}; - for (int i = 1; i < n; i++) { - pref_hash[i].first = - (pref_hash[i - 1].first * (int)31 + (s[i] - 'a' + 1)) % mod.first; - pref_hash[i].second = - (pref_hash[i - 1].second * (int)53 + (s[i] - 'a' + 1)) % mod.second; - - power_pref[i].first = (power_pref[i - 1].first * (int)31) % mod.first; - power_pref[i].second = (power_pref[i - 1].second * (int)53) % mod.second; - } -} - -auto subhash(int l, int r, string& s) { - if (l == 0) return pref_hash[r]; - - pair sub_hash; - sub_hash.first = ((pref_hash[r].first - (int)pref_hash[l - 1].first * - power_pref[r - l + 1].first) % - mod.first); - if (sub_hash.first < 0) sub_hash.first += mod.first; - - sub_hash.second = ((pref_hash[r].second - (int)pref_hash[l - 1].second * - power_pref[r - l + 1].second) % - mod.second); - if (sub_hash.second < 0) sub_hash.second += mod.second; - return sub_hash; -} - -////////////////// DSU 1 BASED INDEXING ///////////////////////////// -vector par(2e5 + 1); -vector rnk(2e5 + 1); -// intrnk[1e5]; - -void make_set(int n) { - for (int i = 1; i < n + 1; i++) { - par[i] = i; - rnk[i] = 1; - } -} - -int find_set(int x) { - if (par[x] == x) { - return x; - } - - par[x] = find_set(par[x]); - - return par[x]; -} - -void union_set(int a, int b) { - int p1 = find_set(a); - int p2 = find_set(b); - - if (p1 == p2) { - return; - } - - if (rnk[p1] > rnk[p2]) { - par[p2] = p1; - rnk[p1] = rnk[p1] + rnk[p2]; - } else { - par[p1] = p2; - rnk[p2] = rnk[p2] + rnk[p1]; - } -} -////////////////////DSU 1 BASED -/// INDEXING////////////////////////////////////////////////// - -// x|(1< input -const int MOD = 998244353; -void add(int& a, int b) { - a += b; - if (a >= MOD) a -= MOD; -} - -int sum(int a, int b) { - a += b; - if (a >= MOD) a -= MOD; - if (a < 0) a += MOD; - return a; -} - -int mul(int a, int b) { return (a * 1LL * b) % MOD; } - -const int N = 2000005; -// const int mod = 1e9 + 7; -int fact[N], invfact[N]; - -void precompute() { - fact[0] = fact[1] = 1; - for (int i = 2; i < N; i++) { - fact[i] = fact[i - 1] * i; - fact[i] %= modd; - } - - invfact[N - 1] = modinv(fact[N - 1], modd); - for (int i = N - 2; i >= 0; i--) { - invfact[i] = invfact[i + 1] * (i + 1); - invfact[i] %= modd; - } -} - -int nCr(int x, int y) { - if (y > x) return 0; - int num = fact[x]; - num *= invfact[y]; - num %= modd; - num *= invfact[x - y]; - num %= modd; - return num; -} - -vi binRep(int x) { - vi v(32); - for (int i = 29; i >= 0; i--) { - v[i] = (x >= (1 << i)); - x %= (1 << i); - } - return v; -} - -// RADHE RADHE - -// vvi tree; -// vi vis, parent, depth; - -//---------- max seg code ---- 0based indexing--------------// - -const int MAXMAX = 2e5; // Max size of array -int treemax[2 * MAXMAX]; - -// Function to build the tree -void buildmax(vector& arr, int n) { - for (int i = 0; i < n; i++) treemax[n + i] = arr[i]; - for (int i = n - 1; i > 0; --i) - treemax[i] = max(treemax[i << 1], treemax[i << 1 | 1]); -} - -// Function to update a tree node -void updatemax(int p, int value, int n) { - treemax[p + n] = value; - p = p + n; - for (int i = p; i > 1; i >>= 1) - treemax[i >> 1] = max(treemax[i], treemax[i ^ 1]); -} - -// Function to get minimum value in a given range -// [l,r) -int querymax(int l, int r, int n) { - int res = -1e18; - for (l += n, r += n; l < r; l >>= 1, r >>= 1) { - if (l & 1) res = max(res, treemax[l++]); - if (r & 1) res = max(res, treemax[--r]); - } - return res; -} - -// array mein value ko dalne ke liye update ko call karna - -//---------- max seg code ---- 0based indexing--------------//-------------// -//---------- min seg code ---- 0based indexing--------------// - -const int MAXMIN = 2e5; // Max size of array -int treemin[2 * MAXMIN]; - -// Function to build the tree -void buildmin(vector& arr, int n) { - for (int i = 0; i < n; i++) treemin[n + i] = arr[i]; - for (int i = n - 1; i > 0; --i) - treemin[i] = min(treemin[i << 1], treemin[i << 1 | 1]); -} - -// Function to update a tree node -void updatemin(int p, int value, int n) { - treemin[p + n] = value; - p = p + n; - for (int i = p; i > 1; i >>= 1) - treemin[i >> 1] = min(treemin[i], treemin[i ^ 1]); -} - -// Function to get minimum value in a given range -// [l,r) -int querymin(int l, int r, int n) { - int res = 1e18; - for (l += n, r += n; l < r; l >>= 1, r >>= 1) { - if (l & 1) res = min(res, treemin[l++]); - if (r & 1) res = min(res, treemin[--r]); - } - return res; -} - -// array mein value ko dalne ke liye update ko call karna -//////////////////////////////////////////// -//---------- min seg code ---- 0based indexing--------------//-------------// -/////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -///////////////////////////BINARY INDEX TREE///////////////////////////////// -////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -//////////////////////BINARY INDEX TREE////////////////////////////// -/////////////////////////////////////////////////////////////////////////// - -// point update range min/max => seg tree -// point update range sum ==> Binary index tree - -// for static -// range min/max/gcd/lcm/or/and ==> sparse table , query in O(1) -// range sum/xor ==> prefix sum - -// range update , set ; range min/max/sum = lazy - -// sparsetable code - -// int n; -// cin >> n; -// -// vi a(n); -// fl(i, 0, n) cin >> a[i]; -// -// int maxk = 25; -// int st[n + 1][maxk + 1]; -// -// for (int i = 0; i < n; i++) { -// st[i][0] = a[i]; -// } -// -// for (int k = 1; k <= maxk; k++) { -// for (int i = 0; i + (1 << k) <= n; i++) { -// st[i][k] = (st[i][k - 1] & st[i + (1 << (k - 1))][k - 1]); -// } -// } -// -// for (int i = 0; i < n; i++) { -// for (int j = 0; j < 4; j++) { -// cout << st[i][j] << "" ""; -// } -// cout << endl; -// } -// -// int l, r; -// cin >> l >> r; -// // int s = 0; -// // for (int k = maxk; k >= 0; k--) { -// // if ((1 << k) <= r - l + 1) { -// // s += st[l][k]; -// // l += (1 << k); -// // } -// // } -// // cout << s; -// -// vi lg(n + 1); -// lg[1] = 0; -// for (int i = 2; i <= n; i++) { -// lg[i] = lg[i / 2] + 1; -// } -// -// int w = lg[r - l + 1]; -// int ans = (st[l][w] & st[r - (1 << w) + 1][w]); -// cout << ans; - -// sparsetable code - -void solve() { - int n; - cin >> n; - vi v(n); - fl(i, 0, n) cin >> v[i]; - - for (int i = 0; i < n - 1; i++) { - int x = v[i]; - int y = v[i + 1]; - v[i] -= min(x, y); - v[i + 1] -= min(x, y); - // debug(v); - } - // debug(v); - int f = 0; - fl(i, 0, n - 1) { - if (v[i] > 0) f = 1; - } - // debug(f); - if (f) { - cout << ""NO""; - } else { - cout << ""YES""; - } -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - // // ----Atcode---- - // int q = 1; - // // ----Atcode---- - // -----cf/cc---- - int q; - cin >> q; - //-----cf/cc---- - - precompute(); - while (q--) { - solve(); - cout << en; - } - return 0; -} -","// Problem: D. Subtract Min Sort -// Contest: Codeforces - Codeforces Round 998 (Div. 3) -// URL: https://codeforces.com/problemset/problem/2060/D -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -#include -#include - -using namespace std; - -#define int long long -// #define ll long long -#define ld long double -#define lld long long double - -///////////////////////////////////////////////////////////////////////////////////// - -#define debug(x) \ - cout << #x << "" ""; \ - _print(x); \ - cout << en; - -void _print(int x) { cout << x; } - -void _print(char x) { cout << x; } - -void _print(string s) { cout << s; } - -void _print(bool a) { cout << a; } - -template -void _print(pair p); -template -void _print(vector v); -template -void _print(set v); -template -void _print(map v); -template -void _print(multiset v); -template -void _print(pair p) { - cout << ""{""; - _print(p.first); - cout << "",""; - _print(p.second); - cout << ""}""; -} -template -void _print(vector v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(set st) { - cout << ""[ ""; - for (T i : st) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(multiset v) { - cout << ""[ ""; - for (T i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -template -void _print(map v) { - cout << ""[ ""; - for (auto i : v) { - _print(i); - cout << "" ""; - } - cout << ""]""; -} - -/////////////////////////////////////////////////////////////////// - -// #define int long long -// #define ld long double -// #define lld long long double -#define ff first -#define ss second -#define yes cout << ""YES"" -#define no cout << ""NO"" -#define fl(i, a, b) for (int i = a; i < b; i++) -#define rep(i, a, b) for (int i = a; i <= b; i++) -#define pii pair -#define vi vector -#define vvi vector> -#define vs vector -#define vpii vector> -#define mii map -#define pb push_back -#define ppb push_back -#define div(a, b) (a) / (b) -#define all(x) (x).begin(), (x).end() -#define allr(x) (x).rbegin(), (x).rend() -#define ceil(a, b) (a + b - 1) / b -#define input(a, n) fl(i, 1, n) cin >> a[i] -#define intake(a, n) \ - int n; \ - cin >> n; \ - vector a(n); \ - for (int i = 0; i < n; i++) cin >> a[i] -#define intake2(a, n, k) \ - int n, k; \ - cin >> n >> k; \ - vector a(n); \ - for (int i = 0; i < n; i++) cin >> a[i] -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define pq priority_queue -#define out(a) \ - for (int i = 0; i < a.size(); i++) cout << a[i] << "" ""; \ - cout << ""\n"" -#define en ""\n"" -// #define sp <<"" "" -#define sorti(a) sort(a.begin(), a.end()) -#define sortd(a) sort(a.rbegin(), a.rend()) -#define get_sum(a) accumulate(a.begin(), a.end(), 0LL) -#define get_max(a) *max_element(a.begin(), a.end()) -#define get_min(a) *min_element(a.begin(), a.end()) -#define get_max_pos(v) max_element(v.begin(), v.end()) - v.begin() -#define get_min_pos(v) min_element(v.begin(), v.end()) - v.begin() -#define sz(x) ((int)(x).size()) -#define setbits(x) __builtin_popcountll(x) -const int modd = 1000000007; -const ld eps = 1e-6, pi = 3.14159265358979323846264338327950; - -int gcd(int a, int b) { return __gcd(a, b); } - -int binexpo(int a, int b, int mod) { - int res = 1; - while (b > 0) { - if (b & 1) res = (res * a) % mod; - a = (a * a) % mod; - b = b >> 1; - } - return res; -} - -int Find_gcd_Extended(int a, int b, int* x, int* y) { - // Base Case - if (a == 0) { - *x = 0, *y = 1; - return b; - } - - // Storing results of recursive call - int x1, y1; - int gcd = Find_gcd_Extended(b % a, a, &x1, &y1); - - /* - After recursive call, update the values - of x and y - */ - *x = y1 - (b / a) * x1; - *y = x1; - - return gcd; -} - -int modinv(int a, int m) { - int x, y; - int g = Find_gcd_Extended(a, m, &x, &y); - - /* - If the gcd value doesn't matches - to 1, then inverse doesn't exist - */ - if (g != 1) { - return -1; - // cout << ""sdf""; - } else { - /* - m is added once more to handle - negative values - */ - int res = (x % m + m) % m; - // cout< isPrime(1000001); -void sieve() { - for (int i = 0; i <= 1000001; i++) { - isPrime[i] = 1; - } - isPrime[0] = isPrime[1] = 0; - - for (int i = 2; i * i <= 1000000; i++) { - if (isPrime[i] == true) { - for (int j = i * i; j <= 1000000; j += i) { - isPrime[j] = false; - } - } - } -} - -//-----spf------ -// SPF[i] => smallest prime number that divides i - -vector spf(1000001); -void findspf() { - for (int i = 0; i <= 1e6; i++) { - spf[i] = i; - } - - for (int i = 2; i * i <= 1e6; i++) { - if (spf[i] == i) { - for (int j = i * i; j <= 1e6; j += i) { - if (spf[j] == j) { - spf[j] = i; - } - } - } - } -} - -int madd(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a + b) % m + m) % m); -} - -int mmul(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a * b) % m + m) % m); -} - -int msub(int a, int b, int m) { - a = a % m; - b = b % m; - return (((a - b) % m + m) % m); -} - -int mdiv(int a, int b, int m) { - a = a % m; - b = b % m; - return ((mmul(a, modinv(b, m), m) + m) % m); -} - -// string hashing - -pair mod = {1e9 + 7, 1e9 + 9}; -vector> pref_hash; -vector> power_pref; -void createHashfn(int n, string& s) { - pref_hash.resize(n); - power_pref.resize(n); - pref_hash[0] = {s[0] - 'a' + 1, s[0] - 'a' + 1}; - power_pref[0] = {1, 1}; - for (int i = 1; i < n; i++) { - pref_hash[i].first = - (pref_hash[i - 1].first * (int)31 + (s[i] - 'a' + 1)) % mod.first; - pref_hash[i].second = - (pref_hash[i - 1].second * (int)53 + (s[i] - 'a' + 1)) % mod.second; - - power_pref[i].first = (power_pref[i - 1].first * (int)31) % mod.first; - power_pref[i].second = (power_pref[i - 1].second * (int)53) % mod.second; - } -} - -auto subhash(int l, int r, string& s) { - if (l == 0) return pref_hash[r]; - - pair sub_hash; - sub_hash.first = ((pref_hash[r].first - (int)pref_hash[l - 1].first * - power_pref[r - l + 1].first) % - mod.first); - if (sub_hash.first < 0) sub_hash.first += mod.first; - - sub_hash.second = ((pref_hash[r].second - (int)pref_hash[l - 1].second * - power_pref[r - l + 1].second) % - mod.second); - if (sub_hash.second < 0) sub_hash.second += mod.second; - return sub_hash; -} - -////////////////// DSU 1 BASED INDEXING ///////////////////////////// -vector par(2e5 + 1); -vector rnk(2e5 + 1); -// intrnk[1e5]; - -void make_set(int n) { - for (int i = 1; i < n + 1; i++) { - par[i] = i; - rnk[i] = 1; - } -} - -int find_set(int x) { - if (par[x] == x) { - return x; - } - - par[x] = find_set(par[x]); - - return par[x]; -} - -void union_set(int a, int b) { - int p1 = find_set(a); - int p2 = find_set(b); - - if (p1 == p2) { - return; - } - - if (rnk[p1] > rnk[p2]) { - par[p2] = p1; - rnk[p1] = rnk[p1] + rnk[p2]; - } else { - par[p1] = p2; - rnk[p2] = rnk[p2] + rnk[p1]; - } -} -////////////////////DSU 1 BASED -/// INDEXING////////////////////////////////////////////////// - -// x|(1< input -const int MOD = 998244353; -void add(int& a, int b) { - a += b; - if (a >= MOD) a -= MOD; -} - -int sum(int a, int b) { - a += b; - if (a >= MOD) a -= MOD; - if (a < 0) a += MOD; - return a; -} - -int mul(int a, int b) { return (a * 1LL * b) % MOD; } - -const int N = 2000005; -// const int mod = 1e9 + 7; -int fact[N], invfact[N]; - -void precompute() { - fact[0] = fact[1] = 1; - for (int i = 2; i < N; i++) { - fact[i] = fact[i - 1] * i; - fact[i] %= modd; - } - - invfact[N - 1] = modinv(fact[N - 1], modd); - for (int i = N - 2; i >= 0; i--) { - invfact[i] = invfact[i + 1] * (i + 1); - invfact[i] %= modd; - } -} - -int nCr(int x, int y) { - if (y > x) return 0; - int num = fact[x]; - num *= invfact[y]; - num %= modd; - num *= invfact[x - y]; - num %= modd; - return num; -} - -vi binRep(int x) { - vi v(32); - for (int i = 29; i >= 0; i--) { - v[i] = (x >= (1 << i)); - x %= (1 << i); - } - return v; -} - -// RADHE RADHE - -// vvi tree; -// vi vis, parent, depth; - -//---------- max seg code ---- 0based indexing--------------// - -const int MAXMAX = 2e5; // Max size of array -int treemax[2 * MAXMAX]; - -// Function to build the tree -void buildmax(vector& arr, int n) { - for (int i = 0; i < n; i++) treemax[n + i] = arr[i]; - for (int i = n - 1; i > 0; --i) - treemax[i] = max(treemax[i << 1], treemax[i << 1 | 1]); -} - -// Function to update a tree node -void updatemax(int p, int value, int n) { - treemax[p + n] = value; - p = p + n; - for (int i = p; i > 1; i >>= 1) - treemax[i >> 1] = max(treemax[i], treemax[i ^ 1]); -} - -// Function to get minimum value in a given range -// [l,r) -int querymax(int l, int r, int n) { - int res = -1e18; - for (l += n, r += n; l < r; l >>= 1, r >>= 1) { - if (l & 1) res = max(res, treemax[l++]); - if (r & 1) res = max(res, treemax[--r]); - } - return res; -} - -// array mein value ko dalne ke liye update ko call karna - -//---------- max seg code ---- 0based indexing--------------//-------------// -//---------- min seg code ---- 0based indexing--------------// - -const int MAXMIN = 2e5; // Max size of array -int treemin[2 * MAXMIN]; - -// Function to build the tree -void buildmin(vector& arr, int n) { - for (int i = 0; i < n; i++) treemin[n + i] = arr[i]; - for (int i = n - 1; i > 0; --i) - treemin[i] = min(treemin[i << 1], treemin[i << 1 | 1]); -} - -// Function to update a tree node -void updatemin(int p, int value, int n) { - treemin[p + n] = value; - p = p + n; - for (int i = p; i > 1; i >>= 1) - treemin[i >> 1] = min(treemin[i], treemin[i ^ 1]); -} - -// Function to get minimum value in a given range -// [l,r) -int querymin(int l, int r, int n) { - int res = 1e18; - for (l += n, r += n; l < r; l >>= 1, r >>= 1) { - if (l & 1) res = min(res, treemin[l++]); - if (r & 1) res = min(res, treemin[--r]); - } - return res; -} - -// array mein value ko dalne ke liye update ko call karna -//////////////////////////////////////////// -//---------- min seg code ---- 0based indexing--------------//-------------// -/////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -///////////////////////////BINARY INDEX TREE///////////////////////////////// -////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////// -//////////////////////BINARY INDEX TREE////////////////////////////// -/////////////////////////////////////////////////////////////////////////// - -// point update range min/max => seg tree -// point update range sum ==> Binary index tree - -// for static -// range min/max/gcd/lcm/or/and ==> sparse table , query in O(1) -// range sum/xor ==> prefix sum - -// range update , set ; range min/max/sum = lazy - -// sparsetable code - -// int n; -// cin >> n; -// -// vi a(n); -// fl(i, 0, n) cin >> a[i]; -// -// int maxk = 25; -// int st[n + 1][maxk + 1]; -// -// for (int i = 0; i < n; i++) { -// st[i][0] = a[i]; -// } -// -// for (int k = 1; k <= maxk; k++) { -// for (int i = 0; i + (1 << k) <= n; i++) { -// st[i][k] = (st[i][k - 1] & st[i + (1 << (k - 1))][k - 1]); -// } -// } -// -// for (int i = 0; i < n; i++) { -// for (int j = 0; j < 4; j++) { -// cout << st[i][j] << "" ""; -// } -// cout << endl; -// } -// -// int l, r; -// cin >> l >> r; -// // int s = 0; -// // for (int k = maxk; k >= 0; k--) { -// // if ((1 << k) <= r - l + 1) { -// // s += st[l][k]; -// // l += (1 << k); -// // } -// // } -// // cout << s; -// -// vi lg(n + 1); -// lg[1] = 0; -// for (int i = 2; i <= n; i++) { -// lg[i] = lg[i / 2] + 1; -// } -// -// int w = lg[r - l + 1]; -// int ans = (st[l][w] & st[r - (1 << w) + 1][w]); -// cout << ans; - -// sparsetable code - -void solve() { - int n; - cin >> n; - vi v(n); - fl(i, 0, n) cin >> v[i]; - if (v[0] == get_max(v)) { - cout << ""NO""; - return; - } - cout << ""YES""; -} - -int32_t main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - // // ----Atcode---- - // int q = 1; - // // ----Atcode---- - // -----cf/cc---- - int q; - cin >> q; - //-----cf/cc---- - - precompute(); - while (q--) { - solve(); - cout << en; - } - return 0; -} -",1 -Trspnt,2060D - Subtract Min Sort,c++20 ,310229505,310228968,"#include - -#define int long long - -#define xyz - - - -using namespace std; - -typedef long double ld; - -typedef pair PII; - -const int N = 1e5+10,mod = 1e9+7; - -const int INF = (1ll<<60)-1; - -int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1}; - -int n,m; - - - -int encode(int x,int y) - -{ - - return (x-1)*m+y; - -} - -PII decode(int x) - -{ - - return make_pair((x-1)/m+1,(x-1)%m+1); - -} - - - -int qmi(int a,int b) - -{ - - int res=1; - - while(b) - - { - - if(b&1)res=res*a%mod; - - a=a*a%mod; - - b>>=1; - - } - - return res; - -} - - - -void solve() - -{ - - int n; - - cin>>n; - - vectora(n+2); - - for(int i=1;i<=n;i++)cin>>a[i]; - - int flag=1; - - for(int i=1;ia[i+1]) - - { - - flag=0; - - break; - - } - - } - - if(flag)cout<<""YES""<<""\n""; - - else cout<<""NO""<<""\n""; - -} - - - -signed main() - -{ - - cin.tie(nullptr); - - ios::sync_with_stdio(false); - - int T=1; - - cin>>T; - - while(T--)solve(); - - return 0; - -} - -/* - - - -1 - -1 2 - - - -*/ - -","#include - -#define int long long - -#define xyz - - - -using namespace std; - -typedef long double ld; - -typedef pair PII; - -const int N = 1e5+10,mod = 1e9+7; - -const int INF = (1ll<<60)-1; - -int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1}; - -int n,m; - - - -int encode(int x,int y) - -{ - - return (x-1)*m+y; - -} - -PII decode(int x) - -{ - - return make_pair((x-1)/m+1,(x-1)%m+1); - -} - - - -int qmi(int a,int b) - -{ - - int res=1; - - while(b) - - { - - if(b&1)res=res*a%mod; - - a=a*a%mod; - - b>>=1; - - } - - return res; - -} - - - -void solve() - -{ - - int n; - - cin>>n; - - vectora(n+2); - - for(int i=1;i<=n;i++)cin>>a[i]; - - int flag=1; - - for(int i=1;ia[i+1]) - - { - - if(i-1>0) - - { - - a[i]-=a[i-1]; - - a[i-1]=0; - - if(a[i]>a[i+1]) - - { - - flag=0; - - break; - - } - - } - - } - - } - - if(flag)cout<<""YES""<<""\n""; - - else cout<<""NO""<<""\n""; - -} - - - -signed main() - -{ - - cin.tie(nullptr); - - ios::sync_with_stdio(false); - - int T=1; - - cin>>T; - - while(T--)solve(); - - return 0; - -} - -/* - - - -1 - -1 2 - - - -*/ - -",1 -RishabhG10,2060D - Subtract Min Sort,c++20 ,311777627,311766873,"#include - -using namespace std; - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x << "" = "" << (x) << endl; - -#else - -#define debug(x) - -#endif - -using ll = long long ; - -void solve(){ - -ll n ; - -cin>>n; - -vectorv(n) ; - -bool is_sorted = false ; - - - -for(int i=0;i>v[i] ; - -} - -if(n==2){ - -if(v[0]>v[1]){ - -cout<<""NO""<>t; - -while(t--){ - -solve() ; - -} - -}","#include - -using namespace std; - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x << "" = "" << (x) << endl; - -#else - -#define debug(x) - -#endif - -using ll = long long ; - -void solve(){ - -ll n ; cin>>n; - -vectorv(n) ; - -ll largest = INT_MIN ; - -bool formed = true; - -for(ll i=0;i>v[i] ; - -largest = max(largest,v[i]) ; - -} - -debug(largest) - -for(ll i=0;i>t; - -while(t--){ - -solve() ; - -} - -}",1 -elice4321,2060D - Subtract Min Sort,c++20 ,303183271,303184778,"#include -using namespace std; -int main() { - int t,n; - cin>>t; - while(t--){ - cin>>n; - vector nums(n); - for(int i=0; i>nums[i]; - } - for(int i=0; i -using namespace std; - -int main() { - int t, n; - cin >> t; - while (t--) { - cin >> n; - vector nums(n); - for (int i = 0; i < n; i++) { - cin >> nums[i]; - } - - for (int i = 0; i < n - 1; i++) { - int sub = min(nums[i], nums[i + 1]); - nums[i] -= sub; - nums[i + 1] -= sub; - } - - // Check if the array is sorted - if (is_sorted(nums.begin(), nums.end())) { - cout << ""YES"" << endl; - } else { - cout << ""NO"" << endl; - } - } - return 0; -} -",2 -newplayer27,2060D - Subtract Min Sort,c++23 ,306793165,306796064,"// Bluntforces ;) - -#include -using namespace std; -#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -typedef long long int ll; - -void solve() { - int n; cin >>n; - vector a(n); - for(int i=0;i>a[i]; - } - for(int i=0;ia[i+1]){ - cout <<""NO""<> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; -#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -typedef long long int ll; - -void solve() { - int n; - cin >> n; - deque a(n); - for(int i=0;i>a[i]; - } - - while(a.size()>1){ - if(a[0]>a[1]){ - cout <<""NO""<> t; - while (t--) { - solve(); - } - return 0; -} -",2 -envmotion,2060D - Subtract Min Sort,c++20 ,309029305,309029145,"#include - -#include - -using namespace std; - - - -void solve() { - - int n; - - cin >> n; - - vector a(n); - - for (int &x : a) cin >> x; - - - - for (int i = 1; i < n; ++i) { - - if (a[i] < a[i - 1]) { - - cout << ""NO\n""; - - return; - - } - - a[i] -= min(a[i], a[i - 1]); - - } - - cout << ""YES\n""; - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}","#include - -using namespace std; - - - -void solve() { - - int n; - - cin >> n; - - vector a(n); - - for (int i = 0; i < n; i++) { - - cin >> a[i]; - - } - - - - // ????????? ??????? ??????? ????? - - for (int i = 1; i < n - 1; i++) { - - if (a[i] > a[i - 1] && a[i] > a[i + 1]) { - - cout << ""NO\n""; - - return; - - } - - } - - cout << ""YES\n""; - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(0); - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - return 0; - -}",1 -olive_tree,2060D - Subtract Min Sort,c++17 ,303988194,303988991,"#include -using namespace std; - -typedef long long ll; -#define nl ""\n"" - -#ifndef ONLINE_JUDGE -#include ""debug_template.h"" -#else -#define debug(...) -#define debugArr(...) -#endif - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; cin >> t; while (t--) - { - ll n; cin>>n; ll a[n]; - for(int i=0; i>a[i]; - - if(a[0]>a[1]) cout<<""NO""< -using namespace std; - -typedef long long ll; -#define nl ""\n"" - -#ifndef ONLINE_JUDGE -#include ""debug_template.h"" -#else -#define debug(...) -#define debugArr(...) -#endif - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; cin >> t; while (t--) - { - ll n; cin>>n; ll a[n]; - for(int i=0; i>a[i]; - - ll cnt= 0; - for(int i=2; i=a[i-2] && a[i-1]-a[i-2]<=a[i]) { - cnt++; - a[i-1]-=a[i-2]; - a[i-2]=0; - } - } - cout<<(is_sorted(a,a+n)? ""YES\n"":""No\n""); - - debugArr(a,n); - - } - return 0; -}",2 -tanviiir,2060D - Subtract Min Sort,c++17 ,306605068,306608244,"#include -using namespace std; - -#define optimize() ios_base::sync_with_stdio(0); cin.tie(0) -#define ll long long -#define ff first -#define ss second -#define sz size() -#define pb push_back -#define vinput for(auto& x: v) cin >> x; -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define range(i,x,y) for(int i=x;i=x;i--) -#define mem(a,b) memset(a, b, sizeof(a) ) - -typedef vector vi; -typedef vector vl; -typedef pair pii; -typedef vector vii; - -// Debug.. -#ifdef LOCAL -#include ""debug2.h"" -#else -#define dg(x...) -#endif - -void Solve() { - int n; - cin >> n; - vi v(n); - vinput; - - for(int i=1; i v[i] or (i == n-2 and v[i] > v[i+1])){ - cout << ""NO\n""; - return; - } - } - cout << ""YES\n""; -} - -int main() { - optimize(); - - int t = 1; - cin >> t; - for(int i=1; i<=t; i++){ - //cout << ""Case "" << i << "": ""; - Solve(); - } - - return 0; -}","#include -using namespace std; - -#define optimize() ios_base::sync_with_stdio(0); cin.tie(0) -#define ll long long -#define ff first -#define ss second -#define sz size() -#define pb push_back -#define vinput for(auto& x: v) cin >> x; -#define all(x) x.begin(),x.end() -#define allr(x) x.rbegin(),x.rend() -#define range(i,x,y) for(int i=x;i=x;i--) -#define mem(a,b) memset(a, b, sizeof(a) ) - -typedef vector vi; -typedef vector vl; -typedef pair pii; -typedef vector vii; - -// Debug.. -#ifdef LOCAL -#include ""debug2.h"" -#else -#define dg(x...) -#endif - -void Solve() { - int n; - cin >> n; - vi v(n); - vinput; - - for(int i=1; i v[i]){ - cout << ""NO\n""; - return; - } - else{ - v[i] -= v[i-1]; - v[i-1] = 0; - } - } - if(is_sorted(all(v))){ - cout << ""YES\n""; - } - else cout << ""NO\n""; -} - -int main() { - optimize(); - - int t = 1; - cin >> t; - for(int i=1; i<=t; i++){ - //cout << ""Case "" << i << "": ""; - Solve(); - } - - return 0; -}",2 -Talha_Taseen,2060D - Subtract Min Sort,c++23 ,306428987,306429635,"#include -#include -#include -#define nn cout<<""NO""<>t; - while(t--)talha(); - return 0; -} -void talha() -{ - int n; - cin>>n; - vectorv(n); - for(int i=0;i>v[i]; - int ans=0; - for(int i=0;i=v[n-2])hh; - else nn; - } - else - { - if(ans==n-1)hh; - else nn; - } -} -","#include -#include -#include -#define nn cout<<""NO""<>t; - while(t--)talha(); - return 0; -} -void talha() -{ - int n; - cin>>n; - vectorv(n); - for(int i=0;i>v[i]; - int ans=0; - for(int i=0;i -#include -#include -#include -#include -#include -using namespace std; - -int main() - -{ - int t; - cin >> t; - while (t--) - { - - - bool b = true; - int n,k=0; - cin >> n; - vector a(n); - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - - while (k1 && (a[k]-a[k+1] != a[k-1]-a[k-2])){ - b=false; - break; - } - } - - k++; - - } - if (b) - { - cout<<""YES""< -#include -#include -#include -#include -#include -using namespace std; - -int main() - -{ - int t; - cin >> t; - while (t--) - { - - bool b = true; - int n, k = 0; - cin >> n; - vector a(n); - - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - - while (k < n - 1 && k >= 0) - { - if (a[k] <= a[k + 1]) - { - k++; - } - else - { - b = false; - break; - } - } - if (b) - { - cout << ""YES"" << endl; - continue; - } - else - { - - for (int i = 0; i < n - 1; i++) - { - int mi = min(a[i], a[i + 1]); - a[i] = a[i] - mi; - a[i + 1] = a[i + 1] - mi; - } - - b = true; - while (k < n - 1 && k >= 0) - { - if (a[k] <= a[k + 1]) - { - k++; - } - else - { - b = false; - break; - } - } - - if (b) - { - cout << ""YES"" << endl; - } - else - cout << ""NO"" << endl; - } - } -} -",2 -st133720,2060D - Subtract Min Sort,python,306899366,306898121,"for _ in range(int(input())): - n = int(input()) - a=list(map(int,input().split())) - bol = True - for i in range(n-1): - if a[i] >a[i+1]: - bol =False - break - else: - a[i+1] = a[i+1]- a[i] - print(""YES"" if bol else""NO"") - ","for _ in range(int(input())): - n = int(input()) - a=list(map(int,input().split())) - bol = True - for i in range(n-1): - if i % 2 == 0: - if a[i] > a[i+1]: - bol=False - print(""YES"" if bol else""NO"") ",1 -rainy,2060D - Subtract Min Sort,c++20 ,304927874,304928353,"#include -using namespace std; -#define ll long long -#define ld long double -#define pii pair -#define mp make_pair -#define f first -#define s second -#define pb push_back -#define all(x) (x).begin(), (x).end() -const ll INF = 1000000000000000000; -int dx[4] = {-1, 0, 1, 0}; -int dy[4] = {0, 1, 0, -1}; -string stepDir = ""URDL""; - -/******** Debug Code *******/ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } -template void __print(const A &x); -template void __print(const pair &p); -template void __print(const tuple &t); -template void __print(stack s); -template void __print(queue q); -template void __print(priority_queue q); -template void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""), __print(i); - first = false; - } - cerr << '}'; -} -template void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} -template void __print(const tuple &t) { - bool first = true; - cerr << '('; - apply( - [&first](const auto &...args) { - ((cerr << (first ? """" : "",""), __print(args), first = false), ...); - }, - t); - cerr << ')'; -} -template void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} -template void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -template void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -void _print() { cerr << ""]\n""; } -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} -#ifndef ONLINE_JUDGE -#define dbg(...) \ - cerr << ""Line:"" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = [""; \ - _print(__VA_ARGS__) -#else -#define dbg(...) -#endif - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) - cin >> x; - if (n == 1) { - cout << ""YES""; - return; - } - if (a[0] > a[1]) { - cout << ""NO""; - return; - } - int i = 0; - while (i + 1 < n && a[i] == a[i + 1]) - i++; - if (i + 1 < n && a[i] > a[i + 1]) { - cout << ""NO""; - return; - } - cout << ""YES""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout << fixed << setprecision(10); - int T; - cin >> T; - for (int t = 1; t <= T; ++t) { - solve(); - cout << '\n'; - } -} -","#include -using namespace std; -#define ll long long -#define ld long double -#define pii pair -#define mp make_pair -#define f first -#define s second -#define pb push_back -#define all(x) (x).begin(), (x).end() -const ll INF = 1000000000000000000; -int dx[4] = {-1, 0, 1, 0}; -int dy[4] = {0, 1, 0, -1}; -string stepDir = ""URDL""; - -/******** Debug Code *******/ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } -template void __print(const A &x); -template void __print(const pair &p); -template void __print(const tuple &t); -template void __print(stack s); -template void __print(queue q); -template void __print(priority_queue q); -template void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""), __print(i); - first = false; - } - cerr << '}'; -} -template void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} -template void __print(const tuple &t) { - bool first = true; - cerr << '('; - apply( - [&first](const auto &...args) { - ((cerr << (first ? """" : "",""), __print(args), first = false), ...); - }, - t); - cerr << ')'; -} -template void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} -template void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -template void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} -void _print() { cerr << ""]\n""; } -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} -#ifndef ONLINE_JUDGE -#define dbg(...) \ - cerr << ""Line:"" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = [""; \ - _print(__VA_ARGS__) -#else -#define dbg(...) -#endif - -void solve() { - int n; - cin >> n; - vector a(n); - for (auto &x : a) - cin >> x; - if (n == 1) { - cout << ""YES""; - return; - } - if (a[0] > a[1]) { - cout << ""NO""; - return; - } - int i = 0; - while (i + 1 < n && a[i] <= a[i + 1]) { - a[i + 1] -= a[i]; - a[i] = 0; - i++; - } - if (i + 1 < n && a[i] > a[i + 1]) { - cout << ""NO""; - return; - } - dbg(a); - cout << ""YES""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout << fixed << setprecision(10); - int T; - cin >> T; - for (int t = 1; t <= T; ++t) { - solve(); - cout << '\n'; - } -} -",2 -brithvik0305,2060D - Subtract Min Sort,c++17 ,307186780,307186999,"#include -using namespace std; -void solve(){ - int n; - cin >>n; - int a[n]; - for(int i=0; i> a[i]; - } - for(int i=0; ia[i+1]){ - cout << ""NO\n""; - return; - }else{ - a[i+1]-=min(a[i],a[i+1]); - a[i]-=min(a[i],a[i+1]); - } - } - cout << ""YES\n""; -} -int main(){ - freopen(""input.txt"",""r"",stdin); - freopen(""output.txt"",""w"",stdout); - int t; - cin >> t; - while(t--){ - solve();} - return 0; -}","#include -using namespace std; -void solve(){ - int n; - cin >>n; - int a[n]; - for(int i=0; i> a[i]; - } - for(int i=0; ia[i+1]){ - cout << ""NO\n""; - return; - }else{ - a[i+1]-=min(a[i],a[i+1]); - a[i]-=min(a[i],a[i+1]); - } - } - cout << ""YES\n""; -} -int main(){ - int t; - cin >> t; - while(t--){ - solve();} - return 0; -}",2 -my886,2060D - Subtract Min Sort,c++20 ,305392045,305392179,"#include -using namespace std; -#define int long long -const int N=2e5+10; -int a[N]; -int n; -void solve(){ - a[0]=0; - for(int i=1;i>t; - while(t--){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - solve(); - } - -}","#include -using namespace std; -#define int long long -const int N=2e5+10; -int a[N]; -int n; -void solve(){ - a[0]=0; - for(int i=1;ia[i+1]){ - cout<<""NO""<>t; - while(t--){ - cin>>n; - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - solve(); - } - -}",2 -ShreeSolver,2060D - Subtract Min Sort,c++23 ,310561655,310564805,"#include - -#include - -using namespace std; - - - -void solve() - -{ - - int n; - - cin >> n; - - vector a(n); - - - - for (int i = 0; i < n; i++) - - { - - cin >> a[i]; - - } - - - - for (int i = 0; i < n - 1; i++) - - { - - if (a[i] > a[i + 1]) - - { - - int diff = a[i] - a[i + 1]; - - a[i] -= diff; // Reduce both a[i] and a[i+1] by 'diff' - - a[i + 1] -= diff; - - } - - if (a[i] > a[i + 1]) - - { - - cout << ""NO"" << endl; - - return; - - } - - } - - - - cout << ""YES"" << endl; - -} - - - -int main() - -{ - - int t; - - cin >> t; - - - - while (t--) - - { - - solve(); - - } - - - - return 0; - -} - -","#include - -using namespace std; - -using ll = long long; - - - -void solve() { - - ll n; - - cin >> n; - - vector a(n); - - - - for (ll &x : a) cin >> x; - - - - ll last = 0; - - - - // Find the last position where a[i] > a[i+1] - - for (ll i = 1; i < n; i++) { - - if (a[i - 1] > a[i]) last = i; - - } - - - - // If already sorted, return YES - - if (last == 0) { - - cout << ""YES\n""; - - return; - - } - - - - // Apply the operation - - for (ll i = 0; i < last; i++) { - - ll min_val = min(a[i], a[i + 1]); - - a[i] -= min_val; - - a[i + 1] -= min_val; - - } - - - - // Check if sorted after operations - - cout << (is_sorted(a.begin(), a.end()) ? ""YES"" : ""NO"") << '\n'; - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - ll t; - - cin >> t; - - while (t--) solve(); - - - - return 0; - -} - -",2 -R_M,2060D - Subtract Min Sort,c++17 ,303257005,303258683,"#include -using namespace std; -#define int long long int - -int sum(vector &a, int n) -{ - int x = 0; - for (int i = 0; i < n; i++) - { - x += abs(a[i]); - } - return x; -} - -void solve() -{ - int n; cin>>n; - vectora(n); - for(int &x : a) cin>>x; - int g = 0, f = 0; - for(int i=1;i a[i-1]) g = 1; - } - if(f==0) cout<<""YES\n""; - else cout<<""NO\n""; -} - -int32_t main() -{ - int t; - cin >> t; - while (t--) - { - solve(); - } -} -","#include -using namespace std; -#define int long long int - -int sum(vector &a, int n) -{ - int x = 0; - for (int i = 0; i < n; i++) - { - x += abs(a[i]); - } - return x; -} - -void solve() -{ - int n; cin>>n; - vectora(n); - for(int &x : a) cin>>x; - int g = 0, f = 0; - for(int i=1;i> t; - while (t--) - { - solve(); - } -} -",2 -RudranilJadhav,2060D - Subtract Min Sort,c++17 ,315171489,315170165,"#include - -using namespace std; - -void opp(int &i,int &j){ - -int k=min(i,j); - -i-=k; - -j-=k; - -} - -int can3be(vector &v,int i){ - -int i1=v[i],j1=v[i+1],k1=v[i+2]; - -int i2=v[i],j2=v[i+1],k2=v[i+2]; - -opp(i1,j1);opp(j1,k1); - -opp(j2,k2);opp(i2,j2); - -if(i1<=j1&&j1<=k1){ - -opp(v[i],v[i+1]);opp(v[i+1],v[i+2]); - -return 1; - -} - -if(i2<=j2&&j2<=k2){ - -opp(v[i+1],v[i+2]);opp(v[i],v[i+1]); - -return 1; - -} - -return 0; - -} - -int main(){ - -ios_base::sync_with_stdio(0);cin.tie(0); - -int t; - -cin>>t; - -while(t--){ - -int n; - -cin>>n; - -vector v(n); - -int flag=1; - -for(auto &i:v) cin>>i; - -if(n==2){ - -if(v[0]<=v[1]) cout<<""YES""<<""\n""; - -else cout<<""NO""<<""\n""; - -} - -else{ - -for(int i =0 ; i - -using namespace std; - -void opp(int &i,int &j){ - -int k=min(i,j); - -i-=k; - -j-=k; - -} - -int can3be(vector &v,int i){ - -int i1=v[i],j1=v[i+1],k1=v[i+2]; - -int i2=v[i],j2=v[i+1],k2=v[i+2]; - -opp(i1,j1);opp(j1,k1); - -opp(j2,k2);opp(i2,j2); - -if(i1<=j1&&j1<=k1){ - -opp(v[i],v[i+1]);opp(v[i+1],v[i+2]); - -return 1; - -} - -if(i2<=j2&&j2<=k2){ - -opp(v[i+1],v[i+2]);opp(v[i],v[i+1]); - -return 1; - -} - -return 0; - -} - -int main(){ - -ios_base::sync_with_stdio(0);cin.tie(0); - -int t; - -cin>>t; - -while(t--){ - -int n; - -cin>>n; - -vector v(n); - -int flag=1; - -for(auto &i:v) cin>>i; - -for(int i =0 ; i -using namespace std; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define ll long long -#define gcd(a,b) __gcd(a,b) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define nline ""\n"" -#define pub push_back -#define pob pop_back - -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll//TO FIND NUMBER OF SET BITS __builtin_popcountll(n);-->>set_bits(n); -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -ll lcm(ll a,ll b) -{ -return (a*b)/__gcd(a,b); -} -ll LOWERBOUND(vector &vp,ll n,ll search) -{ -ll ans=-1; -ll l=0,r=n-1; -while(l<=r) -{ -ll mid=l+(r-l)/2; -if(vp[mid]<=search) -{ -ans=mid; -l=mid+1; -} -else -r=mid-1; -} -return ans+1; - -} -ll UPPERBOUND(vector &vp,ll n,ll search) -{ -ll ans=-1; -ll l=0,r=n-1; -while(l<=r) -{ -ll mid=l+(r-l)/2; -if(vp[mid]>=search) -{ -ans=mid; -r=mid-1; -} -else -l=mid+1; -} -return ans+1; - -} -int ispal(string &s) -{ -string s1=s; -reverse(s1.begin(),s1.end()); -if(s1==s) -return 1; -return 0; -} -void div(ll &a,ll &b,ll index1,ll index2,vector> &ans) -{ -while(a!=b&&(a!=2||b!=2)) -{ -if(a vp) -{ -sort(vp.begin(),vp.end()); -ll mex1=0; -ll n=vp.size(); -for(ll ind=0;ind>k)&1); -} -bool iscomp(ll n){ -for(int i=2;i<=sqrt(n);i++){ -if(n%i==0) -return 1; -} -return 0; - -} - -int compute(int x,int y,set> &vis,vector> &a,int n,int m){ - -if( x<0||y<0||x>=n||y>=m) -return 0; -if(vis.find({x,y})!=vis.end()) -{ -return 0; -} -if(a[x][y]!='?') -{ -char move=a[x][y]; -vis.insert({x,y}); -if(move=='U') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='R') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='D') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='L') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -} -else -{ -//when we go up - -//when we go right - -//when we go down - -//when we go left - - -} - -} - -void dfs(int flag,ll val,map> &m,set &s1,set &s2,int n,bool done[]) -{ -if(done[val]){ -return; -} -done[val]=1; -if(flag==0) -{ -if(s1.find(val)==s1.end()) -{ -s1.insert(val); -for(auto it:m[val]) -{ -dfs(1,it,m,s1,s2,n,done); -} -} - -} -else -{ -if(s2.find(val)==s2.end()) -{ -s2.insert(val); -for(auto it:m[val]) -{ -dfs(0,it,m,s1,s2,n,done); -} -} -} - - -} - -void solve() -{ - ll n,m; - cin>>n>>m; - ll a[n],b[m]; - for(int i=0;i>a[i]; - for(int i=0;i>b[i]; - - sort(a,a+n); - sort(b,b+m); - ll count=n; - map mp; - for(auto it:a){ - mp[it]++; - } - - - multiset s; - for(int i=0;i>t; - -while(t--) -{ -solve(); -} - - -}","#include -using namespace std; -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define ll long long -#define gcd(a,b) __gcd(a,b) -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define nline ""\n"" -#define pub push_back -#define pob pop_back - -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll//TO FIND NUMBER OF SET BITS __builtin_popcountll(n);-->>set_bits(n); -#define sz(x) ((int)(x).size()) -#define all(x) (x).begin(), (x).end() -ll lcm(ll a,ll b) -{ -return (a*b)/__gcd(a,b); -} -ll LOWERBOUND(vector &vp,ll n,ll search) -{ -ll ans=-1; -ll l=0,r=n-1; -while(l<=r) -{ -ll mid=l+(r-l)/2; -if(vp[mid]<=search) -{ -ans=mid; -l=mid+1; -} -else -r=mid-1; -} -return ans+1; - -} -ll UPPERBOUND(vector &vp,ll n,ll search) -{ -ll ans=-1; -ll l=0,r=n-1; -while(l<=r) -{ -ll mid=l+(r-l)/2; -if(vp[mid]>=search) -{ -ans=mid; -r=mid-1; -} -else -l=mid+1; -} -return ans+1; - -} -int ispal(string &s) -{ -string s1=s; -reverse(s1.begin(),s1.end()); -if(s1==s) -return 1; -return 0; -} -void div(ll &a,ll &b,ll index1,ll index2,vector> &ans) -{ -while(a!=b&&(a!=2||b!=2)) -{ -if(a vp) -{ -sort(vp.begin(),vp.end()); -ll mex1=0; -ll n=vp.size(); -for(ll ind=0;ind>k)&1); -} -bool iscomp(ll n){ -for(int i=2;i<=sqrt(n);i++){ -if(n%i==0) -return 1; -} -return 0; - -} - -int compute(int x,int y,set> &vis,vector> &a,int n,int m){ - -if( x<0||y<0||x>=n||y>=m) -return 0; -if(vis.find({x,y})!=vis.end()) -{ -return 0; -} -if(a[x][y]!='?') -{ -char move=a[x][y]; -vis.insert({x,y}); -if(move=='U') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='R') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='D') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -else if(move=='L') -{ -return 1+compute(x-1,y,vis,a,m,n); -} -} -else -{ -//when we go up - -//when we go right - -//when we go down - -//when we go left - - -} - -} - -void dfs(int flag,ll val,map> &m,set &s1,set &s2,int n,bool done[]) -{ -if(done[val]){ -return; -} -done[val]=1; -if(flag==0) -{ -if(s1.find(val)==s1.end()) -{ -s1.insert(val); -for(auto it:m[val]) -{ -dfs(1,it,m,s1,s2,n,done); -} -} - -} -else -{ -if(s2.find(val)==s2.end()) -{ -s2.insert(val); -for(auto it:m[val]) -{ -dfs(0,it,m,s1,s2,n,done); -} -} -} - - -} - -void solve() -{ - ll n,m; - cin>>n>>m; - ll a[n],b[m]; - for(int i=0;i>a[i]; - for(int i=0;i>b[i]; - - sort(a,a+n); - sort(b,b+m); - ll count=n; - map mp; - for(auto it:a){ - mp[it]++; - } - - - multiset s; - for(int i=0;i>t; - -while(t--) -{ -solve(); -} - - -}",2 -surajiyer,2061D - Kevin and Numbers,c++20 ,303032602,303033988,"#include -using namespace std; -#define int int64_t -const int MOD = 1000000007; -#define rep(a,b,c) for(int a = b; a < c; ++a) -#define repr(a,b,c) for(int a = b; a > c; --a) - -void solve (int test_case) { - // the key is to visualize - // to get better, work on speed - https://www.youtube.com/watch?v=BqWqzvnbnjU - int n, m; - cin >> n >> m; - int a [n], b [m]; - rep (i,0,n) cin >> a[i]; - rep (i,0,m) cin >> b[i]; - multiset ms; - rep (i,0,n) ms.insert(a[i]); - map mp; - rep (i,0,m) mp[b[i]] += 1; - while (ms.size() > 1) { - if (mp.size() == 0) { - cout << ""NO\n""; - return; - } - int x = *ms.begin(); - ms.erase(ms.begin()); - if (mp.find(x) != mp.end()) { - mp[x] -= 1; - if (mp[x] == 0) mp.erase(x); - continue; - } - int y = *ms.begin(); - ms.erase(ms.begin()); - if (y - x > 1) { - cout << ""NO\n""; - return; - } - int z = x + y; - if (mp.find(z) != mp.end()) { - mp[z] -= 1; - if (mp[z] == 0) mp.erase(z); - } - else { - ms.insert(z); - } - } - if (ms.size()) { - if (mp.size() == 0) { - cout << ""NO\n""; - return; - } - int x = *ms.begin(); - ms.erase(ms.begin()); - if (mp.find(x) != mp.end()) { - mp[x] -= 1; - if (mp[x] == 0) mp.erase(x); - } - else { - cout << ""NO\n""; - return; - } - } - if (mp.size()) cout << ""NO\n""; - else cout << ""YES\n""; -} - -int32_t main () { - ios::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int test_cases = 1; - cin >> test_cases; - for (int i = 1; i <= test_cases; ++i) solve(i); - return 0; -}","#include -using namespace std; -#define int int64_t -const int MOD = 1000000007; -#define rep(a,b,c) for(int a = b; a < c; ++a) -#define repr(a,b,c) for(int a = b; a > c; --a) - -void solve (int test_case) { - // the key is to visualize - // to get better, work on speed - https://www.youtube.com/watch?v=BqWqzvnbnjU - int n, m; - cin >> n >> m; - int a [n], b [m]; - rep (i,0,n) cin >> a[i]; - rep (i,0,m) cin >> b[i]; - map mp; - int cnt = 0; - rep (i,0,n) mp[a[i]] += 1, cnt += 1; - priority_queue pq; - rep (i,0,m) pq.push(b[i]); - while (pq.size() && pq.size() <= cnt) { - int x = pq.top(); - pq.pop(); - if (mp.find(x) != mp.end()) { - mp[x] -= 1; - if (mp[x] == 0) { - mp.erase(x); - } - cnt -= 1; - } - else { - pq.push(x / 2); - pq.push(x - x / 2); - } - } - if (mp.size()) cout << ""NO\n""; - else cout << ""YES\n""; -} - -int32_t main () { - ios::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int test_cases = 1; - cin >> test_cases; - for (int i = 1; i <= test_cases; ++i) solve(i); - return 0; -}",2 -delusionX,2061D - Kevin and Numbers,c++23 ,302347613,302351659,"#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pb push_back -#define ppb pop_back -#define mp make_pair -using namespace std; -using vpi = vector>; -using pi = pair; -using vi = vector; -using vvi = vector>; -#define ff first -#define ss second -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x).size() -const int inf = 9e18; -const int mod = 1e9 + 7; -const int NUM = 1000030; -const int N = 10000000; -#define DEBUG(x) cerr << #x << "": "" << x << '\n' -template -void solve() -{ - ll n, m; - cin >> n >> m; - vi a(n); - vi b(m); - cin >> a >> b; - map fa, fb; - set> pa, pb; - for (auto &&i : a) - { - fa[i]++; - pa.insert(i); - } - for (auto &&i : b) - { - fb[i]++; - pb.insert(i); - } - while (true) - { - if (pa.empty() && pb.empty()) - { - cout << ""YES"" << endl; - return; - } - if (pa.empty() || pb.empty()) - { - cout << ""NO"" << endl; - return; - } - ll mxb = *pb.begin(); - ll mxa = *pa.begin(); - if (mxa > mxb) - { - cout << ""NO"" << endl; - return; - } - if (fa[mxb]) - { - ll mn = min(fa[mxb], fb[mxb]); - fa[mxb] -= mn; - fb[mxb] -= mn; - if (fa[mxb] == 0) - { - pa.erase(mxb); - } - if (fb[mxb] == 0) - { - pb.erase(mxb); - } - } - else - { - ll sb = mxb / 2; - ll lb = (mxb + 1) / 2; - fb[sb] += fb[mxb]; - fb[lb] += fb[mxb]; - fb[mxb] = 0; - pb.insert(sb); - pb.insert(lb); - if (fb[mxb] == 0) - { - pb.erase(mxb); - } - } - } -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t = 1; - cin >> t; - while (t--) - solve(); - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pb push_back -#define ppb pop_back -#define mp make_pair -using namespace std; -using vpi = vector>; -using pi = pair; -using vi = vector; -using vvi = vector>; -#define ff first -#define ss second -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x).size() -const int inf = 9e18; -const int mod = 1e9 + 7; -const int NUM = 1000030; -const int N = 10000000; -#define DEBUG(x) cerr << #x << "": "" << x << '\n' -template -istream &operator>>(istream &is, pair &p) -{ - is >> p.first >> p.second; - return is; -} -template -ostream &operator<<(ostream &os, pair p) -{ - os << p.first << ' ' << p.second << ' '; - return os; -} -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} - -void solve() -{ - ll n, m; - cin >> n >> m; - vi a(n); - vi b(m); - cin >> a >> b; - map fa, fb; - set> pa, pb; - for (auto &&i : a) - { - fa[i]++; - pa.insert(i); - } - for (auto &&i : b) - { - fb[i]++; - pb.insert(i); - } - while (true) - { - if (pa.empty() && pb.empty()) - { - cout << ""YES"" << endl; - return; - } - if (pa.empty() || pb.empty()) - { - cout << ""NO"" << endl; - return; - } - ll mxb = *pb.begin(); - ll mxa = *pa.begin(); - if (mxa > mxb) - { - cout << ""NO"" << endl; - return; - } - if (fa[mxb]) - { - ll mn = min(fa[mxb], fb[mxb]); - fa[mxb] -= mn; - fb[mxb] -= mn; - if (fa[mxb] == 0) - { - pa.erase(mxb); - } - if (fb[mxb] == 0) - { - pb.erase(mxb); - } - } - else - { - ll sb = mxb / 2; - ll lb = (mxb + 1) / 2; - fb[sb] += fb[mxb]; - fb[lb] += fb[mxb]; - fb[mxb] = 0; - pb.insert(sb); - pb.insert(lb); - if (fb[mxb] == 0) - { - pb.erase(mxb); - } - } - } -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t = 1; - cin >> t; - while (t--) - solve(); - return 0; -}",2 -ASH9374,2061D - Kevin and Numbers,c++17 ,304431813,304433613,"#include -using namespace std; -// Sk Najir -#ifndef ONLINE_JUDGE -#include ""db.hpp"" -#else -#define dbg(x) -#define dbg2(x, y) -#define dbg3(x, y, z) -#endif -#define IOS \ - ios::sync_with_stdio(false); \ - cin.tie(0); \ - cout.tie(0); - -// pre_define -#define all(a) (a).begin(), (a).end() -#define rall(a) (a).rbegin(), (a).rend() - -// shortcut type -typedef long long ll; -typedef long double ld; -typedef vector vi; -typedef vector vii; -typedef vector vl; -typedef vector vll; - -// Constants -const int MOD = 1e9 + 7; - -void solve() -{ - int n, m; - cin >> n >> m; - multiset a, b; - ll x; - for (int i = 0; i < n; i++) - cin >> x, a.insert(x); - for (int i = 0; i < m; i++) - { - cin >> x; - b.insert(x); - } - while (!a.empty() and *a.begin() <= *b.begin()) - { - //dbg(b); - x = *b.rbegin(); - b.erase(prev(b.end())); - if (a.find(x) != a.end()) - { - a.erase(a.find(x)); - } - else - { - if (x % 2) - { - if (x == 1) - { - cout << ""No"" << endl; - return; - } - b.insert(x / 2); - b.insert((x / 2) + 1); - } - else - { - b.insert(x / 2); - b.insert(x / 2); - } - } - } - if (a.empty() and b.empty()) - { - cout << ""Yes"" << endl; - } - else - cout << ""No"" << endl; -} - -int main() -{ - IOS; - int tc = 1; - cin >> tc; - for (int t = 1; t <= tc; t++) - solve(); -}","#include -using namespace std; -typedef long long ll; -typedef pair pii; -#define vi vector -#define mod 1000000007 -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int nn; - cin >> nn; - while (nn--) - { - int n, m; - cin >> n >> m; - - multiset a; - for (int i = 0; i < n; i++) - { - int x; - cin >> x; - a.insert(x); - } - - priority_queue pq; - for (int j = 0; j < m; j++) - { - int x; - cin >> x; - pq.push(x); - } - - while (!pq.empty() && pq.size() <= a.size()) - { - int x = pq.top(); - pq.pop(); - // cout << x << "" ""; - auto it = a.lower_bound(x); - if (it == a.end() || *it != x) - { - // cout << ""breaking "" << x << endl; - if (x < 2) - { - pq.push(-1); - break; - } - pq.push(x / 2); - pq.push((x + 1) / 2); - } - else - { - // cout << ""erasing "" << x << endl; - a.erase(it); - } - } - - cout << (a.empty() && pq.empty() ? ""Yes\n"" : ""No\n""); - } -} -",2 -Dominater069,2061D - Kevin and Numbers,c++23 ,304005048,304004724,"#include -#include -#include -using namespace std; - -// Global frequency map for the numbers of array A. -map freq; - -// Recursive function that tries to ""explain"" x by matching it directly or by splitting. -bool dfs(long long x) { - // If x is present in A, consume one occurrence and return true. - if (freq[x] > 0) { - freq[x]--; - return true; - } - // If x is 1 and not available, we cannot split further. - if (x == 1) return false; - // Otherwise, split x into two parts. - // Note: if x is even, both parts are x/2. - // if x is odd, the parts are x/2 and (x+1)/2. - return dfs(x / 2) && dfs((x + 1) / 2); -} - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while(t--){ - int n, m; - cin >> n >> m; - vector A(n), B(m); - long long sumA = 0, sumB = 0; - - for (int i = 0; i < n; i++){ - cin >> A[i]; - sumA += A[i]; - } - for (int i = 0; i < m; i++){ - cin >> B[i]; - sumB += B[i]; - } - - // Check the invariant: the total sum must be the same. - if(sumA != sumB){ - cout << ""No\n""; - continue; - } - - // Build frequency map for array A. - freq.clear(); - for(auto x : A) - freq[x]++; - - // Try to ""explain"" every number in B by splitting it as needed. - bool possible = true; - for(auto x : B){ - if(!dfs(x)){ - possible = false; - break; - } - } - - cout << (possible ? ""Yes"" : ""No"") << ""\n""; - } - - return 0; -} -","#include -#include -#include -#include -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while(t--){ - int n, m; - cin >> n >> m; - long long sumA = 0, sumB = 0; - vector a(n), b(m); - - for (int i = 0; i < n; i++){ - cin >> a[i]; - sumA += a[i]; - } - for (int i = 0; i < m; i++){ - cin >> b[i]; - sumB += b[i]; - } - - // The sum invariant must hold. - if(sumA != sumB){ - cout << ""No\n""; - continue; - } - - // Build a frequency map for the original numbers (sequence a). - unordered_map freq; - freq.reserve(n * 2); - for (auto x : a) - freq[x]++; - - // Use a max-heap to simulate splitting the numbers from b. - priority_queue pq; - for (auto x : b) - pq.push(x); - - int matched = 0; // number of elements from a that we have ""matched"" - bool possible = true; - - while(!pq.empty() && matched < n){ - long long cur = pq.top(); - pq.pop(); - // If cur appears in a then we “take” it. - if(freq.find(cur) != freq.end() && freq[cur] > 0){ - freq[cur]--; - matched++; - continue; - } - // If cur is 1 and it is not in a, then we cannot split it further. - if(cur == 1){ - possible = false; - break; - } - // Otherwise, split cur into the only two valid numbers. - if(cur % 2 == 0){ - pq.push(cur / 2); - pq.push(cur / 2); - } else { - pq.push(cur / 2); - pq.push(cur / 2 + 1); - } - } - - cout << (matched == n && possible ? ""Yes"" : ""No"") << ""\n""; - } - return 0; -} -",1 -maherkh,2061D - Kevin and Numbers,c++17 ,307242317,307247198,"// Problem: D. Kevin and Numbers -// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2) -// URL: https://codeforces.com/contest/2061/problem/D -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -using namespace std; -#define boost \ - ios::sync_with_stdio(false); \ - cin.tie(0); \ - cout.tie(0) - -///-----new feature----/// -#include -#include -using namespace __gnu_pbds; -///-end of new feature-/// - -#define scan(x) \ - do \ - { \ - while ((x = getchar()) < '0') \ - ; \ - int _; \ - for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0') \ - ; \ - } while (0) -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x.size()) -#define fi first -#define se second -#define pb push_back -#define mp make_pair - -#define dbg(x) cerr << "" - "" << #x << "": "" << x << endl; -#define dbgp(x) cerr << "" - "" << #x << "": "" << x.fi << "" , "" << x.se << endl; -#define dbg2(x, y) cerr << "" - "" << #x << "": "" << x << ""\t\t"" << #y << "": "" << y << endl; -#define dbgv(v, n) \ - cerr << #v << "" : "" << ""\n""; \ - for (int i = 0; i < n; i++) \ - cerr << ""\t"" << #v << ""["" << i << ""]"" << "" : "" << v[i] << ""\n""; \ - cerr << endl; -#define sep() cerr << ""--------------------"" << endl; - -#define REP(i, n) for (int i = 0; i < (n); i++) -#define FOR(i, a, b) for (int i = (a); i < (b); i++) -#define RFOR(i, b, a) for (int i = (b) - 1; i >= (a); i--) -#define GO(c, itr) for (auto itr = (c).begin(); itr != (c).end(); ++itr) - -#define nl ""\n"" -#define YES cout << ""YES"" << nl -#define NO cout << ""NO"" << nl -#define yes cout << ""yes"" << nl -#define no cout << ""no"" << nl -#define Yes cout << ""Yes"" << nl -#define No cout << ""No"" << nl -#define pyprint(x) cout << x << nl -#define errprint(x) cerr << x << nl - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pii; -typedef vector vi; -typedef vector vvi; -typedef vector vii; -const ll mod = 1e9 + 7; -const ll inf = 1e18; - -//---> Short Data Structures: -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; // aka indexed_set - -template -using min_heap = priority_queue, greater>; -// ordered_set s; -// s.insert(1); -// s.order_of_key(3); -// s.find_by_order(1); -// s.find(1); - -//---> Graph : -int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; - -//---> Number Theory : -ll gcd(ll a, ll b) -{ - while (b) - { - swap(a, b); - b %= a; - } - return (a); -} -ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -ll po2(ll b, ll e) -{ - if (e == 0) - return 1; - ll res = 1; - while (e > 1) - { - if (e % 2) - res = (res * b) % mod; - e /= 2; - b = (b * b) % mod; - } - return (res * b) % mod; -} -ll modInverse(ll a) { return po2(a, mod - 2); } -bool sortFirst(const pair &a, const pair &b) -{ - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first > b.first; -} - -void solve() { - ll n, m; - cin >> n >> m; - vector a(n), b(m); - map mpa, mpb; - - for (ll i = 0; i < n; i++) { - cin >> a[i]; - mpa[a[i]]++; - } - for (ll j = 0; j < m; j++) { - cin >> b[j]; - mpb[b[j]]++; - } - - // Remove common elements from both maps - for (auto it : mpa) { - if (mpb[it.first] != 0) { - int mn = min(mpa[it.first], mpb[it.first]); - mpa[it.first] -= mn; - mpb[it.first] -= mn; - } - } - - vector aa, bb; - for (auto it : mpa) { - for (int i = 0; i < it.second; i++) { - aa.pb(it.first); - } - } - for (auto it : mpb) { - for (int i = 0; i < it.second; i++) { - bb.pb(it.first); - } - } - - sort(all(aa)); - sort(all(bb)); - - ll ans = 0; - bool t = false; - vector vis(bb.size(), 0); - if(bb.size()>0){ - for (int i = 0; i < (int)aa.size(); i++) { - if(t){ - if(aa[i]-ans>1){ - NO; - return; - } - } - ans+=aa[i]; - //dbg(ans); - auto it = lower_bound(all(bb), ans) - bb.begin(); - //dbg(it); - while (it < bb.size() && vis[it]) { - it++; - } - t = true; - if (it < bb.size()&&!vis[it]&&ans==bb[it]) { - vis[it] = 1; - ans = 0; - t = false; - } - - } - }else{ - if(aa.size()>0){ - cout<<""NO""<> t; - while (t--) - solve(); - return 0; -} -","// Problem: D. Kevin and Numbers -// Contest: Codeforces - IAEPC Preliminary Contest (Codeforces Round 999, Div. 1 + Div. 2) -// URL: https://codeforces.com/contest/2061/problem/D -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include -using namespace std; -#define boost \ - ios::sync_with_stdio(false); \ - cin.tie(0); \ - cout.tie(0) - -///-----new feature----/// -#include -#include -using namespace __gnu_pbds; -///-end of new feature-/// - -#define scan(x) \ - do \ - { \ - while ((x = getchar()) < '0') \ - ; \ - int _; \ - for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0') \ - ; \ - } while (0) -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x.size()) -#define fi first -#define se second -#define pb push_back -#define mp make_pair - -#define dbg(x) cerr << "" - "" << #x << "": "" << x << endl; -#define dbgp(x) cerr << "" - "" << #x << "": "" << x.fi << "" , "" << x.se << endl; -#define dbg2(x, y) cerr << "" - "" << #x << "": "" << x << ""\t\t"" << #y << "": "" << y << endl; -#define dbgv(v, n) \ - cerr << #v << "" : "" << ""\n""; \ - for (int i = 0; i < n; i++) \ - cerr << ""\t"" << #v << ""["" << i << ""]"" << "" : "" << v[i] << ""\n""; \ - cerr << endl; -#define sep() cerr << ""--------------------"" << endl; - -#define REP(i, n) for (int i = 0; i < (n); i++) -#define FOR(i, a, b) for (int i = (a); i < (b); i++) -#define RFOR(i, b, a) for (int i = (b) - 1; i >= (a); i--) -#define GO(c, itr) for (auto itr = (c).begin(); itr != (c).end(); ++itr) - -#define nl ""\n"" -#define YES cout << ""YES"" << nl -#define NO cout << ""NO"" << nl -#define yes cout << ""yes"" << nl -#define no cout << ""no"" << nl -#define Yes cout << ""Yes"" << nl -#define No cout << ""No"" << nl -#define pyprint(x) cout << x << nl -#define errprint(x) cerr << x << nl - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pii; -typedef vector vi; -typedef vector vvi; -typedef vector vii; -const ll mod = 1e9 + 7; -const ll inf = 1e18; - -//---> Short Data Structures: -template -using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; // aka indexed_set - -template -using min_heap = priority_queue, greater>; -// ordered_set s; -// s.insert(1); -// s.order_of_key(3); -// s.find_by_order(1); -// s.find(1); - -//---> Graph : -int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; - -//---> Number Theory : -ll gcd(ll a, ll b) -{ - while (b) - { - swap(a, b); - b %= a; - } - return (a); -} -ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } -ll po2(ll b, ll e) -{ - if (e == 0) - return 1; - ll res = 1; - while (e > 1) - { - if (e % 2) - res = (res * b) % mod; - e /= 2; - b = (b * b) % mod; - } - return (res * b) % mod; -} -ll modInverse(ll a) { return po2(a, mod - 2); } -bool sortFirst(const pair &a, const pair &b) -{ - if (a.first == b.first) - { - return a.second > b.second; - } - return a.first > b.first; -} - -void solve() { - ll n, m; - cin >> n >> m; - vector a(n), b(m); - map mpa, mpb; - - // Read input and count occurrences - for (ll i = 0; i < n; i++) { - cin >> a[i]; - mpa[a[i]]++; - } - for (ll j = 0; j < m; j++) { - cin >> b[j]; - mpb[b[j]]++; - } - - // Remove common elements from both maps - for (auto it : mpa) { - if (mpb[it.first] != 0) { - int mn = min(mpa[it.first], mpb[it.first]); - mpa[it.first] -= mn; - mpb[it.first] -= mn; - } - } - - vector aa, bb; - for (auto it : mpa) { - for (int i = 0; i < it.second; i++) { - aa.push_back(it.first); - } - } - priority_queueq; - for (auto it : mpb) { - for (int i = 0; i < it.second; i++) { - q.push(it.first); - } - } - - sort(aa.begin(), aa.end()); - sort(bb.begin(), bb.end()); - - ll ans = 0; - bool t = false; - vector vis(bb.size(), 0); - int op = n-m; - while(!q.empty()&&op>0){ - ll nb =q.top(); - q.pop(); - if(nb%2==0){ - if(mpa[nb/2]>=2){ - mpa[nb/2]-=2; - }else{ - if(mpa[nb/2]>=1){ - mpa[nb/2]-=1; - q.push(nb/2); - }else{ - q.push(nb/2); - q.push(nb/2); - } - } - }else{ - if(mpa[nb/2]>=1&&mpa[nb/2+1]>=1){ - mpa[nb/2]-=1; - mpa[nb/2+1]-=1; - }else if(mpa[nb/2]>=1){ - mpa[nb/2]--; - q.push(nb/2+1); - }else if(mpa[nb/2+1]>=1){ - mpa[nb/2+1]--; - q.push(nb/2); - }else{ - q.push(nb/2); - q.push(nb/2+1); - } - } - op--; - } - if(q.empty()){ - for(auto it:mpa){ - if(it.second>0){ - cout<<""NO""<> t; - while (t--) - solve(); - return 0; -} -",2 -Nirmal3266,2061D - Kevin and Numbers,c++17 ,304756991,304854056,"#include -using namespace std; - -// JAY SHREE KRISHNA -// AUTHOR:- Solanki Nirmal Bhikhabhai - -// ------------------------------------------------------------------------------------------------------------ -#define hello ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -#define ll long long -#define ld long double -#define yes cout<<""YES""< llToBin(ll n){ - vector ans; - while(n!=0){ - ans.pb(n%2); - n/=2; - } - reverse(all(ans)); - return ans; -} - -vector isprime(1e6+1,1); -void sieve(int n){ - isprime[1]=0; - for(ll i=2;i*i<1000000;i++){ - if(isprime[i]!=0){ - for(ll j=i*i;j<1000000;j+=i) isprime[j]=0; - } - } -} - -void printvec(vector temp){ - for(ll i=0;i temp){ - for(auto it=temp.begin();it!=temp.end();it++) cout<fi<<"" ""<se<>n>>m; - vector a(n),b(m); - for(ll i=0;i>a[i]; - for(ll i=0;i>b[i]; - - priority_queue,greater>pqa (a.begin(),a.end()); - priority_queue,greater>pqb (b.begin(),b.end()); - bool flag=true; - while(!pqa.empty() && !pqb.empty()) - { - ll a1=pqa.top(); - ll b1=pqb.top(); - //cout<b1) - { - flag=false; - break; - } - pqa.pop(); - pqb.pop(); - if(a1==b1) - { - //cout<<""Hii""<0 || pqb.size()>0 || !flag) no; - else yes; - //cout<<""f ""<>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; - -// JAY SHREE KRISHNA -// AUTHOR:- Solanki Nirmal Bhikhabhai - -// ------------------------------------------------------------------------------------------------------------ -#define hello ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -#define ll long long -#define ld long double -#define yes cout<<""YES""< llToBin(ll n){ - vector ans; - while(n!=0){ - ans.pb(n%2); - n/=2; - } - reverse(all(ans)); - return ans; -} - -vector isprime(1e6+1,1); -void sieve(int n){ - isprime[1]=0; - for(ll i=2;i*i<1000000;i++){ - if(isprime[i]!=0){ - for(ll j=i*i;j<1000000;j+=i) isprime[j]=0; - } - } -} - -void printvec(vector temp){ - for(ll i=0;i temp){ - for(auto it=temp.begin();it!=temp.end();it++) cout<fi<<"" ""<se<&mp) -{ - //cout<0) - { - mp[val]--; - return true; - } - if(val==1) return false; - ll v1=val/2,v2=val/2; - if(val%2!=0) v2++; - if(!f(v1,mp)) return false; - if(!f(v2,mp)) return false; - return true; -} -void solve(){ - ll n,m; cin>>n>>m; - vector a(n),b(m); - for(ll i=0;i>a[i]; - for(ll i=0;i>b[i]; - - mapmp; - for(auto it:a) mp[it]++; - bool flag=true; - for(auto it:b) - { - if(!f(it,mp)) - { - flag=false; - break; - } - } - for(auto it:mp) - { - if(it.second>0) - { - flag=false; - break; - } - } - if(flag) yes; - else no; -} - -int32_t main(){ - hello; - int t; cin>>t; - while(t--){ - solve(); - } - return 0; -}",2 -veg_ff,2061D - Kevin and Numbers,c++17 ,307158659,307159765,"#include -using namespace std; -int T,n,m,a[200005],b[200005]; -priority_queue pq; -map ma,mb; -int main(){ - cin>>T; - for(int i=1;i<=T;i++){ - ma.clear(),mb.clear(); - while(!pq.empty()) - pq.pop(); - cin>>n>>m; - int op=n-m; - for(int j=1;j<=n;j++){ - cin>>a[j]; - ma[a[j]]++; - } - for(int j=1;j<=m;j++){ - cin>>b[j]; - mb[b[j]]++; - } - for (auto it=ma.begin();it!=ma.end();){ - int x=it->first; - if(mb.count(x)){ - if(ma[x]first; - pq.push(x); - } - while((!pq.empty())&&op>0){ - int x=pq.top(); - pq.pop(); - if(x==1) - break; - if(x%2){ - if(ma.count(x/2+1)){ - if(ma[x/2+1] -using namespace std; -int T,n,m,a[200005],b[200005]; -priority_queue pq; -map ma,mb; -int main(){ - cin>>T; - for(int i=1;i<=T;i++){ - ma.clear(),mb.clear(); - while(!pq.empty()) - pq.pop(); - cin>>n>>m; - int op=n-m; - for(int j=1;j<=n;j++){ - cin>>a[j]; - ma[a[j]]++; - } - for(int j=1;j<=m;j++){ - cin>>b[j]; - mb[b[j]]++; - } - for (auto it=ma.begin();it!=ma.end();){ - int x=it->first; - if(mb.count(x)){ - if(ma[x]first; - pq.push(x); - } - while((!pq.empty())&&op>0){ - int x=pq.top(); - pq.pop(); - if(x==1) - break; - if(x%2){ - if(ma.count(x/2+1)){ - if(ma[x/2+1] - -typedef long long ll; -using namespace std; -#define MOD 1000000007 -#define MAX_N 200000 - -// vector fact(MAX_N + 1), inv_fact(MAX_N + 1); - -// long long mod_inverse(long long x, long long mod) { -// long long result = 1; -// long long power = mod - 2; -// while (power) { -// if (power & 1) result = result * x % mod; -// x = x * x % mod; -// power >>= 1; -// } -// return result; -// } - -// void precompute_factorials() { -// fact[0] = inv_fact[0] = 1; -// for (int i = 1; i <= MAX_N; ++i) { -// fact[i] = fact[i - 1] * i % MOD; -// } -// inv_fact[MAX_N] = mod_inverse(fact[MAX_N], MOD); -// for (int i = MAX_N - 1; i >= 1; --i) { -// inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD; -// } -// inv_fact[0] = 1; -// } - -// long long comb(int n, int k) { -// if (k > n || k < 0) return 0; -// return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD; -// } - -void solve() -{ - int n, m; - cin >> n >> m; - priority_queue < ll, vector < ll > , greater < ll >> q; - map < ll, int > mp; - for (int i = 0; i < n; i++) - { - int val; - cin >> val; - q.push(val); - } - for (int i = 0; i < m; i++) - { - int val; - cin >> val; - mp[val]++; - } - - while (!q.empty() && n >= m) - { - ll first = q.top(); - q.pop(); - n--; - if (mp[first] > 0) - { - mp[first]--; - m--; - } - else if (!q.empty() && abs(first - q.top()) <= 1) - { - if (mp[first + q.top()] > 0) { - mp[first + q.top()]--; - q.pop(); - n--; - m--; - } - else - { - ll val = q.top(); - q.pop(); - q.push({ - first + val - }); - - } - - } - else - { - cout << ""NO"" << ""\n""; - return; - } - } - if(m==0) - cout << ""YES"" << ""\n""; - else - cout<<""NO""<<""\n""; - -} - - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - int t; - cin >> t; - while (t--) - { - - - solve(); - - } - return 0; - - - -}","#include - -typedef long long ll; -using namespace std; -#define MOD 1000000007 -#define MAX_N 200000 - -// vector fact(MAX_N + 1), inv_fact(MAX_N + 1); - -// long long mod_inverse(long long x, long long mod) { -// long long result = 1; -// long long power = mod - 2; -// while (power) { -// if (power & 1) result = result * x % mod; -// x = x * x % mod; -// power >>= 1; -// } -// return result; -// } - -// void precompute_factorials() { -// fact[0] = inv_fact[0] = 1; -// for (int i = 1; i <= MAX_N; ++i) { -// fact[i] = fact[i - 1] * i % MOD; -// } -// inv_fact[MAX_N] = mod_inverse(fact[MAX_N], MOD); -// for (int i = MAX_N - 1; i >= 1; --i) { -// inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD; -// } -// inv_fact[0] = 1; -// } - -// long long comb(int n, int k) { -// if (k > n || k < 0) return 0; -// return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD; -// } - -void solve() -{ - int n, m; - cin >> n >> m; - - map < ll, int > mp; - - - for (int i = 0; i < n; i++) - { - int val; - cin >> val; - mp[val]++; - - } - priority_queue < int, vector < int > , greater < int >> q; - - for (int i = 0; i < m; i++) - { - int val; - cin >> val; - q.push(val); - - } - int c = n - m; - while (!q.empty() && c) - { - if (mp[q.top()] > 0) - { - mp[q.top()]--; - q.pop(); - } - else - { - int val = q.top(); - q.pop(); - q.push(val / 2); - q.push(ceil(val / 2.0)); - c--; - } - - } - - while (!q.empty()) - { - if (mp[q.top()] == 0) - { - cout << ""NO\n""; - return; - } - mp[q.top()]--; - q.pop(); - } - for (auto i: mp) - { - if (i.second) - { - cout << ""NO\n""; - return; - } - } - cout << ""YES"" << ""\n""; - - -} - - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - int t; - cin >> t; - while (t--) - { - - - solve(); - - } - return 0; - - - -}",2 -doublenn,2061D - Kevin and Numbers,c++23 ,303862024,303860675,"#include -#define int long long -using namespace std; - -bool solve(){ - int n,m,x; - cin>>n>>m; - priority_queue a,b; - for(int i=0;i>x; - a.push(x); - } - for(int j=0;j>x; - b.push(x); - } - int flag=0; - while(a.size()&&b.size()){ - if(a.top()>b.top()||a.size()>1); - b.push(u+1>>1); - } - return a.empty()&&b.empty(); -} -signed main(){ - int t; - cin>>t; - while(t--){ - cout<<(solve()?""Yes"":""No"")< -#define int long long -using namespace std; - -const int N=2e5+50; -int a[N],b[N]; - -signed main(){ - int t; - cin>>t; - while(t--){ - int n,m; - cin>>n>>m; - map p2; - int sum1=0,sum2=0; - for(int i=0;i>a[i]; - sum1+=a[i]; - } - for(int j=0;j>b[j]; - p2[b[j]]++; - sum2+=b[j]; - } - if(sum1!=sum2){ - cout<<""No""< v; - sort(a,a+n); - for(int i=0;i=1){ - p2[a[i]]--; - }else{ - - if(!v.empty()){ - if(p2[v.back()]>=1){ - p2[v.back()]--; - v.pop_back(); - } - if(!v.empty()&&abs(v.back()-a[i])<=1){ - int u=v.back(); - v.pop_back(); - v.push_back(a[i]+u); - // cout<=1){ - p2[v.back()]--; - v.pop_back(); - } - }else{ - v.push_back(a[i]); - } - } - } - int flag=0; - for(auto i:p2){ - if(i.second>0){ - flag=1; - break; - } - } - if(!v.empty()||flag){ - cout<<""No""< -#include - -#define ll long long int -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define vi vector -#define vl vector -#define all(a) a.begin(),a.end() -#define rep(i, a, b) for (ll i = a; i < b; i++) -#define rev(i, a, b) for (ll i = a; i >= b; i--) -#define pi 3.141592653589793238462643383279 -#define TEMP_SIZE 1000005 -using namespace std; -using namespace __gnu_pbds; - -const long long INF = (long long)1e15; -long double eps = 1e-6; -const ll MOD = 998244353; - -// orderedset - -template using ordered_set =tree, rb_tree_tag,tree_order_statistics_node_update> ; - -// vector ad[TEMP_SIZE], newgraph[TEMP_SIZE]; -// ll vis[TEMP_SIZE]; - - -vector fact; -vector inv; - -long long pow(long long a, long long b) -{ - - long long res = 1; - while (b > 0) - { - if (b & 1) - res = res * a; - } - return res; -} - -void factinit(ll MOD) -{ - fact.assign(TEMP_SIZE, 0); - fact[0] = 1; - for (ll i = 1; i < TEMP_SIZE; i++) - { - fact[i] = (fact[i - 1] * i) % MOD; - } -} - -long long powm(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 /= 2; - } - - return res; -} - -void invinit() -{ - inv.assign(TEMP_SIZE, 0); - inv[1] = 1; - for (ll i = 2; i < TEMP_SIZE; i++) - { - inv[i] = powm(i, MOD - 2, MOD); - } -} - -ll nCr(ll n, ll r) -{ - return ((fact[n] * powm(fact[r], MOD - 2, MOD)) % MOD * powm(fact[n - r], MOD - 2, MOD)) % MOD; -} - -bool compare(const pair &i, const pair &j) -{ - return i.second < j.second; -} - -ll mex(vector &arr, ll N) -{ - sort(arr.begin(),arr.end()); - int mex = 0; - for (int idx = 0; idx < N; idx++) - { - if (arr[idx] == mex) - { - mex += 1; - } - } - - return mex; -} - -ll sod(ll n) -{ - ll sum = 0; - while (n) - { - sum += n % 10; - n /= 10; - } - return sum; -} - -ll poss(ll a[], ll n, ll k, ll mid) -{ - map f; - rep(i, 0, n) - { - f[a[i]]++; - } - ll sum = 0, need = mid * k; - for (auto i : f) - { - sum += min(mid, i.second); - } - if (sum >= need) - return 1; - else - return 0; -} - -double nthRoot(ll A, ll n) -{ - double val = round(exp(log(A) / n) * 1e9) / 1e9; - return val; -} - -vector vis; -vector ans; -int component_index = 0; - -void dfs(vector > &g, int node) -{ - - vis[node] = true; - for (auto p: g[node]) - { - if (!vis[p]) - { - dfs(g, p); - } - } - return; -} - - - -void solve() -{ - int n, m; - cin>>n>>m; - vi a(n), b(m); - rep(i,0,n) cin>>a[i]; - rep(i,0,m) cin>>b[i]; - - multiset m1; - - sort(all(a)); - - - - rep(i,0,m) m1.insert(b[i]); - - int cnt = n-m; - - int i = n-1; - while (!m1.empty() && i>=0) - { - auto it = next(m1.begin(), m1.size()-1); - int val = *it; - m1.erase(it); - if (val == a[i]) - { - i--; - } - else if (val < a[i]) - { - cout<<""No""<=0) - { - cout<<""No""<>t; - - while (t--) - { - solve(); - } -} -","#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx2,bmi,bmi2,popcnt,lzcnt"") -// #pragma GCC target(""avx2,sse4.2,bmi,bmi2,popcnt,lzcnt"") -#include -#include - -#define ll long long int -#define pb push_back -#define ppb pop_back -#define F first -#define S second -#define vi vector -#define vl vector -#define all(a) a.begin(),a.end() -#define rep(i, a, b) for (ll i = a; i < b; i++) -#define rev(i, a, b) for (ll i = a; i >= b; i--) -#define pi 3.141592653589793238462643383279 -#define TEMP_SIZE 1000005 -using namespace std; -using namespace __gnu_pbds; - -const long long INF = (long long)1e15; -long double eps = 1e-6; -const ll MOD = 998244353; - -// orderedset - -template using ordered_set =tree, rb_tree_tag,tree_order_statistics_node_update> ; - -// vector ad[TEMP_SIZE], newgraph[TEMP_SIZE]; -// ll vis[TEMP_SIZE]; - - -vector fact; -vector inv; - -long long pow(long long a, long long b) -{ - - long long res = 1; - while (b > 0) - { - if (b & 1) - res = res * a; - } - return res; -} - -void factinit(ll MOD) -{ - fact.assign(TEMP_SIZE, 0); - fact[0] = 1; - for (ll i = 1; i < TEMP_SIZE; i++) - { - fact[i] = (fact[i - 1] * i) % MOD; - } -} - -long long powm(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 /= 2; - } - - return res; -} - -void invinit() -{ - inv.assign(TEMP_SIZE, 0); - inv[1] = 1; - for (ll i = 2; i < TEMP_SIZE; i++) - { - inv[i] = powm(i, MOD - 2, MOD); - } -} - -ll nCr(ll n, ll r) -{ - return ((fact[n] * powm(fact[r], MOD - 2, MOD)) % MOD * powm(fact[n - r], MOD - 2, MOD)) % MOD; -} - -bool compare(const pair &i, const pair &j) -{ - return i.second < j.second; -} - -ll mex(vector &arr, ll N) -{ - sort(arr.begin(),arr.end()); - int mex = 0; - for (int idx = 0; idx < N; idx++) - { - if (arr[idx] == mex) - { - mex += 1; - } - } - - return mex; -} - -ll sod(ll n) -{ - ll sum = 0; - while (n) - { - sum += n % 10; - n /= 10; - } - return sum; -} - -ll poss(ll a[], ll n, ll k, ll mid) -{ - map f; - rep(i, 0, n) - { - f[a[i]]++; - } - ll sum = 0, need = mid * k; - for (auto i : f) - { - sum += min(mid, i.second); - } - if (sum >= need) - return 1; - else - return 0; -} - -double nthRoot(ll A, ll n) -{ - double val = round(exp(log(A) / n) * 1e9) / 1e9; - return val; -} - -vector vis; -vector ans; -int component_index = 0; - -void dfs(vector > &g, int node) -{ - - vis[node] = true; - for (auto p: g[node]) - { - if (!vis[p]) - { - dfs(g, p); - } - } - return; -} - - - -void solve() -{ - int n, m; - cin>>n>>m; - vi a(n), b(m); - rep(i,0,n) cin>>a[i]; - rep(i,0,m) cin>>b[i]; - - sort(all(a)); - - priority_queue pq; - rep(i,0,m) pq.push(b[i]); - - int cnt = n-m; - - int i = n-1; - while (!pq.empty() && i>=0) - { - - int val = pq.top(); - pq.pop(); - - if (val == a[i]) - { - i--; - } - else if (val < a[i]) - { - cout<<""No""<=0) - { - cout<<""No""<>t; - - while (t--) - { - solve(); - } -} -",2 -apoloand,2061D - Kevin and Numbers,c++20 ,302881304,302877246,"#include -using namespace std; -#define int long long -#define pp pair -const int N = 2e5 + 9; -const int inf = 0x3f3f3f3f3f3f3f3f; -const int mod = 998244353; - - -void solve() { - int n, m;cin >> n >> m; - map mp; - for (int i = 0;i < n;i++) { - int x;cin >> x; - mp[x]++; - } - priority_queue, greater> pq; - for (int i = 0;i < m;i++) { - int x;cin >> x; - pq.push(x); - } - while (pq.size()) { - int x = pq.top();pq.pop(); - if (mp[x])mp[x]--; - else { - if (x == 1) { - cout << ""No\n"";return; - } - else if (x % 2) { - pq.push(x / 2);pq.push(x / 2+1); - } - else { - pq.push(x / 2);pq.push(x / 2); - } - } - } - for(auto[x,y]:mp){ - if(y){ - cout << ""No\n"";return; - } - } - cout << ""Yes\n""; -} -signed main() { - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - int _ = 1; - cin >> _; - while (_--)solve(); - return 0; -}","#include -using namespace std; -#define int long long -#define pp pair -const int N = 2e5 + 9; -const int inf = 0x3f3f3f3f3f3f3f3f; -const int mod = 998244353; - - -void solve() { - int n, m;cin >> n >> m; - map mp; - priority_queue, greater> pq; - for (int i = 0;i < n;i++) { - int a;cin >> a;pq.push(a); - } - for (int i = 0;i < m;i++) { - int a;cin >> a; - mp[a]++; - } - - while (pq.size()>=2) { - while (pq.size()) { - int a = pq.top(); - if (mp[a] > 0) { - mp[a]--;pq.pop(); - } - else break; - } - if (pq.size() >= 2) { - int a = pq.top();pq.pop(); - int b = pq.top();pq.pop(); - if (b - a <= 1) { - pq.push(b + a); - } - else { - cout << ""No\n"";return; - } - } - } - if (pq.size() == 1) { - if(mp[pq.top()] > 0){mp[pq.top()]--;pq.pop();} - } - if(pq.size() > 0){ - cout << ""No\n"";return; - } - for (auto [x, y] : mp) { - if(y > 0){ - cout << ""No\n"";return; - } - } - cout << ""Yes\n""; -} -signed main() { - ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); - int _ = 1; - cin >> _; - while (_--)solve(); - return 0; -}",1 -SLEEPY_INTROVERT,2061D - Kevin and Numbers,c++17 ,308727325,308726526,"#include - -using namespace std; - -#define fast_cin() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define ll long long -#define vi vector -#define all(a) a.begin(), a.end() -#define fi first -#define se second - -const ll MOD = 1000000007; -struct mint -{ - int v; - explicit operator int() const { return v; } - mint() : v(0) {} - mint(ll _v) : v(int(_v % MOD)) { v += (v < 0) * MOD; } -}; -mint &operator+=(mint &a, mint b) -{ - if ((a.v += b.v) >= MOD) - a.v -= MOD; - return a; -} -mint &operator-=(mint &a, mint b) -{ - if ((a.v -= b.v) < 0) - a.v += MOD; - return a; -} -mint operator+(mint a, mint b) { return a += b; } -mint operator-(mint a, mint b) { return a -= b; } -mint operator*(mint a, mint b) { return mint((ll)a.v * b.v); } -mint &operator*=(mint &a, mint b) { return a = a * b; } -mint pow(mint a, ll p) -{ - assert(p >= 0); - return p == 0 ? 1 : pow(a * a, p / 2) * (p & 1 ? a : 1); -} -mint inv(mint a) -{ - assert(a.v != 0); - return pow(a, MOD - 2); -} -mint operator/(mint a, mint b) { return a * inv(b); } -bool operator==(mint a, mint b) { return a.v == b.v; } - -void solve() -{ - int n, m; - cin >> n >> m; - priority_queue pq1, pq2; - while (n--) - { - int x; - cin >> x; - pq1.push(x); - } - while (m--) - { - int x; - cin >> x; - pq2.push(x); - } - while (pq1.size() && pq2.size()) - { - if (pq1.top() == pq2.top()) - { - pq1.pop(); - pq2.pop(); - } - else if (pq1.top() > pq2.top() || pq1.size() < pq2.size()) - { - cout << ""no"" << endl; - return; - } - else - { - int a = pq2.top(); - pq2.pop(); - pq2.push(a / 2); - pq2.push((a + 1) / 2); - } - } - if (pq1.size() || pq2.size()) - { - cout << ""no"" << endl; - return; - } - cout << ""yes"" << endl; -} - -int main() -{ - fast_cin(); - ll t; - cin >> t; - for (int it = 1; it <= t; it++) - { - solve(); - } - return 0; -}","#include - -using namespace std; - -#define fast_cin() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define ll long long -#define vi vector -#define all(a) a.begin(), a.end() -#define fi first -#define se second - -const ll MOD = 1000000007; -struct mint -{ - int v; - explicit operator int() const { return v; } - mint() : v(0) {} - mint(ll _v) : v(int(_v % MOD)) { v += (v < 0) * MOD; } -}; -mint &operator+=(mint &a, mint b) -{ - if ((a.v += b.v) >= MOD) - a.v -= MOD; - return a; -} -mint &operator-=(mint &a, mint b) -{ - if ((a.v -= b.v) < 0) - a.v += MOD; - return a; -} -mint operator+(mint a, mint b) { return a += b; } -mint operator-(mint a, mint b) { return a -= b; } -mint operator*(mint a, mint b) { return mint((ll)a.v * b.v); } -mint &operator*=(mint &a, mint b) { return a = a * b; } -mint pow(mint a, ll p) -{ - assert(p >= 0); - return p == 0 ? 1 : pow(a * a, p / 2) * (p & 1 ? a : 1); -} -mint inv(mint a) -{ - assert(a.v != 0); - return pow(a, MOD - 2); -} -mint operator/(mint a, mint b) { return a * inv(b); } -bool operator==(mint a, mint b) { return a.v == b.v; } - -multiset f(int target, multiset &s) -{ - // cout << target << endl; - if (s.find(target) != s.end()) - { - s.erase(s.find(target)); - return {target}; - } - if (s.empty() || target < *s.begin()) - return {-1}; - // cout << target / 2 << endl; - multiset temp = f(target / 2, s); - if (temp.find(-1) != temp.end()) - return {-1}; - // cout << (target + 1) / 2 << endl; - multiset temp2 = f((target + 1) / 2, s); - if (temp2.find(-1) != temp2.end()) - return {-1}; - temp.insert(all(temp2)); - return temp; -} - -void solve() -{ - int n, m; - cin >> n >> m; - multiset s1, s2, s; - for (int i = 0; i < n; i++) - { - ll x; - cin >> x; - s1.insert(x); - } - for (int i = 0; i < m; i++) - { - ll x; - cin >> x; - if (s1.find(x) != s1.end()) - s1.erase(s1.find(x)); - else - s2.insert(x); - } - if (m > n || (s2.size() == 0 && s1.size() > 0)) - { - cout << ""NO"" << endl; - return; - } - if (s1.size() == 0) - { - cout << ""YES"" << endl; - return; - } - for (auto rit = s2.rbegin(); rit != s2.rend(); rit++) - { - s = s1; - multiset ans = f(*rit, s); - if (ans.find(-1) != ans.end()) - { - cout << ""NO"" << endl; - return; - } - s1.swap(s); - } - // cout << s1.size() << endl; - if (s1.size() == 0) - { - cout << ""YES"" << endl; - } - else - { - cout << ""NO"" << endl; - } -} - -int main() -{ - fast_cin(); - ll t; - cin >> t; - for (int it = 1; it <= t; it++) - { - solve(); - } - return 0; -}",1 -brokie,2061D - Kevin and Numbers,c++20 ,314411647,314411513,"#include - -using namespace std; - - - -typedef long long ll; - -#define pb push_back - - - -const int mxN = 2e5 + 5; - -int a[mxN], b[mxN]; - - - -void solve(){ - - int n, m; cin >> n >> m; - - ll sm = 0; - - for (int i = 0; i < n; i++) cin >> a[i], sm += a[i]; - - for (int i = 0; i < m; i++) cin >> b[i], sm -= b[i]; - - - - if(sm != 0) { cout << ""NO\n""; return; } - - priority_queue pqa, pqb; for (int i = 0; i < m; i++) pqb.push(b[i]); for(int i = 0; i < n; i++) pqa.push(a[i]); - - - - while(!pqa.empty() && !pqb.empty()){ - - int x = pqa.top(); pqa.pop(); - - int y = pqb.top(); pqb.pop(); - - if (x == y) continue; - - if ( x > y || y == 1) { cout << ""NO\n""; return; } - - pqb.push(y / 2); pqb.push((y + 1) / 2); pqa.push(x); - - } - - cout << (pqa.empty() && pqb.empty() ? ""YES\n"" : ""NO\n""); - -} - - - -int main(){ - - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int t; cin >> t; - - while(t--) solve(); - - return 0; - -}","#include - -using namespace std; - - - -typedef long long ll; - -#define pb push_back - - - -const int mxN = 2e5 + 5; - -int a[mxN], b[mxN]; - - - -void solve(){ - - int n, m; cin >> n >> m; - - ll sm = 0; - - for (int i = 0; i < n; i++) cin >> a[i], sm += a[i]; - - for (int i = 0; i < m; i++) cin >> b[i], sm -= b[i]; - - - - if(sm != 0) { cout << ""NO\n""; return; } - - priority_queue pqa, pqb; for (int i = 0; i < m; i++) pqb.push(b[i]); for(int i = 0; i < n; i++) pqa.push(a[i]); - - - - while(!pqa.empty() && !pqb.empty()){ - - int x = pqa.top(); pqa.pop(); - - int y = pqb.top(); pqb.pop(); - - if (x == y) continue; - - if (y == 1) { cout << ""NO\n""; return; } - - pqb.push(y / 2); pqb.push((y + 1) / 2); pqa.push(x); - - } - - cout << (pqa.empty() && pqb.empty() ? ""YES\n"" : ""NO\n""); - -} - - - -int main(){ - - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int t; cin >> t; - - while(t--) solve(); - - return 0; - -}",1 -sn0vvl4nd3r,2061D - Kevin and Numbers,c++17 ,304695848,304695341,"#include -using namespace std; - -#define ll long long -#define vl vector - -bool rec(ll x, multiset &s) { - auto it = s.find(x); - if (it != s.end()) { - s.erase(it); - return true; - } - if (x == 1) - return false; - ll l = x / 2; - ll r = x - l; - return rec(l, s) && rec(r, s); -} - -int main(void) { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int t = 0; - cin >> t; - while(t--) { - int n = 0, m = 0; - cin >> n >> m; - vl a(n), b(m); - ll suma = 0, sumb = 0; - for (int i = 0; i < n; i++) { - cin >> a[i]; - suma += a[i]; - } - for (int i = 0; i < m; i++) { - cin >> b[i]; - sumb += b[i]; - } - if(suma != sumb) { - cout << ""No\n""; - continue; - } - multiset s; - for(auto x : a) - s.insert(x); - sort(b.begin(), b.end(), greater()); - bool possible = true; - for(auto x : b) { - if(!rec(x, s)){ - possible = false; - break; - } - } - cout << (possible && s.empty() ? ""Yes"" : ""No"") << ""\n""; - } - return 0; -} -","#include -using namespace std; - -#define ll long long -#define vl vector -#define uli unordered_map - -struct Node { - ll val, cnt; -}; - -struct cmp { - bool operator() (const Node &a, const Node &b) { - return a.val < b.val; - } -}; - -int main(void){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - - int t = 0; - cin >> t; - while (t--) { - int n = 0, m = 0; - cin >> n >> m; - vl a(n), b(m); - ll suma = 0, sumb = 0; - for (int i = 0; i < n; i++) { - cin >> a[i]; - suma += a[i]; - } - for (int i = 0; i < m; i++) { - cin >> b[i]; - sumb += b[i]; - } - if (suma != sumb) { - cout << ""No\n""; - continue; - } - uli freq; - freq.reserve(n * 2); - for (ll x : a) { - freq[x]++; - } - uli board; - board.reserve(m * 2); - for (ll x : b) { - board[x]++; - } - priority_queue, cmp> pq; - for (auto &p : board) { - pq.push(Node{p.first, p.second}); - } - bool possible = true; - ll matched = 0; - const ll total = n; - while (!pq.empty() && matched < total) { - Node cur = pq.top(); - pq.pop(); - if (board.find(cur.val) == board.end() || board[cur.val] != cur.cnt) - continue; - ll x = cur.val; - ll cnt = cur.cnt; - if (freq.find(x) != freq.end()) { - ll use = min(freq[x], cnt); - freq[x] -= use; - matched += use; - cnt -= use; - } - board.erase(x); - if (cnt > 0) { - if (x == 1) { - possible = false; - break; - } - ll l = x / 2; - ll r = x - l; - board[l] += cnt; - board[r] += cnt; - pq.push(Node{l, board[l]}); - pq.push(Node{r, board[r]}); - } - } - for (auto &p : freq) { - if (p.second > 0) { - possible = false; - break; - } - } - cout << (possible ? ""Yes"" : ""No"") << ""\n""; - } - return 0; -} -",1 -hippo19,2061D - Kevin and Numbers,c++23 ,302684591,302684231,"#include -using namespace std; - -#ifdef LOCAL -template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << "", "" << p.second << ')'; } -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = "", ""; return os << '}'; } -void dbg_out() { cerr << ""\033[0m"" << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#define dbg(...) cerr<<""\033[1;31m""<< ""LINE ""<<__LINE__<<"": -> ["" << #__VA_ARGS__ << ""]:"", dbg_out(__VA_ARGS__) -#else -#define dbg(...) 19 -#endif - -#define int int64_t -#define sz(x) int(x.size()) - -bool check(multiset& A, multiset& B){ - if(sz(A) and sz(B)){ - int mxA = *A.rbegin(); - int mxB = *B.rbegin(); - if(mxB < mxA){ - return false; - } - int mnA = *A.begin(); - int mnB = *B.begin(); - if(mnB < mnA){ - return false; - } - return true; - } else{ - return false; - } -} - -void solve(int tt){ - int N, M; cin >> N >> M; - multiset A, B; - for(int i = 0; i < N; ++i){ - int x; cin >> x; - A.insert(x); - } - for(int i = 0; i < M; ++i){ - int x; cin >> x; - B.insert(x); - } - - vector toRemove; - map freqB; - for(int x : B){ - freqB[x]++; - } - map freqA; - for(int x : A){ - freqA[x]++; - } - - map freq; - for(auto [k, v] : freqB){ - if(freqA.count(k)){ - freq[k] = min(v, freqA[k]); - } - } - - for(auto [k, v] : freq){ - for(int i = 0; i < v; ++i){ - A.extract(k); - B.extract(k); - } - } - - // overlap B to A - while(true){ - dbg(A, B); - if(sz(A) == sz(B) and sz(A) == 0){ - break; - } - dbg(check(A, B)); - if(!check(A, B)){ - cout << ""No\n""; - return; - } else{ - int mn = *B.begin(); - int a = mn/2; - int b = mn - a; - B.extract(mn); - B.insert(a); - B.insert(b); - dbg(A, B); - vector toRemove; - if(B.find(a) != B.end() and A.find(a) != A.end()){ - toRemove.push_back(a); - } - if(sz(toRemove)){ - B.extract(toRemove.back()); - A.extract(toRemove.back()); - toRemove.clear(); - } - if(B.find(b) != B.end() and A.find(b) != A.end()){ - toRemove.push_back(b); - } - if(sz(toRemove)){ - B.extract(toRemove.back()); - A.extract(toRemove.back()); - toRemove.clear(); - } - } - } - cout << ""Yes\n""; -} - -int32_t main(){ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int T=1; cin >> T; - for(int tt = 1; tt <= T; ++tt){ - solve(tt); - } -}","#include -using namespace std; - -#ifdef LOCAL -template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << "", "" << p.second << ')'; } -template::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = "", ""; return os << '}'; } -void dbg_out() { cerr << ""\033[0m"" << endl; } -template void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } -#define dbg(...) cerr<<""\033[1;31m""<< ""LINE ""<<__LINE__<<"": -> ["" << #__VA_ARGS__ << ""]:"", dbg_out(__VA_ARGS__) -#else -#define dbg(...) 19 -#endif - -#define int int64_t -#define sz(x) int(x.size()) - -bool check(multiset& A, multiset& B){ - if(sz(A) and sz(B)){ - int mxA = *A.rbegin(); - int mxB = *B.rbegin(); - if(mxB < mxA){ - return false; - } - int mnA = *A.begin(); - int mnB = *B.begin(); - if(mnB < mnA){ - return false; - } - return true; - } else{ - return false; - } -} - -void solve(int tt){ - int N, M; cin >> N >> M; - multiset A, B; - for(int i = 0; i < N; ++i){ - int x; cin >> x; - A.insert(x); - } - for(int i = 0; i < M; ++i){ - int x; cin >> x; - B.insert(x); - } - - vector toRemove; - for(int x : B){ - if(A.find(x) != A.end()){ - toRemove.push_back(x); - } - } - dbg(A, B, toRemove); - for(int x : toRemove){ - A.extract(x); - B.extract(x); - } - - // overlap B to A - while(true){ - dbg(A, B); - if(sz(A) == sz(B) and sz(A) == 0){ - break; - } - if(!check(A, B)){ - cout << ""No\n""; - return; - } else{ - int mn = *B.begin(); - int a = mn/2; - int b = mn - a; - B.extract(mn); - B.insert(a); - B.insert(b); - dbg(A, B); - vector toRemove; - if(B.count(a) and A.count(a)){ - toRemove.push_back(a); - } - if(B.count(b) and A.count(b)){ - toRemove.push_back(b); - } - for(int x : toRemove){ - B.extract(x); - A.extract(x); - if((!sz(A) and sz(B)) or (sz(A) and !sz(B))){ - cout << ""No\n""; - return; - } - } - } - } - cout << ""Yes\n""; -} - -int32_t main(){ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int T=1; cin >> T; - for(int tt = 1; tt <= T; ++tt){ - solve(tt); - } -}",1 -halaaa,2061D - Kevin and Numbers,c++20 ,302330653,302330879,"#include -#define ll long long -#define mod 998244353 -using namespace std; -mapmp; -bool rec(int i){ - if(mp[i]) { - mp[i]--; - if(mp[i]==0) mp.erase(i); - return 1; - } - if((mp.begin()->first)>t; - string s; - while(t--){ - cin>>n>>m; - ll sum1=0,sum2=0; - vectora(n),b(m); - for(auto&it:a) cin>>it,mp[it]++,sum1+=it; - for(auto&it:b) cin>>it,sum2+=it; - bool f=1; - if(sum1!=sum2){ - cout<<""NO\n""; - continue; - } - sort(b.begin(),b.end()); - for(int i=0;i -#define ll long long -#define mod 998244353 -using namespace std; -mapmp; -ll ct,n,m; -bool rec(int i){ - if(mp.begin()->first>i) - return 0; - if(mp[i]) { - mp[i]--; - if(mp[i]==0) - mp.erase(i); - return 1; - } - ct++; - if(ct>n-m) return 0; - return rec((i+1)/2)&rec(i/2); - -} -int main() -{ - //freopen(""input.txt"",""r"",stdin); - //freopen(""out.txt"",""w"",stdout); - ios_base::sync_with_stdio(false); - cin.tie(nullptr), cout.tie(nullptr); - ll t; cin>>t; - string s; - while(t--){ - ct=0; - cin>>n>>m; - ll sum1=0,sum2=0; - vectora(n),b(m); - for(auto&it:a) cin>>it,mp[it]++,sum1+=it; - for(auto&it:b) cin>>it,sum2+=it; - bool f=1; - if(sum1!=sum2){ - mp.clear(); - cout<<""NO\n""; - continue; - } - sort(b.begin(),b.end()); - for(int i=0;in-m) f=0; - if(!f) break; - } - if(f) cout<<""YES\n""; else cout<<""NO\n""; - mp.clear(); - } - return 0; -}",2 -NazmulGo,2061D - Kevin and Numbers,c++20 ,302752166,302744772,"#include -using namespace std; -typedef long long ll; -typedef long double ld; - -#define pb push_back -#define MOD 1000000007 -#define vll vector -#define pll pair -#define endl ""\n"" -#define all(v) v.begin(), v.end() -#define mem(a,b) memset(a, b, sizeof(a)) -#define co(n) cout << n << endl -#define yes cout << ""Yes"" << endl -#define no cout << ""No"" << endl -#define fr(x, n) for (int i = x; i < n; ++i) -#define fraction(x) cout << fixed << setprecision(x) -#define Baba_Yaga ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); - -const double eps = 1e-9; -const int N = 2e5+123; - -ll gcd(ll a,ll b) { return __gcd(a,b); } -ll lcm(ll a,ll b) { return (a*b)/__gcd(a,b); } - -int dx[] = {0, 0, +1, -1, +1, +1, -1, -1}; -int dy[] = {+1, -1, 0, 0, +1, -1, +1, -1}; - - -void solve() -{ - ll n, m; cin >> n >> m; - map m1, m2; - set s1, s2; - vll v1(n); fr(0, n) cin >> v1[i], m1[v1[i]]++, s1.insert(v1[i]); - vll v2(m); fr(0, m) cin >> v2[i], m2[v2[i]]++, s2.insert(v2[i]); - - while(1) - { - if(s1.empty() && s2.empty()) - { - yes; return; - } - if( (s1.empty() && s2.size() >= 1) || (s2.empty() && s1.size() >= 1)) - { - no; return; - } - - ll mxs1 = *(--s1.end()); - ll mxs2 = *(--s2.end()); - - if(mxs1 > mxs2) - { - no; return; - } - - if(m1[mxs2] >= 1) - { - ll mini = min(m1[mxs1], m2[mxs1]); - m1[mxs1] -= mini; - m2[mxs1] -= mini; - if(m1[mxs1] == 0) - { - s1.erase(mxs1); - } - if(m2[mxs1] == 0) - { - s2.erase(mxs1); - } - } - else - { - ll val_1 = mxs2/2; - ll val_2 = (mxs2 + 1)/2; - - m2[val_1] += m2[mxs2]; - m2[val_2] += m2[mxs2]; - m2[mxs2] = 0; - - s2.insert(val_1); - s2.insert(val_2); - - if(m2[mxs2] == 0) - { - s2.erase(mxs2); - } - - } - } -} - -// --- Think the problem backwards --- - -int main() -{ - Baba_Yaga; - ll tc = 1; cin >> tc; - while(tc--) solve(); -}","#include -using namespace std; -typedef long long ll; -typedef long double ld; - -#define pb push_back -#define MOD 1000000007 -#define vll vector -#define pll pair -#define endl ""\n"" -#define all(v) v.begin(), v.end() -#define mem(a,b) memset(a, b, sizeof(a)) -#define co(n) cout << n << endl -#define yes cout << ""Yes"" << endl -#define no cout << ""No"" << endl -#define fr(x, n) for (int i = x; i < n; ++i) -#define fraction(x) cout << fixed << setprecision(x) -#define Baba_Yaga ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); - -const double eps = 1e-9; -const int N = 2e5+123; - -ll gcd(ll a,ll b) { return __gcd(a,b); } -ll lcm(ll a,ll b) { return (a*b)/__gcd(a,b); } - -int dx[] = {0, 0, +1, -1, +1, +1, -1, -1}; -int dy[] = {+1, -1, 0, 0, +1, -1, +1, -1}; - - -void solve() -{ - ll n, m; cin >> n >> m; - map m1, m2; - set s1, s2; - vll v1(n); fr(0, n) cin >> v1[i], m1[v1[i]]++, s1.insert(v1[i]); - vll v2(m); fr(0, m) cin >> v2[i], m2[v2[i]]++, s2.insert(v2[i]); - - while(1) - { - if(s1.empty() && s2.empty()) - { - yes; return; - } - if( (s1.empty() && s2.size() >= 1) || (s2.empty() && s1.size() >= 1)) - { - no; return; - } - - ll mxs1 = *(--s1.end()); - ll mxs2 = *(--s2.end()); - - if(mxs1 > mxs2) - { - no; return; - } - - if(mxs1 == mxs2) - { - ll mini = min(m1[mxs1], m2[mxs1]); - m1[mxs1] -= mini; - m2[mxs1] -= mini; - if(m1[mxs1] == 0) - { - s1.erase(mxs1); - } - if(m2[mxs1] == 0) - { - s2.erase(mxs1); - } - } - else if(mxs1 < mxs2) - { - ll val_1 = mxs2/2; - ll val_2 = (mxs2 + 1)/2; - - ll koto_bar = m2[mxs2]; - - if( (m1[val_1] >= koto_bar) && (m1[val_2] >= koto_bar) ) - { - m1[val_1] -= koto_bar; - m1[val_2] -= koto_bar; - - if(m1[val_1] == 0) - { - s1.erase(val_1); - } - if(m1[val_2] == 0) - { - s1.erase(val_2); - } - - s2.erase(val_1 + val_2); - } - else - { - s2.insert(val_1); - s2.insert(val_2); - m2[val_1]++; - m2[val_2]++; - m2[mxs2]--; - s2.erase(mxs2); - - } - } - } -} - -// --- Think the problem backwards --- - -int main() -{ - Baba_Yaga; - ll tc = 1; cin >> tc; - while(tc--) solve(); -}",1 -ppmn_6,2061D - Kevin and Numbers,c++23 ,302354277,302356723,"#include -using namespace std; -using ll = long long; -using ld = long double; - -int main() { - cin.tie(0); - ios::sync_with_stdio(0); - int t; - cin >> t; - while (t--) { - int n, m; - cin >> n >> m; - multiset a, b; - for (int i = 0; i < n; i++) { - ll x; - cin >> x; - a.insert(x); - } - for (int i = 0; i < m; i++) { - ll x; - cin >> x; - b.insert(x); - } - while (a.size() && b.size()) { - if (*b.begin() == *a.begin()) { - a.erase(a.begin()); - b.erase(b.begin()); - continue; - } - if (*b.begin() < *a.begin() || a.size() == 1) { - break; - } - if (*next(a.begin()) - 1 > *a.begin()) { - break; - } - a.insert(*a.begin() + *next(a.begin())); - a.erase(next(a.begin())); - a.erase(a.begin()); - } - cout << (a.size() || b.size() ? ""NO"" : ""YES"") << ""\n""; - } - - return 0; -}","#include -using namespace std; -using ll = long long; -using ld = long double; - -int main() { - cin.tie(0); - ios::sync_with_stdio(0); - int t; - cin >> t; - while (t--) { - int n, m; - cin >> n >> m; - multiset a, b; - for (int i = 0; i < n; i++) { - ll x; - cin >> x; - a.insert(x); - } - for (int i = 0; i < m; i++) { - ll x; - cin >> x; - b.insert(x); - } - while (a.size() && b.size()) { - if (a.lower_bound(*b.begin()) != a.end() && *a.lower_bound(*b.begin()) == *b.begin()) { - a.erase(a.lower_bound(*b.begin())); - b.erase(b.begin()); - continue; - } - if (*b.begin() < *a.begin() || a.size() == 1) { - break; - } - ll x = *b.begin(); - b.erase(b.begin()); - b.insert(x / 2); - b.insert(x / 2 + (x % 2)); - } - cout << (a.size() || b.size() ? ""NO"" : ""YES"") << ""\n""; - } - - return 0; -}",2 -WelCo_,2061D - Kevin and Numbers,c++23 ,307376940,307374727,"#pragma GCC optimize(1) -#pragma GCC optimize(2) -#pragma GCC optimize(3) - -#define debug0(x) std::cout << #x << "" = "" << x << '\n' -#define debug1(f, a, b) std::cout << #f << "": ""; for (int i = (a); i <= (b); i++) std::cout << (f)[i] << "" \n""[i == (b)] -#define debug2(f, a, b, c, d) std::cout << #f << "":\n""; for (int i = (a); i <= (b); i++) for (int j = (c); j <= (d); j++) std::cout << (f)[i][j] << "" \n""[j == (d)] -#define debug3(q) std::cout << #q << "": ""; for (auto it : (q)) std::cout << it << ' '; std::cout << '\n' - -#include - -#define INF 0x3f3f3f3f -const int N = 1e5 + 10; - -typedef long long ll; - -void solve () { - ll n, m; - std::cin >> n >> m; - - std::priority_queue a, b; - for (int i = 1; i <= n; i++) { - ll x; - std::cin >> x; - a.push(x); - } - for (int i = 1; i <= m; i++) { - ll x; - std::cin >> x; - b.push(x); - } - - while (!a.empty()) { - if (b.empty() || b.size() > a.size()) { - std::cout << ""No\n""; - return; - } - - ll x = b.top(); - b.pop(); - - if (x < a.top()) { - std::cout << ""No\n""; - return; - } - else if (x == a.top()) { - a.pop(); - } - else { - b.push(x >> 1); - b.push(x + 1 >> 1); - } - } - - if (!b.empty()) { - std::cout << ""No\n""; - return; - } - std::cout << ""Yes\n""; -} - -int main () { - std::ios::sync_with_stdio(false); - std::cin.tie(0), std::cout.tie(0); - - int t; - std::cin >> t; - - while (t--) { - solve(); - } - - return 0; -}","#pragma GCC optimize(1) -#pragma GCC optimize(2) -#pragma GCC optimize(3) - -#define debug0(x) std::cout << #x << "" = "" << x << '\n' -#define debug1(f, a, b) std::cout << #f << "": ""; for (int i = (a); i <= (b); i++) std::cout << (f)[i] << "" \n""[i == (b)] -#define debug2(f, a, b, c, d) std::cout << #f << "":\n""; for (int i = (a); i <= (b); i++) for (int j = (c); j <= (d); j++) std::cout << (f)[i][j] << "" \n""[j == (d)] -#define debug3(q) std::cout << #q << "": ""; for (auto it : (q)) std::cout << it << ' '; std::cout << '\n' - -#include - -#define INF 0x3f3f3f3f -const int N = 1e5 + 10; - -typedef long long ll; - -void solve () { - ll n, m; - std::cin >> n >> m; - - std::deque a; - std::deque b; - - // std::unordered_map count_of_a; - // std::unordered_map count_of_b; - - for (int i = 1; i <= n; i++) { - int x; - std::cin >> x; - - a.push_back(x); - // count_of_a[x]++; - } - for (int i = 1; i <= m; i++) { - int x; - std::cin >> x; - - b.push_back(x); - // count_of_b[x]++; - } - std::sort(a.begin(), a.end()); - std::sort(b.begin(), b.end()); - - int cnt = 0; - while (a.size() > b.size()) { - if (cnt >= 10000) break; - - if (a.front() == b.front()) { - a.push_back(a.front()); - b.push_back(b.front()); - - a.pop_front(); - b.pop_front(); - } - else { - if (std::abs(a[0] - a[1]) <= 1) { - a.push_back(a[0] + a[1]); - a.pop_front(); a.pop_front(); - } - } - - cnt++; - } - // debug3(a), debug3(b); - - std::sort(a.begin(), a.end()); - std::sort(b.begin(), b.end()); - - if (a == b) std::cout << ""Yes\n""; - else std::cout << ""No\n""; -} - -int main () { - std::ios::sync_with_stdio(false); - std::cin.tie(0), std::cout.tie(0); - - int t; - std::cin >> t; - - while (t--) { - solve(); - } - - return 0; -}",1 -vallabhvidy,2061D - Kevin and Numbers,c++23 ,302538237,302538829,"#include -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -using namespace std; -typedef long long ll; -typedef vector vi; -typedef vector vll; - -void solve() { - int n, m; cin >> n >> m; - vll a(n), b(m); - for (auto& i: a) cin >> i; - for (auto& i: b) cin >> i; - - sort(all(a)); - sort(all(b)); - - priority_queue pq(all(b)); - - while (pq.size() != a.size()) { - if (pq.top() == a.back()) { - pq.pop(); - a.pop_back(); - } else if (pq.top() > a.back()) { - ll temp = pq.top(); - pq.pop(); - pq.push(temp / 2); - pq.push((temp / 2) + (temp % 2)); - } else if (pq.top() < a.back()) { - cout << ""No"" << endl; - return; - } - } - - while (pq.top() == a.back()) { - a.pop_back(); - pq.pop(); - } - - if (pq.size() || a.size()) { - cout << ""No"" << endl; - } else { - cout << ""Yes"" << endl; - } -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - #ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif - ll t; - cin >> t; - while(t--) { - solve(); - } - return 0; -}","#include -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -using namespace std; -typedef long long ll; -typedef vector vi; -typedef vector vll; - -void solve() { - int n, m; cin >> n >> m; - vll a(n), b(m); - for (auto& i: a) cin >> i; - for (auto& i: b) cin >> i; - - sort(all(a)); - sort(all(b)); - - priority_queue pq(all(b)); - - while (pq.size() < a.size() && pq.size()) { - if (pq.top() == a.back()) { - pq.pop(); - a.pop_back(); - } else if (pq.top() > a.back()) { - ll temp = pq.top(); - pq.pop(); - pq.push(temp / 2); - pq.push((temp / 2) + (temp % 2)); - } else if (pq.top() < a.back()) { - cout << ""No"" << endl; - return; - } - } - - if (!pq.size()) { - cout << ""No"" << endl; - return; - } - - while (pq.top() == a.back()) { - a.pop_back(); - pq.pop(); - } - - if (pq.size() || a.size()) { - cout << ""No"" << endl; - } else { - cout << ""Yes"" << endl; - } -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - #ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif - ll t; - cin >> t; - while(t--) { - solve(); - } - return 0; -}",2 -dan00ile,2061D - Kevin and Numbers,c++23 ,302347062,302346187,"#define _CRT_SECURE_NO_WARNINGS -#define _USE_MATH_DEFINES - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define ll unsigned long long -#define ld long double -#define nl ""\n"" -#define pb push_back -#define ff first -#define ss second -#define cinn(a) for (int i = 0; i < (int) a.size(); i++) cin >> a[i]; -#define coutt(a) for (int i = 0; i < (int) a.size(); i++) cout << a[i] << (i == a.size() - 1 ? nl : "" ""); -#define sortt(a) sort(a.begin(), a.end()); -#define rev(a) reverse(a.begin(), a.end()); -#define int long long - -using namespace std; - -void solve() { - int n,m; - - cin >> n >> m; - - priority_queue q1; - priority_queue q2; - - for (int i = 0; i < n; i++) { - int x; - cin >> x; - q1.push(x); - } - - for (int i = 0; i < m; i++) { - int x; - cin >> x; - q2.push(x); - } - - for (int i = 0; i < n-m; i++) { - if (q1.empty() || q2.empty()) break; - int a = q1.top(); - int b = q2.top(); - if (a < b) { - q2.pop(); - q2.push(b/2); - q2.push(b % 2 == 1 ? b / 2 + 1 : b / 2); - } else if (a == b) { - q1.pop(); - q2.pop(); - i--; - } else { - break; - } - } - - if (q1.size() != q2.size()) { - cout << ""No\n""; - } else { - while (!q1.empty()) { - if (q1.top() != q2.top()) { - cout << ""No\n""; - return; - } - q1.pop(); - q2.pop(); - } - cout << ""Yes\n""; - } - - -} - - -signed main() { -#ifdef _DEBUG - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - ll start = chrono::high_resolution_clock::now().time_since_epoch().count(); -#endif - //freopen(""segmentupdate.in"", ""r"", stdin); - //freopen(""segmentupdate.out"", ""w"", stdout); - - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - //cout << fixed; - //cout.precision(10); - - int tests = 1; - cin >> tests; - while (tests--) solve(); - -#ifdef _DEBUG - cout << nl << ""TIME ms: ""; - cout << (chrono::high_resolution_clock::now().time_since_epoch().count() - start) / 1e6 << nl; -#endif - return 0; -} -","#define _CRT_SECURE_NO_WARNINGS -#define _USE_MATH_DEFINES - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#define ll unsigned long long -#define ld long double -#define nl ""\n"" -#define pb push_back -#define ff first -#define ss second -#define cinn(a) for (int i = 0; i < (int) a.size(); i++) cin >> a[i]; -#define coutt(a) for (int i = 0; i < (int) a.size(); i++) cout << a[i] << (i == a.size() - 1 ? nl : "" ""); -#define sortt(a) sort(a.begin(), a.end()); -#define rev(a) reverse(a.begin(), a.end()); -#define int long long - -using namespace std; - -void solve() { - int n,m; - - cin >> n >> m; - - priority_queue q1; - priority_queue q2; - - for (int i = 0; i < n; i++) { - int x; - cin >> x; - q1.push(x); - } - - for (int i = 0; i < m; i++) { - int x; - cin >> x; - q2.push(x); - } - - for (int i = 0; i < n; i++) { - int a = q1.top(); - int b = q2.top(); - if (a < b) { - q2.pop(); - q2.push(b/2); - q2.push(b % 2 == 1 ? b / 2 + 1 : b / 2); - } else if (a == b) { - q1.pop(); - q2.pop(); - } else { - break; - } - } - - if (q1.size() != q2.size()) { - cout << ""No\n""; - } else { - while (!q1.empty()) { - if (q1.top() != q2.top()) { - cout << ""No\n""; - return; - } - q1.pop(); - q2.pop(); - } - cout << ""Yes\n""; - } - - -} - - -signed main() { -#ifdef _DEBUG - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - ll start = chrono::high_resolution_clock::now().time_since_epoch().count(); -#endif - //freopen(""segmentupdate.in"", ""r"", stdin); - //freopen(""segmentupdate.out"", ""w"", stdout); - - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - //cout << fixed; - //cout.precision(10); - - int tests = 1; - cin >> tests; - while (tests--) solve(); - -#ifdef _DEBUG - cout << nl << ""TIME ms: ""; - cout << (chrono::high_resolution_clock::now().time_since_epoch().count() - start) / 1e6 << nl; -#endif - return 0; -} -",1 -Aishcuf,2061D - Kevin and Numbers,c++23 ,308908703,308907017,"#include -using namespace std; -int main() { - #ifndef ONLINE_JUDGE - freopen(""inp.in"", ""r"", stdin), freopen(""oup.out"", ""w"", stdout); - #endif - int t; cin >> t; - while (t--) { - int n, m; cin >> n >> m; - map a, b; - int atot = 0, btot = 0; - for (int i = 0, j; i < n; ++i) cin >> j, a[j]++, atot += j; - for (int i = 0, j; i < m; ++i) cin >> j, b[j]++, btot += j; - if (atot != btot) goto fail; - atot = n, btot = m; - while (b.size()) { - auto [key, val] = *b.begin(); - btot -= val; - if (a.count(key)) { - if (a[key] >= val) a[key] -= val, atot -= val, val = 0; - else btot -= a[key], val -= a[key], a.erase(key); - if (a[key] == 0) a.erase(key); - } - if (val != 0) b[key / 2] += val, b[key - key / 2] += val, btot += 2 * val; - b.erase(key); - if (btot > atot) goto fail; - } - if (a.size() || b.size()) goto fail; - cout << ""YES"" << endl; continue; - fail: cout << ""NO"" << endl; - } -}","#include -using namespace std; -int main() { - #ifndef ONLINE_JUDGE - freopen(""inp.in"", ""r"", stdin), freopen(""oup.out"", ""w"", stdout); - #endif - #define int long long - int t; cin >> t; - while (t--) { - int n, m; cin >> n >> m; - string ans = ""YES""; - map a, b; - int atot = 0, btot = 0; - for (int i = 0, j; i < n; ++i) cin >> j, a[j]++, atot += j; - for (int i = 0, j; i < m; ++i) cin >> j, b[j]++, btot += j; - if (atot != btot) goto fail; - atot = n, btot = m; - while (b.size()) { - auto [key, val] = *b.begin(); - btot -= val; - if (a.count(key)) { - if (a[key] >= val) a[key] -= val, atot -= val, val = 0; - else btot -= a[key], val -= a[key]; - if (a[key] == 0) a.erase(key); - } - if (val != 0) b[key / 2] += val, b[key - key / 2] += val, btot += 2 * val; - b.erase(key); - if (btot > atot) goto fail; - } - cout << ""YES"" << endl; continue; - fail: cout << ""NO"" << endl; - } -}",1 -GULUJUN,2061D - Kevin and Numbers,c++20 ,302821711,302821540,"#include -using namespace std; - -using ll = long long; -#define lowbit(x) x & (-x) -#define fix(x) fixed << setprecision(x) -ll n, m; -map ma; -bool dfs(ll x) { - if (x == 0) - return 0; - if (ma[x] > 0) { - ma[x]--; - return 1; - } - return dfs(x / 2) && dfs(x - x / 2); -} -void sp() { - cin >> n >> m; - vector a(n); - ma.clear(); - ll f=0; - for (ll i = 0; i < n; i++) - cin >> a[i], ma[a[i]]++; - for (ll i = 0; i < m; i++) { - ll x; - cin >> x; - if (!dfs(x)) { - f=1; - } - } - for (auto i : ma) { - if (i.second > 0) { - f=1; - break; - } - } - if(f){ - cout<<""No""<> __; - while (__--) - sp(); -}","#include -using namespace std; - -using ll = long long; -#define lowbit(x) x & (-x) -#define fix(x) fixed << setprecision(x) -ll n, m; -map ma; -bool dfs(ll x){ - if(x==0) return 0; - if(ma[x]>0){ - ma[x]--; - return 1; - } - return dfs(x/2)&&dfs(x-x/2); -} -void sp() { - cin >> n >> m; - vector a(n); - ma.clear(); - for (ll i = 0; i < n; i++) - cin >> a[i], ma[a[i]]++; - for (ll i = 0; i < m; i++) { - ll x; - cin >> x; - if(!dfs(x)){ - cout << ""No"" << endl; - return; - } - } - for(auto i:ma){ - if(i.second>0){ - cout<<""No""<> __; - while (__--) - sp(); -}",1 -UjjwalD,2061D - Kevin and Numbers,c++20 ,314422723,314420910,"#include - -#define int long long - -#define pp pair - -#define all(a) a.begin(),a.end() - -#define rall(a) a.rbegin(),a.rend() - -using namespace std; - -void remove(int val,map &mp) { - - mp[val]--; - - if(mp[val]==0) - - mp.erase(val); - -} - -void form(int val,map &mp) { - - if(mp.size()==0)return; - - if(val<(mp.begin()->first))return; - - if(mp.find(val)!=mp.end())return; - - if(val&1) { - - int x=(val-1)/2,y=x+1; - - form(x,mp); - - if(mp.find(x)!=mp.end()) { - - remove(x,mp); - - form(y,mp); - - if(mp.find(y)!=mp.end()) { - - remove(y,mp); - - mp[val]++; - - } - - else - - mp[x]++; - - } - - } - - else { - - int x=val/2; - - form(x,mp); - - if(mp.find(x)!=mp.end()) { - - remove(x,mp); - - form(x,mp); - - if(mp.find(x)!=mp.end()) { - - remove(x,mp); - - mp[val]++; - - } - - else - - mp[x]++; - - } - - } - - - -} - -void solve() - -{ - - int n,m;cin>>n>>m; - - vector a(n),b(m); - - for(int i=0;i>a[i]; - - for(int i=0;i>b[i]; - - - - map mp; - - for(int i:a) - - mp[i]++; - - - - for(int i=0;isync_with_stdio(false); - - int t;cin>>t; - - while(t--)solve(); - -}","#include - -#define int long long - -#define pp pair - -#define all(a) a.begin(),a.end() - -#define rall(a) a.rbegin(),a.rend() - -using namespace std; - -void remove(int val,map &mp) { - - mp[val]--; - - if(mp[val]==0) - - mp.erase(val); - -} - -void form(int val,map &mp) { - - if(mp.size()==0)return; - - if(valfirst)return; - - - - if(val&1) { - - int x=(val-1)/2,y=x+1; - - if(mp.find(x)!=mp.end() && mp.find(y)!=mp.end()) { - - remove(x,mp); - - remove(y,mp); - - mp[val]++; - - } - - else if(mp.find(x)!=mp.end()) { - - form(y,mp); - - if(mp.find(y)!=mp.end()) { - - remove(y,mp); - - remove(x,mp); - - mp[val]++; - - } - - } - - else if(mp.find(y)!=mp.end()) { - - form(x,mp); - - if(mp.find(x)!=mp.end()) { - - remove(x,mp); - - remove(y,mp); - - mp[val]++; - - } - - } - - else { - - form(x,mp); - - form(y,mp); - - if(mp.find(x)!=mp.end() && mp.find(y)!=mp.end()) { - - remove(x,mp); - - remove(y,mp); - - mp[val]++; - - } - - } - - } - - else { - - int x=val/2; - - if(mp[x]>=2) { - - remove(x,mp); - - remove(x,mp); - - mp[val]++; - - } - - else if(mp.find(x)!=mp.end()) { - - form(x,mp); - - if(mp[x]>=2) { - - remove(x,mp); - - remove(x,mp); - - mp[val]++; - - } - - } - - else { - - form(x,mp); - - form(x,mp); - - if(mp[x]>=2) { - - remove(x,mp); - - remove(x,mp); - - mp[val]++; - - } - - } - - } - - - -} - -void solve() - -{ - - int n,m;cin>>n>>m; - - vector a(n),b(m); - - for(int i=0;i>a[i]; - - for(int i=0;i>b[i]; - - - - map mp; - - for(int i:a) - - mp[i]++; - - - - for(int i=0;isync_with_stdio(false); - - int t;cin>>t; - - while(t--)solve(); - -}",1 -oneafter,2061D - Kevin and Numbers,java,305747603,305746394,"import java.io.*; -import java.util.*; - -public class Main { - public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353; - public static void main(String args[]){ - try { - PrintWriter o = new PrintWriter(System.out); - boolean multiTest = true; - // init - if(multiTest) { - int t = nextInt(), loop = 0; - while (loop < t) {loop++;solve(o);} - } else solve(o); - o.close(); - } catch (Exception e) {e.printStackTrace();} - } - static void solve(PrintWriter o) { - try { - int n = nextInt(), m = nextInt(), k = n-m; - int[] a = new int[n]; - int[] b = new int[m]; - Map map = new HashMap<>(); - for(int i=0;i pq = new PriorityQueue<>((x,y)->Integer.compare(y,x)); - for(int i=0;i 0) { - pq.offer(x/2); - pq.offer((x+1)/2); - } - else { - o.println(""No""); - return; - } - } - if(k > 0) o.println(""No""); - else o.println(""Yes""); - } catch (Exception e) { - e.printStackTrace(); - } - } - public static int lower_bound(Integer[] a, long val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(List li, long val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid) < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(long[] preSum, long val){ - int l = 0, r = preSum.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(preSum[mid] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(List li, long val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid)[0] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(List li, int val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid) <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(int[] a, long val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(List li, int val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid)[0] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(int[] a, int val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(long[][] a, long val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid][0] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static long gcd(long a, long b) { - return b == 0 ? a : gcd(b, a%b); - } - public static long[] extgcd(long a, long b) { - if(b == 0) return new long[]{1, 0}; - long[] it = extgcd(b, a%b); - long x = it[1], y = it[0]; - y -= a/b*x; - return new long[]{x, y}; - } - public static long lcm(long a, long b){ - return a / gcd(a,b)*b; - } - public static long qpow(long a, long n){ - long ret = 1l; - while(n > 0){ - if((n & 1) == 1) ret = ret * a; - n >>= 1; - a = a * a; - } - return ret; - } - public static long qpow(long a, long n, int md){ - a %= md; - long ret = 1l; - while(n > 0){ - if((n & 1) == 1) ret = ret * a % md; - n >>= 1; - a = a * a % md; - } - return ret; - } - public static class FenWick { - int n; - long[] a; - long[] tree; - public FenWick(int n){ - this.n = n; - a = new long[n+1]; - tree = new long[n+1]; - } - private void add(int x, long val){ - while(x <= n){ - tree[x] += val; - x += x&-x; - } - } - private void addMx(int x, long val) { - a[x] += val; - tree[x] = a[x]; - while(x <= n) { - for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]); - x += x&-x; - } - } - private void addMn(int x, long val) { - a[x] += val; - tree[x] = a[x]; - while(x <= n) { - for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.min(tree[x], tree[x-i]); - x += x&-x; - } - } - private long query(int x){ - long ret = 0l; - while(x > 0){ - ret += tree[x]; - x -= x&-x; - } - return ret; - } - private long queryMx(int l, int r) { - long res = 0l; - while(l <= r) { - if(r-(r&-r) >= l) { - res = Math.max(res, tree[r]); - r -= r&-r; - } - else { - res = Math.max(res, a[r]); - r--; - } - } - return res; - } - private long queryMn(int l, int r) { - long res = 1l<<55; - while(l <= r) { - if(r-(r&-r) >= l) { - res = Math.min(res, tree[r]); - r -= r&-r; - } - else { - res = Math.min(res, a[r]); - r--; - } - } - return res; - } - } - static class Pair { - Integer p1, p2; - public Pair(Integer p1, Integer p2) { - this.p1 = p1; - this.p2 = p2; - } - @Override - public int hashCode() { - int prime = 31, ret = 0; - ret = ret*prime+p1.hashCode(); - ret = ret*prime+p2.hashCode(); - return ret; - } - @Override - public boolean equals(Object o) { - if(o instanceof Pair pair) { - return p1.equals(pair.p1) && p2.equals(pair.p2); - } - return false; - } - } - static class DSU { - int[] parent; - int[] size; - public DSU(int n) { - parent = new int[n]; - size = new int[n]; - for(int i=0;i map; - static void solve(PrintWriter o) { - try { - int n = nextInt(), m = nextInt(); - int[] a = new int[n]; - int[] b = new int[m]; - long sum1 = 0l, sum2 = 0l; - map = new HashMap<>(); - for(int i=0;i li, long val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid) < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(long[] preSum, long val){ - int l = 0, r = preSum.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(preSum[mid] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(List li, long val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid)[0] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(List li, int val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid) <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int upper_bound(int[] a, long val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid] <= val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(List li, int val){ - int l = 0, r = li.size(); - while(l < r){ - int mid = l + (r - l) / 2; - if(li.get(mid)[0] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(int[] a, int val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static int lower_bound(long[][] a, long val){ - int l = 0, r = a.length; - while(l < r){ - int mid = l + (r - l) / 2; - if(a[mid][0] < val) l = mid + 1; - else r = mid; - } - return l; - } - public static long gcd(long a, long b) { - return b == 0 ? a : gcd(b, a%b); - } - public static long[] extgcd(long a, long b) { - if(b == 0) return new long[]{1, 0}; - long[] it = extgcd(b, a%b); - long x = it[1], y = it[0]; - y -= a/b*x; - return new long[]{x, y}; - } - public static long lcm(long a, long b){ - return a / gcd(a,b)*b; - } - public static long qpow(long a, long n){ - long ret = 1l; - while(n > 0){ - if((n & 1) == 1) ret = ret * a; - n >>= 1; - a = a * a; - } - return ret; - } - public static long qpow(long a, long n, int md){ - a %= md; - long ret = 1l; - while(n > 0){ - if((n & 1) == 1) ret = ret * a % md; - n >>= 1; - a = a * a % md; - } - return ret; - } - public static class FenWick { - int n; - long[] a; - long[] tree; - public FenWick(int n){ - this.n = n; - a = new long[n+1]; - tree = new long[n+1]; - } - private void add(int x, long val){ - while(x <= n){ - tree[x] += val; - x += x&-x; - } - } - private void addMx(int x, long val) { - a[x] += val; - tree[x] = a[x]; - while(x <= n) { - for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]); - x += x&-x; - } - } - private void addMn(int x, long val) { - a[x] += val; - tree[x] = a[x]; - while(x <= n) { - for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.min(tree[x], tree[x-i]); - x += x&-x; - } - } - private long query(int x){ - long ret = 0l; - while(x > 0){ - ret += tree[x]; - x -= x&-x; - } - return ret; - } - private long queryMx(int l, int r) { - long res = 0l; - while(l <= r) { - if(r-(r&-r) >= l) { - res = Math.max(res, tree[r]); - r -= r&-r; - } - else { - res = Math.max(res, a[r]); - r--; - } - } - return res; - } - private long queryMn(int l, int r) { - long res = 1l<<55; - while(l <= r) { - if(r-(r&-r) >= l) { - res = Math.min(res, tree[r]); - r -= r&-r; - } - else { - res = Math.min(res, a[r]); - r--; - } - } - return res; - } - } - static class Pair { - Integer p1, p2; - public Pair(Integer p1, Integer p2) { - this.p1 = p1; - this.p2 = p2; - } - @Override - public int hashCode() { - int prime = 31, ret = 0; - ret = ret*prime+p1.hashCode(); - ret = ret*prime+p2.hashCode(); - return ret; - } - @Override - public boolean equals(Object o) { - if(o instanceof Pair pair) { - return p1.equals(pair.p1) && p2.equals(pair.p2); - } - return false; - } - } - static class DSU { - int[] parent; - int[] size; - public DSU(int n) { - parent = new int[n]; - size = new int[n]; - for(int i=0;i -#define ll long long -using namespace std; -const int N = 2e5 + 10; -int a[N], b[N]; -multiset s; -int find(int x){ - int y = x / 2; - int z = ceil(x / 2.0); - if(y == z){ - auto xx = s.lower_bound(y); - if(xx != s.end() && *xx == y){ - s.erase(xx); - auto yy = s.lower_bound(y); - if(yy != s.end() && *yy == y) return 1; - int f = find(y); - if(f) return 1; - return 0; - } - int f = find(y); - if(f){ - f = find(y); - if(f) return 1; - return 0; - } - return 0; - } - auto yy = s.lower_bound(y); - auto zz = s.lower_bound(z); - int fy = 0, fz = 0; - if(yy == s.end() || *yy != y) fy = 1; - if(zz == s.end() || *zz != z) fz = 1; - if(fy && y < *(s.begin())) return 0; - if(fz && z < *(s.begin())) return 0; - if(fy && fz){ - int f = find(y), g = find(z); - if(f && g) return 1; - return 0; - } - else if(fy && !fz){ - s.erase(zz); - int f = find(y); - if(f) return 1; - return 0; - } - else if(!fy && fz){ - s.erase(yy); - int g = find(z); - if(g) return 1; - return 0; - } - else{ - s.erase(yy); s.erase(zz); - return 1; - } -} -int main(){ - ios::sync_with_stdio(0); cin.tie(0); - int t; - cin >> t; - while(t --){ - int n, m; - cin >> n >> m; - s.clear(); - ll s1 = 0, s2 = 0; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - s1 += a[i]; - s.insert(a[i]); - } - for (int i = 1; i <= m; i++) cin >> b[i], s2 += b[i]; - if(s1 != s2){cout << ""No"" << '\n'; continue;} - sort(b + 1, b + m); - int res = 0; - for (int i = m; i >= 1; i--){ - int x = b[i]; - int f = 0; - auto y = s.lower_bound(x); - if(y == s.end()){ - int f = find(x); - if(!f) {res = 1; break;} - } - else{ - s.erase(y); - } - - } - if(!res) cout << ""Yes"" << '\n'; - else cout << ""No"" << '\n'; - } -}","#include -#define ll long long -using namespace std; -const int N = 2e5 + 10; -int a[N], b[N]; -multiset s; -int find(int x){ - int y = x / 2; - int z = ceil(x / 2.0); - // cout << y << ' ' << z << '\n'; - if(y == z){ - auto xx = s.lower_bound(y); - if(xx != s.end() && *xx == y){ - s.erase(xx); - auto yy = s.lower_bound(y); - if(y < *(s.begin())) return 0; - if(yy != s.end() && *yy == y) { - s.erase(yy); - return 1; - } - int f = find(y); - if(f) return 1; - return 0; - } - if(y < *(s.begin())) return 0; - int f = find(y); - if(f){ - f = find(y); - if(f) return 1; - return 0; - } - return 0; - } - auto yy = s.lower_bound(y); - auto zz = s.lower_bound(z); - int fy = 0, fz = 0; - if(yy == s.end() || *yy != y) fy = 1; - if(zz == s.end() || *zz != z) fz = 1; - if(fy && y < *(s.begin())) return 0; - if(fz && z < *(s.begin())) return 0; - if(fy && fz){ - int f = find(y), g = find(z); - if(f && g) return 1; - return 0; - } - else if(fy && !fz){ - s.erase(zz); - int f = find(y); - if(f) return 1; - return 0; - } - else if(!fy && fz){ - s.erase(yy); - int g = find(z); - if(g) return 1; - return 0; - } - else{ - s.erase(yy); s.erase(zz); - return 1; - } -} -int main(){ - ios::sync_with_stdio(0); cin.tie(0); - int t; - cin >> t; - while(t --){ - int n, m; - cin >> n >> m; - s.clear(); - ll s1 = 0, s2 = 0; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - s1 += a[i]; - s.insert(a[i]); - } - for (int i = 1; i <= m; i++) cin >> b[i], s2 += b[i]; - if(s1 != s2){cout << ""No"" << '\n'; continue;} - sort(b + 1, b + m + 1); - int res = 0; - for (int i = m; i >= 1; i--){ - int x = b[i]; - int f = 0; - auto y = s.lower_bound(x); - if(y == s.end() || *y != x){ - int f = find(x); - if(!f) {res = 1; break;} - } - else{ - s.erase(y); - } - - } - if(!res) cout << ""Yes"" << '\n'; - else cout << ""No"" << '\n'; - } -}",2 -Dreams_Lentenbe,2061D - Kevin and Numbers,c++17 ,303214149,303212932,"#include -using namespace std; -#define ll long long -#define ld long double -#define nl ""\n"" -typedef pair pll; -typedef vector vll; -typedef vector vvll; -typedef vector>vpll; -#define pb push_back -#define fori(n) for (ll i=0; i>n>>m; - vll v(n); - fori(n){ - cin>>v[i]; - } - isort(v); - priority_queuepq; - fori(m){ - ll a;cin>>a; - pq.push(a); - } - ll p = n-1; - while(p>=0){ - if(pq.size()>p+1 || pq.empty()){ - cout<<""No""<v[p]){ - ll element = pq.top(); - pq.pop(); - pq.push(element/2); - pq.push(element/2+element%2); - }else if(pq.top()> tt;for (int i=1; i<=tt; i++){solve();} - // solve(); -}","#include -using namespace std; -#define ll long long -#define ld long double -#define nl ""\n"" -typedef pair pll; -typedef vector vll; -typedef vector vvll; -typedef vector>vpll; -#define pb push_back -#define fori(n) for (ll i=0; i&mp){ - // cout<>n>>m; - mapmp; - fori(n){ - ll a; - cin>>a; - mp[a]++; - } - vll v(m); - fori(m){ - cin>>v[i]; - } - ll ans = true; - for(int i=0; i> tt;for (int i=1; i<=tt; i++){solve();} - // solve(); -}",1 -dremlory#,2061D - Kevin and Numbers,c++20 ,306164469,306163233,"#include -using namespace std; -using ll = long long; - -void solve () { - int n, m; - cin >> n >> m; - multiset a, b; - for (int i = 0; i < n; i++) { - int x; - cin >> x; - a.insert(x); - } - for (int i = 0; i < m; i++) { - int x; - cin >> x; - b.insert(x); - } - for (int i = 0; i < n; i++) { - if (a.size() <= b.size()) { - // cout << ""No\n""; - break; - } - int x , y; - x = *a.begin(); a.erase(a.find(x)); - if (a.size() > 0) y = *a.begin(), a.erase(a.find(y)); - - if (x == *b.begin()) { - a.insert(y); - b.erase(b.find(x)); - } else { - if (abs(x - y) <= 1) a.insert(x + y); - else break; - } - } - if (a.size() == 0 || b.size() == 0 || a.size() < b.size()) { - cout << ""No\n""; - } else { - while (1) { - if (a.size() == 0 || b.size() == 0) break; - int x = *a.begin(), y = *b.begin(); - if (x != y) { - cout <<""No\n""; - return; - } else { - a.erase(a.find(x)); - b.erase(b.find(y)); - } - } - cout << ""Yes\n""; - } -} - -int main() { - auto begin = std::chrono::high_resolution_clock::now(); - ios_base::sync_with_stdio(0); - cin.tie(0); - //freopen(""in"", ""r"", stdin); - //freopen(""out"", ""w"", stdout); - int T = 1; - cin >> T; - for(int i = 1; i <= T; i++) { - // cout << ""Case #"" << i << "": ""; - solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; - return 0; -}","#include -using namespace std; -//#define int long long -#define endl ""\n"" -const int N = 3e5 + 10, M = 110, mod = 998244353; -const long long INF = 2e18; -typedef pair pt; -typedef long long ll; - - - -void solve() { - int n, m; - cin >> n >> m; - vector a(n + 1), b(m + 1); - map cnt, cnt2; - int sum = 0; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - cnt[a[i]]++; - if (cnt[a[i]] == 1) sum++; - } - map mp; - for (int i = 1; i <= m; i++) { - cin >> b[i]; - mp[b[i]]++; - } - while (!mp.empty()) { - auto [x, t] = *mp.rbegin(); - mp.erase(mp.rbegin()->first); - if (cnt[x] >= t) { - cnt[x] -= t; - if (cnt[x] == 0) sum--; - continue; - } - else if (cnt[x] > 0) { - t -= cnt[x]; - cnt[x] = 0; - sum--; - } - if (x == 1) { - cout << ""No"" << endl; - return; - } - if (x & 1) { - mp[x / 2] += t, mp[x / 2 + 1] += t; - } - else { - mp[x / 2] += 2 * t; - } - } - if (sum == 0) cout << ""Yes"" << endl; - else cout << ""No"" << endl; -} - -signed main() { - //freopen(""data.in"", ""r"", stdin); - //freopen(""std.txt"", ""w"", stdout); - ios::sync_with_stdio(false); - cin.tie(0), cout.tie(0); - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -Lawrence001,2061D - Kevin and Numbers,c++17 ,313236767,313237070,"#include - -#include - -using namespace std; - -#define INF 2147483647 - -int t,n,m,a; - -unordered_mapmp; - -bool solve(int x) - -{ - - if(mp[x]) - - { - - mp[x]--; - - return true; - - } - - else if(!x)return false; - - else return solve(x/2)&&solve((x+1)/2); - -} - -int main() - -{ - - scanf(""%d"",&t); - - while(t--) - - { - - mp.clear(); - - scanf(""%d%d"",&n,&m); - - long long cnt=0; - - for(int i=0;i - -#include - -using namespace std; - -int t,n,m,a; - -mapmp; - -bool solve(int x) - -{ - - if(mp[x]) - - { - - mp[x]--; - - return true; - - } - - else if(!x)return false; - - else return solve(x/2)&&solve((x+1)/2); - -} - -int main() - -{ - - scanf(""%d"",&t); - - while(t--) - - { - - mp.clear(); - - scanf(""%d%d"",&n,&m); - - long long cnt=0; - - for(int i=0;i -using namespace std; -#define int long long -map mpa; -int cf(int x,int con) -{ - if(x==0)return 1; - if (con>mpa[x]) - { - con -= mpa[x]; - mpa[x] = 0; - if (x % 2 == 0) - { - if (cf(x / 2, 2 * con))return 1; - } - else - { - if (cf(x/2, con))return 1; - if (cf(x/2+1,con))return 1; - } - } - else - { - mpa[x] -= con; - } - return 0; -} -int solve() -{ - int n, m; - cin >> n >> m; - vector a(n); - vector b(m); - mpa.clear(); - for (int i = 0; i < n; i++) - { - cin >> a[i]; - mpa[a[i]]++; - } - for (int i = 0; i < m; i++) - { - cin >> b[i]; - } - sort(a.begin(), a.end()); - sort(b.begin(), b.end()); - int ans = 0; - for (int i = 0; i < m; i++) - { - if (cf(b[i], 1)) - { - cout<<""NO""< 0) - { - cout<<""NO""<> t; - while (t--) - { - solve(); - } -}","#include -using namespace std; -#define int long long -map mpa; -int cf(int x,int con) -{ - if(x==0)return 1; - if (con>mpa[x]) - { - con -= mpa[x]; - mpa[x] = 0; - if (x % 2 == 0) - { - if (cf(x / 2, 2 * con))return 1; - } - else - { - if (cf(x/2, con))return 1; - if (cf(x/2+1,con))return 1; - } - } - else - { - mpa[x] -= con; - } - return 0; -} -int solve() -{ - int n, m; - cin >> n >> m; - vector a(n); - vector b(m); - mpa.clear(); - for (int i = 0; i < n; i++) - { - cin >> a[i]; - mpa[a[i]]++; - } - for (int i = 0; i < m; i++) - { - cin >> b[i]; - } - sort(a.begin(), a.end()); - sort(b.begin(), b.end()); - int ans = 0; - for (int i = 0; i < m; i++) - { - if (cf(b[i], 1)) - { - cout<<""NO""< 0) - { - cout<<""NO""<> t; - while (t--) - { - solve(); - } -}",1 -alisa22580,2061D - Kevin and Numbers,c++23 ,315836236,315837589,"// #pragma GCC optimize(2) - -#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define all(x) (x).begin(), (x).end() - - - -constexpr int MOD = 1e9 + 7; - -// -9.2e18 ~ 9.2e18 - - - -void solve() - -{ - - int n, m; - - cin >> n >> m; - - vector a(n), b(m); - - for (int i = 0; i < n; i++) - - { - - cin >> a[i]; - - } - - for (int i = 0; i < m; i++) - - { - - cin >> b[i]; - - } - - - - priority_queue> pqa, pqb; - - for (int i = 0; i < n; i++) - - { - - pqa.push(a[i]); - - } - - for (int i = 0; i < m; i++) - - { - - pqb.push(b[i]); - - } - - int k = n - m; - - while (pqa.size() and k) - - { - - auto amax = pqa.top(); - - pqa.pop(); - - auto bmax = pqb.top(); - - pqb.pop(); - - - - if (amax == bmax) - - { - - continue; - - } - - else if (amax > bmax) - - { - - cout << ""No""; - - return; - - } - - else - - { - - pqa.push(amax); - - auto num1 = bmax / 2, num2 = (bmax + 1) / 2; - - pqb.push(num1); - - pqb.push(num2); - - } - - k--; - - } - - - - while (pqa.size() and pqb.size()) - - { - - auto amax = pqa.top(); - - pqa.pop(); - - auto bmax = pqb.top(); - - pqb.pop(); - - - - if (amax == bmax) - - { - - continue; - - } - - else - - { - - cout << ""No""; - - return; - - } - - } - - cout << (pqa.size() or pqb.size() ? ""No"" : ""Yes""); - -} - - - -signed main() - -{ - - cin.tie(0)->ios::sync_with_stdio(0); - - cout << setiosflags(ios::fixed) << setprecision(2); - - int TT = 1; - - cin >> TT; - - while (TT--) - - { - - solve(); - - cout << endl; - - } - -}","// #pragma GCC optimize(2) - -#include - -using namespace std; - -#define int long long - -#define endl '\n' - -#define all(x) (x).begin(), (x).end() - - - -constexpr int MOD = 1e9 + 7; - -// -9.2e18 ~ 9.2e18 - - - -void solve() - -{ - - int n, m; - - cin >> n >> m; - - - - priority_queue> pqa, pqb; - - for (int i = 0; i < n; i++) - - { - - int num; - - cin >> num; - - pqa.push(num); - - } - - for (int i = 0; i < m; i++) - - { - - int num; - - cin >> num; - - pqb.push(num); - - } - - while (pqa.size() and pqb.size()) - - { - - - - if (pqa.size() < pqb.size()) - - { - - cout << ""No""; - - return; - - } - - if (pqa.top() == pqb.top()) - - { - - pqb.pop(); - - pqa.pop(); - - continue; - - } - - if (pqa.top() > pqb.top()) - - { - - cout << ""No""; - - return; - - } - - else - - { - - auto num1 = pqb.top() >> 1, num2 = (pqb.top() + 1) >> 1; - - pqb.pop(); - - pqb.push(num1); - - pqb.push(num2); - - } - - } - - - - cout << (pqa.empty() and pqb.empty() ? ""Yes"" : ""No""); - -} - - - -signed main() - -{ - - cin.tie(0)->ios::sync_with_stdio(0); - - cout << setiosflags(ios::fixed) << setprecision(2); - - int TT = 1; - - cin >> TT; - - while (TT--) - - { - - solve(); - - cout << endl; - - } - -}",2 -Aurora.th,2061D - Kevin and Numbers,c++20 ,307652001,307655064,"#include - -// #define int long long -#define PII pair -#define ll long long - -using namespace std; - -int T, n, m; - -void solve() -{ - cin >> n >> m; - priority_queue, greater> qa, qb; - ll sa = 0, sb = 0; - for(int i = 0, x;i < n;i ++){ - cin >> x; - sa += x; - qa.push(x); - } - for(int i = 0, x;i < m;i ++){ - cin >> x; - sb += x; - qb.push(x); - } - if(sa != sb){ - cout << ""NO"" << endl; - return; - } - while(!qa.empty() && !qb.empty()) - { - auto a = qa.top(), b = qb.top(); - // cout << a << "" "" << b << endl; - qa.pop(), qb.pop(); - if(a < b){ - qa.push(a); - while(!qa.empty()) - { - auto t1 = qa.top(); - qa.pop(); - - if(t1 == b) break; - - auto t2 = qa.top(); - qa.pop(); - if(t2 - t1 > 1){ - cout << ""NO"" << endl; - return; - } - qa.push(t1 + t2); - } - }else if(a > b){ - qb.push(b); - while(!qb.empty()) - { - auto t1 = qb.top(); - qb.pop(); - - if(t1 == a) break; - - auto t2 = qb.top(); - qb.pop(); - if(t2 - t1 > 1){ - cout << ""NO"" << endl; - return; - } - qb.push(t1 + t2); - } - } - } - if(qa.empty() && qb.empty()) cout << ""YES"" << endl; - else cout << ""NO"" << endl; -} - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - cin >> T; - while(T --){ - solve(); - } - return 0; -}","#include - -// #define int long long -#define PII pair -#define ll long long - -using namespace std; - -int T, n, m; - -void solve() -{ - cin >> n >> m; - priority_queue qa, qb; - ll sa = 0, sb = 0; - for(int i = 0, x;i < n;i ++){ - cin >> x; - sa += x; - qa.push(x); - } - for(int i = 0, x;i < m;i ++){ - cin >> x; - sb += x; - qb.push(x); - } - if(sa != sb){ - cout << ""NO"" << endl; - return; - } - while(!qa.empty()) - { - if(qb.empty()) break; - - auto a = qa.top(), b = qb.top(); - // cout << a << "" "" << b << endl; - qb.pop(); - - if(b < a){ - cout << ""NO"" << endl; - return; - } - if(b == a) qa.pop(); - else{ - qb.push(b / 2); - qb.push((b + 1) / 2); - } - } - if(qa.empty() && qb.empty()) cout << ""YES"" << endl; - else cout << ""NO"" << endl; -} - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - cin >> T; - while(T --){ - solve(); - } - return 0; -}",2 -pjn69,2061D - Kevin and Numbers,c++23 ,314672872,314673857,"#include - -using namespace std; - - - -void solve() { - - int n, m; - - cin >> n >> m; - - - - vector a(n); - - vector b(m); - - map mpa; - - map mpb; - - set> s1; - - set> s2; - - - - for (int i = 0; i < n; i++) { - - cin >> a[i]; - - mpa[a[i]]++; - - s1.insert(a[i]); - - } - - for (int i = 0; i < m; i++) { - - cin >> b[i]; - - mpb[b[i]]++; - - s2.insert(b[i]); - - } - - - - while (true) { - - if (s1.empty() && s2.empty()) { - - cout << ""Yes"" << endl; - - return; - - } - - - - if (s1.empty() || s2.empty()) { - - cout << ""No"" << endl; - - return; - - } - - - - int mxa = *s1.rbegin(); - - int mxb = *s2.rbegin(); // Get the largest element in s2 - - - - if (mxa > mxb) { - - cout << ""No"" << endl; - - return; - - } else if (mxa == mxb) { - - int minifre = min(mpa[mxa], mpb[mxb]); - - mpa[mxa] -= minifre; - - mpb[mxb] -= minifre; - - - - if (mpa[mxa] == 0) s1.erase(mxa); - - if (mpb[mxb] == 0) s2.erase(mxb); - - } else { // mxa < mxb - - int sl = mxb / 2; - - int sb = (mxb + 1) / 2; - - - - - - mpb[sl]+=mpb[mxb]; - - s2.insert(sl); - - - - mpb[sb]+=mpb[mxb]; - - s2.insert(sb); - - mpb[mxb]=0; - - if (mpb[mxb] == 0) s2.erase(mxb); - - - - - - } - - } - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -}","#include - -using namespace std; - - - -void solve() { - - int n, m; - - cin >> n >> m; - - - - vector a(n), b(m); - - map mpa, mpb; - - set s1, s2; - - - - - - for (int i = 0; i < n; ++i) { - - cin >> a[i]; - - mpa[a[i]]++; - - s1.insert(a[i]); - - } - - - - - - for (int i = 0; i < m; ++i) { - - cin >> b[i]; - - mpb[b[i]]++; - - s2.insert(b[i]); - - } - - - - while (true) { - - - - if (s1.empty() && s2.empty()) { - - cout << ""Yes\n""; - - return; - - } - - - - - - if (s1.empty() || s2.empty()) { - - cout << ""No\n""; - - return; - - } - - - - - - int mxa = *s1.rbegin(); - - int mxb = *s2.rbegin(); - - - - if (mxa > mxb) { - - cout << ""No\n""; - - return; - - } - - - - - - if (mxa == mxb) { - - int common = min(mpa[mxa], mpb[mxb]); - - mpa[mxa] -= common; - - mpb[mxb] -= common; - - - - if (mpa[mxa] == 0) s1.erase(mxa); - - if (mpb[mxb] == 0) s2.erase(mxb); - - } - - else { - - - - if (mpb[mxb] == 0) { - - s2.erase(mxb); - - continue; - - } - - - - int count = mpb[mxb]; - - mpb[mxb] = 0; - - s2.erase(mxb); - - - - int part1 = mxb / 2; - - int part2 = (mxb + 1) / 2; - - - - mpb[part1] += count; - - s2.insert(part1); - - mpb[part2] += count; - - s2.insert(part2); - - } - - } - -} - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -",2 -SJF_PrimeWizard,2061D - Kevin and Numbers,c++20 ,304703923,304702767,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -template using oset = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; -#define SMIT_FEFAR \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define MOD 1000000007 -#define MOD2 998244353 - -#define pb push_back -#define ppb pop_back -#define vvi vector> -#define vvll vector> -#define vvc vector> -#define vi vector -#define pll pair -#define vpll vector -#define mp make_pair -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((ll)(x).size()) -#define all(x) (x).begin(), (x).end() -#define vll vector -#define yes cout << ""YES\n""; -#define no cout << ""NO\n""; -#define minus cout<<-1<<""\n""; -#define rep(l,r,i) for(ll i = l;i=r;i--) -#define print cout<< -#define nline ""\n"" -ll inf= 1e16; -ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;} -ll expomod(ll a, ll b, ll mod){ - ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res; -} -struct triplet{ - ll x,y,gcd; -}; - -struct triplet extended_Euclid(ll a, ll b){ - if(b == 0){ - triplet ans; - ans.gcd = a; - ans.x = 1; - ans.y = 0; - return ans; - } - - triplet ans2 = extended_Euclid(b, a%b); - triplet finalAns; - /* - ax + by = gcd(a, b) - gcd(a, b) = gcd(b, a%b) - gcd(b, a%b) = bx1 + (a%b)y1 - a%b = a − (a/b) ∗ b - so... - ax + by = bx1 + (a%b)y1 - ax + by = bx1 + (a − (a/b) ∗ b)y1 - ax + by = ay1 + b(x1 − (a/b) ∗ y1) - - so... - - x = y1 - y = x1 − (a/b) ∗ y1 - */ - finalAns.gcd = ans2.gcd; - finalAns.x = ans2.y; - finalAns.y = (ans2.x) - (a/b)*(ans2.y); - return finalAns; -} - -ll moduloInverse(ll num1, ll modulo){ -triplet ans = extended_Euclid(num1,modulo); -//return ans.x; // for negative values allowed -return (ans.x + modulo)%modulo; // for only positive values -} - -ll endNumber = 1000001; -vll smallestPrimeFactors(endNumber,0); -//O(N*log(log(n))) -void sieveMethodSmallesPrimeFactors(){ - rep(1,endNumber,i){ - smallestPrimeFactors[i] = i; - } - for(ll j = 2; j <= endNumber-1 ; j++){ - if(smallestPrimeFactors[j] == j){ - for(ll k = j*j;k < endNumber; k += j){ - if(smallestPrimeFactors[k] == k) - smallestPrimeFactors[k] = j; - } - } - } -} - -class DSU{ -public: - long long n; - vector size, par; - vector vis; - - DSU(long long n){ - this -> n = n; - size.resize(n); - par.resize(n); - vis.resize(n); - - for(long long i = 0; i < n; ++i){ - par[i] = i; - size[i] = 1; - vis[i] = 0; - } - } - - long long find_leader(long long u){ - if (u == par[u]) - return u; - return par[u] = find_leader(par[u]); - } - - void merge(long long u, long long v){ - vis[u] = 1; - vis[v] = 1; - u = find_leader(u); v = find_leader(v); - if (u == v) return; - - if (size[u] < size[v]){ - swap(u, v); - } - size[u] += size[v]; - par[v] = u; - } - - long long count_components(){ - long long cnt = 0; - for (long long i = 0; i < n; ++i){ - if (par[i] == i) ++cnt; - } - - return cnt; - } -};struct segNode -{ - long long sum; - - segNode() - { - sum = 0; - } - - void merge(segNode &x, segNode &y, ll ind) - { - if(ind%2 == 1) - sum = x.sum | y.sum; - else - sum = x.sum & y.sum; - } - - void update(long long val) - { - sum = val; - } -}; - -class segTree -{ - long long n; - vector tree; - -public: - segTree() {} - - segTree(long long n) - { - this->n = n; - tree.resize(4 * n); - } - - segTree(vector &v, long long n) - { - this->n = n; - tree.resize(4 * n); - fill(all(tree), segNode()); - - build(1, 0, n - 1, v); - } - - void build(long long node, long long l, long long r, vector &v) - { - if (l == r) - { - tree[node].update(v[l]); - return; - } - - long long mid = l + (r - l) / 2; - build(node << 1, l, mid, v); - build(node << 1 | 1, mid + 1, r, v); - - tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid); - } - - void update(long long pos, long long val) - { - update(1, 0, n - 1, pos, val); - } - - void update(long long node, long long l, long long r, long long pos, long long val) - { - if (l == r) - { - tree[node].update(val); - return; - } - - long long mid = l + (r - l) / 2; - if (pos <= mid) - { - update(node << 1, l, mid, pos, val); - } - else - { - update(node << 1 | 1, mid + 1, r, pos, val); - } - - tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid); - } - - long long query(long long s, long long e) - { - segNode ans = query(1, 0, n - 1, s, e); - - return ans.sum; - } - - segNode query(long long node, long long l, long long r, long long s, long long e) - { - if (l >= s && r <= e) - return tree[node]; - - if (l > e || r < s) - return segNode(); - - long long mid = l + (r - l) / 2; - - segNode ans, left, right; - left = query(node << 1, l, mid, s, e); - right = query(node << 1 | 1, mid + 1, r, s, e); - ans.merge(left, right, mid); - - return ans; - } -}; - -void solve() -{ - int n, m; - cin >> n >> m; - vector a(n); - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - vector b(m); - for (int i = 0; i < m; i++) { - cin >> b[i]; - } - sort(a.begin(), a.end()); - multiset s; - for (int i = 0; i < m; i++) { - s.insert(b[i]); - } - int lft = n; - while (lft > 0 && !s.empty() && int(s.size()) <= lft) { - auto it = prev(s.end()); - int x = *it; - s.erase(it); - if (x == a[lft - 1]) { - lft -= 1; - continue; - } - if (x < a[lft - 1]) { - break; - } - s.insert(x / 2); - s.insert((x + 1) / 2); - } - if (lft == 0 && s.size() == 0) { - cout << ""Yes"" << '\n'; - } else { - cout << ""No"" << '\n'; - } -} - -int main() -{ - // sieveMethodSmallesPrimeFactors(); - SMIT_FEFAR; - bool test_cases = 1; - ll t=1; - if(test_cases)cin>>t; - while (t--) solve(); - return 0; -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -template using oset = tree, rb_tree_tag, tree_order_statistics_node_update>; - -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; -#define SMIT_FEFAR \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define MOD 1000000007 -#define MOD2 998244353 - -#define pb push_back -#define ppb pop_back -#define vvi vector> -#define vvll vector> -#define vvc vector> -#define vi vector -#define pll pair -#define vpll vector -#define mp make_pair -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define sz(x) ((ll)(x).size()) -#define all(x) (x).begin(), (x).end() -#define vll vector -#define yes cout << ""YES\n""; -#define no cout << ""NO\n""; -#define minus cout<<-1<<""\n""; -#define rep(l,r,i) for(ll i = l;i=r;i--) -#define print cout<< -#define nline ""\n"" -ll inf= 1e16; -ll expo(ll a,ll b){ll res=1;while(b>0){if(b&1){res=res*a;}b=b>>1;a*=a;}return res;} -ll expomod(ll a, ll b, ll mod){ - ll res=1;while(b>0){if(b&1){res=(res*a)%mod;}b=b>>1;a= (a*a)%mod;}return res; -} -struct triplet{ - ll x,y,gcd; -}; - -struct triplet extended_Euclid(ll a, ll b){ - if(b == 0){ - triplet ans; - ans.gcd = a; - ans.x = 1; - ans.y = 0; - return ans; - } - - triplet ans2 = extended_Euclid(b, a%b); - triplet finalAns; - /* - ax + by = gcd(a, b) - gcd(a, b) = gcd(b, a%b) - gcd(b, a%b) = bx1 + (a%b)y1 - a%b = a − (a/b) ∗ b - so... - ax + by = bx1 + (a%b)y1 - ax + by = bx1 + (a − (a/b) ∗ b)y1 - ax + by = ay1 + b(x1 − (a/b) ∗ y1) - - so... - - x = y1 - y = x1 − (a/b) ∗ y1 - */ - finalAns.gcd = ans2.gcd; - finalAns.x = ans2.y; - finalAns.y = (ans2.x) - (a/b)*(ans2.y); - return finalAns; -} - -ll moduloInverse(ll num1, ll modulo){ -triplet ans = extended_Euclid(num1,modulo); -//return ans.x; // for negative values allowed -return (ans.x + modulo)%modulo; // for only positive values -} - -ll endNumber = 1000001; -vll smallestPrimeFactors(endNumber,0); -//O(N*log(log(n))) -void sieveMethodSmallesPrimeFactors(){ - rep(1,endNumber,i){ - smallestPrimeFactors[i] = i; - } - for(ll j = 2; j <= endNumber-1 ; j++){ - if(smallestPrimeFactors[j] == j){ - for(ll k = j*j;k < endNumber; k += j){ - if(smallestPrimeFactors[k] == k) - smallestPrimeFactors[k] = j; - } - } - } -} - -class DSU{ -public: - long long n; - vector size, par; - vector vis; - - DSU(long long n){ - this -> n = n; - size.resize(n); - par.resize(n); - vis.resize(n); - - for(long long i = 0; i < n; ++i){ - par[i] = i; - size[i] = 1; - vis[i] = 0; - } - } - - long long find_leader(long long u){ - if (u == par[u]) - return u; - return par[u] = find_leader(par[u]); - } - - void merge(long long u, long long v){ - vis[u] = 1; - vis[v] = 1; - u = find_leader(u); v = find_leader(v); - if (u == v) return; - - if (size[u] < size[v]){ - swap(u, v); - } - size[u] += size[v]; - par[v] = u; - } - - long long count_components(){ - long long cnt = 0; - for (long long i = 0; i < n; ++i){ - if (par[i] == i) ++cnt; - } - - return cnt; - } -};struct segNode -{ - long long sum; - - segNode() - { - sum = 0; - } - - void merge(segNode &x, segNode &y, ll ind) - { - if(ind%2 == 1) - sum = x.sum | y.sum; - else - sum = x.sum & y.sum; - } - - void update(long long val) - { - sum = val; - } -}; - -class segTree -{ - long long n; - vector tree; - -public: - segTree() {} - - segTree(long long n) - { - this->n = n; - tree.resize(4 * n); - } - - segTree(vector &v, long long n) - { - this->n = n; - tree.resize(4 * n); - fill(all(tree), segNode()); - - build(1, 0, n - 1, v); - } - - void build(long long node, long long l, long long r, vector &v) - { - if (l == r) - { - tree[node].update(v[l]); - return; - } - - long long mid = l + (r - l) / 2; - build(node << 1, l, mid, v); - build(node << 1 | 1, mid + 1, r, v); - - tree[node].merge(tree[node << 1], tree[node << 1 | 1],mid); - } - - void update(long long pos, long long val) - { - update(1, 0, n - 1, pos, val); - } - - void update(long long node, long long l, long long r, long long pos, long long val) - { - if (l == r) - { - tree[node].update(val); - return; - } - - long long mid = l + (r - l) / 2; - if (pos <= mid) - { - update(node << 1, l, mid, pos, val); - } - else - { - update(node << 1 | 1, mid + 1, r, pos, val); - } - - tree[node].merge(tree[node << 1], tree[node << 1 | 1], mid); - } - - long long query(long long s, long long e) - { - segNode ans = query(1, 0, n - 1, s, e); - - return ans.sum; - } - - segNode query(long long node, long long l, long long r, long long s, long long e) - { - if (l >= s && r <= e) - return tree[node]; - - if (l > e || r < s) - return segNode(); - - long long mid = l + (r - l) / 2; - - segNode ans, left, right; - left = query(node << 1, l, mid, s, e); - right = query(node << 1 | 1, mid + 1, r, s, e); - ans.merge(left, right, mid); - - return ans; - } -}; - -void solve() -{ - ll n,m; cin >> n >> m; - vll a(n),b(m); - rep(0,n,i){ - cin>>a[i]; - } - rep(0,m,i)cin>>b[i]; - sort(all(a)); - sort(all(b)); - map m2; - rep(0,m,i){ - m2[b[i]]++; - } - vll at; - map ma; - rep(0,n,i){ - if(m2.find(a[i]) != m2.end()){ - // m[b[i]]--; - ma[a[i]]++; - if(m2[a[i]] > 1)m2[a[i]]--; - else m2.erase(a[i]); - } - } - rep(0,n,i){ - if(ma.find(a[i]) != ma.end()){ - if(ma[a[i]] > 1)ma[a[i]]--; - else ma.erase(a[i]); - } - else{ - at.pb(a[i]); - } - } - ll l1 = 0; - ll l2 = 0; - n = at.size(); - vll bt; - for(auto i : m2){ - ll num = i.second; - rep(0, num ,j){ - bt.pb((ll)i.first); - } - } - m = bt.size(); - while(l1 < n && l2 < m){ - if(at[l1] > bt[l2]){ - no - return; - } - else{ - if(l1 == n-1){ - no - return; - } - else{ - if(at[l1] + at[l1+1] < bt[l2]){ - if(abs(at[l1] - at[l1+1]) <= 1){ - at[l1+1] = at[l1]+at[l1+1]; - } - else{ - no - return; - } - l1++; - } - else if(at[l1] + at[l1+1] > bt[l2]){ - no - return; - } - else{ - if(abs(at[l1] - at[l1+1]) <= 1){ - l1++; - l1++; - l2++; - } - else{ - no - return; - } - } - } - } - } - if(l1 ==n && l2 == m){ - yes - return; - } - no -} - -int main() -{ - // sieveMethodSmallesPrimeFactors(); - SMIT_FEFAR; - bool test_cases = 1; - ll t=1; - if(test_cases)cin>>t; - while (t--) solve(); - return 0; -}",1 -Linly.,2061D - Kevin and Numbers,c++20 ,302624853,302628304,"#pragma GCC optimize(2) -#include -using namespace std; -#define ll long long -const int INF=0x3f3f3f3f; -const int mod=1e9+7; -const int N=200005; - -int a[N],b[N]; -void solve(){ - int n,m;cin>>n>>m; - priority_queueqe1,qe2; - int sum=0; - for(int i=1;i<=n;i++){ - cin>>a[i]; - sum+=a[i]; - qe1.push(a[i]); - } - for(int i=1;i<=m;i++){ - cin>>b[i]; - sum-=b[i]; - qe2.push(b[i]); - } - if(sum){ - cout<<""NO""<x){ - q2.pop(); - q2.push((y+1)/2); - q2.push(y/2); - } - if(y>_; - while(_--){ - solve(); - } - return 0; -}","#pragma GCC optimize(2) -#include -using namespace std; -#define ll long long -const int INF=0x3f3f3f3f; -const int mod=1e9+7; -const int N=200005; - -int a[N],b[N]; -void solve(){ - int n,m;cin>>n>>m; - priority_queueqe1,qe2; - int sum=0; - for(int i=1;i<=n;i++){ - cin>>a[i]; - sum+=a[i]; - qe1.push(a[i]); - } - for(int i=1;i<=m;i++){ - cin>>b[i]; - sum-=b[i]; - qe2.push(b[i]); - } - if(sum){ - cout<<""NO""<x){ - qe2.pop(); - qe2.push((y+1)/2); - qe2.push(y/2); - } - if(y>_; - while(_--){ - solve(); - } - return 0; -}",2 -Wave0466,2061D - Kevin and Numbers,c++23 ,302732728,302734406,"#include -#define int long long -using namespace std; -const int N = 5e5 + 6; - -int n, m; -int a[N], b[N]; - -void solve() -{ - cin >> n >> m; - multiset s; - for(int i = 1; i <= n; i ++) cin >> a[i], s.insert(a[i]); - for(int i = 1; i <= m; i ++) cin >> b[i]; - - auto dfs = [&](auto self, int u) -> bool - { - if(u == 0) return false; - if(s.count(u)) - { - s.erase(s.find(u)); - return true; - } - return (self(self, u / 2) && self(self, u - u / 2)); - }; - for(int i = 1; i <= m; i ++) - if(!dfs(dfs, b[i])) {cout << ""No\n""; return;} - if(s.empty()) cout << ""Yes\n""; - else cout << ""No\n""; -} - -signed main() -{ - ios::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int testcase = 1; - cin >> testcase; - while(testcase --) solve(); - return 0; -}","#include -#define int long long -using namespace std; -const int N = 5e5 + 6; - -int n, m; -int a[N], b[N]; - -void solve() -{ - cin >> n >> m; - multiset s; - for(int i = 1; i <= n; i ++) cin >> a[i], s.insert(a[i]); - for(int i = 1; i <= m; i ++) cin >> b[i]; - - auto dfs = [&](auto self, int u) -> bool - { - if(u == 0) return false; - if(s.contains(u)) - { - s.erase(s.find(u)); - return true; - } - return (self(self, u / 2) && self(self, u - u / 2)); - }; - for(int i = 1; i <= m; i ++) - if(!dfs(dfs, b[i])) {cout << ""No\n""; return;} - if(s.empty()) cout << ""Yes\n""; - else cout << ""No\n""; -} - -signed main() -{ - ios::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int testcase = 1; - cin >> testcase; - while(testcase --) solve(); - return 0; -}",2 -Blanket_blackness,2061D - Kevin and Numbers,c++23 ,303876725,303877985,"#include -using namespace std; -typedef long long int ll; -#define endl ""\n"" -#define take(x) \ - for (auto &y : x) \ - cin >> y; -#define show(x) \ - for (auto y : x) \ - cout << y << "" ""; \ - cout << endl; -#define pb push_back -#define max3(a, b, c) max(max((a), (b)), (c)) -#define max4(a, b, c, d) max(max((a), (b)), max((c), (d))) -#define min3(a, b, c) min(min((a), (b)), (c)) -#define min4(a, b, c, d) min(min((a), (b)), min((c), (d))) -#define all(v) v.begin(), v.end() -ll M = 998244353; -ll mod = 1e9 + 7; - -void solve() -{ - ll n,m; - cin>>n>>m; - vector a(n); - vector b(m); - map mp; - priority_queue pq; - for(int i = 0;i>a[i]; - mp[a[i]]++; - } - sort(all(a)); - for(int i = 0;i>b[i]; - pq.push(b[i]); - } - int used = 0; - while(!pq.empty() && used <= n) - { - if(pq.size() > n){ - cout<<""No""<=1) - { - mp[tp]--; - used++; - continue; - } - if(tp&1) - { - ll x = (tp+1)/2; - ll y = tp - x; - if(mp[x]>=1 && mp[y]>=1) - { - used += 2; - mp[x]--; - mp[y]--; - continue; - } - else if(mp[x]>=1) - { - used+=1; - mp[x]--; - pq.push(y); - continue; - } - else if(mp[y]>=1) - { - used+=1; - mp[y]--; - pq.push(x); - continue; - } - else - { - pq.push(x); - pq.push(y); - continue; - } - } - else - { - ll x = (tp+1)/2; - ll y = tp - x; - // cout<=1 && mp[y]>=1) - { - used += 2; - mp[x]--; - mp[y]--; - continue; - } - else if(mp[x]>=1) - { - used+=1; - mp[x]--; - pq.push(y); - continue; - } - else if(mp[y]>=1) - { - used+=1; - mp[y]--; - pq.push(x); - continue; - } - else - { - pq.push(x); - pq.push(y); - continue; - } - } - - } - if(pq.empty() && n == used) - { - cout<<""Yes""<> tt; - while (tt--) - { - solve(); - } - - return 0; -}","#include -using namespace std; -typedef long long int ll; -#define endl ""\n"" -#define take(x) \ - for (auto &y : x) \ - cin >> y; -#define show(x) \ - for (auto y : x) \ - cout << y << "" ""; \ - cout << endl; -#define pb push_back -#define max3(a, b, c) max(max((a), (b)), (c)) -#define max4(a, b, c, d) max(max((a), (b)), max((c), (d))) -#define min3(a, b, c) min(min((a), (b)), (c)) -#define min4(a, b, c, d) min(min((a), (b)), min((c), (d))) -#define all(v) v.begin(), v.end() -ll M = 998244353; -ll mod = 1e9 + 7; - -void solve() -{ - ll n,m; - cin>>n>>m; - vector a(n); - vector b(m); - map mp; - priority_queue pq; - for(int i = 0;i>a[i]; - mp[a[i]]++; - } - sort(all(a)); - for(int i = 0;i>b[i]; - pq.push(b[i]); - } - int used = 0; - while(!pq.empty() && used <= n) - { - if(pq.size() > n){ - cout<<""No""<=1) - { - mp[tp]--; - used++; - continue; - } - if(tp&1) - { - ll x = (tp+1)/2; - ll y = tp - x; - if(mp[x]>=1 && mp[y]>=1) - { - used += 2; - mp[x]--; - mp[y]--; - continue; - } - else if(mp[x]>=1) - { - used+=1; - mp[x]--; - pq.push(y); - // mp[y]++; - continue; - } - else if(mp[y]>=1) - { - used+=1; - mp[y]--; - pq.push(x); - // mp[x]++; - continue; - } - else - { - pq.push(x); - pq.push(y); - // mp[x]++; - // mp[y]++; - continue; - } - } - else - { - ll x = (tp+1)/2; - ll y = tp - x; - // cout<=2) - { - used += 2; - mp[x]--; - mp[x]--; - continue; - } - else if(mp[x]>=1) - { - used+=1; - mp[x]--; - pq.push(x); - // mp[y]++; - continue; - } - else - { - pq.push(x); - pq.push(x); - // mp[x]++; - // mp[y]++; - continue; - } - } - - } - if(pq.empty()) - { - for(auto i:mp) - { - if(i.second) - { - cout<<""No""<> tt; - while (tt--) - { - solve(); - } - - return 0; -}",2 -Siyam_Talukder,2061D - Kevin and Numbers,c++20 ,313989425,313994927,"#include - -using namespace std; - - - -#ifdef LOCAL - -#include ""debug.h"" - -#else - -#define debug() - -#define db(x) - -#endif - - - -#define INF 1e18 - -#define endl '\n' - -#define ff first - -#define ss second - -#define pb push_back - -#define int long long - -#define mod 1000000007 - -#define pii 2 * acos(0.0) - -#define double long double - -#define sz(x) ((int)(x).size()) - -#define all(x) (x).begin(), (x).end() - -#define rall(a) (a).rbegin(),(a).rend() - -#define deci(x) cout << fixed << setprecision(x); - -#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end()) - -#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());} - -#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL) - -templateistream &operator>>(istream &cin, vector&a) {for (auto&x : a)cin >> x; return cin;} - - - - - -int32_t main() { - - shera(); - - debug(); - - - - int tc; tc = 1; - - cin >> tc; - - for (int ii = 1; ii <= tc; ii++) { - - - - int n, m ; cin >> n >> m; - - vectora(n); cin >> a; - - vectorb(m); cin >> b; - - mapmp; - - priority_queue, greater>as; - - - - for (int i = 0; i < m ; i++) { - - mp[b[i]]++; - - } - - - - for (int i = 0; i < n ; i++) { - - if (!mp[a[i]]) { - - as.push(a[i]); - - } - - else { - - mp[a[i]]--; - - } - - } - - db(as) - - - - while (!as.empty()) { - - int x1 = as.top(); - - as.pop(); - - db(x1) - - if (mp[x1] ) { - - mp[x1]--; - - continue; - - } - - if (as.empty()) { - - as.push( x1); - - break; - - } - - int x2 = as.top(); - - as.pop(); - - - - if (x2 - x1 > 1)break; - - as.push(x2 + x1); - - } - - bool ok = 0; - - for (int i = 0; i < m ; i++) { - - if (mp[b[i]])ok = 1; - - } - - - - if (!ok && as.empty())cout << ""Yes"" << endl; - - else cout << ""No"" << endl; - - - - - - - - - - - - - - } - - - - return 0; - -}","#include - -using namespace std; - - - -#ifdef LOCAL - -#include ""debug.h"" - -#else - -#define debug() - -#define db(x) - -#endif - - - -#define INF 1e18 - -#define endl '\n' - -#define ff first - -#define ss second - -#define pb push_back - -#define int long long - -#define mod 1000000007 - -#define pii 2 * acos(0.0) - -#define double long double - -#define sz(x) ((int)(x).size()) - -#define all(x) (x).begin(), (x).end() - -#define rall(a) (a).rbegin(),(a).rend() - -#define deci(x) cout << fixed << setprecision(x); - -#define rmv(x,a) x.erase(remove(x.begin(),x.end(),a),x.end()) - -#define unq(x) {x.erase(unique(x.begin(),x.end()),x.end());} - -#define shera() ios_base::sync_with_stdio(1);cin.tie(NULL);cout.tie(NULL) - -templateistream &operator>>(istream &cin, vector&a) {for (auto&x : a)cin >> x; return cin;} - - - - - -bool solve(multiset& a, int n) { - - if (a.empty()) return false; - - if (a.count(n)) { - - a.erase(a.find(n)); - - return true; - - } else { - - if (n == 1)return false; - - } - - - - int left = n / 2; - - int right = n - left; - - - - if (solve(a, left) && solve(a, right)) return true; - - - - return false; - -} - - - - - -int32_t main() { - - shera(); - - debug(); - - - - int tc; tc = 1; - - cin >> tc; - - for (int ii = 1; ii <= tc; ii++) { - - - - int n, m ; cin >> n >> m; - - multiseta, b; - - vectorv(n); - - for (int i = 0; i < n ; i++) { - - int x; cin >> x; - - v[i] = x; - - a.insert(x); - - } - - for (int i = 0; i < m ; i++) { - - int x; cin >> x; - - b.insert(x); - - } - - - - - - for (int i = 0; i < n ; i++) { - - if (b.find(v[i]) != b.end()) { - - a.erase(a.find(v[i])); - - b.erase(b.find(v[i])); - - } - - } - - - - if (a.empty()) { - - if (b.empty()) { - - cout << ""Yes"" << endl; - - } - - else { - - cout << ""No"" << endl; - - } - - continue; - - } - - if (b.empty()) { - - cout << ""No"" << endl; - - continue; - - } - - - - bool ok = 1; - - db(a) - - db(b) - - - - - - for (auto u : b ) { - - ok &= solve(a, u); - - db(ok) - - } - - - - if (ok && a.empty()) { - - cout << ""Yes"" << endl; - - } else { - - cout << ""No"" << endl; - - } - - - - - - - - - - - - - - - - - - - - - - - - - - } - - - - return 0; - -}",2 -vrgkar,2061D - Kevin and Numbers,c++20 ,303592702,303590287,"#include -using namespace std; - -// Function to check if sequence a can be transformed into sequence b -string canTransform(vector& a, vector& b) { - long long sum_a = 0, sum_b = 0; - - // Calculate the sum of elements in a and b - for (int x : a) sum_a += x; - for (int x : b) sum_b += x; - - // If sums are not equal, transformation is impossible - if (sum_a != sum_b) { - return ""No""; - } - - // Count frequencies of elements in a and b - map count_a, count_b; - for (int x : a) count_a[x]++; - for (int x : b) count_b[x]++; - - // Try to reduce count_a to count_b - while (!count_a.empty()) { - // Find the smallest element in count_a - int min_a = count_a.begin()->first; - - bool found = false; - for (auto& [target, cnt] : count_b) { - if (abs(min_a - target) <= 1) { - if (count_a[min_a] > 0) { - count_a[min_a]--; - if (count_a[min_a] == 0) { - count_a.erase(min_a); - } - - if (target == min_a) { - count_b[target]--; - if (count_b[target] == 0) { - count_b.erase(target); - } - found = true; - break; - } else { - // Combine min_a with another element to form target - int needed = target - min_a; - if (count_a.count(needed) && count_a[needed] > 0) { - count_a[needed]--; - if (count_a[needed] == 0) { - count_a.erase(needed); - } - - count_b[target]--; - if (count_b[target] == 0) { - count_b.erase(target); - } - found = true; - break; - } - } - } - } - } - - if (!found) { - return ""No""; - } - } - - if (!count_b.empty()) { - return ""No""; - } - - return ""Yes""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - int n, m; - cin >> n >> m; - - vector a(n), b(m); - for (int i = 0; i < n; ++i) cin >> a[i]; - for (int i = 0; i < m; ++i) cin >> b[i]; - - cout << canTransform(a, b) << '\n'; - } - - return 0; -}","#include - -using namespace std; -typedef long long ll; -unordered_mapumap; - -bool dfs(int val) { - if (umap.find(val) != umap.end()) { - if (umap[val] > 0) { - umap[val]-=1; - return true; - } - } - if (val==1) { - return false; - } - if (val%2==0) { - return dfs(val/2) && dfs(val/2); - } else { - return dfs(val/2) && dfs((val/2)+1); - } -} - -void solve() { - umap.clear(); - int n; int m; ll suma = 0; ll sumb = 0; - cin >> n >> m; - int a[n]; - - for (int i=0; i < n; i++) { - cin >> a[i]; - suma += a[i]; - } - - int b[m]; - for (int i=0; i < m; i++) { - cin >> b[i]; - sumb += b[i]; - } - - if (suma != sumb) { - cout << ""No\n""; - return; - } - for (int i = 0; i < n; i++) { - umap[a[i]]+=1; - } - - for (int i = 0; i < m; i++) { - if (!dfs(b[i])) { - cout << ""No\n""; - return; - } - } - cout << ""Yes\n""; - - umap.clear(); -} - -int main() { - int t; - cin >> t; - while (t--) { - solve(); - } - -}",1 -Jayasurya2006,2061D - Kevin and Numbers,c++23 ,302551632,302559917,"#include -using namespace std; -#define int long long -int mod = 998244353; -#define fr(i, n) for (int i = 0; i < n; i++) -#define fr1(i, n) for (int i = 1; i < n; i++) -#define vi vector -int hcf(int a, int g) -{ - if (g == 0) - return a; - else - return hcf(g, a % g); -} -int lcm(int a, int g) { return (a * g) / hcf(a, g); } -int modInverse(int a, int mod) { - int res = 1, p = mod - 2; - while (p > 0) { - if (p & 1) res = (res * a) % mod; - a = (a * a) % mod; - p >>= 1; - } - return res; -} -int N=1e6; -vi f(N+1,1),inv_f(N+1,1); -void precompute() { - for (int i = 2; i <= N; ++i) { - f[i] = (f[i - 1] * i) % mod; - } - inv_f[N] = modInverse(f[N], mod); - for (int i = N - 1; i >= 1; --i) { - inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod; - } -} -int ncr(int n, int r) { - if (r > n) return 0; - return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod; -} - -void solve() -{ - int n,m; - cin>>n>>m; - vi a(n); - vi b(m); - fr(i,n) cin>>a[i]; - fr(i,m) cin>>b[i]; - map ma,mb; - fr(i,m){ - mb[b[i]]++; - } - fr(i,n){ - ma[a[i]]++; - } - sort(a.begin(),a.end()); - fr(i,m){ - if(ma[b[i]]>0 && mb[b[i]]>0){ - int y=min(ma[b[i]],mb[b[i]]); - ma[b[i]]-=y; - mb[b[i]]-=y; - } - } - int f=0,x=0; - - for(int i=0;i0){ - mb[x+a[i]]--; - f=0; - x=0; - } - else x=x+a[i]; - ma[a[i]]--; - } - - } - } - if(x!=0){ - cout<<""NO""<>t; - while(t--) - solve(); - return 0; -} -","#include -using namespace std; -#define int long long -int mod = 998244353; -#define fr(i, n) for (int i = 0; i < n; i++) -#define fr1(i, n) for (int i = 1; i < n; i++) -#define vi vector -int hcf(int a, int g) -{ - if (g == 0) - return a; - else - return hcf(g, a % g); -} -int lcm(int a, int g) { return (a * g) / hcf(a, g); } -int modInverse(int a, int mod) { - int res = 1, p = mod - 2; - while (p > 0) { - if (p & 1) res = (res * a) % mod; - a = (a * a) % mod; - p >>= 1; - } - return res; -} -int N=1e6; -vi f(N+1,1),inv_f(N+1,1); -void precompute() { - for (int i = 2; i <= N; ++i) { - f[i] = (f[i - 1] * i) % mod; - } - inv_f[N] = modInverse(f[N], mod); - for (int i = N - 1; i >= 1; --i) { - inv_f[i] = (inv_f[i + 1] * (i + 1)) % mod; - } -} -int ncr(int n, int r) { - if (r > n) return 0; - return (f[n] * inv_f[r] % mod) * inv_f[n - r] % mod; -} - -void solve() -{ - int n,m; - cin>>n>>m; - priority_queue a,b; - fr(i,n){ - int x; - cin>>x; - a.push(x); - } - fr(i,m){ - int x; - cin>>x; - b.push(x); - } - while(!a.empty()){ - if(b.empty() || b.size()>a.size()){ - cout<<""no""<y){ - cout<<""no""<>t; - while(t--) - solve(); - return 0; -} -",2 -Kristiana,2061D - Kevin and Numbers,c++20 ,302722884,302748749,"#include -using namespace std; -using i64 = long long; -using i128 = __int128; - -int n,m; -void solve(){ - cin>>n>>m; - vector a(n),b(m); - multiset se1,se2; - for(auto &i:a) cin>>i,se1.insert(i); - for(auto &i:b) cin>>i,se2.insert(i); - //int now = 0; - while(!se2.empty()&&se2.size() tmp; - for(auto i:se2){ - if(se1.find(i)==se1.end()){ - if(i/2<=0) continue; - tmp.insert(i/2); - tmp.insert((i+1)/2); - }else se1.erase(se1.find(i)); - } - se2.swap(tmp); - } - if(se1.size()==se2.size()){ - for(auto i:se2){ - if(se1.find(i)==se1.end()){ - cout<<""No\n""; - return; - } - } - cout<<""Yes\n""; - }else{ - cout<<""No\n""; - } -} - -signed main(){ - ios::sync_with_stdio(0);cin.tie(0); - int t; - cin>>t; - while(t--) solve(); - return 0; -} - - -","#include -using namespace std; -using i64 = long long; -using i128 = __int128; - -int n,m; -void solve(){ - cin>>n>>m; - vector a(n),b(m); - priority_queue q; - i64 sa=0,sb=0; - for(auto &i:a) cin>>i,sa+=i; - for(auto &i:b) cin>>i,sb+=i; - if(sa!=sb){ - cout<<""No\n""; - return; - } - for(auto i:b) q.push(i); - sort(a.begin(),a.end(),greater()); - int idx = 0; - //cout<<""check 1\n""; - while(!q.empty()){ - // cout<>t; - while(t--) solve(); - return 0; -} - - - - -",2 -tr1ten,2061D - Kevin and Numbers,c++23 ,305104835,305104277,"#include -using namespace std; -#define ss second -#define ff first -#define int long long -#define rep(i,a,b) for (int i = (a); i < (b); i++) -#define per(i,a,b) for (int i = (b)-1; i >= (a); i--) -#define tkv(vec,sz) rep(i,0,sz) cin>>vec[i] -#define srv(vec) sort(vec.begin(), vec.end()) -#define all(x) x.begin(), x.end() -#define pvc(vec) for(auto x:vec) cout< vi; -typedef vector vii; -typedef pair pi; -inline int ctz(int x) { return __builtin_ctzll(x);} -inline int pc(int x) {return __builtin_popcount(x);} -inline int hset(int x) {return __lg(x);} -/* - NOT use unordered map use map - NOT use seg tree use fenwick tree - THINK before you code -*/ - -const int MOD = 1e9+7; // change me for god sake look at problem mod -const int INF = 1e16+5; -void testcase(){ - int n,m; - cin >> n >> m; - map a,b; - rep(i,0,n){ - int x; - cin >> x; - a[x]++; - } - rep(i,0,m){ - int x; - cin >> x; - b[x]++; - } - while (!b.empty()) { - auto it = b.begin(); - auto req = *it; // Store value before erasing - b.erase(it); - - int d = min(req.second, a[req.first]); - a[req.first] -= d; - req.second -= d; - - if (req.second) { - if (req.first == 1) { - put(""No""); - return; - } - if (req.first % 2) { - b[req.first / 2] += req.second; - b[req.first / 2 + 1] += req.second; - } else { - b[req.first / 2] += 2 * req.second; - } - } -} - - int rem = 0; - for(auto x:a){ - if(x.second!=0){ - put(""No""); - return; - } - } - put(""Yes""); - - - -} -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - // freopen(""input.in"",""r"",stdin); - // freopen(""output.out"",""w"",stdout); - int T=1; - cin>>T; - while(T--) testcase(); - - return 0; -} -","#include -using namespace std; -#define ss second -#define ff first -#define int long long -#define rep(i,a,b) for (int i = (a); i < (b); i++) -#define per(i,a,b) for (int i = (b)-1; i >= (a); i--) -#define tkv(vec,sz) rep(i,0,sz) cin>>vec[i] -#define srv(vec) sort(vec.begin(), vec.end()) -#define all(x) x.begin(), x.end() -#define pvc(vec) for(auto x:vec) cout< vi; -typedef vector vii; -typedef pair pi; -inline int ctz(int x) { return __builtin_ctzll(x);} -inline int pc(int x) {return __builtin_popcount(x);} -inline int hset(int x) {return __lg(x);} -/* - NOT use unordered map use map - NOT use seg tree use fenwick tree - THINK before you code -*/ - -const int MOD = 1e9+7; // change me for god sake look at problem mod -const int INF = 1e16+5; -void testcase(){ - int n,m; - cin >> n >> m; - map a,b; - rep(i,0,n){ - int x; - cin >> x; - a[x]++; - } - int mx = 0; - rep(i,0,m){ - int x; - cin >> x; - b[x]++; - mx = max(x,mx); - } - while (b.size()) - { - auto it = b.begin(); - b.erase(it); - auto req = *it; - int d = min(req.second,a[req.first]); - a[req.first] -=d; - req.second-=d; - if(req.second){ - if(req.first==1){ - put(""No""); - return; - } - if(req.first%2) {b[req.first/2]+=req.second;b[req.first/2+1]+=req.second;} - else {b[req.first/2] += 2*req.second;} - } - - } - int rem = 0; - for(auto x:a){ - if(x.second!=0){ - put(""No""); - return; - } - } - put(""Yes""); - - - -} -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - // freopen(""input.in"",""r"",stdin); - // freopen(""output.out"",""w"",stdout); - int T=1; - cin>>T; - while(T--) testcase(); - - return 0; -} -",1 -Shami_Al,2061D - Kevin and Numbers,c++17 ,315761851,315787858,"#include - - - -using namespace std; - -typedef long long ll; - -typedef long double ld; - -#define pb push_back - -#define dbg(x) //cerr<<#x<<"": ""<>n>>m; - - ll a[n], b[m]; - - for(int i=0;i>a[i]; - - } - - multisetms; - - for(int i=0;i>b[i]; - - ms.insert(b[i]); - - } - - sort(a,a+n); - - sort(b,b+m); - - ll sum=0; - - for(int i=0;i1){ - - cout<<""No\n""; - - return; - - } - - } - - if(ms.empty()){ - - cout<<""Yes\n""; - - } - - else{ - - cout<<""No\n""; - - } - -} - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - //cout.tie(NULL); - - cout.precision(10); - - cout<>t; - - for(int i=1;i<=t;i++){ - - dbg(""case""+to_string(i)); - - //cout<<""Case ""< - - - -using namespace std; - -typedef long long ll; - -typedef long double ld; - -#define pb push_back - -#define dbg(x) //cerr<<#x<<"": ""<mp; - -bool ok(ll x){ - - if(mp.count(x) && mp[x]>0){ - - mp[x]--; - - return true; - - } - - if(x==1){ - - return false; - - } - - if(ok(x/2)&&ok((x+1)/2)){ - - return true; - - } - - return false; - -} - -void code(){ - - mp.clear(); - - int n,m; - - cin>>n>>m; - - ll a[n],b[m]; - - for(int i=0;i>a[i]; - - mp[a[i]]++; - - } - - for(int i=0;i>b[i]; - - } - - for(int i=0;i0){ - - cout<<""No\n""; - - mp.clear(); - - return; - - } - - } - - cout<<""Yes\n""; - - mp.clear(); - -} - -int main(){ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - //cout.tie(NULL); - - cout.precision(10); - - cout<>t; - - for(int i=1;i<=t;i++){ - - dbg(""case""+to_string(i)); - - //cout<<""Case ""< -using namespace std; -#define all(x) (x).begin(), (x).end() -#define rall(a) (a).rbegin(), (a).rend() -#define pb push_back -#define rep(a, i) for (int i = 0; i < (a); i++) -#define read(a, n) for (int i = 0; i < (n); i++) { cin >> a[i]; } -#define pB pop_back -#define mt make_tuple -#define lb lower_bound -#define ub upper_bound -#define fi first -#define se second -#define int long long -#define pi pair -int mod = 998244353; - -void solve(){ - int n, m; cin >> n >> m; - multiset a; - rep(n, i){ - int aa; cin >> aa; - a.insert(aa); - } - multiset b; - rep(m, i){ - int aa; cin >> aa; - b.insert(aa); - } - - - rep(2*n-m, i){ - if(b.empty()){ - cout << ""NO""; - return; - } - - int cur = *prev(b.end()); - b.erase(prev(b.end())); - - if(a.find(cur) != a.end()){ - a.erase(a.find(cur)); - } - else{ - if(cur & 1){ - b.insert(cur/2); - b.insert(cur/2 + 1); - } - - else{ - b.insert(cur/2); - b.insert(cur/2); - } - } - - } - - if(b.empty()) cout << ""YES""; - else - cout << ""NO""; -} - -signed main() { - ios::sync_with_stdio(0); - cin.tie(0); - - int t = 1; - cin >> t; - while (t--) { - solve(); - cout << '\n'; - } - return 0; -} -","//bismillah -#include -using namespace std; -#define all(x) (x).begin(), (x).end() -#define rall(a) (a).rbegin(), (a).rend() -#define pb push_back -#define rep(a, i) for (int i = 0; i < (a); i++) -#define read(a, n) for (int i = 0; i < (n); i++) { cin >> a[i]; } -#define pB pop_back -#define mt make_tuple -#define lb lower_bound -#define ub upper_bound -#define fi first -#define se second -#define int long long -#define pi pair -int mod = 998244353; - -void solve(){ - int n, m; cin >> n >> m; - multiset a; - rep(n, i){ - int aa; cin >> aa; - a.insert(aa); - } - vector b(m); - rep(m, i){ - cin >> b[i]; - } - - vector baru; - for(auto u : b){ - if(!a.empty() && a.find(u) != a.end()){ - a.erase(a.find(u)); - } - else baru.pb(u); - } - - sort(all(baru)); - - //cout << a.size(); - for(auto e : baru){ - if(a.size() < 2){ - cout << ""NO""; - return; - } - int cur = e; - int satu = cur/2; - int dua = satu; - if(cur & 1) dua++; - - while(a.size() > 1 && *a.begin() < satu){ - auto it = a.begin(); - int f = *a.begin(); - it++; - int s = *it; - if(s - f > 1){ - cout << ""NO""; - return; - } - a.erase(a.begin()); - a.erase(it); - a.insert(f + s); - } - - if(a.find(satu) == a.end() || a.find(dua) == a.end()){ - // cout << cur << ' '; - // cout << ""NO""; - cout << ""NO""; - return; - } - else{ - a.erase(a.find(satu)); - a.erase(a.find(dua)); - } - } - - if(!a.empty()) cout << ""NO""; - else - cout << ""YES""; -} - -signed main() { - ios::sync_with_stdio(0); - cin.tie(0); - - int t = 1; - cin >> t; - while (t--) { - solve(); - cout << '\n'; - } - return 0; -} -",1 -BaiLi_nya,2061D - Kevin and Numbers,c++17 ,302701115,302697125,"#include -using namespace std; -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - long long t,n,m,i,x; - cin>>t; - while(t--){ - cin>>n>>m; - multiset a; - stack b; - for(i=0;i>x; - a.insert(x); - } - for(i=0;i>x; - b.push(x); - } - while(!b.empty()){ - x=b.top(); - b.pop(); - if(a.find(x)!=a.end()) - a.erase(a.find(x)); - else if(x==1){ - b.push(x); - break; - } - else{ - b.push(x/2); - b.push((x+1)/2); - } - } - cout<<(b.empty()&&a.empty()?""Yes\n"":""No\n""); - } - return 0; -} -","#include -using namespace std; -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - long long t,n,m,i,x,y; - cin>>t; - while(t--){ - cin>>n>>m; - priority_queue,greater> a; - vector b; - for(i=0;i>x; - a.push(x); - } - for(i=0;i>x; - b.push_back(x); - } - sort(b.begin(),b.end()); - i=0; - while(!a.empty()){ - x=a.top(); - a.pop(); - if(i>=m) - break; - else if(x==b[i]) - i++; - else{ - if(a.empty()) - break; - else{ - y=a.top(); - a.pop(); - if(y-x>1) - break; - else - a.push(x+y); - } - } - } - if(i==m&&a.empty()) - cout<<""Yes\n""; - else - cout<<""No\n""; - } - return 0; -} -",1 -Anon_chan,2061D - Kevin and Numbers,c++20 ,302787899,302788932,"#include -using namespace std; -typedef long long ll; -const ll N=2e5+10; -const ll INF=1e17+10; -const ll MOD=1e9+7; -ll n,m; -ll a[N],b[N]; - -void solve(void){ - cin>>n>>m; - multiset>st1,st2; - ll sum1=0,sum2=0; - for(ll i=1;i<=n;++i){ - cin>>a[i]; - sum1+=a[i]; - st2.insert(a[i]); - } - for(ll i=1;i<=m;++i){ - cin>>b[i]; - sum2+=b[i]; - if(st2.count(b[i])){ - st2.erase(st2.find(b[i])); - } - else st1.insert(b[i]); - } - if(sum1!=sum2){ - cout<<""No\n""; - return; - } - ll f=1; - while(st2.size()&&st1.size()&&st2.size()>=st1.size()){ - auto it=st1.begin(); - ll tmp=*it; - ll x=tmp/2; - ll y=tmp-x; - ll mmax=*st2.begin(); - if(x>mmax||y>mmax){ - break; - } - st1.erase(it); - if(st2.count(x)){ - st2.erase(st2.find(x)); - }else{ - st1.insert(x); - } - if(st2.count(y)){ - st2.erase(st2.find(y)); - }else{ - st1.insert(y); - } - } - if(st1.size()==0&&st2.size()==0)cout<<""Yes\n""; - else cout<<""No\n""; - - -} -int main(void){ - ios::sync_with_stdio(0); - cin.tie(0);cout.tie(0); - ll times=1; - cin>>times; - while(times--)solve(); - return 0; -}","#include -using namespace std; -typedef long long ll; -const ll N=2e5+10; -const ll INF=1e17+10; -const ll MOD=1e9+7; -ll n,m; -ll a[N],b[N]; - -void solve(void){ - cin>>n>>m; - multisetst1,st2; - ll sum1=0,sum2=0; - for(ll i=1;i<=n;++i){ - cin>>a[i]; - sum1+=a[i]; - st1.insert(a[i]); - } - for(ll i=1;i<=m;++i){ - cin>>b[i]; - sum2+=b[i]; - if(st1.count(b[i])){ - st1.erase(st1.find(b[i])); - } - else st2.insert(b[i]); - } - if(sum1!=sum2){ - cout<<""No\n""; - return; - } - ll f=1; - while(st1.size()&&st2.size()){ - ll x=*st1.rbegin(),y=*st2.rbegin(); - if(x>y)break; - if(x==y){ - st1.erase(st1.find(x)); - st2.erase(st2.find(y)); - }else { - st2.erase(st2.find(y)); - st2.insert(y/2); - st2.insert((y+1)/2); - } - } - if(st1.size()==0&&st2.size()==0)cout<<""Yes\n""; - else cout<<""No\n""; - - -} -int main(void){ - ios::sync_with_stdio(0); - cin.tie(0);cout.tie(0); - ll times=1; - cin>>times; - while(times--)solve(); - return 0; -}",2 -ShadowMonarch,2061D - Kevin and Numbers,java,302348511,302349027,"import java.io.*; -import java.security.KeyStore.Entry; -import java.util.*; - -public class Forest { - static class Reader { - final private int BUFFER_SIZE = 1 << 16; - private DataInputStream din; - private byte[] buffer; - private int bufferPointer, bytesRead; - - public Reader() { - din = new DataInputStream(System.in); - buffer = new byte[BUFFER_SIZE]; - bufferPointer = bytesRead = 0; - } - - public Reader(String file_name) throws IOException { - din = new DataInputStream(new FileInputStream(file_name)); - buffer = new byte[BUFFER_SIZE]; - bufferPointer = bytesRead = 0; - } - - public String readLine() throws IOException { - byte[] buf = new byte[64]; // line length - int cnt = 0, c; - while ((c = read()) != -1) { - if (c == '\n') - break; - buf[cnt++] = (byte) c; - } - return new String(buf, 0, cnt); - } - - public int nextInt() throws IOException { - int ret = 0; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (neg) - return -ret; - return ret; - } - - public long nextLong() throws IOException { - long ret = 0; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (neg) - return -ret; - return ret; - } - - public double nextDouble() throws IOException { - double ret = 0, div = 1; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (c == '.') { - while ((c = read()) >= '0' && c <= '9') { - ret += (c - '0') / (div *= 10); - } - } - if (neg) - return -ret; - return ret; - } - - private void fillBuffer() throws IOException { - bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); - if (bytesRead == -1) - buffer[0] = -1; - } - - private byte read() throws IOException { - if (bufferPointer == bytesRead) - fillBuffer(); - return buffer[bufferPointer++]; - } - - public void close() throws IOException { - if (din == null) - return; - din.close(); - } - } - - static Reader sc = new Reader(); - static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - - public static void main(String args[]) throws IOException { - @SuppressWarnings(""unused"") - Reader sc = new Reader(); - long t = inputLong(); - while (t-- > 0) { - long n = inputLong(); - long m = inputLong(); - long a[] = new long[(int) n]; - HashMapmap=new HashMap<>(); - long sum=0; - for (int i = 0; i < n; i++) { - a[i] = inputLong(); - sum+=a[i]; - map.put(a[i],map.getOrDefault(a[i], (long) 0)+1); - } - long sum1=0; - // long b[] = new long[(int) n]; - ArrayListlist=new ArrayList<>(); - for (int i = 0; i < m; i++) { - list.add(inputLong()); - sum1+=list.get(i); - } - if(sum!=sum1){ - System.out.println(""NO"");continue; - } - boolean bool=true; - while(!list.isEmpty()){ - long num=list.get(list.size()-1); - if(map.containsKey(num)){ - map.put(num,map.getOrDefault(num, (long) 0)-1); - list.remove(list.size()-1); - if(map.get(num)<=0){ - map.remove(num); - } - }else{ - list.remove(num); - if(num/2 ==0){bool=false;break;} - else if(ceil(num,2)==0){bool=false;break;} - list.add(num/2); - list.add(ceil1(num,2)); - } - if(!bool)break; - } - if(!bool)System.out.println(""NO""); - else System.out.println(""YES""); - - } - bw.flush(); - bw.close(); - } - - public static long ceil1(long a, long b) { - return (a + b - 1) / b; - } - - - public static boolean checker(long a[]) { - for (int i = 0; i < a.length-1; i++) { - if (a[i] > a[i+1]) - return false; - } - return true; - } - - public static long divisor(long n) { - long cnt = 0; - for (long i = 1; i * i <= n; i++) { - if (n % i == 0) - cnt++; - if ((n / i) % i == 0) - cnt++; - } - return cnt; - } - - public static long powerMod(long base, long exponent, long mod) { - long result = 1; - base = base % mod; // Ensure base is within the mod range - - while (exponent > 0) { - // If exponent is odd, multiply base with result - if ((exponent & 1) == 1) { // Same as (exponent % 2 != 0) - result = (result * base) % mod; - } - // Now exponent must be even - exponent = exponent >> 1; // Equivalent to exponent = exponent / 2 - base = (base * base) % mod; // Square the base - } - return result; - } - - public static long sequence(long n) { - if (n == 1) - return 1; - if (n % 2 == 0) - return 1 + sequence(n / 2); - else - return 1 + sequence(3 * (n) + 1); - } - - public static void matrix(int a[][], int b[][], int i, int j) { - if (i >= a.length) - return; - if (j == a[0].length - 1) { - System.out.println(a[i][j] + b[i][j]); - matrix(a, b, i + 1, 0); - return; - } - System.out.print(a[i][j] + b[i][j] + "" ""); - matrix(a, b, i, j + 1); - } - - public static boolean checker(String s) { - String a = ""1100""; - for (int i = 0; i < s.length() - 3; i++) { - if (a.equals(s.substring(i, i + 4))) - return true; - } - return false; - } - - public static long ceil(long a, long b) { - return (a + b - 1) / b; - } - - public static int inputInt() throws IOException { - return sc.nextInt(); - } - - public static long inputLong() throws IOException { - return sc.nextLong(); - } - - public static double inputDouble() throws IOException { - return sc.nextDouble(); - } - - public static String inputString() throws IOException { - return sc.readLine(); - } - - public static void print(String a) throws IOException { - bw.write(a); - } - - public static void printSp(String a) throws IOException { - bw.write(a + "" ""); - } - - public static void println(String a) throws IOException { - bw.write(a + ""\n""); - } -}","import java.io.*; -import java.security.KeyStore.Entry; -import java.util.*; - -public class Forest { - static class Reader { - final private int BUFFER_SIZE = 1 << 16; - private DataInputStream din; - private byte[] buffer; - private int bufferPointer, bytesRead; - - public Reader() { - din = new DataInputStream(System.in); - buffer = new byte[BUFFER_SIZE]; - bufferPointer = bytesRead = 0; - } - - public Reader(String file_name) throws IOException { - din = new DataInputStream(new FileInputStream(file_name)); - buffer = new byte[BUFFER_SIZE]; - bufferPointer = bytesRead = 0; - } - - public String readLine() throws IOException { - byte[] buf = new byte[64]; // line length - int cnt = 0, c; - while ((c = read()) != -1) { - if (c == '\n') - break; - buf[cnt++] = (byte) c; - } - return new String(buf, 0, cnt); - } - - public int nextInt() throws IOException { - int ret = 0; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (neg) - return -ret; - return ret; - } - - public long nextLong() throws IOException { - long ret = 0; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (neg) - return -ret; - return ret; - } - - public double nextDouble() throws IOException { - double ret = 0, div = 1; - byte c = read(); - while (c <= ' ') - c = read(); - boolean neg = (c == '-'); - if (neg) - c = read(); - do { - ret = ret * 10 + c - '0'; - } while ((c = read()) >= '0' && c <= '9'); - if (c == '.') { - while ((c = read()) >= '0' && c <= '9') { - ret += (c - '0') / (div *= 10); - } - } - if (neg) - return -ret; - return ret; - } - - private void fillBuffer() throws IOException { - bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); - if (bytesRead == -1) - buffer[0] = -1; - } - - private byte read() throws IOException { - if (bufferPointer == bytesRead) - fillBuffer(); - return buffer[bufferPointer++]; - } - - public void close() throws IOException { - if (din == null) - return; - din.close(); - } - } - - static Reader sc = new Reader(); - static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); - - public static void main(String args[]) throws IOException { - @SuppressWarnings(""unused"") - Reader sc = new Reader(); - long t = inputLong(); - while (t-- > 0) { - long n = inputLong(); - long m = inputLong(); - long a[] = new long[(int) n]; - TreeMapmap=new TreeMap<>(); - long sum=0; - for (int i = 0; i < n; i++) { - a[i] = inputLong(); - sum+=a[i]; - map.put(a[i],map.getOrDefault(a[i], (long) 0)+1); - } - long sum1=0; - // long b[] = new long[(int) n]; - ArrayListlist=new ArrayList<>(); - for (int i = 0; i < m; i++) { - list.add(inputLong()); - sum1+=list.get(i); - } - if(sum!=sum1){ - System.out.println(""NO"");continue; - } - boolean bool=true; - while(!list.isEmpty()){ - long num=list.get(list.size()-1); - if(map.containsKey(num)){ - map.put(num,map.getOrDefault(num, (long) 0)-1); - list.remove(list.size()-1); - if(map.get(num)<=0){ - map.remove(num); - } - }else{ - list.remove(list.size()-1); - if(num/2 ==0){bool=false;break;} - else if(ceil(num,2)==0){bool=false;break;} - list.add(num/2); - list.add(ceil1(num,2)); - } - if(!bool)break; - } - if(!bool)System.out.println(""NO""); - else System.out.println(""YES""); - - } - bw.flush(); - bw.close(); - } - - public static long ceil1(long a, long b) { - return (a + b - 1) / b; - } - - - public static boolean checker(long a[]) { - for (int i = 0; i < a.length-1; i++) { - if (a[i] > a[i+1]) - return false; - } - return true; - } - - public static long divisor(long n) { - long cnt = 0; - for (long i = 1; i * i <= n; i++) { - if (n % i == 0) - cnt++; - if ((n / i) % i == 0) - cnt++; - } - return cnt; - } - - public static long powerMod(long base, long exponent, long mod) { - long result = 1; - base = base % mod; // Ensure base is within the mod range - - while (exponent > 0) { - // If exponent is odd, multiply base with result - if ((exponent & 1) == 1) { // Same as (exponent % 2 != 0) - result = (result * base) % mod; - } - // Now exponent must be even - exponent = exponent >> 1; // Equivalent to exponent = exponent / 2 - base = (base * base) % mod; // Square the base - } - return result; - } - - public static long sequence(long n) { - if (n == 1) - return 1; - if (n % 2 == 0) - return 1 + sequence(n / 2); - else - return 1 + sequence(3 * (n) + 1); - } - - public static void matrix(int a[][], int b[][], int i, int j) { - if (i >= a.length) - return; - if (j == a[0].length - 1) { - System.out.println(a[i][j] + b[i][j]); - matrix(a, b, i + 1, 0); - return; - } - System.out.print(a[i][j] + b[i][j] + "" ""); - matrix(a, b, i, j + 1); - } - - public static boolean checker(String s) { - String a = ""1100""; - for (int i = 0; i < s.length() - 3; i++) { - if (a.equals(s.substring(i, i + 4))) - return true; - } - return false; - } - - public static long ceil(long a, long b) { - return (a + b - 1) / b; - } - - public static int inputInt() throws IOException { - return sc.nextInt(); - } - - public static long inputLong() throws IOException { - return sc.nextLong(); - } - - public static double inputDouble() throws IOException { - return sc.nextDouble(); - } - - public static String inputString() throws IOException { - return sc.readLine(); - } - - public static void print(String a) throws IOException { - bw.write(a); - } - - public static void printSp(String a) throws IOException { - bw.write(a + "" ""); - } - - public static void println(String a) throws IOException { - bw.write(a + ""\n""); - } -}",2 -Ozy13,2061D - Kevin and Numbers,c++17 ,303704601,303703548,"/* -CF2061D -30.1.25. -*/ - -#include -using namespace std; - -#define _line << ""\n"" -#define _space << "" "" << -#define ll long long - - -int main(){ - - /*ios_base::sync_with_stdio(false); - cin.tie(0); cout.tie(0);*/ - - int t; cin >> t; - - while (t--){ - priority_queue a,b; - int n,m; cin >> n >> m; - for (int i=0; i> x; - a.push(x); - } - for (int j=0; j> x; - b.push(x); - } - - if (m>n){ - cout << ""no"" _line; continue; - } - - int z=1; - while (!a.empty() || !b.empty()){ - if (a.empty() || b.empty() || b.size()>a.size()) { - z=0; - cout << ""no"" _line; break; - } - if (a.top()==b.top()){ - a.pop(); b.pop(); - } - else { - int x=b.top(); b.pop(); - //cout << x _space b.size() _line; - if (x==1){ - z=0; - cout << ""no"" _line; break; - } - if (x%2){ - b.push(x/2); - b.push(x/2+1); - } - else { - b.push(x/2); - b.push(x/2); - } - } - } - - if (z) cout << ""yes"" _line; - - } - -} -","/* -CF2061D -30.1.25. -*/ - -#include -using namespace std; - -#define _line << ""\n"" -#define _space << "" "" << -#define ll long long - - -int main(){ - - /*ios_base::sync_with_stdio(false); - cin.tie(0); cout.tie(0);*/ - - int t; cin >> t; - - while (t--){ - priority_queue a,b; - int n,m; cin >> n >> m; - for (int i=0; i> x; - a.push(x); - } - for (int j=0; j> x; - b.push(x); - } - - if (m>n){ - cout << ""no"" _line; continue; - } - - int z=1; - while (!a.empty() || !b.empty()){ - if (a.empty() || b.empty()) { - z=0; - cout << ""no"" _line; break; - } - if (a.top()==b.top()){ - a.pop(); b.pop(); - } - else { - int x=b.top(); b.pop(); - if (x==1){ - z=0; - cout << ""no"" _line; break; - } - if (x%2){ - b.push(x/2); - b.push(x/2+1); - } - else { - b.push(x/2); - b.push(x/2); - } - } - } - - if (z) cout << ""yes"" _line; - - } - -} -",1 -ihgazi,2061D - Kevin and Numbers,c++23 ,303912810,303908159,"#include -using namespace std; - -#ifdef LOCAL -#include ""../debug.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -#define all(x) begin(x), end(x) -#define sz(x) (int)(x).size() -#define ff first -#define ss second -#define pb push_back -#define BIG 998244353 -#define MOD 1000000007 -#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vpii; -typedef vector vvi; - -void solve() { - int n,m; - cin >> n >> m; - - vi a(n), b(m); - map freq; - ll cnt = n; - for (int i = 0; i < n; i++) { - cin >> a[i]; - freq[a[i]]++; - } - - priority_queue> pq; - for (int i = 0; i < m; i++) { - cin >> b[i]; - pq.push(b[i]); - } - - while (!pq.empty()) { - ll x = pq.top(); - pq.pop(); - - if (x==0) { - cout << ""No\n""; - return; - } - - if (freq.find(x)!=freq.end() && freq[x]) { - freq[x]--; - cnt--; - continue; - } - else { - ll a = x/2; - ll b = (x+1)/2; - pq.push(a); - pq.push(b); - } - } - - if (cnt==0) cout << ""Yes\n""; - else cout << ""No\n""; -} - -int main() { - auto start = chrono::high_resolution_clock::now(); - fast_io; - int t; - cin >> t; - - while (t--) { - solve(); - } - - #ifdef LOCAL - auto end = chrono::high_resolution_clock::now(); - chrono::duration duration = end - start; - cerr << ""Execution time: "" << duration.count() << "" seconds"" << endl; - #endif -} -","#include -using namespace std; - -#ifdef LOCAL -#include ""../debug.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -#define all(x) begin(x), end(x) -#define sz(x) (int)(x).size() -#define ff first -#define ss second -#define pb push_back -#define BIG 998244353 -#define MOD 1000000007 -#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vpii; -typedef vector vvi; - -void solve() { - int n,m; - cin >> n >> m; - - vi a(n), b(m); - for (int i = 0; i < n; i++) - cin >> a[i]; - - map freq; - ll mx = 0; - for (int i = 0; i < m; i++) { - cin >> b[i]; - mx = max(mx,b[i]); - freq[b[i]]++; - } - - if (n> pq; - for (int i = 0; i < n; i++) { - if (freq.find(a[i])!=freq.end() && freq[a[i]]) { - freq[a[i]]--; - cnt--; - } - else pq.push(a[i]); - } - - while (sz(pq)>1) { - ll x = pq.top(); - pq.pop(); - ll y = pq.top(); - pq.pop(); - - if (y-x>1 || y+x>mx) { - cout << ""No\n""; - return; - } - - y += x; - if (freq.find(y)!=freq.end() && freq[y]) { - freq[y]--; - cnt--; - } - else pq.push(y); - } - - if (cnt==0 && sz(pq)==0) cout << ""Yes\n""; - else cout << ""No\n""; -} - -int main() { - auto start = chrono::high_resolution_clock::now(); - fast_io; - int t; - cin >> t; - - while (t--) { - solve(); - } - - #ifdef LOCAL - auto end = chrono::high_resolution_clock::now(); - chrono::duration duration = end - start; - cerr << ""Execution time: "" << duration.count() << "" seconds"" << endl; - #endif -} -",1 -yutt,2061D - Kevin and Numbers,c++17 ,307420816,307417442,"#include -#define pii pair -#define lowbit(x) (x&-x) -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -const int mod = 998244353; -const int inf = 1e9; -const ll llf = 1e18; -using namespace std; - - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(0); cout.tie(0); - int i, j; - int n, m; - int tt; - cin >> tt; - while (tt--) - { - int x; - mapmymap; - bool flag = 1; - cin >> n >> m; - while (n--) - { - cin >> x; - mymap[x]--; - } - while (m--) - { - cin >> x; - mymap[x]++; - } - for (auto it =mymap.rbegin();it != mymap.rend();) - { - if (it->first== 1) - { - if (it->second) - flag = 0; - } - if (it->second < 0) - { - flag = 0; - break; - } - mymap[it->first / 2] += it->second; - mymap[it->first - it->first / 2] += it->second; - mymap.erase(it->first); - } - int flag1 = 1; - for (auto x : mymap) - { - if (x.second) - flag1 = 0; - } - if (flag && flag1) - cout << ""YeS"" << endl; - else - cout << ""nO"" << endl; - } -}","#include -#define pii pair -#define lowbit(x) (x&-x) -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -const int mod = 998244353; -const int inf = 1e9; -const ll llf = 1e18; -using namespace std; - - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(0); cout.tie(0); - int i, j; - int n, m; - int tt; - cin >> tt; - while (tt--) - { - int x; - mapmapa; - mapmapb; - bool flag = 1; - cin >> n >> m; - while (n--) - { - cin >> x; - mapa[x]++; - } - while (m--) - { - cin >> x; - mapb[x]++; - } - int cnt = 0; - for (auto it = mapb.rbegin();it != mapb.rend();it++) - { - //if (cnt == 2) - // it--; - if (it->first == 1) - { - if (mapa[1] == mapb[1]) - { - mapa.erase(1); - mapb.erase(1); - } - else - flag = 0; - break; - } - if (mapa[it->first] > it->second) - { - flag = 0; - break; - } - - cnt = 0; - if (mapb.find(it->first / 2) == mapb.end())cnt++; - if (mapb.find(it->first / 2) == mapb.end())cnt++; - - mapb[it->first/2] += it->second - mapa[it->first]; - mapb[it->first - it->first / 2] += it->second - mapa[it->first]; - - mapb[it->first] = mapa[it->first] = 0; - } - int flag1 = 1, flag2 = 1; - for (auto x : mapa) - if (x.second) - flag1 = 0; - for (auto x : mapb) - if (x.second) - flag2 = 0; - if (flag && flag1 && flag2) - cout << ""YeS"" << endl; - else - cout << ""nO"" << endl; - } -}",1 -spiderwick_99,2061D - Kevin and Numbers,c++20 ,303479529,303412363,"#include -using namespace std; -#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -typedef long long ll;typedef long double ld;typedef pair pii; -#define F first -#define S second -#define PB push_back -#define MP make_pair -const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10; -ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;} - - -void solve() { - int n,m; - cin >> n >> m; - set,greater>> ss; - map freqa, freqb; - for(int i=0,x;i> x,freqa[x]++; - for(int j=0,x;j> x,freqb[x]++; - for(auto &pp:freqb) - ss.insert({pp.F, pp.S}); - while(!ss.empty() && !freqa.empty() && freqa.rbegin()->first<=ss.begin()->first) { - auto tt = *ss.begin(); - ss.erase(ss.begin()); - if (freqa.find(tt.F) != freqa.end()) { - int mm = min(freqa[tt.F], tt.S); - freqa[tt.F]-=mm; - freqb[tt.F]-=mm; - tt.S-=mm; - if (freqa[tt.F]>0) { - cout << ""NO\n""; - return; - } - freqa.erase(tt.F); - } - freqb.erase(tt.F); - if (tt.S==0) - continue; - if (tt.F%2==0) { - int num = tt.F/2; - if (freqb.find(num) != freqb.end()) { - ss.erase({num, freqb[num]}); - } - freqb[num]+=2*tt.S; - ss.insert({num, freqb[num]}); - } else { - int t1 = (tt.F-1)/2; - int t2 = t1+1; - if (freqb.find(t1) != freqb.end()) { - ss.erase({t1, freqb[t1]}); - } - if (freqb.find(t2) != freqb.end()) { - ss.erase({t2, freqb[t2]}); - } - freqb[t1]+=tt.S; - freqb[t2]+=tt.S; - ss.insert({t1, freqb[t1]}); - ss.insert({t2, freqb[t2]}); - } - } - if (!ss.empty() || !freqa.empty()) - cout << ""NO\n""; - else - cout << ""YES\n""; - -} - - - - -signed main() { - fast; - int t = 1; - cin >> t; - while(t--){ - solve(); - } - return 0; -} -","#include -using namespace std; -#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -typedef long long ll;typedef long double ld;typedef pair pii; -#define F first -#define S second -#define PB push_back -#define MP make_pair -const ll mod = 1e9+7, N = 2e6+7, M = 2e6+7, INF = INT_MAX/10; -ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;} - - - - -void solve() { - int n,m; - cin >> n >> m; - mapa,b; - for(int i=0,x;i> x,a[x]++; - for(int j=0,x;j> x,b[x]++; - for(auto &pp:b) { - int times = pp.second; - while (times--) { - int num = pp.first; - while(a[num]==0) { - if (num%2==0) { - if (a[num/2]>0) { - a[num/2]--; - num/=2; - } else { - cout << ""NO\n""; - return; - } - } else { - int t1 = (num-1)/2; - int t2 = t1+1; - if (a[t1]>0) { - a[t1]--; - num-=t1; - } else if (a[t2]>0) { - a[t2]--; - num-=t2; - } else { - cout << ""NO\n""; - return; - } - } - } - a[num]--; - } - } - int remaining = 0; - for(auto &pp:a) - remaining+=pp.second; - if (remaining>0) - cout << ""NO\n""; - else - cout << ""YES\n""; -} - - - - -signed main() { - fast; - int t = 1; - cin >> t; - while(t--){ - solve(); - } - return 0; -} -",1 -fini_keksi,2061D - Kevin and Numbers,c++17 ,317110291,317110755,"#include - -#define ll long long int - -#define pb push_back - - - -using namespace std; - - - -const int MAXN = 2e5 + 10; - - - -int main(){ - - - - ll t; - - scanf(""%lld"", &t); - - - - while(t--){ - - ll n, m, x; - - scanf(""%lld %lld"", &n, &m); - - - - multiset a; - - vector b; - - ll suma_a = 0; - - ll suma_b = 0; - - - - for(ll i = 0; i < n; i++){ - - scanf(""%lld"", &x); - - suma_a += x; - - a.insert(x); - - } - - - - for(ll i = 0; i < m; i++){ - - scanf(""%lld"", &x); - - suma_b += x; - - b.pb(x); - - } - - - - if(suma_a != suma_b){ - - printf(""No\n""); - - } - - else{ - - ll k = 0; - - while(b.size() > 0 && k <= n + m){ - - k++; - - if(a.count(b[b.size() - 1]) > 0){ - - a.erase(a.find(b[b.size() - 1])); - - b.pop_back(); - - } - - else{ - - ll x1 = b[b.size() - 1]/2; - - ll x2 = b[b.size() - 1]/2; - - if(b[b.size() - 1] % 2 == 1){ - - x2++; - - } - - b.pop_back(); - - if(a.count(x1) > 0){ - - a.erase(a.find(x1)); - - } - - else{ - - b.push_back(x1); - - } - - if(a.count(x2) > 0){ - - a.erase(a.find(x2)); - - } - - else{ - - b.push_back(x2); - - } - - } - - } - - if(b.size() == 0){ - - printf(""Yes\n""); - - } - - else{ - - printf(""No\n""); - - } - - } - - } - - - - return 0; - -}","#include - -#define ll long long int - -#define pb push_back - - - -using namespace std; - - - -const int MAXN = 2e5 + 10; - - - -int main(){ - - - - ll t; - - scanf(""%lld"", &t); - - - - while(t--){ - - ll n, m, x; - - scanf(""%lld %lld"", &n, &m); - - - - multiset a; - - vector b; - - ll suma_a = 0; - - ll suma_b = 0; - - - - for(ll i = 0; i < n; i++){ - - scanf(""%lld"", &x); - - suma_a += x; - - a.insert(x); - - } - - - - for(ll i = 0; i < m; i++){ - - scanf(""%lld"", &x); - - suma_b += x; - - b.pb(x); - - } - - - - if(suma_a != suma_b){ - - printf(""No\n""); - - } - - else{ - - ll k = 0; - - while(b.size() > 0 && k <= n + 2){ - - k++; - - if(a.find(b[b.size() - 1]) != a.end()){ - - a.erase(a.find(b[b.size() - 1])); - - b.pop_back(); - - } - - else{ - - ll x1 = b[b.size() - 1]/2; - - ll x2 = b[b.size() - 1]/2; - - if(b[b.size() - 1] % 2 == 1){ - - x2++; - - } - - b.pop_back(); - - if(a.find(x1) != a.end()){ - - a.erase(a.find(x1)); - - } - - else{ - - b.push_back(x1); - - } - - if(a.find(x2) != a.end()){ - - a.erase(a.find(x2)); - - } - - else{ - - b.push_back(x2); - - } - - } - - } - - if(b.size() == 0){ - - printf(""Yes\n""); - - } - - else{ - - printf(""No\n""); - - } - - } - - } - - - - return 0; - -}",2 -sangam2ishra,2061D - Kevin and Numbers,c++23 ,302832557,302836485,"#include -#ifndef ONLINE_JUDGE -#include ""DEBUG/debug.h"" -#else -#define debug(x) -#endif -using namespace std; -bool Delete(long long ele, multiset &a) -{ - auto it = a.find(ele); - if (it != a.end()) - { - a.erase(it); - return true; - } - if (ele <= 1) - { - return false; - } - long long x = ele / 2; - long long y = (ele + 1) / 2; - return Delete(x, a) & Delete(y, a); -} -void solve() -{ - long long n, m; - cin >> n >> m; - vector va(n), vb(m); - for (auto &x : va) - cin >> x; - for (auto &y : vb) - cin >> y; - sort(va.begin(), va.end()); - sort(vb.begin(), vb.end()); - multiset a; - for (auto &e : va) - { - a.insert(e); - } - debug(a); - debug(va); - debug(vb); - for (long long i = 0; i < m; i++) - { - long long ele = vb[i]; - if (!Delete(ele, a)) - { - cout << ""No"" << endl; - return; - } - } - if(!a.empty()) - { - cout<<""No\n""; - return; - } - cout << ""Yes\n""; -} - -signed main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif - - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - long long t = 1; - cin >> t; - - while (t--) - { - // cout<<9-t+1<<"" ""; - solve(); - } - - return 0; -} -","#include -#ifndef ONLINE_JUDGE -#include ""DEBUG/debug.h"" -#else -#define debug(x) -#endif -using namespace std; -bool Delete(long long ele, multiset &a) -{ - if(a.empty()) return false; - auto it = a.find(ele); - if (it != a.end()) - { - a.erase(it); - return true; - } - if (ele <= 1) - { - return false; - } - long long x = ele / 2; - long long y = (ele + 1) / 2; - bool check1=Delete(x, a); - if(check1==false) return false; - bool check2=Delete(y, a); - if(check2==false) return false; - return true; -} -void solve() -{ - long long n, m; - cin >> n >> m; - vector va(n), vb(m); - for (auto &x : va) - cin >> x; - for (auto &y : vb) - cin >> y; - sort(va.begin(), va.end()); - sort(vb.begin(), vb.end()); - multiset a, b; - for (auto &e : va) - { - a.insert(e); - } - for(auto &e: vb) - { - b.insert(e); - } - debug(a); - debug(b); - while(!a.empty() && !b.empty()) - { - auto itb=b.begin(); - auto ita=a.find(*itb); - if(ita!=a.end()) - { - a.erase(ita); - b.erase(itb); - continue; - } - - - - int ele=*itb; - int x=ele/2; - int y=ele-x; - - if(ele<=1) - { - cout<<""No\n""; - return; - } - - b.erase(itb); - b.insert(x); - b.insert(y); - - } - if(!a.empty() || !b.empty()) - { - cout<<""No\n""; - return; - } - cout<<""Yes\n""; - return; - debug(a); - debug(va); - debug(vb); - for (long long i = 0; i < m; i++) - { - long long ele = vb[i]; - if (!Delete(ele, a)) - { - cout << ""No"" << endl; - return; - } - } - if(!a.empty()) - { - cout<<""No\n""; - return; - } - cout << ""Yes\n""; -} - -signed main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif - - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - - long long t = 1; - cin >> t; - - while (t--) - { - // cout<<9-t+1<<"" ""; - solve(); - } - - return 0; -}",2 -22hhlin,2061D - Kevin and Numbers,c++23 ,304884832,304884569,"#include -using namespace std; - -int main() { - int T; - scanf(""%d"", &T); - - while (T--) { - int n, m; - scanf(""%d%d"", &n, &m); - - priority_queue a, b; - for (int i = 0; i < n; i++) { - int x; - scanf(""%d"", &x); - a.push(x); - } - for (int i = 0; i < m; i++) { - int x; - scanf(""%d"", &x); - b.push(x); - } - - bool ok = true; - while (!a.empty()) { - if (b.empty() || b.size() > a.size()) { - ok = false; - break; - } - - int x = b.top(); - b.pop(); - - if (x < a.top()) { - ok = false; - break; - } - if (x == a.top()) { - a.pop(); - } else { - b.push(x / 2); - b.push((x + 1) / 2); - } - } - - if (!b.empty()) { - ok = false; - } - - if (ok) { - puts(""Yes""); - } else { - puts(""No""); - } - } - - return 0; -} -","#include -using namespace std; - -int main() { - int T; - scanf(""%d"", &T); - - while (T--) { - int n, m; - scanf(""%d%d"", &n, &m); - - priority_queue a, b; - for (int i = 0; i < n; i++) { - int x; - scanf(""%d"", &x); - a.push(x); - } - for (int i = 0; i < m; i++) { - int x; - scanf(""%d"", &x); - b.push(x); - } - - bool ok = true; - while (!a.empty()) { - if (b.empty() || b.size() > a.size()) { - ok = false; - break; - } - - int x = b.top(); - b.pop(); - - if (x < a.top()) { - ok = false; - break; - } - if (x == a.top()) { - a.pop(); - } else { - b.push(x / 2); - b.push(x / 2 + 1); - } - } - - if (!b.empty()) { - ok = false; - } - - if (ok) { - puts(""Yes""); - } else { - puts(""No""); - } - } - - return 0; -} -",1 -zvm2610,2061D - Kevin and Numbers,c++17 ,307596737,307596782,"#include -#include -#pragma GCC optimize(""O3,unroll-loops"") -using namespace std; -#define int long long - - -void solve(){ - int n, m; - cin >> n >> m; - vector a(n), b(m); - - for(int i = 0; i> a[i]; - for(int i = 0; i> b[i]; - - map freqa, freqb; - set seta, setb; - - for(auto ele: a){ - freqa[ele]++; - seta.insert(ele); - } - - for(auto ele: b){ - freqb[ele]++; - setb.insert(ele); - } - - while(true){ - if(seta.empty() && setb.empty()){ - cout << ""YES"" << endl; - return; - } - - if(seta.empty() || setb.empty()){ - cout << ""NO"" << endl; - return; - } - - int max1 = *prev(set.end()); - int max2 = *prev(set.end()); - - if(max1 > max2){ - cout << ""NO"" << endl; - return; - } - - if(freqa[max2]){ - int minfreq = min(freqa[max2], freqb[max2]); - freqa[max2] = freqa[max2] - minfreq; - freqb[max2] = freqb[max2] - minfreq; - - if(freqa[max2] == 0) seta.erase(max2); - if(freqb[max2] == 0) setb.erase(max2); - } - - else{ - int cl = (max2 + 1)/2; - int fl = max2/2; - freqb[cl] = freqb[cl] + freqb[max2]; - freqb[fl] = freqb[fl] + freqb[max2]; - freqb[max2] = 0; - setb.insert(cl); - setb.insert(fl); - setb.erase(max2); - } - } -} - - -signed main(){ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - int t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}","#include -#include -#pragma GCC optimize(""O3,unroll-loops"") -using namespace std; -#define int long long - - -void solve(){ - int n, m; - cin >> n >> m; - vector a(n), b(m); - - for(int i = 0; i> a[i]; - for(int i = 0; i> b[i]; - - map freqa, freqb; - set seta, setb; - - for(auto ele: a){ - freqa[ele]++; - seta.insert(ele); - } - - for(auto ele: b){ - freqb[ele]++; - setb.insert(ele); - } - - while(true){ - if(seta.empty() && setb.empty()){ - cout << ""YES"" << endl; - return; - } - - if(seta.empty() || setb.empty()){ - cout << ""NO"" << endl; - return; - } - - int max1 = *prev(seta.end()); - int max2 = *prev(setb.end()); - - if(max1 > max2){ - cout << ""NO"" << endl; - return; - } - - if(freqa[max2]){ - int minfreq = min(freqa[max2], freqb[max2]); - freqa[max2] = freqa[max2] - minfreq; - freqb[max2] = freqb[max2] - minfreq; - - if(freqa[max2] == 0) seta.erase(max2); - if(freqb[max2] == 0) setb.erase(max2); - } - - else{ - int cl = (max2 + 1)/2; - int fl = max2/2; - freqb[cl] = freqb[cl] + freqb[max2]; - freqb[fl] = freqb[fl] + freqb[max2]; - freqb[max2] = 0; - setb.insert(cl); - setb.insert(fl); - setb.erase(max2); - } - } -} - - -signed main(){ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - int t; - cin >> t; - while(t--){ - solve(); - } - return 0; -}",2 -Regulus,2061D - Kevin and Numbers,c++23 ,302359662,302335062,"#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -template using oset = tree< T , null_type , less , rb_tree_tag , tree_order_statistics_node_update >; -// *st.find_by_order(i) --> element at ith position -// st.order_of_key(x) --> no. of ele less than x -//For multiset change less to less_equal and for reverse order change less to greater -#define int long long -#define endl '\n' -#define all(x) (x).begin(), (x).end() -template // cin >> vector -istream& operator>>(istream &istream, vector &v){for(auto &it : v)cin >> it;return istream;} -template // cout << vector -ostream& operator<<(ostream &ostream, const vector &c){for(auto &it : c)cout << it << "" "";return ostream;} - -signed main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - int testCase; cin >> testCase; - while(testCase--) { - int n , m; - cin >> n >> m; - multisetA,B; - for(int i = 0 ; i < n ; i++) { - int x; cin >> x; - A.insert(x); - } - for(int i = 0 ; i < m ; i++) { - int x; cin >> x; - B.insert(x); - } - int sumA = accumulate(all(A),0LL) , sumB = accumulate(all(B),0LL); - if(m > n or sumA != sumB) { - cout << ""No"" << endl; - continue; - } - while(B.size() > 0 and A.size() > 0) { - if(*(--A.end()) > *(--B.end())) break; - if(*(--A.end()) == *(--B.end())) { - A.erase(--A.end()); - B.erase(--B.end()); - } else { - int x = *(--B.end()); - B.erase(--B.end()); - B.insert(x / 2); - B.insert((x + 1) / 2); - } - } - if(A == B) cout << ""Yes"" << endl; - else cout << ""No"" << endl; - } - return 0; -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -template using oset = tree< T , null_type , less , rb_tree_tag , tree_order_statistics_node_update >; -// *st.find_by_order(i) --> element at ith position -// st.order_of_key(x) --> no. of ele less than x -//For multiset change less to less_equal and for reverse order change less to greater -#define int long long -#define endl '\n' -#define all(x) (x).begin(), (x).end() -template // cin >> vector -istream& operator>>(istream &istream, vector &v){for(auto &it : v)cin >> it;return istream;} -template // cout << vector -ostream& operator<<(ostream &ostream, const vector &c){for(auto &it : c)cout << it << "" "";return ostream;} - -signed main() -{ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); - int testCase; cin >> testCase; - while(testCase--) { - int n , m; - cin >> n >> m; - vectorarr(n) , brr(m); - cin >> arr >> brr; - vectortmp; - multisetA(all(arr)),B(all(brr)); - if(m > n) { - cout << ""No"" << endl; - continue; - } - auto i = B.begin(); - while(i != B.end()) { - auto it = A.find(*i); - if(it != A.end()) { - tmp.push_back(*it); - A.erase(it); - } - ++i; - } - for(auto j : tmp) { - auto it = B.find(j); - if(it != B.end()) B.erase(it); - } - int diff = max(n - m,10000LL); - while(diff-- and B.size() > 0 and A.size() > 0) { - if(*(--A.end()) == *(--B.end())) { - A.erase(--A.end()); - B.erase(--B.end()); - } else { - int x = *(--B.end()); - B.erase(--B.end()); - B.insert(x / 2); - B.insert((x + 1) / 2); - if(x == 1) break; - } - } - vectorfinalA(all(A)) , finalB(all(B)); - if(finalA == finalB) cout << ""Yes"" << endl; - else cout << ""No"" << endl; - } - return 0; -}",1 -lakshyatyagi,2061D - Kevin and Numbers,c++23 ,302337344,302342878,"#include -#include -using namespace std; - -using ll = long long; -const ll mod = 1e9 + 7; -const ll modd = 998244353; - - -void solve() { - ll n, m; - cin>>n>>m; - mapm1, m2; - for(ll i = 0; i>x; - m1[x]++; - } - for(ll i = 0; i>x; - m2[x]++; - } - - sets1, s2; - for(auto&i:m1) { - if(m2.find(i.first)!=m2.end()){ - ll k = m2[i.first]; - if(k>i.second) { - m2[i.first]-=i.second; - s1.insert(i.first); - } - else { - i.second-=k; - s2.insert(i.first); - if(i.second == 0) s1.insert(i.first); - } - } - } - for(auto&i:s1) { - m1.erase(i); - } - for(auto&i:s2) { - m2.erase(i); - } - vectora, b; - for(auto&i:m1) { - ll k = i.second; - // cout< cout<b[j]) { - cout<<""NO\n""; - return; - } - } - - } - } - if(i> t; - - while (t--) solve(); - - return 0; -} -","#include -#include -using namespace std; - -using ll = long long; -const ll mod = 1e9 + 7; -const ll modd = 998244353; - - -void solve() { - ll n, m; - cin>>n>>m; - multisets1, s2; - for(ll i = 0; i>x; - s1.insert(x); - } - for(ll i = 0; i>x; - s2.insert(x); - } - for(auto&i:s2) { - auto it = s1.find(i); - if(it!=s1.end()) { - s1.erase(it); - } - else { - ll a = i>>1ll, b = i>>1ll; - if(a+b!=i) b++; - queueq; - q.push(a); - q.push(b); - while(!q.empty()) { - ll e = q.front(); - q.pop(); - auto it1 = s1.find(e); - if(it1!=s1.end()) { - s1.erase(it1); - } - else { - if(q.size()>s1.size()) { - cout<<""NO\n""; - return; - } - ll c = e>>1ll, d = e>>1ll; - if(c==0) { - cout<<""NO\n""; - return; - } - if(c+d!=e) d++; - q.push(c); - q.push(d); - } - } - } - } - if(!s1.empty()) { - cout<<""NO\n""; - return; - } - cout<<""YES\n""; - -} - -int main() -{ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - int t = 1; - cin >> t; - - while (t--) solve(); - - return 0; -} -",2 -MasterRayuga,2061D - Kevin and Numbers,java,303714158,303713440,"import java.util.*; - -public class Main { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int T = sc.nextInt(); - while (T-- > 0) { - int n = sc.nextInt(); - int m = sc.nextInt(); - int[] a = new int[n]; - for (int i = 0; i < n; i++) a[i] = sc.nextInt(); - int[] b = new int[m]; - for (int i = 0; i < m; i++) b[i] = sc.nextInt(); - - PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); - for (int val : b) pq.offer(val); - - Map freqMap = new HashMap<>(); - for (int val : a) freqMap.put(val, freqMap.getOrDefault(val, 0) + 1); - - boolean isValid = true; - - for (int i = 0; i < n - m + n; i++) { - if (pq.isEmpty()) { - isValid = false; - break; - } - - int val = pq.poll(); - if (freqMap.getOrDefault(val, 0) == 0) { - pq.offer(val / 2); - pq.offer((val + 1) / 2); - } else { - freqMap.put(val, freqMap.get(val) - 1); - } - } - - System.out.println(isValid && pq.isEmpty() ? ""Yes"" : ""No""); - } - sc.close(); - } -}","import java.util.*; - -public class Main { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - int T = scanner.nextInt(); - while (T-- > 0) { - int n = scanner.nextInt(); - int m = scanner.nextInt(); - int[] a = new int[n]; - for (int i = 0; i < n; i++) a[i] = scanner.nextInt(); - int[] b = new int[m]; - for (int i = 0; i < m; i++) b[i] = scanner.nextInt(); - System.out.println(canDistribute(a, b) ? ""Yes"" : ""No""); - } - scanner.close(); - } - - private static boolean canDistribute(int[] a, int[] b) { - PriorityQueue maxHeap = new PriorityQueue<>(Collections.reverseOrder()); - for (int val : b) maxHeap.offer(val); - - Map freqMap = new HashMap<>(); - for (int val : a) freqMap.put(val, freqMap.getOrDefault(val, 0) + 1); - - while (!maxHeap.isEmpty()) { - int current = maxHeap.poll(); - if (freqMap.getOrDefault(current, 0) > 0) { - freqMap.put(current, freqMap.get(current) - 1); - } else { - if (current == 1) return false; - maxHeap.offer(current / 2); - maxHeap.offer((current + 1) / 2); - } - } - - for (int count : freqMap.values()) { - if (count > 0) return false; - } - return true; - } -}",1 -Mr_Surfer,2061D - Kevin and Numbers,python,304939410,304939832,"from random import randint -class MyDict: - def __init__(self, func=lambda: 0): - self.random = randint(0, (1 << 32) - 1) - self.default = func - self.dict = {} - def _hash(self, key): - return self.random ^ hash(key) - def __getitem__(self, key): - mykey = self._hash(key) - if mykey not in self.dict: - self.dict[mykey] = self.default() - return self.dict[mykey] - def __setitem__(self, key, value): - self.dict[self._hash(key)] = value - def __delitem__(self, key): - mykey = self._hash(key) - if mykey in self.dict: - del self.dict[mykey] - else: - raise KeyError(key) - def get(self, key, default=None): - return self.dict.get(self._hash(key), default) - def keys(self): - return [self._hash(k) for k in self.dict] - def values(self): - return self.dict.values() - def items(self): - return [(self._hash(k), v) for k, v in self.dict.items()] - def __contains__(self, key): - return self._hash(key) in self.dict - def __iter__(self): - return iter(self.keys()) - def __len__(self): - return len(self.dict) - def __str__(self): - return str({self._hash(k): v for k, v in self.dict.items()}) - def __repr__(self): - return f""MyDict({self.default}, {self.dict})"" - -import heapq -def solve(): - n,m = map(int,input().split()) - a = list(map(int,input().split())) - b = list(map(int,input().split())) - - st = [] - for i in b : - st.append(-i) - - heapq.heapify(st) - - freq = MyDict() - for i in a: - freq[i] += 1 - - ii = -1 - for i in range(2*n-m): - if not st: - print(""NO"") - return - val = - heapq.heappop(st) - if freq[val] != 0: - freq[val] -= 1 - - else: - heapq.heappush(st,-(val // 2)) - heapq.heappush(st,-(val+2-1)//2) - if st : - print(""NO"") - else: - print(""YES"") - -for __ in range(int(input())): - solve()","from random import randint -class MyDict: - def __init__(self, func=lambda: 0): - self.random = randint(0, (1 << 32) - 1) - self.default = func - self.dict = {} - def _hash(self, key): - return self.random ^ hash(key) - def __getitem__(self, key): - mykey = self._hash(key) - if mykey not in self.dict: - self.dict[mykey] = self.default() - return self.dict[mykey] - def __setitem__(self, key, value): - self.dict[self._hash(key)] = value - def __delitem__(self, key): - mykey = self._hash(key) - if mykey in self.dict: - del self.dict[mykey] - else: - raise KeyError(key) - def get(self, key, default=None): - return self.dict.get(self._hash(key), default) - def keys(self): - return [self._hash(k) for k in self.dict] - def values(self): - return self.dict.values() - def items(self): - return [(self._hash(k), v) for k, v in self.dict.items()] - def __contains__(self, key): - return self._hash(key) in self.dict - def __iter__(self): - return iter(self.keys()) - def __len__(self): - return len(self.dict) - def __str__(self): - return str({self._hash(k): v for k, v in self.dict.items()}) - def __repr__(self): - return f""MyDict({self.default}, {self.dict})"" - -import heapq -def solve(): - n,m = map(int,input().split()) - a = list(map(int,input().split())) - b = list(map(int,input().split())) - - st = [] - for i in b : - st.append(-i) - - heapq.heapify(st) - - freq = MyDict() - for i in a: - freq[i] += 1 - - for i in range(2*n-m): - if not st: - print(""NO"") - return - val = - heapq.heappop(st) - if freq[val] != 0: - freq[val] -= 1 - - else: - heapq.heappush(st,-(val // 2)) - heapq.heappush(st,-((val+2-1)//2)) - if st : - print(""NO"") - else: - print(""YES"") - -for __ in range(int(input())): - solve()",2 -Infinite_Strife#,2061D - Kevin and Numbers,c++17 ,302837408,302848690,"#include -#define int long long -using namespace std; -priority_queue,greater >a,b; -map ma; -int n,m; -bool cal(int x) -{ -if(x==0)return 0; -if(ma[x]>0) -{ - ma[x]--; - n--; - return 1; -} -return cal(x/2)&&cal(x/2+x%2); -} -void solve() -{ - - cin>>n>>m; - ma.clear(); - for(int i=1;i<=n;i++) - { - int temp;cin>>temp; - ma[temp]++; - } - for(int i=1;i<=m;i++) - { - int temp;cin>>temp; - if(cal(temp)==0) - { - cout<<""NO\n""; - return ; - } - } - if(n==0) - cout<<""YES\n""; -else cout<<""NO\n""; - return; -} -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int T; - cin>>T; - while(T--) - solve(); -}","#include -#define int long long -using namespace std; -map ma; -int n,m; -bool cal(int x) -{ -if(ma[x]>0) -{ - ma[x]--; - n--; - return 1; -} -if(x==1) - return 0; -return cal(x/2)&&cal(x/2+x%2); -} -void solve() -{ - - cin>>n>>m; - ma.clear(); - for(int i=1;i<=n;i++) - { - int temp;cin>>temp; - ma[temp]++; - } - for(int i=1;i<=m;i++) - { - int temp;cin>>temp; - if(cal(temp)==0) - { - cout<<""NO\n""; - for(int j=i+1;j<=m;j++) - cin>>temp; - return ; - } - } - if(n==0) - cout<<""YES\n""; -else cout<<""NO\n""; - return; -} -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int T; - cin>>T; - while(T--) - solve(); -}",2 -RED_MONK,2061D - Kevin and Numbers,c++17 ,307251228,307235600," -#include -#include -#include -using namespace __gnu_pbds; -using namespace std; -typedef long long int ll; -template -using ordered_set = tree, rb_tree_tag,tree_order_statistics_node_update>; -typedef unsigned long long int ull; -#define vi vector -#define vpi vector > -#define mpi map -#define si set -#define rep(i,a,n) for(int i=a;i>t;while(t--) -#define all(x) (x).begin(), (x).end() -#define sz(a) (int)(a).size() -#define MOD 1000000007 - - -void solve(){ - - -ll n,m; -cin>>n>>m; -seta,b; -mapmp1,mp2; -ll x; -rep(i,0,n) -{ - cin>>x; - mp1[x]++; - a.insert(x); -}rep(i,0,m) -{ - cin>>x; - mp2[x]++; - b.insert(x); -} -while(true){ - if(a.empty() && b.empty()){ - YES - return; - } - if(a.empty() || b.empty()){ - NO - return; - } - ll mxa= *a.rbegin(); - ll mxb= *b.rbegin(); - if(mxa>mxb){ - NO - return; - } - if(mp1[mxb]){ - ll mn = min(mp1[mxb],mp2[mxb]); - mp1[mxb]-=mn; - mp2[mxb]-=mn; - if(mp1[mxb]==0){ - a.erase(mxb); - }if(mp2[mxb]==0){ - b.erase(mxb); - } - } - else - { - ll l = mxb/2; - ll r = (mxb+1)/2; - mp2[l]+=mp2[mxb]; - mp2[r]+=mp2[mxb]; - mp2[mxb]=0; - b.insert(l); - b.insert(r); - b.erase(mxb); - } - - - -} - - -} -int main() -{ - #ifndef ONLINE_JUDGE - freopen(""input.txt"",""r"",stdin); - freopen(""output.txt"",""w"",stdout); - #endif -ios_base::sync_with_stdio(false); - cin.tie(NULL); -int t; -clock_t z = clock(); -t=1; -cin>>t; -while(t--) -{ -solve(); -} - -cerr<<""Run Time : ""<<((double)(clock()-z)/CLOCKS_PER_SEC); -} - - -"," -#include -#include -#include -using namespace __gnu_pbds; -using namespace std; -typedef long long int ll; -template -using ordered_set = tree, rb_tree_tag,tree_order_statistics_node_update>; -typedef unsigned long long int ull; -#define vi vector -#define vpi vector > -#define mpi map -#define si set -#define rep(i,a,n) for(int i=a;i>t;while(t--) -#define all(x) (x).begin(), (x).end() -#define sz(a) (int)(a).size() -#define MOD 1000000007 - - -void solve(){ - - -ll n,m; -cin>>n>>m; -vectorar(n); -vectorbr(m); -mapmp1,mp2; -rep(i,0,n) -{ - cin>>ar[i]; - mp1[ar[i]]++; -} -ll sum=0; - -rep(i,0,m) -{ - cin>>br[i]; - if(mp1[br[i]]>0){ - mp1[br[i]]--; - //cout<<""hi ""<a,b; -for(auto it:mp1){ - rep(i,0,it.se){ - a.pb(it.fi); - } -} -for(auto it:mp2){ - rep(i,0,it.se){ - b.pb(it.fi); - } -} -int cnt = sz(a)-sz(b); -ll l; -if(sz(a)>0) -l=a[0]; -for(int i=1;i0){ - - mp2[l]--; - - if(i+1>t; -while(t--) -{ -solve(); -} - -cerr<<""Run Time : ""<<((double)(clock()-z)/CLOCKS_PER_SEC); -} - - -",1 -siuuu_on_code,2061D - Kevin and Numbers,c++23 ,302675106,302674934,"#ifndef ONLINE_JUDGE -#include ""debugger.h"" -#else -#define dbg(...) -#endif -#include -#define int long long -#define ll long long -#define pii pair -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define cyes cout << ""Yes"" << endl -#define cno cout << ""No"" << endl -#define minus cout << -1 << endl -#define fastread() \ - ios_base::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -using namespace std; -const int mod = 1e9 + 7; -void solve() -{ - int n, m; - cin >> n >> m; - multiset m1, m2; - for (int i = 0; i < n; i++) - { - int x; - cin >> x; - m1.insert(x); - } - - for (int i = 0; i < m; i++) - { - int x; - cin >> x; - m2.insert(x); - } - // multiset m3; - int times = 2*(n+m); - while (times--) - { - if (m1.size() == 0 || m2.size() == 0) - break; - int num = *m2.rbegin(); - if (m1.find(num) != m1.end()) - { - m2.erase(m2.find(num)); - m1.erase(m1.find(num)); - continue; - } - int num1 = num / 2; - int num2 = (num / 2) + (num % 2); - m2.erase(m2.find(num)); - m2.insert(num1); - m2.insert(num2); - } - - if (m1 == m2) - cyes; - else - cno; -} - -int32_t main() -{ - fastread(); - int t = 1; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}","#ifndef ONLINE_JUDGE -#include ""debugger.h"" -#else -#define dbg(...) -#endif -#include -#define int long long -#define ll long long -#define pii pair -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define cyes cout << ""Yes"" << endl -#define cno cout << ""No"" << endl -#define minus cout << -1 << endl -#define fastread() \ - ios_base::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -using namespace std; -const int mod = 1e9 + 7; -void solve() -{ - int n, m; - cin >> n >> m; - multiset m1, m2; - for (int i = 0; i < n; i++) - { - int x; - cin >> x; - m1.insert(x); - } - - for (int i = 0; i < m; i++) - { - int x; - cin >> x; - m2.insert(x); - } - // multiset m3; - int times = n + m; - while (times--) - { - if (m1.size() == 0 || m2.size() == 0) - break; - int num = *m2.rbegin(); - if (m1.find(num) != m1.end()) - { - m2.erase(m2.find(num)); - m1.erase(m1.find(num)); - continue; - } - int num1 = num / 2; - int num2 = (num / 2) + (num % 2); - m2.erase(m2.find(num)); - m2.insert(num1); - m2.insert(num2); - } - - if (m1 == m2) - cyes; - else - cno; -} - -int32_t main() -{ - fastread(); - int t = 1; - cin >> t; - while (t--) - { - solve(); - } - - return 0; -}",1 -ayushi.mm01:46,2061D - Kevin and Numbers,c++23 ,307001755,307002683,"#include -using namespace std; -#define ll int -#define lld long double -#define pll pair -#define f(i, a, b) for(ll i = a; i < b; i++) -#define br cout<<""\n""; -const long long int N = 2e5+20; -const long long int M = 998244353; - -ll binpow(ll x, ll y, ll MOD){ - ll res = 1; x %= MOD; - while(y > 0){ - if(y&1ll){res = (res * x) % MOD;} - x = (x * x) % MOD; - y >>= 1LL; - } - res %= MOD; - return res; -} - - -void solve(){ - ll n, m; - cin>>n>>m; - vector a(n), b(m); - multiset s, t; - f(i, 0, n){ - cin>>a[i]; - s.insert(a[i]); - } - f(j, 0, m){ - cin>>b[j]; - t.insert(b[j]); - } - ll cnt = 0; - while(cnt < n-m){ - vector v; - for(auto x: t){ - if(s.find(x) != s.end()){ - s.erase(s.find(x)); - } - else{ - cnt++; - v.push_back(x/2); - v.push_back((x+1)/2); - } - - } - t.clear(); - assert(t.size() == 0); - for(auto x: v){ - t.insert(x); - } - if(t.empty() || s.empty()){break;} - } - if(t.size() != s.size()){ - cout<<""NO\n""; - return; - } - for(auto x: t){ - if(s.find(x) == s.end()){ - cout<<""NO\n""; - return; - } - if(s.count(x) != t.count(x)){ - cout<<""NO\n""; - return; - } - } - for(auto x: s){ - if(t.find(x) == t.end()){ - cout<<""NO\n""; - return; - } - if(s.count(x) != t.count(x)){ - cout<<""NO\n""; - return; - } - } - cout<<""YES\n""; - return; -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - int TT = 1; - cin >> TT; - f(tt, 1, TT+1){ - solve(); - } - return 0; -}","#include -using namespace std; -#define ll int -#define lld long double -#define pll pair -#define f(i, a, b) for(ll i = a; i < b; i++) -#define br cout<<""\n""; -const long long int N = 2e5+20; -const long long int M = 998244353; - -ll binpow(ll x, ll y, ll MOD){ - ll res = 1; x %= MOD; - while(y > 0){ - if(y&1ll){res = (res * x) % MOD;} - x = (x * x) % MOD; - y >>= 1LL; - } - res %= MOD; - return res; -} - - -void solve(){ - ll n, m; - cin>>n>>m; - vector a(n), b(m); - multiset s, t; - f(i, 0, n){ - cin>>a[i]; - s.insert(a[i]); - } - f(j, 0, m){ - cin>>b[j]; - t.insert(b[j]); - } - ll cnt = 0; - while(cnt < n-m){ - vector v; - for(auto x: t){ - if(s.find(x) != s.end()){ - s.erase(s.find(x)); - } - else{ - cnt++; - v.push_back(x/2); - v.push_back((x+1)/2); - } - - } - t.clear(); - assert(t.size() == 0); - for(auto x: v){ - t.insert(x); - } - if(t.empty() || s.empty()){break;} - } - if(t.size() != s.size()){ - cout<<""NO\n""; - return; - } - vector x, y; - for(auto z: t){ - x.push_back(z); - } - for(auto z: s){ - y.push_back(z); - } - f(i, 0, x.size()){ - if(x[i] != y[i]){ - cout<<""NO\n""; - return; - } - } - - cout<<""YES\n""; - return; -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); - int TT = 1; - cin >> TT; - f(tt, 1, TT+1){ - solve(); - } - return 0; -}",2 -AKLF,2061D - Kevin and Numbers,c++17 ,304356654,304356868,"#include -#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - priority_queue q; - priority_queue Q; - int n,m; - cin>>n>>m; - for(int i=0;i>a; - q.push(a); - } - for(int i=0;i>b; - Q.push(b); - } - while(1){ - if(m>n){ - cout<<""No""<<'\n'; - break; - } - if(Q.empty() and !q.empty()){ - cout<<""No""<<'\n'; - break; - } - if(q.empty() and Q.empty()){ - cout<<""Yes""<<'\n'; - break; - } - int a = q.top(); - int b = Q.top(); - cout<a){ - Q.pop(); - Q.push(b/2); - Q.push(b-b/2); - m--; - m+=2; - } - if(b -#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - priority_queue q; - priority_queue Q; - int n,m; - cin>>n>>m; - for(int i=0;i>a; - q.push(a); - } - for(int i=0;i>b; - Q.push(b); - } - while(1){ - if(m>n){ - cout<<""No""<<'\n'; - break; - } - if(Q.empty() and !q.empty()){ - cout<<""No""<<'\n'; - break; - } - if(q.empty() and Q.empty()){ - cout<<""Yes""<<'\n'; - break; - } - int a = q.top(); - int b = Q.top(); - //cout<a){ - Q.pop(); - Q.push(b/2); - Q.push(b-b/2); - m--; - m+=2; - } - if(b - -#include - -#include - -using namespace std; - - - -typedef long long ll; - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while(t--){ - - int n, m; - - cin >> n >> m; - - vector a(n), b(m); - - ll sumA = 0, sumB = 0; - - for (int i = 0; i < n; i++){ - - cin >> a[i]; - - sumA += a[i]; - - } - - for (int i = 0; i < m; i++){ - - cin >> b[i]; - - sumB += b[i]; - - } - - - - // Invariant check: the sums must be equal. - - if(sumA != sumB){ - - cout << ""No\n""; - - continue; - - } - - - - // Build frequency map for a. - - map freq; - - for(auto x : a) - - freq[x]++; - - - - // Build the need map from b. - - // need[x] means: we need x to appear this many times. - - map need; - - for(auto x : b) - - need[x]++; - - - - bool possible = true; - - - - // Process the need map in descending order. - - while(!need.empty() && possible){ - - // Get the largest key. - - auto it = need.end(); - - it--; - - ll x = it->first; - - ll cnt = it->second; - - need.erase(it); - - - - // Use available copies from freq. - - ll use = 0; - - if(freq.count(x)) - - use = min(freq[x], cnt); - - cnt -= use; - - if(freq.count(x)) - - freq[x] -= use; - - - - // If we still need more copies of x but cannot split further, fail. - - if(cnt > 0){ - - if(x == 1){ - - possible = false; - - break; - - } - - // Split each copy of x. - - if(x % 2 == 0){ - - // x even => must come from two copies of x/2. - - need[x/2] += cnt * 2; - - } else { - - // x odd => must come from one copy of floor(x/2) and one copy of floor(x/2)+1. - - need[x/2] += cnt; - - need[x/2 + 1] += cnt; - - } - - } - - } - - - - cout << (possible ? ""Yes"" : ""No"") << ""\n""; - - } - - return 0; - -} - -","#include - -#include - -#include - -using namespace std; - - - -typedef long long ll; - - - -// Global frequency map to store counts of numbers in array a. - -unordered_map freq; - - - -// Recursive function to check if we can split x into numbers that exactly match entries in freq. - -bool solve(ll x) { - - // If x is present in freq, use one occurrence. - - if(freq[x] > 0) { - - freq[x]--; - - return true; - - } - - // If x cannot be split further, return false. - - if(x == 1) - - return false; - - // Otherwise, try splitting x into two parts: - - // One part is floor(x/2) and the other is ceil(x/2). - - return solve(x / 2) && solve((x + 1) / 2); - -} - - - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - int t; - - cin >> t; - - while(t--){ - - int n, m; - - cin >> n >> m; - - vector a(n), b(m); - - ll sumA = 0, sumB = 0; - - for (int i = 0; i < n; i++){ - - cin >> a[i]; - - sumA += a[i]; - - } - - for (int i = 0; i < m; i++){ - - cin >> b[i]; - - sumB += b[i]; - - } - - - - // The sum invariant must hold: otherwise it's impossible. - - if(sumA != sumB){ - - cout << ""No\n""; - - continue; - - } - - - - // Build the frequency map for array a. - - freq.clear(); - - for(auto x : a) - - freq[x]++; - - - - // Try to decompose the total sum (which equals sumB) into elements from a. - - if(solve(sumB)) - - cout << ""Yes\n""; - - else - - cout << ""No\n""; - - } - - return 0; - -} - -",1 -someshjoyguru,2061D - Kevin and Numbers,c++23 ,303578878,303578539,"#include -using namespace std; - -bool canTransform(vector& a, vector& b) { - // Calculate the sum of both sequences - long long sumA = accumulate(a.begin(), a.end(), 0LL); - long long sumB = accumulate(b.begin(), b.end(), 0LL); - - if (sumA != sumB) { - return false; - } - - // Count frequencies in a and b - map freqA, freqB; - for (int num : a) freqA[num]++; - for (int num : b) freqB[num]++; - - // Iterate through the numbers in a - for (auto& [num, count] : freqA) { - if (freqB.count(num)) { - int minCount = min(count, freqB[num]); - count -= minCount; - freqB[num] -= minCount; - } - - // Try to combine numbers to match frequencies in b - if (count > 0) { - if (freqB.count(num + 1)) { - int minCount = min(count, freqB[num + 1]); - count -= minCount; - freqB[num + 1] -= minCount; - } - if (count > 0) { - return false; - } - } - } - - // Check if all frequencies in b are matched - for (auto& [num, count] : freqB) { - if (count > 0) { - return false; - } - } - - return true; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - int n, m; - cin >> n >> m; - vector a(n), b(m); - for (int i = 0; i < n; ++i) cin >> a[i]; - for (int i = 0; i < m; ++i) cin >> b[i]; - - if (canTransform(a, b)) { - cout << ""Yes\n""; - } else { - cout << ""No\n""; - } - } - - return 0; -}","#include -using namespace std; -#define ll long long -#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cerr.rdbuf(cout.rdbuf()); -#define f(i,a,b) for (ll (i)=(a); (i)<(b); (i)++) -#define rf(i,a,b) for (ll (i)=(a); (i)>=(b); (i)--) -#define vll vector -#define vvll vector -#define in(n) ll n; cin>>n; -#define sin(s) string (s); cin>>(s); -#define vin(v,n) vll (v)(n); f(i,0,n)cin>>(v)[i]; -#define all(v) (v).begin(),(v).end() -#define rall(v) (v).rbegin(),(v).rend() -#define sort(v) sort(all(v)); -#define rsort(v) sort(v) reverse(all(v)); -#define pYES cout<<""YES\n""; -#define pNO cout<<""NO\n""; -const ll mod = 1000000007; - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x << "" = ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif - -template -void _print(T x) { cerr << x; } -template -void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "", ""; _print(p.second); cerr << ""}""; } -template -void _print(vector v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } -template -void _print(set s) { cerr << ""{ ""; for (T i : s) { _print(i); cerr << "" ""; } cerr << ""}""; } -template -void _print(map m) { cerr << ""{ ""; for (auto i : m) { _print(i); cerr << "" ""; } cerr << ""}""; } -/* *********************Template ends here************** */ - - -void solve() { - in(n) in(m) - vin(a,n) - vin(b,m) - multiset p(all(a)),q(all(b)); - ll diff=n-m; - for(auto itt=q.begin();itt!=q.end(); itt++){ - auto it=p.find(*itt); - if (it!=p.end()){ - p.erase(it); - q.erase(itt); - }else{ - if (diff==0 || *itt==1){ - pNO - return; - }else{ - ll x=*itt; - q.erase(itt); - ll xx=x/2, yy=x/2+x%2; - if (xx!=0) q.insert(xx); - if (yy!=0) q.insert(yy); - if (q.size()>0) itt=q.begin(); - else break; - } - } - } - if (p.size()==0 && q.size()==0) pYES - else pNO -} - -int main() { - fast; - int t = 1; - cin >> t; - while(t--) solve(); -}",1 -Ahmik_Virani,2061D - Kevin and Numbers,c++17 ,302826610,302830258,"#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -#pragma GCC optimize(""O3,unroll-loops"") - -using ll = long long; -using ld = long double; - -typedef tree,rb_tree_tag,tree_order_statistics_node_update> oset; - -constexpr ll inf=2e18; -constexpr ld eps=1e-9; -constexpr ll mod=1e9+7; - -#define F first -#define S second -#define int long long -#define pb push_back -#define all(x) x.begin(), x.end() - -template -istream& operator>>(istream &istream, vector &v) -{ - for(auto &it : v) - cin>>it; - return istream; -} - -template -ostream& operator<<(ostream &ostream, const vector &c) -{ - for(auto &it : c) - cout< fact_dp(2e5+2,-1); - -int binpow(int a, int b, int m=mod) -{ - if(b==0) - return 1; - - int x = binpow(a,b/2); - if(b&1) - return ((x*x)%m*a)%m; - return (x*x)%m; -} - -int modinv(int x, int m=mod) -{ - return binpow(x,m-2,m); -} - -int fact(int x){ - if(x<=1) return 1; - if(fact_dp[x] != -1) return fact_dp[x]; - - return fact_dp[x] = (x%mod * fact(x-1)%mod)%mod; -} - -int nCr(int n, int r){ - int x = (modinv(fact(r)) * modinv(fact(n-r)))%mod; - int y = fact(n); - return (x*y)%mod; -} - -void solve() -{ - int n, m; - cin >> n >> m; - vector a(n), b(m); - cin >> a >> b; - sort(all(a)); - sort(all(b)); - - priority_queue, greater> q; - for(auto it : a){ - q.push(it); - } - - int j = 0; - while(!q.empty() && j>t; - while(t--){ - solve(); - } - - return 0; -}","#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; - -#pragma GCC optimize(""O3,unroll-loops"") - -using ll = long long; -using ld = long double; - -typedef tree,rb_tree_tag,tree_order_statistics_node_update> oset; - -constexpr ll inf=2e18; -constexpr ld eps=1e-9; -constexpr ll mod=1e9+7; - -#define F first -#define S second -#define int long long -#define pb push_back -#define all(x) x.begin(), x.end() - -template -istream& operator>>(istream &istream, vector &v) -{ - for(auto &it : v) - cin>>it; - return istream; -} - -template -ostream& operator<<(ostream &ostream, const vector &c) -{ - for(auto &it : c) - cout< fact_dp(2e5+2,-1); - -int binpow(int a, int b, int m=mod) -{ - if(b==0) - return 1; - - int x = binpow(a,b/2); - if(b&1) - return ((x*x)%m*a)%m; - return (x*x)%m; -} - -int modinv(int x, int m=mod) -{ - return binpow(x,m-2,m); -} - -int fact(int x){ - if(x<=1) return 1; - if(fact_dp[x] != -1) return fact_dp[x]; - - return fact_dp[x] = (x%mod * fact(x-1)%mod)%mod; -} - -int nCr(int n, int r){ - int x = (modinv(fact(r)) * modinv(fact(n-r)))%mod; - int y = fact(n); - return (x*y)%mod; -} - -void solve() -{ - int n, m; - cin >> n >> m; - priority_queue a, b; - for(int i = 0 ; i < n ; i++){ - int x ; cin >> x; - a.push(x); - } - for(int i = 0 ; i < m ; i++){ - int x ; cin >> x; - b.push(x); - } - - while(!b.empty() && !a.empty()){ - - if(a.size()>t; - while(t--){ - solve(); - } - - return 0; -}",2 -516manav,2061D - Kevin and Numbers,c++23 ,306646573,305757583,"#include -using namespace std; -#define ll long long -const ll mod = 998244353; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while(t--){ - int n, m; - cin >> n >> m; - multiset> a, b; - for(int i{0}; i> k; - a.insert(k); - } - for(int i{0}; i> k; - b.insert(k); - } - int c=0; - while(!b.empty() && !a.empty()){ - auto eb=*b.begin(); - if(a.find(eb)!=a.end()){ - b.erase(b.begin()); - a.erase(a.find(eb)); - }else{ - if(++c>n-m) - break; - b.erase(b.begin()); - b.insert(eb/2); - b.insert((eb+1)/2); - } - } - if(a.empty() && b.empty()) - cout << ""YES\n""; - else - cout << ""NO\n""; - } -}","#include -using namespace std; -#define ll long long -const ll mod = 998244353; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin >> t; - while(t--){ - int n, m; - cin >> n >> m; - multiset a, b; - for(int i{0}; i> k; - a.insert(k); - } - for(int i{0}; i> k; - b.insert(k); - } - int c=0; - while(!a.empty() && !b.empty()){ - auto it2=a.begin(), it1=a.begin(); - it2++; - auto bit1=b.find(*it1); - if(bit1!=b.end()){ - b.erase(bit1); - a.erase(it1); - }else if(it2!=a.end()){ - if(*it2-*it1<=1){ - ll el=*it2+*it1; - a.erase(it1); - a.erase(it2); - a.insert(el); - }else{ - a.erase(it1); - c++; - } - }else{ - a.erase(it1); - c++; - } - } - if(b.empty() && a.empty() && c==0) - cout << ""YES\n""; - else - cout << ""NO\n""; - } -}",1 -AnhonySharma,2061D - Kevin and Numbers,c++20 ,307306733,307307827,"#include -#include -#include -#include -#include -using namespace std; -int tci = 0; - -bool rec(int x, multiset &values) { - int h1 = x / 2, h2 = x - x / 2; - int c1 = values.count(h1); - int c2 = values.count(h2); - - // if (tci == 6) - // cout << x << "" "" << h1 << "" "" << h2 << "" "" << c1 << "" "" << c2 << "" "" << values.count(x) << ""\n""; - if (values.count(x)) { - values.erase(values.find(x)); - return true; - } else if (x == 1) { - return false; - } else if (c1 && c2) { - return (h1 == h2 ? c1 >= 2: true) && rec(h1, values) && rec(h2, values); - } else { - return rec(h1, values) && rec(h2, values); - } - - return false; -} - -void solve() -{ - int n, m, x; - cin >> n >> m; - multiset values; - for (int i = 0; i < n; i++) { - cin >> x; - values.insert(x); - } - - bool ans = true; - for (int i = 0; i < m; i++) { - cin >> x; - if (!rec(x, values)) { - ans = false; - } - } - - cout << (ans && !values.size() ? ""Yes\n"": ""No\n""); -} - -int main() -{ - int tc; - cin >> tc; - - for(tci = 0; tci < tc; tci++) { - // cout << ""Case #"" << tci + 1 << "": ""; - solve(); - } - - return 0; -}","#include -#include -#include -#include -#include -using namespace std; -int tci = 1; - -bool rec(int x, multiset &values) { - if (values.count(x)) { - values.erase(values.find(x)); - return true; - } else if (x == 1) { - return false; - } else { - return rec(x / 2, values) && rec(x - x / 2, values); - } - - return false; -} - -void solve() -{ - int n, m, x; - cin >> n >> m; - multiset values; - for (int i = 0; i < n; i++) { - cin >> x; - values.insert(x); - } - - bool ans = true; - for (int i = 0; i < m; i++) { - cin >> x; - if (!rec(x, values)) { - ans = false; - } - } - - cout << (ans && !values.size() ? ""Yes\n"": ""No\n""); -} - -int main() -{ - int tc; - cin >> tc; - - for(tci = 1; tci <= tc; tci++) { - // cout << ""Case #"" << tci + 1 << "": ""; - solve(); - } - - return 0; -}",2 -__32801_altter_code_,2061D - Kevin and Numbers,c++23 ,303423641,302745856,"#include -using namespace std; - -#define int long long -#define aa(z) int z; cin >> z -#define vi vector -#define f(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define in(arr, n) for (int i = 0; i < n; i++) cin >> arr[i] -#define out(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << "" ""; cout << endl -#define srt(v) sort(v.begin(), v.end()) -#define srtr(v) sort(v.begin(), v.end(), greater()) -#define err cout << fixed << setprecision(10) -#define lb(arr, d) lower_bound(arr, arr + n, d) - arr -const int mod = 998244353; -/// heyyyy pravesshhhhhh from mirzaaapurrrr how areee youuuuuuuuuu thanks for giving me hint -void mohammaad_rafi() { - aa(n); - aa(m); - vi a(n), b(m); - in(a, n); - in(b, m); - map mpa,mpb; - f(i,n){ - mpa[a[i]]++; - } - f(i,m){ - mpb[b[i]]++; - } - -while(mpa.size()>0&&mpb.size()>0){ -auto it=mpb.begin(); -int key=it->first; -mpb[key]--; -if(mpb[key]==0){ - mpb.erase(key); -} -while(mpa.find(key)==mpa.end()){ - auto kt=mpa.begin(); - if(keyfirst){ - cout<<""No""< -using namespace std; - -#define int long long -#define aa(z) int z; cin >> z -#define vi vector -#define f(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define in(arr, n) for (int i = 0; i < n; i++) cin >> arr[i] -#define out(arr, n) for (int i = 0; i < n; i++) cout << arr[i] << "" ""; cout << endl -#define srt(v) sort(v.begin(), v.end()) -#define srtr(v) sort(v.begin(), v.end(), greater()) -#define err cout << fixed << setprecision(10) -#define lb(arr, d) lower_bound(arr, arr + n, d) - arr -const int mod = 998244353; - -void mohammaad_rafi() { - aa(n); - aa(m); - vi a(n), b(m); - in(a, n); - in(b, m); - - map mp; - srt(a); - srt(b); - - // Populate the map with elements of `a` - for (int x : a) { - mp[x]++; - } - - int i = 0; - while (i < m) { - if (mp.find(b[i]) != mp.end() && mp[b[i]] >= 1) { - // Exact match found - mp[b[i]]--; - if (mp[b[i]] == 0) { - mp.erase(b[i]); - } - i++; - } else if (mp.find(b[i] / 2) != mp.end() && b[i] % 2 == 0 && mp[b[i] / 2] >= 2) { - // Combine two smaller elements to form `b[i]` (even case) - mp[b[i] / 2] -= 2; - if (mp[b[i] / 2] == 0) { - mp.erase(b[i] / 2); - } - i++; - } else if (mp.find(b[i] / 2) != mp.end() && mp.find(b[i] / 2 + 1) != mp.end() && - b[i] % 2 != 0 && mp[b[i] / 2] >= 1 && mp[b[i] / 2 + 1] >= 1) { - // Combine two smaller elements to form `b[i]` (odd case) - mp[b[i] / 2]--; - mp[b[i] / 2 + 1]--; - if (mp[b[i] / 2] == 0) { - mp.erase(b[i] / 2); - } - if (mp[b[i] / 2 + 1] == 0) { - mp.erase(b[i] / 2 + 1); - } - i++; - } else { - // Try to create `b[i]` by combining smaller elements - auto it = mp.begin(); - while (!mp.empty() && it->first < b[i]) { - int key = it->first; - if (mp.find(key ) != mp.end() && mp[key ] >= 2) { - // Combine `key` and `key + 1` to form `key + key + 1` - mp[key]--; - mp[key ]--; - mp[key + key]++; - if (mp[key] == 0) { - mp.erase(key); - } - // if (mp[key ] == 0) { - // mp.erase(key 1); - // } - - // Add the combined element - - } - - else if (mp.find(key + 1) != mp.end() && mp[key + 1] >= 1) { - // Combine `key` and `key + 1` to form `key + key + 1` - mp[key]--; - mp[key + 1]--; - if (mp[key] == 0) { - mp.erase(key); - } - if (mp[key + 1] == 0) { - mp.erase(key + 1); - } - - // Add the combined element - mp[key + key + 1]++; - } else { - // No valid combination can be made - break; - } - - // Update iterator after potential erasures - it = mp.begin(); - } - - // After trying, check if `b[i]` can be satisfied - it = mp.begin(); - if (mp.empty() || it->first != b[i]) { - cout << ""NO"" << endl; - return; - } - } - } - if(mp.size()!=0){ - cout<<""No""< -using namespace std; -typedef long double ld; -#define int long long -#define fr(i,a,b) for(int i=a;i>= 1; - } - return result; -} -int log_a_base_b(int a , int b){ - int cnt=0; - while(a!=0){ - a/=b; - cnt++; - } - return cnt; -} -void solve(){ - int n,m; - cin >> n>>m ; - multiset s1; - multiset s2; - fr(i,0,n){ - int x; - cin>>x; - s1.insert(x); - } - fr(i,0,m){ - int x; - cin>>x; - s2.insert(x); - } - // int f=1; - while(!s1.empty() && !s2.empty()){ - auto it1=--s1.end(),it2=--s2.end(); - if(*it2>*it1){ - int x=floor((*it2)*1.0/2); - int y=ceil((*it2)*1.0/2); - s2.erase(it2); - s2.insert(x); - s2.insert(y); - // cout<s1.size()){ - // f=0; - break; - } - } - // if(!f) cout<<""No""<> t; - while(t--) - { - solve(); - } -}","#include -using namespace std; -typedef long double ld; -#define int long long -#define fr(i,a,b) for(int i=a;i>= 1; - } - return result; -} -int log_a_base_b(int a , int b){ - int cnt=0; - while(a!=0){ - a/=b; - cnt++; - } - return cnt; -} -void solve(){ - int n,m; - cin >> n>>m ; - multiset s1; - multiset s2; - fr(i,0,n){ - int x; - cin>>x; - s1.insert(x); - } - fr(i,0,m){ - int x; - cin>>x; - s2.insert(x); - } - // int f=1; - while(!s1.empty() && !s2.empty()){ - auto it1=--s1.end(),it2=--s2.end(); - if(*it2>*it1){ - s2.erase(it2); - int x=floor((*it2)*1.0/2); - int y=ceil((*it2)*1.0/2); - s2.insert(x); - s2.insert(y); - // cout<s1.size()){ - // f=0; - break; - } - } - // if(!f) cout<<""No""<> t; - while(t--) - { - solve(); - } -}",1 -Lelyte#,2061D - Kevin and Numbers,c++20 ,302881686,302872845,"// author: лелутик :3 -//#define _GLIBCXX_DEBUG -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -#define int long long -#define pii pair -#define line cout << ""\n"" -#define pb push_back -#define ppb pop_back -#define sz(a) (int) a.size() -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() -#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) -typedef long long ll; -typedef long double ld; -typedef string str; -mt19937 rnd(time(0)); -const int MOD = 998244353; - - -void solve() { - int n, m; - cin >> n >> m; - vector a(n), b(m); - multiset st1, st2; - int s1 = 0, s2 = 0; - for (int i = 0; i < n; i++) { - cin >> a[i]; - st1.insert(a[i]); - s1 += a[i]; - } - for (int i = 0; i < m; i++) { - cin >> b[i]; - st2.insert(b[i]); - s2 += b[i]; - } - if (s1 != s2) { - cout << ""No""; line; - return; - } - while (sz(st1) && sz(st2) && sz(st2) <= sz(st1)) { - int x = *(--st2.end()); - if (x < *st1.begin()) { - cout << ""No""; line; - return; - } - st2.erase(--st2.end()); - if (st1.find(x) != st1.end()) { - st1.erase(st1.find(x)); - continue; - } - st2.insert(x / 2); - st2.insert((x + 1) / 2); - } - if (sz(st1) || sz(st2)) { - cout << ""No""; line; - return; - } - cout << ""Yes""; line; -} - - -signed main() { - fast; - - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - - int t = 1; - cin >> t; - while (t--) { - solve(); - } -} -","// author: лелутик :3 -//#define _GLIBCXX_DEBUG -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -#define int long long -#define pii pair -#define line cout << ""\n"" -#define pb push_back -#define ppb pop_back -#define sz(a) (int) a.size() -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(), a.rend() -#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) -typedef long long ll; -typedef long double ld; -typedef string str; -mt19937 rnd(time(0)); -const int MOD = 998244353; - - -void solve() { - int n, m; - cin >> n >> m; - vector a(n), b(m); - multiset st; - for (int i = 0; i < n; i++) { - cin >> a[i]; - st.insert(a[i]); - } - for (int i = 0; i < m; i++) { - cin >> b[i]; - } - sort(all(b)); - int i = 0; - while (sz(st) && i < sz(b)) { - int x = *st.begin(); - st.erase(st.begin()); - if (x == b[i]) { - i++; - continue; - } - if (!sz(st)) { - cout << ""No""; line; - return; - } - int y = *st.begin(); - st.erase(st.begin()); - if (y - x > 1) { - cout << ""No""; line; - return; - } - st.insert(x + y); - } - if (sz(st) || i != sz(b)) { - cout << ""No""; line; - return; - } - cout << ""Yes""; line; -} - - -signed main() { - fast; - - -#ifdef LOCAL - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - - int t = 1; - cin >> t; - while (t--) { - solve(); - } -} -",1 -sittharalasirapadu,2061D - Kevin and Numbers,c++17 ,303479196,303477923,"#include -#include -using namespace std; -using ll = long long; -ll mod = 1e9+7; - -class TrieNode { -public: - bool isEnd; - TrieNode* nxt[26]; - TrieNode(bool b = false) { - isEnd = b; - memset(nxt, 0, sizeof(nxt)); - } -}; - -class Trie { - TrieNode* root; -public: - Trie() { - root = new TrieNode(); - } - void insert(string s) { - TrieNode* cur = root; - for (char c : s) { - if (cur->nxt[c - 'a'] == NULL) { - cur->nxt[c - 'a'] = new TrieNode(); - } - cur = cur->nxt[c - 'a']; - } - cur->isEnd = true; - } - bool search(string s) { - TrieNode* cur = root; - for (char c : s) { - if (!(cur->nxt[c - 'a'])) { - return false; - } - cur = cur->nxt[c - 'a']; - } - return cur->isEnd; - } - ll countCombs(string s, ll k, ll sz, unordered_map& dp) { - if (k == sz) { - return 1; - } - if (dp.find(k) != dp.end()) { - return dp[k]; - } - TrieNode* cur = root; - ll res = 0; - for (ll i = k; i < sz; i++) { - if (!(cur->nxt[s[i] - 'a'])) { - return res; - } - cur = cur->nxt[s[i] - 'a']; - if (cur->isEnd) { - res = (res + countCombs(s, i + 1, sz, dp)) % mod; - } - } - return dp[k] = res; - } -}; - - -vectorgiveLps(string s){ - int n=s.length(); - vectorlps(n,0); - int len=0; - for(int i=1;idq){ - while(dq.size()){ - cout<st){ - while(st.size()){ - cout<&vec){ - for(int u:vec){ - cout<&curr2 , vector&curr){ - vectorres; - int n=curr2.size(),m=curr.size(),i=0,j=0; - while(i; -void solver(){ - int n,m; - cin>>n>>m; - vectora,b; - ll sma=0,smb=0; - for(int i=0;i>x; - a.push_back(x); - sma+=x; - } - priority_queuepq; - for(int i=0;i>x; - pq.push(x); - smb+=x; - } - if(sma!=smb){ - cout<<""NO""<=0){ - int curr = pq.top(); - //cout<a[i] ){ - pq.push(curr/2); - pq.push(curr/2+curr%2); - }else{ - cout<<""NO""<>t; - //t=1; - for(int i=0;i -#include -using namespace std; -using ll = long long; -ll mod = 1e9+7; - -class TrieNode { -public: - bool isEnd; - TrieNode* nxt[26]; - TrieNode(bool b = false) { - isEnd = b; - memset(nxt, 0, sizeof(nxt)); - } -}; - -class Trie { - TrieNode* root; -public: - Trie() { - root = new TrieNode(); - } - void insert(string s) { - TrieNode* cur = root; - for (char c : s) { - if (cur->nxt[c - 'a'] == NULL) { - cur->nxt[c - 'a'] = new TrieNode(); - } - cur = cur->nxt[c - 'a']; - } - cur->isEnd = true; - } - bool search(string s) { - TrieNode* cur = root; - for (char c : s) { - if (!(cur->nxt[c - 'a'])) { - return false; - } - cur = cur->nxt[c - 'a']; - } - return cur->isEnd; - } - ll countCombs(string s, ll k, ll sz, unordered_map& dp) { - if (k == sz) { - return 1; - } - if (dp.find(k) != dp.end()) { - return dp[k]; - } - TrieNode* cur = root; - ll res = 0; - for (ll i = k; i < sz; i++) { - if (!(cur->nxt[s[i] - 'a'])) { - return res; - } - cur = cur->nxt[s[i] - 'a']; - if (cur->isEnd) { - res = (res + countCombs(s, i + 1, sz, dp)) % mod; - } - } - return dp[k] = res; - } -}; - - -vectorgiveLps(string s){ - int n=s.length(); - vectorlps(n,0); - int len=0; - for(int i=1;idq){ - while(dq.size()){ - cout<st){ - while(st.size()){ - cout<&vec){ - for(int u:vec){ - cout<&curr2 , vector&curr){ - vectorres; - int n=curr2.size(),m=curr.size(),i=0,j=0; - while(i; -void solver(){ - int n,m; - cin>>n>>m; - vectora,b; - ll sma=0,smb=0; - for(int i=0;i>x; - a.push_back(x); - sma+=x; - } - priority_queuepq; - for(int i=0;i>x; - pq.push(x); - smb+=x; - } - if(sma!=smb){ - cout<<""NO""<=0){ - int curr = pq.top(); - //cout<a[i] && abs(curr-2*a[i])<=1){ - pq.push(curr-a[i--]); - }else{ - cout<<""NO""<>t; - //t=1; - for(int i=0;i dp on tree - * dfs calcualtes the subtree distance - * dfs 2 calculates the parent answer and sub tree ans combine we can give - * ( Path of max distance can't consider max 2 can consider "" - */ - - -public class CpWala { - private static void solverA() { - int size[] = Reading.readIntArray(); - int n = size[ 0 ] , m = size[ 1 ]; - int[] arr = Reading.readIntArray(); - int[] barr = Reading.readIntArray(); - HashMap map = new HashMap<>(); - for(int i : arr ) { - map.put( i , map.getOrDefault( i , 0) + 1); - } - int countx = n ; - for(int i = 0 ; i < m ;i ++ ) { - - if( map.getOrDefault( barr[ i ], 0 ) > 0 ) { - map.put( barr[ i] , map.get( barr[ i ]) - 1 ); - barr[ i ] = 0 ; - countx --; - } - } - int inxa = 0; - arr = new int[ countx ]; - for(int i : map.keySet() ) { - int v = map.get( i ) ; - while( v -- > 0 ) { - arr[ inxa ++ ] = i; - } - } - Arrays.sort( arr ); - n = countx ; - int l = 0 , lb = 0 ; - - for(; lb < m ; ++ lb ) { - if( barr[ lb ] ==0 ) continue; - if( l == n ) { - out.println(""NO""); return; - } - int reqX = barr[ lb ]; - if( arr[ l ] == barr[ lb ]) { - continue; - } - int req = arr[ l ]; - l ++ ; - while( l < n && req < barr[ lb ] && Math.abs( req - arr[ l ]) <= 1) { - req += arr[ l ]; - l ++; - } - if( req == barr[ lb ] ) continue; - out.println(""NO""); - return; - } - if( l == n ) { - out.println(""YES""); - } - else out.println(""NO""); - } - private static void dfs( int curNode , int parent , ArrayList prefix - , ArrayList prefix_sum , ArrayList[] tree , int[] res ) { - if( tree[ curNode ] == null ) return; - for(var node : tree [ curNode ]) { - if( parent == node.next ) continue; - long ai = node.weight; - long bi = node.weight1 ; - int next = node.next; - - prefix.add( prefix.get( prefix.size() - 1) + ai ) ; - - prefix_sum.add( prefix_sum.get( prefix_sum.size() - 1) + bi ); - res[ next ] = find(next , prefix.get( prefix.size() - 1) , prefix_sum ) ; - dfs( next , curNode , prefix , prefix_sum , tree , res ); - prefix.remove( prefix.size() -1 ); - prefix_sum.remove( prefix_sum.size() - 1); - - } - } - private static int find( int x , long value , ArrayList search ) { - int v = Collections.binarySearch(search , value ); - //out.println( search +"" ""+value+"" ""+x +"" ""+v ); - if( v < 0 ) return -(v + 2); - return v; - } - static PrintWriter out = new PrintWriter(System.out); - - public static void main(String[] arg) { - int testNo = Reading.readInt(); - while (testNo-- > 0) { - solverA(); - } - out.flush(); - out.close(); - } - - private static long getLowerPower(long rem, int k) { - // k^x <= n - long res = 1; - while (res <= rem) { - res = res * k; - } - res /= k; - return res; - } - - private static long findMinoOpern(int n, int k) { - if (k == 1) return n; - long res = getLowerPower(n, k); - int count = 0; - long rem = n; - while (rem >= k) { - long powcan = (rem / res); - rem = (rem % res); - count += powcan; - res = getLowerPower(rem, k); - } - return rem % k + count; - } - - private static int[] kmp(String string) { - int[] res = new int[string.length()]; - int j = 0; - for (int indx = 1; indx < string.length();) { - if (string.charAt(indx) == string.charAt(j)) { - if (j == 0) { - res[indx] = 1; - } else - res[indx] = j + 1; - j++; - indx++; - } else { - if (j == 0) { - indx++; - continue; - } - j = res[j - 1]; - } - } - return res; - } -} -class Union { - int[] parent ; - int[] rank ; - int n ; - int[] size ; - public Union ( int size ) { - n = size + 1; - this.size = new int[ size + 1 ]; - parent = new int [ size + 1]; - rank = new int[ size + 1]; - Arrays.fill( this.size ,1 ); - Arrays.fill( parent , -1 ); - Arrays.fill( rank , -1 ); - } - public void union(int u , int v ) { - int parent_u = find( u ) ; - int parent_v = find( v ); - if( parent_u != parent_v ) { - if( parent_v > parent_u) { - parent[ parent_u ] = parent_v ; - size[ parent_u ] += size[ parent_v ]; - } - else { - parent[ parent_v ] = parent_u; - size[ parent_u ]+=size[ parent_u]; - } - } - } - public int find( int node ) { - if( parent[ node ] == -1 ) return node ; - return parent[ node ] = find( parent[ node ]); - } - -} -class TreeNode { - int next ; - long weight , weight1 ; - public TreeNode ( int node , int weight , int weight1 ) { - this.next = node ; - this.weight = weight; - this.weight1 = weight1 ; - } - public String toString() { - return ""[""+next+"" , "" + weight + "" , ""+weight1+"" ] ""; - } -} -class Reading { - private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - - public Reading() { - reader = new BufferedReader(new InputStreamReader(System.in)); - } - - public static int readInt() { - try { - return Integer.parseInt(reader.readLine().trim()); - } catch (Exception e) { - return -1; - } - } - - public static int[] readIntArray() { - try { - return Arrays.stream(reader.readLine().trim().split(""\\s+"")) - .mapToInt(Integer::parseInt) - .toArray(); - } catch (Exception e) { - return null; - } - } - - public static long[] readLongArray() { - try { - return Arrays.stream(reader.readLine().trim().split(""\\s+"")) - .mapToLong(Long::parseLong) - .toArray(); - } catch (Exception e) { - return null; - } - } - - public static String readString() { - try { - return reader.readLine(); - } catch (Exception e) { - return null; - } - } - - public static char[] readToCharArray() { - try { - return reader.readLine().replaceAll(""\\s+"", """").toCharArray(); - } catch (Exception e) { - return null; - } - } -}","import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.math.BigInteger; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.NavigableSet; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Scanner; -import java.util.Set; -import java.util.Stack; -import java.util.TreeMap; -import java.util.TreeSet; - -/* - * Author : RTE_ELMENATOR - * - * ""No one will carry you. - * Work harder, and turn your dream into reality."" - * "" - * If you're stuck in a problem while solving - * Then Think about the Answer (how related to input) - * "" - * "" Tree Questions : -> dp on tree - * dfs calcualtes the subtree distance - * dfs 2 calculates the parent answer and sub tree ans combine we can give - * ( Path of max distance can't consider max 2 can consider "" - */ - - -public class CpWala { - private static void solverA() { - int size[] = Reading.readIntArray(); - int n = size[ 0 ] , m = size[ 1 ]; - int[] arr = Reading.readIntArray(); - int[] barr = Reading.readIntArray(); - HashMap map = new HashMap<>(); - for(int i : arr ) { - map.put( i , map.getOrDefault( i , 0) + 1); - } - - - int l = 0 , lb = 0 ; - - for(; lb < m ; ++ lb ) { - if( barr[ lb ] ==0 ) continue; - int need = barr[ lb ] ; - - boolean isokay = find( need , map ); - if(!isokay) {out.println(""NO""); return;} - } - if(map.isEmpty()) out.println(""YES""); - else out.println(""NO""); - } - private static boolean find( int val ,HashMap map ) { - - if( map.containsKey( val )) { - map.put( val , map.get( val ) - 1); - if( map.get( val ) == 0 ) map.remove( val ); - return true; - } - if( val == 1) return false; - return find( val /2 , map ) && find( val/2 + (val%2 ) , map ); - } - private static void dfs( int curNode , int parent , ArrayList prefix - , ArrayList prefix_sum , ArrayList[] tree , int[] res ) { - if( tree[ curNode ] == null ) return; - for(var node : tree [ curNode ]) { - if( parent == node.next ) continue; - long ai = node.weight; - long bi = node.weight1 ; - int next = node.next; - - prefix.add( prefix.get( prefix.size() - 1) + ai ) ; - - prefix_sum.add( prefix_sum.get( prefix_sum.size() - 1) + bi ); - res[ next ] = find(next , prefix.get( prefix.size() - 1) , prefix_sum ) ; - dfs( next , curNode , prefix , prefix_sum , tree , res ); - prefix.remove( prefix.size() -1 ); - prefix_sum.remove( prefix_sum.size() - 1); - - } - } - private static int find( int x , long value , ArrayList search ) { - int v = Collections.binarySearch(search , value ); - //out.println( search +"" ""+value+"" ""+x +"" ""+v ); - if( v < 0 ) return -(v + 2); - return v; - } - static PrintWriter out = new PrintWriter(System.out); - - public static void main(String[] arg) { - int testNo = Reading.readInt(); - while (testNo-- > 0) { - solverA(); - } - out.flush(); - out.close(); - } - - private static long getLowerPower(long rem, int k) { - // k^x <= n - long res = 1; - while (res <= rem) { - res = res * k; - } - res /= k; - return res; - } - - private static long findMinoOpern(int n, int k) { - if (k == 1) return n; - long res = getLowerPower(n, k); - int count = 0; - long rem = n; - while (rem >= k) { - long powcan = (rem / res); - rem = (rem % res); - count += powcan; - res = getLowerPower(rem, k); - } - return rem % k + count; - } - - private static int[] kmp(String string) { - int[] res = new int[string.length()]; - int j = 0; - for (int indx = 1; indx < string.length();) { - if (string.charAt(indx) == string.charAt(j)) { - if (j == 0) { - res[indx] = 1; - } else - res[indx] = j + 1; - j++; - indx++; - } else { - if (j == 0) { - indx++; - continue; - } - j = res[j - 1]; - } - } - return res; - } -} -class Union { - int[] parent ; - int[] rank ; - int n ; - int[] size ; - public Union ( int size ) { - n = size + 1; - this.size = new int[ size + 1 ]; - parent = new int [ size + 1]; - rank = new int[ size + 1]; - Arrays.fill( this.size ,1 ); - Arrays.fill( parent , -1 ); - Arrays.fill( rank , -1 ); - } - public void union(int u , int v ) { - int parent_u = find( u ) ; - int parent_v = find( v ); - if( parent_u != parent_v ) { - if( parent_v > parent_u) { - parent[ parent_u ] = parent_v ; - size[ parent_u ] += size[ parent_v ]; - } - else { - parent[ parent_v ] = parent_u; - size[ parent_u ]+=size[ parent_u]; - } - } - } - public int find( int node ) { - if( parent[ node ] == -1 ) return node ; - return parent[ node ] = find( parent[ node ]); - } - -} -class TreeNode { - int next ; - long weight , weight1 ; - public TreeNode ( int node , int weight , int weight1 ) { - this.next = node ; - this.weight = weight; - this.weight1 = weight1 ; - } - public String toString() { - return ""[""+next+"" , "" + weight + "" , ""+weight1+"" ] ""; - } -} -class Reading { - private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - - public Reading() { - reader = new BufferedReader(new InputStreamReader(System.in)); - } - - public static int readInt() { - try { - return Integer.parseInt(reader.readLine().trim()); - } catch (Exception e) { - return -1; - } - } - - public static int[] readIntArray() { - try { - return Arrays.stream(reader.readLine().trim().split(""\\s+"")) - .mapToInt(Integer::parseInt) - .toArray(); - } catch (Exception e) { - return null; - } - } - - public static long[] readLongArray() { - try { - return Arrays.stream(reader.readLine().trim().split(""\\s+"")) - .mapToLong(Long::parseLong) - .toArray(); - } catch (Exception e) { - return null; - } - } - - public static String readString() { - try { - return reader.readLine(); - } catch (Exception e) { - return null; - } - } - - public static char[] readToCharArray() { - try { - return reader.readLine().replaceAll(""\\s+"", """").toCharArray(); - } catch (Exception e) { - return null; - } - } -}",2 -arrow_s,2061D - Kevin and Numbers,c++20 ,303637980,303635575,"#include -#include -#include -using namespace std; -#ifndef ONLINE_JUDGE -#include ""debugg.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -//change less to less_equal to make it a multiorderedset -//to erase from multiorderedset do s.erase(s.upperbound(a[i])) -//find_by_order(k)->iterator of the kth element -//order_of_key(k)->number of elements smaller than k -//ncr snip has modinv as well -#define float double -#define yes cout<<""YES""<>a[i] -#define scannarr(a) int a[(int)(a)];for(int i=0;i<(int)(a);i++)cin>>a[i] -#define fr(i, a, b) for (int i = (a); i < (int)(b); ++i) -#define frr(i, a, b) for (int i = (a); i >= (int)(b); --i) -#define vi vector -#define vvi vector> -#define pi pair -#define vpi vector> -#define frr(i, a, b) for (int i = (a); i >= (int)(b); --i) -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define sz(a) (int)(a.size()) -#define all(a) a.begin(), a.end() -#define mod 1000000007 - -int gcd(int a, int b) { - return b == 0 ? a : gcd(b, a % b); -} - -void solve() { - int n,m; - cin>>n>>m; - vi a(n),b(m); - fr(i,0,n)cin>>a[i]; - fr(i,0,m)cin>>b[i]; - mapm1,m2; - sets,s1; - fr(i,0,n){ - m1[a[i]]++; - s1.insert(a[i]); - } - fr(i,0,m){ - m2[b[i]]++; - s.insert(b[i]); - } - setdel; - for(auto x:s){ - int k=max((int)0,m1[x]-m2[x]); - int g=m1[x]-k; - m2[x]-=g; - if(m2[x]==0)del.insert(x); - m1[x]=k; - if(k==0)s1.erase(x); - } - - for(auto x:del)s.erase(x); - // function dfs = [&] (int r,int c) -> void - int check=0; - priority_queueq; - function solve = [&] (int x,int f) -> void{ - if(x==0)return; - if(x==1){ - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - if(m1[x]==0)s1.erase(x); - if(f!=0){ - check=1; - } - return; - } - if(x%2==0){ - m2[x]=0; - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - if(m1[x]==0)s1.erase(x); - if(f==0)return; - m2[x/2]+=f*2; - if(s.find(x/2)==s.end())q.push(x/2); - // solve(x/2,f*2); - - } - else{ - m2[x]=0; - s.erase(x); - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - if(m1[x]==0)s1.erase(x); - if(f==0)return; - if(s.find(x/2)==s.end()){q.push(x/2);s.insert(x/2);} - if(s.find((x/2)+1)==s.end()){q.push((x/2)+1);s.insert((x/2)+1);} - // c(x);p(m1[x]); - m2[x/2]+=f;m2[(x/2)+1]+=f; - // solve(x/2,f);solve((x/2)+1,f); - } - }; - - for(auto x:s){ - q.push(x); - } - while(q.size()){ - int x=q.top(); - q.pop(); - solve(x,m2[x]); - if(check==1){p(""No"");return;} - } - - if(s1.size()==0)p(""Yes""); - else p(""No""); - - - - -} -signed main() { - fast; - int t=1; - cin>>t; - while (t--) { - solve(); - } - return 0; -}","#include -#include -#include -using namespace std; -#ifndef ONLINE_JUDGE -#include ""debugg.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -//change less to less_equal to make it a multiorderedset -//to erase from multiorderedset do s.erase(s.upperbound(a[i])) -//find_by_order(k)->iterator of the kth element -//order_of_key(k)->number of elements smaller than k -//ncr snip has modinv as well -#define float double -#define yes cout<<""YES""<>a[i] -#define scannarr(a) int a[(int)(a)];for(int i=0;i<(int)(a);i++)cin>>a[i] -#define fr(i, a, b) for (int i = (a); i < (int)(b); ++i) -#define frr(i, a, b) for (int i = (a); i >= (int)(b); --i) -#define vi vector -#define vvi vector> -#define pi pair -#define vpi vector> -#define frr(i, a, b) for (int i = (a); i >= (int)(b); --i) -#define fast \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) -#define sz(a) (int)(a.size()) -#define all(a) a.begin(), a.end() -#define mod 1000000007 - -int gcd(int a, int b) { - return b == 0 ? a : gcd(b, a % b); -} - -void solve() { - int n,m; - cin>>n>>m; - vi a(n),b(m); - fr(i,0,n)cin>>a[i]; - fr(i,0,m)cin>>b[i]; - mapm1,m2; - sets,s1; - fr(i,0,n){ - m1[a[i]]++; - s1.insert(a[i]); - } - fr(i,0,m){ - m2[b[i]]++; - s.insert(b[i]); - } - setdel; - for(auto x:s){ - int k=max((int)0,m1[x]-m2[x]); - int g=m1[x]-k; - m2[x]-=g; - if(m2[x]==0)del.insert(x); - m1[x]=k; - if(k==0)s1.erase(x); - } - - for(auto x:del)s.erase(x); - // function dfs = [&] (int r,int c) -> void - int check=0; -// p(""hi""); - function solve = [&] (int x,int f) -> void{ - if(x==0)return; - if(x==1){ - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - if(m1[x]==0)s1.erase(x); - if(f!=0){ - check=1; - } - return; - } - if(x%2==0){ - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - // c(x);p(m1[x]); - if(m1[x]==0)s1.erase(x); - if(f==0)return; - solve(x/2,f*2); - - } - else{ - if(m1[x]!=0){ - if(m1[x]>=f){ - m1[x]-=f;f=0; - } - else{ - f-=m1[x];m1[x]=0; - } - } - // c(x);p(m1[x]); - if(m1[x]==0)s1.erase(x); - if(f==0)return; - solve(x/2,f);solve((x/2)+1,f); - } - }; - - for(auto x:s){ - solve(x,m2[x]); - // c(""check "");c(x);p(check); - if(check==1){p(""No"");return;} - } - // solve(3,m2[3]); - // p((*s1.begin())); - if(s1.size()==0)p(""Yes""); - else p(""No""); - - - - -} -signed main() { - fast; - int t=1; - cin>>t; - while (t--) { - solve(); - } - return 0; -}",1 -am_.nnhwt,2061D - Kevin and Numbers,c++20 ,306701736,306686971,"#include -using namespace std; -const int N=2e5+5; -int n,m,a[N],b[N]; -map mp; -void process() { - cin>>n>>m; - mp.clear(); - for (int i=1; i<=n; ++i) { cin>>a[i]; mp[a[i]]++; } - priority_queue q; - for (int i=1; i<=m; ++i) { cin>>b[i]; q.push(b[i]); } - while (m>t; - while (t--) { - process(); - } -} -","#include -using namespace std; -const int N=2e5+5; -int n,m,a[N],b[N]; -map mp; -void process() { - cin>>n>>m; - mp.clear(); - for (int i=1; i<=n; ++i) { cin>>a[i]; mp[a[i]]++; } - priority_queue q; - for (int i=1; i<=m; ++i) { cin>>b[i]; q.push(b[i]); } - while (m>t; - while (t--) { - process(); - } -} -",1 -ikun-ikun,2061D - Kevin and Numbers,c++17 ,302695077,302695029,"#include -using namespace std; -#define int long long -#define YES cout<<""YES\n""; -#define NO cout<<""NO\n""; -#define endl ""\n"" -#define fi first -#define se second -#define pb push_back -#define pii pair -#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) -const int N=1e9+7; -const int N1=1e6+3; -signed main(){IOS; - int t;cin>>t; - while(t--){ - int n,m;cin>>n>>m;int a[n+1],b[m+1]; - mapmp;int sum1=0,sum2=0; - for(int i=1;i<=n;i++){ - cin>>a[i];mp[a[i]]++;sum1+=a[i]; - } - for(int i=1;i<=m;i++)cin>>b[i],sum2+=b[i]; - if(sum1!=sum2){ - cout<<""No""<int{ - if(mp[x]){ - mp[x]--;return 1; - } - if(!x)return 0; - if(x%2==0)return dfs(dfs,x/2)&&dfs(dfs,x/2); - else return dfs(dfs,x/2)&&dfs(dfs,x/2+1); - }; - int flag=1; - for(int i=m;i>=1;i--){ - if(mp[b[i]])mp[b[i]]--; - else{ - flag=dfs(dfs,b[i]); - if(!flag)break; - } - } - if(flag)cout<<""Yes""< -using namespace std; -#define int long long -#define YES cout<<""YES\n""; -#define NO cout<<""NO\n""; -#define endl ""\n"" -#define fi first -#define se second -#define pb push_back -#define pii pair -#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) -const int N=1e9+7; -const int N1=1e6+3; -signed main(){IOS; - int t;cin>>t; - while(t--){ - int n,m;cin>>n>>m;int a[n+1],b[m+1]; - mapmp;int sum1=0,sum2=0; - for(int i=1;i<=n;i++){ - cin>>a[i];mp[a[i]]++;sum1+=a[i]; - } - for(int i=1;i<=m;i++)cin>>b[i],sum2+=b[i]; - if(sum1!=sum2){ - cout<<""No""<int{ - if(mp[x]){ - mp[x]--;return 1; - } - if(!x)return 0; - if(x%2==0)return dfs(dfs,x/2)&&dfs(dfs,x/2); - else return dfs(dfs,x/2)&&dfs(dfs,x/2+1); - }; - int flag=1; - for(int i=m;i>=1;i--){ - if(mp[b[i]])mp[b[i]]--; - else{ - flag=dfs(dfs,b[i]); - } - } - if(flag)cout<<""Yes""< -#include -#include -void solve(){ - int n,m; - std::cin>>n>>m; - std::vector a(n),b(m); - for(int i=0;i>x; - a.push_back(x); - } - std::sort(a.rbegin(),a.rend()); //sort降序排列,从大到小 - for(int i=0;i>x; - b.push_back(x); - } - std::sort(b.rbegin(),b.rend()); //sort降序排列,从大到小 - long long sum=n-m; - while(sum>=0&&a.size()&&b.size()){ - if(a.front()==b.front()){ - a.pop_back(); //最大值相同 匹配则弹出,继续匹配 - b.pop_back(); - }else if(sum>0){ //需要操作 - int t=b.front(); - b.pop_back(); - b.push_back(t/2); - b.push_back(t-t/2); - ; - }else{ - break; - } - } - if(a.empty()&&b.empty()){ //都匹配且弹出 - std::cout<<""YES\n""; - }else{ - std::cout<<""NO\n""; - } -} -int main(){ - int t; - std::cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include -#include -#include -void solve() { - int n, m; - std::cin >> n >> m; - std::priority_queue a, b; - for (int i = 0; i < n; ++ i) { - int x; - std::cin >> x; - a.push(x); - } - - for (int i = 0; i < m; ++ i) { - int x; - std::cin >> x; - b.push(x); - } - - long long sum = n - m; - - while (sum >= 0 && a.size() && b.size()) { - if (a.top() == b.top()) { - a.pop(); - b.pop(); - } else if (sum > 0) { - int u = b.top(); b.pop(); - b.push(u / 2); - b.push(u - u / 2); - -- sum; - } else { - break; - } - } - - if (a.empty() && b.empty()) { - std::cout << ""YES\n""; - } else { - std::cout << ""NO\n""; - } -} -int main(){ - int t; - std::cin>>t; - while(t--){ - solve(); - } - return 0; -} -",2 -sittharalasirapadu,2061D - Kevin and Numbers,c++17 ,303479196,303477973,"#include -#include -using namespace std; -using ll = long long; -ll mod = 1e9+7; - -class TrieNode { -public: - bool isEnd; - TrieNode* nxt[26]; - TrieNode(bool b = false) { - isEnd = b; - memset(nxt, 0, sizeof(nxt)); - } -}; - -class Trie { - TrieNode* root; -public: - Trie() { - root = new TrieNode(); - } - void insert(string s) { - TrieNode* cur = root; - for (char c : s) { - if (cur->nxt[c - 'a'] == NULL) { - cur->nxt[c - 'a'] = new TrieNode(); - } - cur = cur->nxt[c - 'a']; - } - cur->isEnd = true; - } - bool search(string s) { - TrieNode* cur = root; - for (char c : s) { - if (!(cur->nxt[c - 'a'])) { - return false; - } - cur = cur->nxt[c - 'a']; - } - return cur->isEnd; - } - ll countCombs(string s, ll k, ll sz, unordered_map& dp) { - if (k == sz) { - return 1; - } - if (dp.find(k) != dp.end()) { - return dp[k]; - } - TrieNode* cur = root; - ll res = 0; - for (ll i = k; i < sz; i++) { - if (!(cur->nxt[s[i] - 'a'])) { - return res; - } - cur = cur->nxt[s[i] - 'a']; - if (cur->isEnd) { - res = (res + countCombs(s, i + 1, sz, dp)) % mod; - } - } - return dp[k] = res; - } -}; - - -vectorgiveLps(string s){ - int n=s.length(); - vectorlps(n,0); - int len=0; - for(int i=1;idq){ - while(dq.size()){ - cout<st){ - while(st.size()){ - cout<&vec){ - for(int u:vec){ - cout<&curr2 , vector&curr){ - vectorres; - int n=curr2.size(),m=curr.size(),i=0,j=0; - while(i; -void solver(){ - int n,m; - cin>>n>>m; - vectora,b; - ll sma=0,smb=0; - for(int i=0;i>x; - a.push_back(x); - sma+=x; - } - priority_queuepq; - for(int i=0;i>x; - pq.push(x); - smb+=x; - } - if(sma!=smb){ - cout<<""NO""<=0){ - int curr = pq.top(); - //cout<a[i] ){ - pq.push(curr/2); - pq.push(curr/2+curr%2); - }else{ - cout<<""NO""<>t; - //t=1; - for(int i=0;i -#include -using namespace std; -using ll = long long; -ll mod = 1e9+7; - -class TrieNode { -public: - bool isEnd; - TrieNode* nxt[26]; - TrieNode(bool b = false) { - isEnd = b; - memset(nxt, 0, sizeof(nxt)); - } -}; - -class Trie { - TrieNode* root; -public: - Trie() { - root = new TrieNode(); - } - void insert(string s) { - TrieNode* cur = root; - for (char c : s) { - if (cur->nxt[c - 'a'] == NULL) { - cur->nxt[c - 'a'] = new TrieNode(); - } - cur = cur->nxt[c - 'a']; - } - cur->isEnd = true; - } - bool search(string s) { - TrieNode* cur = root; - for (char c : s) { - if (!(cur->nxt[c - 'a'])) { - return false; - } - cur = cur->nxt[c - 'a']; - } - return cur->isEnd; - } - ll countCombs(string s, ll k, ll sz, unordered_map& dp) { - if (k == sz) { - return 1; - } - if (dp.find(k) != dp.end()) { - return dp[k]; - } - TrieNode* cur = root; - ll res = 0; - for (ll i = k; i < sz; i++) { - if (!(cur->nxt[s[i] - 'a'])) { - return res; - } - cur = cur->nxt[s[i] - 'a']; - if (cur->isEnd) { - res = (res + countCombs(s, i + 1, sz, dp)) % mod; - } - } - return dp[k] = res; - } -}; - - -vectorgiveLps(string s){ - int n=s.length(); - vectorlps(n,0); - int len=0; - for(int i=1;idq){ - while(dq.size()){ - cout<st){ - while(st.size()){ - cout<&vec){ - for(int u:vec){ - cout<&curr2 , vector&curr){ - vectorres; - int n=curr2.size(),m=curr.size(),i=0,j=0; - while(i; -void solver(){ - int n,m; - cin>>n>>m; - vectora,b; - ll sma=0,smb=0; - for(int i=0;i>x; - a.push_back(x); - sma+=x; - } - priority_queuepq; - for(int i=0;i>x; - pq.push(x); - smb+=x; - } - if(sma!=smb){ - cout<<""NO""<=0){ - int curr = pq.top(); - //cout<a[i] && abs(curr-2*a[i])<=1){ - pq.push(curr-a[i--]); - }else{ - cout<<""NO""<>t; - //t=1; - for(int i=0;i -using namespace std; - - -typedef long long ll; -typedef long double ld; -typedef complex cd; -typedef pair pii; -typedef pair pll; -typedef vector vi; -typedef vector vll; -typedef vector vpii; -typedef vector vpll; -typedef vector vs; -typedef unordered_map ull; - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -#define endl '\n' -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(), (x).end() -#define sz(x) ((int)(x).size()) -#define F first -#define S second -#define REP(i, a, b) for (int i = (a); i < (b); ++i) -#define REPR(i, a, b) for (int i = (a); i > (b); --i) -#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) -#define SORT(v) sort(all(v)) -#define RSORT(v) sort(all(v), greater()) -#define REVERSE(v) reverse(all(v)) -#define MAX(a, b) a = max(a, b) -#define MIN(a, b) a = min(a, b) -#define SQR(x) ((ll)(x) * (x)) -#define RESET(a, b) memset(a, b, sizeof(a)) -#define yes cout<<""YES""<<""\n"" -#define no cout<<""NO""<<""\n"" -#define input(a, n) for(int i = 0; i < n; i++) cin >> a[i] - -const int MOD = 1e9 + 7; -const int INF = 1e9; -const ll LLINF = 1e18; -const double PI = acos(-1.0); -const double EPS = 1e-9; - -#define DEBUG -#ifdef DEBUG -#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) -#define dbg(x) cerr << #x << "" = "" << x << endl -#endif - -template -void print(T t) { cout << t << ""\n""; } - -template -void print(T t, Args... args) { - cout << t << "" ""; - print(args...); -} - -template -void printVector(const vector& v) { - for (const T& x : v) cout << x << "" ""; - cout << ""\n""; -} - - -ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } -ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } -ll mod_add(ll a, ll b, ll m) { return (a % m + b % m) % m; } -ll mod_sub(ll a, ll b, ll m) { return (a % m - b % m + m) % m; } -ll mod_mul(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; } -ll mod_pow(ll b, ll p, ll m) { - ll r = 1; - while (p) { - if (p & 1) r = mod_mul(r, b, m); - b = mod_mul(b, b, m); - p >>= 1; - } - return r; -} - - -void solve() { - ll n,m; - cin>>n>>m; - vll a(n,0),b(m,0); - unordered_mapmpp1,mpp2; - REP(i,0,n) - { - cin>>a[i]; - mpp1[a[i]]++; - } - REP(j,0,m) - { - cin>>b[j]; - mpp2[b[j]]++; - } - multisets1,s2; - for(int i=0;i0) - { - mpp1[a[i]]--; - if(mpp1[a[i]]==0) mpp1.erase(a[i]); - s1.insert(a[i]); - } - } - } - // cout<0) - { - if(abs(v1[i]-sum)<=1) - { - sum+=v1[i]; - i++; - } - else - { - cout<<""No""<<""\n""; - return; - } - } - } - if(sum!=(v2[j])) - { - cout<<""No""<<""\n""; - return; - } - else - { - sum=0; - j++; - } - } - if(s2.size()==0 && s1.size()!=0) - { - cout<<""No""<<""\n""; - return; - } - cout<<""Yes""<<""\n""; - -} - -int main() { - fastio; - - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - - -typedef long long ll; -typedef long double ld; -typedef complex cd; -typedef pair pii; -typedef pair pll; -typedef vector vi; -typedef vector vll; -typedef vector vpii; -typedef vector vpll; -typedef vector vs; -typedef unordered_map ull; - -#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) -#define endl '\n' -#define pb push_back -#define mp make_pair -#define all(x) (x).begin(), (x).end() -#define sz(x) ((int)(x).size()) -#define F first -#define S second -#define REP(i, a, b) for (int i = (a); i < (b); ++i) -#define REPR(i, a, b) for (int i = (a); i > (b); --i) -#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) -#define SORT(v) sort(all(v)) -#define RSORT(v) sort(all(v), greater()) -#define REVERSE(v) reverse(all(v)) -#define MAX(a, b) a = max(a, b) -#define MIN(a, b) a = min(a, b) -#define SQR(x) ((ll)(x) * (x)) -#define RESET(a, b) memset(a, b, sizeof(a)) -#define yes cout<<""YES""<<""\n"" -#define no cout<<""NO""<<""\n"" -#define input(a, n) for(int i = 0; i < n; i++) cin >> a[i] - -const int MOD = 1e9 + 7; -const int INF = 1e9; -const ll LLINF = 1e18; -const double PI = acos(-1.0); -const double EPS = 1e-9; - -#define DEBUG -#ifdef DEBUG -#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) -#define dbg(x) cerr << #x << "" = "" << x << endl -#endif - -template -void print(T t) { cout << t << ""\n""; } - -template -void print(T t, Args... args) { - cout << t << "" ""; - print(args...); -} - -template -void printVector(const vector& v) { - for (const T& x : v) cout << x << "" ""; - cout << ""\n""; -} - - -ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } -ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } -ll mod_add(ll a, ll b, ll m) { return (a % m + b % m) % m; } -ll mod_sub(ll a, ll b, ll m) { return (a % m - b % m + m) % m; } -ll mod_mul(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; } -ll mod_pow(ll b, ll p, ll m) { - ll r = 1; - while (p) { - if (p & 1) r = mod_mul(r, b, m); - b = mod_mul(b, b, m); - p >>= 1; - } - return r; -} - - -void solve() { - ll n,m; - cin>>n>>m; - vll a(n,0),b(m,0); - multisets1,s2; - REP(i,0,n) - { - cin>>a[i]; - s1.insert(a[i]); - } - REP(j,0,m) - { - cin>>b[j]; - s2.insert(b[j]); - } - // multisets1,s2; - for(int i=0;i<=(n-m);i++) - { - while(!(s1.empty()) && !(s2.empty())) - { - ll num1=*(s1.rbegin()); - ll num2=*(s2.rbegin()); - if(num1==num2) - { - s1.erase(s1.find(num1)); - s2.erase(s2.find(num1)); - } - else break; - } - if(s1.empty() && s2.empty()) - { - yes; - return; - } - if(!s2.empty()) - { - ll last=*(s2.rbegin()); - s2.erase(s2.find(last)); - s2.insert(last/2); - s2.insert((last+1)/2); - } - } - if(s1.empty() && s2.empty()) - { - yes; - return; - } - else no; - -} - -int main() { - fastio; - - - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",2 -x3x3,2061D - Kevin and Numbers,python,316498092,316502254,"import sys - -import string - -import math - -import array - -import bisect - -from heapq import heappop,heappush - -from functools import lru_cache,cache - -from collections import deque,defaultdict,Counter - -from itertools import permutations,combinations - -#sys.setrecursionlimit(10**5) - -input = sys.stdin.readline - -printf = lambda x:sys.stdout.write(x) - - - -INF = 10**15 - - - -RI = lambda: int(sys.stdin.readline()) - -RF = lambda: float(sys.stdin.readline()) - -RS = lambda: sys.stdin.readline().strip() - -RFF = lambda: map(float, sys.stdin.readline().split()) - -RII = lambda: map(int, sys.stdin.readline().split()) - -RSS = lambda: map(str, sys.stdin.readline().strip().split()) - -RIL = lambda: list(RII()) - -RFL = lambda: list(RFF()) - -RSL = lambda: list(RSS()) - - - -# from types import GeneratorType - -# def bootstrap(f, stack=[]): - -# def wrappedfunc(*args, **kwargs): - -# if stack: - -# return f(*args, **kwargs) - -# else: - -# to = f(*args, **kwargs) - -# while True: - -# if type(to) is GeneratorType: - -# stack.append(to) - -# to = next(to) - -# else: - -# stack.pop() - -# if not stack: - -# break - -# to = stack[-1].send(to) - -# return to - - - -# return wrappedfunc - - - -def main(): - - test = RI() - - - - for i in range(test): - - n,m = RII() - - a = RIL() - - b = RIL() - - db = Counter([i for i in b]) - - a.sort() - - q = [] - - for i in a: - - #q.append(i) - - heappush(q,i) - - cnt = 0 - - while q and cnt=1 or (not q) or abs(x-q[0])>1: - - db[x] -= 1 - - continue - - y = 0 - - if q: - - y = heappop(q) - - else: - - break - - if db[x+y]>=1: - - db[x+y] -= 1 - - cnt += 1 - - continue - - else: - - heappush(q,x+y) - - cnt += 1 - - while q: - - x = heappop(q) - - db[x] -= 1 - - #print(db) - - flag = False - - for i,x in db.items(): - - if x!=0: - - flag = True - - break - - if flag==False: - - print('Yes') - - else: - - print('No') - - - - - - - -if __name__ == '__main__': - - main()","import sys - -import string - -import math - -import array - -import bisect - -from heapq import heappop,heappush - -from functools import lru_cache,cache - -from collections import deque,defaultdict,Counter - -from itertools import permutations,combinations - -#sys.setrecursionlimit(10**5) - -input = sys.stdin.readline - -printf = lambda x:sys.stdout.write(x) - - - -INF = 10**15 - - - -RI = lambda: int(sys.stdin.readline()) - -RF = lambda: float(sys.stdin.readline()) - -RS = lambda: sys.stdin.readline().strip() - -RFF = lambda: map(float, sys.stdin.readline().split()) - -RII = lambda: map(int, sys.stdin.readline().split()) - -RSS = lambda: map(str, sys.stdin.readline().strip().split()) - -RIL = lambda: list(RII()) - -RFL = lambda: list(RFF()) - -RSL = lambda: list(RSS()) - - - -from types import GeneratorType - -def bootstrap(f, stack=[]): - - def wrappedfunc(*args, **kwargs): - - if stack: - - return f(*args, **kwargs) - - else: - - to = f(*args, **kwargs) - - while True: - - if type(to) is GeneratorType: - - stack.append(to) - - to = next(to) - - else: - - stack.pop() - - if not stack: - - break - - to = stack[-1].send(to) - - return to - - - - return wrappedfunc - - - -def main(): - - test = RI() - - - - for i in range(test): - - n,m = RII() - - a = RIL() - - b = RIL() - - #db = Counter(b) - - #a.sort() - - da = Counter([str(i) for i in a]) - - - - # @bootstrap - - # def dp(i): - - # if i==1: - - # da[i] -= 1 - - # yield None - - # if da[i]>=1: - - # da[i] -= 1 - - # yield None - - # x = i//2 - - # y = x+i%2 - - # yield dp(x) - - # yield dp(y) - - # yield None - - cnt = 0 - - @bootstrap - - def dp(i): - - nonlocal cnt - - if cnt>=n: - - da[str(0)] -= 1 - - yield None - - if i==1: - - da[str(i)] -= 1 - - cnt += 1 - - yield None - - if da[str(i)]>=1: - - da[str(i)] -= 1 - - cnt += 1 - - yield None - - x = i//2 - - y = x+i%2 - - yield dp(x) - - yield dp(y) - - yield None - - - - for i in b: - - dp(i) - - #print(da) - - flag = True - - for x in da.values(): - - if x!=0: - - flag = False - - break - - - - if flag==True: - - print('Yes') - - else: - - print('No') - - - - - -if __name__ == '__main__': - - main()",2 -alizarin_,2061D - Kevin and Numbers,c++20 ,302566204,302565778,"#include ""bits/stdc++.h"" -using namespace std; -#define ll long long -#define ld long double -#define pii pair -#define M 1000000007 -#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -int main() { - IOS; - ll t; - cin>>t; - - while(t--){ - ll n,m; - cin>>n>>m; - - map a; - - for(ll i =0;i>k; - - a[k]++; - } - - map b; - - for(ll i =0;i>k; - - b[k]++; - } - - ll ct = 0; - - bool k = 0; - - while(b.size() && ct<=n-m){ - auto it = b.rbegin(); - - ll x = it->first; - if(b[x]a[x]){ - if(x == 1){ - k = 1; - cout<<""No\n""; - break; - } - b[x]--; - b[x/2]++; - b[(x+1)/2]++; - ct++; - } - else{ - b[x] = 0; - a[x] = 0; - a.erase(x); - b.erase(x); - } - } - - if(k == 0 && (a.size() || b.size())) cout<<""No\n""; - else if(k == 0) cout<<""Yes\n""; - - - } -} -","#include ""bits/stdc++.h"" -using namespace std; -#define ll long long -#define ld long double -#define pii pair -#define M 1000000007 -#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -int main() { - IOS; - ll t; - cin>>t; - - while(t--){ - ll n,m; - cin>>n>>m; - - map a; - - for(ll i =0;i>k; - - a[k]++; - } - - map b; - - for(ll i =0;i>k; - - b[k]++; - } - - ll ct = 0; - - while(b.size() && ct<=n-m){ - auto it = b.rbegin(); - - ll x = it->first; - if(b[x]a[x]){ - if(x == 1){ - cout<<""No\n""; - break; - } - b[x]--; - b[x/2]++; - b[(x+1)/2]++; - ct++; - } - else{ - b[x] = 0; - a[x] = 0; - a.erase(x); - b.erase(x); - } - } - - if(a.size() || b.size()) cout<<""No\n""; - else cout<<""Yes\n""; - - - } -} -",1 -HYMonkey,2061D - Kevin and Numbers,c++23 ,302714203,302708737,"// #define ONLINE_JUDGE 1 -// clang-format off -#include -using namespace std; -using ll = long long; using ull = unsigned long long; using pll = pair; -#define all(a) (a).begin(),(a).end() -#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) -const ll N = 2e6 + 10; -#ifdef LOCAL -#include -#else -#define dbg(...) (__VA_ARGS__) -#endif -template void input(T &...a) { (cin >> ... >> a); } -template bool chmax(T &a, const U b) {return a bool chmin(T &a, const U b) {return a>b?a=b,true:false; } -// clang-format on - -void solve() -{ - LL(n, m); - dbg(n, m); - map mp; - for (ll i = 0; i < n; i++) - { - LL(x); - mp[x]++; - } - ll cnt = 0; - priority_queue qu; - for (ll i = 0; i < m; i++) - { - LL(x); - qu.push(x); - } - while (!qu.empty() && cnt < n) - { - if((ll)qu.size() > n-cnt)return void(cout << ""No\n""); - ll x = qu.top(); - qu.pop(); - if (mp[x]) - { - mp[x]--; - cnt++; - } - else - { - if(x == 1)return void(cout << ""No\n""); - qu.push(x / 2); - qu.push((x + 1) / 2); - } - } - cout << (cnt == n ? ""Yes\n"" : ""No\n""); -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - ll T = 1; - cin >> T; - while (T--) solve(); - return 0; -}","// #define ONLINE_JUDGE 1 -// clang-format off -#include -using namespace std; -using ll = long long; using ull = unsigned long long; using pll = pair; -#define all(a) (a).begin(),(a).end() -#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) -const ll N = 2e6 + 10; -#ifdef LOCAL -#include -#else -#define dbg(...) (__VA_ARGS__) -#endif -template void input(T &...a) { (cin >> ... >> a); } -template bool chmax(T &a, const U b) {return a bool chmin(T &a, const U b) {return a>b?a=b,true:false; } -// clang-format on - -void solve() -{ - LL(n, m); - map mp; - for (ll i = 0; i < n; i++) - { - LL(x); - mp[x]++; - } - ll cnt = 0; - function dfs = [&](ll x) -> ll - { - dbg(x); - if (mp[x]) return mp[x]--, cnt++, 0; - if (cnt >= n || x == 1) return 1; - if (dfs(x / 2)) return 1; - return dfs((x + 1) / 2); - }; - for (ll i = 1; i <= m; i++) - { - LL(x); - if (dfs(x)) return cout << ""No\n"", void(); - } - cout << (cnt == n ? ""Yes\n"" : ""No\n""); -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - ll T = 1; - cin >> T; - while (T--) solve(); - return 0; -}",1 -Vedant2379,2061D - Kevin and Numbers,c++17 ,303641446,303465205,"#include -using namespace std; -#define ll long long -const ll N=1e4+5; - -int main(){ - ll T; - cin>>T; - while(T--){ - ll n; - cin>>n; - ll m; - cin>>m; - ll a[n],b[m]; - map ma,mb; - queue q; - for(ll i=0;i>a[i]; - ma[a[i]]=0; - mb[a[i]]=0; - } - for(ll i=0;i>b[i]; - ma[b[i]]=0; - } - sort(a,a+n); - sort(b,b+m); - for(ll i=0;i0) ma[a[i]]--; - else{ - mb[a[i]]++; - count++; - mini=min(mini,a[i]); - } - } - for(auto z:ma){ - if(z.second>0){ - for(ll i=0;icount){ - flag=1; - break; - } - for(ll i=0;i0){ - mb[c]--; - count--; - } - else{ - q.push(c); - mini1=min(mini1,c); - } - if(mb[d]>0){ - mb[d]--; - count--; - } - else{ - q.push(d); - mini1=min(mini1,d); - } - } - if(mini10) cout<<""No""< -using namespace std; -#define ll long long -const ll N=1e4+5; - -int main(){ - ll T; - cin>>T; - ll c=0; - while(T--){ - ll n; - cin>>n; - ll m; - cin>>m; - ll a[n],b[m]; - map ma; - for(ll i=0;i>a[i]; - ma[a[i]]=0; - } - for(ll i=0;i>b[i]; - ma[b[i]]=0; - } - sort(a,a+n); - sort(b,b+m); - for(ll i=0;i,greater> pq; - ll flag=0; - for(ll i=0;i0) ma[a[i]]--; - else pq.push(a[i]); - } - ll sz=pq.size(); - while(sz>1){ - ll x=pq.top(); - pq.pop(); - sz--; - if(ma[x]>0) ma[x]--; - else{ - ll y=pq.top(); - pq.pop(); - if(abs(x-y)>1){ - flag=1; - break; - } - pq.push(x+y); - } - } - if(sz>0){ - ll pp=pq.top(); - if(ma[pp]>0){ - ma[pp]--; - pq.pop(); - sz--; - } - } - for(auto z:ma){ - if(z.second>0) flag=1; - } - if(sz>0) flag=1; - if(flag==1) cout<<""NO""< -using namespace std; -#define f first -#define s second -#define pb push_back -#define pob pop_back -#define b back -#define cout(x) cout << x << endl -#define lb long double -#define soa(arr, n) sort(arr,arr+n) -#define inputVector(v, n) for(ll i = 0; i < n; i++) cin >> v[i] -#define sov(v) sort(v.begin(), v.end()) -#define rev(v) reverse(v.begin(), v.end()) -#define pl pair -#define all(a) a.begin(), a.end() -#define vpp vector> -#define fastIo ios_base::sync_with_stdio(false), cin.tie(0) -#define endl '\n' -#define No cout << ""NO\n""; -#define Yes cout << ""YES\n""; -typedef long long int ll; - -const ll mod = 998244353; - - -void solve(ll n, ll m, vector & a, vector & b) { - ll sa = 0; - for(auto it: a) { - sa += it; - } - - for(auto it: b) { - sa -= it; - } - - if(sa != 0) { - cout << ""No\n""; - return; - } - - multiset aa, bb; - - for(auto it: a) { - aa.insert(it); - } - - for(auto it: b) { - if(aa.find(it) != aa.end()) { - aa.erase(aa.find(it)); - } else { - bb.insert(it); - } - } - - // for(auto it: aa) { - // cout << it << "" ""; - // } - // cout << endl; - - // for(auto it: bb) { - // cout << it << "" ""; - // } - - // cout << endl; - - // from aa now from bb. - - while(!bb.empty() && !aa.empty()) { - - auto it = * bb.begin(); - bb.erase(bb.find(it)); - if(aa.find(it) != aa.end()) { - aa.erase(aa.find(it)); - continue; - } - - if(it > 1) { - int x = it/2; - int y = it - x; - - bb.insert(x); - bb.insert(y); - } else { - break; - } - } - - - // for(auto it: aa) { - // cout << it << "" ""; - // } - // cout << endl; - - // for(auto it: bb) { - // cout << it << "" ""; - // } - - // cout << endl; - - - if(aa.empty() && bb.empty()) { - cout << ""Yes\n""; - return; - } - - if(aa.size() == 1 && bb.size() == 1 && (*aa.begin()) == (*bb.begin())) { - cout << ""Yes\n""; - return; - } - - cout << ""No\n""; -} - - - int main() { - ll t=1,i=1, n, m; - - cin >> t; - - - while(t --) { - ll n, m; - cin >> n >> m; - vector a(n), bb(m); - for(ll i = 0; i < n; i ++) { - cin >> a[i]; - } - - for(ll i = 0; i < m; i ++) { - cin >> bb[i]; - } - solve(n, m, a, bb); - - } -} - -// 2 2 3 3 5 -// 6 9 - -// k = a + b + ","#include -using namespace std; -#define f first -#define s second -#define pb push_back -#define pob pop_back -#define b back -#define cout(x) cout << x << endl -#define lb long double -#define soa(arr, n) sort(arr,arr+n) -#define inputVector(v, n) for(ll i = 0; i < n; i++) cin >> v[i] -#define sov(v) sort(v.begin(), v.end()) -#define rev(v) reverse(v.begin(), v.end()) -#define pl pair -#define all(a) a.begin(), a.end() -#define vpp vector> -#define fastIo ios_base::sync_with_stdio(false), cin.tie(0) -#define endl '\n' -#define No cout << ""NO\n""; -#define Yes cout << ""YES\n""; -typedef long long int ll; - -const ll mod = 998244353; - - -void solve(ll n, ll m, vector & a, vector & b) { - ll sa = 0; - for(auto it: a) { - sa += it; - } - - for(auto it: b) { - sa -= it; - } - - if(sa != 0) { - cout << ""No\n""; - return; - } - - multiset aa, bb; - - for(auto it: a) { - aa.insert(it); - } - - for(auto it: b) { - if(aa.find(it) != aa.end()) { - aa.erase(aa.find(it)); - } else { - bb.insert(it); - } - } - - // from aa now from bb. - - while(aa.size() >= 2) { - - auto it = aa.begin(); - auto it1 = aa.begin(); - it1 ++; - auto itf = * it; - auto its = * it1; - - - if(bb.find(itf) != bb.end()) { - aa.erase(it); - bb.erase(bb.find(itf)); - continue; - } - - if(its - itf <= 1) { - aa.erase(it); - aa.erase(it1); - - if(bb.find(itf + its) != bb.end()) { - bb.erase(bb.find(itf + its)); - } else { - aa.insert(itf + its); - } - } else { - break; - } - - - } - - if(aa.empty() && bb.empty()) { - cout << ""Yes\n""; - return; - } - - if(aa.size() == 1 && bb.size() == 1 && (*aa.begin()) == (*bb.begin())) { - cout << ""Yes\n""; - return; - } - - cout << ""No\n""; -} - - - int main() { - ll t=1,i=1, n, m; - - cin >> t; - - - while(t --) { - ll n, m; - cin >> n >> m; - vector a(n), bb(m); - for(ll i = 0; i < n; i ++) { - cin >> a[i]; - } - - for(ll i = 0; i < m; i ++) { - cin >> bb[i]; - } - solve(n, m, a, bb); - - } -}",1 -OUYU_NOW,2061D - Kevin and Numbers,c++20 ,306816253,306816310,"#include -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) -#define endl '\n' -#define int long long -#define PII pair -#define _rep(i,a,b) for( int i=(a); i<=(b); ++i) -#define _per(i,a,b) for( int i=(a); i>=(b); --i) -using namespace std; -const int N = 1e6+10 ; -const int M = 1e3+10 ; -const int INF = 0x3f3f3f3f3f3f3f3f; -const int MOD = 1e9 + 7 ; -const double eps = 1e-9 ; -int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } -int lcm(int a, int b){ return a * b / gcd(a,b); } -int qmi(int a, int b){ - int res = 1 ; - while(b){ - if(b&1) res = a * res % MOD ; - b >>= 1 ; - a = a * a % MOD ; - } - return res ; -} -int T = 1 ; -int ans = 0 ; -int n , m, k, q ; -int a[N], b[N] ; -map mp ; -void dfs(int x){ - if(mp[x]){ - mp[x] -- ; - - }else if(x!=1){ - int a = x + 1 >> 1 ; - int b = x >> 1 ; - dfs(a) ; - dfs(b) ; - } -} -void solve(){ - mp.clear() ; - cin >> n >> m ; - int sum = 0 ; - for(int i = 1; i <= n ; ++ i){ - cin >> a[i] ; - sum += a[i] ; - mp[a[i]] ++ ; - } - for(int i = 1; i <= m ; ++ i){ - cin >> b[i] ; - sum -= b[i] ; - } - sort(a + 1, a + 1 + n) ; - sort(b + 1, b + 1 + m) ; - if(sum != 0 || a[1] > b[1] || b[m] < a[n]){ - cout << ""No"" << endl ; - return ; - } - for(int i = 1; i <= m ; ++ i){ - dfs(b[i]) ; - } - for(auto e: mp){ - if(e.second != 0){ - cout << ""No"" << endl ; - return ; - } - } - cout << ""Yes"" << endl ; - - -} -signed main(){ - IOS ; - cin >> T ; - while(T --){ - solve() ; - } - return 0; - -}","#include -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) -#define endl '\n' -#define int long long -#define PII pair -#define _rep(i,a,b) for( int i=(a); i<=(b); ++i) -#define _per(i,a,b) for( int i=(a); i>=(b); --i) -using namespace std; -const int N = 1e6+10 ; -const int M = 1e3+10 ; -const int INF = 0x3f3f3f3f3f3f3f3f; -const int MOD = 1e9 + 7 ; -const double eps = 1e-9 ; -int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } -int lcm(int a, int b){ return a * b / gcd(a,b); } -int qmi(int a, int b){ - int res = 1 ; - while(b){ - if(b&1) res = a * res % MOD ; - b >>= 1 ; - a = a * a % MOD ; - } - return res ; -} -int T = 1 ; -int ans = 0 ; -int n , m, k, q ; -int a[N], b[N] ; -map mp ; -void dfs(int x){ - if(mp[x]){ - mp[x] -- ; - - }else if(x /2 >= a[1]){ - int a = x + 1 >> 1 ; - int b = x >> 1 ; - dfs(a) ; - dfs(b) ; - } -} -void solve(){ - mp.clear() ; - cin >> n >> m ; - int sum = 0 ; - for(int i = 1; i <= n ; ++ i){ - cin >> a[i] ; - sum += a[i] ; - mp[a[i]] ++ ; - } - for(int i = 1; i <= m ; ++ i){ - cin >> b[i] ; - sum -= b[i] ; - } - sort(a + 1, a + 1 + n) ; - sort(b + 1, b + 1 + m) ; - if(sum != 0 || a[1] > b[1] || b[m] < a[n]){ - cout << ""No"" << endl ; - return ; - } - for(int i = 1; i <= m ; ++ i){ - dfs(b[i]) ; - } - for(auto e: mp){ - if(e.second != 0){ - cout << ""No"" << endl ; - return ; - } - } - cout << ""Yes"" << endl ; - - -} -signed main(){ - IOS ; - cin >> T ; - while(T --){ - solve() ; - } - return 0; - -}",2 -XED_STARRY_SKY,2061D - Kevin and Numbers,c++23 ,303873247,303873380,"#include -using namespace std; -#define int long long -typedef long long ll; - - -#pragma GCC optimize(2) -#define debug(a) cout<<#a<<'='<a;i--) -#define perr(i,b,a) for(int i=b;i>=a;i--) -#define pii pair -#define mm memset -#define endl '\n' -#define ff first -#define ss second -#define pb push_back -#define INF 0x7fffffffffffffff - -const double eps =1e-8; -const int mod=998244353; -const int N=2e5+2; - -int a[N]; -int b[N]; - -bool dfs(int x,unordered_map&h) -{ - if(x==1) - { - if(!h[1])return false; - h[1]--;return true; - } - if(h[x]) - { - h[x]--; - return true; - } - else - { - if(x%2) - { - if(!dfs(x/2+1,h)) - return false ; - if(!dfs(x/2,h)) - return false; - } - else - { - if(!dfs(x/2,h)) - return false; - if(!dfs(x/2,h)) - return false; - } - } - return true; -} -void fun(){ - int n,m; - cin>>n>>m; - ll sa=0,sb=0; - unordered_maph1,h2; - repp(i,1,n)cin>>a[i],sa+=a[i],h1[a[i]]++; - repp(i,1,m)cin>>b[i],sb+=b[i],h2[b[i]]++; - if(sa!=sb) - { - cout<<""No""<>t; - - while(t--){ - fun(); - } - - - -} -","#include -using namespace std; -#define int long long -typedef long long ll; - - -#pragma GCC optimize(2) -#define debug(a) cout<<#a<<'='<a;i--) -#define perr(i,b,a) for(int i=b;i>=a;i--) -#define pii pair -#define mm memset -#define endl '\n' -#define ff first -#define ss second -#define pb push_back -#define INF 0x7fffffffffffffff - -const double eps =1e-8; -const int mod=998244353; -const int N=2e5+2; - -int a[N]; -int b[N]; - -bool dfs(int x,map&h) -{ - if(x==1) - { - if(!h[1])return false; - h[1]--;return true; - } - if(h[x]) - { - h[x]--; - return true; - } - else - { - if(x%2) - { - if(!dfs(x/2+1,h)) - return false ; - if(!dfs(x/2,h)) - return false; - } - else - { - if(!dfs(x/2,h)) - return false; - if(!dfs(x/2,h)) - return false; - } - } - return true; -} -void fun(){ - int n,m; - cin>>n>>m; - ll sa=0,sb=0; - maph1,h2; - repp(i,1,n)cin>>a[i],sa+=a[i],h1[a[i]]++; - repp(i,1,m)cin>>b[i],sb+=b[i],h2[b[i]]++; - if(sa!=sb) - { - cout<<""No""<>t; - - while(t--){ - fun(); - } - - - -} -",2 -Lunaroa,2061D - Kevin and Numbers,c++17 ,314311076,314311120,"#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -#define int long long - -const int MAXN=1000010,inf=0x3f3f3f3f; - - - -int n,m; - -int a[MAXN],b[MAXN]; - -mapmp; - -int check(int x){ - - if (mp[x]){ - - mp[x]--; - - return 1; - - } - - if (x==0)return 0; - - if (x&1)return check(x/2)&&check((x+1)/2); - - return check(x/2)&&check(x/2); - -} - -void solve(){ - - cin>>n>>m; - - - - int sum=0; - - for (int i=1;i<=n;i++)cin>>a[i],mp[a[i]]++,sum+=a[i]; - - for (int i=1;i<=m;i++){ - - cin>>b[i]; - - sum-=b[i]; - - } - - if (sum!=0){ - - cout<<""No""<>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} - -","#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -#define int long long - -const int MAXN=1000010,inf=0x3f3f3f3f; - - - -int n,m; - -int a[MAXN],b[MAXN]; - -mapmp; - -int check(int x){ - - if (mp[x]){ - - mp[x]--; - - return 1; - - } - - if (x==0)return 0; - - if (x&1)return check(x/2)&&check(x/2+1); - - return (check(x/2)&&check(x/2)); - -} - -void solve(){ - - cin>>n>>m; - - mp.clear(); - - int sum=0; - - for (int i=1;i<=n;i++)cin>>a[i],mp[a[i]]++,sum+=a[i]; - - for (int i=1;i<=m;i++){ - - cin>>b[i]; - - sum-=b[i]; - - } - - if (sum!=0){ - - cout<<""No""<>t; - - while(t--) - - { - - solve(); - - } - - return 0; - -} - -",2 -Acid12,2061D - Kevin and Numbers,c++20 ,307329418,307383767,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define py cout << ""YES"" << endl -#define pn cout << ""NO"" << endl -#define ll long long -#define forw(i, j, n) for (ll i = j; i < n; i++) -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define pb push_back -#define ppb pop_back -#define all(x) x.begin(), x.end() -bool fun(ll x,unordered_map&mp1,unordered_map&mp2){ - if(x<=0)return false; - if(mp2.count(x) && mp2[x]==false)return mp2[x]; - bool ans=true; - if(mp1[x]>0){ - mp1[x]--; - return true; - } - ll l,r; - if(x%2){ - l=x/2; - r=l+1; - } - else{ - l=x/2; - r=x/2; - } - if(l==1){ - if(mp1[1]>0){ - mp1[1]--; - } - else ans=false; - - } - else if(l==0){ans=false;} - - else ans&=fun(l,mp1,mp2); - if(r==1){ - if(mp1[1]>0){ - mp1[1]--; - } - else ans=false; - } - else if(r==0){ans=false;} - - - else ans&=fun(r,mp1,mp2); - mp2[x]=ans; - return ans; -} -int main() { - int t; cin>>t; - while(t--){ - ll n,m; cin>>n>>m; - vector a(n),b(m); - unordered_mapmp1; - unordered_mapmp2; - forw(i,0,n){ - cin>>a[i]; - mp1[a[i]]++; - } - forw(i,0,m){ - cin>>b[i]; - - } - bool ans=true; - forw(i,0,m){ - ans&=fun(b[i],mp1,mp2); - if(ans==false)break; - } - for(auto it:mp1){ - if(it.second>0){ans=false; break;} - } - - - - if(ans)py; - else pn; - } - return 0; -} -// 1 1 1 1 1 2 2 2 2 2 3 3 3 3","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define py cout << ""YES"" << endl -#define pn cout << ""NO"" << endl -#define ll long long -#define forw(i, j, n) for (ll i = j; i < n; i++) -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -#define pb push_back -#define ppb pop_back -#define all(x) x.begin(), x.end() - -int main() { - int t; cin>>t; - forw(k,0,t){ - ll n,m; cin>>n>>m; - vector a(n),b(m); - multisetmp1,mp2; - forw(i,0,n){ - cin>>a[i]; - mp1.insert(a[i]); - } - forw(i,0,m){ - cin>>b[i]; - mp2.insert(b[i]); - } - - bool ans=true; - - while(!mp1.empty() && !mp2.empty() && mp1.size()>=mp2.size()){ - ll x=*--mp2.end(); - //ll x1=*--mp2.end(); - //cout< -#define int long long -#define F first -#define S second -#define pb push_back -#define endl ""\n"" -const int mod = 1e9 + 7; -const int N = 300000 + 10; -using namespace std; -typedef pair pi; -int n, m, k; -int a[N], b[N]; -char c[4][4]; -int gcd(int A, int b) { - return b ? gcd(b, A % b) : A; -} -string s, s1, s2; -mapmp; -int qsm(int a, int b) {//a/b%mod,快速幂,费马小定理 - int ans = 1; - while (b) { - if (b & 1) ans = ans * a % mod; - a = a * a % mod; - b >>= 1; - } return ans; -}int x, y; -priority_queue, greater>q; -bool cmp(int x, int y) { - return x < y; -} -struct pai{ - int x, y; -}d[N]; -void solve() { - cin >> n >> m; - int maxx = -1; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - } - while (!q.empty()) { - q.pop(); - } - for (int i = 1; i <= m; i++) { - int u; - cin >> u; - q.push(u); - } - mp.clear(); - for (int i = 1; i <= n; i++) { - if (mp.find(a[i]) != mp.end()) { - mp[a[i]]++; - } - else { - mp[a[i]] = 1; - } - } - while (!q.empty()) { - int u = q.top(); - q.pop(); - if (mp[u] > 0) { - mp[u]--; - } - else { - if (u == 1) { - cout << ""No"" << endl; - return; - } - else { - if (u % 2 == 1) { - q.push(u / 2); - q.push(u / 2 + 1); - } - else { - q.push(u / 2); - q.push(u / 2); - } - } - } - } - for (auto i : mp) { - if (i.second > 0) { - cout << ""No"" << endl; - return; - } - } - cout << ""Yes"" << endl; -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cout << fixed << setprecision(12); // 小数保留位数 - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -#define int long long -#define F first -#define S second -#define pb push_back -#define endl ""\n"" -const int mod = 1e9 + 7; -const int N = 300000 + 10; -using namespace std; -typedef pair pi; -int n, m, k; -int a[N], b[N]; -char c[4][4]; -int gcd(int A, int b) { - return b ? gcd(b, A % b) : A; -} -string s, s1, s2; -mapmp; -int qsm(int a, int b) {//a/b%mod,快速幂,费马小定理 - int ans = 1; - while (b) { - if (b & 1) ans = ans * a % mod; - a = a * a % mod; - b >>= 1; - } return ans; -}int x, y; -priority_queueq;//优先队列默认,大顶堆 -bool cmp(int x, int y) { - return x < y; -} -struct pai{ - int x, y; -}d[N]; -void solve() { - cin >> n >> m; - if (m ==1&&n==1) { - int aaa, bbb; - cin >> aaa >> bbb; - if (aaa == bbb) { - cout << ""Yes"" << endl; - } - else { - cout << ""No"" << endl; - } - return; - } - int maxx = -1; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - } - while (!q.empty()) { - q.pop(); - } - for (int i = 1; i <= m; i++) { - int u; - cin >> u; - q.push(u); - } - mp.clear(); - for (int i = 1; i <= n; i++) { - if (mp.find(a[i]) != mp.end()) { - mp[a[i]]++; - } - else { - mp[a[i]] = 1; - } - } - while (!q.empty()) { - int u = q.top(); - q.pop(); - if (mp[u] > 0) { - mp[u]--; - } - else { - if (u == 1) { - cout << ""No"" << endl; - return; - } - else { - if (u % 2 == 1) { - q.push(u / 2); - q.push(u / 2 + 1); - } - else { - q.push(u / 2); - q.push(u / 2); - } - } - } - } - for (auto i : mp) { - if (i.second > 0) { - cout << ""No"" << endl; - return; - } - } - cout << ""Yes"" << endl; -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cout << fixed << setprecision(12); // 小数保留位数 - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -ExoticLur3e37,2061D - Kevin and Numbers,c++17 ,303481843,303479745,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define ll long long -#define floop(i, a, b) for (int i = (a); i < (b); i++) -#define vi vector -#define vvi vector> -#define vpii vector> -#define pii pair -#define all(x) (x).begin(), (x).end() -const ll inf = 1e16; -const int mod = 1e9 + 7; -const int N = 1e6; -ll i = 0, j = 0; -ll n, m; - -bool solve(priority_queue &bb, map &a) -{ - for (int i = 0; i < (2 * n - m); i++) - { - if (bb.empty()) - { - return false; - } - ll num = bb.top(); - bb.pop(); - - if (a[num] == 0) - { - bb.push(num / 2); - bb.push((num + 1) / 2); - } - else - { - a[num]--; - } - } - if (bb.empty()) - return true; - return false; -} -void ExoticLur3e37() -{ - ll p; - cin >> n >> m; - map a; - for (i = 0; i < n; i++) - { - cin >> p; - a[p]++; - } - vector b(m); - // vector vis(m, 0); - priority_queue bb; - for (i = 0; i < m; i++){ - cin >> b[i]; - bb.push(b[i]); - } - - // for (int i = 0; i < m; i++) - // { - // int num = b[i]; - // if (a[num] > 0) - // { - // a[num]--; - // if (a[num] == 0) - // a.erase(num); - // vis[i] = 1; - // } - // } - - // for (int i = 0; i < m; i++) - // { - // if (!vis[i]) - // bb.push(b[i]); - // } - - bool res = solve(bb, a); - - res?cout<<""YES"":cout<<""NO""; -} -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - cin >> t; - // t = 1; - while (t--) - { - ExoticLur3e37(); - cout << ""\n""; - } -}","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define ll long long -#define floop(i, a, b) for (int i = (a); i < (b); i++) -#define vi vector -#define vvi vector> -#define vpii vector> -#define pii pair -#define all(x) (x).begin(), (x).end() -const ll inf = 1e16; -const int mod = 1e9 + 7; -const int N = 1e6; -ll i = 0, j = 0; -ll n, m; -void ExoticLur3e37() -{ - ll n, m, p; - cin >> n >> m; - map a; - for (i = 0; i < n; i++) - { - cin >> p; - a[p]++; - } - vector b(m); - vector vis(m, 0); - for (i = 0; i < m; i++) - cin >> b[i]; - - for (int i = 0; i < m; i++) - { - int num = b[i]; - if (a[num] > 0) - { - a[num]--; - vis[i] = 1; - } - } - - priority_queue, greater> aa; - for (auto c : a) - { - if (c.second > 0) - { - int freq = c.second; - while (freq--) - { - aa.push(c.first); - } - } - } - vector bb; - for (int i = 0; i < m; i++) - { - if (!vis[i]) - bb.push_back(b[i]); - } - - if (bb.size() == 0 && aa.size() != 0) - { - cout << ""NO""; - return; - } - - if (bb.size() == 1 && aa.size() == 1) - { - bb[0] == aa.top() ? cout << ""YES"" : cout << ""NO""; - return; - } - - sort(all(bb)); - - i = 0, j = 0; - - while (aa.size() > 1 && j < bb.size()) - { - ll x = aa.top(); - aa.pop(); - ll y = aa.top(); - aa.pop(); - if (abs(x - y) <= 1 && (x + y) == bb[j]) - j++; - else if (abs(x - y) <= 1) - { - aa.push(x + y); - } - else - { - cout << ""NO""; - return; - } - } - if (aa.size() == 1 && j == bb.size() - 1) - { - bb[j] == aa.top() ? cout << ""YES"" : cout << ""NO""; - return; - } - if (j == bb.size()) - cout << ""YES""; - else - cout << ""NO""; -} -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - ll t; - cin >> t; - // t = 1; - while (t--) - { - ExoticLur3e37(); - cout << ""\n""; - } -}",1 -Manstein_Zhukov,2061D - Kevin and Numbers,c++17 ,302713431,302714631,"#include -#include -#include -#include -#define ll long long -#define N 200005 -using namespace std; -ll i,j,k,m,n,o,p,l,s,t,sum1,sum2,ans,times,bz; -multiset f,g; -ll a[N],b[N]; -int main() -{ - freopen(""a.in"",""r"",stdin); - freopen(""a.out"",""w"",stdout); - scanf(""%lld"",×); - while (times--) - { - scanf(""%lld%lld"",&n,&m); - if (n==4&m==2) - { - int sdfgwse=0; - } - f.clear(),g.clear(); - sum1=sum2=0; - for (i=1;i<=n;i++) scanf(""%lld"",&a[i]),sum1+=a[i],f.insert(a[i]); - for (i=1;i<=m;i++) scanf(""%lld"",&b[i]),sum2+=b[i],g.insert(b[i]); - if (sum1!=sum2) - { - puts(""No""); - continue; - } - bz=1; - while ((!f.empty())||(!g.empty())) - { - ll x=*f.rbegin(),y=*g.rbegin(); - auto posx=f.find(x),posy=g.find(y); - if (x==y) - { - f.erase(posx),g.erase(posy); - } - else if (x>y) - { - bz=0;puts(""No"");break; - } else { - g.erase(posy); - g.insert(y/2),g.insert((y+1)/2); - } - } - if (bz) puts(""Yes""); - else puts(""No""); - } - return 0; -}","#include -#include -#include -#include -#define ll long long -#define N 200005 -using namespace std; -ll i,j,k,m,n,o,p,l,s,t,sum1,sum2,ans,times,bz; -multiset f,g; -ll a[N],b[N]; -int main() -{ - // freopen(""a.in"",""r"",stdin); - // freopen(""a.out"",""w"",stdout); - scanf(""%lld"",×); - while (times--) - { - scanf(""%lld%lld"",&n,&m); - bz=1; - f.clear(),g.clear(); - sum1=sum2=0; - for (i=1;i<=n;i++) scanf(""%lld"",&a[i]),sum1+=a[i],f.insert(a[i]); - for (i=1;i<=m;i++) scanf(""%lld"",&b[i]),sum2+=b[i],g.insert(b[i]); - if (sum1!=sum2) - { - puts(""No""); - continue; - } - while ((!f.empty())||(!g.empty())) - { - ll x=*f.rbegin(),y=*g.rbegin(); - auto posx=f.find(x),posy=g.find(y); - if (x==y) - { - f.erase(posx),g.erase(posy); - } - else if (x>y) - { - bz=0;break; - } else { - g.erase(posy); - g.insert(y/2),g.insert((y+1)/2); - } - } - if (bz) puts(""Yes""); - else puts(""No""); - } - return 0; -}",2 -Mohak_25,2061D - Kevin and Numbers,c++17 ,302347224,302343677,"#include -using namespace std; - -#define int long long -#define nl -#define imin INT_MIN -#define imax INT_MAX -#define lmin LLONG_MIN -#define lmax LLONG_MAX -int solve(int x,map &m){ - if(m.find(x)!=m.end()){ - m[x]--; - if(m[x]==0){ - m.erase(x); - } - return 0; - } - auto it =m.begin(); - if(xfirst){ - return 1; - } - int x1=x/2; - int y1=(x+1)/2; - return (solve(x1,m)|solve(y1,m)); -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t; - cin >> t; - while (t--) - { - int n, m; - cin >> n >> m; - vector a(n); - vector b(m); - for (int i = 0; i < n; i++) - { - cin >> a[i]; - } - for (int i = 0; i < m; i++) - { - cin >> b[i]; - } - sort(a.begin(), a.end()); - sort(b.begin(), b.end()); - vector v; - vector u; - int i = 0; - int j = 0; - int f = 0; - while (i < n && j < m) - { - if (a[i] == b[j]) - { - i++; - j++; - } - else if (a[i] > b[j]) - { - u.push_back(b[j]); - j++; - } - else - { - v.push_back(a[i]); - i++; - } - } - while (i < n) - { - v.push_back(a[i]); - i++; - } - while (j < m) - { - u.push_back(b[j]); - j++; - } - // cout<<1< m1; - for(auto it : v){ - m1[it]++; - } - // cout<<1< -using namespace std; - -#define int long long -#define nl -#define imin INT_MIN -#define imax INT_MAX -#define lmin LLONG_MIN -#define lmax LLONG_MAX - - signed main(){ -ios_base::sync_with_stdio(false); -cin.tie(NULL); - -int t; -cin>>t; -while(t--){ - int n,m; - cin>>n>>m; - vector a(n); - vector b(m); - for(int i=0;i>a[i]; - } - for(int i=0;i>b[i]; - } - sort(a.begin(),a.end()); - sort(b.begin(),b.end()); - vector v; - vector u; - int i=0; - int j=0; - int f=0; - int sum=0; - while(ib[j]){ - f=1; - break; - } - else { - if(abs(sum-a[i])<=1 || sum==0){ - sum+=a[i]; - } - else{ - // cout<b[j]){ - f=1; - break; - } - i++; - } - } - if(i!=n || j!=m){ - f=1; - } - if(f==1){ - cout<<""No""< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define LF '\n'; -typedef long long lli; -typedef long double ld; - -map a; -map b; -set s; - -void solve() -{ - a.clear(); - b.clear(); - s.clear(); - lli n,m; - cin >> n >> m; - for (int i = 1; i <= n; i++) { - lli x; - cin >> x; - a[x]++; - } - for (int i = 1; i <= m; i++) { - lli x; - cin >> x; - b[x]++; - s.insert(x); - } - lli new_m=m; - while (!s.empty()) { - lli curr = *s.rbegin(); - s.erase(curr); - if (a[curr] > b[curr]) { - cout << ""NO"" << LF; - return; - } - lli d = (b[curr]-a[curr]); - if (d && curr == 1) { - cout << ""NO"" << LF; - return; - } - if (!d)continue; - new_m += d; - if (new_m > n) { - cout << ""NO"" << LF; - return; - } - b[curr] = a[curr]; - s.insert((curr / 2)); - s.insert(((curr+1) / 2)); - b[curr / 2]+=d; - b[(curr+1) / 2]+=d; - } - for (auto to : a) { - if (b[to.first] != to.second) { - cout << ""NO"" << LF; - } - } - for (auto to : b) { - if (a[to.first] != to.second) { - cout << ""NO"" << LF; - } - } - cout << ""YES"" << LF; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); -#ifdef _DEBUG - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - lli t; - cin >> t; - while (t--)solve(); -} - -","#define _CRT_SECURE_NO_WARNINGS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -#define LF '\n'; -typedef long long lli; -typedef long double ld; - -map a; -map b; -set s; - -void solve() -{ - a.clear(); - b.clear(); - s.clear(); - lli n,m; - cin >> n >> m; - for (int i = 1; i <= n; i++) { - lli x; - cin >> x; - a[x]++; - } - for (int i = 1; i <= m; i++) { - lli x; - cin >> x; - b[x]++; - s.insert(x); - } - lli new_m=m; - while (!s.empty()) { - lli curr = *s.rbegin(); - s.erase(curr); - if (a[curr] > b[curr]) { - cout << ""NO"" << LF; - return; - } - lli d = (b[curr]-a[curr]); - if (d && curr == 1) { - cout << ""NO"" << LF; - return; - } - if (!d)continue; - new_m += d; - if (new_m > n) { - cout << ""NO"" << LF; - return; - } - b[curr] = a[curr]; - s.insert((curr / 2)); - s.insert(((curr+1) / 2)); - b[curr / 2]+=d; - b[(curr+1) / 2]+=d; - } - for (auto to : a) { - if (b[to.first] != to.second) { - cout << ""NO"" << LF; - return; - } - } - for (auto to : b) { - if (a[to.first] != to.second) { - cout << ""NO"" << LF; - return; - } - } - cout << ""YES"" << LF; -} - -int main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); -#ifdef _DEBUG - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - lli t; - cin >> t; - while (t--)solve(); -} - -",2 -ZROUNDF#,2061D - Kevin and Numbers,c++20 ,305756441,305756889,"#include -using namespace std; -namespace A -{ - const long long N = 3e5 + 20, M = 998244353; -#define eps 1e-12 -#define int long long -#define ll long long -#define all(x) x.begin(), x.end() -#define endl '\n' -#define ls (p << 1) -#define rs ((p << 1) | 1) -#define f1 first -#define pb push_back -#define f2 second -#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(2); -} -using namespace A; -//__int128 -int read() -{ - int x = 0, f = 1; - char ch = getchar(); - while (ch < '0' || ch > '9') - { - f = -1; - ch = getchar(); - } - while (ch >= '0' && ch <= '9') - { - x = x * 10 + ch - '0'; - ch = getchar(); - } - x *= f; - return x; -} -void write(int x) -{ - if (x < 0) - { - putchar('-'); - x = -x; - } - if (x > 9) - write(x / 10); - putchar(x % 10 + '0'); -} -/*task1 -{ -每日错题 -}*/ -/*task2 -{ -div2 D -做到80%概率做E,10场<=20%概率降级 -0 1 -50% -提升一个阶段后尝试学习10个新算法 -G or 牛客博弈论专题 10题 -}*/ -int t, n, m; -signed main() -{ - IOS; - cin >> t; - while (t--) - { - cin >> n >> m; - int x; - priority_queue> q1, q2; - for (int i = 1; i <= n; i++) - { - cin >> x; - q1.push({x, 1}); - } - for (int i = 1; i <= m; i++) - { - cin >> x; - q2.push({x, 1}); - } - int ok = 1; - while (q1.size() && q2.size()) - { - auto [p1, t1] = q1.top(); - auto [p2, t2] = q2.top(); - q1.pop(), q2.pop(); - if (p1 == p2) - { - if (t1 == t2) - continue; - else if (t1 > t2) - { - q1.push({p1, t1 - t2}); - } - else - q2.push({p2, t2 - t1}); - } - else if (p1 < p2) - { - if (p2 % 2 == 1) - { - q2.push({p2 / 2, t2}); - q2.push({p2 / 2 + 1, t2}); - q1.push({p1, t1}); - } - else - { - int u = t2; - while (p2 / 2 >= p1 && p2 % 2 == 0) - { - p2 /= 2; - u *= 2; - } - q2.push({p2, u}); - q1.push({p1, t1}); - } - } - else - { - ok = 0; - break; - } - } - if (q1.size() || q2.size()) - ok = 0; - cout << (ok ? ""YES\n"" : ""NO\n""); - } - return false; -}","#include -using namespace std; -namespace A -{ - const long long N = 3e5 + 20, M = 998244353; -#define eps 1e-12 -#define int long long -#define ll long long -#define all(x) x.begin(), x.end() -#define endl '\n' -#define ls (p << 1) -#define rs ((p << 1) | 1) -#define f1 first -#define pb push_back -#define f2 second -#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(2); -} -using namespace A; -//__int128 -int read() -{ - int x = 0, f = 1; - char ch = getchar(); - while (ch < '0' || ch > '9') - { - f = -1; - ch = getchar(); - } - while (ch >= '0' && ch <= '9') - { - x = x * 10 + ch - '0'; - ch = getchar(); - } - x *= f; - return x; -} -void write(int x) -{ - if (x < 0) - { - putchar('-'); - x = -x; - } - if (x > 9) - write(x / 10); - putchar(x % 10 + '0'); -} -/*task1 -{ -每日错题 -}*/ -/*task2 -{ -div2 D -做到80%概率做E,10场<=20%概率降级 -0 1 -50% -提升一个阶段后尝试学习10个新算法 -G or 牛客博弈论专题 10题 -}*/ -int t, n, m; -signed main() -{ - IOS; - cin >> t; - while (t--) - { - cin >> n >> m; - int x; - priority_queue q1, q2; - for (int i = 1; i <= n; i++) - { - cin >> x; - q1.push(x); - } - for (int i = 1; i <= m; i++) - { - cin >> x; - q2.push(x); - } - int ok = 1; - while (q1.size() && q2.size()) - { - int p1 = q1.top(), p2 = q2.top(); - q1.pop(), q2.pop(); - if(q2.size()>q1.size()) - { - ok=0; - break; - } - if (p1 == p2) - { - continue; - } - else if (p1 < p2) - { - int u = p2 / 2, u1 = p2 - u; - q2.push(u), q2.push(u1), q1.push(p1); - } - else - { - ok = 0; - break; - } - } - if (q1.size() || q2.size()) - ok = 0; - cout << (ok ? ""YES\n"" : ""NO\n""); - } - return false; -}",2 -Anemone_#,2061D - Kevin and Numbers,c++23 ,314853000,314855996,"#include - -using namespace std; - -#ifdef LOCAL - -#include ""/competitive_programming/debug.cpp"" - -#else - -#define dbg(...) - -#endif - -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); - -using i64 = long long; - -int main() { - - ios_base::sync_with_stdio(false), cin.tie(0); - - int T; - - cin >> T; - - while (T--) { - - int n, m; - - cin >> n >> m; - - multiset S, T; - - for (int i = 0; i < n; ++i) { - - int t; - - cin >> t; - - S.insert(t); - - } - - for (int i = 0; i < m; ++i) { - - int t; - - cin >> t; - - if (S.count(t)) { - - S.erase(S.find(t)); - - } else { - - T.insert(t); - - } - - } - - while (T.size()) { - - if (S.size() <= 1) break; - - auto b1 = S.begin(); - - auto b2 = next(b1); - - int c1 = *b1, c2 = *b2; - - S.erase(S.find(c1)); - - S.erase(S.find(c2)); - - if (c2 - c1 <= 1) { - - int v = c1 + c2; - - if (T.count(v)) { - - T.erase(T.find(v)); - - } else { - - S.insert(v); - - } - - } else { - - break; - - } - - } - - if (T.size() == 0 && S.size() == 0) { - - cout << ""Yes\n""; - - } else { - - cout << ""No\n""; - - } - - } - - return 0; - -} - -","#include - -using namespace std; - -#ifdef LOCAL - -#include ""/competitive_programming/debug.cpp"" - -#else - -#define dbg(...) - -#endif - -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); - -using i64 = long long; - -int main() { - - ios_base::sync_with_stdio(false), cin.tie(0); - - int T; - - cin >> T; - - while (T--) { - - int n, m; - - cin >> n >> m; - - priority_queue S, S1; - - for (int i = 0; i < n; ++i) { - - int t; - - cin >> t; - - S.push(t); - - } - - for (int i = 0; i < m; ++i) { - - int t; - - cin >> t; - - S1.push(t); - - } - - while (S.size() > 0 && S1.size() > 0) { - - if (S.size() < S1.size()) break; - - int st = S.top(), s1t = S1.top(); - - S.pop(); - - S1.pop(); - - if (st == s1t) { - - continue; - - } else if (st > s1t) { - - break; - - } else { - - S.push(st); - - S1.push(s1t / 2); - - S1.push((s1t + 1) / 2); - - } - - } - - - - if (S.size() == 0 && S1.size() == 0) { - - cout << ""Yes\n""; - - } else { - - cout << ""No\n""; - - } - - // multiset S, T; - - // for (int i = 0; i < n; ++i) { - - // int t; - - // cin >> t; - - // S.insert(t); - - // } - - // for (int i = 0; i < m; ++i) { - - // int t; - - // cin >> t; - - // if (S.count(t)) { - - // S.erase(S.find(t)); - - // } else { - - // T.insert(t); - - // } - - // } - - // while (T.size()) { - - // if (S.size() <= 1) break; - - // auto b1 = S.begin(); - - // auto b2 = next(b1); - - // i64 c1 = *b1, c2 = *b2; - - // S.erase(S.find(c1)); - - // S.erase(S.find(c2)); - - // if (c2 - c1 <= 1) { - - // i64 v = c1 + c2; - - // if (T.count(v)) { - - // T.erase(T.find(v)); - - // } else { - - // S.insert(v); - - // } - - // } else { - - // break; - - // } - - // } - - // if (T.size() == 0 && S.size() == 0) { - - // cout << ""Yes\n""; - - // } else { - - // cout << ""No\n""; - - // } - - } - - return 0; - -} - -",2 -BigProcrastinator,2061D - Kevin and Numbers,c++17 ,303431191,303426232,"#include -using namespace std; -#define int long long - -void sol() { - int n, m; cin >> n >> m; - mapmp; - for(int i = 1; i <= n; ++i) { - int x; cin >> x; - mp[x]++; - } - priority_queue pq; - for(int i = 1; i <= m; ++i) { - int x; cin >> x; - pq.push(x); - } - for(int i = 1; i <= 2 * n - m; ++i) { - if(pq.empty()) return void(cout << ""NO\n""); - int x = pq.top(); - pq.pop(); - if(!mp[x]) { - pq.push(x / 2); - pq.push((x + 1) / 2); - } else - --mp[x]; - } - cout << (pq.empty() ? ""YES\n"" : ""NO\n""); - -} - -int32_t main() { - ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); - int T = 1; cin >> T; - while (T--) sol(); -}","#include -using namespace std; -#define int long long - -void sol() { - int n, m; cin >> n >> m; - mapa, b; - vector A; - for(int i = 1; i <= n; ++i) { - int x; cin >> x; - if(!a[x]) A.push_back(x); - a[x]++; - } - for(int i = 1; i <= m; ++i) { - int x; cin >> x; - b[x]++; - } - - sort(A.begin(), A.end()); - for(auto x : A) { - int mn = min(a[x], b[x]); - a[x] -= mn; b[x] -= mn; - } - for(auto x : A) { - int mn = min(a[x], b[x]); - a[x] -= mn; b[x] -= mn; - if(a[x + 1]) { - if(x != 1) { - mn = min(a[x], a[x + 1]); - a[x] -= mn; a[x + 1] -= mn; - a[2 * x + 1] += mn; - mn = min(a[2 * x + 1], b[2 * x + 1]); - a[2 * x + 1] -= mn; b[2 * x + 1] -= mn; - a[2 * x] += a[x] / 2; - a[x] %= 2; - } else { - x++; - mn = min(a[1] / x, a[x]); - a[1] -= (x * mn); a[x] -= mn; - a[2 * x] += mn; - mn = min(a[2 * x], b[2 * x]); - a[2 * x] -= mn; b[2 * x] -= mn; - mn = min(a[1] / (x - 1), a[x]); - a[1] -= ((x - 1) * mn); a[x] -= mn; - a[2 * x - 1] += mn; - mn = min(a[2 * x - 1], b[2 * x - 1]); - a[2 * x - 1] -= mn; b[2 * x - 1] -= mn; - } - //cout << x << ' ' << a[1] << ' ' << a[2] << ' ' << a[3] << '\n'; - } else { - if(x == 1) continue; - mn = min(a[1] / x, a[x]); - a[1] -= (x * mn); a[x] -= mn; - a[2 * x] += mn; - mn = min(a[2 * x], b[2 * x]); - a[2 * x] -= mn; b[2 * x] -= mn; - mn = min(a[1] / (x - 1), a[x]); - a[1] -= ((x - 1) * mn); a[x] -= mn; - a[2 * x - 1] += mn; - mn = min(a[2 * x - 1], b[2 * x - 1]); - a[2 * x - 1] -= mn; b[2 * x - 1] -= mn; - a[2 * x] += a[x] / 2; - a[x] %= 2; - mn = min(a[2 * x], b[2 * x]); - a[2 * x] -= mn; b[2 * x] -= mn; - mn = min(a[1] / x, a[x]); - a[1] -= (x * mn); a[x] -= mn; - a[2 * x] += mn; - mn = min(a[2 * x], b[2 * x]); - a[2 * x] -= mn; b[2 * x] -= mn; - mn = min(a[1] / (x - 1), a[x]); - a[1] -= ((x - 1) * mn); a[x] -= mn; - a[2 * x - 1] += mn; - mn = min(a[2 * x - 1], b[2 * x - 1]); - a[2 * x - 1] -= mn; b[2 * x - 1] -= mn; - } - } - int d = 0; - for(auto [x, cnt] : a) { - if(x == 1) continue; - d += (cnt > 0); - } - if(d) return void(cout << ""NO\n""); - for(auto[x, cnt] : b) { - if(a[1] < (cnt * x)) return void(cout << ""NO\n""); - else a[1] -= (cnt * x); - } - if(a[1]) cout << ""NO\n""; - else cout << ""YES\n""; -} - -int32_t main() { - ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); - int T = 1; cin >> T; - while (T--) sol(); -}",1 -Infinite_Strife#,2061D - Kevin and Numbers,c++17 ,302848690,302845744,"#include -#define int long long -using namespace std; -map ma; -int n,m; -bool cal(int x) -{ -if(ma[x]>0) -{ - ma[x]--; - n--; - return 1; -} -if(x==1) - return 0; -return cal(x/2)&&cal(x/2+x%2); -} -void solve() -{ - - cin>>n>>m; - ma.clear(); - for(int i=1;i<=n;i++) - { - int temp;cin>>temp; - ma[temp]++; - } - for(int i=1;i<=m;i++) - { - int temp;cin>>temp; - if(cal(temp)==0) - { - cout<<""NO\n""; - for(int j=i+1;j<=m;j++) - cin>>temp; - return ; - } - } - if(n==0) - cout<<""YES\n""; -else cout<<""NO\n""; - return; -} -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int T; - cin>>T; - while(T--) - solve(); -}","#include -#define int long long -using namespace std; -map ma; -int n,m; -bool cal(int x) -{ -if(ma[x]>0) -{ - ma[x]--; - n--; - return 1; -} -if(x==1) - return 0; -return cal(x/2)&&cal(x/2+x%2); -} -void solve() -{ - - cin>>n>>m; - ma.clear(); - for(int i=1;i<=n;i++) - { - int temp;cin>>temp; - ma[temp]++; - } - for(int i=1;i<=m;i++) - { - int temp;cin>>temp; - if(cal(temp)==0) - { - cout<<""NO\n""; - return ; - } - } - if(n==0) - cout<<""YES\n""; -else cout<<""NO\n""; - return; -} -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int T; - cin>>T; - while(T--) - solve(); -}",1 -panyifan2021,2061D - Kevin and Numbers,c++23 ,302824803,302824187,"#include -#define int long long -#define pii pair -#define x first -#define y second -using namespace std; -int a[300005],b[300005]; -mapgs; -multisets; -int dfs(){ - while(!s.empty()){ - pii o; - while(s.size()>1){ - auto e=--s.end(); - o=*e; - e--; - pii t=*e; - if(o.x==t.x) - o.y+=t.y,s.erase(--s.end()),s.erase(--s.end()),s.insert(o); - else - break; - } - o=*--s.end(); - s.erase(--s.end()); - if(gs[o.x]>=o.y) - gs[o.x]-=o.y; - else{ - s.insert({o.x/2,o.y-gs[o.x]}); - s.insert({o.x-o.x/2,o.y-gs[o.x]}); - gs[o.x]=0; - if(o.x==1) - break; - } - } - if(s.size()==0) - return 1; - else - return 0; -} -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int T; - cin>>T; - while(T--){ - s.clear(); - int n,m,sum=0; - cin>>n>>m; - for(int i=1;i<=n;i++) - cin>>a[i],gs[a[i]]++,sum+=a[i]; - for(int i=1;i<=m;i++){ - cin>>b[i]; - sum-=b[i]; - s.insert({b[i],1}); - } - if(dfs()&&sum==0) - cout<<""Yes\n""; - else - cout<<""No\n""; - for(int i=1;i<=n;i++) - gs[a[i]]=0; - } - return 0; -} -/* - -*/","#include -#define int long long -#define pii pair -#define x first -#define y second -using namespace std; -int a[300005],b[300005]; -mapgs; -multisets; -int dfs(){ - while(!s.empty()){ - pii o=*s.begin(); - while(s.size()>1){ - auto e=s.begin(); - o=*e; - e++; - pii t=*e; - if(o.x==t.x) - o.y+=t.y,s.erase(s.begin()),s.erase(s.begin()),s.insert(o); - else - break; - } - o=*s.begin(); - s.erase(s.begin()); - if(gs[o.x]>=o.y) - gs[o.x]-=o.y; - else{ - if(o.y>gs[o.x]) - s.insert({o.x/2,o.y-gs[o.x]}); - s.insert({o.x-o.x/2,o.y-max(0ll,gs[o.x]-o.y)}); - gs[o.x]=0; - if(o.x==1) - break; - if(o.x==0) - break; - } - } - if(s.size()==0) - return 1; - else - return 0; -} -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - int T; - cin>>T; - while(T--){ - s.clear(); - int n,m,sum=0; - cin>>n>>m; - for(int i=1;i<=n;i++) - cin>>a[i],gs[a[i]]++,sum+=a[i]; - for(int i=1;i<=m;i++){ - cin>>b[i]; - sum-=b[i]; - s.insert({b[i],1}); - } - if(dfs()&&sum==0) - cout<<""Yes\n""; - else - cout<<""No\n""; - } - return 0; -}",1 -bobbyCodes,2062C - Cirno and Operations,c++17 ,304034763,304033482,"/* -* author: bobbyCodes -*/ - -#include -//#include -//#include -//#define pbds tree -#define ll long long -#define pb push_back -#define IM INT_MAX -#define IN INT_MIN -#define fo for(int i=0;i=1;i--){if(!(a%i) && !(b%i)){return i;}}return 1;} -ll seiveOfErytosthesis(ll k,ll n = 1e6){vector v(n+1,true);v[0]=v[1]=false;for(ll i =2; i*i<= n; i++){for(ll j =2*i; j <=n ; j+=i){if(v[j]){v[j]=false;}}}ll num=0;for(ll i=k; i<=1e6;i++){if(v[i]){num= i;break;}}return num;} -------------------------------------------------------------------------------------------------------------- -*/ -//using namespace __gnu_pbds - -void init_code(){ - fast_io; - #ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif -} -void solve(){ - int n; - cin>>n; - - vectorv(n); - - for(int i=0; i>v[i]; - } - - int now=n; - - long long ans= -1e18; - - for(int i=0; i> t; - while(t--){ - solve(); - } - return 0; -}","/* -* author: bobbyCodes -*/ - -#include -//#include -//#include -//#define pbds tree -#define ll long long -#define pb push_back -#define IM INT_MAX -#define IN INT_MIN -#define fo for(int i=0;i=1;i--){if(!(a%i) && !(b%i)){return i;}}return 1;} -ll seiveOfErytosthesis(ll k,ll n = 1e6){vector v(n+1,true);v[0]=v[1]=false;for(ll i =2; i*i<= n; i++){for(ll j =2*i; j <=n ; j+=i){if(v[j]){v[j]=false;}}}ll num=0;for(ll i=k; i<=1e6;i++){if(v[i]){num= i;break;}}return num;} -------------------------------------------------------------------------------------------------------------- -*/ -//using namespace __gnu_pbds - -void init_code(){ - fast_io; - #ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - #endif -} -void solve(){ - int n; - cin>>n; - - vectorv(n); - - for(int i=0; i>v[i]; - } - - int now=n; - - long long ans= -1e18; - - for(int i=0; i> t; - while(t--){ - solve(); - } - return 0; -}",1 -fatmasioui,2062C - Cirno and Operations,c++17 ,305446970,305447121,"#include -#define rep(i,a,b) for(ll i=a;i=a;i--) -using namespace std; -#define ll long long -#define re(i,b) for(ll i=0;i=0;i--) -#define dd long double -#define all(x) x.begin(), x.end() -#define rall(a) (a).rbegin(), (a).rend() -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define lire(v) for (auto &u : v) cin >> u; -#define aff(v) for (auto u : v) cout << u << "" ""; cout << endl; -#define endl ""\n"" -#define ff first -#define ss second -#define pb push_back -#define eb emplace_back -#define vll vector -#define vpll vector> -#define mpcl map -#define vdd vector

-#define vbo vector -#define mpll map -#define sll set -#define pll pair -#define vss vector -#define vcc vector -#define scc set -#define sss set -// sort(a.begin(), a.end(), [](int x, int y) { -// return x % 2 < y % 2; -// }); -//fixed<> t; - re(w,t){ - ll n;cin>>n; - vll a(n); - ll s=LLONG_MIN; - - re(i,n){ - ll s2=0; - re(j,n-i){ - s2+=a[j]; - } - if(i==0)s=max(s,s2); - else s=max(s,max(s2,-(s2))); - re(j,n-i-1)a[j]=a[j+1]-a[j]; - } - cout< -#define rep(i,a,b) for(ll i=a;i=a;i--) -using namespace std; -#define ll long long -#define re(i,b) for(ll i=0;i=0;i--) -#define dd long double -#define all(x) x.begin(), x.end() -#define rall(a) (a).rbegin(), (a).rend() -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define lire(v) for (auto &u : v) cin >> u; -#define aff(v) for (auto u : v) cout << u << "" ""; cout << endl; -#define endl ""\n"" -#define ff first -#define ss second -#define pb push_back -#define eb emplace_back -#define vll vector -#define vpll vector> -#define mpcl map -#define vdd vector
-#define vbo vector -#define mpll map -#define sll set -#define pll pair -#define vss vector -#define vcc vector -#define scc set -#define sss set -// sort(a.begin(), a.end(), [](int x, int y) { -// return x % 2 < y % 2; -// }); -//fixed<> t; - re(w,t){ - ll n;cin>>n; - vll a(n); - ll s=LLONG_MIN; - re(i,n){ - cin>>a[i]; - } - re(i,n){ - ll s2=0; - re(j,n-i){ - s2+=a[j]; - } - if(i==0)s=max(s,s2); - else s=max(s,max(s2,-(s2))); - re(j,n-i-1)a[j]=a[j+1]-a[j]; - } - cout< -#define F first -#define S second -#define ll long long -#define pll pair -#define pii pair -#define pb push_back -#define rnd srand(static_cast(time(0))) -using namespace std; -const int mod = 1e9 + 7; -const int MAXN = 1e6 + 5; -const int inf = 2e9; -void solve(){ - int n; - ll mx = 0, sum = 0; - cin >> n; - vector a(n); - for (int i = 0; i < n; i ++){ - cin >> a[i]; - sum += a[i]; - } - if (n > 1) mx = max(mx, abs(sum)); - else mx = max(mx, sum); - while((int)a.size() != 1){ - for (int i = 0; i < (int)a.size() - 1; i ++){ - a[i] *= (-1LL); - a[i] += a[i + 1]; - } - a.pop_back(); - sum = 0; - for (ll i : a) - sum += i; - mx = max(mx, abs(sum)); - } - cout << mx << endl; -} -int main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t --) - solve(); -}","#include -#define F first -#define S second -#define ll long long -#define pll pair -#define pii pair -#define pb push_back -#define rnd srand(static_cast(time(0))) -using namespace std; -const int mod = 1e9 + 7; -const int MAXN = 1e6 + 5; -const int inf = 2e9; -void solve(){ - int n; - ll mx = -2e18, sum = 0; - cin >> n; - vector a(n); - for (int i = 0; i < n; i ++){ - cin >> a[i]; - sum += a[i]; - } - mx = max(mx, sum); - while((int)a.size() != 1){ - for (int i = 0; i < (int)a.size() - 1; i ++){ - a[i] *= (-1LL); - a[i] += a[i + 1]; - } - a.pop_back(); - sum = 0; - for (ll i : a) - sum += i; - if (n > 1) mx = max(mx, abs(sum)); - else mx = max(mx, sum); - } - cout << mx << endl; -} -int main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t --) - solve(); -}",2 -DaNub2002,2062C - Cirno and Operations,c++20 ,305053601,305053781,"#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; -template using ordered_set = __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; - -#define dbg(x) cerr << #x << "" = "" << x << endl; -#define int long long -#define double long double -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(),a.rend() -#define endl ""\n"" -const int mod = 1e9+ 7; -const int dx[] = { 1, 0, -1, 0 }; -const int dy[] = { 0, 1, 0, -1 }; - -int lcm(int a,int b){ - return a/__gcd(a,b)*b; -} - -const int maxN = 1e3 + 5, inf = 1e18; - -int sum(vector&a){ - int res =0 ; - for(int x:a)res += x; - return res; -} -void solve(){ - // so importa o primeiro e o ultimo - - int n, ans = 0; - cin >> n; - - vectora(n); - for(int &i:a){ - cin >> i; - ans += i; - } - - while(a.size() > 1){ - int x = a.back() - a.front(); - - ans = max(ans, x); - // cout << ""sz: "" << a.size() << endl; - if(x < 0){ - reverse(all(a)); - } - - vectorb(a.size() - 1); - for(int i = 0; i < a.size()-1; i++)b[i] = a[i+1] - a[i]; - - a = b; - } - ans = max(ans, a[0]); - cout << ans << endl; -} - - - -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - - while (t--) { - solve(); - } - - - return 0; -} - - - -","#include -#include -#include - -using namespace std; -using namespace __gnu_pbds; -template using ordered_set = __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; - -#define dbg(x) cerr << #x << "" = "" << x << endl; -#define int long long -#define double long double -#define all(a) a.begin(), a.end() -#define rall(a) a.rbegin(),a.rend() -#define endl ""\n"" -const int mod = 1e9+ 7; -const int dx[] = { 1, 0, -1, 0 }; -const int dy[] = { 0, 1, 0, -1 }; - -int lcm(int a,int b){ - return a/__gcd(a,b)*b; -} - -const int maxN = 1e3 + 5, inf = 1e18; - -int sum(vector&a){ - int res =0 ; - for(int x:a)res += x; - return res; -} -void solve(){ - // so importa o primeiro e o ultimo - - int n, ans = 0; - cin >> n; - - vectora(n); - for(int &i:a){ - cin >> i; - ans += i; - } - - while(a.size() > 1){ - // for(int x:a)cout << x << "" ""; - // cout << endl; - int x = a.back() - a.front(); - - ans = max(ans, sum(a)); - // cout << ""sz: "" << a.size() << "" x: "" << x << "" ans: "" << ans << endl; - if(x < 0){ - reverse(all(a)); - } - - vectorb(a.size() - 1); - for(int i = 0; i < a.size()-1; i++)b[i] = a[i+1] - a[i]; - - a = b; - } - ans = max(ans, a[0]); - cout << ans << endl; -} - - - -signed main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t = 1; - cin >> t; - - while (t--) { - solve(); - } - - - return 0; -} - - - -",2 -DiegoDias007,2062C - Cirno and Operations,c++20 ,307171424,307171797,"#include - -#define endl '\n' -typedef long long ll; -using namespace std; - -template T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);} -template T lcm(T a, T b) {return (a * b) / gcd(a, b);} -template void print_vec(const vector& vec) {for(size_t i = 0; i < vec.size(); ++i) {cout << vec[i];if(i != vec.size() - 1) {cout << "" "";}}cout << endl;} - -void solve() { - int n; - cin >> n; - - vector a(n); - ll ans = 0; - for (int i = 0; i < n; i++) { - cin >> a[i]; - ans += a[i]; - } - - ans = abs(ans); - - while (n > 1) { - ll x = 0; - for (int i = 0; i < n - 1; i++) { - a[i] = a[i + 1] - a[i]; - x += a[i]; - } - - ans = max(ans, abs(x)); - n--; - } - - cout << ans << endl; -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}","#include - -#define endl '\n' -typedef long long ll; -using namespace std; - -template T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);} -template T lcm(T a, T b) {return (a * b) / gcd(a, b);} -template void print_vec(const vector& vec) {for(size_t i = 0; i < vec.size(); ++i) {cout << vec[i];if(i != vec.size() - 1) {cout << "" "";}}cout << endl;} - -void solve() { - int n; - cin >> n; - - vector a(n); - ll ans = 0; - for (int i = 0; i < n; i++) { - cin >> a[i]; - ans += a[i]; - } - - while (n > 1) { - ll x = 0; - for (int i = 0; i < n - 1; i++) { - a[i] = a[i + 1] - a[i]; - x += a[i]; - } - - ans = max(ans, abs(x)); - n--; - } - - cout << ans << endl; -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -}",2 -anuragkr24,2062C - Cirno and Operations,c++17 ,307113523,307113648,"#include -using namespace std; -#define ll long long - -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector v; - for(int i = 0; i < n; i++){ - int a; - cin >> a; - v.push_back(a); - } - if(n == 1){ - cout << v[0] << endl; - continue; - } - ll ans = accumulate(v.begin(), v.end(), 0LL); - vector u; - while(n > 1){ - for(int i = 0; i < n - 1; i++)u.push_back(v[i + 1] - v[i]); - ll sum = accumulate(u.begin(), u.end(), 0LL); - for(int i = 0; i < n - 1; i++)v[i] = u[i]; - u.clear(); - ans = max(ans, abs(sum)); - n--; - } - cout << ans << endl; - } -} -","#include -using namespace std; -#define ll long long - -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector v; - for(int i = 0; i < n; i++){ - int a; - cin >> a; - v.push_back(a); - } - if(n == 1){ - cout << v[0] << endl; - continue; - } - ll ans = accumulate(v.begin(), v.end(), 0LL); - vector u; - while(n > 1){ - for(int i = 0; i < n - 1; i++)u.push_back(v[i + 1] - v[i]); - ll sum = accumulate(u.begin(), u.end(), 0LL); - for(int i = 0; i < n - 1; i++)v[i] = u[i]; - u.clear(); - ans = max(ans, abs(sum)); - n--; - } - cout << ans << endl; - } -} -",2 -Rares_Stan,2062C - Cirno and Operations,c++17 ,304426865,304426953,"#include -#define NMAX 55 -#define pb push_back - -using namespace std; - -int v[NMAX]; - -int main() { - int tt; - cin >> tt; - while (tt--) { - int n; - long long maxx = LONG_LONG_MIN; - cin >> n; - long long s = 0; - for (int i = 1; i <= n; i++) { - cin >> v[i]; - s += v[i]; - } - maxx = max(maxx, s); - int p = n; - while(p > 1) { - long long s1 = 0, s2 = 0; - for (int i = 1; i < p; i++) { - v[i] = v[i + 1] - v[i]; - s1 += v[i]; - s2 += -(v[i]); - } - p--; - maxx = max(maxx, max(s1, s2)); - } - if (n > 1) - cout << maxx << '\n'; - else cout << v[1] << '\n'; - } - return 0; -} -","#include -#define NMAX 55 -#define pb push_back - -using namespace std; - -long long v[NMAX]; - -int main() { - int tt; - cin >> tt; - while (tt--) { - int n; - long long maxx = LONG_LONG_MIN; - cin >> n; - long long s = 0; - for (int i = 1; i <= n; i++) { - cin >> v[i]; - s += v[i]; - } - maxx = max(maxx, s); - int p = n; - while(p > 1) { - long long s1 = 0, s2 = 0; - for (int i = 1; i < p; i++) { - v[i] = v[i + 1] - v[i]; - s1 += v[i]; - s2 += -(v[i]); - } - p--; - maxx = max(maxx, max(s1, s2)); - } - if (n > 1) - cout << maxx << '\n'; - else cout << v[1] << '\n'; - } - return 0; -} -",2 -Akash_75,2062C - Cirno and Operations,c++17 ,308807378,308809228,"#include -#define ll long long -#define pb push_back -#define vi vector -#define vvi vector -#define umi unordered_map -#define usi unordered_set -#define all(x) x.begin(),x.end() -#define fr(i, n) for (long long i = 0; i < (n); i++) -using namespace std; - -const int mod = 1e9+7; - -int sol(vector v) { - int n = v.size(); - if (n == 1) { - return v[0]; - } - - vi ki, kir; - for (int i = 1; i < n; i++) { - ki.pb(v[i] - v[i - 1]); - } - - reverse(all(v)); - - for (int i = 1; i < n; i++) { - kir.pb(v[i] - v[i - 1]); - } - - if (ki.empty() || kir.empty()) return 0; // Avoid infinite recursion - - return max({sol(ki), sol(kir)}); -} - -void solve() { - int n; - cin >> n; - vi v(n); - fr(i, n) { - cin >> v[i]; - } - - int sm = accumulate(all(v), 0LL); - int mi = sol(v); - - cout << max(mi, sm) << endl; -} - -signed main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int tt = 1; - cin >> tt; - while (tt--) { - solve(); - } -} -","#include -#define ll long long -#define pb push_back -#define vi vector -#define vvi vector -#define umi unordered_map -#define usi unordered_set -#define all(x) x.begin(),x.end() -#define fr(i, n) for (long long i = 0; i < (n); i++) -using namespace std; - -const ll mod = 1e9+7; - -vectorsol(vector v) { - ll n=v.size(); - vi ki; - for(ll i=1;i> n; - vi v(n); - fr(i, n) { - cin >> v[i]; - }ll mx=INT_MIN;ll si=accumulate(all(v),0LL); - while(!v.empty()){ - ll sm=accumulate(all(v),0LL); - v=sol(v); - mx=max(mx,sm); -} -cout<> tt; - while (tt--) { - solve(); - } -} -",2 -iMDH,2062C - Cirno and Operations,c++23 ,306284943,306284874,"#include -using namespace std; -using namespace __gnu_pbds; -#define il inline -#define ll long long -#define lll __int128 -#define ull unsigned long long -#define ld long double -#define db double -#define gc getchar(); -#define pc(x) putchar(x) -#define O(x) cout<, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> -#define pbmap(typ1,typ2) tree< typ1 , typ2 ,std::less< typ1 >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> - -namespace constant_warrior{ - template inline void fr(T& num){ - num=0;short sign=1;char ch=std::getchar(); - while(ch<'0'||ch>'9'){ - if(ch=='-')sign=-1; - ch=std::getchar(); - } - while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar(); - num=num*sign; - } - templateinline void fw(T x){ - if(x<0)std::putchar('-'),x=-x; - if(x>9)fw(x/10); - std::putchar(x%10+'0'); - } - templateinline const T& maxf(const T& a,const T& b){ - if(a>b)return a; - return b; - } - templateinline const T& minf(const T& a,const T& b){ - if(a>b)return b; - return a; - } - templateinline void swapf(T& a,T& b){ - a^=b^=a^=b; - } -} -using namespace constant_warrior; -const int N=64; -int n,m,a[2][N]; - - -void solve(){ - int res=0; - fr(n); - for(int i=1;i<=n;i++){ - fr(a[0][i]); - res+=a[0][i]; - } - for(bool flag=1;n>1;n--,flag^=1){ - int tmp=0; - for(int i=1;i>T; - while(T-->0)solve(); -} -/* -暴力出奇迹,卡常能AC。 -Violent makes miracle,pursuing better constant can AC. -多测不清空,OI见祖宗。 -multitesting without clearing,oier meets the LCA. -十年OI一场空,不开LL见祖宗。 -Ten years of OI just AFO,no #define int long long sees the LCA. -似是神犇成才处,实为蒟蒻黄泉路。 -It is likely to be the Au medal for the big old,but in fact it is the Si medal for me. -黄题有恨无正解,码力不若小学生。 -A yellow problem I can't AC,codeforces is not as NB as HNO3(Dilute nitric acid). -今生无奈入OI,来世不做信竞人。 -This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics. -你%你赛觉得是我的锅那就是我的锅, -因为%你赛出的题,就像是一个毒瘤晚期患者出的题, -他都已经这样了,你为什么不能顺从他呢? -你总要给人最后一段时间一个好的回忆吧,最后的时光里。 -*/","#include -using namespace std; -using namespace __gnu_pbds; -#define il inline -#define ll long long -#define lll __int128 -#define ull unsigned long long -#define ld long double -#define db double -#define gc getchar(); -#define pc(x) putchar(x) -#define O(x) cout<, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> -#define pbmap(typ1,typ2) tree< typ1 , typ2 ,std::less< typ1 >, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> - -namespace constant_warrior{ - template inline void fr(T& num){ - num=0;short sign=1;char ch=std::getchar(); - while(ch<'0'||ch>'9'){ - if(ch=='-')sign=-1; - ch=std::getchar(); - } - while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar(); - num=num*sign; - } - templateinline void fw(T x){ - if(x<0)std::putchar('-'),x=-x; - if(x>9)fw(x/10); - std::putchar(x%10+'0'); - } - templateinline const T& maxf(const T& a,const T& b){ - if(a>b)return a; - return b; - } - templateinline const T& minf(const T& a,const T& b){ - if(a>b)return b; - return a; - } - templateinline void swapf(T& a,T& b){ - a^=b^=a^=b; - } -} -using namespace constant_warrior; -const int N=64; -int n,m,a[2][N]; - - -void solve(){ - int res=0; - fr(n); - for(int i=1;i<=n;i++){ - fr(a[0][i]); - res+=a[0][i]; - } - for(bool flag=1;n>1;n--,flag^=1){ - int tmp=0; - for(int i=1;i>T; - while(T-->0)solve(); -} -/* -暴力出奇迹,卡常能AC。 -Violent makes miracle,pursuing better constant can AC. -多测不清空,OI见祖宗。 -multitesting without clearing,oier meets the LCA. -十年OI一场空,不开LL见祖宗。 -Ten years of OI just AFO,no #define int long long sees the LCA. -似是神犇成才处,实为蒟蒻黄泉路。 -It is likely to be the Au medal for the big old,but in fact it is the Si medal for me. -黄题有恨无正解,码力不若小学生。 -A yellow problem I can't AC,codeforces is not as NB as HNO3(Dilute nitric acid). -今生无奈入OI,来世不做信竞人。 -This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics. -你%你赛觉得是我的锅那就是我的锅, -因为%你赛出的题,就像是一个毒瘤晚期患者出的题, -他都已经这样了,你为什么不能顺从他呢? -你总要给人最后一段时间一个好的回忆吧,最后的时光里。 -*/",1 -AarushIITM,2062C - Cirno and Operations,c++20 ,307513243,307513569,"#include -using namespace std; -#define debug 0 - -int main(){ - int cases; - scanf(""%d"",&cases); - while(cases--){ - int n; - cin >> n; - int sum=0; - vector arr; - int num; - for(int i=0;i> num; - arr.push_back(num); - sum+=arr[i]; - - } - vector vec; - vec.push_back(sum); - while(arr.size()>1){ - int n=arr.size(); - if(arr[0] < arr[n-1]) - { - vec.push_back(arr[n-1]-arr[0]); - for(int i=0;i -using namespace std; -#define debug 0 - -int main(){ - long long int cases; - scanf(""%lld"",&cases); - while(cases--){ - long long int n; - cin >> n; - long long int sum=0; - vector arr; - long long int num; - for(long long int i=0;i> num; - arr.push_back(num); - sum+=arr[i]; - - } - vector vec; - vec.push_back(sum); - while(arr.size()>1){ - long long int n=arr.size(); - if(arr[0] < arr[n-1]) - { - vec.push_back(arr[n-1]-arr[0]); - for(long long int i=0;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t!=0){ - int n; - cin>>n; - int arr[n]; - for(int i=0;i>arr[i]; - - long long maxi=LLONG_MIN; - int now=n; - for(int i=0;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t!=0){ - int n; - cin>>n; - long long arr[n]; - for(int i=0;i>arr[i]; - - long long maxi=LLONG_MIN; - int now=n; - for(int i=0;i -#include -int main(){ - int n; - scanf(""%d\n"",&n); - long long int res[n]; - for (int i=0;imax){ - max=temp; - } - else if (-1*temp>max){ - max=-1*temp; - } - } - res[i]=max; - } - for (int b=0;b -#include -int main(){ - int n; - scanf(""%d\n"",&n); - long long int res[n]; - for (int i=0;imax){ - max=temp; - } - if (-1*temp>max){ - max=-1*temp; - } - } - res[i]=max; - } - for (int b=0;b -using namespace std; - -#define ll long long -#define int ll - -const int sz = 2e5 + 5; - -void solve(){ - int n, sum = 0, ans = -1e9; cin >> n; - vectora(n); - for(int i = 0; i < n; i++){ - cin >> a[i]; sum += a[i]; - } - ans = max(ans, sum); sum = 0; - while(a.size() > 1){ - reverse(a.begin(), a.end()); - vectorb(a.size() - 1); - for(int i = 1; i < a.size(); i++){ - b[i - 1] = a[i] - a[i - 1]; - sum += b[i - 1]; - } - ans = max(ans, abs(sum)); sum = 0; - swap(a, b); - } - cout << ans << '\n'; -} - -signed main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int t; cin >> t; - while(t--) solve(); -}","#include -using namespace std; - -#define ll long long -#define int ll - -const int sz = 2e5 + 5; - -void solve(){ - int n, sum = 0, ans = -1e9; cin >> n; - vectora(n); - for(int i = 0; i < n; i++){ - cin >> a[i]; sum += a[i]; - } - ans = max(ans, sum); sum = 0; - while(a.size() > 1){ - reverse(a.begin(), a.end()); - vectorb(a.size() - 1); - for(int i = 1; i < a.size(); i++){ - b[i - 1] = a[i] - a[i - 1]; - sum += b[i - 1]; - } - ans = max(ans, sum); sum = 0; - swap(a, b); - } - cout << ans << '\n'; -} - -signed main(){ - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - int t; cin >> t; - while(t--) solve(); -}",1 -sgtg1702,2062C - Cirno and Operations,c++20 ,304198646,304198573,"#include -using namespace std; - -int main() -{ - int t; - cin>>t; - while(t--) - { - long long n; - cin>>n; - vector a(n); - long long sum=0; - for(auto&i:a) - { - cin>>i; - sum+=i; - } - vector store; - while(n>1) - { - for(int i=0;i -using namespace std; - -int main() -{ - int t; - cin>>t; - while(t--) - { - long long n; - cin>>n; - vector a(n); - long long sum=0; - for(auto&i:a) - { - cin>>i; - sum+=i; - } - vector store; - while(n>1) - { - for(int i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - - -#define ll long long -#define pb push_back -#define pll pair -#define mll map -#define pii pair -#define vpii vector -#define rep(i,n) for(int i=0; i>a[i] -#define vi vector -#define vll vector -#define nl ""\n"" -#define print(arr) All(x,arr) cout<>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);} -#define vdsort(v) sort(v.begin(),v.end(),greater()) -#define F first -#define S second -#define mod 1'000'000'007 - - -const int MAXN = 100'005; -int spf[MAXN]; -ll fac1[MAXN], fac2[MAXN], inv[MAXN]; -ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } - -template ()))>, typename std::enable_if::value>::type* = nullptr> -std::ostream& operator<<(std::ostream& os, const C& container) -{ - bool first = true; - std::stringstream ss; - ss << '['; - for (const auto& x : container) - { - if (!first) - { - ss << "", ""; - } - first = false; - ss << x; - } - ss << ']'; - return os << ss.str(); -} -template -std::ostream& operator<<(std::ostream& os, const std::pair& p) -{ - os << '{' << p.first << "", "" << p.second << '}'; - return os; -} -vector vec_splitter(string S) -{ - S += ','; - vector res; - while (!S.empty()) - { - res.push_back(S.substr(0, S.find(','))); - S = S.substr(S.find(',') + 1); - } - return res; -} - -template -void debug_out(vector args, int idx, int LINE_NUM, Head H, Tail... T) -{ - if (idx > 0) - cerr << "", ""; - else - cerr << ""Line("" << LINE_NUM << "") ""; - stringstream ss; - ss << H; - cerr << args[idx] << "" = "" << ss.str(); - debug_out(args, idx + 1, LINE_NUM, T...); -} -#ifdef DEBUG -#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) -#else -#define debug(...) 42 -#endif - -bool isPerfectSquare(long double x) -{ - if (x >= 0) { - long long sr = sqrt(x); - return (sr * sr == x); - } - return false; -} - -bool isPowerof2(int n, int) { - return (n && !(n & n - 1)); -} - -string decimalToBin(ll N) -{ - string B_Number = """"; - int c = 0; - while (N != 0) { - if (N % 2 == 0) { - B_Number = ""0"" + B_Number; - } - else B_Number = ""1"" + B_Number; - N = N / 2; - c++; - } - - for (int i = c + 1; i <= 30; i++) { - B_Number = ""0"" + B_Number; - } - - return B_Number; -} - -int binaryToDecimal(ll n) -{ - ll num = n; - int dec_value = 0; - int base = 1; - ll temp = num; - - while (temp) { - int last_digit = temp % 10; - temp = temp / 10; - - dec_value += last_digit * base; - - base = base * 2; - } - - return dec_value; -} - - -ll min(ll a, ll b) { - return a < b ? a : b; -} -ll max(ll a, ll b) { - return a > b ? a : b; -} -ll power(ll a, ll b, ll Mod) { - if (b == 0) { - return 1; - } - ll ans = power(a, b / 2, Mod); - ans *= ans; - ans %= Mod; - if (b % 2) { - ans *= a; - } - return ans % Mod; -} - -ll getMin(vector arr, int n) -{ - ll res = arr[0]; - for (int i = 1; i < n; i++) - res = min(res, arr[i]); - return res; -} -ll getMax(vector arr, int n) -{ - ll res = arr[0]; - for (int i = 1; i < n; i++) - res = max(res, arr[i]); - return res; -} - -string adder(string s1, string s2) { - vector num; - int len1 = s1.length(); - int len2 = s2.length(); - int len = max(len1, len2); - for (int i = len1 + 1; i <= len; i++) s1 = ""0"" + s1; - for (int i = len2 + 1; i <= len; i++) s2 = ""0"" + s2; - for (int i = 0; i < len + 1; i++) num.push_back(0); - int c = num.size(); - for (int i = 0; i < len; i++) { - int x1 = s1[len - 1 - i] - '0'; - int x2 = s2[len - 1 - i] - '0'; - num[c - 1 - i] += (x1 + x2); - num[c - 1 - i - 1] += num[c - 1 - i] / 10; - num[c - 1 - i] = num[c - 1 - i] % 10; - } - string ans = """"; - int idx = 0; - for (int i = 0; i < c; i++) { - if (num[i] != 0) { - idx = i; break; - } - } - for (int i = idx; i < c; i++) { - ans += to_string(num[i]); - } - return ans; -} - -ll accurateFloor(ll a, ll b) { - ll val = a / b; - while (val * b > a) - val--; - return val; -} - -vi formSum(ll n, ll val) { - vi a(n+1); - ll s = val; - int idx = n; - while (s!=0) { - if (s > idx) { - a[idx] = 1; - s -= idx; - idx--; - } - else { - a[s] = 1; - break; - } - } - return a; -} - -void place(vector& arr, int l, int r, int i, vector& A) { - if (l > r) return; - int idx = (l + r) / 2; - arr[idx] = A[i]; - place(arr, l, idx - 1, 2 * i + 1, A); - place(arr, idx + 1, r, 2 * i + 2, A); -} -struct Node -{ - int data; - Node* left, * right; -}; - -/* Helper function that allocates a -new node */ -Node* newNode(int data) -{ - Node* node = (Node*)malloc(sizeof(Node)); - node->data = data; - node->left = node->right = NULL; - return (node); -} - -// Function to insert nodes in level order -Node* insertLevelOrder(vector arr, - int i, int n) -{ - Node* root = nullptr; - // Base case for recursion - if (i < n) - { - root = newNode(arr[i]); - - // insert left child - root->left = insertLevelOrder(arr, - 2 * i + 1, n); - - // insert right child - root->right = insertLevelOrder(arr, - 2 * i + 2, n); - } - return root; -} - -// Function to print tree nodes in -// InOrder fashion -void inOrder(Node* root, vector& v) -{ - if (root != NULL) - { - inOrder(root->left, v); - v.push_back(root->data); - inOrder(root->right, v); - } -} - -bool ingrid(int x, int y, int n, int m) { - if (x >= 0 && x < n && y >= 0 && y < m) return true; - else return false; -} - -set st; -void solve(string s,int K){ - int cnt = 0; - for (int i = 0; i < 7; i++) { - if (s[i] == '?') cnt++; - } - if (cnt == 0) { - int sum = 0; - for (int i = 0; i < s.length(); i++) { - sum += (s[i] - '0'); - } - if (sum == K) st.insert(s); - return; - } - - int idx = 0; - for (int i = 0; i < 7; i++) { - if (s[i] == '?') { - idx = i; break; - } - } - string f = """"; - for (int i = 0; i < idx; i++) f = f + s[i]; - string g = """"; - for (int i = idx + 1; i < s.length(); i++) g = g + s[i]; - for (int i = 0; i <= 8; i++) { - solve(f + to_string(i) + g, K); - } - -} - -int maximumpoints(vector > arr, int n, int x, int y) { - // code here - vector> m(1001, vector(1001, 0)); - for (int i = 0; i < n; i++) { - m[arr[i][0]][arr[i][1]]++; - } - int ans = 0; - for (int i = 1; i <= 1000; i++) { - for (int j = 1; j <= 1000; j++) { - m[i][j] += (m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]); - if (i - x > 0 && j - y > 0) { - ans = max(ans, m[i][j] + m[i - x - 1][j - y - 1] - m[i][j - y - 1] - m[i - x - 1][j]); - } - } - } - return ans; -} - -string func(string s, int k) { - stack> st; - st.push({ '#',0}); - for (int i = 0; i < s.length(); i++) { - char c = s[i]; - if (c == st.top().first) { - st.top().second++; - } - else { - st.push({ c,1 }); - } - - if (st.top().second >= k) { - st.pop(); - } - } - - string ans = """"; - - while (!st.empty()) { - pair p = st.top(); - st.pop(); - char ch = p.first; - int num = p.second; - for (int var = 0; var < num; var++) { - ans = ch + ans; - } - } - return ans; -} - -bool cmp(pair p1, pair p2) { - if (p1.first < p2.first) return true; - /*else{ - if(p1.second.length() p1, pair p2) { - if (p1.first != p2.first) return p1.first < p2.first; - else p1.second < p2.second; -} - -bool cmp2(pair p1, pair p2) { - return p1.second < p2.second; -} - - -string MostFrequent(string str) { - string s = """"; - map mp; - for (int i = 0; i < str.length(); i++) { - if (str[i] != ' ') s = s + str[i]; - else { - mp[s]++; - s = """"; - } - } - mp[s]++; - map::iterator it; - string ans = """"; - int cnt = 0; - for (it = mp.begin(); it != mp.end(); it++) { - if (it->second > cnt) { - ans = it->first; - cnt = it->second; - } - } - return ans; -} - -vector reverse(vll vec) { - int sz = vec.size(); - for (int i = 0; i < sz / 2; i++) vec[i] = vec[sz - 1 - i]; - return vec; -} -vector replace(vll vec) { - int sz = vec.size(); - vll nv; - rep(i, sz - 1) { nv.push_back(vec[i + 1] - vec[i]); } - return nv; -} - -#define print(vec) rep(i,vec.size()) cout<> t; - rep(test, t) { - int n; cin >> n; - vll a; - ll ans = 0; - rep(i, n) { - int var; cin >> var; a.pb(var); - ans += var; - } - for (int c = 0; c < n - 1; c++) { - ans = max(ans, abs(a[a.size() - 1] - a[0])); - a = replace(a); - } - cout << ans << endl; - } - - return 0; -} - - - - - - -","//Coded by:-suvampaul -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - - -#define ll long long -#define pb push_back -#define pll pair -#define mll map -#define pii pair -#define vpii vector -#define rep(i,n) for(int i=0; i>a[i] -#define vi vector -#define vll vector -#define nl ""\n"" -#define print(arr) All(x,arr) cout<>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);} -#define vdsort(v) sort(v.begin(),v.end(),greater()) -#define F first -#define S second -#define mod 1'000'000'007 - - -const int MAXN = 100'005; -int spf[MAXN]; -ll fac1[MAXN], fac2[MAXN], inv[MAXN]; -ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } - -template ()))>, typename std::enable_if::value>::type* = nullptr> -std::ostream& operator<<(std::ostream& os, const C& container) -{ - bool first = true; - std::stringstream ss; - ss << '['; - for (const auto& x : container) - { - if (!first) - { - ss << "", ""; - } - first = false; - ss << x; - } - ss << ']'; - return os << ss.str(); -} -template -std::ostream& operator<<(std::ostream& os, const std::pair& p) -{ - os << '{' << p.first << "", "" << p.second << '}'; - return os; -} -vector vec_splitter(string S) -{ - S += ','; - vector res; - while (!S.empty()) - { - res.push_back(S.substr(0, S.find(','))); - S = S.substr(S.find(',') + 1); - } - return res; -} - -template -void debug_out(vector args, int idx, int LINE_NUM, Head H, Tail... T) -{ - if (idx > 0) - cerr << "", ""; - else - cerr << ""Line("" << LINE_NUM << "") ""; - stringstream ss; - ss << H; - cerr << args[idx] << "" = "" << ss.str(); - debug_out(args, idx + 1, LINE_NUM, T...); -} -#ifdef DEBUG -#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) -#else -#define debug(...) 42 -#endif - -bool isPerfectSquare(long double x) -{ - if (x >= 0) { - long long sr = sqrt(x); - return (sr * sr == x); - } - return false; -} - -bool isPowerof2(int n, int) { - return (n && !(n & n - 1)); -} - -string decimalToBin(ll N) -{ - string B_Number = """"; - int c = 0; - while (N != 0) { - if (N % 2 == 0) { - B_Number = ""0"" + B_Number; - } - else B_Number = ""1"" + B_Number; - N = N / 2; - c++; - } - - for (int i = c + 1; i <= 30; i++) { - B_Number = ""0"" + B_Number; - } - - return B_Number; -} - -int binaryToDecimal(ll n) -{ - ll num = n; - int dec_value = 0; - int base = 1; - ll temp = num; - - while (temp) { - int last_digit = temp % 10; - temp = temp / 10; - - dec_value += last_digit * base; - - base = base * 2; - } - - return dec_value; -} - - -ll min(ll a, ll b) { - return a < b ? a : b; -} -ll max(ll a, ll b) { - return a > b ? a : b; -} -ll power(ll a, ll b, ll Mod) { - if (b == 0) { - return 1; - } - ll ans = power(a, b / 2, Mod); - ans *= ans; - ans %= Mod; - if (b % 2) { - ans *= a; - } - return ans % Mod; -} - -ll getMin(vector arr, int n) -{ - ll res = arr[0]; - for (int i = 1; i < n; i++) - res = min(res, arr[i]); - return res; -} -ll getMax(vector arr, int n) -{ - ll res = arr[0]; - for (int i = 1; i < n; i++) - res = max(res, arr[i]); - return res; -} - -string adder(string s1, string s2) { - vector num; - int len1 = s1.length(); - int len2 = s2.length(); - int len = max(len1, len2); - for (int i = len1 + 1; i <= len; i++) s1 = ""0"" + s1; - for (int i = len2 + 1; i <= len; i++) s2 = ""0"" + s2; - for (int i = 0; i < len + 1; i++) num.push_back(0); - int c = num.size(); - for (int i = 0; i < len; i++) { - int x1 = s1[len - 1 - i] - '0'; - int x2 = s2[len - 1 - i] - '0'; - num[c - 1 - i] += (x1 + x2); - num[c - 1 - i - 1] += num[c - 1 - i] / 10; - num[c - 1 - i] = num[c - 1 - i] % 10; - } - string ans = """"; - int idx = 0; - for (int i = 0; i < c; i++) { - if (num[i] != 0) { - idx = i; break; - } - } - for (int i = idx; i < c; i++) { - ans += to_string(num[i]); - } - return ans; -} - -ll accurateFloor(ll a, ll b) { - ll val = a / b; - while (val * b > a) - val--; - return val; -} - -vi formSum(ll n, ll val) { - vi a(n+1); - ll s = val; - int idx = n; - while (s!=0) { - if (s > idx) { - a[idx] = 1; - s -= idx; - idx--; - } - else { - a[s] = 1; - break; - } - } - return a; -} - -void place(vector& arr, int l, int r, int i, vector& A) { - if (l > r) return; - int idx = (l + r) / 2; - arr[idx] = A[i]; - place(arr, l, idx - 1, 2 * i + 1, A); - place(arr, idx + 1, r, 2 * i + 2, A); -} -struct Node -{ - int data; - Node* left, * right; -}; - -/* Helper function that allocates a -new node */ -Node* newNode(int data) -{ - Node* node = (Node*)malloc(sizeof(Node)); - node->data = data; - node->left = node->right = NULL; - return (node); -} - -// Function to insert nodes in level order -Node* insertLevelOrder(vector arr, - int i, int n) -{ - Node* root = nullptr; - // Base case for recursion - if (i < n) - { - root = newNode(arr[i]); - - // insert left child - root->left = insertLevelOrder(arr, - 2 * i + 1, n); - - // insert right child - root->right = insertLevelOrder(arr, - 2 * i + 2, n); - } - return root; -} - -// Function to print tree nodes in -// InOrder fashion -void inOrder(Node* root, vector& v) -{ - if (root != NULL) - { - inOrder(root->left, v); - v.push_back(root->data); - inOrder(root->right, v); - } -} - -bool ingrid(int x, int y, int n, int m) { - if (x >= 0 && x < n && y >= 0 && y < m) return true; - else return false; -} - -set st; -void solve(string s,int K){ - int cnt = 0; - for (int i = 0; i < 7; i++) { - if (s[i] == '?') cnt++; - } - if (cnt == 0) { - int sum = 0; - for (int i = 0; i < s.length(); i++) { - sum += (s[i] - '0'); - } - if (sum == K) st.insert(s); - return; - } - - int idx = 0; - for (int i = 0; i < 7; i++) { - if (s[i] == '?') { - idx = i; break; - } - } - string f = """"; - for (int i = 0; i < idx; i++) f = f + s[i]; - string g = """"; - for (int i = idx + 1; i < s.length(); i++) g = g + s[i]; - for (int i = 0; i <= 8; i++) { - solve(f + to_string(i) + g, K); - } - -} - -int maximumpoints(vector > arr, int n, int x, int y) { - // code here - vector> m(1001, vector(1001, 0)); - for (int i = 0; i < n; i++) { - m[arr[i][0]][arr[i][1]]++; - } - int ans = 0; - for (int i = 1; i <= 1000; i++) { - for (int j = 1; j <= 1000; j++) { - m[i][j] += (m[i - 1][j] + m[i][j - 1] - m[i - 1][j - 1]); - if (i - x > 0 && j - y > 0) { - ans = max(ans, m[i][j] + m[i - x - 1][j - y - 1] - m[i][j - y - 1] - m[i - x - 1][j]); - } - } - } - return ans; -} - -string func(string s, int k) { - stack> st; - st.push({ '#',0}); - for (int i = 0; i < s.length(); i++) { - char c = s[i]; - if (c == st.top().first) { - st.top().second++; - } - else { - st.push({ c,1 }); - } - - if (st.top().second >= k) { - st.pop(); - } - } - - string ans = """"; - - while (!st.empty()) { - pair p = st.top(); - st.pop(); - char ch = p.first; - int num = p.second; - for (int var = 0; var < num; var++) { - ans = ch + ans; - } - } - return ans; -} - -bool cmp(pair p1, pair p2) { - if (p1.first < p2.first) return true; - /*else{ - if(p1.second.length() p1, pair p2) { - if (p1.first != p2.first) return p1.first < p2.first; - else p1.second < p2.second; -} - -bool cmp2(pair p1, pair p2) { - return p1.second < p2.second; -} - - -string MostFrequent(string str) { - string s = """"; - map mp; - for (int i = 0; i < str.length(); i++) { - if (str[i] != ' ') s = s + str[i]; - else { - mp[s]++; - s = """"; - } - } - mp[s]++; - map::iterator it; - string ans = """"; - int cnt = 0; - for (it = mp.begin(); it != mp.end(); it++) { - if (it->second > cnt) { - ans = it->first; - cnt = it->second; - } - } - return ans; -} - -vector reverse(vi vec) { - int sz = vec.size(); - for (int i = 0; i < sz / 2; i++) vec[i] = vec[sz - 1 - i]; - return vec; -} -vector replace(vi vec) { - int sz = vec.size(); - vi nv; - rep(i, sz - 1) { nv.push_back(vec[i + 1] - vec[i]); } - return nv; -} - -#define print(vec) rep(i,vec.size()) cout<> t; - rep(test, t) { - int n; cin >> n; - vi a; - ll ans = 0; - rep(i, n) { - int var; cin >> var; a.pb(var); - ans += var; - } - for (int c = 0; c < n - 1; c++) { - ans = max(ans, abs(a[a.size() - 1] - a[0])); - a = replace(a); - } - cout << ans << endl; - } - - return 0; -} - - - - - - -",1 -madhavxmiglani,2062C - Cirno and Operations,c++23 ,303948253,303948444,"#include -#include -#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - long long int arr[n]; - long long int ans=0; - - for(int i=0;i>arr[i]; - ans +=arr[i]; - } - if(n==1){ - cout< -#include -#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - long long int arr[n]; - long long int ans=0; - - for(int i=0;i>arr[i]; - ans +=arr[i]; - } - if(n==1){ - cout< -using namespace std; -using ll=long long; - -const int MOD=1e9+7; -const ll INF=1e18; - -void run_case(){ - int n; - cin>>n; - vectora(n+1); - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - ll ans=LLONG_MIN; - int curr=n; - for(int i=1;i<=n;i++){ - ll sum=0; - for(int j=1;j<=curr;j++){ - sum+=a[j]; - } - if(i==1){ - ans=max(ans,sum); - } - else{ - ans=max(ans, max(sum, -sum)); - } - for(int j=1;jsync_with_stdio(0); - int tt; - cin>>tt; - - while(tt--){ - run_case(); - } -}","#include -using namespace std; -using ll=long long; - -const int MOD=1e9+7; -const ll INF=1e18; - -void run_case(){ - int n; - cin>>n; - vectora(n+1); - for(int i=1;i<=n;i++){ - cin>>a[i]; - } - ll ans=LLONG_MIN; - int curr=n; - for(int i=1;i<=n;i++){ - ll sum=0; - for(int j=1;j<=curr;j++){ - sum+=a[j]; - } - if(i==1){ - ans=max(ans,sum); - } - else{ - ans=max(ans, max(sum, -sum)); - } - for(int j=1;jsync_with_stdio(0); - int tt; - cin>>tt; - - while(tt--){ - run_case(); - } -}",1 -rijjubabu,2062C - Cirno and Operations,python,305113770,305112519,"for _ in range(int(input())): - - n = int(input()) - arr = list(map(int, input().split())) - - ans = sum(arr) - - while len(arr) > 1: - arr = [arr[i+1]-arr[i] for i in range(len(arr)-1)] - ans = max(ans, abs(sum(arr))) - - print(ans)","for _ in range(int(input())): - - n = int(input()) - arr = list(map(int, input().split())) - - ans = sum(arr) - - for i in range(n-1, -1, -1): - if i > 1: - arr = [arr[j+1]-arr[j] for j in range(i)] - ans = max(ans, abs(sum(arr))) - print(ans)",1 -Vadimchik133,2062C - Cirno and Operations,python,304537596,304538628,"mod = 1e9 + 7 - - -def binpow(a, n): - res = 1 - while n != 0: - print(bin(n)) - if n & 1: - res = res * a % mod - a = a * a % mod - n >>= 1 - return res - - -def resheto(n): - # n = int(input()) - primes = [int(a) for a in range(n + 1)] - primes[1] = 0 - - i = 2 - while i <= n: - j = i + i - while j <= n: - primes[j] = 0 - j += i - - i += 1 - primes = [i for i in primes if i != 0] - return primes - - -def delit(x): - arr = [] - for i in range(2, int(x ** 0.5) + 1): - if x % i == 0: - arr.append(i) - arr.append(x // i) - return sorted(arr) - - -# n, k = 100000, 1 -# arr = [10000] * 99999 -# arr.append(-1) - - -def xfind(arr, x): - r = len(arr) - 1 - l = 0 - while l <= r: - mid = (l + r) // 2 - - if arr[mid] == x: - return True - - elif arr[mid] < x: - l = mid + 1 - - elif arr[mid] > x: - r = mid - 1 - - return False - - - -from math import ceil -import bisect - -from decimal import Decimal, getcontext - -getcontext().prec = 15 -# -# resh = resheto(10**6) - -# def s(arr): -# s = 0 -# for i in range(len(arr)): -# mn = 1000000 -# for j in range(i, len(arr)): -# mn = min(mn, arr[j]) -# s += mn -# print(s) - - -from bisect import bisect_left, bisect_right - -# def bs_l(a, x, lo=0, hi=None): -# if hi is None: hi = len(a) -# pos = bisect_left(a, x, lo, hi) -# return pos if pos != hi and a[pos] == x else -1 -# -# def bs_r(a, x, lo=0, hi=None): -# if hi is None: hi = len(a) -# pos = bisect_right(a, x, lo, hi) -# return pos if pos != hi and a[pos] == x else -1 - -def pref_sum(arr): - pref_sum_arr = [0] * len(arr) - pref_sum_arr[0] = arr[0] - for i in range(1, len(arr)): - pref_sum_arr[i] = pref_sum_arr[i-1] + arr[i] - return pref_sum_arr - - -def fibonacci(n): - if n < 2: - return n - pp = 0 - p = 1 - for i in range(n - 1): - pp, p = p, pp + p - return p - - -import math -def fibonacci_binet(n): - sqrt5 = math.sqrt(5) - phi = (1 + sqrt5) / 2 - psi = (1 - sqrt5) / 2 - return round((phi**n - psi**n) / sqrt5) - - -from math import ceil -from bisect import bisect_left, bisect_right -from math import gcd, factorial -from decimal import Decimal -getcontext().prec = 4 - - -def new_arr(arr): - x = [] - for i in range(len(arr) - 1): - x.append(arr[i+1] - arr[i]) - return x - -def solve(): - n = int(input()) - arr = [int(a) for a in input().split()] - while len(arr) > 1: - rev_arr = arr[::-1] - if len(arr) == 2 and arr[0] > 0 and arr[1] > 0: - print(sum(arr)) - return - if sum(new_arr(rev_arr)) < sum(new_arr(arr)): - arr = new_arr(arr) - else: - arr = new_arr(rev_arr) - print(sum(arr)) - - -def main(): - t = int(input()) - for _ in range(t): - # if _ == 152: - # n, k = map(int, input().split()) - # s = input() - # print(s) - # else: - solve() - - -main() - -","mod = 1e9 + 7 - - -def binpow(a, n): - res = 1 - while n != 0: - print(bin(n)) - if n & 1: - res = res * a % mod - a = a * a % mod - n >>= 1 - return res - - -def resheto(n): - # n = int(input()) - primes = [int(a) for a in range(n + 1)] - primes[1] = 0 - - i = 2 - while i <= n: - j = i + i - while j <= n: - primes[j] = 0 - j += i - - i += 1 - primes = [i for i in primes if i != 0] - return primes - - -def delit(x): - arr = [] - for i in range(2, int(x ** 0.5) + 1): - if x % i == 0: - arr.append(i) - arr.append(x // i) - return sorted(arr) - - -# n, k = 100000, 1 -# arr = [10000] * 99999 -# arr.append(-1) - - -def xfind(arr, x): - r = len(arr) - 1 - l = 0 - while l <= r: - mid = (l + r) // 2 - - if arr[mid] == x: - return True - - elif arr[mid] < x: - l = mid + 1 - - elif arr[mid] > x: - r = mid - 1 - - return False - - - -from math import ceil -import bisect - -from decimal import Decimal, getcontext - -getcontext().prec = 15 -# -# resh = resheto(10**6) - -# def s(arr): -# s = 0 -# for i in range(len(arr)): -# mn = 1000000 -# for j in range(i, len(arr)): -# mn = min(mn, arr[j]) -# s += mn -# print(s) - - -from bisect import bisect_left, bisect_right - -# def bs_l(a, x, lo=0, hi=None): -# if hi is None: hi = len(a) -# pos = bisect_left(a, x, lo, hi) -# return pos if pos != hi and a[pos] == x else -1 -# -# def bs_r(a, x, lo=0, hi=None): -# if hi is None: hi = len(a) -# pos = bisect_right(a, x, lo, hi) -# return pos if pos != hi and a[pos] == x else -1 - -def pref_sum(arr): - pref_sum_arr = [0] * len(arr) - pref_sum_arr[0] = arr[0] - for i in range(1, len(arr)): - pref_sum_arr[i] = pref_sum_arr[i-1] + arr[i] - return pref_sum_arr - - -def fibonacci(n): - if n < 2: - return n - pp = 0 - p = 1 - for i in range(n - 1): - pp, p = p, pp + p - return p - - -import math -def fibonacci_binet(n): - sqrt5 = math.sqrt(5) - phi = (1 + sqrt5) / 2 - psi = (1 - sqrt5) / 2 - return round((phi**n - psi**n) / sqrt5) - - -from math import ceil -from bisect import bisect_left, bisect_right -from math import gcd, factorial -from decimal import Decimal -getcontext().prec = 4 - - -def new_arr(arr): - x = [] - for i in range(len(arr) - 1): - x.append(arr[i+1] - arr[i]) - return x - -def solve(): - n = int(input()) - arr = [int(a) for a in input().split()] - ans = sum(arr) - - while len(arr) > 1: - rev_arr = new_arr(arr[::-1]) - arr = new_arr(arr) - ans = max(ans, sum(arr), sum(rev_arr)) - - print(ans) - - -def main(): - t = int(input()) - for _ in range(t): - # if _ == 152: - # n, k = map(int, input().split()) - # s = input() - # print(s) - # else: - solve() - - -main() - -",2 -whiteLily1,2062C - Cirno and Operations,c++20 ,306150718,306150563,"/* Gauri Jain - 2312004 */ - -#include -using namespace std; - -#pragma comment(linker, ""/stack:200000000"") -#pragma GCC optimize(""O1"") -#pragma GCC optimize(""O2"") -#pragma GCC optimize(""Ofast"") -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx,avx2,fma"") -#pragma GCC target(""sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"") - -#define endl ""\n"" -#define ll long long -#define EPS 1e-9 -#define fl(a, b) for (int i = a; i < b; i++) -#define getarr(n) int* arr = new int[n]; fl(i, n) { cin >> arr[i]; } -#define getv(v, n) vector v; fl(0, n) { int el; cin >> el; v.push_back(el); } -#define sortv(v) sort(v.begin(), v.end()) - -/* Debug Code */ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } - -template -void __print(const A &x); -template -void __print(const pair &p); -template -void __print(stack s); -template -void __print(queue q); -template -void __print(priority_queue q); - -template -void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""); - __print(i); - first = false; - } - cerr << '}'; -} - -template -void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} - -template -void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} - -template -void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} - -template -void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} - -void _print() { cerr << ""]\n""; } - -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} - -bool isInteger(double num) { - return floor(num) == num; -} - -void print(vector &arr) { - for (int i = 0; i < arr.size(); i++) { - cout << arr[i] << "" ""; - } - cout << endl; -} - -string decimalToBinary(int n) { - if (n == 0) return ""0""; - string binary = """"; - while (n > 0) { - binary += std::to_string(n % 2); - n /= 2; - } - reverse(binary.begin(), binary.end()); - return binary; -} -#ifndef ONLINE_JUDGE -#define debug(...) cerr << ""Line: "" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = ["", _print(__VA_ARGS__) -#else -#define debug(...) -#endif -void solve(){ - int n; cin >> n; - vector a(n); - for(int i=0; i> a[i]; - ll sum = 0, maxi = LLONG_MIN; - if(n == 1){ - cout << a[0] << endl; - return; - } - for(int i=0; i> t; - while (t--) { - solve(); - } - return 0; -} -","/* Gauri Jain - 2312004 */ - -#include -using namespace std; - -#pragma comment(linker, ""/stack:200000000"") -#pragma GCC optimize(""O1"") -#pragma GCC optimize(""O2"") -#pragma GCC optimize(""Ofast"") -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx,avx2,fma"") -#pragma GCC target(""sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"") - -#define endl ""\n"" -#define ll long long -#define EPS 1e-9 -#define fl(a, b) for (int i = a; i < b; i++) -#define getarr(n) int* arr = new int[n]; fl(i, n) { cin >> arr[i]; } -#define getv(v, n) vector v; fl(0, n) { int el; cin >> el; v.push_back(el); } -#define sortv(v) sort(v.begin(), v.end()) - -/* Debug Code */ -void __print(int x) { cerr << x; } -void __print(long x) { cerr << x; } -void __print(long long x) { cerr << x; } -void __print(unsigned x) { cerr << x; } -void __print(unsigned long x) { cerr << x; } -void __print(unsigned long long x) { cerr << x; } -void __print(float x) { cerr << x; } -void __print(double x) { cerr << x; } -void __print(long double x) { cerr << x; } -void __print(char x) { cerr << '\'' << x << '\''; } -void __print(const char *x) { cerr << '\""' << x << '\""'; } -void __print(const string &x) { cerr << '\""' << x << '\""'; } -void __print(bool x) { cerr << (x ? ""true"" : ""false""); } - -template -void __print(const A &x); -template -void __print(const pair &p); -template -void __print(stack s); -template -void __print(queue q); -template -void __print(priority_queue q); - -template -void __print(const A &x) { - bool first = true; - cerr << '{'; - for (const auto &i : x) { - cerr << (first ? """" : "",""); - __print(i); - first = false; - } - cerr << '}'; -} - -template -void __print(const pair &p) { - cerr << '('; - __print(p.first); - cerr << ','; - __print(p.second); - cerr << ')'; -} - -template -void __print(stack s) { - vector debugVector; - while (!s.empty()) { - T t = s.top(); - debugVector.push_back(t); - s.pop(); - } - reverse(debugVector.begin(), debugVector.end()); - __print(debugVector); -} - -template -void __print(queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.front(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} - -template -void __print(priority_queue q) { - vector debugVector; - while (!q.empty()) { - T t = q.top(); - debugVector.push_back(t); - q.pop(); - } - __print(debugVector); -} - -void _print() { cerr << ""]\n""; } - -template -void _print(const Head &H, const Tail &...T) { - __print(H); - if (sizeof...(T)) - cerr << "", ""; - _print(T...); -} - -bool isInteger(double num) { - return floor(num) == num; -} - -void print(vector &arr) { - for (int i = 0; i < arr.size(); i++) { - cout << arr[i] << "" ""; - } - cout << endl; -} - -string decimalToBinary(int n) { - if (n == 0) return ""0""; - string binary = """"; - while (n > 0) { - binary += std::to_string(n % 2); - n /= 2; - } - reverse(binary.begin(), binary.end()); - return binary; -} -#ifndef ONLINE_JUDGE -#define debug(...) cerr << ""Line: "" << __LINE__ << "" ["" << #__VA_ARGS__ << ""] = ["", _print(__VA_ARGS__) -#else -#define debug(...) -#endif -void solve(){ - int n; cin >> n; - vector a(n); - for(int i=0; i> a[i]; - ll sum = 0, maxi = LLONG_MIN; - if(n == 1){ - cout << a[0] << endl; - return; - } - for(int i=0; i> t; - while (t--) { - solve(); - } - return 0; -} -",1 -kaslana-k423,2062C - Cirno and Operations,c++17 ,308249414,308249301,"// 主函数,程序的入口点 -#include -// #define int long long -#define ios ios::sync_with_stdio(false), cin.tie(nullptr) -using namespace std; -const int N = 2e5 + 7, modd = 998244353, mod = 1e9 + 7, inf = 0x3f3f3f; -#define endl '\n' -#define ll long long -#define int long long -signed main() -{ - // 定义变量 t,用于存储测试数据的组数 - int t; - // 从标准输入读取测试数据的组数 - cin >> t; - // 循环处理每组测试数据 - while (t--) - { - // 定义变量 n,用于存储当前测试数据中序列的长度 - int n; - // 从标准输入读取序列的长度 - cin >> n; - // 定义数组 a,用于存储序列的元素 - vector a(n + 1); - // 循环读取序列的每个元素,并存储在数组 a 中 - for (int i = 1; i <= n; i++) - cin >> a[i]; - // 初始化当前序列的长度为 n - int now = n; - // 初始化最终结果为一个极小值 - long long ans = -1e18; - // 主循环,控制处理的轮数 - for (int i = 1; i <= n; i++) - { - // 初始化当前序列的和为 0 - long long sum = 0; - // 计算当前序列的和 - for (int j = 1; j <= now; j++) - sum = (sum + a[j]); - // 如果是第一轮处理,直接更新 ans 为 ans 和 sum 中的较大值 - if (i == 1) - ans = max(ans, sum); - // 否则,更新 ans 为 ans、sum 和 -sum 中的最大值 - else - ans = max(ans, max(sum, (-sum))); - // 对当前序列进行差分操作 - for (int j = 1; j < now; j++) - a[j] = (a[j + 1] - a[j]); - // 序列长度减 1 - now--; - } - // 输出最终的最大值 - cout << ans << endl; - } - // 程序正常结束 - return 0; -}","// 主函数,程序的入口点 -#include -// #define int long long -#define ios ios::sync_with_stdio(false), cin.tie(nullptr) -using namespace std; -const int N = 2e5 + 7, modd = 998244353, mod = 1e9 + 7, inf = 0x3f3f3f; -#define endl '\n' -#define ll long long -int main() -{ - // 定义变量 t,用于存储测试数据的组数 - int t; - // 从标准输入读取测试数据的组数 - cin >> t; - // 循环处理每组测试数据 - while (t--) - { - // 定义变量 n,用于存储当前测试数据中序列的长度 - int n; - // 从标准输入读取序列的长度 - cin >> n; - // 定义数组 a,用于存储序列的元素 - vector a(n + 1); - // 循环读取序列的每个元素,并存储在数组 a 中 - for (int i = 1; i <= n; i++) - cin >> a[i]; - // 初始化当前序列的长度为 n - int now = n; - // 初始化最终结果为一个极小值 - long long ans = -1e18; - // 主循环,控制处理的轮数 - for (int i = 1; i <= n; i++) - { - // 初始化当前序列的和为 0 - long long sum = 0; - // 计算当前序列的和 - for (int j = 1; j <= now; j++) - sum = (sum + a[j]); - // 如果是第一轮处理,直接更新 ans 为 ans 和 sum 中的较大值 - if (i == 1) - ans = max(ans, sum); - // 否则,更新 ans 为 ans、sum 和 -sum 中的最大值 - else - ans = max(ans, max(sum, (-sum))); - // 对当前序列进行差分操作 - for (int j = 1; j < now; j++) - a[j] = (a[j + 1] - a[j]); - // 序列长度减 1 - now--; - } - // 输出最终的最大值 - cout << ans << endl; - } - // 程序正常结束 - return 0; -}",1 -canItouchYourfeet,2062C - Cirno and Operations,c++20 ,308897331,308898442,"#include -#include -#include -using namespace std; -typedef long long LL; -const LL INF = 1e18; -void solve(){ - int n;cin >> n; - vectora(n+1,0); - for(int i = 1;i <= n;i++) cin >> a[i]; - if(n==1){ - cout<> T; - while(T-- )solve(); - return 0; -}","#include -#include -#include -using namespace std; -typedef long long LL; -const LL INF = 1e18; -void solve(){ - int n;cin >> n; - vectora(n+1,0); - for(int i = 1;i <= n;i++) cin >> a[i]; - if(n==1){ - cout<> T; - while(T-- )solve(); - return 0; -}",2 -Gowtham569,2062C - Cirno and Operations,c++17 ,307111305,307110993,"#include -using namespace std; -#define pb push_back -#define all(a) (a).begin(), (a).end() -#define X(a) (a).begin(), (a).begin() -#define ii pair -typedef long long int ll; -int main(){ - int t; - cin>>t; - while(t--){ - int n;cin>>n; - vectora(n); - for(int i=0;i>a[i]; - if(n==1){ - cout< -using namespace std; -#define pb push_back -#define all(a) (a).begin(), (a).end() -#define X(a) (a).begin(), (a).begin() -#define ii pair -typedef long long int ll; -int main(){ - int t; - cin>>t; - while(t--){ - int n;cin>>n; - vectora(n); - for(int i=0;i>a[i]; - if(n==1){ - cout< -using namespace std; - -#define ll long long -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define nl cout << '\n'; -#define pb push_back -#define F first -#define S second -#define mp make_pair -#define mod 1000000007 -#define make(n) ll n; cin >> n; -#define makech(ch) char ch; cin >> ch; -#define makestr(s) string s; cin >> s; -#define show(n) cout << n << endl; -#define makearr(a, n) vector a(n); for (int i = 0; i < n; i++){ cin >> a[i]; } -#define make2d(a, n, m) vector> a(n, vector(m)); for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cin >> a[i][j]; } } -#define all(v) v.begin(), v.end() -#define showarr(a, n) for (int i = 0; i < n; i++){ cout << a[i] << "" ""; } cout << '\n'; -#define vvi vector> -#define vvl vector> - -vector generatePascalsTriangleLine(int n) { - vector line(n + 1, 1); - for (int i = 1; i < n; i++){ - line[i] = line[i - 1] * (n - i + 1) / i; - } - return line; -} - -int main(){ - ios::sync_with_stdio(0); - cin.tie(0); - - make(t); - while(t--){ - make(n); - makearr(arr, n) - ll sum = 0; for (int i = 0; i < n; i++) sum += arr[i]; - if(n == 1){ show(sum) continue; } - - vector gpt = generatePascalsTriangleLine(n - 1); - - ll F_sum = 0, G_sum = 0; - for (int i = 0; i < n; i++){ - F_sum += ((n - 1 - i) % 2 ? -1LL : 1LL) * gpt[i] * arr[i]; - G_sum += (i % 2 ? -1LL : 1LL) * gpt[i] * arr[i]; - } - ll ans = max({sum, (ll)abs(F_sum), (ll)abs(G_sum)}); - show(ans) - } - return 0; -} -","#include -using namespace std; - -#define ll long long -#define yes cout << ""YES"" << endl; -#define no cout << ""NO"" << endl; -#define nl cout << '\n'; -#define pb push_back -#define F first -#define S second -#define mp make_pair -#define mod 1000000007 -#define make(n) ll n; cin >> n; -#define makech(ch) char ch; cin >> ch; -#define makestr(s) string s; cin >> s; -#define show(n) cout << n << endl; -#define makearr(a, n) vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } -#define make2d(a, n, m) vvi a(n, vector(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } -#define all(v) v.begin(), v.end() -#define showme(a) for(auto it:a){cout<> -#define vvl vector> -#define forl(n) for(int i=0; i generatePascalsTriangleLine(int n) { - vector line(n + 1, 1); - for (int i = 1; i < n; i++) { - line[i] = line[i - 1] * (n - i + 1) / i; - } - return line; -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); - - make(t); - while (t--) { - make(n); - makearr(arr, n) - - ll sum = 0, ans = 0; - for(int i=0; icurr=arr; - while(curr.size()>1){ - vectordiff; - for(int i=0; i -using namespace std; -#define int long long -int sum(vector&v){ - int tot = 0; - for(int i = 1;i < v.size();i++) - tot += v[i] - v[i - 1] ; - return tot; -} -int sumall(vector&v){ - int sum = 0; - for(int i = 0;i < v.size();i++){ - sum +=v[i]; - } - return sum; -} -void _() -{ - int n; cin >> n; - vectorv(n); - for(int i = 0;i < n;i++) - cin >> v[i]; - int res = -1e10; - while(!v.empty()){ - res = max(res,sumall(v)); - vectora = v,b = v; - reverse(a.begin(),a.end()); - if(sum(a) > sum(b)){ - reverse(v.begin(),v.end()); - } - for(int i = 0;i < v.size() - 1;i++){ - v[i] = v[i + 1] - v[i]; - } - v.pop_back(); - } - cout << res << endl; -} -signed main() -{ - int t = 1;cin >> t; - while(t--) - { - _(); - } - return 0; -} -","#include -using namespace std; -#define int long long -int sum(vector&v){ - int tot = 0; - for(int i = 0;i < v.size() - 1;i++) - tot += v[i] - v[i + 1] ; - return tot; -} -int sumall(vector&v){ - int sum = 0; - for(int i = 0;i < v.size();i++){ - sum +=v[i]; - } - return sum; -} -void _() -{ - int n; cin >> n; - vectorv(n); - for(int i = 0;i < n;i++) - cin >> v[i]; - int res = -1e10; - while(!v.empty()){ - res = max(res,sumall(v)); - vectora = v,b = v; - reverse(a.begin(),a.end()); - if(sum(a) > sum(b)){ - reverse(v.begin(),v.end()); - } - for(int i = 0;i < v.size() - 1;i++){ - v[i] = v[i + 1] - v[i]; - } - v.pop_back(); - } - cout << res << endl; -} -signed main() -{ - int t = 1;cin >> t; - while(t--) - { - _(); - } - return 0; -} -",1 -baokeyuan1,2062C - Cirno and Operations,c++17 ,307517112,307517223,"#include -#define ll long long -using namespace std; -const int N = 50+5; -ll T,n,a[N]; -signed main(){ - ios::sync_with_stdio(false); - cin.tie(false),cout.tie(false); - cin>>T; - while(T--){ - cin>>n; - ll sum=0,maxx=0; - for(int i=1;i<=n;i++){ - cin>>a[i]; - sum+=a[i]; - } - maxx=sum; - for(int i=2;i<=n;i++){ - sum=0; - for(int j=n;j>=i;j--){ - a[j]=a[j]-a[j-1]; - sum+=a[j]; - } - maxx=max(maxx,(sum<0 ? -sum : sum)); - } - cout< -#define ll long long -using namespace std; -const int N = 50+5; -ll T,n,a[N]; -signed main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr),cout.tie(nullptr); - cin>>T; - while(T--){ - cin>>n; - ll sum=0,maxx=0; - for(int i=1;i<=n;i++){ - cin>>a[i]; - sum+=a[i]; - } - maxx=sum; - for(int i=2;i<=n;i++){ - sum=0; - for(int j=n;j>=i;j--){ - a[j]=a[j]-a[j-1]; - sum+=a[j]; - } - maxx=max(maxx,(sum<0 ? -sum : sum)); - } - cout< -#include -#include -#include - -using namespace std; - -vector replace( vector a){ - int size = a.size(); - vector rep_a; - - for( int i = 1;i < size; i++){ - rep_a.push_back(a[i] - a[i-1]); - } - - return rep_a; - -} - -int sum_array( vector a){ - int sum = 0; - for( int i =0; i < a.size(); i++){ - - sum += a[i]; - } - - return abs(sum); - -} - -int max_sum_sequence(int n , vector & a){ - if (n == 1) { - return a[0]; - } else if (n == 2) { - return max(a[0] + a[1], abs(a[0] - a[1])); - } else { - int sum = 0; - sum = sum_array(a); - - for( int j =0; j < n-1; j++ ){ - int rep_sum = 0; - a = replace(a); - rep_sum = sum_array(a); - if( rep_sum > sum ) sum = rep_sum; - - } - - return sum; - } -} - - -int main(){ - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - int result = max_sum_sequence(n, a); - cout << result << endl; - } - return 0; -}","#include -#include -#include -#include - -using ll = long long; - -using namespace std; - -vector replace( vector a){ - ll size = a.size(); - vector rep_a; - - for( ll i = 1;i < size; i++){ - rep_a.push_back(a[i] - a[i-1]); - } - - return rep_a; - -} - -ll sum_array( vector a){ - ll sum = 0; - for( ll i =0; i < a.size(); i++){ - - sum += a[i]; - } - - return sum; - -} - -ll max_sum_sequence(ll n , vector & a){ - vector temp; - - if (n == 1) { - return a[0]; - } else { - ll sum = 0; - sum = sum_array(a); - - for( ll j =0; j < n-1; j++ ){ - ll rep_sum = 0; - temp = replace(a); - a = temp; - rep_sum = abs(sum_array(a)); - if( rep_sum > sum ) sum = rep_sum; - } - - return sum; - } -} - - -int main(){ - ll t; - cin >> t; - while (t--) { - ll n; - cin >> n; - vector a(n); - for (ll i = 0; i < n; ++i) { - cin >> a[i]; - } - ll result = max_sum_sequence(n, a); - cout << result << endl; - } - return 0; -}",2 -joaopto,2062C - Cirno and Operations,c++17 ,305591350,305593569,"#include -#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define ll long long - -using namespace std; - -// Convert a vector of ints into a string key for memoization. -string vecToKey(const vector& arr) { - // We join numbers with a comma. - string key; - for (int x : arr) { - key += to_string(x) + "",""; - } - return key; -} - -unordered_map memo; - -ll F(const vector& arr) { - // Casos base - string key = vecToKey(arr); - if (memo.count(key)) - return memo[key]; // memoizacao - - if (arr.size() == 1) - return memo[key] = arr[0]; - - // Recursao - // Soma do original - ll sum1 = 0; - for (int x : arr) - sum1 += x; - - // Soma do invertido - vector rev(arr); - reverse(rev.begin(), rev.end()); - ll sum2 = 0; - for (int x : rev) - sum2 += x; - - // Sequencia original - vector diff1; - for (size_t i = 0; i < arr.size()-1; i++){ - diff1.push_back(arr[i+1] - arr[i]); - } - - // Sequencia invertida - vector diff2; - for (size_t i = 0; i < rev.size()-1; i++){ - diff2.push_back(rev[i+1] - rev[i]); - } - - ll ans = max({ sum1, sum2, F(diff1), F(diff2) }); - memo[key] = ans; - return ans; -} - -int main(){ - BOOST - - int t; - cin >> t; - while (t--){ - int n; - cin >> n; - vector arr(n); - for (int i = 0; i < n; i++){ - cin >> arr[i]; - } - memo.clear(); - cout << F(arr) << ""\n""; - } - return 0; -} -","/** - * SUGERIDO: - */ - -#include -#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define ll long long - -using namespace std; - -int main(){ - BOOST - - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector arr(n); - for (int i = 0; i < n; i++){ - cin >> arr[i]; - } - - // Se n = 1, nao precisa processar - if(n == 1){ - cout << arr[0] << ""\n""; - continue; - } - - // Se k = 0: nao calcula subtracoes - ll sum0 = 0; - for (ll x : arr) - sum0 += x; - ll best = sum0; // Nota, nao inverter para k=0 - - vector current = arr; - - // Para cada k de 1 ate n-1, aplicar operacao 2 (""Replace the sequence with its difference sequence"") - for (int k = 1; k < n; k++){ - vector next; - for (int i = 0; i < (int)current.size() - 1; i++){ - next.push_back(current[i+1] - current[i]); - } - // Soma da diferenca - ll s = 0; - for (ll x : next) - s += x; - - // Para k >= 1 ver com o sinal trocado (se s negativo, inversao da positivo - llabs) - best = max(best, llabs(s)); - - // Proxima iteracao - current = next; - } - - cout << best << ""\n""; - } - return 0; -} -",2 -milestones,2062C - Cirno and Operations,c++20 ,304267670,304267356,"#include -using namespace std; -#define endl '\n' -#define int long long -int a[1000005],n; - -void solve() { - cin >> n; - int ans = 0; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - ans += a[i]; - } - if (n == 1) { - cout << ans << endl;//不能进行1,2操作 - return; - } - while (n) { - n--; - for (int i = 1; i <= n; i++) { - a[i] = a[i + 1] - a[i];//2操作 - } - int sum = 0; - for (int i = 1; i <= n; i++) sum += a[i]; - ans = max(ans, max(sum, -sum));//是否进行1操作 - } - cout << ans << endl; -} -signed main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - int tt; - cin >> tt; - while (tt--) - solve(); - return 0; -}","#include -using namespace std; -#define endl '\n' -#define int long long -int a[1000005],n; - -void solve() { - cin >> n; - int ans = 0; - for (int i = 1; i <= n; i++) { - cin >> a[i]; - ans += a[i]; - } - if (n == 1) { - cout << ans << endl;//不能进行1,2操作 - } - while (n) { - n--; - for (int i = 1; i <= n; i++) { - a[i] = a[i + 1] - a[i];//2操作 - } - int sum = 0; - for (int i = 1; i <= n; i++) sum += a[i]; - ans = max(ans, max(sum, -sum));//是否进行1操作 - } - cout << ans << endl; -} -signed main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - int tt; - cin >> tt; - while (tt--) - solve(); - return 0; -}",1 -lokesh_s_2k6,2062C - Cirno and Operations,c++17 ,306651399,306647960,"#include -#include -#include -using namespace std; -int main() { - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vector arr(n+1); - for(int i=1;i<=n;i++){ - cin>>arr[i]; - } - if(n==1){ - cout< -#include -#include -using namespace std; -long long fac(vector &dp,int n,int i,int a){ - if(n<=i){ - return 1; - } - - return n*fac(dp,n-1,i,a-1)/a; -} -int main() { - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - bool f=false; - vector arr(n); - for(int i=0;i>arr[i]; - if(arr[i]<=0){ - f = true; - } - } - if(n==1){ - cout< dp(n+1); - for(auto x:dp)x=-1; - long long sum=0; - if(f){ - for(int i=0;i 1: - ans = max(ans, abs(a[0] - a[-1])) - a = [a[i] - a[i - 1] for i in range(1, len(a))] - return ans - - -for _ in range(int(input())): - # solve() - print(solve()) - # print(""YES"" if solve() else ""NO"") -","import sys - -input = lambda: sys.stdin.readline().rstrip(""\r\n"") - -INF = int(1e18) - - -def solve(): - N = int(input()) - a = [int(v) for v in input().split()] - ans = -INF - while len(a) > 1: - ans = max(ans, abs(sum(a))) - a = [a[i] - a[i - 1] for i in range(1, len(a))] - ans = max(ans, abs(a[0])) - return ans - - -for _ in range(int(input())): - # solve() - print(solve()) - # print(""YES"" if solve() else ""NO"") -",1 -Xeno_er,2062C - Cirno and Operations,c++23 ,306154059,306153916,"#include -#include -#include -#include -using namespace std; -#define int long long -#define endl ""\n"" -void solve(){ - int n; - cin >> n; - vectora(n+1); - for(int i=1;i<=n;i++)cin >> a[i]; - if(n==1){ - cout << a[1] << endl; - return ; - } - int ans=-1e9; - for(int i=n-1;i>=1;i--){ - int t=0; - for(int j=1;j<=i+1;j++)t+=a[j]; - if(i==n-1)ans=max({ans,t}); - else{ - ans=max({ans,-t,t}); - } - for(int j=1;j<=i;j++){ - a[j]=a[j+1]-a[j]; - } - } - cout << max({ans,a[1],-a[1]}) << endl; -} -signed main(){ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int _=1; - cin >> _; - while(_--) - solve(); -}","#include -#include -#include -#include -using namespace std; -#define int long long -#define endl ""\n"" -void solve(){ - int n; - cin >> n; - vectora(n+1); - for(int i=1;i<=n;i++)cin >> a[i]; - if(n==1){ - cout << a[1] << endl; - return ; - } - int ans=-1e9; - for(int i=n-1;i>=1;i--){ - int t=0; - for(int j=1;j<=i+1;j++)t+=a[j]; - ans=max({ans,t}); - for(int j=1;j<=i;j++){ - a[j]=a[j+1]-a[j]; - } - } - cout << max({ans,a[1],-a[1]}) << endl; -} -signed main(){ - ios::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int _=1; - cin >> _; - while(_--) - solve(); -}",1 -Steven050826,2062C - Cirno and Operations,c++20 ,304792011,304792574,"#include -#include -#include -#include -#include -using namespace std; - -void solve() -{ - int n; - cin >> n; - vector a(n); - int sum = 0; - for(int &i:a) - { - cin >> i; - sum += i; - } - if (n == 1) - { - cout << a[0] << endl; - return; - } - for (int i = 0; i < n - 1; ++i) - { - for(int j=0;jabs(sum) ) - { - sum=temp; - } - } - cout<> t; - while (t--) solve(); - return 0; -} -","#include -#include -#include -#include -#include -using namespace std; - -void solve() -{ - long long a[1010]; - int n; - cin >> n; - for (int i = 1; i <= n; i++) cin >> a[i]; - int now = n; - long long ans = -1e18; - for (int i = 1; i <= n; i++) { - long long sum = 0; - for (int i = 1; i <= now; i++) sum = (sum + a[i]); - if (i == 1) ans = max(ans, sum); - else ans = max(ans, max(sum, (-sum))); - for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]); - now--; - } - cout << ans << endl; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) solve(); - return 0; -} -",2 -Kiyra,2062C - Cirno and Operations,c++23 ,309026936,309026255,"#define _GLIBCXX_FILESYSTEM -#include -using namespace std; -using ll = long long; -const int maxn = 1e9 + 10; -const ll INF = 1e18 + 100; -const int mod = 998244353; - -void solve() { - int n; - cin >> n; - vector a(n + 1); - for (int i = 1; i <= n; i++) cin >> a[i]; - ll ans = -INF; - int now = n; - for (int i = 1; i <= n; i++) { - ll sum = 0; - for (int i = 1; i <= now; i++) sum += a[i]; - if (i == 1) ans = max(ans, sum); - else ans = max(ans, abs(sum)); - for (int j = 1; j < now; j++) - a[j] = a[j + 1] - a[j]; - now--; - } - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int T = 1; - cin >> T; - while (T--) - solve(); - - return 0; -} -/* - -1 -4 -1 1 1 1 -1 1 1 1 -1 1 1 2 -1 1 1 2 - - -*/","#define _GLIBCXX_FILESYSTEM -#include -using namespace std; -using ll = long long; -const int maxn = 1e9 + 10; -const int INF = 1e9 + 100; -const int mod = 998244353; - -void solve() { - int n; - cin >> n; - vector a(n + 1); - for (int i = 1; i <= n; i++) cin >> a[i]; - int ans = -INF, now = n; - for (int i = 1; i <= n; i++) { - int sum = accumulate(a.begin(), a.begin() + now + 1, 0); - if (i == 1) ans = max(ans, sum); - else ans = max(ans, abs(sum)); - for (int j = 1; j < now; j++) - a[j] = a[j + 1] - a[j]; - now--; - } - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int T = 1; - cin >> T; - while (T--) - solve(); - - return 0; -} -/* - -1 -4 -1 1 1 1 -1 1 1 1 -1 1 1 2 -1 1 1 2 - - -*/",1 -Ambrose0321,2062C - Cirno and Operations,c++20 ,304568143,304577365,"#include -#define pb push_back -using namespace std; -typedef long long ll; -int _, n, ans, sum, a[51], b[51]; -int main() { - scanf(""%d"", &_); - for (; _--; ) { - ans = 0; - scanf(""%d"", &n); - for (int i = 1; i <= n; i++) - scanf(""%d"", &a[i]), ans += a[i]; - if (n == 1) { - printf(""%d\n"", a[1]); - continue; - } - for (; n > 1; ) { - sum = 0; - for (int i = 1; i < n; i++) - b[i] = a[i + 1] - a[i], sum += b[i]; - ans = max(ans, abs(sum)); - --n; - for (int i = 1; i <= n; i++) - a[i] = b[i]; - } - printf(""%d\n"", ans); - } -} -","#include -#define pb push_back -using namespace std; -typedef long long ll; -int _, n; -ll ans, sum, a[51]; -int main() { - scanf(""%d"", &_); - for (; _--; ) { - ans = 0; - scanf(""%d"", &n); - for (int i = 1; i <= n; i++) - scanf(""%lld"", &a[i]), ans += a[i]; - for (int i = 1; i < n; i++) { - sum = 0; - for (int j = 1; i + j <= n; j++) - a[j] -= a[j + 1], sum += a[j]; - if (sum < 0) - sum *= -1; - ans = max(ans, sum); - } - printf(""%lld\n"", ans); - } -} -",2 -_JG_,2062C - Cirno and Operations,c++23 ,305031827,305030831," //#define MYDEBUG - #ifndef oUwUo - #include - - using namespace std; - - #define endl << ""\n"" - #define FOR(x, n) for (int x=0; x < n; x++) - #define ll long long - #define vi vector - #define vpi vector> - #define vvi vector> - #define vll vector - #define vpll vector> - #define vvll vector> - #define mp make_pair - #define SMIN(x,y) x=min(x,y) - #define SMAX(x,y) x=max(x,y) - #define RNG(j,l,r) for(int j=l;j=l;j--) - - #ifdef MYDEBUG - #define D(x) {cerr << #x << "" = "" << x endl;} - #define D2(x, y) {cerr << #x << "" = "" << x << ""/t"" << #y << "" = "" << y endl;} - #define DT(t,x) {cerr<>n; - - ll res=0; - - vll a(n),b(n-1); - - FOR(i,n) cin>>a[i]; - - for(int el:a) res+=el; - - - while(a.size()>1){ - int s=a.size(); - b.resize(s-1); - ll value=0; - - - FOR(i,s-1){ - b[i]=a[i]-a[i+1]; - } - for(ll el :b) value+=el; - res=max(res,abs(value)); - - swap(a,b); - - - } - - cout<> _; - for (int t = 1; t <= _; t++) - { - #ifdef MYDEBUG - cerr << ""______________________ testcsase = "" << t endl; - #endif - solve(); - } - - return 0; - } - - - -"," //#define MYDEBUG - #ifndef oUwUo - #include - - using namespace std; - - #define endl << ""\n"" - #define FOR(x, n) for (int x=0; x < n; x++) - #define ll long long - #define vi vector - #define vpi vector> - #define vvi vector> - #define vll vector - #define vpll vector> - #define vvll vector> - #define mp make_pair - #define SMIN(x,y) x=min(x,y) - #define SMAX(x,y) x=max(x,y) - #define RNG(j,l,r) for(int j=l;j=l;j--) - - #ifdef MYDEBUG - #define D(x) {cerr << #x << "" = "" << x endl;} - #define D2(x, y) {cerr << #x << "" = "" << x << ""/t"" << #y << "" = "" << y endl;} - #define DT(t,x) {cerr<>n; - - ll res=0; - - vi a(n),b(n-1); - - FOR(i,n) cin>>a[i]; - - for(int el:a) res+=el; - - - while(a.size()>1){ - int s=a.size(); - b.resize(s-1); - ll value=0; - - - FOR(i,s-1){ - b[i]=a[i]-a[i+1]; - } - for(int el :b) value+=el; - res=max(res,abs(value)); - - swap(a,b); - - - } - - cout<> _; - for (int t = 1; t <= _; t++) - { - #ifdef MYDEBUG - cerr << ""______________________ testcsase = "" << t endl; - #endif - solve(); - } - - return 0; - } - - - -",1 -Ismael101038,2062C - Cirno and Operations,c++20 ,307874096,307874041,"#include -using namespace std; -/* -#define isOn(S, j) (S & (1< ii; -typedef long double ld; -typedef vector vi; -typedef vector vs; -typedef tuple iss; -typedef tuple iii; -#pragma GCC optimize(""Ofast,unroll-loops,fast-math,prefetch-loop-arrays,tree-vectorize,omit-frame-pointer,no-peephole"") -//mt19937_64 qrand(chrono::steady_clock::now().time_since_epoch().count()); - - - -main() { - FAST_IO; - // freopen(""input.txt"", ""r"", stdin); - // freopen(""output.txt"", ""w"", stdout); - int tt; - cin >> tt; - while(tt -- ){ - int n; - cin >> n; - vector datos(n); - for(ll &i:datos) cin >> i; - int newN=n; - ll ans=-1e18; - for(int i=0;i -using namespace std; -/* -#define isOn(S, j) (S & (1< ii; -typedef long double ld; -typedef vector vi; -typedef vector vs; -typedef tuple iss; -typedef tuple iii; -#pragma GCC optimize(""Ofast,unroll-loops,fast-math,prefetch-loop-arrays,tree-vectorize,omit-frame-pointer,no-peephole"") -//mt19937_64 qrand(chrono::steady_clock::now().time_since_epoch().count()); - - - -main() { - FAST_IO; - // freopen(""input.txt"", ""r"", stdin); - // freopen(""output.txt"", ""w"", stdout); - int tt; - cin >> tt; - while(tt -- ){ - int n; - cin >> n; - vector datos(n); - for(ll &i:datos) cin >> i; - int newN=n; - ll ans=-1e18; - for(int i=0;i -#define TC int t;cin>>t;while(t--) -#define Tanveer ios::sync_with_stdio(false);cin.tie(0); -using namespace std; -#ifdef LOKAL -#include ""DEBUG_TEMPLATE.h"" -#else -#define HERE -#define debug(args...) -#endif -#define int long long - -void solve() -{ - int n; cin>>n; - vector v(n); - int ans = 0; - for(int i=0;i>v[i], ans+=v[i]; - - - vector t; - while(v.size()!=1) - { - for(int i=1; i -#define TC int t;cin>>t;while(t--) -#define Tanveer ios::sync_with_stdio(false);cin.tie(0); -using namespace std; -#ifdef LOKAL -#include ""DEBUG_TEMPLATE.h"" -#else -#define HERE -#define debug(args...) -#endif -#define int long long -int ans; -void fun(vector v) -{ - if(v.size()==1){ - ans = max(ans, v[0]); return; - } - int n = v.size(); - vector t; - for(int i=1; i tt; - for(int i=1; i>n; - vector v(n); - ans = 0; - for(int i=0;i>v[i], ans+=v[i]; - fun(v); - cout< - -using namespace std; - -int n, t; - -void solve() { - scanf(""%d"", &n); - long long a[n]; - - long long ans = 0; - for (int i = 0; i < n; i++) { - scanf(""%lli"", a + i); - ans += a[i]; - } - - for (int i = 1; i < n; i++) { - long long curr = 0; - for (int j = n - 1; j >= i; j--) { - a[j] -= a[j - 1]; - curr += a[j]; - } - ans = max(ans, abs(curr)); - } - - printf(""%lli\n"", ans); -} - -int main() { - scanf(""%d"", &t); - while (t--) { - solve(); - } - return 0; -} -","#include - -using namespace std; - -int n, t; - -void solve() { - scanf(""%d"", &n); - int a[n], ans = 0; - - for (int i = 0; i < n; i++) { - scanf(""%d"", a + i); - ans += a[i]; - } - - for (int i = 1; i < n; i++) { - int curr = 0; - for (int j = n - 1; j >= i; j--) { - a[j] -= a[j - 1]; - curr += a[j]; - } - ans = max(ans, abs(curr)); - } - - printf(""%d\n"", ans); -} - -int main() { - scanf(""%d"", &t); - while (t--) { - solve(); - } - return 0; -} -",1 -50-shades-dorker,2062C - Cirno and Operations,c++17 ,304871180,304867008,"#include -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code(); -#include -#define ll long long -#define read(x) int x;cin>>x; -#define vi vector -#define vvi vector -#define vl vector -#define vvl vector -#define vb vector -#define ld long double -using namespace std; - -void init_code(){ - #ifndef ONLINE_JUDGE - freopen(""inputf.txt"",""r"",stdin); - freopen(""outputf.txt"",""w"",stdout); - #endif -} - -ll min(ll a, ll b){ - if (ab)return a; - return b; -} - -void solve(){ - ll n ; cin >> n; - vl arr(n); - ll sum =0; - for (int i=0;i>arr[i];sum+=arr[i];} - if (n==1){ - cout < -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);init_code(); -#include -#define ll long long -#define read(x) int x;cin>>x; -#define vi vector -#define vvi vector -#define vl vector -#define vvl vector -#define vb vector -#define ld long double -#define vld vector -using namespace std; - -void init_code(){ - #ifndef ONLINE_JUDGE - freopen(""inputf.txt"",""r"",stdin); - freopen(""outputf.txt"",""w"",stdout); - #endif -} - -int solve2(int pos, vvl &edges,int n){ - int maxi = INT_MIN; - for (int i=0;ib)return a; - return b; -} - -void solve(){ - ld n; cin >>n; - ld sum =0; - vld arr(n); - for (int i=0;i>arr[i]; - sum += arr[i]; - } - if (n==1 and arr[0] < 0){ - cout < -using namespace std; -bool isValid(int,int); -int n,m; -int main() { - int t; - cin>>t; - while(t--) { - long long int n,baari=0,ans=0,sum1=0,sum2=0; - cin>>n; - long long int a[n+1],b[n+1]; - for(int i=0;i>a[i]; - - for(int i=0;i1) { - for(int i=0;i1) { - // for(int i=1,j=0;isum2) { - // ans=max(ans,sum1); - // for(int i=1;i -using namespace std; -bool isValid(int,int); -int n,m; -int main() { - int t; - cin>>t; - while(t--) { - long long int n,baari=0,ans=0,sum=0,sum2=0; - cin>>n; - long long int a[n+1],b[n+1]; - for(int i=0;i>a[i]; - - for(int i=0;i1) { - for(int i=0;i1) { - // for(int i=1,j=0;isum2) { - // ans=max(ans,sum1); - // for(int i=1;i -#include -#include -#include - - -#define int long long -#define endl '\n' -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define x first -#define y second -#define lc v<<1 -#define rc v<<1|1 -const int N = 4e5 + 10; -using namespace std; -using PII = pair; -using i128 = __int128; -#define debug0 -const int base = 233; -const int ubase = 141; -using ull = unsigned long long; -const int MOD = 998244353; - -int ans = -INT_MAX; -void dfs(vector& arr,int sum){ - if(arr.size() == 1){ - return; - } - for(int k = 0;k <= 1;++k){ - if(k)reverse(arr.begin(),arr.end()); - int tsum = sum; - vectorb; - for(int i = 1;i < arr.size();++i){ - int t = arr[i] - arr[i - 1]; - tsum += t; - b.push_back(t); - } - if(ans < (int)accumulate(b.begin(),b.end(),0)){ - ans = (int)accumulate(b.begin(),b.end(),0); - for(auto it : b)cout << it << "" ""; - cout << ""ans :"" << ans << endl; - } - - dfs(b,0); - } - -}; - -void solve() { - int n;cin >> n; - vectora(n); - for(int i = 0;i < n;++i)cin >> a[i]; - int ans = accumulate(a.begin(),a.end(),0); - auto diff = [&](int x,int y){ - return x > 0 && y < 0 || x < 0 && y > 0; - }; - while(a.size() > 1){ - vectorb;int cntb = 0,absb = 0,sumb = 0; - for(int i = 1;i < a.size();++i){ - b.push_back(a[i]-a[i-1]); - if(i > 1 && diff(b[i-1],b[i-2]))cntb++; - absb += abs(b[i-1]); - sumb += b[i-1]; - } - reverse(a.begin(),a.end()); - vectorc;int cntc = 0,absc = 0,sumc = 0; - for(int i = 1;i < a.size();++i){ - c.push_back(a[i]-a[i-1]); - if(i > 1 && diff(c[i-1],c[i-2]))cntc++; - absc += abs(c[i-1]); - sumc += c[i - 1]; - } - ans = max({ans,sumb,sumc}); - if(cntb == cntc){ - if(absb < absc)a = c; - else a = c; - }else{ - if(cntb > cntc)a = b; - else a = c; - } - } - - cout << ans << endl; -} - -#define FILE -#define MULTI - -signed main() { - - -#ifndef ONLINE_JUDGE -#ifdef FILE - freopen(""in.txt"", ""r"",stdin); - freopen(""out.txt"", ""w"",stdout); -#endif -#endif - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int T = 1; - -#ifdef MULTI - cin >> T; -#endif - - - auto be = chrono::steady_clock::now(); - while(T--){ - solve(); - } - - auto af = chrono::steady_clock::now(); -// cout << chrono::duration(af-be).count() << ""ms"" << endl; - return 0; -}","// -// Created by Mrlaolu on 2024/7/10. -// - -#include -#include -#include -#include - - -#define int long long -#define endl '\n' -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define x first -#define y second -#define lc v<<1 -#define rc v<<1|1 -const int N = 4e5 + 10; -using namespace std; -using PII = pair; -using i128 = __int128; -#define debug0 -const int base = 233; -const int ubase = 141; -using ull = unsigned long long; -const int MOD = 998244353; - -int ans = -INT_MAX; -void dfs(vector& arr,int sum){ - if(arr.size() == 1){ - return; - } - for(int k = 0;k <= 1;++k){ - if(k)reverse(arr.begin(),arr.end()); - int tsum = sum; - vectorb; - for(int i = 1;i < arr.size();++i){ - int t = arr[i] - arr[i - 1]; - tsum += t; - b.push_back(t); - } - ans = max(ans, (int)accumulate(b.begin(),b.end(),0)); - dfs(b,0); - } -}; - -void solve() { - int n;cin >> n; - vectora(n); - for(int i = 0;i < n;++i)cin >> a[i]; - ans = accumulate(a.begin(),a.end(),0); - dfs(a,0); - - cout << ans << endl; -} - -#define FILE -#define MULTI - -signed main() { - - -#ifndef ONLINE_JUDGE -#ifdef FILE - freopen(""in.txt"", ""r"",stdin); - freopen(""out.txt"", ""w"",stdout); -#endif -#endif - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - int T = 1; - -#ifdef MULTI - cin >> T; -#endif - - - auto be = chrono::steady_clock::now(); - while(T--){ - solve(); - } - - auto af = chrono::steady_clock::now(); -// cout << chrono::duration(af-be).count() << ""ms"" << endl; - return 0; -}",1 -elou36,2062C - Cirno and Operations,c++17 ,303985167,303985286,"//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -vector diff(vector arr){ - vector ans(arr.size() - 1); - for (int i = 0; i < ans.size(); i++){ - ans[i] = arr[i+1] - arr[i]; - } - return ans; -} -void solve(){ - int n; - cin >> n; - vector arr(n); - long long ans = 0; - for (int i = 0; i < n; i++){ - cin >> arr[i]; - ans += arr[i]; - } - for (int i = 0; i < n - 1; i++){ - ans = max(ans, 1LL * abs(arr[arr.size() - 1] - arr[0])); - arr = diff(arr); - } - cout << ans << ""\n""; -} - -int main(){ - int t; - cin >> t; - for (int i = 0; i < t; i++){ - solve(); - } - return 0; - -}","//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -vector diff(vector arr){ - vector ans(arr.size() - 1); - for (int i = 0; i < ans.size(); i++){ - ans[i] = arr[i+1] - arr[i]; - } - return ans; -} -void solve(){ - int n; - cin >> n; - vector arr(n); - long long ans = 0; - for (int i = 0; i < n; i++){ - cin >> arr[i]; - ans += arr[i]; - } - for (int i = 0; i < n - 1; i++){ - ans = max(ans, 1LL * abs(arr[arr.size() - 1] - arr[0])); - arr = diff(arr); - } - cout << ans << ""\n""; -} - -int main(){ - int t; - cin >> t; - for (int i = 0; i < t; i++){ - solve(); - } - return 0; - -}",2 -alimennaali80,2062C - Cirno and Operations,c++23 ,304192412,304192160,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define all(vc) vc.begin() , vc.end() -#define inf 0x3f3f3f3f3f3f3f3f -#define N 1000005 -#define khatun ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define Time ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -#define MOD 1000000007 -using namespace std; -const ll mod = 1e9+7, infinity = 1e4; - -vector> dir = { - {0, 1}, // right - {0, -1}, // left - {1, 0}, // down - {-1, 0} // up -}; -void solve() { - ll n,ans=LONG_LONG_MIN; - cin>>n; - vectorvc(n); - for (int i=0 ; i>vc[i]; - } - ll sz=n; - for (int i=0 ; i>tc; - for (int i=1 ; i<= tc ; ++i){ - solve(); - } - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define all(vc) vc.begin() , vc.end() -#define inf 0x3f3f3f3f3f3f3f3f -#define N 1000005 -#define khatun ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define Time ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); -#define MOD 1000000007 -using namespace std; -const ll mod = 1e9+7, infinity = 1e4; - -vector> dir = { - {0, 1}, // right - {0, -1}, // left - {1, 0}, // down - {-1, 0} // up -}; -void solve() { - int n,ans=INT_MIN; - cin>>n; - vectorvc(n); - for (int i=0 ; i>vc[i]; - } - int sz=n; - for (int i=0 ; i>tc; - for (int i=1 ; i<= tc ; ++i){ - solve(); - } - return 0; -} -",1 -Emadow,2062C - Cirno and Operations,c++23 ,304722460,304722923,"#include -using namespace std; -int res=-2e9; -int a[60],bk[60]; -int n; -void solve() { - long long ans=0; - cin>>n; - for(int i=1;i<=n;i++) { - cin>>a[i]; - ans+=a[i]; - } - for(int j=n;j>=2;j--) { - long long sum=0; - for(int i=1;i>t; - while(t--)solve(); -}","#include -using namespace std; -int res=-2e9; -long long a[60]; -int n; -void solve() { - long long ans=0; - cin>>n; - for(int i=1;i<=n;i++) { - cin>>a[i]; - ans+=a[i]; - } - for(int j=n;j>=2;j--) { - long long sum=0; - for(int i=1;i>t; - while(t--)solve(); -}",2 -krishnats_29,2062C - Cirno and Operations,c++23 ,307396863,307283696,"#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef pair pii; -typedef map mii; -typedef unordered_set usi; -typedef set si; -#define Pb push_back -#define Mp make_pair -#define FOR(i,a,b) for(int i = a ; i>n; - vector arr(n); - int sum = 0; - FOR(i,0,n){ - cin>>arr[i]; - sum+=arr[i]; - } - FOR(i,1,n) - { - int nsum = 0; - int prevbefore = arr[i-1]; - int prev = arr[i-1]; - FOR(j,i,n) - { - prevbefore = arr[j]; - arr[j] = arr[j] - prev; - prev = prevbefore; - nsum+=arr[j]; - } - if(abs(nsum)>sum){ - sum = abs(nsum); - // cout<>t; - while(t--){ - solve(); - } -}","#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef pair pii; -typedef map mii; -typedef unordered_set usi; -typedef set si; -#define Pb push_back -#define Mp make_pair -#define FOR(i,a,b) for(int i = a ; i>n; - vector arr(n); - int sum = 0; - FOR(i,0,n){ - cin>>arr[i]; - sum+=arr[i]; - } - FOR(i,0,n) - { - int nsum = 0; - FOR(j,0,n-1) - { - arr[j] = arr[j+1] - arr[j]; - nsum+=arr[j]; - } - if(abs(nsum)>sum){ - sum = abs(nsum); - } - } - cout<>t; - while(t--){ - solve(); - } -}",1 -Aarav_4761,2062C - Cirno and Operations,c++17 ,304548187,304548012,"#include -using namespace std; - -#define ll long long -#define mod 1000000007 -#define rr(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define all(v) v.begin(), v.end() -#define nn '\n' - -// Fast Input-Output -void fastIO() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -int main() -{ - fastIO(); - - int t; - cin >> t; - - - while (t--){ - int n; - cin >> n; - vectora(n+1); - for (int i = 1; i <= n; i++) cin >> a[i]; - int now = n; - long long ans = -1e18; - for (int i = 1; i <= n; i++){ - long long sum = 0; - for (int i = 1; i <= now; i++) sum = (sum + a[i]) ; - if (i == 1) ans = max(ans, sum); - else ans = max(ans, max(sum, ( - sum) )); - for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ; - now--; - } - cout << ans << endl; - } - return 0; -} -","#include -using namespace std; - -#define ll long long -#define mod 1000000007 -#define rr(i, n) for (int i = 0; i < n; i++) -#define pb push_back -#define all(v) v.begin(), v.end() -#define nn '\n' - -// Fast Input-Output -void fastIO() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -int main() -{ - fastIO(); - - int t; - cin >> t; - - - while (t--){ - int n; - cin >> n; - vectora(n+1); - for (int i = 1; i <= n; i++) cin >> a[i]; - int now = n; - long long ans = -1e18; - for (int i = 1; i <= n; i++){ - long long sum = 0; - for (int i = 1; i <= now; i++) sum = (sum + a[i]) ; - if (i == 1) ans = max(ans, sum); - else ans = max(ans, max(sum, ( - sum) )); - for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ; - now--; - } - cout << ans << endl; - } - return 0; -} -",1 -_Vamshi_,2062C - Cirno and Operations,c++20 ,305717085,305707495,"#include -#include -#include -#include - -using ll = long long; - -using namespace std; - -vector replace( vector a){ - ll size = a.size(); - vector rep_a; - - for( ll i = 1;i < size; i++){ - rep_a.push_back(a[i] - a[i-1]); - } - - return rep_a; - -} - -ll sum_array( vector a){ - ll sum = 0; - for( ll i =0; i < a.size(); i++){ - - sum += a[i]; - } - - return sum; - -} - -ll max_sum_sequence(ll n , vector & a){ - vector temp; - - if (n == 1) { - return a[0]; - } else { - ll sum = 0; - sum = sum_array(a); - - for( ll j =0; j < n-1; j++ ){ - ll rep_sum = 0; - temp = replace(a); - a = temp; - rep_sum = abs(sum_array(a)); - if( rep_sum > sum ) sum = rep_sum; - } - - return sum; - } -} - - -int main(){ - ll t; - cin >> t; - while (t--) { - ll n; - cin >> n; - vector a(n); - for (ll i = 0; i < n; ++i) { - cin >> a[i]; - } - ll result = max_sum_sequence(n, a); - cout << result << endl; - } - return 0; -}","#include -#include -#include -#include - - -using namespace std; - -int max_sum_sequence(int n , vector & a){ - if (n == 1) { - return a[0]; - } else if (n == 2) { - return max(a[0] + a[1], abs(a[0] - a[1])); - } else { - int sum = 0; - for (int num : a) { - sum += num; - } - return sum; - } -} - - -int main(){ - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - int result = max_sum_sequence(n, a); - cout << result << endl; - } - return 0; -}",1 -coder__raj,2062C - Cirno and Operations,c++23 ,306551198,306536459,"#include -using namespace std; -typedef long long ll; - -void solve(){ - int n; cin>>n; - vector vi; - ll ans=0; - for(int i=0;i>x; - vi.push_back(x); - ans+=x; - } - if(n==1){ - cout<2){ - for(int i=1;i<=n-2;i++){ - ll check=0; - for(auto j:vi){ - check+=j; - } - ans=max(ans,check); - ll sum=0; - for(auto it=vi.begin();it!=vi.end()-1;it++){ - *it=*(it+1)-*(it); - sum+=(*it); - } - ans=max(ans,max(sum,-sum)); - vi.pop_back(); - } - } - ll a=vi[0]+vi[1]; ll b=vi[0]-vi[1]; - ans=max(ans,(max(a,max(b,-b)))); - cout<> t; - while (t-- > 0) { - solve(); - cout << ""\n""; - } - return 0; -} -","#include -using namespace std; -typedef long long ll; - -void solve(){ - int n; cin>>n; - vector vi; - ll ans=0; - for(int i=0;i>x; - vi.push_back(x); - ans+=x; - } - if(n==1){ - cout<2){ - for(int i=1;i<=n-2;i++){ - for(auto it=vi.begin();it!=vi.end()-1;it++){ - ll sum=0; - *it=*(it)-*(it+1); - sum+=(*it); - sum=abs(sum); - ans=max(ans,sum); - } - vi.pop_back(); - } - } - auto it=vi.begin(); - ll a=*(it+1)+*it; ll b=(*it)-*(it+1); ll c=*(it+1)-(*it); - ans=max(ans,max(a,max(b,c))); - cout<> t; - while (t-- > 0) { - solve(); - cout << ""\n""; - } - return 0; -} -",1 -waltercodeforces,2062C - Cirno and Operations,c++17 ,307163364,307163726,"#include -using namespace std; -#define ll long long - -void solve(){ - int n;cin>>n; - vector v; - ll mx=0; - for(int i=0;i>x; - mx+=x; - v.push_back(x); - } - if(n==1){ - cout<1){ - vector u; - ll sum=0; - for(int i=1;i>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define ll long long - -void solve(){ - int n;cin>>n; - vector v; - ll mx=0; - for(int i=0;i>x; - mx+=x; - v.push_back(x); - } - while(n>1){ - vector u; - ll sum=0; - for(int i=1;i>t; - while(t--){ - solve(); - } - return 0; -}",2 -Dora12,2062C - Cirno and Operations,c++17 ,304982612,304971812,"#include -#define int long long -#define endl '\n' -using namespace std; -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin>>t; - for(int i=1;i<=t;i++) - { - int n; - cin>>n; - vectorarr(n,0); - for(int i=0;i>arr[i]; - vectortemp=arr; - int maxi=LLONG_MIN; - while(true) - { - int sum=0ll; - for(int i=0;iv; - for(int i=1;i -#define int long long -#define endl '\n' -using namespace std; -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(NULL); - int t; - cin>>t; - for(int i=1;i<=t;i++) - { - int n; - cin>>n; - vectorarr(n,0); - for(int i=0;i>arr[i]; - vectortemp=arr; - int maxi=LLONG_MIN; - while(true) - { - int sum=0; - for(int i=0;iv; - for(int i=1;i -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector v; - for(int i=0;i> a; - v.push_back(a); - } - long long ans = accumulate(v.begin(),v.end(),0LL); - while(n > 1){ - vector v1; - for(int i = 1;i -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -int main(){ - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector v; - for(int i=0;i> a; - v.push_back(a); - } - long long ans = accumulate(v.begin(),v.end(),0LL); - vector v1; - while(n > 1){ - for(int i = 1;i -using namespace std; - -using ll = long long; - -ll cur_sum(vector v) { - ll sum = 0; - for (int i = 0; i < v.size(); ++i) { - sum += v[i]; - } - return abs(sum); -} - -void solve() { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - - if (n == 1) { - cout << a[0] << '\n'; - return; - } - - ll ans = accumulate(a.begin(), a.end(), 0LL); - vector k = a; - while (true) { - vector temp; - for (int i = 1; i < k.size(); ++i) { - temp.push_back(k[i] - k[i - 1]); - } - k = temp; - ans = max(ans, cur_sum(k)); - if (k.size() == 1) { - break; - } - temp.clear(); - } - cout << ans << '\n'; -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - - return 0; -}","#include -using namespace std; - -using ll = long long; - -ll cur_sum(vector v) { - ll sum = 0; - for (int i = 0; i < v.size(); ++i) { - sum += v[i]; - } - return abs(sum); -} - -void solve() { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - - if (n == 1) { - cout << a[0] << '\n'; - return; - } - - ll ans = cur_sum(a); - vector k = a; - while (true) { - vector temp; - for (int i = 1; i < k.size(); ++i) { - temp.push_back(k[i] - k[i - 1]); - } - k = temp; - ans = max(ans, cur_sum(k)); - if (k.size() == 1) { - break; - } - temp.clear(); - } - cout << ans << '\n'; -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - - return 0; -}",1 -beta99999#,2062C - Cirno and Operations,c++23 ,307955309,307956632,"#include -using namespace std; - -#define putchar_unlocked putchar -#define getchar_unlocked getchar - -struct Reader { int ch; operator bool() { return ch != EOF; } template Reader &operator>>(T &x) { x = 0; int f = 1; ch = getchar_unlocked(); while (ch != EOF && (ch < '0' || ch > '9')) { if (ch == '-') f = -1; ch = getchar_unlocked(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar_unlocked(); } x *= f; return *this; } Reader &operator>>(char &s) { ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); s = ch; return *this; } Reader &operator>>(char *s) { char ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); while (ch != ' ' && ch != '\n' && ch != '\r' && ch != EOF) *(s++) = ch, ch = getchar_unlocked(); *s = '\0'; return *this; } } reader; struct Writer { template Writer &operator<<(T x) { if (x < 0) { putchar_unlocked('-'); x = -x; } if (x > 9) *this << x / 10; putchar_unlocked(x % 10 + '0'); return *this; } Writer &operator<<(char ch) { putchar_unlocked(ch); return *this; } Writer &operator<<(const char *s) { for (int i = 0; s[i]; i++) putchar_unlocked(s[i]); return *this; } } writer; - -#define cin reader -#define cout writer -#define endl '\n' - -#define f(i, a, b) for (int i = (a), _##i = (b); i <= _##i; i++) -#define fr(i, a, b) for (int i = (a), _##i = (b); i >= _##i; i--) -typedef long long LL; - -const int N = 55; -int n, a[N]; -int solve() { - cin >> n; f(i, 1, n) cin >> a[i]; - LL ans = accumulate(a + 1, a + n + 1, 0ll); - while (n > 1) { - f(i, 1, n - 1) a[i] = a[i + 1] - a[i]; - n--; - LL sum = accumulate(a + 1, a + n + 1, 0ll); - ans = max(ans, abs(sum)); - } - return ans; -} -int main() { - int T; cin >> T; - while (T--) cout << solve() << endl; -}","#include -using namespace std; - -#define putchar_unlocked putchar -#define getchar_unlocked getchar - -struct Reader { int ch; operator bool() { return ch != EOF; } template Reader &operator>>(T &x) { x = 0; int f = 1; ch = getchar_unlocked(); while (ch != EOF && (ch < '0' || ch > '9')) { if (ch == '-') f = -1; ch = getchar_unlocked(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar_unlocked(); } x *= f; return *this; } Reader &operator>>(char &s) { ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); s = ch; return *this; } Reader &operator>>(char *s) { char ch = getchar_unlocked(); while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar_unlocked(); while (ch != ' ' && ch != '\n' && ch != '\r' && ch != EOF) *(s++) = ch, ch = getchar_unlocked(); *s = '\0'; return *this; } } reader; struct Writer { template Writer &operator<<(T x) { if (x < 0) { putchar_unlocked('-'); x = -x; } if (x > 9) *this << x / 10; putchar_unlocked(x % 10 + '0'); return *this; } Writer &operator<<(char ch) { putchar_unlocked(ch); return *this; } Writer &operator<<(const char *s) { for (int i = 0; s[i]; i++) putchar_unlocked(s[i]); return *this; } } writer; - -#define cin reader -#define cout writer -#define endl '\n' - -#define f(i, a, b) for (int i = (a), _##i = (b); i <= _##i; i++) -#define fr(i, a, b) for (int i = (a), _##i = (b); i >= _##i; i--) -typedef long long LL; - -const int N = 55; -int n; -LL a[N]; -LL solve() { - cin >> n; f(i, 1, n) cin >> a[i]; - LL ans = accumulate(a + 1, a + n + 1, 0ll); - while (--n >= 1) { - f(i, 1, n) a[i] = a[i + 1] - a[i]; - LL sum = accumulate(a + 1, a + n + 1, 0ll); - ans = max(ans, abs(sum)); - } - return ans; -} -int main() { - int T; cin >> T; - while (T--) cout << solve() << endl; -}",2 -Ambrose0321,2062C - Cirno and Operations,c++20 ,304577365,304565395,"#include -#define pb push_back -using namespace std; -typedef long long ll; -int _, n; -ll ans, sum, a[51]; -int main() { - scanf(""%d"", &_); - for (; _--; ) { - ans = 0; - scanf(""%d"", &n); - for (int i = 1; i <= n; i++) - scanf(""%lld"", &a[i]), ans += a[i]; - for (int i = 1; i < n; i++) { - sum = 0; - for (int j = 1; i + j <= n; j++) - a[j] -= a[j + 1], sum += a[j]; - if (sum < 0) - sum *= -1; - ans = max(ans, sum); - } - printf(""%lld\n"", ans); - } -} -","#include -#define pb push_back -using namespace std; -typedef long long ll; -int _, n, ans, sum, a[51]; -int main() { - scanf(""%d"", &_); - for (; _--; ) { - sum = 0; - scanf(""%d"", &n); - for (int i = 1; i <= n; i++) - scanf(""%d"", &a[i]), sum += a[i]; - if (n == 1) { - printf(""%d\n"", a[1]); - continue; - } - ans = abs(sum); - for (; n > 1; --n) { - sum = 0; - for (int i = 1; i < n; i++) - sum += (a[i] = a[i + 1] - a[i]); - ans = max(ans, abs(sum)); - } - printf(""%d\n"", ans); - } -} -",1 -OMT_TaiLung,2062C - Cirno and Operations,c++20 ,304485235,304485519,"#include -using namespace std; -#define int long long -#define ii pair -#define iii pair -#define fi first -#define se second -#define inf 1e16 -const int N = 55; -int tc, n, a[N]; -vector chuyen(vector &vec) { - vector tmp; - reverse(vec.begin(),vec.end()); - for(int i = 1; i < vec.size(); i++) tmp.push_back(vec[i] - vec[i-1]); - return tmp; -} -void solve() { - vector vec; - int mx = 0; - for(int i = 1; i <= n; i++) { - vec.push_back(a[i]); - mx += a[i]; - } - while(vec.size()) { - if(vec.size() == 1) { - mx = max(mx, vec[0]); - break; - } - int sum = 0; - for(int i = 0; i < vec.size() - 1; i++) sum += vec[i] - vec[i+1]; - mx = max(mx, sum); - vec = chuyen(vec); - } - cout << mx << '\n'; -} -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - if(fopen(""main.inp"",""r"")) { - freopen(""main.inp"", ""r"", stdin); - freopen(""main.out"", ""w"", stdout); - } - cin >> tc; - while(tc--) { - cin >> n; - for(int i = 1; i <= n; i++) cin >> a[i]; - solve(); - } - return 0; -} -","#include -using namespace std; -#define int long long -#define ii pair -#define iii pair -#define fi first -#define se second -#define inf 1e16 -const int N = 55; -int tc, n, a[N]; -vector chuyen(vector &vec) { - vector tmp; - reverse(vec.begin(),vec.end()); - for(int i = 1; i < vec.size(); i++) tmp.push_back(vec[i] - vec[i-1]); - return tmp; -} -void solve() { - vector vec; - int mx = 0; - for(int i = 1; i <= n; i++) { - vec.push_back(a[i]); - mx += a[i]; - } - while(vec.size()) { - if(vec.size() == 1) { - mx = max(mx, vec[0]); - break; - } - int sum = 0; - for(int i = 0; i < vec.size() - 1; i++) sum += vec[i] - vec[i+1]; - mx = max(mx, max(sum,-sum)); - vec = chuyen(vec); - } - cout << mx << '\n'; -} -signed main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - if(fopen(""main.inp"",""r"")) { - freopen(""main.inp"", ""r"", stdin); - freopen(""main.out"", ""w"", stdout); - } - cin >> tc; - while(tc--) { - cin >> n; - for(int i = 1; i <= n; i++) cin >> a[i]; - solve(); - } - return 0; -} -",2 -imran67,2062C - Cirno and Operations,c++17 ,304233155,304233454,"#include -using namespace std; - -#define isEven(a) ((a & 1) == 0) -#define isOdd(a) ((a & 1) == 1) -#define isPowerof2(a) (((a) & ((a) - 1)) == 0) -#define ll long long -#define ull unsigned long long -#define vi vector -#define vll vector -#define vull vector -#define fi(a, b) for (int i = (a); (i) < (b); (i)++) -#define fj(a, b) for (int j = (a); (j) < (b); (j)++) -#define fx(m) for (auto &x : m) -#define fy(m) for (auto &y : m) -#define fz(m) for (auto &z : m) -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define pb push_back -#define po pop_back -#define M (int)(1e9+7) -#define N (int)(2e5+20) -#define sc second -#define fs first -#define make_unique(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()); -#define print_vec(v) fx(v) cout << x << "" ""; cout << ""\n"" - -void solve(){ - int n; - cin>>n; - vi a; - fi(0,n){ - int x; - cin>>x; - a.pb(x); - } - ll sum=0; - ll ans=INT_MIN; - fi(0,n){ - sum+=a[i]; - } - ans=max(sum,ans); - int num=n-1; - while(num--){ - int j=1; - ll sum=0; - int n=a.size(); - vector temp; - while(j>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; - -#define isEven(a) ((a & 1) == 0) -#define isOdd(a) ((a & 1) == 1) -#define isPowerof2(a) (((a) & ((a) - 1)) == 0) -#define ll long long -#define ull unsigned long long -#define vi vector -#define vll vector -#define vull vector -#define fi(a, b) for (int i = (a); (i) < (b); (i)++) -#define fj(a, b) for (int j = (a); (j) < (b); (j)++) -#define fx(m) for (auto &x : m) -#define fy(m) for (auto &y : m) -#define fz(m) for (auto &z : m) -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define pb push_back -#define po pop_back -#define M (int)(1e9+7) -#define N (int)(2e5+20) -#define sc second -#define fs first -#define make_unique(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()); -#define print_vec(v) fx(v) cout << x << "" ""; cout << ""\n"" - -void solve(){ - ll n; - cin>>n; - vll a; - fi(0,n){ - ll x; - cin>>x; - a.pb(x); - } - ll sum=0; - ll ans=INT_MIN; - fi(0,n){ - sum+=a[i]; - } - ans=max(sum,ans); - ll num=n-1; - while(num--){ - ll j=1; - ll sum=0; - ll n=a.size(); - vector temp; - while(j>t; - while(t--){ - solve(); - } - return 0; -}",2 -Paris_dream,2062C - Cirno and Operations,c++23 ,304953543,304953033,"#include -using namespace std; -#define ll long long -void solve(){ - long long n; - cin>>n; - vector a(n+10); - long long x=0; - for(long long i=1;i<=n;i++){ - cin>>a[i]; - x+=a[i]; - } - if(n==1){ - cout<>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -#define ll long long -void solve(){ - int n; - cin>>n; - vector a(n+10); - int x=0; - for(int i=1;i<=n;i++){ - cin>>a[i]; - x+=a[i]; - } - if(n==1){ - cout<>t; - while(t--){ - solve(); - } - return 0; -}",1 -bartm0ss,2062C - Cirno and Operations,c++17 ,307058606,307058432,"#include -using namespace std; -#define ll long long -#define pb push_back -#define eb emplace_back -#define mp make_pair -#define PI 3.1415926535897932384626 -#define MOD 1000000007 -typedef pair pii; -typedef pair pl; -typedef vector vi; -typedef vector vl; -typedef vector vpii; -typedef vector vpl; -typedef vector vvi; -typedef vector vvl; -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif -ios_base::sync_with_stdio(0); -cin.tie(0); -cout.tie(0); -int t; -cin >> t; -while (t--) -{ - int n; - cin >> n; - - vector nums(n); - for (auto& a : nums) - cin >> a; - - ll sum = LLONG_MIN; - - for (int i = 0; i < n; ++i) - { - ll runningsum = 0; - - for (int j = 0; j < n - i; ++j) - { - runningsum += nums[j]; - } - if (i == 0) - sum = max(sum, runningsum); - else - sum = max(sum, max(runningsum, -runningsum)); - - for (int j = 0; j < n - i - 1; ++j) - { - nums[j] = nums[j + 1] - nums[j]; - } - } - - cout << sum << '\n'; -} -return 0; -}","#include -using namespace std; -#define ll long long -#define pb push_back -#define eb emplace_back -#define mp make_pair -#define PI 3.1415926535897932384626 -#define MOD 1000000007 -typedef pair pii; -typedef pair pl; -typedef vector vi; -typedef vector vl; -typedef vector vpii; -typedef vector vpl; -typedef vector vvi; -typedef vector vvl; -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif -ios_base::sync_with_stdio(0); -cin.tie(0); -cout.tie(0); -int t; -cin >> t; -while (t--) -{ - int n; - cin >> n; - - vector nums(n); - for (auto& a : nums) - cin >> a; - - ll sum = LLONG_MIN; - - for (int i = 0; i < n; ++i) - { - ll runningsum = 0; - - for (int j = 0; j < n - i; ++j) - { - runningsum += nums[j]; - } - if (i == 0) - sum = max(sum, runningsum); - else - sum = max(sum, max(runningsum, -runningsum)); - - for (int j = 0; j < n - i - 1; ++j) - { - nums[j] = nums[j + 1] - nums[j]; - } - } - - cout << sum << '\n'; -} -return 0; -}",1 -donpaul2718,2062C - Cirno and Operations,c++20 ,305050775,305050728," -/*Don Paul*/ - -#include -using namespace std; - -#define ll long long -#define ld long double -#define el __int128 - -#define vl vector -#define ust unordered_set -#define ump unordered_map -#define prq priority_queue - -#define pb push_back -#define pp pop_back -#define sz(x) ((int)x.size()) -#define be(x) x.begin(), x.end() -#define farr(i, arr) for(int i=0; ifirst<<"" - ""<second<<""\n""; - -ll mod = 1e9 + 7; -ll inf = 7e18; - -/*======================================================================================================================*/ - - -ll find(vl &nums) -{ - ll i = 0; - ll mx = -1e18; - ll mn = 1e18; - - while(sz(nums) != 1) - { - ll sum = 0; - - for(ll i=0; i>ti; - - ll x; - - while(ti--) - { - ll n; - cin>>n; - - vl nums; - vl tnums; - ll sum = 0; - - ll s1 = 0; - ll s2 = 0; - - for(ll i=0; i>x; - - if(x%2 == 0) - s1 += x; - else - s2 += x; - - sum += x; - nums.pb(x); - } - - tnums = nums; - - // parr(nums); - // cout< -using namespace std; - -#define ll long long -#define ld long double -#define el __int128 - -#define vl vector -#define ust unordered_set -#define ump unordered_map -#define prq priority_queue - -#define pb push_back -#define pp pop_back -#define sz(x) ((int)x.size()) -#define be(x) x.begin(), x.end() -#define farr(i, arr) for(int i=0; ifirst<<"" - ""<second<<""\n""; - -ll mod = 1e9 + 7; -ll inf = 7e18; - -/*======================================================================================================================*/ - - -ll find(vl &nums) -{ - ll i = 0; - ll mx = -1e18; - ll mn = 1e18; - - while(sz(nums) != 1) - { - ll sum = 0; - - for(ll i=0; i>ti; - - ll x; - - while(ti--) - { - ll n; - cin>>n; - - vl nums; - vl tnums; - ll sum = 0; - - ll s1 = 0; - ll s2 = 0; - - for(ll i=0; i>x; - - if(x%2 == 0) - s1 += x; - else - s2 += x; - - sum += x; - nums.pb(x); - } - - tnums = nums; - - // parr(nums); - // cout< -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define op() \ - ios_base::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -#define srt(a) sort(a.begin(), a.end()) -#define rsrt(a) sort(a.begin(), a.end(), greater<>()) -#define fo(n) for (int i = 0; i < n; i++) -#define fo1(n) for (int i = 1; i <= n; i++) -#define all(a) a.begin(), a.end() -#define pb push_back -#define ll long long -#define Inf (ll)1e17 + 7 -#define pi 3.1415926536 -#define gcd __gcd -#define vi vector -#define vl vector -#define nl '\n' -#define min_priority priority_queue, greater> -#define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> -#define show(a) \ - for (auto e : a) \ - cout << e << "" ""; \ - cout << nl; -#define rY \ - cout << ""YES"" << nl; \ - return; -#define rN \ - cout << ""NO"" << nl; \ - return; -#define rr return -const ll mod = 1e9 + 7; -void Solve() -{ - ll n, m, x, y, z, i, j, k, l, r, q, W; - cin >> n; - vl v(n); - for (i = 0; i < n; i++) - cin >> v[i]; - ll ans = -1 * Inf; - x = 0; - for (auto e : v) - { - x += e; - } - ans = max(ans, x); - while (v.size() > 1) - { - - vector v1 = v; - for (i = 1; i < v.size(); i++) - { - v[i - 1] = v[i] - v[i - 1]; - } - v.pop_back(); - reverse(all(v1)); - for (i = 1; i < v1.size(); i++) - { - v1[i - 1] = v1[i] - v1[i - 1]; - } - v1.pop_back(); - y = 0; - for (auto e : v1) - { - y += e; - } - ans = max(ans, y); - x = 0; - for (auto e : v) - { - x += e; - } - ans = max(ans, x); - if (x < y) - v = v1; - } - ans = max(ans, v[0]); - cout << ans << nl; -} -int main() -{ - op(); - int test = 1, c = 1; - cin >> test; - while (test--) - { - // cin.ignore(); - // cout << ""Case "" << c++ << "": ""; - Solve(); - } - return 0; -}","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; -#define op() \ - ios_base::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -#define srt(a) sort(a.begin(), a.end()) -#define rsrt(a) sort(a.begin(), a.end(), greater<>()) -#define fo(n) for (int i = 0; i < n; i++) -#define fo1(n) for (int i = 1; i <= n; i++) -#define all(a) a.begin(), a.end() -#define pb push_back -#define ll long long -#define Inf (ll)1e17 + 7 -#define pi 3.1415926536 -#define gcd __gcd -#define vi vector -#define vl vector -#define nl '\n' -#define min_priority priority_queue, greater> -#define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> -#define show(a) \ - for (auto e : a) \ - cout << e << "" ""; \ - cout << nl; -#define rY \ - cout << ""YES"" << nl; \ - return; -#define rN \ - cout << ""NO"" << nl; \ - return; -#define rr return -const ll mod = 1e9 + 7; -void Solve() -{ - ll n, m, x, y, z, i, j, k, l, r, q, W; - cin >> n; - vl v(n); - for (i = 0; i < n; i++) - cin >> v[i]; - ll ans = -1 * Inf; - while (v.size() > 1) - { - x = 0; - for (auto e : v) - { - x += e; - } - ans = max(ans, x); - vector v1 = v; - for (i = 1; i < v.size(); i++) - { - v[i - 1] = v[i] - v[i - 1]; - } - v.pop_back(); - reverse(all(v1)); - for (i = 1; i < v1.size(); i++) - { - v1[i - 1] = v1[i] - v1[i - 1]; - } - v1.pop_back(); - y = 0; - for (auto e : v1) - { - y += e; - } - ans = max(ans, y); - if (x < y) - v = v1; - } - ans = max(ans, v[0]); - cout << ans << nl; -} -int main() -{ - op(); - int test = 1, c = 1; - cin >> test; - while (test--) - { - // cin.ignore(); - // cout << ""Case "" << c++ << "": ""; - Solve(); - } - return 0; -}",1 -AKID2.0#,2062C - Cirno and Operations,c++23 ,309105133,309103504,"#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -#define fr(i,j,n) for(i=j;i()) -#define rvr(a) reverse(a.begin(),a.end()) -#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin()) -#define mxel(a) *max_element(a.begin(),a.end()) -#define mnel(a) *min_element(a.begin(),a.end()) -#define ve vector -#define vep vector> -#define vee vector> -using namespace std; -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -const ll M=998244353; -const ll N=4e5+2; -ll a[1010]; -void solve() -{ - ll n,i;cin >> n;fr(i,1,n+1)cin >> a[i];ll j,k=n,ans,an=-N;//if(n==1) {cout << a[1] << endl;return;} - fr(i,1,n+1){ - ans=0;fr(j,1,k+1) ans+=a[j]; - if(i==1)an=max(an,ans); - else an=max(an,max(ans,(-ans))); - fr(j,1,k)a[j]=(a[j+1]-a[j]); - //if(n==1) if(ans<0) an=max(an,-ans); - k--; - } - cout << an << endl; -} -int main() -{ - ll testcase=1; - cin >> testcase; - while(testcase--) solve(); - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -#define fr(i,j,n) for(i=j;i()) -#define rvr(a) reverse(a.begin(),a.end()) -#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin()) -#define mxel(a) *max_element(a.begin(),a.end()) -#define mnel(a) *min_element(a.begin(),a.end()) -#define ve vector -#define vep vector> -#define vee vector> -using namespace std; -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -const ll M=998244353; -const ll N=4e5+2; -void solve() -{ - ll n;cin >> n;ve a(n);cin >> a;ll i,ans,an=-N;if(n==1) {cout << a[0] << endl;return;} - while(n){ - ans=0;fr(i,0,n) ans+=a[i]; - if(n==1)an=max(an,ans); - else an=max(an,max(ans,(-ans))); - fr(i,0,n)a[i]=(a[i+1]-a[i]); - //if(n==1) if(ans<0) an=max(an,-ans); - n--; - } - cout << an << endl; -} -int main() -{ - ll testcase=1; - cin >> testcase; - while(testcase--) solve(); - return 0; -} -",1 -mintu_m07,2062C - Cirno and Operations,c++23 ,305778120,305780215,"#include -#include -#include -#include -using namespace std; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; i++){ - cin >> a[i]; - } - - // Candidate 0: doing nothing. - long long baseSum = 0; - for(auto x : a) baseSum += x; - long long ans = baseSum; - - // We'll simulate consecutive difference operations. - // dp[0] is the original sequence. - vector> dp; - dp.push_back(a); - - // Continue while the current sequence has at least 2 elements. - for (int k = 0; dp[k].size() > 1; k++){ - vector nxt; - for (int i = 0; i + 1 < dp[k].size(); i++){ - nxt.push_back(dp[k][i+1] - dp[k][i]); - } - dp.push_back(nxt); - long long candidate; - if(nxt.size() == 1) - candidate = llabs(nxt[0]); - else - candidate = llabs(nxt.back() - nxt.front()); - ans = max(ans, candidate); - } - - cout << ans < -#include -#include -#include -using namespace std; - -// Recursive function that returns the maximum final sum obtainable -// from the current sequence using allowed operations. -long long solveSequence(const vector& seq) { - long long s = 0; - for (auto x : seq) - s += x; - long long best = s; //do nothing and take the sum - - int n = seq.size(); - if(n >= 2) { - // perform one difference operation. - // By reversing if necessary, we can obtain |last - first| - best = max(best, llabs(seq.back() - seq.front())); - - // Compute the difference sequence (in natural order). - vector diffSeq(n - 1); - for (int i = 0; i < n - 1; i++){ - diffSeq[i] = seq[i+1] - seq[i]; - } - //continue operations on the difference sequence. - best = max(best, solveSequence(diffSeq)); - } - return best; -} - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; i++){ - cin >> a[i]; - } - - // If the sequence has only one element, output it. - if(n == 1){ - cout << a[0] < -using namespace std; - -// Fast I/O -#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) - -// Input/Output file setup for debugging -#ifndef ONLINE_JUDGE - #define FILE_IO freopen(""input.txt"", ""r"", stdin); freopen(""output.txt"", ""w"", stdout);freopen(""error.txt"", ""w"", stderr) -#else - #define FILE_IO -#endif - -// Type Definitions -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -#define sz(x) (ll)(x).size() -#define vii vector -#define vll vector -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl - -// Constants -const ll MOD = 1e9 + 7; // Modular arithmetic constant - -// Debugging Macro (Prints variable values during local testing) -#ifndef ONLINE_JUDGE - #define debug(x) cerr << #x << "" = "" << x << endl - #define debugv(v) cerr << #v << "" = ""; for (auto i : v) cerr << i << "" ""; cerr << endl -#else - #define debug(x) - #define debugv(x) -#endif - -// Utility Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } -ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } -ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } -ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -// Main problem-solving function -void solve() { - int n; - cin >> n; - vll v(n), k; - for(auto &a: v) cin >> a; - ll ans = accumulate(all(v),0LL); - while(n > 0){ - for(int i = 0; i < n-1; ++i){ - k.pb(v[i+1] - v[i]); - } - if (!k.empty()) { - ans = max(ans, abs(accumulate(all(k), 0LL))); - } - for(int i = 0; i < n-1; ++i){ - v[i] = k[i]; - } - k.clear(); - n--; - } - cout << ans << endl; - -} - -int main() { - // File and Fast I/O Setup - FAST_IO; - FILE_IO; - - // Number of test cases - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -","#include -using namespace std; - -// Fast I/O -#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) - -// Input/Output file setup for debugging -#ifndef ONLINE_JUDGE - #define FILE_IO freopen(""input.txt"", ""r"", stdin); freopen(""output.txt"", ""w"", stdout);freopen(""error.txt"", ""w"", stderr) -#else - #define FILE_IO -#endif - -// Type Definitions -#define ll long long -#define ull unsigned long long -#define endl ""\n"" -#define pb push_back -#define all(x) (x).begin(), (x).end() -#define sz(x) (ll)(x).size() -#define vii vector -#define vll vector -#define ff first -#define ss second -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl - -// Constants -const ll MOD = 1e9 + 7; // Modular arithmetic constant - -// Debugging Macro (Prints variable values during local testing) -#ifndef ONLINE_JUDGE - #define debug(x) cerr << #x << "" = "" << x << endl - #define debugv(v) cerr << #v << "" = ""; for (auto i : v) cerr << i << "" ""; cerr << endl -#else - #define debug(x) - #define debugv(x) -#endif - -// Utility Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } -ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; } -ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; } -ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; } - -// Main problem-solving function -void solve() { - int n; - cin >> n; - vii v(n), k; - for(auto &a: v) cin >> a; - ll ans = accumulate(all(v),0LL); - while(n > 0){ - for(int i = 0; i < n-1; ++i){ - k.pb(v[i+1] - v[i]); - } - if (!k.empty()) { - ans = max(ans, abs(accumulate(all(k), 0LL))); - } - for(int i = 0; i < n-1; ++i){ - v[i] = k[i]; - } - k.clear(); - n--; - } - cout << ans << endl; - -} - -int main() { - // File and Fast I/O Setup - FAST_IO; - FILE_IO; - - // Number of test cases - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -",1 -canhnam357,2062C - Cirno and Operations,c++17 ,307409766,307411575,"// source problem : -#include -using namespace std; -#define all(x) x.begin(), x.end() -#define int long long -#define lb lower_bound -#define ub upper_bound -#define MASK(i) (1LL << (i)) -const int inf = 1e18; -void ckmax(int& f, int s) -{ - f = (f > s ? f : s); -} -void ckmin(int& f, int s) -{ - f = (f < s ? f : s); -} -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vector a(n); - for (int &i : a) cin >> i; - n--; - int ans = accumulate(all(a), 0); - while (n--) - { - reverse(all(a)); - for (int i = 1; i < a.size(); i++) - { - a[i - 1] = a[i] - a[i - 1]; - } - a.pop_back(); - ckmax(ans, accumulate(all(a), 0)); - } - cout << ans << '\n'; - } - return 0; -}","// source problem : -#include -using namespace std; -#define all(x) x.begin(), x.end() -#define int long long -#define lb lower_bound -#define ub upper_bound -#define MASK(i) (1LL << (i)) -const int inf = 1e18; -void ckmax(int& f, int s) -{ - f = (f > s ? f : s); -} -void ckmin(int& f, int s) -{ - f = (f < s ? f : s); -} -int32_t main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vector a(n); - for (int &i : a) cin >> i; - n--; - int ans = accumulate(all(a), 0); - while (n--) - { - for (int i = 1; i < a.size(); i++) - { - a[i - 1] = a[i] - a[i - 1]; - } - a.pop_back(); - ckmax(ans, abs(accumulate(all(a), 0LL))); - } - cout << ans << '\n'; - } - return 0; -}",2 -L3002,2062C - Cirno and Operations,c++23 ,305472660,305471946,"#include - -int main(){ - int t; - scanf(""%d"",&t); - while(t-- > 0){ - int n; - scanf(""%d"",&n); - long long arr[n]; - long long sum = 0; - for(int i=0; i= 2){ - sum = 0; - long long sum2 = arr[n-1] - arr[0]; - long long sum2rev = -sum2; - for(int i=0; i - -int main(){ - int t; - scanf(""%d"",&t); - while(t-- > 0){ - int n; - scanf(""%d"",&n); - int arr[n]; - int sum = 0; - for(int i=0; i= 2){ - sum = 0; - int sum2 = arr[n-1] - arr[0]; - int sum2rev = -sum2; - for(int i=0; i - -using namespace std; -typedef long long ll; -int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; -int dy[] = {0, -1, 0, 1, -1, 1, -1, 1}; - -void solve(int T) { - int n; - cin >> n; - vector v(n); - for (auto &i: v) cin >> i; - if (n == 1) { - cout << v[0]; - return; - } - ll ans = accumulate(v.begin(), v.end(), 0ll); - while (v.size() > 1) { - for (int i = 0; i < (int) v.size() - 1; ++i) { - v[i] = v[i + 1] - v[i]; - } - v.pop_back(); - } - ans = max(ans, abs(accumulate(v.begin(), v.end(), 0ll))); - cout << ans; - -} - -int main() { -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - ios_base::sync_with_stdio(false); - cin.tie(nullptr), cout.tie(nullptr); - int T = 1; - cin >> T; - for (int i = 1; i <= T; ++i) { - solve(i); - cout << '\n'; - } -}","#include - -using namespace std; -typedef long long ll; -int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; -int dy[] = {0, -1, 0, 1, -1, 1, -1, 1}; - -void solve(int T) { - int n; - cin >> n; - vector v(n); - for (auto &i: v) cin >> i; - if (n == 1) { - cout << v[0]; - return; - } - ll ans = accumulate(v.begin(), v.end(), 0ll); - while (v.size() > 1) { - for (int i = 0; i < (int) v.size() - 1; ++i) { - v[i] = v[i + 1] - v[i]; - } - v.pop_back(); - ans = max(ans, abs(accumulate(v.begin(), v.end(), 0ll))); -// cout << abs(accumulate(v.begin(), v.end(), 0ll)) << '\n'; - } - cout << ans; - -} - -int main() { -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - - ios_base::sync_with_stdio(false); - cin.tie(nullptr), cout.tie(nullptr); - int T = 1; - cin >> T; - for (int i = 1; i <= T; ++i) { - solve(i); - cout << '\n'; - } -}",2 -ccd111,2062C - Cirno and Operations,c++17 ,307412088,307411084,"#include -#include -#include -using namespace std; - -int main() { - int t; - cin >> t; - - while(t--) { - int n; - cin >> n; - vector arr(n + 1); - - for(int i = 1; i <= n; i++) { - cin >> arr[i]; - } - - int row = n; - long long sum = -1e18; - - for(int j = 1; j <= n; j++) { - long long ans = 0; - for(int b = 1; b <= row; b++) { - ans += arr[b]; - } - - if(j == 1) { - sum = max(ans, sum); - } else { - sum = max(sum, max(-ans, ans)); - } - - for(int a = 1; a < row; a++) { - arr[a] = arr[a + 1] - arr[a]; - } - row--; - } - - cout << sum << endl; - } - - return 0; -} -","#include -#include -#include -using namespace std; - -int main() { - int t; - cin >> t; - - while(t--) { - int n; - cin >> n; - vector arr(n + 1); - - for(int i = 1; i <= n; i++) { - cin >> arr[i]; - } - - int row = n; - long long sum = -1e18; - - for(int j = 1; j <= n; j++) { - long long ans = 0; - for(int b = 1; b <= row; b++) { - ans += arr[b]; - } - - if(j == 1) { - sum = max(ans, sum); - } else { - sum = max(sum, max(-ans, ans)); - } - - for(int a = 1; a < row; a++) { - arr[a] = arr[a + 1] - arr[a]; - } - row--; - } - - cout << sum << endl; - } - - return 0; -} -",1 -Talha_Taseen,2062C - Cirno and Operations,c++23 ,306127638,306127791,"#include -#include -#include -#define nn cout<<""NO""<>t; - while(t--)talha(); - return 0; -} -void talha() -{ - int n; - cin>>n; - vectorv(n),vv; - ll sm=0,ans=0; - for(int i=0; i>v[i]; - sm+=v[i]; - } - while(n>1) - { - ans=0; - for(int j=0; j -#include -#include -#define nn cout<<""NO""<>t; - while(t--)talha(); - return 0; -} -void talha() -{ - ll n; - cin>>n; - vectorv(n),vv; - ll sm=0,ans=0; - for(int i=0; i>v[i]; - sm+=v[i]; - } - while(n>1) - { - ans=0; - for(int j=0; j -#include -#include -using namespace __gnu_pbds; -using namespace std; -#define ll long long -#define endl ""\n"" -#define pb push_back -#define ff first -#define ss second -#define ld long double -#define pll pair -#define pllv pair> -#define all(a) a.begin(),a.end() -#define ump unordered_map -#define deb1(a) cout< -#define vvll vector> -#define rep(a,b) for(ll i=a;i>n; - vector a(n); - ll ans = -INF; - for(ll i=0;i>a[i]; - vector v = a; - if(v.size()== 1) { - cout<1) { - ll stSum = 0; - for(ll i=0;i reducedV; - for(ll i=1;i>t; - while(t--) - { - solve(); - } -} -","#include -#include -#include -using namespace __gnu_pbds; -using namespace std; -#define ll long long -#define endl ""\n"" -#define pb push_back -#define ff first -#define ss second -#define ld long double -#define pll pair -#define pllv pair> -#define all(a) a.begin(),a.end() -#define ump unordered_map -#define deb1(a) cout< -#define vvll vector> -#define rep(a,b) for(ll i=a;i>n; - vector a(n); - ll ans = -INF; - for(ll i=0;i>a[i]; - vector v = a; - if(v.size()== 1) { - cout<1) { - ll stSum = 0; - for(ll i=0;i reducedV; - for(ll i=1;i>t; - while(t--) - { - solve(); - } -} -",2 -code_saint,2062C - Cirno and Operations,c++17 ,307184002,307185519,"#include -using namespace std; - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x << "" "";_print(x) ;cerr << endl; -#else -#define debug(x); -#endif - -typedef long long ll; - -template void _print(T x) { cerr << x << "" ""; } - - -// template void _print(vector v1); -template void _print(vector v1){for(T& ele : v1){_print(ele);}} - - -void stdInput(){ - #ifndef ONLINE_JUDGE - freopen(""input.txt"",""r"",stdin); - freopen(""output.txt"",""w"",stdout); - freopen(""error.txt"",""w"",stderr); - #endif -} - - -ll solve(vector& v1,int n) -{ - ll mxSum = LLONG_MIN; - - mxSum = accumulate(v1.begin(),v1.end(),0ll); - debug(mxSum); - vector tmp; - - while(n > 1){ - // debug(mxSum); - for(int i = 0;i < n-1;++i){ - tmp.push_back(v1[i+1] - v1[i]); - } - ll sum = 0; - for(ll &ele : tmp){ - sum += ele; - } - // mxSum = max(mxSum,abs(accumulate(tmp.begin(),tmp.end(),0ll))); - // debug(v1); - // cout << sum << endl; - - for(int i = 0;i < n-1;i++){ - v1[i] = tmp[i]; - } - mxSum = max(mxSum,abs(sum)); - tmp.clear(); - n--; - } - return mxSum; - -} -int main() -{ - stdInput(); - int T; - cin >> T; - while(T--) - { - int n; - cin >> n; - vector v1(n); - for(int &i : v1){ - cin >> i; - } - cout << solve(v1,n) << endl; - } -}","#include -using namespace std; - -#ifndef ONLINE_JUDGE -#define debug(x) cerr << #x << "" "";_print(x) ;cerr << endl; -#else -#define debug(x); -#endif - -typedef long long ll; - -template void _print(T x) { cerr << x << "" ""; } - - -// template void _print(vector v1); -template void _print(vector v1){for(T& ele : v1){_print(ele);}} - - -void stdInput(){ - #ifndef ONLINE_JUDGE - freopen(""input.txt"",""r"",stdin); - freopen(""output.txt"",""w"",stdout); - freopen(""error.txt"",""w"",stderr); - #endif -} - - -ll solve(vector& v1,int n) -{ - ll mxSum = LLONG_MIN; - - mxSum = accumulate(v1.begin(),v1.end(),0ll); - debug(mxSum); - vector tmp; - - while(n > 1){ - // debug(mxSum); - for(int i = 0;i < n-1;++i){ - tmp.push_back(v1[i+1] - v1[i]); - } - ll sum = 0; - for(ll &ele : tmp){ - sum += ele; - } - // mxSum = max(mxSum,abs(accumulate(tmp.begin(),tmp.end(),0ll))); - // debug(v1); - // cout << sum << endl; - - for(int i = 0;i < n-1;i++){ - v1[i] = tmp[i]; - } - mxSum = max(mxSum,abs(sum)); - tmp.clear(); - n--; - } - return mxSum; - -} -int main() -{ - stdInput(); - int T; - cin >> T; - while(T--) - { - int n; - cin >> n; - vector v1(n); - for(ll &i : v1){ - cin >> i; - } - cout << solve(v1,n) << endl; - } -}",2 -Mitul_Aggarwal,2062C - Cirno and Operations,c++23 ,307030969,307029397,"#include -#include -#include -#include -#include - -using namespace std; -#define int long long -#define endl '\n' -#define fastio()ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -int mod1=998244353; -int mod2=1e9+9; -int Dp[12][1002][1002]; -int Abs(int a,int b){ - if(a>b){ - return a-b; - } - return b-a; -} -void input(vector& vec,int n){ - for(int i=0;i>vec[i]; - } -} -void print(vector& vec){ - for(auto it:vec){ - cout<>x; - return x; -} - -class DisjointSet { - vector rank, parent, size; -public: - DisjointSet(int n) { - rank.resize(n + 1, 0); - parent.resize(n + 1); - size.resize(n + 1); - for (int i = 0; i <= n; i++) { - parent[i] = i; - size[i] = 1; - } - } - - int findUPar(int node) { - if (node == parent[node]) - return node; - return parent[node] = findUPar(parent[node]); - } - - void unionByRank(int u, int v) { - int ulp_u = findUPar(u); - int ulp_v = findUPar(v); - if (ulp_u == ulp_v) return; - if (rank[ulp_u] < rank[ulp_v]) { - parent[ulp_u] = ulp_v; - } - else if (rank[ulp_v] < rank[ulp_u]) { - parent[ulp_v] = ulp_u; - } - else { - parent[ulp_v] = ulp_u; - rank[ulp_u]++; - } - } - - void unionBySize(int u, int v) { - int ulp_u = findUPar(u); - int ulp_v = findUPar(v); - if (ulp_u == ulp_v) return; - if (size[ulp_u] < size[ulp_v]) { - parent[ulp_u] = ulp_v; - size[ulp_v] += size[ulp_u]; - } - else { - parent[ulp_v] = ulp_u; - size[ulp_u] += size[ulp_v]; - } - } -}; -int func1(vector> &vec,int n,int d,int a){ - queue> q; - int minus=0; - int ans=0; - for(int i=0;i> &vec,int n,int d,int a){ - queue> q; - int minus=0; - int ans=0; - for(int i=n-1;i>=0;i--){ - int currI=vec[i][0]; - int currH=vec[i][1]; - while(!q.empty()){ - auto [ele,m]=q.front(); - if(ele>currI){ - minus-=m; - q.pop(); - } - else{ - break; - } - } - int diff=currH-minus; - if(diff<0){ - diff=0; - } - int need=(diff+a-1)/a; - ans+=need; - minus+=need*a; - q.push({currI-2*d,need*a}); - } - return ans; -} -int gcd(int a,int b,int &x,int &y){ - if(a==0){ - x=0; - y=1; - return b; - } - int x1,x2; - int st= gcd(b%a,a,x1,x2); - y=x1; - x=x2-x1*(b/a); - return st; -} -// int val=0; -void swap2(vector& vec,int i,int j){ - if(i==j){ - return; - } - // val+=j-i+1; - while(i<=j){ - swap(vec[i],vec[j]); - i++; - j--; - } -} -bool check(int a,int k){ - while(a){ - int need; - if(a%10<=7){ - need=7-a%10; - } - else{ - need=17-a%10; - } - if(need<=k){ - return true; - } - a/=10; - } - return false; -} -void solve() { - int n; - cin>>n; - vector vec(n); - input(vec,n); - if(n==1){ - cout< New(n); - int ans=0; - for(auto it:vec){ - ans+=it; - } - for(int j=1;j<=n-1;j++){ - for(int i=0;i>t; - while(t--){ - solve(); - } -} -// ","#include -#include -#include -#include -#include - -using namespace std; -#define int long long -#define endl '\n' -#define fastio()ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -int mod1=998244353; -int mod2=1e9+9; -int Dp[12][1002][1002]; -int Abs(int a,int b){ - if(a>b){ - return a-b; - } - return b-a; -} -void input(vector& vec,int n){ - for(int i=0;i>vec[i]; - } -} -void print(vector& vec){ - for(auto it:vec){ - cout<>x; - return x; -} - -class DisjointSet { - vector rank, parent, size; -public: - DisjointSet(int n) { - rank.resize(n + 1, 0); - parent.resize(n + 1); - size.resize(n + 1); - for (int i = 0; i <= n; i++) { - parent[i] = i; - size[i] = 1; - } - } - - int findUPar(int node) { - if (node == parent[node]) - return node; - return parent[node] = findUPar(parent[node]); - } - - void unionByRank(int u, int v) { - int ulp_u = findUPar(u); - int ulp_v = findUPar(v); - if (ulp_u == ulp_v) return; - if (rank[ulp_u] < rank[ulp_v]) { - parent[ulp_u] = ulp_v; - } - else if (rank[ulp_v] < rank[ulp_u]) { - parent[ulp_v] = ulp_u; - } - else { - parent[ulp_v] = ulp_u; - rank[ulp_u]++; - } - } - - void unionBySize(int u, int v) { - int ulp_u = findUPar(u); - int ulp_v = findUPar(v); - if (ulp_u == ulp_v) return; - if (size[ulp_u] < size[ulp_v]) { - parent[ulp_u] = ulp_v; - size[ulp_v] += size[ulp_u]; - } - else { - parent[ulp_v] = ulp_u; - size[ulp_u] += size[ulp_v]; - } - } -}; -int func1(vector> &vec,int n,int d,int a){ - queue> q; - int minus=0; - int ans=0; - for(int i=0;i> &vec,int n,int d,int a){ - queue> q; - int minus=0; - int ans=0; - for(int i=n-1;i>=0;i--){ - int currI=vec[i][0]; - int currH=vec[i][1]; - while(!q.empty()){ - auto [ele,m]=q.front(); - if(ele>currI){ - minus-=m; - q.pop(); - } - else{ - break; - } - } - int diff=currH-minus; - if(diff<0){ - diff=0; - } - int need=(diff+a-1)/a; - ans+=need; - minus+=need*a; - q.push({currI-2*d,need*a}); - } - return ans; -} -int gcd(int a,int b,int &x,int &y){ - if(a==0){ - x=0; - y=1; - return b; - } - int x1,x2; - int st= gcd(b%a,a,x1,x2); - y=x1; - x=x2-x1*(b/a); - return st; -} -// int val=0; -void swap2(vector& vec,int i,int j){ - if(i==j){ - return; - } - // val+=j-i+1; - while(i<=j){ - swap(vec[i],vec[j]); - i++; - j--; - } -} -bool check(int a,int k){ - while(a){ - int need; - if(a%10<=7){ - need=7-a%10; - } - else{ - need=17-a%10; - } - if(need<=k){ - return true; - } - a/=10; - } - return false; -} -void solve() { - int n; - cin>>n; - vector vec(n); - input(vec,n); - vector New(n); - int ans=0; - for(int j=1;j<=n-1;j++){ - int sum=0; - for(int i=0;i<=n-j;i++){ - sum+=vec[i]; - } - ans=max(ans,sum); - for(int i=0;i>t; - while(t--){ - solve(); - } -} -// ",1 -Keval_Mori__,2062C - Cirno and Operations,c++20 ,305833859,305833167,"#include -using namespace std; - -//KEVAL MORI// - -#define Jay ios_base::sync_with_stdio(false); -#define Shree cin.tie(NULL); -#define Ram cout.tie(NULL); -#define read(n) long long int n;cin>>n; -#define tread(a,b) long long int a,b;cin>>a>>b; -#define thread(a,b,c) long long int a,b,c;cin>>a>>b>>c; -#define fread(a,b,c,d) long long int a,b,c,d; cin>>a>>b>>c>>d; -#define vread(v) for(int i=0;i>v[i]; -#define vvread(v) for(int i=0;i>v[i][j];} -#define lli long long int -#define ll long long -#define MOD 1000000007 -#define ld long double -#define f(i,x,n) for(ll i = x; i < n; i++) -#define rf(i,x,n) for(ll i = x; i >= n; i--) -#define fr(i,m) for(auto &i:m) -#define vl vector -#define vvl vector> -#define vs vector -#define vpl vector> -#define pb push_back -#define all(v) (v).begin(),(v).end() -#define rall(a) (a).rbegin(), (a).rend() -#define rll(v) (v).begin(), (v).end(),greater() -#define sl set -#define ss set -#define mll map -#define mss map -#define msl map -#define mls map -#define pl pair -#define fi first -#define se second -#define PI (3.141592653589) -#define maxar *max_element -#define minar *min_element -#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) -#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) -#define UNIQUE(x) (all(x)), x.erase(unique(all(x)), x.end()) -#define yes cout<<""YES""<=0){ll sr=sqrt(x);return (sr*sr==x);}} -bool isInteger(double n){return floor(n)==n;} - -void solve() -{ - read(n); - vl a(n); - vread(a); - - lli ans=accumulate(all(a),0LL),sum=0; - - lli limit=n-1; - while(limit>0) - { - for (int i= 0; i < limit; i++) { - a[i]=(a[i+1]-a[i]); - sum+=(a[i]); - } - limit--; - ans=max(abs(sum),ans); - sum=0; - } - cout<> t; - - while (t--) - { - solve(); - } - - return 0; -}","#include -using namespace std; - -//KEVAL MORI// - -#define Jay ios_base::sync_with_stdio(false); -#define Shree cin.tie(NULL); -#define Ram cout.tie(NULL); -#define read(n) long long int n;cin>>n; -#define tread(a,b) long long int a,b;cin>>a>>b; -#define thread(a,b,c) long long int a,b,c;cin>>a>>b>>c; -#define fread(a,b,c,d) long long int a,b,c,d; cin>>a>>b>>c>>d; -#define vread(v) for(int i=0;i>v[i]; -#define vvread(v) for(int i=0;i>v[i][j];} -#define lli long long int -#define ll long long -#define MOD 1000000007 -#define ld long double -#define f(i,x,n) for(ll i = x; i < n; i++) -#define rf(i,x,n) for(ll i = x; i >= n; i--) -#define fr(i,m) for(auto &i:m) -#define vl vector -#define vvl vector> -#define vs vector -#define vpl vector> -#define pb push_back -#define all(v) (v).begin(),(v).end() -#define rall(a) (a).rbegin(), (a).rend() -#define rll(v) (v).begin(), (v).end(),greater() -#define sl set -#define ss set -#define mll map -#define mss map -#define msl map -#define mls map -#define pl pair -#define fi first -#define se second -#define PI (3.141592653589) -#define maxar *max_element -#define minar *min_element -#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) -#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) -#define UNIQUE(x) (all(x)), x.erase(unique(all(x)), x.end()) -#define yes cout<<""YES""<=0){ll sr=sqrt(x);return (sr*sr==x);}} -bool isInteger(double n){return floor(n)==n;} - -void solve() -{ - read(n); - vl a(n); - vread(a); - - lli ans=accumulate(all(a),0LL),sum=0; - - lli limit=n-1; - while(limit>0) - { - for (int i= 0; i < limit; i++) { - a[i]=(a[i]-a[i+1]); - if(limit!=1) sum+=abs(a[i]); - else sum+=a[i]; - } - limit--; - ans=max(sum,ans); - sum=0; - } - cout<> t; - - while (t--) - { - solve(); - } - - return 0; -}",1 -godAngryOver,2062C - Cirno and Operations,java,307980245,307982788,"import java.io.*; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - - - -public class Main { - static int MOD = (int) (1e9+7); - static InputReader in = new InputReader(System.in); - static PrintWriter out = new PrintWriter(System.out, false); - static class InputReader { - public BufferedReader reader; - public StringTokenizer tokenizer; - public int nextInt() { - return Integer.parseInt(next()); - } - public InputReader(InputStream stream) { - reader = new BufferedReader(new InputStreamReader(stream), 32768); - tokenizer = null; - } - - public String next() { - while (tokenizer == null || !tokenizer.hasMoreTokens()) { - try { - tokenizer = new StringTokenizer(reader.readLine()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return tokenizer.nextToken(); - } - public long nextLong() { - return Long.parseLong(next()); - } - - public double nextDouble() { - return Double.parseDouble(next()); - } - } - static List list = new ArrayList<>(); - public static void main(String[] args) throws Exception { - - Main main = new Main(); - int T = in.nextInt(); - while (T-- > 0){ - main.solve(); - } - out.flush(); - } - - void solve() { - int n = in.nextInt(); - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(in.nextInt()); - } - int max = list.stream().reduce(0, Integer::sum); - while (list.size() > 1){ - List list0 = new ArrayList<>(); - for (int i = 1; i < list.size(); i++) { - list0.add(list.get(i) - list.get(i - 1)); - } - max = Math.max(max, Math.abs(list0.stream().reduce(0, Integer::sum))); - list = list0; - - } - out.println(max); - } - - - - - -} - -","import java.io.*; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - - - -public class Main { - static int MOD = (int) (1e9+7); - static InputReader in = new InputReader(System.in); - static PrintWriter out = new PrintWriter(System.out, false); - static class InputReader { - public BufferedReader reader; - public StringTokenizer tokenizer; - public int nextInt() { - return Integer.parseInt(next()); - } - public InputReader(InputStream stream) { - reader = new BufferedReader(new InputStreamReader(stream), 32768); - tokenizer = null; - } - - public String next() { - while (tokenizer == null || !tokenizer.hasMoreTokens()) { - try { - tokenizer = new StringTokenizer(reader.readLine()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return tokenizer.nextToken(); - } - public long nextLong() { - return Long.parseLong(next()); - } - - public double nextDouble() { - return Double.parseDouble(next()); - } - } - static List list = new ArrayList<>(); - public static void main(String[] args) throws Exception { - - Main main = new Main(); - int T = in.nextInt(); - while (T-- > 0){ - main.solve(); - } - out.flush(); - } - - void solve() { - int n = in.nextInt(); - List list = new ArrayList<>(); - long sum = 0; - for (int i = 0; i < n; i++) { - long t = in.nextInt(); - list.add(t); - sum += t; - } - long max = sum; - while (list.size() > 1){ - List list0 = new ArrayList<>(); - sum = 0; - for (int i = 1; i < list.size(); i++) { - long t = list.get(i) - list.get(i - 1); - list0.add(t); - sum += t; - } - if(sum < 0) sum *= -1; - max = Math.max(max, sum); - list = list0; - - } - out.println(max); - } - - - - - -} - -",2 -Manveer_Kaur,2062C - Cirno and Operations,c++23 ,307531402,307531549,"#include -using namespace std; -int main() -{int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int t=n; - long long unsigned int arr[n]; - long long unsigned ans=INT_MIN; - long long unsigned int sum=0; - for(int i=0;i>arr[i];sum=sum+arr[i];} - if(sum>ans)ans=sum; - for(int k=0;kans)ans=sum;t--;} - cout< -using namespace std; -int main() -{int t; - cin>>t; - while(t--){ - int n; - cin>>n; - int t=n; - long long int arr[n]; - long long ans=INT_MIN; - long long int sum=0; - for(int i=0;i>arr[i];sum=sum+arr[i];} - if(sum>ans)ans=sum; - for(int k=0;kans)ans=sum;t--;} - cout< -using namespace std; -typedef long long ll; -int dfs(vectora, int n, int flag) -{ - int sum = 0; - for(int i=0;i>n; - vectora(n); - ll ans = 0; - for(int i=0;i>a[i]; - ans += a[i]; - } -// int sum = dfs(a, n, 0); -// cout<>t; - while(t--) - { - cal(); - } - return 0; -} -","#include -using namespace std; -typedef long long ll; -int dfs(vectora, int n, int flag) -{ - int sum = 0; - for(int i=0;i>n; - vectora(n); - for(int i=0;i>a[i]; - } - int sum = dfs(a, n, 0); - cout<>t; - while(t--) - { - cal(); - } - return 0; -}",1 -Kodo-no-Kami,2062C - Cirno and Operations,c++20 ,304416826,304414971,"#include -#include -#include -#include -#include - -using namespace std; -#define int long long - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - int t, ct = 0; - cin >> t; - while (t--) - { - ct++; - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) - { - cin >> a[i]; - } - long long max_sum = -1e18; - - vector current_diff = a; - for (int k = 1; k <= n; ++k) - { - int currsum = accumulate(current_diff.begin(), current_diff.end(), 0ll); - if (k == 1) - max_sum = currsum; - else - max_sum = max(max_sum, abs(currsum)); - vector next_diff(current_diff.size() - 1); - for (int i = 0; i < next_diff.size(); i++) - { - next_diff[i] = current_diff[i + 1] - current_diff[i]; - } - swap(current_diff, next_diff); - } - - cout << max_sum << endl; - } - return 0; -}","#include -#include -#include -#include -#include - -using namespace std; -#define int long long - -signed main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vector a(n); - for (int i = 0; i < n; ++i) - { - cin >> a[i]; - } - if (t == 9) - { - cout << ""6981221260116394\n""; - continue; - } - long long original_sum = accumulate(a.begin(), a.end(), 0LL); - long long max_sum = original_sum; - - vector current_diff = a; - for (int k = 1; k < n; ++k) - { - vector next_diff(current_diff.size() - 1); - for (int i = 0; i < next_diff.size(); ++i) - { - next_diff[i] = current_diff[i + 1] - current_diff[i]; - } - // The sum after k steps is the sum of next_diff, which is the last element of current_diff minus the first - long long current_max = 0; - for (long long val : next_diff) - { - current_max = max(current_max, abs(val)); - } - max_sum = max(max_sum, current_max); - current_diff = move(next_diff); - } - - cout << max_sum << endl; - } - return 0; -}",1 -rikul,2062C - Cirno and Operations,python,304068179,304161783,"m=int(input()) -for _ in range(m): - n=int(input()) - l=list(map(int,input().split())) - ans=sum(l) - while n>1: - for i in range(n-1): - l[i]=l[i+1]-l[i] - ans=max(ans,abs(l[n-2]-l[0])) - if n==2: - ans=max(ans,abs(l[n-2])) - n-=1 - print(ans)","m=int(input()) -for _ in range(m): - n=int(input()) - l=list(map(int,input().split())) - if n==1: - print(l[0]) - else: - ans=max(sum(l),abs(l[n-1]-l[0])) - while n>1: - for i in range(n-1): - l[i]=l[i+1]-l[i] - if n!=2: - ans=max(ans,abs(l[n-2]-l[0])) - if n==2: - ans=max(ans,abs(l[n-2])) - #print(n,l,ans) - n-=1 - print(ans) - ",2 -n_error,2062C - Cirno and Operations,c++17 ,307202104,307245343,"#include -#include -#define whc long long int -#define whl ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define nl ""\n"" -using namespace std; -vector divisor(whc n) -{ - vector div; - whc i; - for(i=1;i<=sqrt(n);i++) - { - if(n%i==0) - { - if(n/i==i) - div.push_back(i); - else - div.push_back(i),div.push_back(n/i); - } - } - sort(div.begin(),div.end()); - return div; -} -bool is_prime(whc n) -{ - if(n==1) - return false; - whc i; - i=2; - while(i*i<=n) - { - if (n%i==0) - return false; - i+=1; - } - return true; -} -whc distance(whc x1,whc y1,whc x2,whc y2) -{ - return (((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); -} -whc lcm(vector vec) -{ - whc x=2,i,m,r=1; - sort(vec.begin(),vec.end()); - m=vec[vec.size()-1]; - while(x<=m) - { - vector cnt; - for(i=0;i=2) - { - for(i=0;i>t; - //t=1; - while(t--) - { - whc n,i,x,s=-1e18,a; - cin>>n; - vector vec,tmp; - for(i=0;i>x; - vec.push_back(x); - } - a=accumulate(vec.begin(),vec.end(),0); - s=max(s,a); - while(n>1) - { - for(i=1;i -#include -#define whc long long int -#define whl ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); -#define nl ""\n"" -using namespace std; -vector divisor(whc n) -{ - vector div; - whc i; - for(i=1;i<=sqrt(n);i++) - { - if(n%i==0) - { - if(n/i==i) - div.push_back(i); - else - div.push_back(i),div.push_back(n/i); - } - } - sort(div.begin(),div.end()); - return div; -} -bool is_prime(whc n) -{ - if(n==1) - return false; - whc i; - i=2; - while(i*i<=n) - { - if (n%i==0) - return false; - i+=1; - } - return true; -} -whc distance(whc x1,whc y1,whc x2,whc y2) -{ - return (((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))); -} -whc lcm(vector vec) -{ - whc x=2,i,m,r=1; - sort(vec.begin(),vec.end()); - m=vec[vec.size()-1]; - while(x<=m) - { - vector cnt; - for(i=0;i=2) - { - for(i=0;i>t; - //t=1; - while(t--) - { - whc n,s=-1e18,i,j,m,a; - cin>>n; - vector vec(n+1); - for (i=1;i<=n;i++) - cin>>vec[i]; - m=n; - for(j=1;j<=n;j++) - { - a=0; - for(i=1;i<=m;i++) - a+=vec[i]; - if(j==1) - s=max(s,a); - else - s=max(s,max(a,(-a))); - for(i=1;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vectorv(n); - for(int i=0;i>v[i]; - } - long long maxS=INT_MIN,maxs=0; - int now=n; - for(int i=0;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t--){ - long long n; - cin>>n; - vectorv(n); - for(int i=0;i>v[i]; - } - long long maxS=INT_MIN; - long long maxs=0; - int now=n; - for(int i=0;i -#define ll long long -using namespace std; - -int main(){ - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vector a(n); - ll sum = 0; - for(int i = 0; i < n; i++){ - cin >> a[i]; - sum+=a[i]; - } - if(n == 1){ - cout << a[0] << endl; - continue; - } - - while (n) - { - ll tmp = a[n-1] - a[0]; - for(int i=0; i -#define ll long long -using namespace std; - -int main(){ - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - vector a(n); - ll sum = 0; - for(int i = 0; i < n; i++){ - cin >> a[i]; - sum+=a[i]; - } - if(n == 1){ - cout << a[0] << endl; - continue; - } - - while (n) - { - ll tmp = a[n-1] - a[0]; - for(int i=0; i -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector a(n, int64_t(0)); - for (auto &el : a) { - cin >> el; - } - int64_t ans = accumulate(a.begin(), a.end(), 0LL); - while (a.size() > 2) { - vector b; - for (int i = 0;i+1 < a.size(); ++i) { - b.push_back(a[i+1] - a[i]); - } - a = b; - ans = max(ans, accumulate(a.begin(), a.end(), int64_t(0))); - } - if (n == 1) { - cout << a[0] << '\n'; - } else { - ans = max({ans, a[1] - a[0], a[0] - a[1]}); - cout << ans << '\n'; - } - } -} -","#include -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector a(n, int64_t(0)); - for (auto &el : a) { - cin >> el; - } - int64_t ans = accumulate(a.begin(), a.end(), 0LL); - while (a.size() > 2) { - vector b; - for (int i = 0;i+1 < a.size(); ++i) { - b.push_back(a[i+1] - a[i]); - } - a = b; - int64_t sum = accumulate(a.begin(), a.end(), int64_t(0)); - ans = max({ans, sum, -sum}); - } - if (n == 1) { - cout << a[0] << '\n'; - } else { - ans = max({ans, a[1] - a[0], a[0] - a[1]}); - cout << ans << '\n'; - } - } -} -",2 -RishiSharmapro,2062C - Cirno and Operations,c++17 ,304530756,304530584,"// Created by Rishi Sharma (@rishisharmapro) on 05-02-2025 at 13:10 -// #include -#include -#include -#include - -using namespace std; - -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define ll long long -#define pb push_back -#define all(v) v.begin(), v.end() -#define sz(x) (int)(x.size()) - -const ll MOD = 1e9 + 7; -const ll INF = 1e18; - -void solve() { - int n; - cin >> n; - ll a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - - ll maxSum = accumulate(a, a+n, 0ll), sum = 0; - - while(--n) { - sum = 0; - for(int i = 0; i < n; i++) { - a[i] = a[i+1] - a[i]; - sum += a[i]; - } - // cout << sum << "" ""; - sum = max(sum, -1 * sum); - maxSum = max(maxSum, sum); - } - maxSum = max(maxSum, (ll)a[0]); - - cout << maxSum << endl; -} - -int main() { - // problem: https://codeforces.com/contest/2062/problem/C - fast_io; - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","// Created by Rishi Sharma (@rishisharmapro) on 05-02-2025 at 13:10 -// #include -#include -#include -#include - -using namespace std; - -#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define ll long long -#define pb push_back -#define all(v) v.begin(), v.end() -#define sz(x) (int)(x.size()) - -const ll MOD = 1e9 + 7; -const ll INF = 1e18; - -void solve() { - int n; - cin >> n; - int a[n]; - for(int i = 0; i < n; i++) cin >> a[i]; - - ll maxSum = accumulate(a, a+n, 0ll), sum = 0; - - while(--n) { - sum = 0; - for(int i = 0; i < n; i++) { - a[i] = a[i+1] - a[i]; - sum += a[i]; - } - // cout << sum << "" ""; - sum = max(sum, -1 * sum); - maxSum = max(maxSum, sum); - } - maxSum = max(maxSum, (ll)a[0]); - - cout << maxSum << endl; -} - -int main() { - // problem: https://codeforces.com/contest/2062/problem/C - fast_io; - int t = 1; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -L._.,2062C - Cirno and Operations,c++20 ,303947973,303985034,"/*Les do some thikr: -سُبْحَانَ ٱللَّٰهِ -ٱلْحَمْدُ لِلَّٰهِ - الله أكبر -أَسْتَغْفِرُ ٱللَّٰهَ -سُبْحَانَ اللَّهِ وَبِحَمْدِهِ، سُبْحَانَ اللَّهِ العَظِيم - لَا حَوْلَ وَلَا قُوَّةَ إِلَّا بِٱللَّٰهِ ٱلْعَلِيِّ ٱلْعَظِيمِ -لا إله إلا الله -and durood -اللَّهُمَّ بَارِكْ عَلَى مُحَمَّدٍ، وَعَلَى آلِ مُحَمَّدٍ، كَمَا بَارَكْتَ عَلَى إِبْرَاهِيمَ، وَعَلَى آلِ إِبْرَاهِيمَ، إِنَّكَ حَمِيدٌ مَجِيدٌ -*/ -#include -using namespace std; -#define ll long long - -//bitset<100001>a; -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t=1; -cin>>t; - - while(t--) - { - ll n,i,x,f=0,sum=0,mx; - cin>>n; - vectorv,v1; - for(i=0; i>x; - v.push_back(x); - - sum+=x; - } - mx=sum; - while(n--) - { sum=0,f=0; - reverse(v.begin(),v.end()); - for(i=1; i -using namespace std; -#define ll long long - -//bitset<100001>a; -int main() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - int t=1; -cin>>t; - - while(t--) - { - ll n,i,x,f=0,sum=0,mx; - cin>>n; - vectorv,v1; - for(i=0; i>x; - v.push_back(x); - - sum+=x; - } - mx=sum; - while(n--) - { sum=0,f=0; - - for(i=1; i -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -#define fr(i,j,n) for(i=j;i()) -#define rvr(a) reverse(a.begin(),a.end()) -#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin()) -#define mxel(a) *max_element(a.begin(),a.end()) -#define mnel(a) *min_element(a.begin(),a.end()) -#define ve vector -#define vep vector> -#define vee vector> -using namespace std; -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -const ll M=998244353; -const ll N=4e5+2; -void solve() -{ - ll n;cin >> n;ve a(n);cin >> a;ll i,ans,an=-N;if(n==1) {cout << a[0] << endl;return;} - while(n){ - ans=0;fr(i,0,n) ans+=a[i];an=max(an,ans); - fr(i,0,n)a[i]=a[i+1]-a[i]; - if(n==1) if(ans<0) an=max(an,-ans); - n--; - } - cout << an << endl; -} -int main() -{ - ll testcase=1; - cin >> testcase; - while(testcase--) solve(); - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long int -#define fr(i,j,n) for(i=j;i()) -#define rvr(a) reverse(a.begin(),a.end()) -#define rdp(a) a.resize(unique(a.begin(),a.end())-a.begin()) -#define mxel(a) *max_element(a.begin(),a.end()) -#define mnel(a) *min_element(a.begin(),a.end()) -#define ve vector -#define vep vector> -#define vee vector> -using namespace std; -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -const ll M=998244353; -const ll N=4e5+2; -ll a[1010]; -void solve() -{ - ll n,i;cin >> n;fr(i,1,n+1)cin >> a[i];ll j,k=n,ans,an=-N;//if(n==1) {cout << a[1] << endl;return;} - fr(i,1,n+1){ - ans=0;fr(j,1,k+1) ans+=a[j]; - if(i==1)an=max(an,ans); - else an=max(an,max(ans,(-ans))); - fr(j,1,k)a[j]=(a[j+1]-a[j]); - //if(n==1) if(ans<0) an=max(an,-ans); - k--; - } - cout << an << endl; -} -int main() -{ - ll testcase=1; - cin >> testcase; - while(testcase--) solve(); - return 0; -} -",2 -Spemodic233,2062C - Cirno and Operations,c++20 ,304752537,304752892,"#include -using namespace std; -#define pii pair -#define mp(x,y) make_pair(x,y) -#define inf (1e9) -#define INF (1e18) -#define eps (1e-8) -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -#define ull unsigned long long -#define int long long -#define Int __int128 -typedef long long LL; -mt19937 rnd(time(0)); -const int N = 5e5 + 10, M = 1e6 + 10, mod = 1e9 + 7; -int n, a[N]; - -void solve() -{ - vector f1, f2; - int ans = -1e15; - cin >> n; - for (int i = 1; i <= n; i++) { - int x; - cin >> x; - f1.push_back(x); - } - if (n == 1) { - cout << f1[0] << endl; - return; - } - int res = 0; - for (auto x : f1) { - res += x; - } - ans = max(ans, max(res, -res)); - while (f1.size() > 1) { - f2.clear(); - for (int i = 1; i < f1.size(); i += 1) { - f2.push_back(f1[i] - f1[i - 1]); - } - res = 0; - for (auto x : f2) res += x; - ans = max(ans, max(res, -res)); - f1 = f2; - } - cout << ans << endl; -} - -signed main() -{ - // IOS; - // init(); - int __; - cin >> __; - while (__ --) - solve(); - - return 0; -} -//-Wl,--stack=1998244353 - - -/* - -*/","#include -using namespace std; -#define pii pair -#define mp(x,y) make_pair(x,y) -#define inf (1e9) -#define INF (1e18) -#define eps (1e-8) -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -#define ull unsigned long long -#define int long long -#define Int __int128 -typedef long long LL; -mt19937 rnd(time(0)); -const int N = 5e5 + 10, M = 1e6 + 10, mod = 1e9 + 7; -int n; - -void solve() -{ - vector f1, f2; - int ans = -1e15; - cin >> n; - for (int i = 1; i <= n; i++) { - int x; - cin >> x; - f1.push_back(x); - } - if (n == 1) { - cout << f1[0] << endl; - return; - } - int res = 0; - for (auto x : f1) { - res += x; - } - ans = max(ans, res); - while (f1.size() > 1) { - f2.clear(); - for (int i = 1; i < f1.size(); i += 1) { - f2.push_back(f1[i] - f1[i - 1]); - } - res = 0; - for (auto x : f2) res += x; - ans = max(ans, max(res, -res)); - f1 = f2; - } - cout << ans << endl; -} - -signed main() -{ - // IOS; - // init(); - int __; - cin >> __; - while (__ --) - solve(); - - return 0; -} -//-Wl,--stack=1998244353 - - -/* - -*/",2 -Fjodor,2062C - Cirno and Operations,c++20 ,305736381,305736716,"#include -#include -#include - -using namespace std; -int main() { - int num_tests; - cin >> num_tests; - - for (int t = 0; t < num_tests; ++t) { - int n; - cin >> n; - vector a; - int s = 0; - for (int i = 0; i < n; ++i) { - int ai; - cin >> ai; - s += ai; - a.push_back(ai); - } - - vector b; - while (a.size() >= 2) { - int next_s = 0; - if (a[0] > a[a.size() - 1]) { - reverse(a.begin(), a.end()); - } - for (int i = 1; i < a.size(); ++i) { - next_s += a[i] - a[i - 1]; - b.push_back(a[i] - a[i - 1]); - } - if (next_s > s) { - s = next_s; - } - a = b; - b.clear(); - } - printf(""%d\n"", s); - } -} -","#include -#include -#include - -using namespace std; -int main() { - int num_tests; - cin >> num_tests; - - for (int t = 0; t < num_tests; ++t) { - int n; - cin >> n; - vector a; - long long s = 0; - for (int i = 0; i < n; ++i) { - long ai; - cin >> ai; - s += ai; - a.push_back(ai); - } - - vector b; - while (a.size() >= 2) { - long long next_s = 0; - if (a[0] > a[a.size() - 1]) { - reverse(a.begin(), a.end()); - } - for (int i = 1; i < a.size(); ++i) { - next_s += a[i] - a[i - 1]; - b.push_back(a[i] - a[i - 1]); - } - if (next_s > s) { - s = next_s; - } - a = b; - b.clear(); - } - printf(""%lld\n"", s); - } -} -",2 -lokesh_s_2k6,2062C - Cirno and Operations,c++17 ,306651011,306651399,"#include -#include -#include -using namespace std; -int main() { - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vector arr(n); - for(int i=1;i<=n;i++){ - cin>>arr[i]; - } - if(n==1){ - cout< -#include -#include -using namespace std; -int main() { - int t; - cin>>t; - while(t--){ - int n; - cin>>n; - vector arr(n+1); - for(int i=1;i<=n;i++){ - cin>>arr[i]; - } - if(n==1){ - cout< -using namespace std; -#define ll long long - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - - int n; // Number of test cases - cin >> n; - - for (int i = 0; i < n; ++i) { - int a; - cin >> a ; - vector k(a); - - for (int i = 0; i < a; i++) { - cin >> k[i]; - } - bool flag = true; - int size = a; - ll sum = accumulate(k.begin(),k.end(),0ll); - // if(size == 2) sum = max(sum,max(k[0] - k[1],k[1] - k[0])); - // else{ - while(size!=1){ - for(int i = 1;i -using namespace std; -#define ll long long - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); - - int n; // Number of test cases - cin >> n; - - for (int i = 0; i < n; ++i) { - int a; - cin >> a ; - vector k(a); - - for (int i = 0; i < a; i++) { - cin >> k[i]; - } - bool flag = true; - int size = a; - ll sum = accumulate(k.begin(),k.end(),0ll); - if(size == 2) sum = max(sum,max(k[0] - k[1],k[1] - k[0])); - else{ - while(size!=1){ - for(int i = 1;i -#define inf LLONG_MAX -#define neg_inf LLONG_MIN -using namespace std ; -void solve(){ - int n ; - cin>>n ; - vectorarr(n) ; - int cntneg=0 ; - for(int i=0 ; i>arr[i] ; - if(arr[i]<0)cntneg++; -} - if(n==1){ - cout<temp = arr ; - for(int i=0 ; i k ; - for(int j=1 ; j>t ; - while(t--)solve() ; - return 0 ; -}","#define SETBIT(x, i) ((x & (1 << i)) != 0) -#define ll long long -#include -#define inf LLONG_MAX -#define neg_inf LLONG_MIN -using namespace std ; -void solve(){ - int n ; - cin>>n ; - vectorarr(n) ; - for(int i=0 ; i>arr[i]; - if(n==1){ - cout<temp = arr ; - for(int i=0 ; i k ; - for(int j=0 ; j>t ; - while(t--)solve() ; - return 0 ; -}",1 -Vain_Kane,2062C - Cirno and Operations,c++23 ,304595164,304595284,"#include - -#define max(a, b) ((a > b) ? a : b) - -using namespace std; - -long long a[59]; -int tmp[59]; - -int t; -int n; - -long long res = 0; -long long sum; - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - cin >> t; - - while (t--) - { - cin >> n; - - res = LONG_LONG_MIN; - - for (int i = 0; i < n; i++) cin >> a[i]; - - int k = n; - - for (int j = 0; j < k; j++) - { - sum = 0; - - for (int i = 0; i < n; i++) sum += a[i]; - - res = max(res, sum); - if (k > 1) res = max(res, -sum); - n--; - - for (int i = 0; i < n; i++) a[i] = a[i + 1] - a[i]; - } - - cout << res << '\n'; - } - - return 0; -}","#include - -#define max(a, b) ((a > b) ? a : b) - -using namespace std; - -long long a[59]; -int tmp[59]; - -int t; -int n; - -long long res = 0; -long long sum; - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - - cin >> t; - - while (t--) - { - cin >> n; - - res = LONG_LONG_MIN; - - for (int i = 0; i < n; i++) cin >> a[i]; - - int k = n; - - for (int j = 0; j < k; j++) - { - sum = 0; - - for (int i = 0; i < n; i++) sum += a[i]; - - res = max(res, sum); - if (j > 0) res = max(res, -sum); - n--; - - for (int i = 0; i < n; i++) a[i] = a[i + 1] - a[i]; - } - - cout << res << '\n'; - } - - return 0; -}",2 -giorgi123glm,2062C - Cirno and Operations,c++23 ,304281645,304280892,"/* -................................................................................ -................................................................................ -................................................................................ -................................................................................ -................................................................................ -................................................##.............................. -..........................................#########............................. -.........................................##########............................. -........................................###########............................. -....................................################............................ -......................................##############............................ -......................................###############........................... -.....................................#################.......................... -.....................................################........................... -......................................###############........................... -.......................................#############............................ -.......................................############............................. -........................................###########............................. -........................................###########............................. -..............................####......##############.......................... -............................#######....################......................... -..........................##############################........................ -.........................################################....................... -.........................#################################...................... -.........................################################....................... -.........................###############################........................ -...........................#######.#####################........................ -....................................####################........................ -.....................................###################........................ -......................................###################....................... -......................................###################....................... -......................................###################....................... -......................................##############..##........................ -.....................................###############............................ -.....................................###############............................ -......................................###############........................... -...................................#..###############........................... -......................................###############........................... -......................................###############........................... -......................................###############........................... -......................................###############........................... -......................................###############........................... -.......................................###############.......................... -.......................................###############.......................... -.......................................###############.......................... -.......................................###############.......................... -.......................................###############.......................... -.......................................###############.......................... -.......................................###############.......................... -.......................................################......................... -.......................................################......................... -.......................................################......................... -.......................................################......................... -.......................................################......................... -.......................................################......................... -......................................##################........................ -......................................##################........................ -......................................##################........................ -......................................##################........................ -......................................##################........................ -*/ - -#include -#include -#include -using namespace std; - -void check () { - int n = 0; - cin >> n; - - vector v (n); - for (int i = 1; i <= n; i++) - cin >> v[i - 1]; - - long long ansmax = 0; - while (true) { - long long sum = 0; - for (long long& e : v) - sum += e; - - if (v.size() < n) - ansmax = max (ansmax, abs (sum)); - else - ansmax = sum; - - vector v1 (v.size() - 1); - for (int i = 1; i < v.size(); i++) - v1[i - 1] = v[i] - v[i - 1]; - - if (v1.size() == 0) - break; - v = v1; - } - - cout << ansmax << '\n'; -} - -int main () { - ios::sync_with_stdio(false); - cin.tie (0); - cout.tie (0); - - int t = 0; - cin >> t; - - while (t--) - check (); -}","/* -................................................................................ -................................................................................ -................................................................................ -................................................................................ -................................................................................ -................................................#............................... -..........................................######.#.............................. -.........................................##########............................. -......................................#############............................. -.......................................############............................. -.......................................#############............................ -.......................................##############........................... -......................................################.......................... -.......................................##############........................... -.......................................#############............................ -........................................###########............................. -........................................##########.............................. -........................................##########.............................. -.......................................#############............................ -.......................................##############........................... -.......................................################......................... -.......................................#################........................ -......................................##################........................ -......................................#################......................... -......................................################.......................... -......................................################.......................... -.......................................################......................... -.......................................################......................... -.......................................#################........................ -.......................................################......................... -.......................................############..#.......................... -......................................##############............................ -......................................##############............................ -.......................................#############............................ -.......................................############............................. -.......................................############............................. -.......................................############............................. -.......................................############............................. -.......................................############............................. -.......................................############............................. -.......................................############............................. -.......................................#############............................ -.......................................#############............................ -.......................................#############............................ -.......................................#############............................ -......................................##############............................ -......................................##############............................ -......................................###############........................... -......................................###############........................... -......................................###############........................... -......................................###############........................... -......................................################.......................... -......................................################.......................... -......................................################.......................... -......................................################.......................... -......................................################.......................... -......................................################.......................... -......................................#################......................... -......................................#################......................... -.....................................##################......................... -*/ - -#include -#include -#include -using namespace std; - -void check () { - int n = 0; - cin >> n; - - vector v (n); - for (int i = 1; i <= n; i++) - cin >> v[i - 1]; - - int ansmax = 0; - while (true) { - int sum = 0; - for (int& e : v) - sum += e; - - if (v.size() < n) - ansmax = max (ansmax, abs (sum)); - else - ansmax = sum; - - vector v1 (v.size() - 1); - for (int i = 1; i < v.size(); i++) - v1[i - 1] = v[i] - v[i - 1]; - - if (v1.size() == 0) - break; - v = v1; - } - - cout << ansmax << '\n'; -} - -int main () { - ios::sync_with_stdio(false); - cin.tie (0); - cout.tie (0); - - int t = 0; - cin >> t; - - while (t--) - check (); -}",1 -jdsb06,2062C - Cirno and Operations,c++23 ,304761897,304763186,"#include -using namespace std; - -void solve() { - long long n; - cin >> n; - vector a(n); - for (long long i = 0;i > a[i];} - if (n == 1){ cout << a[0] << endl; return; } - - long long sum1 = 0; - long long ans = 0; - - for (long long i = 0; i 0) { - for (long long j = n-1; j >= start+1; j--) { - a[j] -= a[j-1]; - } - sum1 = 0; - for (long long i = start; i> t; - while (t--) { - solve(); - } - return 0; -}","#include -using namespace std; - -void solve() { - long long n; - cin >> n; - vector a(n); - for (long long i = 0;i > a[i];} - if (n == 1){ cout << a[0] << endl; return; } - - long long sum1 = 0; - long long ans = 0; - - for (long long i = 0; i 1) { - for (long long j = n-1; j >= start+1; j--) { - a[j] -= a[j-1]; - } - sum1 = 0; - start++; - for (long long i = start; i> t; - while (t--) { - solve(); - } - return 0; -}",2 -OrganicBot,2062C - Cirno and Operations,c++23 ,307077025,307077779,"#include -#define ll long long -#define el ""\n"" -#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) -#define MOD 998244353 -#define int long long -#define vi vector -#define all(x) (x).begin(), (x).end() - -using namespace std; - -vector applyDifference(const vector& seq) { - vector diffSeq; - for (int i = 1; i < seq.size(); ++i) { - diffSeq.push_back(seq[i] - seq[i-1]); - } - return diffSeq; -} - -void solve() { - int n; - cin >> n; - - vi seq(n); - for(int i=0;i> seq[i]; - } - int og = accumulate(all(seq),0ll); - - while (seq.size() > 1) { - // Step 1: Apply difference operation - seq = applyDifference(seq); - - // Step 2: Reverse the sequence - reverse(seq.begin(), seq.end()); - } - - // The final result, which is the only remaining element - if(n!=1) - cout<< max(og,abs(seq[0])) << endl; - else - cout << og << el; -} - -signed main() { - OrganicBot; - int t; - cin >> t; // Number of test cases - - while (t--) { - solve(); - } - - return 0; -} -","#include -#define ll long long -#define el ""\n"" -#define OrganicBot ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) -#define MOD 998244353 -#define int long long -#define vi vector -#define all(x) (x).begin(), (x).end() - -using namespace std; - -vector applyDifference(const vector& seq) { - vector diffSeq; - for (int i = 1; i < seq.size(); ++i) { - diffSeq.push_back(seq[i] - seq[i-1]); - } - return diffSeq; -} - -void solve() { - int n; - cin >> n; - - vi seq(n); - for(int i=0;i> seq[i]; - } - int og = accumulate(all(seq),0ll); - int ans = og; - while (seq.size() > 1) { - // Step 1: Apply difference operation - seq = applyDifference(seq); - ans = max(ans,abs(accumulate(all(seq),0ll))); - } - - // The final result, which is the only remaining element - cout << max(og,ans) << el; -} - -signed main() { - OrganicBot; - int t; - cin >> t; // Number of test cases - - while (t--) { - solve(); - } - - return 0; -}",2 -hmgudals528,2062C - Cirno and Operations,python,308009932,308010252,"import sys -data = sys.stdin.read().splitlines() - -line = 2 -while (line < len(data)): - arr = list(map(int, data[line].split())) - # print(""arr="", arr) - new_arr = arr - diff = sum(arr) - if len(arr) == 2: - diff = max(abs(arr[0]-arr[1]), diff) - else: - for i in range(len(arr)-1): - new_arr = [new_arr[i+1]-new_arr[i] for i in range(len(new_arr)-1)] - if diff < abs(new_arr[0] - new_arr[-1]): - diff = abs(new_arr[0] - new_arr[-1]) - # print(new_arr, ""...diff="", diff) - print(diff) - line += 2","import sys -data = sys.stdin.read().splitlines() - -line = 2 -while (line < len(data)): - arr = list(map(int, data[line].split())) - new_arr = arr - diff = sum(arr) - # print(arr, ""...diff="", diff) - if len(arr) == 2: - diff = max(abs(arr[0]-arr[1]), diff) - elif len(arr) > 2: - for i in range(len(arr)-2): - new_arr = [new_arr[i+1]-new_arr[i] for i in range(len(new_arr)-1)] - diff = max(abs(new_arr[0]-new_arr[-1]), diff, abs(sum(new_arr))) - # print(new_arr, ""...diff="", diff) - print(diff) - line += 2",2 -trueskill,2062C - Cirno and Operations,c++17 ,308583246,308583169,"#include -using namespace std; - -int main() { - int t, n; - cin >> t; - while (t--) { - cin >> n; - vector v(n); - long long sum = 0; - for (int i = 0; i < n; ++i) { - cin >> v[i]; - sum += v[i]; - } - while (v.size() != 1) { - vector v1(v.size() - 1); - for (int i = 0; i < (int) v.size() - 1; ++i) { - v1[i] = v[i + 1] - v[i]; - } - sum = max(sum, abs(accumulate(v1.begin(), v1.end(), 0LL))); - v = v1; - } - cout << sum << '\n'; - } -}","#include -using namespace std; - -int main() { - int t, n; - cin >> t; - while (t--) { - cin >> n; - vector v(n); - long long sum = 0; - for (int i = 0; i < n; ++i) { - cin >> v[i]; - } - while (v.size() != 1) { - vector v1; - for (int i = 0; i < (int) v.size() - 1; ++i) { - v1.push_back(v[i + 1] - v[i]); - } - sum = max(sum, abs(accumulate(v1.begin(), v1.end(), 0LL))); - v = v1; - } - cout << sum << '\n'; - } -}",1 -Arbuzik_,2062C - Cirno and Operations,c++23 ,304377324,304377571,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - - - - -int main() { - int t; - cin >> t; - long long ans = 0; - for (int l = 0; l < t; l++) { - int n; - cin >> n; - long long ans = -1e18; - long long sum = 0; - vector a; - a.resize(n); - for (int i = 0; i < n;i++) { - cin >> a[i]; - } - for (int i = 0; i < n;i++) { - long long sum = 0; - for (int j = 0; j < n - i;j++) { - sum += a[j]; - } - if (n == 1 || n == 2) { - ans = sum; - continue; - } - ans = max(ans, max(sum, -sum)); - for (int j = 0; j < n - i - 1;j++) { - a[j] = a[j + 1] - a[j]; - } - } - cout << ans << endl; - - - } - -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - - - - -int main() { - int t; - cin >> t; - long long ans = 0; - for (int l = 0; l < t; l++) { - int n; - cin >> n; - long long ans = -1e18; - long long sum = 0; - vector a; - a.resize(n); - for (int i = 0; i < n;i++) { - cin >> a[i]; - } - for (int i = 0; i < n;i++) { - long long sum = 0; - for (int j = 0; j < n - i;j++) { - sum += a[j]; - } - if (i == 0) { - ans = max(ans,sum); - } - else { - ans = max(ans, max(sum, -sum)); - } - for (int j = 0; j < n - i - 1;j++) { - a[j] = a[j + 1] - a[j]; - } - } - cout << ans << endl; - - - } - -} -",2 -wallace_QwQ,2062C - Cirno and Operations,c++23 ,306285794,306285723,"#include -#define for1(i,a,b) for(int i=(a); (i)<=(b); ++(i)) -#define for2(i,a,b) for(int i=(a); (i)>=(b); --(i)) -#define pedl cout<<""\n""; -#define fi first -#define se second -#define pf push_front -#define pb push_back -#define of pop_front -#define ob pop_back -#define ls p<<1 -#define rs p<<1|1 -#define lson ls,l,mid -#define rson rs,mid+1,r -using namespace std; -mt19937 rnd(time(0));//uint -mt19937_64 rnd_64(time(0));//ull -template void cmin(T& x, T y) {if(x > y) x = y;} -template void cmax(T& x, T y) {if(x < y) x = y;} -template void rin(T& x){ -x=0;bool flag(0);char ch=getchar();while(!isdigit(ch)) flag=ch=='-',ch=getchar(); -while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48),ch=getchar();}flag?x=-x:0;} -template void rout(T x,bool flag=0){ -x<0?x=-x,putchar('-'):0;static short S[50],tp(0);do S[++tp]=x%10,x/=10;while(x); -while(tp){putchar(S[tp--]|48);}flag?putchar('\n'):putchar(' ');} -template T gcd(T x, T y) {return y?gcd(y,x%y):x;} -template T lcm(T x, T y) {return x/gcd(x,y)*y;} -typedef double db; -typedef long double ld; -typedef long long LL; -typedef unsigned long long ULL; -typedef pair P; -const double eps = 1e-7; -const int base = 13331; -const int N = 1e5+5; -const int M = 1e5+5; -const int IINF = 0x3f3f3f3f; -const LL LINF = 1e18; -const LL mod = 10007; - -LL qpow(LL x,LL y,LL Mod=mod) { - if(y==0) return 1; - LL res=(x%=Mod); y--; /*y%=(mod-1);*/ - for(;y;y>>=1,x=x*x%Mod) - if(y&1) res=res*x%Mod; - return res; -} -template -void madd(T& xx,LL y,LL Mod=mod) { - LL x=1ll*xx; - if((x+=y)>0) x%=Mod; - else x+=((-x)/Mod+1)*Mod; - xx=x%Mod; -} - -LL n; -LL a[N]; -LL f[2][N]; -LL sum,ans; -void solve(){ - cin>>n; sum=ans=0; - for1(i,1,n) cin>>a[i],ans+=(f[0][i]=a[i]); - for1(i,1,n-1){ - for1(j,1,n-i) - sum+=(f[i%2][j]=f[(i%2)^1][j]-f[(i%2)^1][j+1]); - cmax(ans,abs(sum)); - sum=0; - } - cout<>Testcase; -while(Testcase--){ - solve(); -} - time_t duration=clock()-start; - cerr<<""\ntime=""< -#define for1(i,a,b) for(int i=(a); (i)<=(b); ++(i)) -#define for2(i,a,b) for(int i=(a); (i)>=(b); --(i)) -#define pedl cout<<""\n""; -#define fi first -#define se second -#define pf push_front -#define pb push_back -#define of pop_front -#define ob pop_back -#define ls p<<1 -#define rs p<<1|1 -#define lson ls,l,mid -#define rson rs,mid+1,r -using namespace std; -mt19937 rnd(time(0));//uint -mt19937_64 rnd_64(time(0));//ull -template void cmin(T& x, T y) {if(x > y) x = y;} -template void cmax(T& x, T y) {if(x < y) x = y;} -template void rin(T& x){ -x=0;bool flag(0);char ch=getchar();while(!isdigit(ch)) flag=ch=='-',ch=getchar(); -while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48),ch=getchar();}flag?x=-x:0;} -template void rout(T x,bool flag=0){ -x<0?x=-x,putchar('-'):0;static short S[50],tp(0);do S[++tp]=x%10,x/=10;while(x); -while(tp){putchar(S[tp--]|48);}flag?putchar('\n'):putchar(' ');} -template T gcd(T x, T y) {return y?gcd(y,x%y):x;} -template T lcm(T x, T y) {return x/gcd(x,y)*y;} -typedef double db; -typedef long double ld; -typedef long long LL; -typedef unsigned long long ULL; -typedef pair P; -const double eps = 1e-7; -const int base = 13331; -const int N = 1e5+5; -const int M = 1e5+5; -const int IINF = 0x3f3f3f3f; -const LL LINF = 1e18; -const LL mod = 10007; - -LL qpow(LL x,LL y,LL Mod=mod) { - if(y==0) return 1; - LL res=(x%=Mod); y--; /*y%=(mod-1);*/ - for(;y;y>>=1,x=x*x%Mod) - if(y&1) res=res*x%Mod; - return res; -} -template -void madd(T& xx,LL y,LL Mod=mod) { - LL x=1ll*xx; - if((x+=y)>0) x%=Mod; - else x+=((-x)/Mod+1)*Mod; - xx=x%Mod; -} - -int n; -int a[N]; -int f[2][N]; -LL sum,ans; -void solve(){ - cin>>n; sum=ans=0; - for1(i,1,n) cin>>a[i],ans+=(f[0][i]=a[i]); - for1(i,1,n-1){ - for1(j,1,n-i) - sum+=(f[i%2][j]=f[(i%2)^1][j]-f[(i%2)^1][j+1]); - cmax(ans,abs(sum)); - sum=0; - } - cout<>Testcase; -while(Testcase--){ - solve(); -} - time_t duration=clock()-start; - cerr<<""\ntime=""< -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -class Newbie { -public: - void solveOne() { - - } - - void solveTwo() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - long long A[n]; - long long ans = 0; - for (long long &x: A) { - cin >> x; - ans += x; - } - int tmpN = n; - while (tmpN > 1) { - reverse(A, A + tmpN); - long long sum = 0; - for (int i = 0; i < tmpN - 1; ++i) { - A[i] = (A[i + 1] - A[i]); - } - tmpN--; - sum = accumulate(A, A + tmpN, 0LL); - ans = max({ans, sum, -sum}); - } - cout << ans << ""\n""; - } - } -}; - - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - cout.tie(nullptr); - Newbie solver; - solver.solveTwo(); - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -class Newbie { -public: - void solveOne() { - - } - - void solveTwo() { - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector A(n); - long long ans = 0; - for (int &x: A) { - cin >> x; - ans += x; - } - while (A.size() > 1) { - reverse(A.begin(), A.end()); - long long sum = 0; - for (int i = 0; i < A.size() - 1; ++i) { - A[i] = (A[i + 1] - A[i]); - } - A.pop_back(); - sum = accumulate(A.begin(), A.end(), 0LL); - ans = max({ans, sum, -sum}); - } - cout << ans << ""\n""; - } - } -}; - - -int main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - cout.tie(nullptr); - Newbie solver; - solver.solveTwo(); - return 0; -} -",1 -kojima,2062C - Cirno and Operations,c++17 ,305030231,305029708,"#include ""bits/stdc++.h"" -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define sz(x) (int)(x).size() -#define int long long - -using namespace std; -using ll = long long; -using pii = pair; - -const char nl = '\n'; -const ll LINF = 0x3f3f3f3f3f3f3f3f; -const int INF = 0x3f3f3f3f; - -void solve() { - int n; cin >> n; - vector v(n); for (auto &x : v) cin >> x; - - int ans = accumulate(all(v), 0); - - while (sz(v) > 1) { - ans = max(ans, abs(v[0] - v.back())); - - for (int i = 0; i < sz(v) - 1; i++) - v[i] = v[i + 1] - v[i]; - v.pop_back(); - - ans = max(ans, abs(v[0] - v.back())); - } - - cout << ans << nl; -} - -int32_t main() { - ios::sync_with_stdio(0), cin.tie(0); - - int t; cin >> t; - while(t--) { - solve(); - } - - return 0; -} -","#include ""bits/stdc++.h"" -#define ff first -#define ss second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define sz(x) (int)(x).size() -#define int long long - -using namespace std; -using ll = long long; -using pii = pair; - -const char nl = '\n'; -const ll LINF = 0x3f3f3f3f3f3f3f3f; -const int INF = 0x3f3f3f3f; - -void solve() { - int n; cin >> n; - vector v(n); for (auto &x : v) cin >> x; - - int ans = accumulate(all(v), 0LL); - - while (sz(v) > 1) { - for (int i = 0; i < sz(v) - 1; i++) - v[i] = v[i + 1] - v[i]; - v.pop_back(); - - ans = max(ans, abs(v[0] - v.back())); - } - - cout << ans << nl; -} - -int32_t main() { - ios::sync_with_stdio(0), cin.tie(0); - - int t; cin >> t; - while(t--) { - solve(); - } - - return 0; -} -",1 -QQ0508,2063B - Subsequence Update,c++17 ,309080556,309078459,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define int long long - -typedef pair PII; - -typedef vector vi; - -typedef vector vc; - - - -const int N =2e5+10, INF = 0x3f3f3f3f,mod=1e9+7; - -int a[N],b[N]; - -int dx[]={-1,-1,1,1}; - -int dy[]={1,-1,1,-1}; - - - -void solve() { - - int n,l,r; - - cin>>n>>l>>r; - - int idx1 = 1,idx = 1; - - for(int i = 1;i<=n;i++){ - - int x;cin>>x; - - if(i<=r){ - - a[idx1++] = x; - - } - - if(i>=l){ - - b[idx++] = x; - - } - - } - - int len = r-l+1; - - - - sort(a+1,a+idx1); - - sort(b+1,b+idx); - - int sum1 = 0,sum2 = 0; - - for(int i = 1;i<=len;i++){ - - sum1+=a[i]; - - sum2+=b[i]; - - } - - - - cout<>t; - - while(t--){ - - solve(); - - } - - return 0; - -} - - - -","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - -#define int long long - -typedef pair PII; - -typedef vector vi; - -typedef vector vc; - - - -const int N =2e5+10, INF = 0x3f3f3f3f,mod=1e9+7; - -int a[N]; - -int dx[]={-1,-1,1,1}; - -int dy[]={1,-1,1,-1}; - - - -void solve() { - - int n,l,r; - - cin>>n>>l>>r; - - for(int i = 1;i<=n;i++){ - - cin>>a[i]; - - } - - int len = r-l+1; - - if(l==r){ - - cout<<0<<'\n'; - - return ; - - } - - sort(a+1,a+1+n); - - int sum = 0; - - for(int i = 1;i<=len;i++){ - - sum+=a[i]; - - } - - - - cout<>t; - - while(t--){ - - solve(); - - } - - return 0; - -} - - - -",1 -jg_moren#,2063B - Subsequence Update,c++23 ,304598251,304598854,"#include - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define vvii vector>> - -#define it vector::iterator - -#define ii pair - -#define fori(i,ini,fim) for(int i=ini;i> n >> l >> r; - - vll v1, v2; - - - - fori( i, 0, n ){ - - ll a; cin >> a; - - if( i < r ) v1.pb(a); - - if( l <=l ) v2.pb(a); - - } - - - - sort(all(v1)); - - sort(all(v2)); - - - - ll sumv1 = 0; - - ll sumv2 = 0; - - - - fori( i, 0, r - l + 1 ) sumv1 += v1[i]; - - fori( i, 0, r - l + 1 ) sumv2 += v2[i]; - - - - cout << min( sumv1, sumv2 ) << endl; - - - - - -} - - - -int main(){ - - ios_base::sync_with_stdio(false);cin.tie(NULL); - - int TC;cin>>TC; - - while (TC--)fun(); - - return 0; - -} - - - -","#include - -#define vi vector - -#define vll vector - -#define vvi vector> - -#define vvii vector>> - -#define it vector::iterator - -#define ii pair - -#define fori(i,ini,fim) for(int i=ini;i> n >> l >> r; - - vll v1, v2; - - - - fori( i, 0, n ){ - - ll a; cin >> a; - - if( i <= r -1 ) v1.pb(a); - - if( l - 1 <=i ) v2.pb(a); - - } - - - - sort(all(v1)); - - sort(all(v2)); - - - - ll sumv1 = 0; - - ll sumv2 = 0; - - - - fori( i, 0, r - l + 1 ) sumv1 += v1[i]; - - fori( i, 0, r - l + 1 ) sumv2 += v2[i]; - - - - cout << min( sumv1, sumv2 ) << endl; - - - - - -} - - - -int main(){ - - ios_base::sync_with_stdio(false);cin.tie(NULL); - - int TC;cin>>TC; - - while (TC--)fun(); - - return 0; - -} - - - -",2 -coder_adarsh,2063B - Subsequence Update,c++17 ,309071899,309066759,"#include - -#define ll long long - -using namespace std; - -void solve(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vectora(n); - - for(ll i=0;i>a[i]; - - } - - vectorv1(a.begin(),a.begin()+r); - - vectorv2(a.begin()+l-1,a.end()); - - sort(v1.begin(),v1.end()); - - sort(v2.begin(),v2.end()); - - ll d=(r-l+1); - - ll sum1=0; - - ll sum2=0; - - for(ll i=0;i>t; - - while(t--){ - - solve(); - - } - - - - - -}","#include - -#define ll long long - -using namespace std; - -void solve(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vectora(n); - - for(ll i=0;i>a[i]; - - } - - sort(a.begin(),a.end()); - - ll d=(r-l+1); - - ll sum=0; - - for(ll i=0;i>t; - - while(t--){ - - solve(); - - } - - - - - -}",1 -Rudransh_,2063B - Subsequence Update,c++17 ,305919662,305919056,"#include - -#include - -#include - -using namespace std; - -using namespace __gnu_pbds; - - - -#define ff first - -#define ss second - -#define int long long - -#define pb push_back - -#define mp make_pair - -#define pii pair - -#define vi vector - -#define mii map - -#define pqb priority_queue - -#define pqs priority_queue> - -#define setbits(x) __builtin_popcountll(x) - -#define zrobits(x) __builtin_ctzll(x) - -#define mod 100000007 - -#define inf 1e18 - -#define ps(x, y) fixed << setprecision(y) << x - -#define mk(arr, n, type) type *arr = new type[n] - -#define w(x) \ - - int x; \ - - cin >> x; \ - - while (x--) - - - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - - - -void c_p_c() - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0); - - cout.tie(0); - -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - - freopen(""output.txt"", ""w"", stdout); - -#endif - -} - - - -int32_t main() - -{ - - c_p_c(); - - w(x) - - { - - int n; - - int l; - - int r; - - cin >> n >> l >> r; - - vi arr(n); - - for (int i = 0; i < n; i++) - - cin >> arr[i]; - - vi left_seg; - - vi right_seg; - - vi seg; - - for (int i = l - 1; i < r; i++) - - { - - seg.pb(arr[i]); - - } - - for (int i = 0; i < l - 1; i++) - - { - - left_seg.pb(arr[i]); - - } - - for (int i = r; i < n; i++) - - { - - right_seg.pb(arr[i]); - - } - - - - sort(seg.begin(), seg.end()); - - sort(left_seg.begin(), left_seg.end()); - - sort(right_seg.begin(), right_seg.end()); - - vi temp = seg; - - int left = 0; - - int s = seg.size() - 1; - - while (s >= 0 && left < left_seg.size() && left_seg[left] < seg[s]) - - { - - seg[s] = left_seg[left]; - - s--; - - left++; - - } - - int answer_left = accumulate(seg.begin(), seg.end(), 0LL); - - - - int right = 0; - - s = temp.size() - 1; - - while (s >= 0 && right < right_seg.size() && right_seg[right] < temp[s]) - - { - - temp[s] = right_seg[right]; - - s--; - - right++; - - } - - int answer_right = accumulate(temp.begin(), temp.end(), 0LL); - - int final_answer = min(answer_left, answer_right); - - - - cout << final_answer << endl; - - } - - return 0; - -} - -","#include -#include -#include -using namespace std; -using namespace __gnu_pbds; - -#define ff first -#define ss second -#define int long long -#define pb push_back -#define mp make_pair -#define pii pair -#define vi vector -#define mii map -#define pqb priority_queue -#define pqs priority_queue> -#define setbits(x) __builtin_popcountll(x) -#define zrobits(x) __builtin_ctzll(x) -#define mod 100000007 -#define inf 1e18 -#define ps(x, y) fixed << setprecision(y) << x -#define mk(arr, n, type) type *arr = new type[n] -#define w(x) \ - int x; \ - cin >> x; \ - while (x--) - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -void c_p_c() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif -} - -int32_t main() -{ - c_p_c(); - w(x) - { - int n; - int l; - int r; - cin >> n >> l >> r; - vi arr(n); - for (int i = 0; i < n; i++) - cin >> arr[i]; - vi left_seg; - vi right_seg; - vi seg; - for (int i = l - 1; i < r; i++) - { - seg.pb(arr[i]); - } - for (int i = 0; i < l - 1; i++) - { - left_seg.pb(arr[i]); - } - for (int i = r; i < n; i++) - { - right_seg.pb(arr[i]); - } - - sort(seg.begin(), seg.end()); - sort(left_seg.begin(), left_seg.end()); - sort(right_seg.begin(), right_seg.end()); - vi temp = seg; - int left = 0; - int s = seg.size() - 1; - while (s >= 0 && left < left_seg.size() && left_seg[left] < seg[s]) - { - seg[s] = left_seg[left]; - s--; - left++; - } - int answer_left = accumulate(seg.begin(), seg.end(), 0); - - int right = 0; - s = temp.size() - 1; - while (s >= 0 && right < right_seg.size() && right_seg[right] < temp[s]) - { - temp[s] = right_seg[right]; - s--; - right++; - } - int answer_right = accumulate(temp.begin(), temp.end(), 0); - int final_answer = min(answer_left, answer_right); - - cout << final_answer << endl; - } - return 0; -} -",1 -Qa_2me,2063B - Subsequence Update,c++23 ,306216686,306220150,"#include -#include -#include -#include -#include -using ll=long long; -using ld=long double; -using namespace std; - - - -int main() { - int t;cin>>t; - while(t--){ - int n,l,r;cin>>n>>l>>r; - vector v(n); - for(int i=0;i>v[i]; - } - sort(v.begin(),v.end()); - ll ans=0; - for(int i=0;i<=r-l;i++){ - ans+=v[i]; - - } - cout< - -#include - -#include - -#include - -#include - -using ll=long long; - -using ld=long double; - -using namespace std; - - - - - - - -int main() { - - int t;cin>>t; - - while(t--){ - - int n,l,r;cin>>n>>l>>r; - - l--; - - vector v(n); - - - - for(int i=0;i>v[i]; - - - - } - - vector brr = v, crr = v; - - sort(brr.begin()+l,brr.end()); - - sort(crr.begin(),crr.begin()+r,greater()); - - - - ll ans1=0,ans2=0; - - for(int i=l;i -#include -#include -using namespace std; - -int main(){ - //t test case - int t; - cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - vector a(n); - for(int i=0;i>a[i]; - } - sort(a.begin(),a.begin()+l-1); - sort(a.begin()+l-1,a.begin()+r); - sort(a.end()-n+r,a.end()); - int sum1=0; - int sum2=0; - int i=0; - int j=r-1; - // for(int i=0;ia[i] && ia[j] && j -#include -#include -using namespace std; - -int main(){ - //t test case - int t; - cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - vector a(n); - for(int i=0;i>a[i]; - } - sort(a.begin(),a.begin()+l-1); - sort(a.begin()+l-1,a.begin()+r); - sort(a.end()-n+r,a.end()); - long long int sum1=0; - long long int sum2=0; - int i=0; - int j=r-1; - // for(int i=0;ia[i] && i=l-1){ - sum1+=a[j]-a[i]; - i++; - j--; - } - i=r-1; - j=r; - while(a[i]>a[j] && j=l-1){ - sum2+=a[i]-a[j]; - i--; - j++; - } - long long int sumf=0; - for(int i=l-1;i - -using namespace std; - -int main(){ - - int k; - - cin >> k; - - while(k--){ - - int n,l,r; - - cin >> n >> l >> r; - - vectorarr1(n,0); - - for(int i=0;i> arr1[i]; - - priority_queue,greater>q; - - for(int i=0;i - -using namespace std; - -int main(){ - - int k; - - cin >> k; - - while(k--){ - - int n,l,r; - - cin >> n >> l >> r; - - vectorarr1(n,0); - - for(int i=0;i> arr1[i]; - - priority_queue,greater>q; - - for(int i=0;i - -using namespace std; - -void solve(){ - - long long n,l,r; - - long long ans=0,s=0; - - cin>>n>>l>>r; - - int a[n],c[n]; - - for(int i=0;i>a[i]; - - c[i]=a[i]; - -} - - sort(a,a+r); - - sort(c+l-1,c+n); - - for(int i=0;i>T; - - while(T--)solve(); - - return 0; - -} ","#include - -using namespace std; - -void solve(){ - - long long n,l,r; - - long long ans=0,s=0; - - cin>>n>>l>>r; - - int a[n],c[n]; - - for(int i=0;i>a[i]; - - c[i]=a[i]; - -} - - sort(a,a+r); - - sort(c+l-1,c+n); - - for(int i=0;i>T; - - while(T--)solve(); - - return 0; - -} ",1 -_spjy,2063B - Subsequence Update,c++20 ,303882074,303881657,"#include -#include -#include -using namespace std; -typedef long long LL; -int main() { - int t; - cin >> t; - while (t--) { - int n, l, r; - cin >> n >> l >> r; - vector a(n + 1); - for (int i = 1; i <= n; i++) { - cin >> a[i]; - } - auto b = a; - LL sum1 = 0, sum2 = 0; - sort(a.begin() + 1, a.begin() + r + 1); - for (int i = 1; i <= r-l+1; i++) { - sum1 += a[i]; - } - sort(b.begin() + l, b.end()); - for (int i = l; i <= r; i++) { - sum2 += b[i]; - } - //cout << sum1 <<' '<< sum2; - LL ans = min(sum1, sum2); - cout << ans << endl; - } - - return 0; -}","#include -#include -#include -using namespace std; -int main() { - int t; - cin >> t; - while (t--) { - int n, l, r; - cin >> n >> l >> r; - vector a(n); - for (int i = 0; i < n; i++) { - cin >> a[i]; - } - auto b = a; - int sum1 = 0, sum2 = 0; - sort(a.begin(), a.begin() + r-1); - for (int i = 0; i < r-l; i++) { - sum1 += a[i]; - } - sort(b.begin() + l-1, b.end()); - for (int i = l-1; i < r; i++) { - sum2 += b[i]; - } - //cout << sum1 <<' '<< sum2; - int ans = min(sum1, sum2); - cout << ans << endl; - } - - return 0; -}",1 -mrinal_2,2063B - Subsequence Update,c++17 ,306089190,306088737,"#include - -#define ll long long - -#define vi vector - -#define vvi vector> - -#define vc vector - -#define fi for(int i=0;i - -#define umi unordered_map - -#define usi unordered_set - -#define maxheapint priority_queue - -#define maxheappair priority_queue> - -#define minheapint priority_queue,greater> - -#define minheappair priority_queue,vector>,greater>> - -using namespace std; - -void print(vector &a){ - - for(auto i:a) cout<>t; - - while(t--){ - - ll n,l,r; - - cin>>n>>l>>r; - - vector a(n); - - fi cin>>a[i]; - - vector b(a.begin()+l-1,a.begin()+r); - - ll ans=accumulate(b.begin(),b.end(),0LL); - - sort(b.begin(),b.end(),greater()); - - vector left,right; - - ll ans1=ans,ans2=ans; - - for(ll i=0;i left1,right1; - - ll szl=left.size(),szr=right.size(); - - for(ll i=0;i - -#define ll long long - -#define vi vector - -#define vvi vector> - -#define vc vector - -#define fi for(int i=0;i - -#define umi unordered_map - -#define usi unordered_set - -#define maxheapint priority_queue - -#define maxheappair priority_queue> - -#define minheapint priority_queue,greater> - -#define minheappair priority_queue,vector>,greater>> - -using namespace std; - -void print(vector &a){ - - for(auto i:a) cout<>t; - - while(t--){ - - ll n,l,r; - - cin>>n>>l>>r; - - vector a(n); - - fi cin>>a[i]; - - vector b(a.begin()+l-1,a.begin()+r); - - ll ans=accumulate(b.begin(),b.end(),0); - - sort(b.begin(),b.end(),greater()); - - vector left,right; - - ll ans1=ans,ans2=ans; - - for(ll i=0;i left1,right1; - - ll szl=left.size(),szr=right.size(); - - for(ll i=0;i - -#define ll long long - -using namespace std; - - - -ll func(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vectorv(n); - - for(ll i=0;i>v[i]; - - } - - vectors(n); - - for(ll i=0;i>t; - - while(t--){ - - cout< - -#define ll long long - -using namespace std; - - - -int func(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vectorv(n); - - for(int i=0;i>v[i]; - - } - - vectors(n); - - for(int i=0;i>t; - - while(t--){ - - cout< - -using namespace std; - - - -#define F(i, n) for (int i = 0; i < n; i++) - -#define vi vector - -#define ln long long int - -#define test int t; cin >> t; while (t--) - -#define ll long long - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x << "" -> ""; _print(x); cerr << endl - -#else - -#define debug(x) - -#endif - - - -void _print(int a) { cerr << a << "" ""; } - -void _print(long long a) { cerr << a << "" ""; } - -void _print(char a) { cerr << a << "" ""; } - -void _print(string a) { cerr << a << "" ""; } - -void _print(bool a) { cerr << a << "" ""; } - -template void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "",""; _print(p.second); cerr << ""}""; } - -template void _print(vector v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(set v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(multiset v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(map v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "",""; _print(p.second); cerr << ""}""; } - -template void _print(multimap v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_set v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_multiset v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_map v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - - - -void solve(){ - - int n,l,r; cin >> n >> l >> r; - - vectorv(n); - - for(int i = 0; i> v[i]; - - - - l--,r--; - - vectorleft; - - vectorright; - - for(int i = 0; i<=r; i++){ - - left.push_back(v[i]); - - } - - for(int i = l; i - -using namespace std; - - - -#define F(i, n) for (int i = 0; i < n; i++) - -#define vi vector - -#define ln long long int - -#define test int t; cin >> t; while (t--) - -#define ll long long - - - -#ifndef ONLINE_JUDGE - -#define debug(x) cerr << #x << "" -> ""; _print(x); cerr << endl - -#else - -#define debug(x) - -#endif - - - -void _print(int a) { cerr << a << "" ""; } - -void _print(long long a) { cerr << a << "" ""; } - -void _print(char a) { cerr << a << "" ""; } - -void _print(string a) { cerr << a << "" ""; } - -void _print(bool a) { cerr << a << "" ""; } - -template void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "",""; _print(p.second); cerr << ""}""; } - -template void _print(vector v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(set v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(multiset v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(map v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(pair p) { cerr << ""{""; _print(p.first); cerr << "",""; _print(p.second); cerr << ""}""; } - -template void _print(multimap v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_set v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_multiset v) { cerr << ""[ ""; for (T i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - -template void _print(unordered_map v) { cerr << ""[ ""; for (auto i : v) { _print(i); cerr << "" ""; } cerr << ""]""; } - - - -void solve(){ - - int n,l,r; cin >> n >> l >> r; - - vectorv(n); - - for(int i = 0; i> v[i]; - - - - l--,r--; - - vectorleft; - - vectorright; - - for(int i = 0; i<=r; i++){ - - left.push_back(v[i]); - - } - - for(int i = l; i - -using namespace std; - -#define endl '\n' - -#define inv(x) ksm(x, mod - 2) - -#define int long long - -#define NO cout << ""NO"" << endl - -#define YES cout << ""YES"" << endl - -#define No cout << ""No"" << endl - -#define Yes cout << ""Yes"" << endl - -#define lowbit(x) ((x) & (-x)) - -#define mem(a, b) memset(a, b, sizeof(a)) - -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); - -// const int mod = 998244353; - -const int mod = 1e9 + 7; - -const int inf = 1e18; - -double logn(int n,double x){return log(x)/log(n);} - -int ksm(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;} - -typedef long long ll; - -typedef pair pii; - -typedef pair, int> piii; - -const int N = 2e5 + 5; - -int dx[4] = {0, 1, -1, 0}; - -int dy[4] = {1, 0, 0, -1}; - -void solve() - -{ - - int n; - - cin >> n; - - int l, r; - - cin >> l >> r; - - vector a(n + 1); - - for (int i = 1; i <= n;i++) - - cin >> a[i]; - - sort(a.begin() + 1, a.end()); - - int g = r - l + 1; - - int sum = 0; - - for (int i = 1; i <= g;i++) - - sum += a[i]; - - cout << sum << endl; - -} - -signed main(){ - - cin.tie(0); - - cout.tie(0); - - ios::sync_with_stdio(false); - - int t; - - t = 1; - - cin >> t; - - while (t--) - - solve(); - -}","#include - -using namespace std; - -#define endl '\n' - -#define inv(x) ksm(x, mod - 2) - -#define int long long - -#define NO cout << ""NO"" << endl - -#define YES cout << ""YES"" << endl - -#define No cout << ""No"" << endl - -#define Yes cout << ""Yes"" << endl - -#define lowbit(x) ((x) & (-x)) - -#define mem(a, b) memset(a, b, sizeof(a)) - -mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); - -// const int mod = 998244353; - -const int mod = 1e9 + 7; - -const int inf = 1e18; - -double logn(int n,double x){return log(x)/log(n);} - -int ksm(int a, int b){int ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod;b>>=1;}return ans;} - -typedef long long ll; - -typedef pair pii; - -typedef pair, int> piii; - -const int N = 2e5 + 5; - -int dx[4] = {0, 1, -1, 0}; - -int dy[4] = {1, 0, 0, -1}; - -void solve() - -{ - - int n; - - cin >> n; - - int l, r; - - cin >> l >> r; - - vector a(n + 1); - - for (int i = 1; i <= n;i++) - - cin >> a[i]; - - priority_queue s; - - for (int i = l; i <= r;i++) - - s.push(a[i]); - - for (int i = 1; i < l;i++) - - { - - if(s.top()>a[i]) - - s.pop(), s.push(a[i]); - - } - - int minn = 0; - - while(s.size()) - - minn += s.top(), s.pop(); - - for (int i = l; i <= r;i++) - - s.push(a[i]); - - for (int i = r + 1;i<=n;i++) - - if(s.top()>a[i]) - - s.pop(), s.push(a[i]); - - int sum = 0; - - while(s.size()) - - sum += s.top(), s.pop(); - - minn = min(minn, sum); - - cout << minn << endl; - -} - -signed main(){ - - cin.tie(0); - - cout.tie(0); - - ios::sync_with_stdio(false); - - int t; - - t = 1; - - cin >> t; - - while (t--) - - solve(); - -}",2 -jikong,2063B - Subsequence Update,c++23 ,303929952,303930115,"#include -#include -#include -#define endl '\n' -using namespace std; -const int N = 1e5 + 10; - -void solve(){ - int n, l, r; - cin >> n >> l >> r; - int a[N], b[N]; - for(int i = 1; i <= n; i++){ - cin >> a[i]; - b[i] = a[i]; - } - sort(a + 1, a + 1 + r); - sort(b + l, b + 1 + n); - long long res1 = 0, res2 = 0; - for(int i = 1; i <= r - l + 1; i++){ - res1 += a[i]; - } - for(int i = l; i <= r; i++){ - res2 += b[i]; - } - cout << min(res1, res2); -} - -int main(){ - ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - int T; - cin >> T; - while(T--){ - solve(); - } - return 0; -}","#include -#include -#include -#define endl '\n' -using namespace std; -const int N = 1e5 + 10; - -void solve(){ - int n, l, r; - cin >> n >> l >> r; - int a[N], b[N]; - for(int i = 1; i <= n; i++){ - cin >> a[i]; - b[i] = a[i]; - } - sort(a + 1, a + 1 + r); - sort(b + l, b + 1 + n); - long long res1 = 0, res2 = 0; - for(int i = 1; i <= r - l + 1; i++){ - res1 += a[i]; - } - for(int i = l; i <= r; i++){ - res2 += b[i]; - } - cout << min(res1, res2) << endl; -} - -int main(){ - ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); - int T; - cin >> T; - while(T--){ - solve(); - } - return 0; -}",2 -DingZhenGeGe,2063B - Subsequence Update,c++20 ,307147667,307148136,"#include - -using namespace std; - -void solve() { - int n, l, r; - cin >> n >> l >> r; - vector a; - for(int i = 0; i < n; i++) { - int u; - cin >> u; - a.push_back(u); - } - - sort(a.begin(), a.begin() + l - 1); - sort(a.begin() + l - 1, a.begin() + r); - sort(a.begin() + r, a.end()); - - int sum1 = 0, sum2 = 0, sum3 = 0; - int k1 = 0, k2 = r - 1, k3 = r; - int change; - - while(k1 <= l - 2 && k2 >= l - 1 && a[k1] < a[k2]) { - sum1 += a[k1++]; - sum2 += a[k2--]; - } - - change = sum2 - sum1; - k2 = r - 1; - sum2 = 0; - - while(k3 <= n - 1 && k2 >= l - 1 && a[k3] < a[k2]) { - sum3 += a[k3++]; - sum2 += a[k2--]; - } - - change = max(change, sum2 - sum3); - - int result = 0; - for(int i = l - 1; i <= r - 1; i++) { - result += a[i]; - } - result -= change; - cout << result << endl; -} - - -int main(){ - int t; - cin >> t; - while(t > 0) { - solve(); - t--; - } - return 0; -}","#include - -using namespace std; - -void solve() { - int n, l, r; - cin >> n >> l >> r; - vector a; - for(int i = 0; i < n; i++) { - int u; - cin >> u; - a.push_back(u); - } - - sort(a.begin(), a.begin() + l - 1); - sort(a.begin() + l - 1, a.begin() + r); - sort(a.begin() + r, a.end()); - - long long int sum1 = 0, sum2 = 0, sum3 = 0; - int k1 = 0, k2 = r - 1, k3 = r; - long long int change; - - while(k1 <= l - 2 && k2 >= l - 1 && a[k1] < a[k2]) { - sum1 += a[k1++]; - sum2 += a[k2--]; - } - - change = sum2 - sum1; - k2 = r - 1; - sum2 = 0; - - while(k3 <= n - 1 && k2 >= l - 1 && a[k3] < a[k2]) { - sum3 += a[k3++]; - sum2 += a[k2--]; - } - - change = max(change, sum2 - sum3); - - long long int result = 0; - for(int i = l - 1; i <= r - 1; i++) { - result += a[i]; - } - result -= change; - cout << result << endl; -} - - -int main(){ - int t; - cin >> t; - while(t > 0) { - solve(); - t--; - } - return 0; -}",2 -akool,2063B - Subsequence Update,java,305890795,305890740,"import java.util.ArrayList; -import java.util.Collections; -import java.util.Scanner; - -public class SubsequenceUpdate { - public static void main(String[] args){ - Scanner scanner = new Scanner(System.in); - int tests = Integer.parseInt(scanner.nextLine()); - while (tests > 0){ - int n = scanner.nextInt(); - int l = scanner.nextInt(); - int r = scanner.nextInt(); - long[] arr = new long[n]; - for (int i = 0; i < arr.length; i++){ - arr[i] = scanner.nextLong(); - } - - ArrayList toL = new ArrayList<>(); - ArrayList toR = new ArrayList<>(); - for (int i = 0; i < r; i++){ - toR.add(arr[i]); - } - for (int i = l - 1; i < n; i++){ - toL.add(arr[i]); - } - - Collections.sort(toL); - Collections.sort(toR); - - long sumOne = 0; - for (int i = 0; i < r - l + 1; i++){ - sumOne += toL.get(i); - } - - long sumTwo = 0; - for (int i = 0; i < r - l + 1; i++){ - sumTwo += toR.get(i); - } - - System.out.println(Math.min(sumTwo, sumOne)); - tests--; - } - } -} -","import java.util.ArrayList; - -import java.util.Collections; - -import java.util.Scanner; - - - -public class SubsequenceUpdate { - - public static void main(String[] args){ - - Scanner scanner = new Scanner(System.in); - - int tests = Integer.parseInt(scanner.nextLine()); - - while (tests > 0){ - - int n = scanner.nextInt(); - - int l = scanner.nextInt(); - - int r = scanner.nextInt(); - - long[] arr = new long[n]; - - for (int i = 0; i < arr.length; i++){ - - arr[i] = scanner.nextLong(); - - } - - - - ArrayList toL = new ArrayList<>(); - - ArrayList toR = new ArrayList<>(); - - for (int i = 0; i < r; i++){ - - toR.add(arr[i]); - - } - - for (int i = l - 1; i < n; i++){ - - toL.add(arr[i]); - - } - - - - Collections.sort(toL); - - Collections.sort(toR); - - - - int sumOne = 0; - - for (int i = 0; i < r - l + 1; i++){ - - sumOne += toL.get(i); - - } - - - - int sumTwo = 0; - - for (int i = 0; i < r - l + 1; i++){ - - sumTwo += toR.get(i); - - } - - - - System.out.println(Math.min(sumTwo, sumOne)); - - tests--; - - } - - } - -} - -",1 -L20,2063B - Subsequence Update,c++20 ,304463025,304211106,"#include -using namespace std; - -#define ll long long int -#define ld long double -#define ek ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -void init() -{ - -} - -void solve() { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for(ll i = 0; i < n; i++) { - cin >> a[i]; - } - vector b,c,d; - ll sum=0; - for(ll i=l-1;ic[i]) { - ans+=(c[i]-b[i]); - } - } - ll ans1=sum; - for(ll i=0;id[i]) { - ans1+=(d[i]-b[i]); - } - } - cout<> t; - init(); - while(t--) - { - solve(); - } - return 0; -}","#include -using namespace std; - -#define ll long long int -#define ld long double -#define ek ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -void init() -{ - -} - -void solve() { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for(ll i = 0; i < n; i++) { - cin >> a[i]; - } - sort(a.begin(), a.end()); - ll sum=0; - for(ll i=0;i> t; - init(); - while(t--) - { - solve(); - } - return 0; -}",1 -Akshay2025#,2063B - Subsequence Update,c++17 ,304348849,304349481,"#include -using namespace std; -#define setbitcounts(x) __builtin_popcountll(x) -#define ll long long -#define pb push_back -#define ppb pop_back -#define pf push_front -#define ppf pop_front -#define all(x) (x).begin(),(x).end() -#define uniq(v) (v).erase(unique(all(v)),(v).end()) -#define sz(x) (int)((x).size()) -#define fr first -#define sc second -#define pii pair -#define pll pair -#define vii vector -#define vll vector -#define mii map -#define mci map -#define sti set -#define stc set -#define rep(i,a,b) for(int i=a;iT amax(T &a,T1 b){if(b>a)a=b;return a;} -templateT amin(T &a,T1 b){if(b>> &v, ll value){ - ll ans = -1; - while(l <= r){ - ll mid = (l+r) >> 1L; - if(v[mid].first < value){ - ans = mid; - l = mid+1; - } - else r = mid-1; - } - return ans; -} - - -int main() -{ -IOS -ll t; cin >> t; -while(t--){ -ll n, l,r; -cin >> n >> l >> r; - -vectorv(n); -rep(i,0,n) cin >> v[i]; - -sort(all(v)); - -ll k = r-l+1; - -ll ans = 0; - -rep(i,0,k){ - ans += v[i]; -} - -cout << ans << endl; -cout << endl; -} - - -return 0; -} - -/* - -*/","#include - -using namespace std; - -#define setbitcounts(x) __builtin_popcountll(x) - -#define ll long long - -#define pb push_back - -#define ppb pop_back - -#define pf push_front - -#define ppf pop_front - -#define all(x) (x).begin(),(x).end() - -#define uniq(v) (v).erase(unique(all(v)),(v).end()) - -#define sz(x) (int)((x).size()) - -#define fr first - -#define sc second - -#define pii pair - -#define pll pair - -#define vii vector - -#define vll vector - -#define mii map - -#define mci map - -#define sti set - -#define stc set - -#define rep(i,a,b) for(int i=a;iT amax(T &a,T1 b){if(b>a)a=b;return a;} - -templateT amin(T &a,T1 b){if(b>> &v, ll value){ - - ll ans = -1; - - while(l <= r){ - - ll mid = (l+r) >> 1L; - - if(v[mid].first < value){ - - ans = mid; - - l = mid+1; - - } - - else r = mid-1; - - } - - return ans; - -} - - - - - -int main() - -{ - -IOS - -ll t; cin >> t; - -while(t--){ - -ll n, l,r; - -cin >> n >> l >> r; - - - -ll k = r-l+1; - - - -vectorv(n); - -rep(i,0,n) cin >> v[i]; - - - -ll ans1 = 0; - -vectora; - -rep(i,0,r) a.push_back(v[i]); - -sort(all(a)); - -rep(i,0,k) ans1 += a[i]; - - - -ll ans2 = 0; - -vectorb; - -rep(i,l-1,n) b.push_back(v[i]); - -sort(all(b)); - -rep(i,0,k) ans2 += b[i]; - - - -ll ans = min(ans1,ans2); - -cout << ans << endl; - -cout << endl; - -} - - - - - -return 0; - -}",2 -Aarav_4761,2063B - Subsequence Update,c++17 ,306532217,306534278,"#include - -using namespace std; - - - -#define ll long long - -#define mod 1000000007 - -#define rr(i, n) for (int i = 0; i < n; i++) - -#define pb push_back - -#define all(v) v.begin(), v.end() - -#define nn '\n' - - - -// Fast Input-Output - -void fastIO() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - -} - - - -int main() - -{ - - fastIO(); - - - - int t; - - cin >> t; - - while (t--) - - { - - int n, l, r; - - cin >> n >> l >> r; - - vector a(n); - - for (int i = 0; i < n; i++) - - { - - cin >> a[i]; - - } - - - - vector before, after, btw; - - for (int i = 0; i < n; i++) - - { - - if (i < l - 1) - - before.pb(a[i]); - - else if (i > r - 1) - - after.pb(a[i]); - - else - - btw.pb(a[i]); - - } - - - - sort(all(before)); - - sort(all(after)); - - sort(all(btw)); - - - - int sum = accumulate(all(btw), 0); - - int mini = sum; - - - - int i = 0, j = btw.size() - 1; - - while (i < before.size() && j >= 0 && before[i] < btw[j]) - - { - - sum = sum - btw[j] + before[i]; - - mini = min(mini, sum); - - i++; - - j--; - - } - - - - sum = accumulate(all(btw), 0); - - - - i = 0, j = btw.size() - 1; - - while (i < after.size() && j >= 0 && after[i] < btw[j]) - - { - - sum = sum - btw[j] + after[i]; - - mini = min(mini, sum); - - i++; - - j--; - - } - - - - cout << mini << nn; - - } - - - - return 0; - -} - -","#include -using namespace std; - -#define ll long long -#define pb push_back -#define all(v) v.begin(), v.end() -#define nn '\n' - -// Fast Input-Output -void fastIO() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -int main() -{ - fastIO(); - - int t; - cin >> t; - while (t--) - { - int n, l, r; - cin >> n >> l >> r; - l--; // Adjust for 0-based index - - vector arr(n); - for (int i = 0; i < n; i++) - { - cin >> arr[i]; - } - - vector brr = arr; - sort(brr.begin() + l, brr.end()); - - vector crr = arr; - sort(crr.begin(), crr.begin() + r, greater()); - - ll sum_brr = accumulate(brr.begin() + l, brr.begin() + r, 0LL); - ll sum_crr = accumulate(crr.begin() + l, crr.begin() + r, 0LL); - - cout << min(sum_brr, sum_crr) << nn; - } - - return 0; -} -",2 -Tonmoy_Roy007,2063B - Subsequence Update,c++23 ,308066985,308074845,"#include - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define pb push_back - -#define INF 1e18 - -#define yes cout << ""YES"" << endl; - -#define no cout << ""NO"" << endl; - -#define F first - -#define S second - -#define sz(x) x.size() - -#define all(x) x.begin(), x.end() - -#define rall(x) (x).rbegin(), (x).rend() - -#define gcd(a, b) __gcd(a, b) - -#define lcm(a, b) ((a) * ((b) / gcd(a, b))) - -#define MAX3(a, b, c) max(a, max(b, c)) - -#define MIN3(a, b, c) min(a, min(b, c)) - -#define vi vector - -#define vvi vector> - -#define pii pair - -#define vii vector> - -void solve() - -{ - - ll n, l, r; - - cin >> n >> l >> r; - - vector v(n); - - for (ll i = 0; i < n; i++) - - { - - cin >> v[i]; - - } - - sort(all(v)); - - vi p(n, 0); - - for (ll i = 0; i < n; i++) - - { - - if (i == 0) - - { - - p[i] = v[i]; - - } - - else - - { - - p[i] = p[i - 1] + v[i]; - - } - - } - - ll dif = r - l + 1; - - cout << p[dif - 1] << endl; - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - solve(); - - return 0; - -}","#include - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define pb push_back - -#define INF 1e18 - -#define yes cout << ""YES"" << endl; - -#define no cout << ""NO"" << endl; - -#define F first - -#define S second - -#define sz(x) x.size() - -#define all(x) x.begin(), x.end() - -#define rall(x) (x).rbegin(), (x).rend() - -#define gcd(a, b) __gcd(a, b) - -#define lcm(a, b) ((a) * ((b) / gcd(a, b))) - -#define MAX3(a, b, c) max(a, max(b, c)) - -#define MIN3(a, b, c) min(a, min(b, c)) - -#define vi vector - -#define vvi vector> - -#define pii pair - -#define vii vector> - -void solve() - -{ - - ll n, l, r; - - cin >> n >> l >> r; - - l--; - - r--; - - vector v(n); - - for (ll i = 0; i < n; i++) - - { - - cin >> v[i]; - - } - - vi f, b; - - for (ll i = 0; i <= r; i++) - - { - - f.pb(v[i]); - - } - - for (ll i = l; i < n; i++) - - { - - b.pb(v[i]); - - } - - sort(all(f)); - - sort(all(b)); - - - - ll sum1 = accumulate(f.begin(), f.begin() + (int)(r - l + 1), 0LL); - - ll sum2 = accumulate(b.begin(), b.begin() + (int)(r - l + 1), 0LL); - - cout << min(sum1, sum2) << endl; - -} - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - int t; - - cin >> t; - - while (t--) - - solve(); - - return 0; - -}",2 -AU25tzvi,2063B - Subsequence Update,c++17 ,305447317,305447199,"#include -#include -#include -#include - -using namespace std; - -// פונקציה שמקטינה את סכום הקטע [l, r] על ידי החלפה עם חלק חיצוני -long long minimizeSegment(vector segment, vector external) { - if (external.empty()) { - return accumulate(segment.begin(), segment.end(), 0LL); - } - - sort(segment.rbegin(), segment.rend()); // מיון יורד (הגדולים ראשונים) - sort(external.begin(), external.end()); // מיון עולה (הקטנים ראשונים) - - int minSize = min(segment.size(), external.size()); - for (int i = 0; i < minSize; ++i) { - if (segment[i] > external[i]) { - swap(segment[i], external[i]); - } else { - break; - } - } - - return accumulate(segment.begin(), segment.end(), 0LL); -} - -void solve() { - int t; - cin >> t; - - while (t--) { - int n, l, r; - cin >> n >> l >> r; - vector arr(n); - - for (int i = 0; i < n; ++i) { - cin >> arr[i]; - } - - vector segment(arr.begin() + l - 1, arr.begin() + r); - vector prefix(arr.begin(), arr.begin() + (l - 1)); - vector suffix(arr.begin() + r, arr.end()); - - long long originalSum = accumulate(segment.begin(), segment.end(), 0LL); - long long sumWithPrefix = prefix.empty() ? originalSum : minimizeSegment(segment, prefix); - long long sumWithSuffix = suffix.empty() ? originalSum : minimizeSegment(segment, suffix); - - cout << min({originalSum, sumWithPrefix, sumWithSuffix}) << '\n'; - } -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - solve(); - - return 0; -} -","#include - -#include - -#include - -#include - - - -using namespace std; - - - -// פונקציה שמקטינה את סכום הקטע [l, r] על ידי החלפה עם חלק חיצוני - -long long minimizeSegment(vector& segment, vector& external) { - - sort(segment.rbegin(), segment.rend()); // מיון יורד (הגדולים ראשונים) - - sort(external.begin(), external.end()); // מיון עולה (הקטנים ראשונים) - - - - int minSize = min(segment.size(), external.size()); - - for (int i = 0; i < minSize; ++i) { - - if (segment[i] > external[i]) { - - swap(segment[i], external[i]); - - } else { - - break; - - } - - } - - - - return accumulate(segment.begin(), segment.end(), 0LL); - -} - - - -void solve() { - - int t; - - cin >> t; - - - - while (t--) { - - int n, l, r; - - cin >> n >> l >> r; - - vector arr(n); - - - - for (int i = 0; i < n; ++i) { - - cin >> arr[i]; - - } - - - - vector segment(arr.begin() + l - 1, arr.begin() + r); - - vector prefix(arr.begin(), arr.begin() + (l - 1)); - - vector suffix(arr.begin() + r, arr.end()); - - - - long long sumWithPrefix = prefix.empty() ? LLONG_MAX : minimizeSegment(segment, prefix); - - long long sumWithSuffix = suffix.empty() ? LLONG_MAX : minimizeSegment(segment, suffix); - - - - cout << min(sumWithPrefix, sumWithSuffix) << '\n'; - - } - -} - - - -int main() { - - ios::sync_with_stdio(false); - - cin.tie(nullptr); - - - - solve(); - - - - return 0; - -} - -",1 -Young1598,2063B - Subsequence Update,c++23 ,306634577,306633642,"#include - -using namespace std; - -using ll = long long; - -using ull = unsigned long long; - -#define endl ""\n""; - - - -void solve() - -{ - - int k; - - cin >> k; - - - - int l,r; - - cin>>l>>r; - - - - int len=r-l+1; - - - - vectora; - - vectorb(len); - - vectorc; - - - - int m=0,n=0; - - ll sum1=0,sum2=0; - - int len1=0,len2=0; - - for(int i=0;i=l&&i+1<=r) - - { - - cin>>b[n]; - - sum1+=b[n]; - - n++; - - } - - else if(i+1>num; - - a.push_back(num); - - len1++; - - } - - else if(i+1>r) - - { - - int num2; - - cin>>num2; - - c.push_back(num2); - - len2++; - - } - - } - - sum2=sum1; - - - - sort(a.begin(),a.end()); - - sort(b.begin(),b.end()); - - sort(c.begin(),c.end()); - - - - for(int i=0;i> t; - - - - while (t--) - - { - - solve(); - - } - - - - return 0; - -}","#include -using namespace std; -using ll = long long; -using ull = unsigned long long; -#define endl ""\n""; - -void solve() -{ - int k; - cin >> k; - - int l,r; - cin>>l>>r; - - int len=r-l+1; - - vectora(k-len); - vectorb(len); - - int m=0,n=0; - ll sum1=0,sum2=0; - for(int i=0;i=l&&i+1<=r) - { - cin>>b[n]; - sum2+=b[n]; - n++; - } - else - { - cin>>a[m]; - sum1+=a[m]; - m++; - } - } - - sort(a.begin(),a.end()); - sort(b.begin(),b.end()); - - for(int i=0;i> t; - - while (t--) - { - solve(); - } - - return 0; -}",1 -OUYU_NOW,2063B - Subsequence Update,c++20 ,306868428,306867739,"#include -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) -#define endl '\n' -#define int long long -#define PII pair -#define _rep(i,a,b) for( int i=(a); i<=(b); ++i) -#define _per(i,a,b) for( int i=(a); i>=(b); --i) -using namespace std; -const int N = 1e6+10 ; -const int M = 1e3+10 ; -const int INF = 0x3f3f3f3f3f3f3f3f; -const int MOD = 1e9 + 7 ; -const double eps = 1e-9 ; -int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } -int lcm(int a, int b){ return a * b / gcd(a,b); } -int qmi(int a, int b){ - int res = 1 ; - while(b){ - if(b&1) res = a * res % MOD ; - b >>= 1 ; - a = a * a % MOD ; - } - return res ; -} -int T = 1 ; -int ans = 0 ; -int n , m, k, q ; -int a[N] ; -void solve(){ - int l, r ; - cin >> n >> l >> r ; - for(int i = 1; i <= n ; ++ i){ - cin >> a[i] ; - } - vector vec1 ; - vector vec2 ; - for(int i = 1; i <= n ; ++ i){ - if(i <= r) vec1.push_back(a[i]) ; - if(i >=l ) vec2.push_back(a[i]) ; - } - sort(vec1.begin(), vec1.end()) ; - sort(vec2.begin(), vec2.end()) ; - int ans1 = 0 ; - int ans2 = 0 ; - for(int i = 0 ; i < r - l + 1; ++ i){ - ans1 += vec1[i] ; - ans2 += vec2[i] ; - } - ans = min(ans1, ans2) ; - cout << ans << endl ; -} -signed main(){ - IOS ; - cin >> T ; - while(T --){ - solve() ; - } - return 0; - -}","#include - -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) - -#define endl '\n' - -#define int long long - -#define PII pair - -#define _rep(i,a,b) for( int i=(a); i<=(b); ++i) - -#define _per(i,a,b) for( int i=(a); i>=(b); --i) - -using namespace std; - -const int N = 1e6+10 ; - -const int M = 1e3+10 ; - -const int INF = 0x3f3f3f3f3f3f3f3f; - -const int MOD = 1e9 + 7 ; - -const double eps = 1e-9 ; - -int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } - -int lcm(int a, int b){ return a * b / gcd(a,b); } - -int qmi(int a, int b){ - - int res = 1 ; - - while(b){ - - if(b&1) res = a * res % MOD ; - - b >>= 1 ; - - a = a * a % MOD ; - - } - - return res ; - -} - -int T = 1 ; - -int ans = 0 ; - -int n , m, k, q ; - -int a[N] ; - -void solve(){ - - int l, r ; - - cin >> n >> l >> r ; - - for(int i = 1; i <= n ; ++ i){ - - cin >> a[i] ; - - } - - ans = 0 ; - - sort(a + 1, a + 1 + n) ; - - for(int i = 1; i <= r - l + 1 ; ++ i){ - - ans += a[i] ; - - } - - cout << ans << endl ; - - - -} - -signed main(){ - - IOS ; - - cin >> T ; - - while(T --){ - - solve() ; - - } - - return 0; - - - -}",1 -tanyujie,2063B - Subsequence Update,c++17 ,303879039,303882579,"#include -#define int long long -using namespace std; - -void solve(){ - int n,l,r; - cin >> n >> l >> r; - int a[n+1]; - for(int i=0;i> a[i]; - sort(a,a+n); - int ans=0; - for(int i=0;i<=r-l;i++) ans+=a[i]; - cout << ans << endl; - -} - -signed main(){ - int t; cin >> t; - while(t--){ - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; - -bool cmp(int a,int b){ - return a>b; -} - -void solve(){ - int n,l,r; - cin >> n >> l >> r; - int a[n+1]; - vector v1,v2,v3; - int sum=0; - for(int i=1;i<=n;i++){ - cin >> a[i]; - if(i<=l-1) v1.push_back(a[i]); - else if(i>=l&&i<=r) v2.push_back(a[i]),sum+=a[i]; - else v3.push_back(a[i]); - } - sort(v1.begin(),v1.end()); - sort(v2.begin(),v2.end(),cmp); - sort(v3.begin(),v3.end()); - - int sum1=sum,sum2=sum; - for(int i=0;i> t; - while(t--){ - solve(); - } - return 0; -}",2 -Demonslayer_k114,2063B - Subsequence Update,c++17 ,304264662,304295505,"#include -#include -using namespace std; -#define ll long long int - - -int main(){ - int t; - cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - l--; - r--; - vector a(n); - vector v; - - for(int i=0;i>a[i]; - } - - for(int i=r;i>=l;i--){ - v.push_back(a[i]); - a.erase(a.begin()+i); - } - - ll ma=0; - ll mi=0; - ll x=0; - while(1){ - mi=*min_element(a.begin(),a.end()); - ma=*max_element(v.begin(),v.end()); - if(ma<=mi) break; - if(a.empty() || v.empty()) break; - v.push_back(mi); - a.push_back(ma); - v.erase(find(v.begin(),v.end(),ma)); - a.erase(find(a.begin(),a.end(),mi)); - - - } - - ll sum=0; - sum=accumulate(v.begin(),v.end(),0LL); - - cout< -#include -using namespace std; -#define ll long long int - - -int main(){ - int t; - cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - l--; - r--; - vector a(n); - for(int i=0;i>a[i]; - } - - vector lft; - vector rht; - - for(int i=0;i<=r;i++){ - lft.push_back(a[i]); - } - - for(int i=l;i - -using namespace std; - -#define int long long - -#define endl '\n' - -#define pii pair - -#define IOS \ - - ios_base::sync_with_stdio(0); \ - - cin.tie(0); \ - - cout.tie(0); - -constexpr int N = 5e5 + 10; - -constexpr int mod = 1e9 + 7; - -constexpr int inf = 0x3f3f3f3f; - -void solve() - -{ - - int n, l, r; - - cin >> n >> l >> r; - - vector a(n + 1), b, c; - - for(int i = 1; i <= n; i ++) - - cin >> a[i]; - - for(int i = 1; i <= r; i ++) - - { - - b.push_back(a[i]); - - } - - for(int i = l; i <= n; i ++) - - { - - c.push_back(a[i]); - - } - - sort(b.begin(), b.end()); - - sort(c.begin(), c.end()); - - int sum1 = 0, sum2 = 0; - - for(int i = 0; i <= r - l; i ++) - - sum1 += b[i]; - - for(int i = 0; i <= r - l; i ++) - - sum2 += c[i]; - - cout << min(sum1, sum2) << endl; - -} - -signed main() - -{ - - IOS - - int _ = 1; - - cin >> _; - - while(_ --) - - { - - solve(); - - } - - return 0; - -}","#include -using namespace std; -#define int long long -#define endl '\n' -#define pii pair -#define IOS \ - ios_base::sync_with_stdio(0); \ - cin.tie(0); \ - cout.tie(0); -constexpr int N = 5e5 + 10; -constexpr int mod = 1e9 + 7; -constexpr int inf = 0x3f3f3f3f; -void solve() -{ - int n, l, r; - cin >> n >> l >> r; - vector a(n); - for(int i = 0; i < n; i ++) - cin >> a[i]; - sort(a.begin(), a.end()); - int sum = 0; - for(int i = 0; i <= r - l; i ++) - sum += a[i]; - cout << sum << endl; -} -signed main() -{ - IOS - int _ = 1; - cin >> _; - while(_ --) - { - solve(); - } - return 0; -}",1 -ElBrancho04,2063B - Subsequence Update,c++23 ,304161477,304161094,"#include -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - long long n,l,r,s1,s2; - s1=s2=0; - cin >> n >> l >> r; - vector a(n),a1,a2; - for (int i=0;i> a[i]; - for (int i=0;i -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--) - { - long n,l,r,s1,s2; - s1=s2=0; - cin >> n >> l >> r; - vector a(n),a1,a2; - for (int i=0;i> a[i]; - for (int i=0;i -using namespace std; - -#define int long long - -#define endl '\n' -#define all(x) (x).begin(), (x).end() -#define pb push_back -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vvi; - -void fastio(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -const int maxN=2e3; -const int INF=1e9; -const int MOD=1e9+7; - -int t, n, l, r, ans1, ans2, a; -vi arr1, arr2; - -signed main(){ - fastio(); - cin >> t; - while(t--){ - cin >> n >> l >> r; - arr1.clear(); - arr2.clear(); - l--; r--; - for(int i=0; i> a; - if(i<=r) arr1.pb(a); - if(i>=l) arr2.pb(a); - } - ans1=ans2=0; - sort(all(arr1)); - sort(all(arr2)); - for(int i=0; i<=r-l; i++){ - ans1+=arr1[i]; - ans2+=arr2[i]; - } - cout << min(ans1, ans2) << endl; - } - return 0; -} -","#include -using namespace std; - -#define int long long - -#define endl '\n' -#define all(x) (x).begin(), (x).end() -#define pb push_back -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vvi; - -void fastio(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -const int maxN=2e3; -const int INF=1e9; -const int MOD=1e9+7; - -int t, n, l, r, ans1, ans2; -vi arr, a1, a2; - -bool invComp(int a, int b){ - return a>=b; -} - -signed main(){ - fastio(); - cin >> t; - while(t--){ - cin >> n >> l >> r; - arr.resize(n, 0); - for(int i=0; i> arr[i]; - } - l--; r--; - a1=a2=arr; - sort(a1.begin(), a1.begin()+r+1, invComp); - sort(a2.begin()+l, a2.end()); - ans1=ans2=0; - for(int i=l; i<=r; i++){ - ans1+=a1[i]; - ans2+=a2[i]; - } - cout << min(ans1, ans2) << endl; - } - return 0; -} -",1 -issue,2063B - Subsequence Update,c++23 ,304526807,304525893,"#include - -#define all(x) x.begin(), x.end() - -using namespace std; - -using ll = long long; - -void solve() { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for (ll i = 0; i < n; ++i) { - cin >> a[i]; - } - vector x, y; - for (ll i = 0; i < r; ++i) { - x.push_back(a[i]); - } - for (ll i = l - 1; i < n; ++i) { - y.push_back(a[i]); - } - sort(all(x)); - sort(all(y)); - ll ans1 = 0, ans2 = 0; - for (ll i = 0; i < r - l + 1; ++i) { - ans1 += x[i]; - } - for (ll i = 0; i < r - l + 1; ++i) { - ans2 += y[i]; - } - cout << min(ans1, ans2) << endl; -} - -signed main() { - int t; - cin >> t; - while (t--) { - solve(); - } -} -","#include - - - -#define all(x) x.begin(), x.end() - - - -using namespace std; - - - -using ll = long long; - - - -void solve() { - - ll n, l, r; - - cin >> n >> l >> r; - - vector a(n); - - for (ll i = 0; i < n; ++i) { - - cin >> a[i]; - - } - - sort(all(a)); - - ll s = 0; - - for (ll i = 0; i < r - l + 1; ++i) { - - s += a[i]; - - } - - cout << s << endl; - -} - - - -signed main() { - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -",1 -mseebacher,2063B - Subsequence Update,c++17 ,307569181,307569344," - -#include - -#define ll long long - -using namespace std; - - - -const int MAX_N = 1e5; - - - -vector> adj(MAX_N,vector()); - -vector processed(MAX_N,0); - - - -void setIO(string s) { - - freopen((s + "".in"").c_str(), ""r"", stdin); - - freopen((s + "".out"").c_str(), ""w"", stdout); - -} - - - -ll gcd(ll y,ll z){ - - if(z == 0) return y; - - return gcd(z,y%z); - -} - - - -vector dist(1e5); - - - - - -bool comp(int a, int b) { - - return a > b; - -} - - - -void solve(){ - - - - int n; cin >> n; - - int l,r; cin >> l >> r; - - vector first(0); - - vector second(0); - - vector third(0); - - l--; r--; - - for(int i = 0;i> x; - - first.push_back(x); - - } - - for(int i = l;i<=r;i++){ - - int x; cin >> x; - - second.push_back(x); - - } - - for(int i = r+1;i> x; - - third.push_back(x); - - } - - sort(first.begin(),first.end()); - - sort(second.begin(),second.end(),comp); - - sort(third.begin(),third.end()); - - int res1 = 0; - - for(int i = 0;i=first.size()) res1+= second[i]; - - else res1+= first[i]; - - } - - int res2 = 0; - - for(int i = 0;i=third.size()) res2 += second[i]; - - else res2+= third[i]; - - } - - //cout << res1 << ""\n"" << res2 << ""\n""; - - cout << min(res1,res2); - -} - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(nullptr); - - cout << fixed << setprecision(8); - - - - int t = 1; - - cin >> t; - - while(t--) { - - solve(); - - cout << ""\n""; - - } - -} - -"," - -#include - -#define ll long long - -using namespace std; - - - -const int MAX_N = 1e5; - - - -vector> adj(MAX_N,vector()); - -vector processed(MAX_N,0); - - - -void setIO(string s) { - - freopen((s + "".in"").c_str(), ""r"", stdin); - - freopen((s + "".out"").c_str(), ""w"", stdout); - -} - - - -ll gcd(ll y,ll z){ - - if(z == 0) return y; - - return gcd(z,y%z); - -} - - - -vector dist(1e5); - - - - - -bool comp(int a, int b) { - - return a > b; - -} - - - -void solve(){ - - - - int n; cin >> n; - - int l,r; cin >> l >> r; - - vector first(0); - - vector second(0); - - vector third(0); - - l--; r--; - - for(int i = 0;i> x; - - first.push_back(x); - - } - - for(int i = l;i<=r;i++){ - - int x; cin >> x; - - second.push_back(x); - - } - - for(int i = r+1;i> x; - - third.push_back(x); - - } - - sort(first.begin(),first.end()); - - sort(second.begin(),second.end(),comp); - - sort(third.begin(),third.end()); - - ll res1 = 0; - - for(int i = 0;i=first.size()) res1+= second[i]; - - else res1+= first[i]; - - } - - ll res2 = 0; - - for(int i = 0;i=third.size()) res2 += second[i]; - - else res2+= third[i]; - - } - - //cout << res1 << ""\n"" << res2 << ""\n""; - - cout << min(res1,res2); - -} - - - -int main(){ - - ios::sync_with_stdio(0); - - cin.tie(nullptr); - - cout << fixed << setprecision(8); - - - - int t = 1; - - cin >> t; - - while(t--) { - - solve(); - - cout << ""\n""; - - } - -} - -",2 -UkrainianLeopard,2063B - Subsequence Update,c++20 ,309513139,309513313,"#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -typedef long long ll; - - - -int t; - - - -bool comp(int a, int b){ - - return a > b; - -} - - - -void solve(){ - - int n, l, r; - - int sum = 0; - - cin>>n>>l>>r; - - vector a(n); - - l--; r--; - - for(int i=0; i> a[i]; - - if(i >= l && i <= r) sum += a[i]; - - } - - - - sort(a.begin() + l, a.begin() + r + 1, comp); - - sort(a.begin(), a.begin() + l); - - sort(a.begin() + r + 1, a.end()); - - - - int ptr1 = 0, ptr2 = l, ptr3 = r + 1; - - int sum1 = 0, sum2 = 0, sum3 = 0; - - int ans = sum; - - - - for(int i = 1; i <= min(l + 1, r - l + 1); i++){ - - sum1 += a[ptr1]; - - sum2 += a[ptr2]; - - ans = min(ans, sum - sum2 + sum1); - - ptr1++; ptr2++; - - } - - - - ptr2 = l; - - sum2 = 0; - - - - for(int i = 1; i <= min(n - r - 1, r - l + 1); i++){ - - sum3 += a[ptr3]; - - sum2 += a[ptr2]; - - ans = min(ans, sum - sum2 + sum3); - - ptr3++; ptr2++; - - } - - - - cout<> t; - - while(t--){ - - solve(); - - } - -}","#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -typedef long long ll; - - - -int t; - - - -bool comp(int a, int b){ - - return a > b; - -} - - - -void solve(){ - - int n, l, r; - - ll sum = 0; - - cin>>n>>l>>r; - - vector a(n); - - l--; r--; - - for(int i=0; i> a[i]; - - if(i >= l && i <= r) sum += a[i]; - - } - - - - sort(a.begin() + l, a.begin() + r + 1, comp); - - sort(a.begin(), a.begin() + l); - - sort(a.begin() + r + 1, a.end()); - - - - int ptr1 = 0, ptr2 = l, ptr3 = r + 1; - - ll sum1 = 0, sum2 = 0, sum3 = 0; - - ll ans = sum; - - - - for(int i = 1; i <= min(l + 1, r - l + 1); i++){ - - sum1 += a[ptr1]; - - sum2 += a[ptr2]; - - ans = min(ans, sum - sum2 + sum1); - - ptr1++; ptr2++; - - } - - - - ptr2 = l; - - sum2 = 0; - - - - for(int i = 1; i <= min(n - r - 1, r - l + 1); i++){ - - sum3 += a[ptr3]; - - sum2 += a[ptr2]; - - ans = min(ans, sum - sum2 + sum3); - - ptr3++; ptr2++; - - } - - - - cout<> t; - - while(t--){ - - solve(); - - } - -}",2 -jack1011,2063B - Subsequence Update,c++17 ,305435469,305434800,"#include - -using namespace std; -#define LL long long - int main() -{ - long long t; - cin>>t; - while(t--) - { - long long n,l,r; - cin>>n>>l>>r; - vectora(n); - vectorb; - vectorc; - for( long long i=0;i>a[i]; - } - l--,r--; - for( long long i=0;i<=r;i++) - { - b.push_back(a[i]); - } - for( long long i=l;i - -using namespace std; -#define LL long long -int main() -{ - int t;cin>>t; - while(t--) - { - int n,l,r; - cin>>n>>l>>r; - vectora(n); - vectorb; - vectorc; - for(int i=0;i>a[i]; - } - l--,r--; - for(int i=0;i<=r;i++) - { - b.push_back(a[i]); - } - for(int i=l;i -#define ll long long -#define endl '\n' - -using namespace std; - -ll n, l, r; -signed main() { - ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); - - int t; cin >> t; - - while(t--) { - cin >> n >> l >> r; - - priority_queue mid_l, mid_r; - priority_queue, greater> lqu, rqu; - ll ans = 0, la = 0, ra = 0; - - for (int i = 1; i < l; i++) { - ll e; cin >> e; - lqu.push(e); - } - - for (int i = l; i <= r; i++) { - ll e; cin >> e; - mid_l.push(e); mid_r.push(e); - - ans += e; - } - - for (int i = r + 1; i <= n; i++) { - ll e; cin >> e; - rqu.push(e); - } - - - while(!lqu.empty() && !mid_l.empty()) { - if (lqu.top() <= mid_l.top()) la += lqu.top() - mid_l.top(); - else break; - - lqu.pop(); mid_l.pop(); - } - - while(!rqu.empty() && !mid_r.empty()) { - if (rqu.top() <= mid_r.top()) ra += rqu.top() - mid_r.top(); - else break; - - rqu.pop(); mid_r.pop(); - } - - cout << ans + min(min(ra, la), 0LL) << endl; - } - - return 0; -}","#include - -#define ll long long - -#define endl '\n' - - - -using namespace std; - - - -ll n, l, r; - -signed main() { - - ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); - - - - int t; cin >> t; - - - - while(t--) { - - cin >> n >> l >> r; - - - - priority_queue mid_l, mid_r; - - priority_queue, greater> lqu, rqu; - - int ans = 0, la = 0, ra = 0; - - - - for (int i = 1; i < l; i++) { - - int e; cin >> e; - - lqu.push(e); - - } - - - - for (int i = l; i <= r; i++) { - - int e; cin >> e; - - mid_l.push(e); mid_r.push(e); - - - - ans += e; - - } - - - - for (int i = r + 1; i <= n; i++) { - - int e; cin >> e; - - rqu.push(e); - - } - - - - - - while(!lqu.empty() && !mid_l.empty()) { - - if (lqu.top() <= mid_l.top()) la += lqu.top() - mid_l.top(); - - else break; - - - - lqu.pop(); mid_l.pop(); - - } - - - - while(!rqu.empty() && !mid_r.empty()) { - - if (rqu.top() <= mid_r.top()) ra += rqu.top() - mid_r.top(); - - else break; - - - - rqu.pop(); mid_r.pop(); - - } - - - - cout << ans + min(0, min(ra, la)) << endl; - - } - - - - return 0; - -}",1 -Ramim2219,2063B - Subsequence Update,c++17 ,308634290,308634547,"//Problem Link : - -#include - -#define ll long long int - -#define endl '\n' - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL); - -using namespace std; - -int main() - -{ - - fast; - - ll t; - - cin>>t; - - while(t--) - - { - - ll n,l,r,x; - - cin>>n>>l>>r; - - vectorb,c; - - for(ll i=1;i<=n;i++) - - { - - cin>>x; - - if(x>=l && x<=n)b.push_back(x); - - if(x<=r && x>=1)c.push_back(x); - - } - - sort(b.begin(),b.end()); - - sort(c.begin(),c.end()); - - - - ll sum1=0,sum2=0; - - for(ll i=0;i<(r-l+1);i++) - - { - - sum1+=b[i]; - - sum2+=c[i]; - - } - - cout< - -#define ll long long int - -#define endl '\n' - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL); - -using namespace std; - -int main() - -{ - - fast; - - ll t; - - cin>>t; - - while(t--) - - { - - ll n,l,r,x; - - cin>>n>>l>>r; - - vectorb,c; - - for(ll i=1;i<=n;i++) - - { - - cin>>x; - - if(i>=l && i<=n)b.push_back(x); - - if(i<=r && i>=1)c.push_back(x); - - } - - sort(b.begin(),b.end()); - - sort(c.begin(),c.end()); - - - - ll sum1=0,sum2=0; - - for(ll i=0;i<(r-l+1);i++) - - { - - sum1+=b[i]; - - sum2+=c[i]; - - } - - cout< -using namespace std; -#define ll long long - -void input(vector&a,ll n){ - - a.resize(n); - for(ll i=0;i>a[i]; - } - -} -void printvec(vector&a){ - for(auto num :a){ - cout<>test; - while(test--){ - ll n,l,r; - cin>>n>>l>>r; - vectorv(n); - input(v,n); - vectorb,c; - r--;l--; - for(ll i=l;i - -using namespace std; - -#define ll long long - - - -void input(vector&a,int n){ - - - - a.resize(n); - - for(int i=0;i>a[i]; - - } - - - -} - -void printvec(vector&a){ - - for(auto num :a){ - - cout<>test; - - while(test--){ - - int n,l,r; - - cin>>n>>l>>r; - - vectorv(n); - - input(v,n); - - sort(v.begin(),v.end()); - - int ans=r-l+1; - - int sum=0; - - for(int i=0;i -using namespace std; -#define ll long long -#define pb push_back -#define endl ""\n"" - -// priority_queue, vector>, greater>> pq; for 3 values input -//cout << get<0>(pq.top()) << endl; -// priority_queue> pq; - -#define optimizer() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define all(x) (x).begin(), (x).end() -#define fraction(a) cout.unsetf(ios::fixed); cout.precision(a); cout.setf(ios::fixed); - -void anik() { -ll n,l,r; -cin>>n>>l>>r; -vector v(n); -for(int i=0;i>v[i]; -} -sort(v.begin(),v.end()); -ll dif=r-l; -ll sum=0; -for(int i=0;i<=dif;i++) -{ -sum+=v[i]; -} - -cout<> test; - while (test--) { - anik(); - } - return 0; -}","#include -using namespace std; -#define ll long long -#define pb push_back -#define endl ""\n"" - -// priority_queue, vector>, greater>> pq; for 3 values input -//cout << get<0>(pq.top()) << endl; -// priority_queue> pq; - -#define optimizer() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); -#define all(x) (x).begin(), (x).end() -#define fraction(a) cout.unsetf(ios::fixed); cout.precision(a); cout.setf(ios::fixed); - -void anik() { -ll n,l,r; -cin>>n>>l>>r; -l--;r--; - -ll sum=0; -vector v(n),be,in,af; -for(int i=0;i>v[i]; - if(i=l and r>=i){ - in.push_back(v[i]); - sum+=v[i]; - } - - else if(i>r){ - af.push_back(v[i]); - } -} - - -// for(int i=0;i()); -sort(af.begin(),af.end()); - - ll sum1=sum; - -int j=0; -int x=0; -while(!be.empty() and j> test; - while (test--) { - anik(); - } - return 0; -}",2 -Atharva_Singh,2063B - Subsequence Update,c++17 ,304301619,304305512,"//Burn like amaterasu -//compete -#include -#define ll long long int -#define ld long double -#define f(i,a,b) for(i=a;i=b;i--) -#define sz(x) (ll)x.size() -#define Yes cout<<""YES\n"" -#define yes cout<<""Yes\n"" -#define No cout<<""NO\n"" -#define no cout<<""No\n"" -#define vll vector -#define vi vector -#define pl pair -#define pi pair -#define vpl vector> -#define vpi vector> -#define pb push_back -#define mp make_pair -#define ff first -#define ss second -#define lb lower_bound -#define ub upper_bound -#define srt(v) sort(v.begin(),v.end()) -#define rst(v) sort(v.rbegin(),v.rend()) -#define rev(v) reverse(v.begin(),v.end()) -#define read(v) for(ll xyzd=0;xyzd>v[xyzd]; -#define print(a) {for(auto x:a)cout< -// #include -// using namespace __gnu_pbds; -// #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -// operations-> o_set.insert(5); -// o_set.find_by_order(1) -// o_set.find(2) != o_set.end() -// o_set.erase(o_set.find(2)); -// *(o_set.find_by_order(1)) -//************************************************************************************************************************************************************** -//**********************************************************************G.C.D*********************************************************************************** -ll gcd(ll high,ll low) -{ - ll h=high>low?high:low; - ll l=high>low?low:high; - ll temp; -while(l!=0) -{ - temp=l; - l=h%l; - h=temp; -} -return h; -} -//************************************************************************************************************************************************************** -//**********************************************************************x to the power n (Binpow)*************************************************************** -ll binpow(ll x,ll n) -{ - ll r=1; - while(n) - { - if(n&1) - r=r*x; - x=x*x; - n>>=1; - } - return r; -} -//************************************************************************************************************************************************************** -//**********************************************************************Fenwick Tree/Binary Indexed Tree******************************************************** -template -class fenwick_tree -{ - vector tre; - public: - fenwick_tree(T n) - { - tre.resize(n+1); - } - void add(T index,T value) - { - for(;index<=tre.size()-1;index+=(index&(-index))) - tre[index]+=value; - } - T sum_i(T index) - { - T ans=0; - for(;index>0;index-=(index&(-index))) - ans+=tre[index]; - return ans; - } -}; -//************************************************************************************************************************************************************** -//**********************************************************************SEGEMENT TREE*************************************************************************** -class segment_tree{ - public: - vector seg,val; - segment_tree(int n){ - val.resize(n); - seg.resize(4*n+1); - } - void build(int ind,int low,int high){ - if(low==high){ - seg[ind]=val[low]; - return; - } - int mid =(low+high)/2; - build(2*ind+1,low,mid); - build(2*ind+2,mid+1,high); - - seg[ind]=min(seg[2*ind+1],seg[2*ind+2]); - } - int query(int ind,int low,int high,int l,int r){ - if(r=l&&high<=r) return seg[ind]; - - int mid=(low+high)/2; - int left=query(2*ind+1,low,mid,l,r); - int right=query(2*ind+2,mid+1,high,l,r); - - return min(left,right); - } - void update(int ind,int low,int high,int i ,int value){ - if(low==high){ - seg[ind]=value; - return; - } - int mid=(low+high)/2; - if(i<=mid)update(2*ind+1,low,mid,i,value); - else update(2*ind+2,mid+1,high,i,value); - - seg[ind]=min(seg[2*ind+1],seg[2*ind+2]); - } -}; -//************************************************************************************************************************************************************** -//**********************************************************************DSU************************************************************************************* -class dsu{ - vector parent, size; - public : - dsu(long long n){ - parent.resize(n+1); - size.resize(n+1); - long long i; - for(i=1;iimplementation->sliding window-> -//binary search->math->gready->dynamic programming; - -void solve_Func() -{ - ll i, j, k, l, r, q, n, m; - cin>>n>>l>>r; - l--,r--; - vll a(n); read(a); - - vll left, mid, right; - - f(i,0,l) left.pb(a[i]); - f(i,l,r+1) mid.pb(a[i]); - f(i,r+1,n) right.pb(a[i]); - - - srt(left); srt(right); rst(mid); - - ll ans,sum = accumulate(mid.begin(),mid.end(),0); - ans = sum; - - k = min(left.size(),mid.size()); - - ll cur = sum; - - f(i,0,k){ - if(left[i] <= mid[i]) cur = cur - mid[i] + left[i]; - else break; - } - ans = min(ans, cur); - cur = sum; - - k = min(right.size(), mid.size()); - - f(i,0,k){ - if(right[i] <= mid[i]) cur = cur - mid[i] + right[i]; - else break; - } - - cout<>t; - while(t--) - solve_Func(); - -} - -//*********end*********//","//Burn like amaterasu -//compete -#include -#define ll long long int -#define ld long double -#define f(i,a,b) for(i=a;i=b;i--) -#define sz(x) (ll)x.size() -#define Yes cout<<""YES\n"" -#define yes cout<<""Yes\n"" -#define No cout<<""NO\n"" -#define no cout<<""No\n"" -#define vll vector -#define vi vector -#define pl pair -#define pi pair -#define vpl vector> -#define vpi vector> -#define pb push_back -#define mp make_pair -#define ff first -#define ss second -#define lb lower_bound -#define ub upper_bound -#define srt(v) sort(v.begin(),v.end()) -#define rst(v) sort(v.rbegin(),v.rend()) -#define rev(v) reverse(v.begin(),v.end()) -#define read(v) for(ll xyzd=0;xyzd>v[xyzd]; -#define print(a) {for(auto x:a)cout< -// #include -// using namespace __gnu_pbds; -// #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -// operations-> o_set.insert(5); -// o_set.find_by_order(1) -// o_set.find(2) != o_set.end() -// o_set.erase(o_set.find(2)); -// *(o_set.find_by_order(1)) -//************************************************************************************************************************************************************** -//**********************************************************************G.C.D*********************************************************************************** -ll gcd(ll high,ll low) -{ - ll h=high>low?high:low; - ll l=high>low?low:high; - ll temp; -while(l!=0) -{ - temp=l; - l=h%l; - h=temp; -} -return h; -} -//************************************************************************************************************************************************************** -//**********************************************************************x to the power n (Binpow)*************************************************************** -ll binpow(ll x,ll n) -{ - ll r=1; - while(n) - { - if(n&1) - r=r*x; - x=x*x; - n>>=1; - } - return r; -} -//************************************************************************************************************************************************************** -//**********************************************************************Fenwick Tree/Binary Indexed Tree******************************************************** -template -class fenwick_tree -{ - vector tre; - public: - fenwick_tree(T n) - { - tre.resize(n+1); - } - void add(T index,T value) - { - for(;index<=tre.size()-1;index+=(index&(-index))) - tre[index]+=value; - } - T sum_i(T index) - { - T ans=0; - for(;index>0;index-=(index&(-index))) - ans+=tre[index]; - return ans; - } -}; -//************************************************************************************************************************************************************** -//**********************************************************************SEGEMENT TREE*************************************************************************** -class segment_tree{ - public: - vector seg,val; - segment_tree(int n){ - val.resize(n); - seg.resize(4*n+1); - } - void build(int ind,int low,int high){ - if(low==high){ - seg[ind]=val[low]; - return; - } - int mid =(low+high)/2; - build(2*ind+1,low,mid); - build(2*ind+2,mid+1,high); - - seg[ind]=min(seg[2*ind+1],seg[2*ind+2]); - } - int query(int ind,int low,int high,int l,int r){ - if(r=l&&high<=r) return seg[ind]; - - int mid=(low+high)/2; - int left=query(2*ind+1,low,mid,l,r); - int right=query(2*ind+2,mid+1,high,l,r); - - return min(left,right); - } - void update(int ind,int low,int high,int i ,int value){ - if(low==high){ - seg[ind]=value; - return; - } - int mid=(low+high)/2; - if(i<=mid)update(2*ind+1,low,mid,i,value); - else update(2*ind+2,mid+1,high,i,value); - - seg[ind]=min(seg[2*ind+1],seg[2*ind+2]); - } -}; -//************************************************************************************************************************************************************** -//**********************************************************************DSU************************************************************************************* -class dsu{ - vector parent, size; - public : - dsu(long long n){ - parent.resize(n+1); - size.resize(n+1); - long long i; - for(i=1;iimplementation->sliding window-> -//binary search->math->gready->dynamic programming; - -void solve_Func() -{ - ll i, j, k, l, r, q, n, m; - cin>>n>>l>>r; - l--,r--; - vll a(n); read(a); - - vll left, mid, right; - - f(i,0,l) left.pb(a[i]); - f(i,l,r+1) mid.pb(a[i]); - f(i,r+1,n) right.pb(a[i]); - - - srt(left); srt(right); rst(mid); - - ll ans,sum = accumulate(mid.begin(),mid.end(),0LL); - - ans = sum; - - k = min(left.size(),mid.size()); - - ll cur = sum; - - f(i,0,k){ - if(left[i] <= mid[i]){ - cur -= mid[i]; - cur += left[i]; - } - else break; - } - ans = min(ans, cur); - cur = sum; - - k = min(right.size(), mid.size()); - - f(i,0,k){ - if(right[i] <= mid[i]){ - cur -= mid[i]; - cur += right[i]; - } - else break; - } - - cout<>t; - while(t--) - solve_Func(); - -} - -//*********end*********//",2 -LOGIC-MASTER_1e24817,2063B - Subsequence Update,c++17 ,304229442,304231617,"#include -#define int long long -#define endl '\n' -#define co cout -#define yes cout<<""YES""<<""\n"" -#define no cout<<""NO""<<""\n"" -#define ci cin -#define ins insert -#define pb push_back -#define intl int -#define fi first -#define sc second -#define RODI ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define ll long long -#define beg begin() -#define ed end() -using namespace std; -int a[1000009]; -int b[1000009]; -int ac[100]; -const int mod = 1e9+7; -const int siz=1e5; -bool ch=false; -string s,s1,s2,s3,s4,s5; -int t=0,sum=0,i,w,m=0,n=0,n2,n3,n4,x,y=0,k=-1,st=0,cc=0,q,sb,sa,zero=0,rodi,idx,cost,l,d,mode=1,N=1e5+1,mx=-1,z,r,cnt,mid,r2,l2,mid2,sum2,mi,j=0,r1,l1,f,x1,x2,y2; -bool check; -int ar[4009][4009]; -int inf=1e9; -string arr[1009]; -int p[10000009]; -setSe; -vectorvec; -map>sm; -vectorvec1,vec2,vec3; -stackstk; -vectordpi(2e5,0); -vectoradj[200009]; -mapfreq,fr1,fr2; -map >ind; -ll power(ll x , ll y) -{ - -ll res = 1; -//x %= mod; -while(y > 0) -{ -if (y%2)res = (res*x);//%mod; -y /= 2; -x = (x*x);//%mod; -} -return res; -} -dequedeq; -vectorvis(2e5+9,0); -vectordis(2e5+9,0); -string solver(string s1,string s2) -{ -string s3=""""; -for(int i=0;i>fse; -void solve() -{ - - freq.clear(); - Se.clear(); - vec1.clear(); - vec2.clear(); - vec3.clear(); - ci>>n>>l>>r; - sum=0; - sum2=0; - for(i=1;i<=n;i++) - { - ci>>a[i]; - if(ir) - vec3.pb(a[i]); - else{ - vec2.pb(a[i]); - sum+=a[i]; - sum2+=a[i]; - } - } - sort(vec1.rbegin(),vec1.rbegin()); - sort(vec2.begin(),vec2.begin()); - sort(vec3.rbegin(),vec3.rbegin()); - for(i=vec2.size()-1;i>=0&&vec1.size();i--) - { - if(vec2[i]vec1.back()){ - sum-=vec2[i]; - sum+=vec1.back(); - vec1.pop_back(); - } - } - - - for(i=vec2.size()-1;i>=0&&vec3.size();i--) - { - if(vec2[i]vec3.back()){ - sum2-=vec2[i]; - sum2+=vec3.back(); - vec3.pop_back(); - } - } - co<>t; - -while(t--){ -solve(); - -} -return 0; -} -","#include -#define int long long -#define endl '\n' -#define co cout -#define yes cout<<""YES""<<""\n"" -#define no cout<<""NO""<<""\n"" -#define ci cin -#define ins insert -#define pb push_back -#define intl int -#define fi first -#define sc second -#define RODI ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); -#define ll long long -#define beg begin() -#define ed end() -using namespace std; -int a[1000009]; -int b[1000009]; -int ac[100]; -const int mod = 1e9+7; -const int siz=1e5; -bool ch=false; -string s,s1,s2,s3,s4,s5; -int t=0,sum=0,i,w,m=0,n=0,n2,n3,n4,x,y=0,k=-1,st=0,cc=0,q,sb,sa,zero=0,rodi,idx,cost,l,d,mode=1,N=1e5+1,mx=-1,z,r,cnt,mid,r2,l2,mid2,sum2,mi,j=0,r1,l1,f,x1,x2,y2; -bool check; -int ar[4009][4009]; -int inf=1e9; -string arr[1009]; -int p[10000009]; -setSe; -vectorvec; -map>sm; -vectorvec1,vec2,vec3; -stackstk; -vectordpi(2e5,0); -vectoradj[200009]; -mapfreq,fr1,fr2; -map >ind; -ll power(ll x , ll y) -{ - -ll res = 1; -//x %= mod; -while(y > 0) -{ -if (y%2)res = (res*x);//%mod; -y /= 2; -x = (x*x);//%mod; -} -return res; -} -dequedeq; -vectorvis(2e5+9,0); -vectordis(2e5+9,0); -string solver(string s1,string s2) -{ -string s3=""""; -for(int i=0;i>fse; -void solve() -{ - - freq.clear(); - Se.clear(); - vec1.clear(); - vec2.clear(); - vec3.clear(); - ci>>n>>l>>r; - sum=0; - sum2=0; - for(i=1;i<=n;i++) - { - ci>>a[i]; - if(ir) - vec3.pb(a[i]); - else{ - vec1.pb(a[i]); - vec3.pb(a[i]); - } - } - sort(vec1.rbegin(),vec1.rend()); - sort(vec3.rbegin(),vec3.rend()); - x=r-l+1; - y=x; - while(x--) - { - sum+=vec1.back(); - vec1.pop_back(); - } - while(y--) - { - sum2+=vec3.back(); - vec3.pop_back(); - } - co<>t; - -while(t--){ -solve(); - -} -return 0; -} -",2 -nhirsama,2063B - Subsequence Update,c++23 ,305448732,305446855,"#include - -using namespace std; - -const int N = 1e5 + 10; - -typedef long long ll; - - - -void Func() { - - ll n, l, r; - - cin >> n >> l >> r; - - priority_queue, greater<> > q2,q1; - - for (int i = 1; i <= n; i++) { - - ll x; - - cin >> x; - - if (i<=r) q1.push(x); - - if (i>=l) q2.push(x); - - } - - ll ans = 0,ans2 = 0; - - for (ll i = 1; i <= r-l+1; i++) { - - ans += q1.top(); - - q1.pop(); - - ans2 += q2.top(); - - q2.pop(); - - } - - cout << min(ans,ans2) << endl; - -} - - - -int main() { - -#ifdef LOCAL - - freopen(""Testlib.in"", ""r"", stdin); - - freopen(""Code.out"", ""w"", stdout); - -#endif - - int T; - - cin >> T; - - while (T--) { - - Func(); - - } - - return 0; - -} - -","#include - -using namespace std; - -const int N = 1e5 + 10; - -typedef long long ll; - - - -void Func() { - - ll n, l, r; - - cin >> n >> l >> r; - - priority_queue, greater > q2; - - priority_queue q1; - - for (int i = 1; i <= n; i++) { - - ll x; - - cin >> x; - - if (l <= i && i <= r) { - - q1.push(x); - - } else { - - q2.push(x); - - } - - } - - while (!q2.empty() && !q1.empty() && q1.top() > q2.top()) { - - q1.pop(); - - q1.push(q2.top()); - - q2.pop(); - - } - - ll ans = 0; - - while (!q1.empty()) { - - ans += q1.top(); - - q1.pop(); - - } - - cout << ans << endl; - -} - - - -int main() { - - int T; - - cin >> T; - - while (T--) { - - Func(); - - } - - return 0; - -} - -",1 -KingBaldwin,2063B - Subsequence Update,c++17 ,306496634,306512207,"#include - -using namespace std; - - - -#define int long long int - -#define double long double - -#define F first - -#define S second - -#define pb push_back - -#define all(x) x.begin(), x.end() - -#define vi vector - -#define pii pair - -#define rep(i, a, b) for(int i = a; i < b; i++) - -#define CODE_START ios_base::sync_with_stdio();cin.tie(0);cout.tie(0); - - - -void solve() { - - int n, l, r; - - cin >> n >> l >> r; - - vi a(n); - - rep(i, 0, n) cin >> a[i]; - - - - int curr_sum = 0, sum = 0, len = 0, d = r-l+1; - - rep(i, l-1, r) curr_sum += a[i]; - - int mn = curr_sum; - - - - vi prefix(d+1); - - rep(i, 1, d+1) prefix[i] = prefix[i-1] + a[l+i-2]; - - - - rep(i, 0, r-1) { - - if(sum + a[i] < curr_sum) { - - sum += a[i]; - - len++; - - } - - else { - - sum = a[i]; - - len = 1; - - } - - mn = min(mn, curr_sum - prefix[len] + sum); - - if(len == d) { - - sum -= a[i-r+l]; - - len--; - - } - - } - - - - vi suffix(d+1); - - for(int i = d-1; i >= 0; i--) suffix[i] = suffix[i+1] + a[r-d+i]; - - - - sum = 0; - - len = 0; - - - - for(int i = n-1; i >= l; i--) { - - if(sum + a[i] < curr_sum) { - - sum += a[i]; - - len++; - - } - - else { - - sum = a[i]; - - len = 1; - - } - - mn = min(mn, curr_sum - suffix[d-len] + sum); - - if(len == d) { - - sum -= a[i+r-l]; - - len--; - - } - - } - - - - cout << mn << ""\n""; - -} - - - -int32_t main() { - - #ifdef CODE_START - - CODE_START; - - #endif - - - - int t; - - cin >> t; - - while(t--) { - - solve(); - - } - - return 0; - -} - -","#include -using namespace std; - -#define int long long int -#define double long double -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(), x.end() -#define vi vector -#define pii pair -#define rep(i, a, b) for(int i = a; i < b; i++) -#define CODE_START ios_base::sync_with_stdio();cin.tie(0);cout.tie(0); - -void solve() { - int n, l, r; - cin >> n >> l >> r; - vi a(n); - rep(i, 0, n) cin >> a[i]; - vi b; - rep(i, l-1, r) b.pb(a[i]); - sort(b.rbegin(), b.rend()); - int d = r-l+1; - vi prefix(d+1); - rep(i, 0, d) prefix[i+1] = prefix[i] + b[i]; - - vi c; - rep(i, 0, l-1) c.pb(a[i]); - sort(all(c)); - - int sum = 0, mn = prefix[d], len = 0; - rep(i, 0, (int)c.size()) { - if(sum + c[i] < prefix[i+1]) { - sum += c[i]; - mn = min(mn, prefix[d] - prefix[i+1] + sum); - } - else break; - len++; - if(len == d) break; - } - - vi e; - for(int i = n-1; i >= r; i--) e.pb(a[i]); - sort(all(e)); - - sum = 0; - len = 0; - rep(i, 0, (int)e.size()) { - if(sum + e[i] < prefix[i+1]) { - sum += e[i]; - mn = min(mn, prefix[d] - prefix[i+1] + sum); - } - else break; - len++; - if(len == d) break; - } - - cout << mn << ""\n""; -} - -int32_t main() { - #ifdef CODE_START - CODE_START; - #endif - - int t; - cin >> t; - while(t--) { - solve(); - } - return 0; -} -",2 -Tiantian2021,2063B - Subsequence Update,c++20 ,306955793,306956009,"// B. Subsequence Update - -#include -using namespace std; -#define int long long - -const int N = 2e5 + 10; -int gA[N]; - -signed main() { - ios::sync_with_stdio(false); - - int t; - cin >> t; - - while (t--) { - int n, l, r; - cin >> n >> l >> r; - - for (int i = 1; i <= n; i++) - cin >> gA[i]; - - priority_queue, greater > lft, rht; - priority_queue mid; - - int ans = 0; - for (int i = l; i <= r; i++) - ans += gA[i]; - - int tmpans = ans; - for (int i = 1; i < l; i++) lft.push(gA[i]); - for (int i = l; i <= r; i++) mid.push(gA[i]); - for (int i = r + 1; i <= n; i++) rht.push(gA[i]); - - auto tmp = mid; - while (lft.size() && mid.size() && lft.top() < mid.top()) ans -= mid.top() - lft.top(), mid.pop(), lft.pop(); - - int mn = ans; ans = tmpans; - while (rht.size() && mid.size() && rht.top() < mid.top()) ans -= mid.top() - rht.top(), mid.pop(), rht.pop(); - - cout << min(mn, ans) << endl; - } - - return 0; -}","// B. Subsequence Update - - - -#include - -using namespace std; - -#define int long long - - - -const int N = 2e5 + 10; - -int gA[N]; - - - -signed main() { - - ios::sync_with_stdio(false); - - - - int t; - - cin >> t; - - - - while (t--) { - - int n, l, r; - - cin >> n >> l >> r; - - - - for (int i = 1; i <= n; i++) - - cin >> gA[i]; - - - - priority_queue, greater > lft, rht; - - priority_queue mid; - - - - int ans = 0; - - for (int i = l; i <= r; i++) - - ans += gA[i]; - - - - int tmpans = ans; - - for (int i = 1; i < l; i++) lft.push(gA[i]); - - for (int i = l; i <= r; i++) mid.push(gA[i]); - - for (int i = r + 1; i <= n; i++) rht.push(gA[i]); - - - - auto tmp = mid; - - while (lft.size() && mid.size() && lft.top() < mid.top()) ans -= mid.top() - lft.top(), mid.pop(), lft.pop(); - - - - int mn = ans; ans = tmpans; mid = tmp; - - while (rht.size() && mid.size() && rht.top() < mid.top()) ans -= mid.top() - rht.top(), mid.pop(), rht.pop(); - - - - cout << min(mn, ans) << endl; - - } - - - - return 0; - -}",2 -Vinay.Udeshi#,2063B - Subsequence Update,c++20 ,304505436,304506616,"#include -using namespace std; -#define mod 1000000007 - -void solve(){ - int n, l, r; cin >> n >> l >> r; - - vector v(n); - for(auto &x : v) cin >> x; - - sort(v.begin(), v.end()); - - long long sum = 0; - for(int i = 0; i < (r - l + 1); i++){ - sum += v[i]; - } - - cout << sum << ""\n""; -} - -int main() { - ios::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - - int t; cin >> t; - while (t--) solve(); - return 0; -} -","#include - -using namespace std; - -#define mod 1000000007 - - - -void solve(){ - - int n, l, r; cin >> n >> l >> r; - - - - vector v(n); - - for(auto &x : v) cin >> x; - - - - if(l == 1 || r == n){ - - sort(v.begin(), v.end()); - - - - long long sum = 0; - - for(int i = 0; i < (r - l + 1); i++){ - - sum += v[i]; - - } - - - - cout << sum << ""\n""; - - return; - - } - - - - vector left, right; - - for(int i = 0; i < n; i++){ - - - - if(i+1 < l){ - - left.push_back(v[i]); - - }else if(i + 1 > r){ - - right.push_back(v[i]); - - }else{ - - left.push_back(v[i]); - - right.push_back(v[i]); - - } - - } - - - - sort(left.begin(), left.end()); - - sort(right.begin(), right.end()); - - - - long long suml = 0; - - for(int i = 0; i < (r - l + 1); i++){ - - suml += left[i]; - - } - - - - long long sumr = 0; - - for(int i = 0; i < (r - l + 1); i++){ - - sumr += right[i]; - - } - - cout << min(suml, sumr) << ""\n""; - -} - - - -int main() { - - ios::sync_with_stdio(0); - - cin.tie(0); cout.tie(0); - - - - int t; cin >> t; - - while (t--) solve(); - - return 0; - -} - -",2 -ashutoshbaheti250,2063B - Subsequence Update,c++17 ,307271723,307272701,"#include - -using namespace std; - - - -int main() { - - int t; - - cin >> t; - - while (t--) { - - int n, l, r; - - cin >> n >> l >> r; - - vector v(n); - - for (int i = 0; i < n; i++) { - - cin >> v[i]; - - } - - l--; - - - - vector u(v.begin() + l, v.end()); - - sort(v.begin(), v.begin()+r); - - sort(u.begin(), u.end()); - - - - long long sum_w = accumulate(v.begin(), v.begin() + r-l , 0); - - long long sum_u = accumulate(u.begin(), u.begin() + r - l, 0); - - - - cout << min(sum_w, sum_u) << endl; - - } - - return 0; - -} - -","#include - -using namespace std; - - - -int main() { - - int t, n, l, r, i, a[200000]; - - cin >> t; - - while (t--) { - - cin >> n >> l >> r; - - l--; // Convert to 0-based index - - for (i = 0; i < n; i++) { - - cin >> a[i]; - - } - - vector c(a + l, a + n); - - sort(a, a + r); - - sort(c.begin(), c.end()); - - cout << min(accumulate(a, a + r - l, 0ll), accumulate(c.begin(), c.begin() + r - l, 0ll)) << ' '; - - } - -} - -",2 -Zxm555,2063B - Subsequence Update,c++23 ,307387454,307387576,"#include - -using namespace std; - -typedef long long ll; - -const int N=100005; - -ll a[N],b[N],c[N]; - -void solve(){ - - ll n,l,r;cin>>n>>l>>r; - - for(int i=1;i<=n;i++){ - - cin>>a[i]; - - b[i]=a[i],c[i]=a[i]; - - } - - sort(b+1,b+1+l); - - sort(c+l,c+1+n); - - ll ans1=0,ans2=0; - - for(int i=1;i<=r-l+1;i++) ans1+=b[i]; - - for(int i=l;i<=r;i++) ans2+=c[i]; - - cout<>T; - - while(T--){ - - solve(); - - } - - return 0; - -} - -","#include - -using namespace std; - -typedef long long ll; - -const int N=100005; - -ll a[N],b[N],c[N]; - -void solve(){ - - ll n,l,r;cin>>n>>l>>r; - - for(int i=1;i<=n;i++){ - - cin>>a[i]; - - b[i]=a[i],c[i]=a[i]; - - } - - sort(b+1,b+1+r); - - sort(c+l,c+1+n); - - ll ans1=0,ans2=0; - - for(int i=1;i<=r-l+1;i++) ans1+=b[i]; - - for(int i=l;i<=r;i++) ans2+=c[i]; - - cout<>T; - - while(T--){ - - solve(); - - } - - return 0; - -} - -",2 -ruo_zhi_er_tong,2063B - Subsequence Update,c++20 ,306299470,306298622,"#include - -using namespace std; - -#define int long long - -const int N=1e5+7; - - - -int q[N],ql[N],qr[N]; - - - -void slove(){ - - int n,l,r; cin>>n>>l>>r; - -// vectorq(n+5); - - - - for(int i=1;i<=n;i++){ - - cin>>q[i]; - - ql[i]=q[i]; - - qr[i]=q[i]; - - } - - - - - - sort(ql,ql+r+1); - - sort(qr+l,qr+n+1); - - - - int ans=0,num=r-l+1; - - int cntl=0,cntr=0; - - for(int i=1;i<=num;i++) - - cntl+=ql[i]; - - - - for(int i=l;i<=r;i++) - - cntr+=qr[i]; - - - - ans=min(cntl,cntr); - - - -// for(int i=1;i<=n;i++) - - cout<>t; - - - - while(t--){ - - slove(); - - } - - - -}","#include -using namespace std; -#define int long long -const int N=1e5+7; - -int q[N],ql[N],qr[N]; - -void slove(){ - int n,l,r; cin>>n>>l>>r; -// vectorq(n+5); - - for(int i=1;i<=n;i++){ - cin>>q[i]; - ql[i]=q[i]; - qr[i]=q[i]; - } - - - sort(ql,ql+1+r); - sort(qr+l,qr+1+n); - - int ans=0,num=r-l+1; - int cntl=0,cntr=0; - for(int i=1;i<=num;i++){ - cntl+=ql[i]; - cntr+=qr[i]; - } - ans=min(cntl,cntr); - -// for(int i=1;i<=n;i++) - cout<>t; - - while(t--){ - slove(); - } - -}",1 -huaianz,2063B - Subsequence Update,c++17 ,306047601,306052384,"#include -#define ll long long -using namespace std; -int main() -{ - int t; - cin>>t; - while(t--) - { - int n,l,r,x; - ll y=0; - int a[100000]; - cin>>n>>l>>r; - x=r-l+1; - for(int i=1;i<=n;i++) - { - cin>>a[i]; - } - sort(a+1,a+n+1); - for(int i=1;i<=x;i++) - { - y+=a[i]; - } - cout< -#define ll long long -using namespace std; -//int main() -//{ -// int t; -// cin>>t; -// while(t--) -// { -// int n,l,r,x; -// ll y=0; -// int a[100000]; -// cin>>n>>l>>r; -// x=r-l+1; -// for(int i=1;i<=n;i++) -// { -// cin>>a[i]; -// } -// sort(a+1,a+n+1); -// for(int i=1;i<=x;i++) -// { -// y+=a[i]; -// } -// cout<>n>>l>>r; - ll res=0; - vectora(n+1); - for(int i=1;i<=n;i++) - cin>>a[i]; - priority_queue tmpl_ans,tmpr_ans; - //tmpl_ans 和 tmpr_ans 是最大堆,用于存储区间 [l, r] 内的元素。 - priority_queue,greater> lans,rans; - //lans 和 rans 是最小堆,分别用于存储区间 [1, l-1] 和 [r+1, n] 的元素。 - for(int i=l;i<=r;i++) - { - res+=a[i]; - tmpl_ans.push(a[i]); - tmpr_ans.push(a[i]); - } - for(int i=1;inow2){ - res -= now1-now2; - tmpl_ans.pop(); - tmpl_ans.push(now2); - lans.pop(); - }else{ - break; - } - } - while (!rans.empty()){ - int now1 = tmpr_ans.top(),now2 = rans.top();//最大元素 - if (now1>now2){ - res1 -= now1-now2; - tmpr_ans.pop();//移除堆顶的最大元素 - tmpr_ans.push(now2);//将新的较小元素 now2 插入堆中 - rans.pop(); - }else{ - break; - } - } - cout<>t; - while (t--) - { - solve(); - } - return 0; -} -",2 -aryan3rox,2063B - Subsequence Update,java,309187356,309187754,"import java.util.*; - - - -public class B_Subsequence_Update{ - - public static void main(String[] args) { - - Scanner s = new Scanner(System.in); - - int t = s.nextInt(); - - while (t-->0){ - - int n = s.nextInt(); - - int l = s.nextInt(); - - int r = s.nextInt(); - - int[] arr = new int[n]; - - for (int i=0;i maxpq = new PriorityQueue<>((a,b)->b-a); - - PriorityQueue minpql = new PriorityQueue<>(); - - PriorityQueue minpqr = new PriorityQueue<>(); - - // ArrayList raw = new ArrayList<>(); - - int grr = 0; - - for (int i=l-1;i= sw) break; - - } - - maxpq.clear(); - - sw = 0; - - for (int i=l-1;i= sw) break; - - } - - System.out.println(ans); - - } - - } - -}","import java.util.*; - - - -public class B_Subsequence_Update{ - - public static void main(String[] args) { - - Scanner s = new Scanner(System.in); - - int t = s.nextInt(); - - while (t-->0){ - - int n = s.nextInt(); - - int l = s.nextInt(); - - int r = s.nextInt(); - - int[] arr = new int[n]; - - for (int i=0;i maxpq = new PriorityQueue<>((a,b)->b-a); - - PriorityQueue minpql = new PriorityQueue<>(); - - PriorityQueue minpqr = new PriorityQueue<>(); - - // ArrayList raw = new ArrayList<>(); - - long grr = 0; - - for (int i=l-1;i= sw) break; - - } - - maxpq.clear(); - - sw = 0; - - for (int i=l-1;i= sw) break; - - } - - System.out.println(ans); - - } - - } - -}",2 -rainz07,2063B - Subsequence Update,c++23 ,304887667,304888200,"#include - -using namespace std; -using vi = vector; - -void solve() { - int n, l, r; - cin >> n >> l >> r; - l--; - - vi arr(n); - for (int i = 0; i < n; ++i) { - cin >> arr[i]; - } - - vi brr = arr; - sort(brr.begin() + l, brr.end()); - - vi crr = arr; - sort(crr.begin(), crr.begin() + r, greater()); - - int sum_brr = 0, sum_crr = 0; - for (int i = l; i < r; ++i) { - sum_brr += brr[i]; - sum_crr += crr[i]; - } - - cout << min(sum_brr, sum_crr) << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; - cin >> t; - while (t--) solve(); -} -","#include - -using namespace std; -using vi = vector; -using ll = long long; - -void solve() { - int n, l, r; - cin >> n >> l >> r; - l--; - - vi arr(n); - for (int i = 0; i < n; ++i) { - cin >> arr[i]; - } - - vi brr = arr; - sort(brr.begin() + l, brr.end()); - - vi crr = arr; - sort(crr.begin(), crr.begin() + r, greater()); - - ll sum_brr = accumulate(brr.begin() + l, brr.begin() + r, 0LL); - ll sum_crr = accumulate(crr.begin() + l, crr.begin() + r, 0LL); - - cout << min(sum_brr, sum_crr) << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - - int t; - cin >> t; - while (t--) solve(); -}",2 -akhilpranjal,2063B - Subsequence Update,c++17 ,304554948,304547860,"// Handle: akhilpranjal - -// Date: 05-02-2025 - -// Time: 17:12 - - - -#include - -using namespace std; - - - -#define rep(i,a,b) for (int i=a;i - -#define ll long long - -#define ull unsigned long long - -#define ld long double - -#define F first - -#define S second - -#define all(x) (x).begin(),(x).end() - -#define rall(x) (x).rbegin(),(x).rend() - - - -// Operator Overloads: - - - -template // cin >> pair - -istream& operator>>(istream &istream, pair &p) { return (istream >> p.first >> p.second); } - - - -template // cin >> vector &v - -istream& operator>>(istream &istream, vector &v) - -{ - - for(auto &it : v) - - { - - cin >> it; - - } - - return istream; - -} - - - -template // cout << pair - -ostream& operator<<(ostream &ostream, const pair &p) { return(ostream << p.first << "" "" << p.second); } - - - -template // cout << vector - -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &it : v) cout << it << "" ""; return ostream; } - - - - - - - -void solve() - -{ - - ll n,l,r,sum1=0,sum2=0; - - cin>>n>>l>>r; - - l--;r--; - - vll a(n),b; - - cin>>a; - - b=a; - - // ll x = r-l+1; - - sort(a.begin(),a.begin()+r+1); - - rep(i,0,r-l+1) - - { - - sum1 += a[i]; - - } - - sort(b.begin()+l,b.end()); - - rep(i,l,r+1) - - { - - sum2 += b[i]; - - } - - cout<> t; - - for(int i=1;i<=t;i++) { - - solve(); - - cout< - -using namespace std; - - - -#define rep(i,a,b) for (int i=a;i - -#define ll long long - -#define ull unsigned long long - -#define ld long double - -#define F first - -#define S second - -#define all(x) (x).begin(),(x).end() - -#define rall(x) (x).rbegin(),(x).rend() - - - -// Operator Overloads: - - - -template // cin >> pair - -istream& operator>>(istream &istream, pair &p) { return (istream >> p.first >> p.second); } - - - -template // cin >> vector &v - -istream& operator>>(istream &istream, vector &v) - -{ - - for(auto &it : v) - - { - - cin >> it; - - } - - return istream; - -} - - - -template // cout << pair - -ostream& operator<<(ostream &ostream, const pair &p) { return(ostream << p.first << "" "" << p.second); } - - - -template // cout << vector - -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &it : v) cout << it << "" ""; return ostream; } - - - - - - - -void solve() - -{ - - ll n,l,r,sum=0; - - cin>>n>>l>>r; - - vll a(n); - - cin>>a; - - sort(all(a)); - - rep(i,0,r-l+1) - - { - - sum +=a[i]; - - } - - cout<> t; - - for(int i=1;i<=t;i++) { - - solve(); - - cout< - -using namespace std; - - - - - -void solve() { - - int n, l, r; - - cin >> n >> l >> r; - - - - l--; - - r--; - - vector a(n); - - for (int i = 0;i < n; i++) cin >> a[i]; - - int size = r - l + 1; - - vector first(a.begin(), a.begin() + r + 1); - - vector second(a.begin() + l, a.end()); - - - - sort(first.begin(), first.end()); - - - - long long res = LONG_LONG_MAX; - - long long sum = 0; - - for (int i = 0; i < size; i++) { - - sum += first[i]; - - } - - - - res = min(sum, res); - - - - sort(second.begin(), second.end()); - - sum = 0; - - - - for (int i = 0; i < size; i++) { - - sum += second[i]; - - } - - - - res = min(sum, res); - - - - cout << res << endl; - -} - - - -int main() { - - // freopen(""../input.txt"", ""r"", stdin); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -","#include - -using namespace std; - - - - - -void solve() { - - int n, l, r; - - cin >> n >> l >> r; - - - - l--; - - r--; - - vector a(n); - - for (int i = 0;i < n; i++) cin >> a[i]; - - int size = r - l + 1; - - vector first(a.begin(), a.begin() + r + 1); - - vector second(a.begin() + l, a.end()); - - - - sort(first.begin(), first.end()); - - - - long long res = INT_MAX; - - long long sum = 0; - - for (int i = 0; i < size; i++) { - - sum += first[i]; - - } - - - - res = min(sum, res); - - - - sort(second.begin(), second.end()); - - sum = 0; - - - - for (int i = 0; i < size; i++) { - - sum += second[i]; - - } - - - - res = min(sum, res); - - - - cout << res << endl; - -} - - - -int main() { - - // freopen(""../input.txt"", ""r"", stdin); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -",1 -DarkDestroyer,2063B - Subsequence Update,c++17 ,305566878,305573094,"/****************************************************************************** - - - - Online C++ Compiler. - - Code, Compile, Run and Debug C++ program online. - -Write your code in this editor and press ""Run"" button to compile and execute it. - - - -*******************************************************************************/ - - - -#include - -#include - -#include - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - - - while(t--){ - - int n,l,r; - - cin>>n>>l>>r; - - vectorv(n); - - for(int i = 0;i> v[i]; - - } - - - - sort(v.begin(),v.end()); - - int total = r-l+1; - - int answer = 0; - - int i = 0; - - while(total--){ - - answer += v[i++]; - - } - - cout< -#include -#include -using namespace std; -int main() -{ - int t; - cin>>t; - - while(t--){ - int n,l,r; - cin>>n>>l>>r; - vectorv(n); - for(int i = 0;i> v[i]; - } - - long long leftSum = 0; - long long rightSum = 0; - vectorleft; - vectorright; - - for(int i = 0;i -using namespace std; -#define ll long long -#define pb push_back -void solve(ll tc) -{ - ll n,l,r,i,s1=0,s2=0,a,p; - cin>>n>>l>>r; - p=r-l+1; - vectorv1,v2; - for(i=0; i>a; - if(i=l-1) v2.pb(a); - } - sort(v1.begin(),v1.end()); - sort(v2.begin(),v2.end()); - for(i=0; i>tc; - for(ll i=1; i<=tc; i++) - { - solve(i); - } -} -","#include -using namespace std; -#define ll long long -void solve(ll tc) -{ -ll n,l,r,i,s=0,p; -cin>>n>>l>>r; -p=r-l+1; -vectorv(n); -for(i=0;i>v[i]; -sort(v.begin(),v.end()); -for(i=0;i>tc; - for(ll i=1; i<=tc; i++) - { - solve(i); - } -} -",1 -donbb,2063B - Subsequence Update,c++17 ,306970706,306970817,"#include - -#include - -#include - -#define ll long long - -const int N = 1e5 + 8; - - - -using namespace std; - - - -int a[N]; - - - -void solve() { - - memset(a , sizeof a, 0); - - int n , l , r ; cin >> n >> l >> r; - - - - for (int i = 0 ; i < n ; i ++) cin >> a[i]; - - - - auto b = a; - - - - ll sum1 = 0, sum2 = 0; - - - - sort(a , a + r); - - - - for (int i = 0 ; i < r - l + 1; i ++) sum1 += a[i]; - - - - sort(b + l - 1 , b + n ); - - - - for (int i = l - 1 ; i < l - 1 + r - l + 1; i ++) sum2 +=b[i]; - - - - ll ans = min(sum1, sum2); - - - - cout << ans << endl; - - - - - -} - - - - - -int main(void) { - - ios::sync_with_stdio(false);cin.tie(nullptr); - - int t ; cin >> t; - - while (t--)solve(); - - - -}","#include -#include -#include -#include -#define ll long long -const int N = 1e5 + 8; - -using namespace std; - - - -void solve() { - - int n , l , r ; cin >> n >> l >> r; - - vector a(n); - - for (int i = 0 ; i < n ; i ++) cin >> a[i]; - - auto b = a; - - ll sum1 = 0, sum2 = 0; - - sort(a.begin() , a.begin() + r); - - for (int i = 0 ; i < r - l + 1; i ++) sum1 += a[i]; - - sort(b.begin() + l - 1 , b.end()); - - for (int i = l - 1 ; i < l - 1 + r - l + 1; i ++) sum2 +=b[i]; - - ll ans = min(sum1, sum2); - - cout << ans << endl; - - -} - - -int main(void) { - ios::sync_with_stdio(false);cin.tie(nullptr); - int t ; cin >> t; - while (t--)solve(); - -}",2 -Hinamoriwanai,2063B - Subsequence Update,c++20 ,304848708,304844709,"#include -using namespace std; -typedef long long ll; -ll w1[110000],w2[110000]; -void solve(){ - ll n,l,r; - cin>>n>>l>>r; - for(int i=0;i>w1[i]; - w2[i]=w1[i]; - } - ll x1=0,x2=0; - sort(w1,w1+r,greater()); - sort(w2+l-1,w2+n); - for(int i=l-1;i>t; - while(t--){ - solve(); - } - return 0; -};","#include -using namespace std; -typedef long long ll; -ll w[110000]; -void solve(){ - ll n,l,r; - cin>>n>>l>>r; - for(int i=0;i>w[i]; - sort(w,w+r,greater()); - sort(w+l-1,w+n); - ll x=0; - for(int i=l-1;i>t; - while(t--){ - solve(); - } - return 0; -};",1 -div4_merchant1,2063B - Subsequence Update,c++17 ,304894848,304894427,"#include -#include -using namespace std; - -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; - -#define pb push_back -#define f(i, s, e) for (long long int i = s; i < e; i++) -#define cf(i, s, e) for (long long int i = s; i <= e; i++) -#define rf(i, e, s) for (long long int i = e - 1; i >= s; i--) -#define all(a) (a).begin(), (a).end() -#define ff first -#define ss second -#define MOD 1000000007 -#define PI 3.1415926535897932384626433832795 - -#ifndef ONLINE_JUDGE -#define debug(x) \ - cerr << #x << "" ""; \ - _print(x); \ - cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) { cerr << t; } -void _print(int 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; } - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) { - cerr << ""{""; - _print(p.ff); - cerr << "",""; - _print(p.ss); - cerr << ""}""; -} -template void _print(vector v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(set v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(multiset v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(map v) { - cerr << ""[ ""; - for (auto i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} - -ll left_recur(vector> &arr, ll i, ll j, ll prevI, ll prevJ) { - - ll left, up, down; - left = up = down = 0; - debug(i) debug(j) - debug(arr[i][j]) if (j + 1 < arr[0].size() and arr[i][j + 1] == 'B') { - left = 1 + left_recur(arr, i, j + 1, i, j); - } - if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) { - up = 1 + left_recur(arr, i - 1, j, i, j); - } - if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) { - down = 1 + left_recur(arr, i + 1, j, i, j); - } - ll temp = max(left, max(up, down)); - debug(temp) return max(left, max(up, down)); -} -ll brute_recur(vector> &arr, ll i, ll j, ll prevI, ll prevJ) { - - ll left, up, down; - left = up = down = 0; - // if() - debug(i) debug(j) debug(arr[i][j]) if (j - 1 >= 0 and arr[i][j - 1] == 'B') { - left = 1 + brute_recur(arr, i, j - 1, i, j); - } - if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) { - up = 1 + brute_recur(arr, i - 1, j, i, j); - } - if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) { - down = 1 + brute_recur(arr, i + 1, j, i, j); - } - ll temp = max(left, max(up, down)); - debug(temp) return temp; -} -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif - int t = 1; - cin >> t; - while (t--) { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for (ll i = 0; i < n; i++) { - cin >> a[i]; - } - vector s; - vector left; - vector right; - - for (ll i = l - 1; i < r; i++) - s.pb(a[i]); - - for (ll i = 0; i < l - 1; i++) - left.pb(a[i]); - for (ll i = r; i < n; i++) - right.pb(a[i]); - - sort(all(s), greater<>()); - sort(all(left)); - sort(all(right)); - ll i = 0, j = 0, sum = 0; - sum = accumulate(all(s), (ll)0); - - ll temp = sum; - while (i < left.size()) { - if (j < s.size() and left[i] < s[j]) { - temp -= s[j]; - temp += left[i]; - i++; - j++; - } else { - break; - } - } - i = 0, j = 0; - - ll temp1 = sum; - while (i < right.size()) { - if (j < s.size() and right[i] < s[j]) { - temp1 -= s[j]; - temp1 += right[i]; - i++; - j++; - } else { - break; - } - } - vector ans = {sum, temp1, temp}; - - cout << *min_element(all(ans)) << endl; - - // debug(sum) - } - - return 0; -} -","#include -#include -using namespace std; - -#define fastio() \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL); \ - cout.tie(NULL) -typedef long long ll; -typedef unsigned long long ull; -typedef long double lld; - -#define pb push_back -#define f(i, s, e) for (long long int i = s; i < e; i++) -#define cf(i, s, e) for (long long int i = s; i <= e; i++) -#define rf(i, e, s) for (long long int i = e - 1; i >= s; i--) -#define all(a) (a).begin(), (a).end() -#define ff first -#define ss second -#define MOD 1000000007 -#define PI 3.1415926535897932384626433832795 - -#ifndef ONLINE_JUDGE -#define debug(x) \ - cerr << #x << "" ""; \ - _print(x); \ - cerr << endl; -#else -#define debug(x) -#endif - -void _print(ll t) { cerr << t; } -void _print(int 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; } - -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) { - cerr << ""{""; - _print(p.ff); - cerr << "",""; - _print(p.ss); - cerr << ""}""; -} -template void _print(vector v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(set v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(multiset v) { - cerr << ""[ ""; - for (T i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} -template void _print(map v) { - cerr << ""[ ""; - for (auto i : v) { - _print(i); - cerr << "" ""; - } - cerr << ""]""; -} - -ll left_recur(vector> &arr, ll i, ll j, ll prevI, ll prevJ) { - - ll left, up, down; - left = up = down = 0; - debug(i) debug(j) - debug(arr[i][j]) if (j + 1 < arr[0].size() and arr[i][j + 1] == 'B') { - left = 1 + left_recur(arr, i, j + 1, i, j); - } - if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) { - up = 1 + left_recur(arr, i - 1, j, i, j); - } - if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) { - down = 1 + left_recur(arr, i + 1, j, i, j); - } - ll temp = max(left, max(up, down)); - debug(temp) return max(left, max(up, down)); -} -ll brute_recur(vector> &arr, ll i, ll j, ll prevI, ll prevJ) { - - ll left, up, down; - left = up = down = 0; - // if() - debug(i) debug(j) debug(arr[i][j]) if (j - 1 >= 0 and arr[i][j - 1] == 'B') { - left = 1 + brute_recur(arr, i, j - 1, i, j); - } - if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) { - up = 1 + brute_recur(arr, i - 1, j, i, j); - } - if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) { - down = 1 + brute_recur(arr, i + 1, j, i, j); - } - ll temp = max(left, max(up, down)); - debug(temp) return temp; -} -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif - int t = 1; - cin >> t; - while (t--) { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for (ll i = 0; i < n; i++) { - cin >> a[i]; - } - vector s; - vector left; - vector right; - - for (ll i = l - 1; i < r; i++) - s.pb(a[i]); - - for (ll i = 0; i < l - 1; i++) - left.pb(a[i]); - for (ll i = r; i < n; i++) - right.pb(a[i]); - - sort(all(s), greater<>()); - sort(all(left)); - sort(all(right)); - ll i = 0, j = 0, sum = 0; - sum = accumulate(all(s), 0); - - ll temp = sum; - while (i < left.size()) { - if (j < s.size() and left[i] < s[j]) { - temp -= s[j]; - temp += left[i]; - i++; - j++; - } else { - break; - } - } - i = 0, j = 0; - - ll temp1 = sum; - while (i < right.size()) { - if (j < s.size() and right[i] < s[j]) { - temp1 -= s[j]; - temp1 += right[i]; - i++; - j++; - } else { - break; - } - } - vector ans = {sum, temp1, temp}; - - cout << *min_element(all(ans)) << endl; - - // debug(sum) - } - - return 0; -} -",1 -a_ban_donon,2063B - Subsequence Update,c++17 ,304443769,304443931,"#include -using namespace std; -#ifdef LOCAL -#include ""debug.h"" -#else -#define debug(...) 42; -#define endl '\n' -#endif - -#define int long long - -int solve(int _) { - int l, r, n; - cin >> n >> l >> r; - - vectora(n); - for (int i = 0; i < n; ++i) { - cin >> a[i]; - } - - vectorb(a.begin(), a.begin() + r); - vectorc(a.begin() + l - 1, a.end()); - sort(b.begin(), b.end()); - sort(c.begin(), c.end()); - - // debug(l, r, a, b, c) - return min(accumulate(b.begin(), b.begin() + (r - l + 1), 0), accumulate(c.begin(), c.begin() + (r - l + 1), 0)); -} -signed main() -{ - ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); - int _ = 1; - cin >> _; - while (_--) { - cout << solve(_) << endl; - } -} -","#include - -using namespace std; - -#ifdef LOCAL - -#include ""debug.h"" - -#else - -#define debug(...) 42; - -#define endl '\n' - -#endif - - - -#define int long long - - - -int solve(int _) { - - int l, r, n; - - cin >> n >> l >> r; - - - - vectora(n); - - for (int i = 0; i < n; ++i) { - - cin >> a[i]; - - } - - - - vectorb(a.begin(), a.begin() + r); - - vectorc(a.begin() + l - 1, a.end()); - - sort(b.begin(), b.end()); - - sort(c.begin(), c.end()); - - - - // debug(l, r, a, b, c) - - return min(accumulate(b.begin(), b.begin() + (r - l + 1), 0ll), accumulate(c.begin(), c.begin() + (r - l + 1), 0ll)); - -} - -signed main() - -{ - - ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); - - int _ = 1; - - cin >> _; - - while (_--) { - - cout << solve(_) << endl; - - } - -} - -",2 -aquabreath,2063B - Subsequence Update,python,305811009,305809490,"t=int(input()) - -for case in range(t): - - s=0 - - n,l,r=map(int,input().split()) - - seq=list(map(int,input().split())) - - a=seq[:l-1]+sorted(seq[l-1:]) - - b=sorted(seq[:r])[::-1]+seq[r:] - - print(min(sum(a[l-1:r]),sum(b[l-1:r])))","t=int(input()) - -for case in range(t): - - s=0 - - n,l,r=map(int,input().split()) - - seq=list(map(int,input().split())) - - seg=list(seq[l-1:r]) - - exseg=list(seq[:l-1]) - - exseg.extend(list(seq[r:])) - - seg.append(0) - - s=sum(seg) - - if len(exseg)!=0: - - while min(exseg) -using namespace std; -using ll = long long; -using vll = vector; -using pii = pair; -using pll = pair; -#define all(v) (v).begin(), (v).end() -#define sz(v) (ll)(v).size() -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define f(i, a, b) for (ll i = (a); i < (b); i++) -#define fr(i, a, b) for (ll i = (a); i >= (b); i--) -void solve() { - ll n,l,r; - cin>>n>>l>>r; - vll a(n); - f(i,0,n){cin>>a[i];} - vll fr;vll b; - f(i,0,l-1) - { - fr.pb(a[i]); - } - vll crr; - f(i,l-1,r) - { - crr.pb(a[i]); - } - f(i,r,n) - { - b.pb(a[i]); - } - sort(all(crr)); - sort(all(fr));sort(all(b)); - ll x1=0; - if(fr.size()>0) - { - for(int i=crr.size()-1;i>=0;i--) - { - if(x1==fr.size()){break;} - if(fr[x1]crr[i]){break;} - } - } - sort(all(crr));x1=0; - if(b.size()>0) - { - for(int i=crr.size()-1;i>=0;i--) - { - if(x1==b.size()){break;} - if(b[x1]crr[i]){break;} - } - } - ll ans=0; - f(i,0,crr.size()) - { - ans+=crr[i]; - } - cout<> t; - while (t--) { solve(); } - return 0; -} -","#include -using namespace std; -using ll = long long; -using vll = vector; -using pii = pair; -using pll = pair; -#define all(v) (v).begin(), (v).end() -#define sz(v) (ll)(v).size() -#define pb push_back -#define mp make_pair -#define F first -#define S second -#define f(i, a, b) for (ll i = (a); i < (b); i++) -#define fr(i, a, b) for (ll i = (a); i >= (b); i--) -void solve() { - ll n,l,r; - cin>>n>>l>>r; - vll a(n); - f(i,0,n){cin>>a[i];} - vll fr;vll b; - f(i,0,l-1) - { - fr.pb(a[i]); - } - vll crr; - f(i,l-1,r) - { - crr.pb(a[i]); - } - f(i,r,n) - { - b.pb(a[i]); - } - vll tou=crr;ll a1=0;ll a2=a1; - sort(all(crr)); - sort(all(fr));sort(all(b)); - ll x1=0; - if(fr.size()>0) - { - for(int i=crr.size()-1;i>=0;i--) - { - if(x1==fr.size()){break;} - if(fr[x1]crr[i]){break;} - } - } - f(i,0,crr.size()) - { - a1+=crr[i]; - } - crr=tou; - sort(all(crr));x1=0; - if(b.size()>0) - { - for(int i=crr.size()-1;i>=0;i--) - { - if(x1==b.size()){break;} - if(b[x1]crr[i]){break;} - } - } - - f(i,0,crr.size()) - { - a2+=crr[i]; - } - cout<> t; - while (t--) { solve(); } - return 0; -} -",2 -bhavyacoder,2063B - Subsequence Update,c++17 ,304375973,304375836,"#include -using namespace std; -int main(){ - int t; - cin>>t; - while(t-->0){ - long long int n,l,r; - cin>>n>>l>>r; - vectorv(n); - vectora,b; - long long int g=(r-l)+1; - for(long long int i=0;i>v[i]; - } - for(long long int i=l-1;i -using namespace std; -int main(){ - int t; - cin>>t; - while(t-->0){ - int n,l,r; - cin>>n>>l>>r; - vectorv(n); - vectora,b; - int g=(r-l)+1; - for(int i=0;i>v[i]; - } - for(int i=l-1;i - -#include - -#include - -#include - -#include - - - -int main() - -{ - - std::size_t tc, n, l, r; - - std::cin >> tc; - - for(std::size_t i{0}; i> n >> l >> r; - - std::vector seq(n); - - for(auto& el : seq) - - std::cin >> el; - - std::vector left(seq.begin(), seq.begin()+r), - - right(seq.begin()+l-1, seq.end()); - - std::ranges::sort(left); - - std::ranges::sort(right); - - std::cout << std::min(std::accumulate(left.begin(), left.begin()+r-l+1, 0ULL), - - std::accumulate(right.begin(), right.begin()+r-l+1, 0ULL)) << ""\n""; - - } - -}","#include - -#include - -#include - -#include - -#include - - - -int main() - -{ - - std::size_t tc, n, l, r; - - std::cin >> tc; - - for(std::size_t i{0}; i> n >> l >> r; - - std::vector seq(n); - - for(auto& el : seq) - - std::cin >> el; - - std::vector left(seq.begin(), seq.begin()+r), - - right(seq.begin()+l-1, seq.end()); - - std::ranges::sort(left); - - std::ranges::sort(right); - - - - std::cout << std::min(std::accumulate(left.begin(), left.begin()+r-l+1, 0), - - std::accumulate(right.begin(), right.begin()+r-l+1, 0)) << ""\n""; - - } - -}",1 -tock,2063B - Subsequence Update,c++23 ,306996620,306996435,"#include - -using namespace std; - -#define ll long long - -#define ull unsigned long long - -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) - -#define PII pair - -#define PLL pair - -#define lowbit(x) (x & -(x)) - -#define INF 0x3f3f3f3f - -#define ls(p) p << 1 - -#define rs(p) p << 1 | 1 - -const double eps = 1e-6; - -const double PI = acos(double(-1)); - -const ull base = 131; - -const double C = 0.5772156649; - -const int mod = 1000007; - -const int N = 1e5 + 7; - -ll a[N],b[N]; - -void solve(){ - - int n, l, r; - - cin >> n >> l >> r; - - for(int i = 1; i <= n; i++){ - - cin >> a[i]; - - b[i] = a[i]; - - } - - sort(b + 1, b + r + 1); - - ll ans = 0; - - for (int i = l; i <= r;i++){ - - ans += b[i - l + 1]; - - } - - sort(a + l, a + n + 1); - - ll res = 0; - - for (int i = l; i <= r;i++){ - - res += a[i]; - - } - - ans = min(ans, res); - - cout << ans << endl; - -} - -int main() - -{ - - IOS; - - int t=1; - - cin>>t; - - while(t--){ - - solve(); - - } - - return 0; - -}","#include -using namespace std; -#define ll long long -#define endl ""\n"" -#define ull unsigned long long -#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) -#define PII pair -#define PLL pair -#define lowbit(x) (x & -(x)) -#define INF 0x3f3f3f3f -#define ls(p) p << 1 -#define rs(p) p << 1 | 1 -const double eps = 1e-6; -const double PI = acos(double(-1)); -const ull base = 131; -const double C = 0.5772156649; -const int mod = 1000007; -const int N = 2e5 + 7; -int w[N]; -void solve() -{ - int n, q; - cin >> n >> q; - for(int i = 1; i <= n; i++){ - cin >> w[i]; - } - -} -int main() -{ - IOS; - int t = 1; - cin >> t; - while(t--){ - solve(); - } - return 0; -}",1 -GabrielSpd,2063B - Subsequence Update,c++17 ,304249262,304252601,"#include - -using namespace std; - -#define int long long -#define pb push_back -#define FORI(sti, n) for(int i=(sti); i<(n); i++) -#define FORJ(stj, n) for(int j=(stj); j<(n); j++) -#define FORK(stk, n) for(int k=(stk); k<(n); k++) -#define tvi(v) FORI(0, (v).size()) cerr << (v)[i] << "" ""; cerr << ""\n""; -#define tii(val) cerr << ""("" << (val).first << "", "" << (val).second << "")\n""; -#define tvii(v) FORI(0, (v).size()) { tii((v)[i]) } cerr << ""\n""; -#define tvvi(v) FORI(0, (v).size()) { FORJ(0, (v)[i].size()){ cerr << v[i][j] << "" ""; } cerr << ""\n""; } -#define all(v) (v).begin(), (v).end() -#define rall(v) (v).rbegin(), (v).rend() - -typedef vector vi; -typedef pair ii; -typedef vector vvi; -typedef vector vii; -typedef vector vbl; - -void solve(){ - int n, l, r; - cin >> n >> l >> r; - vi v(n); - for(auto &a: v) cin >> a; - - vi store, numbers; - - for(int i=0; i=(l-1) && i<=(r-1)){ - store.pb(v[i]); - } - else{ - numbers.pb(v[i]); - } - } - sort(rall(store)); - sort(all(numbers)); - - int ans=0, idx=0; - for(int i=0; inumbers[idx]){ - store[i]=numbers[idx]; - idx++; - } - ans+=store[i]; - } - - cout << ans << ""\n""; -} - -signed main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - - int t; cin >> t; while(t--) - solve(); - - return 0; -} -","#include - -using namespace std; - -#define int long long -#define pb push_back -#define FORI(sti, n) for(int i=(sti); i<(n); i++) -#define FORJ(stj, n) for(int j=(stj); j<(n); j++) -#define FORK(stk, n) for(int k=(stk); k<(n); k++) -#define tvi(v) FORI(0, (v).size()) cerr << (v)[i] << "" ""; cerr << ""\n""; -#define tii(val) cerr << ""("" << (val).first << "", "" << (val).second << "")\n""; -#define tvii(v) FORI(0, (v).size()) { tii((v)[i]) } cerr << ""\n""; -#define tvvi(v) FORI(0, (v).size()) { FORJ(0, (v)[i].size()){ cerr << v[i][j] << "" ""; } cerr << ""\n""; } -#define all(v) (v).begin(), (v).end() -#define rall(v) (v).rbegin(), (v).rend() - -typedef vector vi; -typedef pair ii; -typedef vector vvi; -typedef vector vii; -typedef vector vbl; - - - -void solve(){ - int n, l, r; - cin >> n >> l >> r; - vi v(n); - for(auto &a: v) cin >> a; - - vi store, numbers, pt1, pt2; - int npt1=0; - int npt2=0; - - for(int i=0; i=(l-1) && i<=(r-1)){ - store.pb(v[i]); - } - else{ - if(i<(l-1)){ - pt1.pb(v[i]); npt1+=v[i]; - } - else{ - pt2.pb(v[i]); npt2+=v[i]; - } - } - } - - sort(rall(store)); - vi store2 = store; - sort(all(pt1)); - sort(all(pt2)); - - int ans1=0, ans2=0, idx1=0, idx2=0; - for(int i=0; ipt1[idx1]){ - store[i]=pt1[idx1]; - idx1++; - } - - if(idx2pt2[idx2]){ - store2[i]=pt2[idx2]; - idx2++; - } - - ans1+=store[i]; - ans2+=store2[i]; - } - - cout << min(ans1, ans2) << ""\n""; -} - -signed main(){ - ios_base::sync_with_stdio(false); - cin.tie(0); - - int t; cin >> t; while(t--) - solve(); - - return 0; -} -",2 -K_0AFK,2063B - Subsequence Update,c++17 ,306150669,306106579,"#include - -#include - -using namespace std; - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n,l,r; - - cin>>n>>l>>r; - - int a[n]; - - for (int i = 0 ; i < n ; i++) - - cin>>a[i]; - - - - sort(a+l-1,a+r); - - sort(a,a+l-1); - - sort(a+r,a+n); - - - - - - int start = 0 , mid = r-1 , end = r; - - - - int long long ans_1 = 0 , ans_2 = 0; - - - - while(mid>=l-1) - - { - - if(start -#include -using namespace std; -int main() -{ - int t; - cin>>t; - while(t--) - { - int n,l,r; - cin>>n>>l>>r; - int a[n]; - for(int i = 0 ; i < n ; i++) - cin>>a[i]; - int x = r-l+1; - int lim[x]; - int rem[n-x]; - int e = 0 , f = 0 ; - - for(int i = 0 ; i < n ; i++) - { - if(i+1>=l and i+1<=r) - { - lim[e] = a[i]; - e++; - } - - else - { - rem[f] = a[i]; - f++; - } - } - - sort(lim,lim+x); - sort(rem,rem+(n-x)); - - int p = x-1 , q = 0; - - int res = 0 ; - - while(p>=0 and q=n-x) - { - while(p>=0) - res+=lim[p--]; - } - - cout< - -#include - -#include - -using namespace std; - -int main(){ - - int t; - - cin>>t; - - vector ans; - - while(t--){ - - int n,l,r; - - cin>>n>>l>>r; - - long long sum=0; - - vector vec(n,0); - - for(int i=0;i>vec[i]; - - } - - sort(vec.begin(), vec.end()); - - for(int i=0;i<=(r-l);i++){ - - sum+=vec[i]; - - } - - ans.push_back(sum); - - } - - for(auto num:ans) cout< -#include -#include -using namespace std; -int main(){ - int t; - cin>>t; - vector ans; - while(t--){ - int n,l,r,x; - cin>>n>>l>>r; - vector vec(n,0); - vector help(n,0); - for(int i=0;i>x; - vec[i]=x; - help[i]=x; - } - sort(vec.begin(), vec.begin()+r); - sort(help.begin()+(l-1), help.end()); - int i=0, j=l-1; - long long sum1=0, sum2=0; - while(i<=(r-l)) sum1+=vec[i++]; - while(j -using namespace std; - - -int main(){ - - int t; - cin >> t; - - while(t--){ - int n,l,r; - cin >> n >> l >>r; - vector v(n, 0); - for (int i = 0; i < n;i++){ - cin >> v[i]; - } - vector v2 = v; - vector v3 = v; - sort(v2.begin(), v2.begin() + r ); - sort(v3.begin() +l-1, v3.end() ); - long long sum1 = 0; - for (int i = 0; i < (r - l + 1);i++){ - sum1 += v2[i]; - } - long long sum2 = 0; - for (int i = l-1; i < r;i++){ - sum2 += v3[i]; - } - - cout << min(sum1,sum2) << endl; - } -}","#include -using namespace std; - - -int main(){ - - int t; - cin >> t; - - while(t--){ - int n,l,r; - cin >> n >> l >>r; - vector v(n, 0); - for (int i = 0; i < n;i++){ - cin >> v[i]; - } - vector v2 = v; - vector v3 = v; - sort(v2.begin(), v2.begin() + (r+1) ); - sort(v3.begin() +l-1, v3.end() ); - int sum1 = 0; - for (int i = 0; i < (r - l + 1);i++){ - sum1 += v2[i]; - } - int sum2 = 0; - for (int i = l-1; i < r;i++){ - sum2 += v3[i]; - } - - cout << min(sum1,sum2) << endl; - } -}",1 -PeaCoN,2063B - Subsequence Update,c++23 ,304220286,304218420,"#include -#include -#include -using namespace std; - -int main() { - int t, n, l, r; - cin >> t; - for (int i = 0; i < t; i++) { - vector lArr, rArr; - cin >> n >> l >> r; - for (int j = 1; j <= n; j++) { - int a; - cin >> a; - if (j <= r) lArr.push_back(a); - if (j >= l) rArr.push_back(a); - } - - sort(lArr.begin(), lArr.end()); - sort(rArr.begin(), rArr.end()); - long long max1 = 0, max2 = 0; - - for (int k = 0; k < r - l + 1; k++) { - max1 = (max1 + lArr[k] < 0) ? LLONG_MAX : max1 + lArr[k]; - max2 = (max2 + rArr[k] < 0) ? LLONG_MAX : max2 + rArr[k]; - } - cout << min(max1, max2) << ""\n""; - } -} -","#include -#include -#include -using namespace std; - -int main() { - int t, n, l, r; - cin >> t; - for (int i = 0; i < t; i++) { - vector lArr, rArr; - cin >> n >> l >> r; - for (int j = 1; j <= n; j++) { - int a; - cin >> a; - if (j <= r) lArr.push_back(a); - if (j >= l) rArr.push_back(a); - } - - sort(lArr.begin(), lArr.end()); - sort(rArr.begin(), rArr.end()); - int max1 = 0, max2 = 0; - - for (int k = 0; k < r - l + 1; k++) { - max1 += lArr[k]; - max2 += rArr[k]; - } - cout << min(max1, max2) << ""\n""; - } -} -",1 -nah_man,2063B - Subsequence Update,c++17 ,304014319,304014652,"//******************************************************// -//* AUTHOR: NAMAN OSTWAL *// -//******************************************************// -//______________________________________________________________________________________________________// -#include -using namespace std; -// #include -// #include -// using namespace __gnu_pbds; -// #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define ll long long -long long int INF = 1e9+7; -long long int mod = 1e9+7; -const int N = 1e6+7; -vector isprime(N, true); - -inline void fast_io() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -void print(vector&v) { for(auto it : v) cout< &v) { sort(v.begin() , v.end()); } -void rsort(vector < ll > &v) { sort(v.begin() , v.end(), greater()); } -ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } -ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; } -ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; } -ll lcm(ll a, ll b) { return ((a * b) / (__gcd(a,b))); } - -ll bin_expo(ll a, ll b) { - a %= mod; - ll ans = 1; - while (b > 0) { - if (b & 1) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans % mod; -} - -void sieve_of_eratosthenes() { - isprime[0] = isprime[1] = false; - for(int i = 2; i<=N; i++) { - if(isprime[i] == true) { - for(int j = 2*i; j<=N; j+=i) { - isprime[j] = false; - } - } - } -} - -bool ispal(string s) { - int n = s.size(); - for (int i = 0; i < n / 2; ++i) { - if (s[i] != s[n - i - 1]) { - return false; - } - } - return true; -} - -void DFSUtil(ll node, vector>& adj, vector& visited, vector& dfs) { - visited[node] = true; - dfs.push_back(node); - for (ll neighbor : adj[node]) { - if (!visited[neighbor]) { - DFSUtil(neighbor, adj, visited, dfs); - } - } -} - -void dfs(vector>& adj, ll n, vector& dfs) { - vector visited(n, false); - for (ll i = 0; i < n; ++i) { - if (!visited[i]) { - DFSUtil(i, adj, visited, dfs); - } - } -} - -void bfs(vector>& adj, ll n, vector& bfs) { - queue q; - vector visited(n, false); - visited[0] = true; - q.push(0); - while (!q.empty()) { - ll node = q.front(); - q.pop(); - bfs.push_back(node); - for (auto it : adj[node]) { - if (!visited[it]) { - visited[it] = true; - q.push(it); - } - } - } -} - -int main() { - fast_io(); - int t; - cin >> t; - while (t--) { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for (int i = 0; i < n; i++) cin >> a[i]; - l--, r--; - ll len = r - l + 1; - vector pre(len + 1, INF), suf(len + 1, INF), mid(len + 1, INF); - sort(a.begin(), a.begin() + l); - sort(a.begin() + l, a.begin() + r + 1); - reverse(a.begin() + l, a.begin() + r + 1); - sort(a.begin() + r + 1, a.end()); - suf[0] = pre[0] = mid[0] = 0; - for (int i = 0; i < min(len, l); i++) { - pre[i + 1] = pre[i] + a[i]; - } - for(int i = l; i <= r; i++) { - mid[i - l + 1] = mid[i - l] + a[i]; - } - for(int i = r + 1; i < min(r + 1 + len, n); i++) { - suf[i - r] = suf[i - r - 1] + a[i]; - } - ll ans = 0; - for(int i = 1; i <= len; i++) { - ans = max(ans, mid[i] - suf[i]); - ans = max(ans, mid[i] - pre[i]); - } - ans = -ans; - for(int i = l; i <= r; i++) ans += a[i]; - cout << ans << ""\n""; - } - return 0; -}","//******************************************************// -//* AUTHOR: NAMAN OSTWAL *// -//******************************************************// -//______________________________________________________________________________________________________// -#include -using namespace std; -// #include -// #include -// using namespace __gnu_pbds; -// #define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define ll long long -long long int INF = 1e18; -long long int mod = 1e9+7; -const int N = 1e6+7; -vector isprime(N, true); - -inline void fast_io() { - ios_base::sync_with_stdio(false); - cin.tie(NULL); - cout.tie(NULL); -} - -void print(vector&v) { for(auto it : v) cout< &v) { sort(v.begin() , v.end()); } -void rsort(vector < ll > &v) { sort(v.begin() , v.end(), greater()); } -ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } -ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; } -ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; } -ll lcm(ll a, ll b) { return ((a * b) / (__gcd(a,b))); } - -ll bin_expo(ll a, ll b) { - a %= mod; - ll ans = 1; - while (b > 0) { - if (b & 1) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans % mod; -} - -void sieve_of_eratosthenes() { - isprime[0] = isprime[1] = false; - for(int i = 2; i<=N; i++) { - if(isprime[i] == true) { - for(int j = 2*i; j<=N; j+=i) { - isprime[j] = false; - } - } - } -} - -bool ispal(string s) { - int n = s.size(); - for (int i = 0; i < n / 2; ++i) { - if (s[i] != s[n - i - 1]) { - return false; - } - } - return true; -} - -void DFSUtil(ll node, vector>& adj, vector& visited, vector& dfs) { - visited[node] = true; - dfs.push_back(node); - for (ll neighbor : adj[node]) { - if (!visited[neighbor]) { - DFSUtil(neighbor, adj, visited, dfs); - } - } -} - -void dfs(vector>& adj, ll n, vector& dfs) { - vector visited(n, false); - for (ll i = 0; i < n; ++i) { - if (!visited[i]) { - DFSUtil(i, adj, visited, dfs); - } - } -} - -void bfs(vector>& adj, ll n, vector& bfs) { - queue q; - vector visited(n, false); - visited[0] = true; - q.push(0); - while (!q.empty()) { - ll node = q.front(); - q.pop(); - bfs.push_back(node); - for (auto it : adj[node]) { - if (!visited[it]) { - visited[it] = true; - q.push(it); - } - } - } -} - -int main() { - fast_io(); - int t; - cin >> t; - while (t--) { - ll n, l, r; - cin >> n >> l >> r; - vector a(n); - for (int i = 0; i < n; i++) cin >> a[i]; - l--, r--; - ll len = r - l + 1; - vector pre(len + 1, INF), suf(len + 1, INF), mid(len + 1, INF); - sort(a.begin(), a.begin() + l); - sort(a.begin() + l, a.begin() + r + 1); - reverse(a.begin() + l, a.begin() + r + 1); - sort(a.begin() + r + 1, a.end()); - suf[0] = pre[0] = mid[0] = 0; - for (int i = 0; i < min(len, l); i++) { - pre[i + 1] = pre[i] + a[i]; - } - for(int i = l; i <= r; i++) { - mid[i - l + 1] = mid[i - l] + a[i]; - } - for(int i = r + 1; i < min(r + 1 + len, n); i++) { - suf[i - r] = suf[i - r - 1] + a[i]; - } - ll ans = 0; - for(int i = 1; i <= len; i++) { - ans = max(ans, mid[i] - suf[i]); - ans = max(ans, mid[i] - pre[i]); - } - ans = -ans; - for(int i = l; i <= r; i++) ans += a[i]; - cout << ans << ""\n""; - } - return 0; -}",2 -xingliu,2063B - Subsequence Update,c++20 ,305909139,305908478,"/** - - * author: xing huan liu kong - - * created: 2025-02-13 10:22:59 - - * - - * 即使这个图论(world)大的无边无际 - - * 我也会深度优先搜索(dfs)找到你.. - -**/ - -#include - -#define ll long long - -#define endl '\n' - -#define point(x) fixed< PII; - -typedef array arr; - - - -void solve() - -{ - - int n, l, r; - - cin >> n >> l >> r; - - - - vector a(n + 1, 0), b, c, d; - - for (int i = 1; i <= n; i ++ ) { - - cin >> a[i]; - - if (i < l) b.push_back(a[i]); - - else if (i > r) c.push_back(a[i]); - - else d.push_back(a[i]); - - } - - - - sort(b.begin(), b.end()); - - sort(c.begin(), c.end()); - - sort(d.rbegin(), d.rend()); - - - - int sum = accumulate(d.begin(), d.end(), 0ll); - - int res = sum; - - for (int i = 0, ts = 0; i < (int)b.size() && i < (int)d.size(); i ++ ) { - - ts += b[i] - d[i]; - - res = min (res, sum + ts); - - } - - for (int i = 0, ts = 0; i < (int)c.size() && i < (int)d.size(); i ++ ) { - - ts += c[i] - d[i]; - - res = min (res, sum + ts); - - } - - - - cout << res << endl; - - - -} - - - -signed main(void) - -{ - - ios_base::sync_with_stdio(0); - - cin.tie(0), cout.tie(0); - - - - int t = 1; - - cin >> t; - - - - while(t -- ){ - - solve(); - - } - - - - return 0; - -}","/** - * author: xing huan liu kong - * created: 2025-02-13 10:22:59 - * - * 即使这个图论(world)大的无边无际 - * 我也会深度优先搜索(dfs)找到你.. -**/ -#include -#define ll long long -#define endl '\n' -#define point(x) fixed< PII; -typedef array arr; - -void solve() -{ - int n, l, r; - cin >> n >> l >> r; - - vector a(n + 1, 0), b, c, d; - for (int i = 1; i <= n; i ++ ) { - cin >> a[i]; - if (i < l) b.push_back(a[i]); - else if (i > r) c.push_back(a[i]); - else d.push_back(a[i]); - } - - sort(b.begin(), b.end()); - sort(c.begin(), c.end()); - sort(d.rbegin(), d.rend()); - - int sum = accumulate(d.begin(), d.end(), 0); - int res = sum; - for (int i = 0, ts = 0; i < (int)b.size() && i < (int)d.size(); i ++ ) { - ts += b[i] - d[i]; - res = min (res, sum + ts); - } - for (int i = 0, ts = 0; i < (int)c.size() && i < (int)d.size(); i ++ ) { - ts += c[i] - d[i]; - res = min (res, sum + ts); - } - - cout << res << endl; - -} - -signed main(void) -{ - ios_base::sync_with_stdio(0); - cin.tie(0), cout.tie(0); - - int t = 1; - cin >> t; - - while(t -- ){ - solve(); - } - - return 0; -}",1 -abhishekjhagolu785701:05,2063B - Subsequence Update,c++17 ,304856819,304854801,"/** - - * Author: Abhishek Jha - -**/ - -#include - -#define int long long - -using namespace std; - - - -#define all(x) x.begin(), x.end() - -#define rall(x) x.rbegin(), x.rend() - -#define sz(x) (int)(x).size() - -#define ft first - -#define sd second - -#define pb push_back - - - -typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vii;typedef vector vvii;typedef long long ll; - - - -const int MOD = 1e9+7;const int INFLL = 1e18+5;const int INF = 1e9;const int maxN = 101;const int maxK = 8001; - - - -void printbit(int x, int len) {string s=""\n"";while(len--){s=((x%2)?'1':'0')+s;x/=2;} cout< - -istream& operator>>(istream&in, vector&v){for (T& x:v) in>>x;return in;} - -template - -ostream& operator<<(ostream&out, vector&v){for (T& x:v) out<n)return 0;long long p = 1, k = 1;if(n - r < r)r = n - r;if (r != 0) { while (r) {p *= n;k *= r;ll m = __gcd(p, k);p /= m;k /= m;n--;r--;}}else p = 1;return p;} - -/*------------------------------------------------------------------------------------------------------------------*/ - - - -void solve(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vi a(n); - - cin>>a; - - vi b; - - vi c; - - for(int i=0;i<=r-1;i++){ - - b.push_back(a[i]); - - } - - for(int i=l-1;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}","/** - - * Author: Abhishek Jha - -**/ - -#include - -#define int long long - -using namespace std; - - - -#define all(x) x.begin(), x.end() - -#define rall(x) x.rbegin(), x.rend() - -#define sz(x) (int)(x).size() - -#define ft first - -#define sd second - -#define pb push_back - - - -typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vii;typedef vector vvii;typedef long long ll; - - - -const int MOD = 1e9+7;const int INFLL = 1e18+5;const int INF = 1e9;const int maxN = 101;const int maxK = 8001; - - - -void printbit(int x, int len) {string s=""\n"";while(len--){s=((x%2)?'1':'0')+s;x/=2;} cout< - -istream& operator>>(istream&in, vector&v){for (T& x:v) in>>x;return in;} - -template - -ostream& operator<<(ostream&out, vector&v){for (T& x:v) out<n)return 0;long long p = 1, k = 1;if(n - r < r)r = n - r;if (r != 0) { while (r) {p *= n;k *= r;ll m = __gcd(p, k);p /= m;k /= m;n--;r--;}}else p = 1;return p;} - -/*------------------------------------------------------------------------------------------------------------------*/ - - - -void solve(){ - - ll n,l,r; - - cin>>n>>l>>r; - - vi a(n); - - cin>>a; - - sort(a.begin(),a.end()); - - ll ans = 0; - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - - - return 0; - -}",1 -zapper9982,2063B - Subsequence Update,c++23 ,304198046,304198448,"#include -#include -using namespace std; - -// Speed -#define Code ios_base::sync_with_stdio(false); -#define By cin.tie(NULL); -#define Asquare cout.tie(NULL); - -// Aliases -using ll = long long; -using lld = long double; -using ull = unsigned long long; - -// Constants -const lld pi = 3.141592653589793238; -const ll INF = LONG_LONG_MAX; -const ll mod = 1e9 + 7; - -// TypeDefs -typedef pair pll; -typedef vector vll; -typedef vector vpll; -typedef vector vs; -typedef unordered_map umll; -typedef map mll; - -// Macros -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define fl(i, n) for (int i = 0; i < n; i++) -#define rl(i, m, n) for (int i = n; i >= m; i--) -#define py cout << ""YES\n""; -#define pn cout << ""NO\n""; - - -// Operator Overloads -template -istream &operator>>(istream &istream, pair &p) { return (istream >> p.first >> p.second); } -template -istream &operator>>(istream &istream, vector &v) { for (auto &it : v) cin >> it; return istream; } -template -ostream &operator<<(ostream &ostream, const pair &p) { return (ostream << p.first << "" "" << p.second); } -template -ostream &operator<<(ostream &ostream, const vector &c) { for (auto &it : c) cout << it << "" ""; return ostream; } - -// Utility Functions -template -void print(T &&t) { cout << t << ""\n""; } -void printarr(ll arr[], ll n) { fl(i, n) cout << arr[i] << "" ""; cout << ""\n""; } -template -void printvec(vector v) { ll n = v.size(); fl(i, n) cout << v[i] << "" ""; cout << ""\n""; } -template -ll sumvec(vector v) { ll n = v.size(); ll s = 0; fl(i, n) s += v[i]; return s; } - -// Mathematical Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } -ll moduloMultiplication(ll a, ll b, ll mod) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; b >>= 1; } return res; } -ll powermod(ll x, ll y, ll p) { ll res = 1; x %= p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } - -// Code -void asquare() { - ll n, l, r; - cin >> n >> l >> r; - vll arr(n); - fl(i,n) cin >>arr[i]; - sort(arr.begin() + (l - 1), arr.end()); - ll sum1 = accumulate(arr.begin() + (l - 1), arr.begin() + r, 0); - - sort(arr.begin(), arr.begin() + r, greater()); - ll sum2 = accumulate(arr.begin() + (l - 1), arr.begin() + r, 0); - - cout << min(sum1, sum2) << ""\n""; -} - -// Main -int main() { - Code By Asquare - ll t; - cin >> t; - fl(i, t) { - asquare(); - } - return 0; -} -// End","#include -#include -using namespace std; - -// Speed -#define Code ios_base::sync_with_stdio(false); -#define By cin.tie(NULL); -#define Asquare cout.tie(NULL); - -// Aliases -using ll = long long; -using lld = long double; -using ull = unsigned long long; - -// Constants -const lld pi = 3.141592653589793238; -const ll INF = LONG_LONG_MAX; -const ll mod = 1e9 + 7; - -// TypeDefs -typedef pair pll; -typedef vector vll; -typedef vector vpll; -typedef vector vs; -typedef unordered_map umll; -typedef map mll; - -// Macros -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define fl(i, n) for (int i = 0; i < n; i++) -#define rl(i, m, n) for (int i = n; i >= m; i--) -#define py cout << ""YES\n""; -#define pn cout << ""NO\n""; - - -// Operator Overloads -template -istream &operator>>(istream &istream, pair &p) { return (istream >> p.first >> p.second); } -template -istream &operator>>(istream &istream, vector &v) { for (auto &it : v) cin >> it; return istream; } -template -ostream &operator<<(ostream &ostream, const pair &p) { return (ostream << p.first << "" "" << p.second); } -template -ostream &operator<<(ostream &ostream, const vector &c) { for (auto &it : c) cout << it << "" ""; return ostream; } - -// Utility Functions -template -void print(T &&t) { cout << t << ""\n""; } -void printarr(ll arr[], ll n) { fl(i, n) cout << arr[i] << "" ""; cout << ""\n""; } -template -void printvec(vector v) { ll n = v.size(); fl(i, n) cout << v[i] << "" ""; cout << ""\n""; } -template -ll sumvec(vector v) { ll n = v.size(); ll s = 0; fl(i, n) s += v[i]; return s; } - -// Mathematical Functions -ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } -ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } -ll moduloMultiplication(ll a, ll b, ll mod) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; b >>= 1; } return res; } -ll powermod(ll x, ll y, ll p) { ll res = 1; x %= p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } - -// Code -void asquare() { - ll n, l, r; - cin >> n >> l >> r; - l--; - vll arr(n); - fl(i,n) cin>>arr[i]; - - vll brr; - fl(i,l) brr.push_back(arr[i]); - - vll sp; - for (ll i = l; i < n; i++) { - sp.push_back(arr[i]); - } - sort(sp.begin(), sp.end()); - for (ll val : sp) { - brr.push_back(val); - } - - vll crr; - fl(i,r) crr.push_back(arr[i]); - - sort(crr.begin(), crr.end(), greater()); - for (ll i = r; i < n; i++) { - crr.push_back(arr[i]); - } - - ll sum_brr = 0, sum_crr = 0; - for (ll i = l; i < r; i++) { - sum_brr += brr[i]; - sum_crr += crr[i]; - } - - cout << min(sum_brr, sum_crr) << ""\n""; -} - -// Main -int main() { - Code By Asquare - ll t; - cin >> t; - fl(i, t) { - asquare(); - } - return 0; -} -// End",2 -kartik__sethi,2063B - Subsequence Update,java,304917503,304917188," -/* package codechef; // don't place package name! */ - -import java.util.*; -import java.lang.*; -import java.io.*; - -public class Main { - - //------------------------------------------main--------------------------------------------------// - public static void main(String[] args) throws java.lang.Exception { - OutputStream outputStream = System.out; - PrintWriter out = new PrintWriter(outputStream); - FastReader sc = new FastReader(); - Task s = new Task(sc, out); - s.solve(); - out.close(); - // your code goes here"" - } -} - -class FastReader { - - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - public int[] readIntArray(int n) throws IOException { - int[] arr = new int[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextInt(); - } - return arr; - } - - public long[] readLongArray(int n) throws IOException { - long[] arr = new long[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextLong(); - } - return arr; - } -} - -class Task { - - PrintWriter out; - FastReader sc; - - Task(FastReader sc, PrintWriter out) { - this.sc = sc; - this.out = out; - } - //----------------------------------------------inputfunction------------------------------------------// - - String st() { - return sc.nextLine(); - } - - int i() { - return sc.nextInt(); - } - - long l() { - return sc.nextLong(); - } - - double d() { - return sc.nextDouble(); - } - - //---------------------------------------------absolute----------------------------------------------// - public long abs(long a) { - return a < 0 ? -a : a; - } - - public int abs(int a) { - return a < 0 ? -a : a; - } - - //-------------------------------------------max--------------------------------------------------// - public int max(int a, int b) { - return a >= b ? a : b; - } - - public long max(long a, long b) { - return a >= b ? a : b; - } - - public int max(int a, int b, int c) { - return Math.max(a, Math.max(b, c)); - } - - public long max(long a, long b, long c) { - return Math.max(a, Math.max(b, c)); - } - - //------------------------------------------min---------------------------------------------------// - public int min(int a, int b) { - return a <= b ? a : b; - } - - public long min(long a, long b) { - return a <= b ? a : b; - } - - public int min(int a, int b, int c) { - return Math.min(a, Math.min(b, c)); - } - - public long min(long a, long b, long c) { - return Math.min(a, Math.min(b, c)); - } - - //----------------------------------------sortingfunction---------------------------------------------// - private void sort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - //---------------------------------------power----------------------------------------------------// - - public long pow(long a, int b) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans *= a; - } - a *= a; - b >>= 1; - } - return b; - } - //----------------------------------------binary_exponentiation-----------------------------------// - - public long exp(long a, long b, long mod) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans; - } - - //---------------------------------------helpingmethods-------------------------------------------// - //---------------------------------------main-----------------------------------------------------// - int t, n; - - public void solve() throws IOException { - int T = sc.nextInt(); - for(int t= 1;t<=T;t++) { - int n = i(), l = i(), r= i(); - List x = new ArrayList<>(), y = new ArrayList<>(), z = new ArrayList<>(); - for(int i= 1;i=y.get(i)) break; - temp += x.get(i) - y.get(i); - } - ans = min(ans, temp); - temp= sum; - for(int i = 0;i=y.get(i)) break; - temp += z.get(i) - y.get(i); - } - ans = min(temp , ans ); - out.print(ans); - out.print(""\n""); - } - } -} -"," -/* package codechef; // don't place package name! */ - -import java.util.*; -import java.lang.*; -import java.io.*; - -public class Main { - - //------------------------------------------main--------------------------------------------------// - public static void main(String[] args) throws java.lang.Exception { - OutputStream outputStream = System.out; - PrintWriter out = new PrintWriter(outputStream); - FastReader sc = new FastReader(); - Task s = new Task(sc, out); - s.solve(); - out.close(); - // your code goes here"" - } -} - -class FastReader { - - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - public int[] readIntArray(int n) throws IOException { - int[] arr = new int[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextInt(); - } - return arr; - } - - public long[] readLongArray(int n) throws IOException { - long[] arr = new long[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextLong(); - } - return arr; - } -} - -class Task { - - PrintWriter out; - FastReader sc; - - Task(FastReader sc, PrintWriter out) { - this.sc = sc; - this.out = out; - } - //----------------------------------------------inputfunction------------------------------------------// - - String st() { - return sc.nextLine(); - } - - int i() { - return sc.nextInt(); - } - - long l() { - return sc.nextLong(); - } - - double d() { - return sc.nextDouble(); - } - - //---------------------------------------------absolute----------------------------------------------// - public long abs(long a) { - return a < 0 ? -a : a; - } - - public int abs(int a) { - return a < 0 ? -a : a; - } - - //-------------------------------------------max--------------------------------------------------// - public int max(int a, int b) { - return a >= b ? a : b; - } - - public long max(long a, long b) { - return a >= b ? a : b; - } - - public int max(int a, int b, int c) { - return Math.max(a, Math.max(b, c)); - } - - public long max(long a, long b, long c) { - return Math.max(a, Math.max(b, c)); - } - - //------------------------------------------min---------------------------------------------------// - public int min(int a, int b) { - return a <= b ? a : b; - } - - public long min(long a, long b) { - return a <= b ? a : b; - } - - public int min(int a, int b, int c) { - return Math.min(a, Math.min(b, c)); - } - - public long min(long a, long b, long c) { - return Math.min(a, Math.min(b, c)); - } - - //----------------------------------------sortingfunction---------------------------------------------// - private void sort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - //---------------------------------------power----------------------------------------------------// - - public long pow(long a, int b) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans *= a; - } - a *= a; - b >>= 1; - } - return b; - } - //----------------------------------------binary_exponentiation-----------------------------------// - - public long exp(long a, long b, long mod) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans; - } - - //---------------------------------------helpingmethods-------------------------------------------// - //---------------------------------------main-----------------------------------------------------// - int t, n; - - public void solve() throws IOException { - int T = sc.nextInt(); - for(int t= 1;t<=T;t++) { - int n = i(), l = i(), r= i(); - if(t==80){ - for(int i = 1;i<=n;i++) out.print(i()+','); - return; - } - List x = new ArrayList<>(), y = new ArrayList<>(), z = new ArrayList<>(); - for(int i= 1;i=y.get(i)) break; - temp += x.get(i) - y.get(i); - } - ans = min(ans, temp); - temp= ans; - for(int i = 0;i=y.get(i)) break; - temp += z.get(i) - y.get(i); - } - ans = min(temp , ans ); - out.print(ans); - out.print(""\n""); - } - } -} -",1 -Flemoid,2063B - Subsequence Update,c++23 ,304962273,304961251,"#include -using namespace std; - -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vll; -typedef vector vs; -typedef vector vd; -typedef vector > vvi; -typedef vector > vvll; -typedef vector > vvs; -typedef vector > vvd; -#define pb push_back -#define all(v) (v).begin(), (v).end() -#define FOR(i, a, b) for (int i = (a); i < (b); i++) -#define FORR(i, a, b) for (int i = (a); i >= (b); i--) -// #define FOR2D(i, j, n, m) for (int i = 0; i < (n); i++) for (int j = 0; j < (m); j++) -#define FOR2D(i, j, start_i, end_i, start_j, end_j) \ - for (int i = (start_i); i < (end_i); ++i) \ - for (int j = (start_j); j < (end_j); ++j) -#define FORE(item, container) for (auto &item : container) -#define FORSTEP(i, a, b, step) for (int i = (a); i < (b); i += (step)) -#define NL std::cout << ""\n"" -#define MOD 1000000007 - -void solve() -{ - int n, l, r; - cin>>n>>l>>r; - vll arr(n); - FOR(i, 0, n) { - cin>>arr[i]; - } - priority_queue pq; - priority_queue, greater > a, b; - FOR(i, l-1, r) - pq.push(arr[i]); - FOR(i, 0, l-1) - a.push(arr[i]); - FOR(i, r, n) - b.push(arr[i]); - - ll sum = 0LL; - ll minSum = LLONG_MAX; - while(!pq.empty()) { - if(a.empty()) { - sum += pq.top(); - } - else { - sum += min(a.top(), pq.top()); - a.pop(); - } - pq.pop(); - } - minSum = min(minSum, sum); - - FOR(i, l-1, r) - pq.push(arr[i]); - - sum = 0LL; - while(!pq.empty()) { - if(b.empty()) { - sum += pq.top(); - } - else { - sum += min(b.top(), pq.top()); - b.pop(); - } - pq.pop(); - } - minSum = min(minSum, sum); - - cout << minSum; - NL; -} - -int main() -{ - // #ifndef ONLINE_JUDGE - // freopen(""input.txt"", ""r"", stdin); - // freopen(""output.txt"", ""w"", stdout); - // #endif - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}","#include -using namespace std; - -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vll; -typedef vector vs; -typedef vector vd; -typedef vector > vvi; -typedef vector > vvll; -typedef vector > vvs; -typedef vector > vvd; -#define pb push_back -#define all(v) (v).begin(), (v).end() -#define FOR(i, a, b) for (int i = (a); i < (b); i++) -#define FORR(i, a, b) for (int i = (a); i >= (b); i--) -// #define FOR2D(i, j, n, m) for (int i = 0; i < (n); i++) for (int j = 0; j < (m); j++) -#define FOR2D(i, j, start_i, end_i, start_j, end_j) \ - for (int i = (start_i); i < (end_i); ++i) \ - for (int j = (start_j); j < (end_j); ++j) -#define FORE(item, container) for (auto &item : container) -#define FORSTEP(i, a, b, step) for (int i = (a); i < (b); i += (step)) -#define NL std::cout << ""\n"" -#define MOD 1000000007 - -void solve() -{ - int n, l, r; - cin>>n>>l>>r; - vi arr(n); - FOR(i, 0, n) { - cin>>arr[i]; - } - priority_queue pq; - priority_queue, greater > a, b; - FOR(i, l-1, r) - pq.push(arr[i]); - FOR(i, 0, l-1) - a.push(arr[i]); - FOR(i, r, n) - b.push(arr[i]); - - int sum = 0; - int minSum = INT_MAX; - while(!pq.empty()) { - if(a.empty()) { - sum += pq.top(); - } - else { - sum += min(a.top(), pq.top()); - a.pop(); - } - pq.pop(); - } - minSum = min(minSum, sum); - - FOR(i, l-1, r) - pq.push(arr[i]); - - sum = 0; - while(!pq.empty()) { - if(b.empty()) { - sum += pq.top(); - } - else { - sum += min(b.top(), pq.top()); - b.pop(); - } - pq.pop(); - } - minSum = min(minSum, sum); - - cout << minSum; - NL; -} - -int main() -{ - // #ifndef ONLINE_JUDGE - // freopen(""input.txt"", ""r"", stdin); - // freopen(""output.txt"", ""w"", stdout); - // #endif - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}",1 -sudaneseguy,2063B - Subsequence Update,c++17 ,304889254,304890455,"#include -using namespace std; - - -#define endl '\n' -typedef long long ll; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t; - cin>>t; - - while(t-- >0){ - - - ll s,l,r; - cin>>s>>l>>r; - vector vec(s); - for(auto &x: vec){cin>>x;} - vector pref = vec; - ll prefix=0; - sort(pref.begin(),pref.begin()+r); - - reverse(pref.begin(),pref.begin()+r); - prefix+= accumulate(pref.begin()+l-1,pref.begin()+r,0); - - vector suffix = vec; - ll suff=0; - sort(suffix.begin()+l-1,suffix.end()); - - suff=accumulate(suffix.begin()+l-1,suffix.begin()+r,0); - cout< -using namespace std; - - -#define endl '\n' -typedef long long ll; - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - ll t; - cin>>t; - - while(t-- >0){ - - - ll s,l,r; - cin>>s>>l>>r; - vector vec(s); - for(auto &x: vec){cin>>x;} - vector pref = vec; - ll prefix=0; - sort(pref.begin(),pref.begin()+r); - - reverse(pref.begin(),pref.begin()+r); - for(int i = l-1;i suffix = vec; - ll suff=0; - sort(suffix.begin()+l-1,suffix.end()); - - for(int i = l-1;i -using namespace std; -#define lowbit(x) x&(-x) -#define int long long - -int INF = 1e18; -const int N = 5e5+20; - -int n,l,r; -int lis[N]; - -void solve() { - cin>>n>>l>>r; - for(int i = 0;i>lis[i]; - sort(lis,lis+n); - - int ans = 0; - for(int i = 0;i> caset; - while (caset--) { solve(); } - - - return 0; -}","#include -using namespace std; -#define lowbit(x) x&(-x) -#define int long long - -int INF = 1e18; -const int N = 5e5+20; - -int n,l,r; -int lis[N]; -vector nl,nr,in; - -void solve() { - cin>>n>>l>>r; - for(int i = 1;i<=n;i++) cin>>lis[i]; - - nl.clear(); - nr.clear(); - in.clear(); - - for(int i = 1;i()); - sort(nr.begin(),nr.end()); - - int t1 = 0; - int t2 = 0; - for(int i = 0;i> caset; - while (caset--) { solve(); } - - - return 0; -}",2 -raunitkumarsingh9653,2063B - Subsequence Update,c++17 ,306430180,306450790,"#include -#include -#include -using namespace std; - -// Function to solve the problem -int solve(int n, vector sequence, int l, int r) { - vector copy = sequence; - sort(copy.begin(), copy.begin() + r,greater()); - sort(sequence.begin() + (l - 1), sequence.end()); - int left = 0, right = 0; - for (int i = l - 1; i < r; i++) { - left += copy[i]; - right += sequence[i]; - } - return min(left, right); -} - -int main() { - int t; - cin >> t; - - while (t-- > 0) { - int n, l, r; - cin >> n >> l >> r; - vector sequence(n); - - for (int i = 0; i < n; i++) { - cin >> sequence[i]; - } - - cout << solve(n, sequence, l, r) << endl; - } - - return 0; -} -","#include -#include -#include -using namespace std; - -// Function to solve the problem -long long solve(int n, vector sequence, int l, int r) { - vector copy = sequence; - - // Sorting first 'r' elements in descending order - sort(copy.begin(), copy.begin() + r, greater()); - - // Sorting from 'l' to 'n' in ascending order - sort(sequence.begin() + (l - 1), sequence.end()); - - long long left = 0, right = 0; // Use long long to store large sums - - for (int i = l - 1; i < r; i++) { - left += copy[i]; - right += sequence[i]; - } - - return min(left, right); -} - -int main() { - int t; - cin >> t; - - while (t-- > 0) { - int n, l, r; - cin >> n >> l >> r; - vector sequence(n); - - for (int i = 0; i < n; i++) { - cin >> sequence[i]; - } - - cout << solve(n, sequence, l, r) << endl; - } - - return 0; -} - -//#include -//#include -//#include -// -//using namespace std; -//int solve(int n, vector& sequence, int l, int r) { -// vector left_part(sequence.begin(), sequence.begin() + r); -// vector right_part(sequence.begin() + (l - 1), sequence.end()); -// sort(left_part.begin(), left_part.end(), greater()); -// sort(right_part.begin(), right_part.end()); // Ascending -// -// int left_sum = 0, right_sum = 0; -// for (int i = l - 1; i < r; i++) { -// left_sum += left_part[i]; -// right_sum += right_part[i - (l - 1)]; -// } -// -// return min(left_sum, right_sum); -//} -// -//int main() { -// int t; -// cin >> t; -// -// while (t-- > 0) { -// int n, l, r; -// cin >> n >> l >> r; -// vector sequence(n); -// -// for (int i = 0; i < n; i++) { -// cin >> sequence[i]; -// } -// -// cout << solve(n, sequence, l, r) << endl; -// } -// -// return 0; -//} -",2 -chennnnnm#,2063B - Subsequence Update,c++23 ,306537897,306538063,"#include - - - -using namespace std; - - - -const int N = 100010; - -int a[N],b[N]; - -int main(){ - - int t; scanf(""%d"",&t); - - while(t--){ - - int n,l,r,len; scanf(""%d%d%d"",&n,&l,&r); - - len = r - l + 1; - - for(int i = 0;i < n;i++){ - - scanf(""%d"",&a[i]); - - b[i] = a[i]; - - } - - sort(a,a + r); - - int ans = 0,tmp = 0; - - for(int i = 0;i < len;i++) tmp += a[i]; - - sort(b + l - 1,b + n); - - for(int i = l - 1;i < l - 1 + len;i++) ans += b[i]; - - ans = min(ans,tmp); - - printf(""%d\n"",ans); - - } - - return 0; - -}","#include - -using namespace std; - -const int N = 100010; -int a[N],b[N]; -int main(){ - int t; scanf(""%d"",&t); - while(t--){ - int n,l,r,len; scanf(""%d%d%d"",&n,&l,&r); - len = r - l + 1; - for(int i = 0;i < n;i++){ - scanf(""%d"",&a[i]); - b[i] = a[i]; - } - sort(a,a + r); - long long ans = 0,tmp = 0; - for(int i = 0;i < len;i++) tmp += a[i]; - sort(b + l - 1,b + n); - for(int i = l - 1;i < l - 1 + len;i++) ans += b[i]; - ans = min(ans,tmp); - printf(""%lld\n"",ans); - } - return 0; -}",2 -AboRady#,2063B - Subsequence Update,c++20 ,304427296,304435637,"#include - -using namespace std; - - - -void solve() - -{ - - int n, l, r; cin >> n >> l >> r; - - vector a(n), b(n); - - for(int i=0; i> a[i], b[i]=a[i]; - - sort(a.begin(), a.begin()+r-1); - - sort(b.begin()+l-1, b.end()); - - cout << min(accumulate(a.begin(), a.begin()+r-l+1, 0ll), accumulate(b.begin()+l-1, b.begin()+r, 0ll)) << '\n'; - -} - - - -int main() - -{ - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - int tc=1; cin >> tc; - - while(tc--) solve(); - -}","#include -using namespace std; - -void solve() -{ - int n, l, r; cin >> n >> l >> r; - vector a(n), b(n); - for(int i=0; i> a[i], b[i]=a[i]; - sort(a.begin(), a.begin()+r); - sort(b.begin()+l-1, b.end()); - cout << min(accumulate(a.begin(), a.begin()+r-l+1, 0ll), accumulate(b.begin()+l-1, b.begin()+r, 0ll)) << '\n'; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int tc=1; cin >> tc; - while(tc--) solve(); -}",2 -_Djhhh,2063B - Subsequence Update,java,304209617,304209806,"import java.io.*; -import java.util.*; - -/** - * @Author: _Djhhh - * @Introduction: - */ - -public class Main { - static FastReader fr = new FastReader(); - static FastWriter fw = new FastWriter(); - - public static void solve() { - int n=fr.nextInt(); - int l=fr.nextInt(); - int r=fr.nextInt(); - int[] arr = new int[n]; - int[] brr = new int[n]; - for(int i=0;i 0) solve(); - } -} - -class DSU { - int n; - int[] fa; - int[] dep; - int[] siz; - int[] edges; - boolean[] v; - DSU(int n) { - fa = new int[n]; - dep = new int[n]; - siz = new int[n]; - edges = new int[n]; - v = new boolean[n]; - for (int i = 0; i < n; i++) { - fa[i] = i; - dep[i] = 0; - siz[i] = 1; - edges[i] = 0; - v[i]=false; - } - } - int look(int x) { - if (fa[x] == x) return x; - else return fa[x] = look(fa[x]); - } - void merge(int x, int y) { - v[x]=v[y]=true; - int xx = look(x); - int yy = look(y); - if (xx == yy) return; - edges[xx] += edges[yy] + 1; - siz[xx] += siz[yy]; - if (dep[xx] < dep[yy]) { - fa[xx] = yy; - } else { - fa[yy] = xx; - } - - if (dep[xx] == dep[yy]) dep[xx]++; - } - boolean isMerge(int x, int y) { - return look(x) == look(y); - } - int getSize(int x) { - return siz[look(x)]; - } - int getEdges(int x) { - return edges[look(x)]; - } -} -class Pair { - private T1 first; - private T2 second; - - public Pair(T1 first, T2 second) { - this.first = first; - this.second = second; - } - public void setFirst(T1 first) { - this.first=first; - } - - public void setSecond(T2 second) { - this.second=second; - } - public T1 getFirst() { - return first; - } - - public T2 getSecond() { - return second; - } -} -class Algorithm { - /** - * 查找第一个大于等于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于等于 x 的位置 - */ - public static int lowBs(int[] arr, long x, int L, int R){ - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] >= x){ - res = mid; - r = mid - 1; - } - else{ - l = mid + 1; - } - } - return res; - } - - /** - * 查找第一个大于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于 x 的位置 - */ - public static int highBs(int[] arr, long x, int L, int R) { - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] > x){ - res = mid; - r = mid -1; - } - else{ - l = mid +1; - } - } - return res; - } -} -class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - int[] nextIntArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - int[] arr = new int[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Integer.parseInt(strNums[i]); - } - return arr; - } - - long[] nextLongArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - long[] arr = new long[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Long.parseLong(strNums[i]); - } - return arr; - } - - char[] nextCharArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - char[] arr = new char[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = strNums[i].charAt(0); - } - return arr; - } - - char[] StringtoChar() { - String line = nextLine(); - return line.toCharArray(); - } -} -class FastWriter { - private final PrintWriter writer; - - public FastWriter() { - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); - } - - public void print(Object object) { - writer.print(object); - } - - public void println(Object object) { - writer.println(object); - } - - public void flush() { - writer.flush(); - } -}","import java.io.*; -import java.util.*; - -/** - * @Author: _Djhhh - * @Introduction: - */ - -public class Main { - static FastReader fr = new FastReader(); - static FastWriter fw = new FastWriter(); - - public static void solve() { - int n=fr.nextInt(); - int l=fr.nextInt(); - int r=fr.nextInt(); - int[] arr = new int[n]; - int[] brr = new int[n]; - for(int i=0;i 0) solve(); - } -} - -class DSU { - int n; - int[] fa; - int[] dep; - int[] siz; - int[] edges; - boolean[] v; - DSU(int n) { - fa = new int[n]; - dep = new int[n]; - siz = new int[n]; - edges = new int[n]; - v = new boolean[n]; - for (int i = 0; i < n; i++) { - fa[i] = i; - dep[i] = 0; - siz[i] = 1; - edges[i] = 0; - v[i]=false; - } - } - int look(int x) { - if (fa[x] == x) return x; - else return fa[x] = look(fa[x]); - } - void merge(int x, int y) { - v[x]=v[y]=true; - int xx = look(x); - int yy = look(y); - if (xx == yy) return; - edges[xx] += edges[yy] + 1; - siz[xx] += siz[yy]; - if (dep[xx] < dep[yy]) { - fa[xx] = yy; - } else { - fa[yy] = xx; - } - - if (dep[xx] == dep[yy]) dep[xx]++; - } - boolean isMerge(int x, int y) { - return look(x) == look(y); - } - int getSize(int x) { - return siz[look(x)]; - } - int getEdges(int x) { - return edges[look(x)]; - } -} -class Pair { - private T1 first; - private T2 second; - - public Pair(T1 first, T2 second) { - this.first = first; - this.second = second; - } - public void setFirst(T1 first) { - this.first=first; - } - - public void setSecond(T2 second) { - this.second=second; - } - public T1 getFirst() { - return first; - } - - public T2 getSecond() { - return second; - } -} -class Algorithm { - /** - * 查找第一个大于等于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于等于 x 的位置 - */ - public static int lowBs(int[] arr, long x, int L, int R){ - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] >= x){ - res = mid; - r = mid - 1; - } - else{ - l = mid + 1; - } - } - return res; - } - - /** - * 查找第一个大于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于 x 的位置 - */ - public static int highBs(int[] arr, long x, int L, int R) { - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] > x){ - res = mid; - r = mid -1; - } - else{ - l = mid +1; - } - } - return res; - } -} -class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - int[] nextIntArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - int[] arr = new int[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Integer.parseInt(strNums[i]); - } - return arr; - } - - long[] nextLongArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - long[] arr = new long[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Long.parseLong(strNums[i]); - } - return arr; - } - - char[] nextCharArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - char[] arr = new char[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = strNums[i].charAt(0); - } - return arr; - } - - char[] StringtoChar() { - String line = nextLine(); - return line.toCharArray(); - } -} -class FastWriter { - private final PrintWriter writer; - - public FastWriter() { - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); - } - - public void print(Object object) { - writer.print(object); - } - - public void println(Object object) { - writer.println(object); - } - - public void flush() { - writer.flush(); - } -}",2 -Tioz0,2063B - Subsequence Update,c++23 ,303926407,303925525,"#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace __gnu_pbds; -using ll = long long; - -#define all(v) v.begin(), v.end() -#define left id << 1 -#define right id << 1 | 1 -#define sz(x) (int)x.size() -#define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> -#define DEBUG cout << ""TESTCASE "" << tc << "": ""; - -template -void see(T&... args) { ((cin >> args), ...);} -template -void put(T&&... args) { ((cout << args << "" ""), ...);} - -const int lg2 = 20; -const int N = 2010; -const int mod = 1e9 + 7; -const ll inf = 0x3f3f3f3f3f3f3f; - -struct chash { - static uint64_t splitmix64(uint64_t x) { - // http://xorshift.di.unimi.it/splitmix64.c - 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); - } -}; - -ll gcd(ll x, ll y) { - if (!y) return x; - return gcd(y, x % y); -} - -ll lcm(ll x, ll y) { - return (x * y) / gcd(x, y); -} - -bool cmp(pair a, pair b) { - return a.second < b.second; -} - -template -bool ckmin(T &a, T b) { - if (a > b) - return (a = b); - return 0; -} - -template -bool ckmax(T &a, T b) { - if (a < b) - return (a = b); - return 0; -} - -ll binpow(ll a, ll b) { - ll res = 1; - while (b) { - if (b & 1) - res *= a; - b >>= 1; - a *= a; - } - return res; -} - -void add(ll &a, ll b) { - a += b; - if (a >= mod) - a -= mod; -} - -void sub(ll &a, ll b) { - a -= b; - if (a < 0) - a += mod; -} - -void solve() { - int n, l, r; see(n, l, r); - vector a(n); - for (int &e: a) cin >> e; - vector x(a.begin(), a.begin() + r); - vector y(a.begin() + l - 1, a.end()); - sort(all(x)); sort(all(y)); - int cnt = r - l + 1; - cout << min(accumulate(x.begin(), x.begin() + cnt, 0ll), accumulate(y.begin(), y.begin() + cnt, 0ll)) << '\n'; -} - -/* - -*/ - -int32_t main() { - - // if (fopen(""input.inp"", ""r"")) { - // freopen(""input.inp"", ""r"", stdin); - // freopen(""output.out"", ""w"", stdout); - // } - - ios::sync_with_stdio(NULL); - cin.tie(0); cout.tie(0); - - - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - - return 0; -} - -/* - nice bin string - 1 must go with 0 - 0 must go with 1 - */","#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace __gnu_pbds; -using ll = long long; - -#define all(v) v.begin(), v.end() -#define left id << 1 -#define right id << 1 | 1 -#define sz(x) (int)x.size() -#define ordered_set tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> -#define DEBUG cout << ""TESTCASE "" << tc << "": ""; - -template -void see(T&... args) { ((cin >> args), ...);} -template -void put(T&&... args) { ((cout << args << "" ""), ...);} - -const int lg2 = 20; -const int N = 2010; -const int mod = 1e9 + 7; -const ll inf = 0x3f3f3f3f3f3f3f; - -struct chash { - static uint64_t splitmix64(uint64_t x) { - // http://xorshift.di.unimi.it/splitmix64.c - 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); - } -}; - -ll gcd(ll x, ll y) { - if (!y) return x; - return gcd(y, x % y); -} - -ll lcm(ll x, ll y) { - return (x * y) / gcd(x, y); -} - -bool cmp(pair a, pair b) { - return a.second < b.second; -} - -template -bool ckmin(T &a, T b) { - if (a > b) - return (a = b); - return 0; -} - -template -bool ckmax(T &a, T b) { - if (a < b) - return (a = b); - return 0; -} - -ll binpow(ll a, ll b) { - ll res = 1; - while (b) { - if (b & 1) - res *= a; - b >>= 1; - a *= a; - } - return res; -} - -void add(ll &a, ll b) { - a += b; - if (a >= mod) - a -= mod; -} - -void sub(ll &a, ll b) { - a -= b; - if (a < 0) - a += mod; -} - -void solve() { - int n, l, r; see(n, l, r); - vector a(n); - for (int &e: a) cin >> e; - sort(all(a)); - ll sum = 0; - for (int i = 0; i < r - l + 1; ++i) { - sum += a[i]; - } - cout << sum << '\n'; -} - -/* - -*/ - -int32_t main() { - - // if (fopen(""input.inp"", ""r"")) { - // freopen(""input.inp"", ""r"", stdin); - // freopen(""output.out"", ""w"", stdout); - // } - - ios::sync_with_stdio(NULL); - cin.tie(0); cout.tie(0); - - - int tc = 1; - cin >> tc; - while (tc--) { - solve(); - } - - return 0; -} - -/* - nice bin string - 1 must go with 0 - 0 must go with 1 - */",1 -Zeph340,2063B - Subsequence Update,java,304054988,304054556,"import java.io.*; -import java.util.*; - -public class TestCodeforces -{ - public static void main(String[] args) - { - FastReader fr = new FastReader(); - PrintWriter pw = new PrintWriter(System.out); - int t = fr.nextInt(); - while(t-->0) - { - int n = fr.nextInt(); - int l = fr.nextInt(); - int r = fr.nextInt(); - int wnd = r-l+1; - long arr[] = new long[n]; - for(int i=0; i0) - { - int n = fr.nextInt(); - int l = fr.nextInt(); - int r = fr.nextInt(); - int wnd = r-l+1; - int arr[] = new int[n]; - for(int i=0; i -using namespace std; -typedef long long ll; -#define pp make_pair -#define endl ""\n"" -#define f first -#define s second -#define TxtIO freopen(""input.txt"",""r"",stdin); freopen(""output.txt"",""w"",stdout); -#define int long long -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t ;cin>>t; - while (t--) - { - int n,l,r ; cin>>n>>l>>r; - l--;r--; - vector v(n); - for (int i = 0 ; i>v[i]; - sort(v.begin(),v.end()); - int ans=0; - for (int i = 0;i -using namespace std; -typedef long long ll; -#define pp make_pair -#define endl ""\n"" -#define f first -#define s second -#define TxtIO freopen(""input.txt"",""r"",stdin); freopen(""output.txt"",""w"",stdout); -#define int long long - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t ;cin>>t; - while (t--) - { - int n,l,r ; cin>>n>>l>>r; - l--;r--; - vector v(n); - for (int i = 0 ; i>v[i]; - - vector v1; - vector v2; - - for (int i = l; i<=r;i++) { - v1.push_back(v[i]); - v2.push_back(v[i]); - } - - for (int i = 0 ;i>n>>l>>r ; -vectorv(n); -for(auto &a : v) cin>>a ; -sort(v.begin(),v.end()); -ll ans = 0 ; -for(int i = 0 ; i < r-l+1 ; i++){ - ans += v[i]; -} -cout<>t ; - while(t--){ - akibify(); - - - } - - - return 0; -}","#include""bits/stdc++.h"" -using namespace std; - -#define YES cout<<""YES\n"" -#define NO cout<<""NO\n"" -#define endl ""\n"" -#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) - -typedef long long ll; -const int MOD = 1000000007; -const int Nmax = 2e5+5; - -void akibify(){ -ll n,l,r ; -cin>>n>>l>>r ; -vectorv(n); -vectorlv,rv; -for(auto &a : v) cin>>a ; - -for(int i = 0 ; i < r ; i++) lv.push_back(v[i]); -for(int i = l-1 ; i < n ; i++) rv.push_back(v[i]); -sort(lv.begin(),lv.end()); -sort(rv.begin(),rv.end()); -ll suml=0,sumr = 0; -for(int i = 0 ; i < r-l+1 ; i++) suml+=lv[i]; -for(int i = 0 ; i < r-l+1 ; i++) sumr+=rv[i]; -ll ans = min(suml,sumr) ; - -cout<>t ; - while(t--){ - akibify(); - - - } - - - return 0; -}",2 -rushilrmalode,2063B - Subsequence Update,c++17 ,304310523,304306212,"#include - - - -using namespace std; - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n,l,r; - - cin>>n>>l>>r; - - vectora(n); - - for(auto &x:a) - - cin>>x; - - long long sum=0; - - for(int i=l-1;i<=r-1;i++) - - { - - sum+=a[i]; - - } - - if(r1) - - { - - sort(a.begin()+l-1,a.begin()+r); - - sort(a.begin(),a.begin()+l-1); - - sort(a.begin()+r,a.end()); - - long long lsum=sum,rsum=sum; - - int xl=r,yl=r-1; - - while(xl=l-1 && a[xl]=l-1 && a[xr]=0 && a[x]1) - - { - - sort(a.begin()+l-1,a.begin()+r); - - sort(a.begin(),a.begin()+l-1); - - int x=0,y=r-1; - - while(x=l-1 && a[x] - - - -using namespace std; - - - -int main() - -{ - - int t; - - cin>>t; - - while(t--) - - { - - int n,l,r; - - cin>>n>>l>>r; - - vectora(n); - - for(auto &x:a) - - cin>>x; - - long long sum=0; - - for(int i=l-1;i<=r-1;i++) - - { - - sum+=a[i]; - - } - - if(r1) - - { - - sort(a.begin()+l-1,a.begin()+r-1); - - sort(a.begin(),a.begin()+l-2); - - sort(a.begin()+r,a.end()); - - long long lsum=sum,rsum=sum; - - int xl=r,yl=r-1; - - while(xl=l-1 && a[xl]=l-1 && a[xr]=0 && a[x]1) - - { - - sort(a.begin()+l-1,a.begin()+r-1); - - sort(a.begin(),a.begin()+l-2); - - int x=0,y=r-1; - - while(x=l-1 && a[x] - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -int64_t min_sum(const vector& lr, const vector& other) { - - int64_t diff = 0; - - - - for (int i = 0; i < min(lr.size(), other.size()); i++) { - - // cout << ""loop: "" << other[i] << "" "" << lr[i] << endl; - - if (other[i] < lr[i]) diff += (lr[i] - other[i]); - - } - - // cout << diff << endl; - - return diff; - -} - -void solve() { - - // Read input - - int n, l, r; - - cin >> n >> l >> r; - - l--; r--; - - vector a(n); - - for (int i = 0; i < n; ++i) { - - cin >> a[i]; - - } - - - - // Solve the problem here - - vector lr; - - for (int i = l; i <= r; i++) { - - lr.push_back(a[i]); - - } - - sort(lr.begin(), lr.end(), std::greater()); - - - - int64_t sum = accumulate(lr.begin(), lr.end(), 0); - - // cout << sum << endl; - - vector bl; - - for (int i = 0; i < l; i++) { - - bl.push_back(a[i]); - - } - - sort(bl.begin(), bl.end()); - - - - vector ar; - - for (int i = r + 1; i < n; i++) { - - ar.push_back(a[i]); - - } - - sort(ar.begin(), ar.end()); - - - - sum = min(sum, sum - min_sum(lr, bl)); - - sum = min(sum, sum - min_sum(lr, ar)); - - // Print output - - cout << sum << endl; - -} - - - -int main() { - - // freopen(""input.txt"",""r"",stdin),freopen(""output.txt"",""w"",stdout); - - - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout << setprecision(10); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -using namespace std; - - - -int64_t min_sum(const vector& lr, const vector& other) { - - int64_t diff = 0; - - - - for (int i = 0; i < min(lr.size(), other.size()); i++) { - - // cout << ""loop: "" << other[i] << "" "" << lr[i] << endl; - - if (other[i] < lr[i]) diff += (lr[i] - other[i]); - - } - - // cout << diff << endl; - - return diff; - -} - -void solve() { - - // Read input - - int n, l, r; - - cin >> n >> l >> r; - - l--; r--; - - vector a(n); - - for (int i = 0; i < n; ++i) { - - cin >> a[i]; - - } - - - - // Solve the problem here - - vector lr; - - for (int i = l; i <= r; i++) { - - lr.push_back(a[i]); - - } - - sort(lr.begin(), lr.end(), std::greater()); - - - - int64_t sum = accumulate(lr.begin(), lr.end(), int64_t(0)); - - // cout << sum << endl; - - vector bl; - - for (int i = 0; i < l; i++) { - - bl.push_back(a[i]); - - } - - sort(bl.begin(), bl.end()); - - - - vector ar; - - for (int i = r + 1; i < n; i++) { - - ar.push_back(a[i]); - - } - - sort(ar.begin(), ar.end()); - - - - sum = min(min(sum, sum - min_sum(lr, bl)), sum - min_sum(lr, ar)); - - // Print output - - cout << sum << endl; - -} - - - -int main() { - - // freopen(""input.txt"",""r"",stdin),freopen(""output.txt"",""w"",stdout); - - - - ios_base::sync_with_stdio(false); - - cin.tie(nullptr); - - cout << setprecision(10); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - - - - return 0; - -}",2 -ashishgangwar,2063B - Subsequence Update,c++20 ,304735426,304739383,"#include -using namespace std; -typedef long long ll; -int main() -{ - int test; - cin>>test; - while(test--) - { - int n,l,r; - cin>>n>>l>>r; - vector vec(n); - for(int i=0;i>vec[i]; - ll sum1=0,sum2=0; - vector vec2(n); - for(int i=0;i -using namespace std; -typedef long long ll; -int main() -{ - int test; - cin>>test; - while(test--) - { - int n,l,r; - cin>>n>>l>>r; - vector vec(n); - for(int i=0;i>vec[i]; - ll sum1=0,sum2=0; - vector vec2 =vec; - sort(vec.begin(),vec.begin()+r); - sort(vec2.begin()+l-1,vec2.end()); - for(int i=0;i -#define ll long long int -#define pb push_back -#define _mp make_pair -#define vt vector -#define MAXN 200002 -using namespace std; -typedef long long LL; -ll mod=1e9+7; -// f[0]=f[1]=inv[0]=inv[1]=1; -// for(int i=2;i v1, pair v2) -// { -// if(v1.first==v2.first)return v1.second>v2.second; -// return v1.first maxSubArraySum(vector&a, int size) -{ - ll max_so_far = 0, max_ending_here = 0; - int num=0,mx_len=0; - for (int i = 0; i < size; i++) { - max_ending_here = (max_ending_here + a[i]); - num++; - if (max_so_far < max_ending_here) - {max_so_far = max_ending_here;mx_len=num;} - else{ - max_ending_here=0;num=0; - } - } - if(mx_len==size)max_so_far=0; - return {max_so_far,mx_len}; -} -bool isPrime(ll N){ - int flag = 1; - - double sqroot = sqrt(N); - - // Iterate from 2 to sqrt(n) - for (int i = 2; i <= sqroot; i++) { - - // If n is divisible by any number between 2 and - // sqrt(n), it is not prime - if (N % i == 0) { - flag = 0; - break; - } - } - return flag; -} -void rev(int start,int ind,int end,vt&vec){ -int val=ind+1; -while(val>0){ - for(int i=start;ia,pairb){ - if(a.second& arr, int l, int m, int r) { - - // Counts in two subarrays - int n1 = m - l + 1, n2 = r - m; - - // Set up two vectors for left and right halves - vector left(n1), right(n2); - for (int i = 0; i < n1; i++) - left[i] = arr[i + l]; - for (int j = 0; j < n2; j++) - right[j] = arr[m + 1 + j]; - - // Initialize inversion count (or result) and merge two halves - int res = 0; - int i = 0, j = 0, k = l; - while (i < n1 && j < n2) { - - // No increment in inversion count if left[] has a - // smaller or equal element - if (left[i] <= right[j]) - arr[k++] = left[i++]; - - // If right is smaller, then it is smaller than n1-i - // elements because left[] is sorted - else { - arr[k++] = right[j++]; - res += (n1 - i); - } - } - - // Merge remaining elements - while (i < n1) - arr[k++] = left[i++]; - while (j < n2) - arr[k++] = right[j++]; - - return res; -} - -// Function to count inversions in the array -ll countInv(vector& arr, int l, int r){ - ll res = 0; - if (l < r) { - int m = (r + l) / 2; - - // Recursively count inversions in the left and - // right halves - res += countInv(arr, l, m); - res += countInv(arr, m + 1, r); - - // Count inversions such that greater element is in - // the left half and smaller in the right half - res += countAndMerge(arr, l, m, r); - } - return res; -} - -ll inversionCount(vector& arr) { - int n = arr.size(); - return countInv(arr, 0, n-1); -} -ll p(ll x,ll y){ - if(y==0)return 1; - if(y==1)return x; - ll z=p(x,y/2); - ll r=(z*z)%(998244353); - if(y%2)r=(r*x)%(998244353); - return r; -} -void _solve1() -{ - int t;cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - vtv(n); - for(int i=0;i>v[i]; - sort(v.begin(),v.end()); - ll sum=0; - for(int i=0;i<(r-l+1);i++)sum+=v[i]; - cout< - -#define ll long long int - -#define pb push_back - -#define _mp make_pair - -#define vt vector - -#define MAXN 200002 - -using namespace std; - -typedef long long LL; - -ll mod=1e9+7; - -// f[0]=f[1]=inv[0]=inv[1]=1; - -// for(int i=2;i v1, pair v2) - -// { - -// if(v1.first==v2.first)return v1.second>v2.second; - -// return v1.first maxSubArraySum(vector&a, int size) - -{ - - ll max_so_far = 0, max_ending_here = 0; - - int num=0,mx_len=0; - - for (int i = 0; i < size; i++) { - - max_ending_here = (max_ending_here + a[i]); - - num++; - - if (max_so_far < max_ending_here) - - {max_so_far = max_ending_here;mx_len=num;} - - else{ - - max_ending_here=0;num=0; - - } - - } - - if(mx_len==size)max_so_far=0; - - return {max_so_far,mx_len}; - -} - -bool isPrime(ll N){ - - int flag = 1; - - - - double sqroot = sqrt(N); - - - - // Iterate from 2 to sqrt(n) - - for (int i = 2; i <= sqroot; i++) { - - - - // If n is divisible by any number between 2 and - - // sqrt(n), it is not prime - - if (N % i == 0) { - - flag = 0; - - break; - - } - - } - - return flag; - -} - -void rev(int start,int ind,int end,vt&vec){ - -int val=ind+1; - -while(val>0){ - - for(int i=start;ia,pairb){ - - if(a.second& arr, int l, int m, int r) { - - - - // Counts in two subarrays - - int n1 = m - l + 1, n2 = r - m; - - - - // Set up two vectors for left and right halves - - vector left(n1), right(n2); - - for (int i = 0; i < n1; i++) - - left[i] = arr[i + l]; - - for (int j = 0; j < n2; j++) - - right[j] = arr[m + 1 + j]; - - - - // Initialize inversion count (or result) and merge two halves - - int res = 0; - - int i = 0, j = 0, k = l; - - while (i < n1 && j < n2) { - - - - // No increment in inversion count if left[] has a - - // smaller or equal element - - if (left[i] <= right[j]) - - arr[k++] = left[i++]; - - - - // If right is smaller, then it is smaller than n1-i - - // elements because left[] is sorted - - else { - - arr[k++] = right[j++]; - - res += (n1 - i); - - } - - } - - - - // Merge remaining elements - - while (i < n1) - - arr[k++] = left[i++]; - - while (j < n2) - - arr[k++] = right[j++]; - - - - return res; - -} - - - -// Function to count inversions in the array - -ll countInv(vector& arr, int l, int r){ - - ll res = 0; - - if (l < r) { - - int m = (r + l) / 2; - - - - // Recursively count inversions in the left and - - // right halves - - res += countInv(arr, l, m); - - res += countInv(arr, m + 1, r); - - - - // Count inversions such that greater element is in - - // the left half and smaller in the right half - - res += countAndMerge(arr, l, m, r); - - } - - return res; - -} - - - -ll inversionCount(vector& arr) { - - int n = arr.size(); - - return countInv(arr, 0, n-1); - -} - -ll p(ll x,ll y){ - - if(y==0)return 1; - - if(y==1)return x; - - ll z=p(x,y/2); - - ll r=(z*z)%(998244353); - - if(y%2)r=(r*x)%(998244353); - - return r; - -} - -void _solve1() - -{ - - int t;cin>>t; - - while(t--){ - - int n,l,r; - - cin>>n>>l>>r; - - vtv(n); - - for(int i=0;i>v[i]; - - vts1,s2,s3; - - for(int i=0;iprea(s1.size()+1,0); - - vtpreb(s2.size()+1,0); - - vtprec(s3.size()+1,0); - - for(int i=1;i -#define ll long long -using namespace std; -ll log_2(ll n) { - if(n==0) { - return -1; - } - ll pos=0; - ll bitPos=-1; - while(n>0) { - if(n&1) { - bitPos=pos; - } - n=n>>1; - pos++; - } - return bitPos; -} -ll MEX(vector &a) { - std::unordered_set s(a.begin(), a.end()); - ll mex=0; - while(s.find(mex)!=s.end()) { - mex++; - } - return mex; -} -int binarySearch(vector &arr, int l, int r, int x) { - while(l<=r) { - int m=l+((r-l)/2); - if(arr[m]==x) { - return m; - } - if(arr[m] &a) { - int n=a.size(); - int ct=0; - for(int i=0; ia[(i+1)%n]) { - ct++; - } - } - return ct<=1; -} -ll GCD(vector &a) { - int n=a.size(); - ll gcd=0; - for(int i=0; i a) { - ll lcm=a[0]; - for(int i=1; i a, int size) { - for(int i=1; ia[i]) { - return false; - } - } - return true; -} -ll factorial(int n) { - vector f(n+1); - f[0]=1; - f[1]=1; - for(int i=2; i<=n; i++) { - f[i]=f[i-1]*i; - } - return f[n]; -} -// int dfs(vector> &a, vector> &vis, int i, int j) { -// int n=a.size(), m=a[0].size(); -// vis[i][j]=1; -// int ans=a[i][j]; -// if(i && a[i-1][j] && !vis[i-1][j]) { -// ans+=dfs(a, vis, i-1, j); -// } -// if(i!=n-1 && a[i+1][j] && !vis[i+1][j]) { -// ans+=dfs(a, vis, i+1, j); -// } -// if(j && a[i][j-1] && !vis[i][j-1]) { -// ans+=dfs(a, vis, i, j-1); -// } -// if(j!=m-1 && a[i][j+1] && !vis[i][j+1]) { -// ans+=dfs(a, vis, i, j+1); -// } -// return ans; -// } -// const int NMAX=2e5+5; -// int dp[NMAX], id[NMAX]; -// vector> edg[NMAX]; -// void dfs(int u) { -// for(auto it : edg[u]) { -// if(dp[it.first]==0) { -// dp[it.first]=dp[u]+(it.second<=id[u]); -// id[it.first]=it.second; -// dfs(it.first); -// } -// } -// } -ll sumOfDigits(ll n) { - ll sum=0; - while(n) { - sum+=(n%10); - n/=10; - } - return sum; -} -ll flips(vector &a) { - ll n=a.size(); - ll ct=0, ans=0; - for(int i=n-1; i>=0; i--) { - if(!a[i]) { - ct++; - } else { - ans+=ct; - } - } - return ans; -} -const ll mod=1e9+7; -bool is_square(ll n) { - ll l=1, r=3037000500, mid; - while(r-l>1) { - mid=(l+r)/2; - ll x=mid*mid; - if(x<=n) { - l=mid; - } else { - r=mid; - } - } - return (l*l==n); -} -ll power(ll a, ll b) { - ll ans=1; - while(b) { - if(b%2) { - ans*=a; - } - a*=a; - b/=2; - } - return ans; -} -ll powmod(ll a, ll b, ll mod) { - ll ans=1; - a%=mod; - while(b) { - if(b%2) { - ans=(a*ans)%mod; - } - a=(a*a)%mod; - b/=2; - } - return ans; -} -ll factmod(ll n, ll mod) { - ll ans=1; - while(n) { - ans=(ans*(n--))%mod; - } - return ans; -} -ll ncrmod(ll n, ll r, ll mod) { - return (((factmod(n, mod)*powmod(factmod(r, mod), mod-2, mod))%mod)*powmod(factmod(n-r, mod), mod-2, mod))%mod; -} -// ll score(vector &p, vector &a, int s, int k) { -// int n=p.size(); -// ll mx=0, cur=0; -// vector vis(n, 0); -// while(!vis[s] && k>0) { -// vis[s]=1; -// mx=max(mx, cur+(1ll*k*a[s])); -// cur+=a[s]; -// k--; -// s=p[s]; -// } -// return mx; -// } -// void add_divs(int x, map &mp) { -// int i=2; -// while(i*i<=x) { -// while(x%i==0) { -// mp[i]++; -// x/=i; -// } -// i++; -// } -// if(x>1) { -// mp[x]++; -// } -// } -// int getPos(vector &dp, int n, int pos) { -// if(pos>n) { -// return n+1; -// } -// if(pos==n) { -// return 0; -// } -// return dp[pos]; -// } -// const int N=200003; -// const int M=30; -// int pf[N][M]; -// int a[N]; -// void Buildprefix(int n) { -// for(int i=0; i> g, vector ct) { -// if(g[v].size()==1 && g[v][0]==p) { -// ct[v]=1; -// } else { -// for(auto u : g[v]) { -// if(u!=p) { -// dfs(u, v, g, ct); -// ct[v]+=ct[u]; -// } -// } -// } -// } -bool helper(const string &s, const string &t) { - int i=0, j=0; - while(i &a, int ind) { - vector c; - for(int i=0; i1) { - ll q=a/m; - ll t=m; - m=a%m; - a=t; - t=y; - y=x-q*y; - x=t; - } - if(x<0) { - x+=m0; - } - return x; -} -int calcFib(int a1, int a2, int a3, int a4, int a5) { - int ct=0; - if(a4==a3+a2) { - ct++; - } - if(a3==a2+a1) { - ct++; - } - if(a5==a4+a3) { - ct++; - } - return ct; -} -void solve() { - // int a, b; - // cin>>a>>b; - // if(abs(a)==abs(b)) { - // cout<<2*(abs(a))<>n; - // vector b(n); - // int l=0, u=0; - // for(int i=0; i>b[i]; - // if(b[i]>0) { - // l++; - // } else { - // u++; - // } - // } - // for(int i=1; i<=n; i++) { - // if(i<=l) { - // cout<>n; - // string s; - // cin>>s; - // for(int i=0; i'A' && s[i]<'Z') { - // s[i]='a'+s[i]-'A'; - // } - // } - // s.erase(unique(s.begin(), s.end()), s.end()); - // cout<<(s==""meow"" ? ""yes"" : ""no"")<>n; - // vector a(n), b(n); - // // int maxA=INT_MIN, maxB=INT_MIN; - // for(int i=0; i>a[i]; - // // maxA=max(maxA, a[i]); - // } - // for(int i=0; i>b[i]; - // // maxB=max(maxB, b[i]); - // } - // for(int i=0; ia[n-1] || b[i]>b[n-1]) { - // int temp=a[i]; - // a[i]=b[i]; - // b[i]=temp; - // } - // } - // int ans=1; - // for(int i=0; ia[n-1] || b[i]>b[n-1]) { - // ans=0; - // break; - // } - // } - // if(ans) { - // cout<<""yes""<>k; - // string s; - // cin>>s; - // string ref=""""; - // for(int i=1; i<=100; i++) { - // if(i%3==0) { - // ref+='F'; - // } - // if(i%5==0) { - // ref+='B'; - // } - // } - // int x=ref.find(s); - // if(x!=string::npos) { - // cout<<""yes""<>n>>m; - // string s, t; - // cin>>s>>t; - // reverse(t.begin(), t.end()); - // s+=t; - // int ct=0; - // for(int i=1; i>n; - // vector a(2*(n-1)); - // vector ans; - // for(int i=0; i<(2*(n-1)); i++) { - // cin>>a[i]; - // if(a[i].length()==n-1) { - // ans.push_back(a[i]); - // } - // } - // reverse(ans[0].begin(), ans[0].end()); - // if(ans[0]==ans[1]) { - // cout<<""yes""<>a>>b; - // ll n, m; - // cin>>n>>m; - // ll q=n/(m+1), r=n-(q*(m+1)); - // cout<<(q*min(a*m, b*(m+1)))+(r*min(a, b))<>n; - // vector h(n); - // int ct=0; - // for(int i=0; i>h[i]; - // if(h[i]==1) { - // ct++; - // } - // } - // cout<<(ct/2)+(n-ct)+(ct%2)<>n>>a>>b; - // string s; - // cin>>s; - // int ans=0; - // int x=0, y=0; - // for(int i=0; i<100; i++) { - // for(char c : s) { - // if(c=='N') { - // y++; - // } else if(c=='S') { - // y--; - // } else if(c=='E') { - // x++; - // } else { - // x--; - // } - // if(x==a && y==b) { - // ans=1; - // break; - // } - // } - // } - // if(ans) { - // cout<<""yes""<>n>>b>>c; - // if(!b) { - // if(c>=n) { - // cout<=n-2) { - // cout<=n) { - // cout<>n; - // cout<>s; - // for(int i=0; i>n>>a>>b; - // if(a%2==b%2) { - // cout<<""yes""<>n; - // vector a(n), b(n); - // for(int i=0; i>a[i]; - // } - // int ok=-1, mini=1e9, req=0; - // bool ans=false; - // for(int i=0; i>b[i]; - // if(a[i]=req) ? ""yes"" : ""no"")<>n>>m; - // vector> cards(n, vector (m)); - // for(int i=0; i>cards[i][j]; - // } - // sort(cards[i].begin(), cards[i].end()); - // } - // vector ind(n); - // for(int i=0; i>n>>k; - // vector x(n); - // unordered_map mp; - // for(int i=0; i>x[i]; - // mp[x[i]]++; - // } - // int score=0; - // for(auto it=mp.begin(); it!=mp.end(); it++) { - // int num=it->first; - // int comp=k-num; - // if(mp[num]>0) { - // if(num==comp) { - // score+=mp[num]/2; - // mp[num]%=2; - // } else if(mp.count(comp)) { - // int pairs=min(mp[num], mp[comp]); - // score+=pairs; - // mp[num]-=pairs; - // mp[comp]-=pairs; - // } - // } - // } - // cout<>n; - // vector a(n); - // for(int i=0; i>a[i]; - // } - // bool ans=true; - // for(int i=1; i>s; - // int ans=0; - // for(int i=0; i>n; - // vector a(n); - // bool ans=true; - // for(int i=0; i>a[i]; - // } - // for(int i=0; i>l>>r; - // if(l==r && l==1) { - // cout<<1<>n>>l>>r; - l--; - r--; - vector a(n); - for(int i=0; i>a[i]; - } - int x=r-l+1; - vector v1, v2; - for(int i=0; i<=r; i++) { - v1.push_back(a[i]); - } - for(int i=l; i>t; - while(t--) { - solve(); - } - return 0; -}","#include -#define ll long long -using namespace std; -ll log_2(ll n) { - if(n==0) { - return -1; - } - ll pos=0; - ll bitPos=-1; - while(n>0) { - if(n&1) { - bitPos=pos; - } - n=n>>1; - pos++; - } - return bitPos; -} -ll MEX(vector &a) { - std::unordered_set s(a.begin(), a.end()); - ll mex=0; - while(s.find(mex)!=s.end()) { - mex++; - } - return mex; -} -int binarySearch(vector &arr, int l, int r, int x) { - while(l<=r) { - int m=l+((r-l)/2); - if(arr[m]==x) { - return m; - } - if(arr[m] &a) { - int n=a.size(); - int ct=0; - for(int i=0; ia[(i+1)%n]) { - ct++; - } - } - return ct<=1; -} -ll GCD(vector &a) { - int n=a.size(); - ll gcd=0; - for(int i=0; i a) { - ll lcm=a[0]; - for(int i=1; i a, int size) { - for(int i=1; ia[i]) { - return false; - } - } - return true; -} -ll factorial(int n) { - vector f(n+1); - f[0]=1; - f[1]=1; - for(int i=2; i<=n; i++) { - f[i]=f[i-1]*i; - } - return f[n]; -} -// int dfs(vector> &a, vector> &vis, int i, int j) { -// int n=a.size(), m=a[0].size(); -// vis[i][j]=1; -// int ans=a[i][j]; -// if(i && a[i-1][j] && !vis[i-1][j]) { -// ans+=dfs(a, vis, i-1, j); -// } -// if(i!=n-1 && a[i+1][j] && !vis[i+1][j]) { -// ans+=dfs(a, vis, i+1, j); -// } -// if(j && a[i][j-1] && !vis[i][j-1]) { -// ans+=dfs(a, vis, i, j-1); -// } -// if(j!=m-1 && a[i][j+1] && !vis[i][j+1]) { -// ans+=dfs(a, vis, i, j+1); -// } -// return ans; -// } -// const int NMAX=2e5+5; -// int dp[NMAX], id[NMAX]; -// vector> edg[NMAX]; -// void dfs(int u) { -// for(auto it : edg[u]) { -// if(dp[it.first]==0) { -// dp[it.first]=dp[u]+(it.second<=id[u]); -// id[it.first]=it.second; -// dfs(it.first); -// } -// } -// } -ll sumOfDigits(ll n) { - ll sum=0; - while(n) { - sum+=(n%10); - n/=10; - } - return sum; -} -ll flips(vector &a) { - ll n=a.size(); - ll ct=0, ans=0; - for(int i=n-1; i>=0; i--) { - if(!a[i]) { - ct++; - } else { - ans+=ct; - } - } - return ans; -} -const ll mod=1e9+7; -bool is_square(ll n) { - ll l=1, r=3037000500, mid; - while(r-l>1) { - mid=(l+r)/2; - ll x=mid*mid; - if(x<=n) { - l=mid; - } else { - r=mid; - } - } - return (l*l==n); -} -ll power(ll a, ll b) { - ll ans=1; - while(b) { - if(b%2) { - ans*=a; - } - a*=a; - b/=2; - } - return ans; -} -ll powmod(ll a, ll b, ll mod) { - ll ans=1; - a%=mod; - while(b) { - if(b%2) { - ans=(a*ans)%mod; - } - a=(a*a)%mod; - b/=2; - } - return ans; -} -ll factmod(ll n, ll mod) { - ll ans=1; - while(n) { - ans=(ans*(n--))%mod; - } - return ans; -} -ll ncrmod(ll n, ll r, ll mod) { - return (((factmod(n, mod)*powmod(factmod(r, mod), mod-2, mod))%mod)*powmod(factmod(n-r, mod), mod-2, mod))%mod; -} -// ll score(vector &p, vector &a, int s, int k) { -// int n=p.size(); -// ll mx=0, cur=0; -// vector vis(n, 0); -// while(!vis[s] && k>0) { -// vis[s]=1; -// mx=max(mx, cur+(1ll*k*a[s])); -// cur+=a[s]; -// k--; -// s=p[s]; -// } -// return mx; -// } -// void add_divs(int x, map &mp) { -// int i=2; -// while(i*i<=x) { -// while(x%i==0) { -// mp[i]++; -// x/=i; -// } -// i++; -// } -// if(x>1) { -// mp[x]++; -// } -// } -// int getPos(vector &dp, int n, int pos) { -// if(pos>n) { -// return n+1; -// } -// if(pos==n) { -// return 0; -// } -// return dp[pos]; -// } -// const int N=200003; -// const int M=30; -// int pf[N][M]; -// int a[N]; -// void Buildprefix(int n) { -// for(int i=0; i> g, vector ct) { -// if(g[v].size()==1 && g[v][0]==p) { -// ct[v]=1; -// } else { -// for(auto u : g[v]) { -// if(u!=p) { -// dfs(u, v, g, ct); -// ct[v]+=ct[u]; -// } -// } -// } -// } -bool helper(const string &s, const string &t) { - int i=0, j=0; - while(i &a, int ind) { - vector c; - for(int i=0; i1) { - ll q=a/m; - ll t=m; - m=a%m; - a=t; - t=y; - y=x-q*y; - x=t; - } - if(x<0) { - x+=m0; - } - return x; -} -int calcFib(int a1, int a2, int a3, int a4, int a5) { - int ct=0; - if(a4==a3+a2) { - ct++; - } - if(a3==a2+a1) { - ct++; - } - if(a5==a4+a3) { - ct++; - } - return ct; -} -void solve() { - // int a, b; - // cin>>a>>b; - // if(abs(a)==abs(b)) { - // cout<<2*(abs(a))<>n; - // vector b(n); - // int l=0, u=0; - // for(int i=0; i>b[i]; - // if(b[i]>0) { - // l++; - // } else { - // u++; - // } - // } - // for(int i=1; i<=n; i++) { - // if(i<=l) { - // cout<>n; - // string s; - // cin>>s; - // for(int i=0; i'A' && s[i]<'Z') { - // s[i]='a'+s[i]-'A'; - // } - // } - // s.erase(unique(s.begin(), s.end()), s.end()); - // cout<<(s==""meow"" ? ""yes"" : ""no"")<>n; - // vector a(n), b(n); - // // int maxA=INT_MIN, maxB=INT_MIN; - // for(int i=0; i>a[i]; - // // maxA=max(maxA, a[i]); - // } - // for(int i=0; i>b[i]; - // // maxB=max(maxB, b[i]); - // } - // for(int i=0; ia[n-1] || b[i]>b[n-1]) { - // int temp=a[i]; - // a[i]=b[i]; - // b[i]=temp; - // } - // } - // int ans=1; - // for(int i=0; ia[n-1] || b[i]>b[n-1]) { - // ans=0; - // break; - // } - // } - // if(ans) { - // cout<<""yes""<>k; - // string s; - // cin>>s; - // string ref=""""; - // for(int i=1; i<=100; i++) { - // if(i%3==0) { - // ref+='F'; - // } - // if(i%5==0) { - // ref+='B'; - // } - // } - // int x=ref.find(s); - // if(x!=string::npos) { - // cout<<""yes""<>n>>m; - // string s, t; - // cin>>s>>t; - // reverse(t.begin(), t.end()); - // s+=t; - // int ct=0; - // for(int i=1; i>n; - // vector a(2*(n-1)); - // vector ans; - // for(int i=0; i<(2*(n-1)); i++) { - // cin>>a[i]; - // if(a[i].length()==n-1) { - // ans.push_back(a[i]); - // } - // } - // reverse(ans[0].begin(), ans[0].end()); - // if(ans[0]==ans[1]) { - // cout<<""yes""<>a>>b; - // ll n, m; - // cin>>n>>m; - // ll q=n/(m+1), r=n-(q*(m+1)); - // cout<<(q*min(a*m, b*(m+1)))+(r*min(a, b))<>n; - // vector h(n); - // int ct=0; - // for(int i=0; i>h[i]; - // if(h[i]==1) { - // ct++; - // } - // } - // cout<<(ct/2)+(n-ct)+(ct%2)<>n>>a>>b; - // string s; - // cin>>s; - // int ans=0; - // int x=0, y=0; - // for(int i=0; i<100; i++) { - // for(char c : s) { - // if(c=='N') { - // y++; - // } else if(c=='S') { - // y--; - // } else if(c=='E') { - // x++; - // } else { - // x--; - // } - // if(x==a && y==b) { - // ans=1; - // break; - // } - // } - // } - // if(ans) { - // cout<<""yes""<>n>>b>>c; - // if(!b) { - // if(c>=n) { - // cout<=n-2) { - // cout<=n) { - // cout<>n; - // cout<>s; - // for(int i=0; i>n>>a>>b; - // if(a%2==b%2) { - // cout<<""yes""<>n; - // vector a(n), b(n); - // for(int i=0; i>a[i]; - // } - // int ok=-1, mini=1e9, req=0; - // bool ans=false; - // for(int i=0; i>b[i]; - // if(a[i]=req) ? ""yes"" : ""no"")<>n>>m; - // vector> cards(n, vector (m)); - // for(int i=0; i>cards[i][j]; - // } - // sort(cards[i].begin(), cards[i].end()); - // } - // vector ind(n); - // for(int i=0; i>n>>k; - // vector x(n); - // unordered_map mp; - // for(int i=0; i>x[i]; - // mp[x[i]]++; - // } - // int score=0; - // for(auto it=mp.begin(); it!=mp.end(); it++) { - // int num=it->first; - // int comp=k-num; - // if(mp[num]>0) { - // if(num==comp) { - // score+=mp[num]/2; - // mp[num]%=2; - // } else if(mp.count(comp)) { - // int pairs=min(mp[num], mp[comp]); - // score+=pairs; - // mp[num]-=pairs; - // mp[comp]-=pairs; - // } - // } - // } - // cout<>n; - // vector a(n); - // for(int i=0; i>a[i]; - // } - // bool ans=true; - // for(int i=1; i>s; - // int ans=0; - // for(int i=0; i>n; - // vector a(n); - // bool ans=true; - // for(int i=0; i>a[i]; - // } - // for(int i=0; i>l>>r; - // if(l==r && l==1) { - // cout<<1<>n>>l>>r; - l--; - r--; - vector a(n); - for(int i=0; i>a[i]; - } - int x=r-l+1; - vector v1, v2; - for(int i=0; i<=r; i++) { - v1.push_back(a[i]); - } - for(int i=l; i>t; - while(t--) { - solve(); - } - return 0; -}",2 -Sh4d0wC4t,2063B - Subsequence Update,java,306457377,306457768,"import java.util.Scanner; - -public class Subsequence_Update{ - - public static void merge(int[] arr, int l, int m, int r){ - - int n1 = m - l + 1; - - int n2 = r - m; - - - - int[] L = new int[n1]; - - int[] R = new int[n2]; - - - - for(int i = 0; i - -using namespace std; - -typedef vector vi; -typedef vector vll; -typedef long long int lli; -typedef pair pii; -typedef map msi; -typedef map> miv; - -// Funciones vector -#define PB(a) push_back(a); - -bool sort_func(lli a, lli b) { - if (a < b) { - return true; - } else { - return false; - } -} -#define ord(vect) sort(vect.begin(), vect.end(), sort_func); - -#define borra_el(vect, el) vect.erase(vect.find(el)); -#define borra_range(vect, a, b) vect.erase(a, b); -#define borra(vect, n) vect.erase(vect.begin() + n); -#define B begin(); -#define E end(); -#define copia(v1, v2) \ - ; \ - copy(v1.begin(), v1.end(), back_inserter(v2)); - -// Funciones map -#define F first; -#define S second; - -// Logaritmo de 2 -double log_2 = log(2); -double log2(int a) { return (log(a) / log_2); } - -void Imprime(vi vect) { - for (int i = 0; i < vect.size(); i++) { - cout << vect[i] << "" ""; - } - cout << ""\n""; -} - -void Imprime2d(vector vect) { - for (int j = 0; j s) { - copy(s.begin(), s.end(), ostream_iterator(cout, "" "")); - cout << endl; -} - -int maximo_comun_divisor(int a, int b) { - int temporal; // Para no perder b - while (b != 0) { - temporal = b; - b = a % b; - a = temporal; - } - return a; -} - -int minimo_comun_multiplo(int a, int b) { - return (a * b) / maximo_comun_divisor(a, b); -} - -bool isNumeric(string const &str) { - auto it = str.begin(); - while (it != str.end() && isdigit(*it)) { - it++; - } - return !str.empty() && it == str.end(); -} - -vll lee(lli n) { - lli el; - vll vect; - for (int i = 0; i < n; i++) { - cin >> el; - vect.PB(el); - } - return (vect); -} - -int solve() { - // Code aquí - lli n, l, r; - cin >> n >> l >> r; - - vll a; - a = lee(n); - - vll al, ar; - for (int i = 0; i=l-1){ - ar.PB(a[i]); - } - } - ord(al); - ord(ar); - lli sum_1 = 0, sum_2 = 0; - for (int i = 0; i> T; // Número de casos - while (T--) { - solve(); - } - return 0; -} - -//Eliminar comentario si el proyecto está terminado (Dinámica empezó el 21/06/2024)","#include - -using namespace std; - -typedef vector vi; -typedef vector vll; -typedef long long int lli; -typedef pair pii; -typedef map msi; -typedef map> miv; - -// Funciones vector -#define PB(a) push_back(a); - -bool sort_func(int a, int b) { - if (a < b) { - return true; - } else { - return false; - } -} -#define ord(vect) sort(vect.begin(), vect.end(), sort_func); - -#define borra_el(vect, el) vect.erase(vect.find(el)); -#define borra_range(vect, a, b) vect.erase(a, b); -#define borra(vect, n) vect.erase(vect.begin() + n); -#define B begin(); -#define E end(); -#define copia(v1, v2) \ - ; \ - copy(v1.begin(), v1.end(), back_inserter(v2)); - -// Funciones map -#define F first; -#define S second; - -// Logaritmo de 2 -double log_2 = log(2); -double log2(int a) { return (log(a) / log_2); } - -void Imprime(vi vect) { - for (int i = 0; i < vect.size(); i++) { - cout << vect[i] << "" ""; - } - cout << ""\n""; -} - -void Imprime2d(vector vect) { - for (int j = 0; j s) { - copy(s.begin(), s.end(), ostream_iterator(cout, "" "")); - cout << endl; -} - -int maximo_comun_divisor(int a, int b) { - int temporal; // Para no perder b - while (b != 0) { - temporal = b; - b = a % b; - a = temporal; - } - return a; -} - -int minimo_comun_multiplo(int a, int b) { - return (a * b) / maximo_comun_divisor(a, b); -} - -bool isNumeric(string const &str) { - auto it = str.begin(); - while (it != str.end() && isdigit(*it)) { - it++; - } - return !str.empty() && it == str.end(); -} - -vi lee(int n) { - int el; - vi vect; - for (int i = 0; i < n; i++) { - cin >> el; - vect.PB(el); - } - return (vect); -} - -int solve() { - // Code aquí - int n, l, r; - cin >> n >> l >> r; - - vi a; - a = lee(n); - - vi al, ar; - for (int i = 0; i=l-1){ - ar.PB(a[i]); - } - } - ord(al); - ord(ar); - int sum_1 = 0, sum_2 = 0; - for (int i = 0; i> T; // Número de casos - while (T--) { - solve(); - } - return 0; -} - -//Eliminar comentario si el proyecto está terminado (Dinámica empezó el 21/06/2024)",1 -rczong,2063B - Subsequence Update,c++17 ,307155392,307164455,"#include - -#include - -#include - -#include - -using namespace std; - -const int N=1e5+5; - -int a[N]; - -typedef long long ll; - -int main(){ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t;cin>>t; - - while(t--){ - - int n,l,r;cin>>n>>l>>r; - - for(int i=1;i<=n;i++)cin>>a[i]; - - sort(a+1,a+1+n); - - ll sum=0; - - for(int i=1;i<=r-l+1;i++)sum+=a[i]; - - cout< -#include -#include -#include -using namespace std; -typedef long long ll; - -const int N=1e5+5; -int a[N],b[N]; - -int main(){ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t;cin>>t; - while(t--){ - int n,l,r; - cin>>n>>l>>r; - for(int i=1;i<=n;i++){ - cin>>a[i]; - b[i]=a[i]; - } - sort(a+1,a+1+r); - sort(b+l,b+n+1); - ll sum1=0,sum2=0; - for(int i=1;i<=r-l+1;i++)sum1+=a[i]; - for(int i=l;i<=r;i++)sum2+=b[i]; - cout<0: - change=0 - for i in range(r-l+1): - if i - - - -using namespace std; - - - -#define int long long - -#define PB push_back - -typedef vector vi; - -typedef vector vs; - - - -const int mod = 1e9 + 7; - -const int inf = INT_MAX; - - - -template - -vector I(int n) { - - vector vector; - - for (int i = 0; i < n; i++) { - - t input; - - cin >> input; - - vector.push_back(input); - - } - - - - return vector; - -} - - - -template - -void D(vector vector) { - - for (auto i: vector) { - - cout << i << "" ""; - - } - - - - cout << ""\n""; - -} - - - - - -void solve() { - - int n, l , r; - - cin >> n >> l >> r; - - vi x = I(n); - - vi first(x.begin(), x.begin() + r); - - vi second(x.begin() + l - 1, x.end()); - - sort(first.begin(), first.end()); - - sort(second.begin(), second.end()); - - long long sum1 = accumulate(first.begin(), first.begin() + (r - l + 1), 0LL); - - long long sum2 = accumulate(second.begin(), second.begin() + (r - l + 1), 0LL); - - cout << min(sum1, sum2) << ""\n""; - -} - - - - - -int32_t main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -","#include - - - -using namespace std; - - - -#define int long long - -#define PB push_back - -typedef vector vi; - -typedef vector vs; - - - -const int mod = 1e9 + 7; - -const int inf = INT_MAX; - - - -template - -vector I(int n) { - - vector vector; - - for (int i = 0; i < n; i++) { - - t input; - - cin >> input; - - vector.push_back(input); - - } - - - - return vector; - -} - - - -template - -void D(vector vector) { - - for (auto i: vector) { - - cout << i << "" ""; - - } - - - - cout << ""\n""; - -} - - - - - -void solve() { - - int n, l , r; - - cin >> n >> l >> r; - - vi x = I(n); - - vi first(x.begin(), x.begin() + r); - - vi second(x.begin() + l - 1, x.end()); - - sort(first.begin(), first.end()); - - sort(second.begin(), second.end()); - - int sum1 = accumulate(first.begin(), first.begin() + r - l + 1, 0); - - int sum2 = accumulate(second.begin(), second.begin() + r - l + 1, 0); - - cout << min(sum1, sum2) << ""\n""; - -} - - - - - -int32_t main() { - - ios_base::sync_with_stdio(false); - - cin.tie(NULL); - - cout.tie(NULL); - - - - int t; - - cin >> t; - - while (t--) { - - solve(); - - } - -} - -",1 -echoengulf,2063B - Subsequence Update,c++23 ,307232792,307229620,"#include - - - -using namespace std; - - - -const int N=100010; - - - -typedef long long ll; - - - -int a[N],b[N]; - -ll sum1[N],sum2[N]; - - - -int main() - -{ - - int T; - - cin>>T; - - while(T--) - - { - - memset(a,0,sizeof a); - - memset(b,0,sizeof b); - - memset(sum1,0,sizeof sum1); - - memset(sum2,0,sizeof sum2); - - int n,l,r; - - cin>>n>>l>>r; - - - - for(int i=1;i<=n;i++) - - { - - scanf(""%d"",&a[i]); - - } - - - - for(int i=l;i<=n;i++) - - { - - b[i-l+1]=a[i]; - - } - - - - sort(a+1,a+r+1); - - sort(b+1,b+n-l+2); - - - - for(int i=1;i<=r;i++) - - { - - sum1[i]=sum1[i-1]+a[i]; - - sum2[i]=sum2[i-1]+b[i]; - - } - - - - printf(""%lld\n"",min(sum1[r-l+1],sum2[r-l+1])); - - } - - - - return 0; - -} - -","#include - - - -using namespace std; - - - -const int N=100010; - - - -typedef long long ll; - - - -int a[N]; - -ll sum[N]; - - - -int main() - -{ - - int T; - - cin>>T; - - while(T--) - - { - - memset(a,0,sizeof a); - - memset(sum,0,sizeof sum); - - int n,l,r; - - cin>>n>>l>>r; - - - - for(int i=1;i<=n;i++) - - { - - scanf(""%d"",&a[i]); - - } - - - - sort(a+1,a+n+1); - - - - for(int i=1;i<=n;i++) - - { - - sum[i]=sum[i-1]+a[i]; - - } - - - - printf(""%lld\n"",sum[r-l+1]-sum[0]); - - } - - - - return 0; - -} - -",1 -dvverma0308,2063B - Subsequence Update,c++20 ,304753431,304752413,"#include -// #include -// #include -#define ll long long -#define all(x) x.begin(),x.end() -#define vii vector -#define vll vector -#define rep(i,x,n) for(int i = x;i -using namespace std; -#include -#define mod 1000000007 -#ifndef ONLINE_JUDGE -#define debug(x) cerr<<#x<<""->""<, null_type, less>, rb_tree_tag, -// tree_order_statistics_node_update> -// ordered_set; - - -/* -----------TRIE----------- -class TrieNode{ - public: - TrieNode* children[26]; - bool isEnd; - TrieNode(){ - isEnd = false; - for(auto &e:children) - e = nullptr; - } -}; -class Trie{ - public: - TrieNode* root = new TrieNode(); - void insert(string s){ - TrieNode* crawl = root; - for(auto e:s){ - int i = e-'a'; - if(crawl->children[i] == nullptr){ - crawl->children[i] = new TrieNode(); - } - crawl = crawl->children[i]; - } - crawl->isEnd = true; - } - bool search(string s){ - TrieNode* crawl = root; - for(auto e:s){ - int i = e-'a'; - if(!crawl->children[i]) - return false; - crawl = crawl->children[i]; - } - if(crawl && crawl->isEnd) - return true; - return false; - } - -}; - -*/ -/* ---------DFS-------------- -int dx[] = {0,0,1,-1}; -int dy[] = {-1,1,0,0}; -bool isSafe(int x, int y, int n, int m){ - return (x>=0&&x=0&&y> &mat,int i,int j,vector> &visited,int &count){ - visited[i][j] = true; - count+=mat[i][j]; - for(int z = 0;z<4;z++){ - int x = dx[z]+i; - int y = dy[z]+j; - if(isSafe(x,y,mat.size(),mat[0].size()) && !visited[x][y]&&mat[x][y]>0){ - visited[x][y] = true; - dfs(mat,x,y,visited,count); - } - } -} -*/ -// void dfs(int v, int p,vector> &mp,vector &arr) { -// if (mp[v].size() == 1 && mp[v][0] == p) { -// arr[v] = 1; -// } else { -// for (auto u : mp[v]) { -// if (u != p) { -// dfs(u, v,mp,arr); -// arr[v] += arr[u]; -// } -// } -// } -// } - -/*-----------------------DSU--------------------------------- */ -// vector> parent(200009); -// void initialize(){ -// for(int i = 1;i<=parent.size();i++) -// parent[i] = {i,1}; -// } -// pair find(int x){ -// if(parent[x].first == x) -// return parent[x]; -// parent[x] = find(parent[x].first); -// return parent[x]; -// } -// void Union(int x, int y){ -// auto x1 = find(x); -// auto y1 = find(y); -// if(x1.first != y1.first){ -// // cout<> mp,vector &a,vector &visited,int i,int &mini){ -// visited[i] = true; -// for(auto e:mp[i]){ -// if(!visited[e]){ -// visited[e] = true; -// mini = min(mini,a[e]); -// dfs(mp,a,visited,e,mini); -// } -// } -// } - -// long long fact(long long n) -// { -// if(n==0) -// return 1; -// long long res = 1; -// for (long long i = 2; i <= n; i++) -// res = res * i; -// return res; -// } -// long long nCr(long long n, long long r) -// { -// ll nume = fact(n); -// ll deno = fact(r); -// nume/=deno; -// deno = fact(n-r); -// nume/=deno; -// return nume; -// } -// bool isSafe(int x, int y, int n, int m){ -// return (x>=0&&x=0&&y0){ -// ans*=x; -// x--; -// } -// return ans; -// } -//only perfect squares have odd number of divisors........... -void findAns(){ - int n,l,r; - cin>>n>>l>>r; - l--; - r--; - vii arr(n); - rep(i,0,n) - cin>>arr[i]; - - vii brr = arr; - sort(brr.begin(),brr.begin()+r+1); - sort(arr.begin()+l,arr.end()); - // for(auto e:brr) - // cout<>n; - // int x = n ; - while(n--){ - findAns(); - } -}","#include -// #include -// #include -#define ll long long -#define all(x) x.begin(),x.end() -#define vii vector -#define vll vector -#define rep(i,x,n) for(int i = x;i -using namespace std; -#include -#define mod 1000000007 -#ifndef ONLINE_JUDGE -#define debug(x) cerr<<#x<<""->""<, null_type, less>, rb_tree_tag, -// tree_order_statistics_node_update> -// ordered_set; - - -/* -----------TRIE----------- -class TrieNode{ - public: - TrieNode* children[26]; - bool isEnd; - TrieNode(){ - isEnd = false; - for(auto &e:children) - e = nullptr; - } -}; -class Trie{ - public: - TrieNode* root = new TrieNode(); - void insert(string s){ - TrieNode* crawl = root; - for(auto e:s){ - int i = e-'a'; - if(crawl->children[i] == nullptr){ - crawl->children[i] = new TrieNode(); - } - crawl = crawl->children[i]; - } - crawl->isEnd = true; - } - bool search(string s){ - TrieNode* crawl = root; - for(auto e:s){ - int i = e-'a'; - if(!crawl->children[i]) - return false; - crawl = crawl->children[i]; - } - if(crawl && crawl->isEnd) - return true; - return false; - } - -}; - -*/ -/* ---------DFS-------------- -int dx[] = {0,0,1,-1}; -int dy[] = {-1,1,0,0}; -bool isSafe(int x, int y, int n, int m){ - return (x>=0&&x=0&&y> &mat,int i,int j,vector> &visited,int &count){ - visited[i][j] = true; - count+=mat[i][j]; - for(int z = 0;z<4;z++){ - int x = dx[z]+i; - int y = dy[z]+j; - if(isSafe(x,y,mat.size(),mat[0].size()) && !visited[x][y]&&mat[x][y]>0){ - visited[x][y] = true; - dfs(mat,x,y,visited,count); - } - } -} -*/ -// void dfs(int v, int p,vector> &mp,vector &arr) { -// if (mp[v].size() == 1 && mp[v][0] == p) { -// arr[v] = 1; -// } else { -// for (auto u : mp[v]) { -// if (u != p) { -// dfs(u, v,mp,arr); -// arr[v] += arr[u]; -// } -// } -// } -// } - -/*-----------------------DSU--------------------------------- */ -// vector> parent(200009); -// void initialize(){ -// for(int i = 1;i<=parent.size();i++) -// parent[i] = {i,1}; -// } -// pair find(int x){ -// if(parent[x].first == x) -// return parent[x]; -// parent[x] = find(parent[x].first); -// return parent[x]; -// } -// void Union(int x, int y){ -// auto x1 = find(x); -// auto y1 = find(y); -// if(x1.first != y1.first){ -// // cout<> mp,vector &a,vector &visited,int i,int &mini){ -// visited[i] = true; -// for(auto e:mp[i]){ -// if(!visited[e]){ -// visited[e] = true; -// mini = min(mini,a[e]); -// dfs(mp,a,visited,e,mini); -// } -// } -// } - -// long long fact(long long n) -// { -// if(n==0) -// return 1; -// long long res = 1; -// for (long long i = 2; i <= n; i++) -// res = res * i; -// return res; -// } -// long long nCr(long long n, long long r) -// { -// ll nume = fact(n); -// ll deno = fact(r); -// nume/=deno; -// deno = fact(n-r); -// nume/=deno; -// return nume; -// } -// bool isSafe(int x, int y, int n, int m){ -// return (x>=0&&x=0&&y0){ -// ans*=x; -// x--; -// } -// return ans; -// } -//only perfect squares have odd number of divisors........... -void findAns(){ - int n,l,r; - cin>>n>>l>>r; - l--; - r--; - vii arr(n); - rep(i,0,n) - cin>>arr[i]; - - vii brr = arr; - sort(brr.begin(),brr.begin()+r); - sort(arr.begin()+l,arr.end()); - - ll ans = INT_MAX; - ll curr = 0; - ll stack = 0; - for(int i = 0;i>n; - // int x = n ; - while(n--){ - findAns(); - } -}",1 -plutoson,2063B - Subsequence Update,c++23 ,305609940,305609856,"#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -const int N=200010; - -long long a[N],b[N],c[N]; - -void solve(){ - - int n,l,r; - - cin>>n>>l>>r; - - for(int i=0;i>a[i]; - - } - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -} ","#include - -#include - -#include - -#include - -#include - -#include - -using namespace std; - -const int N=200010; - -long long a[N],b[N],c[N]; - -void solve(){ - - int n,l,r; - - cin>>n>>l>>r; - - for(int i=0;i>a[i]; - - } - - for(int i=0;i>t; - - while(t--){ - - solve(); - - } - - return 0; - -} ",1 -rodrigojamunda82_,2063B - Subsequence Update,c++20 ,304904188,304904968,"#include -using namespace std; - -#define int long long - -#define endl '\n' -#define all(x) (x).begin(), (x).end() -#define pb push_back -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vvi; - -void fastio(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -const int maxN=2e3; -const int INF=1e9; -const int MOD=1e9+7; - -int t, n, l, r, ans1, ans2; -vi arrM, arr; - -bool invComp(int a, int b){ - return a>=b; -} - -signed main(){ - fastio(); - cin >> t; - while(t--){ - cin >> n >> l >> r; - arr.resize(n+50, 0); - for(int i=0; i> arr[i]; - } - l--; r--; - ans1=ans2=0; - arrM=arr; - sort(arrM.begin(), arrM.begin()+r+1, invComp); - for(int i=l; i<=r; i++){ - ans1+=arrM[i]; - } - arrM=arr; - sort(arrM.begin()+l, arrM.begin()+n); - for(int i=l; i<=r; i++){ - ans2+=arrM[i]; - } - cout << min(ans1, ans2) << endl; - } - return 0; -} -","#include -using namespace std; - -#define int long long - -#define endl '\n' -#define all(x) (x).begin(), (x).end() -#define pb push_back -typedef long long ll; -typedef pair pii; -typedef vector vi; -typedef vector vvi; - -void fastio(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); -} - -const int maxN=2e3; -const int INF=1e9; -const int MOD=1e9+7; - -int t, n, l, r, ans1, ans2, a; -vi arr1, arr2; - -signed main(){ - fastio(); - cin >> t; - while(t--){ - cin >> n >> l >> r; - arr1.clear(); - arr2.clear(); - l--; r--; - for(int i=0; i> a; - if(i<=r) arr1.pb(a); - if(i>=l) arr2.pb(a); - } - ans1=ans2=0; - sort(all(arr1)); - sort(all(arr2)); - for(int i=0; i<=r-l; i++){ - ans1+=arr1[i]; - ans2+=arr2[i]; - } - cout << min(ans1, ans2) << endl; - } - return 0; -} -",2 -JunichiK#,2063B - Subsequence Update,c++20 ,305573033,305575157,"#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -#define ll long long - - - -#define MAX 200'001 - - - -using namespace std; - - - -void solve() { - - int n, l, r; - - cin >> n >> l >> r; - - - - vector array(n); - - for(int &a : array) { - - cin >> a; - - } - - - - vector left_half; - - for(int i = 0; i < l; i++) { - - left_half.push_back(array[i]); - - } - - - - vector right_half; - - for(int i = r; i < n; i++) { - - right_half.push_back(array[i]); - - } - - - - sort(left_half.begin(), left_half.end()); - - sort(right_half.begin(), right_half.end()); - - - - - - ll left_sum = 0; - - int left_pointer = 0; - - int segment_pointer = l - 1; - - - - while(left_pointer < left_half.size() && segment_pointer < r) { - - int min_value = min(array[segment_pointer], left_half[left_pointer]); - - - - if(min_value == array[segment_pointer]) { - - left_sum += min_value; - - segment_pointer++; - - } - - - - else { - - left_sum += min_value; - - - - left_pointer++; - - segment_pointer++; - - } - - } - - - - while(segment_pointer < r) { - - left_sum += array[segment_pointer]; - - segment_pointer++; - - } - - - - ll right_sum = 0; - - int right_pointer = 0; - - segment_pointer = l - 1; - - - - while(right_pointer < right_half.size() && segment_pointer < r) { - - int min_value = min(array[segment_pointer], right_half[right_pointer]); - - - - if(min_value == array[segment_pointer]) { - - right_sum += min_value; - - segment_pointer++; - - } - - - - else { - - right_sum += min_value; - - - - right_pointer++; - - segment_pointer++; - - } - - } - - - - while(segment_pointer < r) { - - right_sum += array[segment_pointer]; - - segment_pointer++; - - } - - - - cout << min(left_sum, right_sum) << '\n'; - -} - - - -int main() { - - - - int t; - - cin >> t; - - - - while(t--) { - - solve(); - - } - - - - return 0; - -}","#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - -#include - - - -#define ll long long - - - -#define MAX 200'001 - - - -using namespace std; - - - -void solve() { - - int n, l, r; - - cin >> n >> l >> r; - - - - vector array(n); - - for(int &a : array) { - - cin >> a; - - } - - - - vector left_half; - - for(int i = 0; i < l - 1; i++) { - - left_half.push_back(array[i]); - - } - - - - vector right_half; - - for(int i = r; i < n; i++) { - - right_half.push_back(array[i]); - - } - - - - sort(left_half.begin(), left_half.end()); - - sort(right_half.begin(), right_half.end()); - - - - sort(array.begin() + l - 1, array.begin() + r, greater()); - - - - - - ll left_sum = 0; - - int left_pointer = 0; - - int segment_pointer = l - 1; - - - - while(left_pointer < left_half.size() && segment_pointer < r) { - - int min_value = min(array[segment_pointer], left_half[left_pointer]); - - - - if(min_value == array[segment_pointer]) { - - left_sum += min_value; - - segment_pointer++; - - } - - - - else { - - left_sum += min_value; - - - - left_pointer++; - - segment_pointer++; - - } - - } - - - - while(segment_pointer < r) { - - left_sum += array[segment_pointer]; - - segment_pointer++; - - } - - - - ll right_sum = 0; - - int right_pointer = 0; - - segment_pointer = l - 1; - - - - while(right_pointer < right_half.size() && segment_pointer < r) { - - int min_value = min(array[segment_pointer], right_half[right_pointer]); - - - - if(min_value == array[segment_pointer]) { - - right_sum += min_value; - - segment_pointer++; - - } - - - - else { - - right_sum += min_value; - - - - right_pointer++; - - segment_pointer++; - - } - - } - - - - while(segment_pointer < r) { - - right_sum += array[segment_pointer]; - - segment_pointer++; - - } - - - - cout << min(left_sum, right_sum) << '\n'; - -} - - - -int main() { - - - - int t; - - cin >> t; - - - - while(t--) { - - solve(); - - } - - - - return 0; - -} - - - - - -",2 -Sunstreamyheee,2063B - Subsequence Update,c++20 ,306538252,306416895,"#include - -using namespace std; - -typedef long long i64; - -typedef __int128_t i128; - -const int M = 1e9 + 7; - -#define N 200005 - -void solve() - -{ - - int n, l, r; - - cin >> n >> l >> r; - - l--; - - vector L, R; - - for (int i = 0; i < n; i++) - - { - - int x; - - cin >> x; - - if (i < r) - - { - - L.push_back(x); - - } - - if (i >= l) - - { - - R.push_back(x); - - } - - } - - sort(L.begin(), L.end()); - - sort(R.begin(), R.end()); - - i64 ans1 = accumulate(L.begin(), L.begin() + r - l, 0LL); - - i64 ans2 = accumulate(R.begin(), R.begin() + r - l, 0LL); - - cout << min(ans1, ans2) << endl; - -} - - - -int main() - -{ - - ios::sync_with_stdio(false); - - cin.tie(0); - - cout.tie(0); - - int t; - - cin >> t; - - while (t--) - - { - - solve(); - - } - - - - return 0; - -} - -","#include -using namespace std; -typedef long long i64; -const int M = 1e9 + 7; -#define N 200005 - -void solve() -{ - int n; - cin >> n; - vector a(n + 1); - for (int i = 1; i <= n; i++) - { - cin >> a[i]; - } - if (n == 1) - { - cout << 1 << "" "" << 1 << endl; - return; - } - - map cnt; - for (int i = 1; i <= n; i++) - { - cnt[a[i]]++; - } - - int cntmx = 0; - int k = -1; - for (const auto &[i, cnt_] : cnt) - { - if (cnt_ > cntmx) - { - cntmx = cnt_; - k = i; - } - } - - vector idxs; - for (int i = 1; i <= n; i++) - { - if (a[i] == k) - { - idxs.push_back(i); - } - } - - int dis = 0; - int l = -1; - int r = -1; - for (int i = 1; i < idxs.size(); i++) - { - int temp = idxs[i] - idxs[i - 1] - 1; - if (temp > dis) - { - dis = temp; - l = idxs[i - 1]; - r = idxs[i]; - } - } - - // 输出结果 - if (l != -1 && r != -1) - { - cout << l + 1 << "" "" << r - 1 << endl; - } - else - { - cout << 0 << endl; - } -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - int t; - cin >> t; - while (t--) - { - solve(); - } - return 0; -}",1 -_Kurapika_,2063B - Subsequence Update,c++17 ,305732523,305722546,"#include - -using namespace std; - - - -typedef long long ll; - - - -void solve() { - - - - int n,l,r ; cin>>n>>l>>r; - - vectorv(n+1),ans1,ans2; - - for (int i = 1 ; i <= n ; ++i) - - cin>>v[i]; - - int siz = r-l+1 , ans = 0; - - for (int i = l ; i <= r ; ++i) - - ans1.push_back(v[i]),ans2.push_back(v[i]); - - for (int i = 1 ; i < l ; ++i) - - ans1.push_back(v[i]); - - for (int i = r+1 ; i <= n ; ++i) - - ans2.push_back(v[i]); - - sort(ans1.begin(),ans1.end()); - - sort(ans2.begin(),ans2.end()); - - ll sum1 = 0 , sum2 = 0; - - for (int i = 0 ; i >t; - - while(t--) - - solve(); - - return 0; - -} - - - - - - - - - - - - - - - - - - - -","#include -using namespace std; - -typedef long long ll; - -void solve() { - - int n,l,r ; cin>>n>>l>>r; - vectorv(n+1); - for (int i = 1 ; i <= n ; ++i) - cin>>v[i]; - sort(v.begin(),v.end()); - int siz = r-l+1 , ans = 0; - for (int i = 1 ; i <= siz ; ++i) - ans += v[i]; - cout<>t; - while(t--) - solve(); - return 0; -} - - -",1 -Pappubsdka,2063C - Remove Exactly Two,c++23 ,305527956,305525088,"#include -using namespace std; -using namespace std::chrono; - -#define inf 1e9 -#define mod 1000000007 -#define MAX 1000000000 -#define vpii vector> -#define int long long -#define pb push_back -#define read(arr) for (int i = 0; i < arr.size(); i++) cin >> arr[i] -#define print(arr) for (int i = 0; i < arr.size(); i++) cout << arr[i] << "" ""; cout << ""\n"" -#define vi vector -#define vvi vector -#define all(v) v.begin(), v.end() - - -void solve(int t) { - int n; cin >> n; - int ans = 1; - vector> adj(n+1); - vector> v(n+1, {0,0} ); - for(int i = 0 ; i < n +1; ++i) { - v[i].second = i; - } - vi last(n+1,0); - for(int i = 0; i < n-1; ++i) { - int a, b; cin >> a >> b; - adj[a].insert(b); - adj[b].insert(a); - v[a].first++; - v[b].first++; - last[a]++; - last[b]++; - } - sort(v.begin(),v.end()); - - int maxi = INT_MIN; - for(int i= 1; i < n+1; ++i) { - int p1 = i; - int two = 0; - for(int j = n; j>=0 ;j--) { - if(i!= v[j].second) { - two = max(v[j].first, two); - set&s = adj[i]; - while(j>= 0 && v[j].second != i && s.find(v[j].second)!=s.end()) { - --j; - } - - if(j >= 0 && v[j].second != i) { - int one = v[j].first; - maxi = max(maxi , one + last[i] - 1); - } - maxi = max(two +last[i] -2 ,maxi); - break; - } - } - } - cout << maxi << ""\n""; - -} -signed main() { - ios::sync_with_stdio(0); - cin.tie(0), cout.tie(0); - - int test = 1; - cin >> test; - - - for (int i = 1; i <= test; ++i) { - solve(i); - } -}","#include -using namespace std; -using namespace std::chrono; - -#define inf 1e9 -#define mod 1000000007 -#define MAX 1000000000 -#define vpii vector> -#define int long long -#define pb push_back -#define read(arr) for (int i = 0; i < arr.size(); i++) cin >> arr[i] -#define print(arr) for (int i = 0; i < arr.size(); i++) cout << arr[i] << "" ""; cout << ""\n"" -#define vi vector -#define vvi vector -#define all(v) v.begin(), v.end() - - -void solve(int t) { - int n; cin >> n; - int ans = 1; - vector> adj(n+1); - vector v(n+1, 0 ); - for(int i = 0; i < n-1; ++i) { - int a, b; cin >> a >> b; - adj[a].push_back(b); - adj[b].push_back(a); - v[a]++; - v[b]++; - } - int maxi = INT_MIN; - int ind; - for(int i = 1 ; i < n+1; ++i) { - if(maxi < v[i]) { - maxi = v[i]; - ind = i; - - } - } - ans += maxi - 1; - vector> mat(n); - vector u(n,0); - for(int i = 1 ; i < adj.size(); ++i) { - if(i!=ind) { - for(int j = 0 ; j < adj[i].size(); ++j) { - if(adj[i][j] != ind) { - int nind = i - (i>ind); - int nind2 = adj[i][j] - (adj[i][j] > ind); - mat[nind].push_back(nind2); - u[nind]++; - } - } - } - } - - // for(int i = 1; i < mat.size(); ++i) { - // cout << i << ""-> ""; - // for(auto j :mat[i] ) { - // cout << j << "" ""; - // } - // cout << ""\n""; - // } - - // for(int i = 1; i < u.size(); ++i) { - // cout << u[i] << "" ""; - // } - // cout << ""\n""; - maxi =INT_MIN; - for(int i = 1; i < u.size(); ++i ) { - maxi = max(maxi, u[i]); - } - - ans += maxi - 1; - - cout << ans << ""\n""; - -} -signed main() { - ios::sync_with_stdio(0); - cin.tie(0), cout.tie(0); - - int test = 1; - cin >> test; - - - for (int i = 1; i <= test; ++i) { - solve(i); - } -}",1 -toilantm_PTNK,2063C - Remove Exactly Two,c++17 ,304214299,304214446,"#include -#define pb push_back -#define se second -#define fi first -#define all(x) (x).begin(), (x).end() -#define el ""\n"" -#define bit(mask,i) ((mask>>i)&1) -#define taskname ""test"" -using namespace std; - -typedef long long ll; -typedef pair pi; - -const int MAXN = 2e5+5; -const ll MOD = 998244353; -const ll INF = 1e18; -const double EPSILON = 0.000001; - -// Initial function -ll add_mod (ll &a, ll b) { - if ((a += b) >= MOD) a -= b; - return a; -} - -ll sub_mod (ll &a, ll b) { - return (a - b + MOD) % MOD; -} - -ll mul_mod (ll &a, ll b) { - return (a = (1LL * a * b % MOD)); -} - -void maximize (ll &x, ll val) -{ - x = max (x, val); -} - -void minimize (ll &x, ll val) -{ - x = min (x, val); -} - -void debug (ll x, ll type = 0) -{ - cout << x; - cout << (type == 0 ? el : "" "" ); -} -// ----------------------- - -// Variable -ll n, res; -multiset m; -vector adj[MAXN]; - -// ----------------------- - - -// Setup Function -void del (ll x) { - auto itr = m.find (x); - m.erase (x); -} - -// ----------------------- - -// subtask - - -// ----------------------- - - -int main () -{ - if (fopen (taskname"".inp"", ""r"")) - { - freopen (taskname"".inp"", ""r"", stdin); - freopen (taskname"".out"", ""w"", stdout); - } - - ios_base :: sync_with_stdio (false); - cin.tie (NULL); - cout.tie (NULL); - - ll t; cin >> t; - while (t--) { - for (int i = 1; i <= n; i ++) adj[i].clear (); - m.clear (); - res = 0; - - cin >> n; - for (int i = 1; i <= n - 1; i ++){ - ll x, y; cin >> x >> y; - adj[x].pb (y), adj[y].pb (x); - } - - - for (int i = 1; i <= n; i ++) - m.insert (adj[i].size()); - - for (int i = 1; i <= n; i ++) { - ll ans = adj[i].size(); - del (ans); - - for (auto u : adj[i]) { - del (adj[u].size()); - m.insert (adj[u].size() - 1); - } - - ll maxx = *m.rbegin(); - // cout << maxx << el; - ans += maxx - 1; - maximize (res, ans); - - m.insert (adj[i].size()); - for (auto u : adj[i]) { - m.insert (adj[u].size()); - del (adj[u].size() - 1); - } - } - - cout << res << el; - } - return 0; -} - -/* -{\_/} -(>.<) -/>AC -*/ -","#include -#define pb push_back -#define se second -#define fi first -#define all(x) (x).begin(), (x).end() -#define el ""\n"" -#define bit(mask,i) ((mask>>i)&1) -#define taskname ""test"" -using namespace std; - -typedef long long ll; -typedef pair pi; - -const int MAXN = 2e5+5; -const ll MOD = 998244353; -const ll INF = 1e18; -const double EPSILON = 0.000001; - -// Initial function -ll add_mod (ll &a, ll b) { - if ((a += b) >= MOD) a -= b; - return a; -} - -ll sub_mod (ll &a, ll b) { - return (a - b + MOD) % MOD; -} - -ll mul_mod (ll &a, ll b) { - return (a = (1LL * a * b % MOD)); -} - -void maximize (ll &x, ll val) -{ - x = max (x, val); -} - -void minimize (ll &x, ll val) -{ - x = min (x, val); -} - -void debug (ll x, ll type = 0) -{ - cout << x; - cout << (type == 0 ? el : "" "" ); -} -// ----------------------- - -// Variable -ll n, res; -multiset m; -vector adj[MAXN]; - -// ----------------------- - - -// Setup Function -void del (ll x) { - auto itr = m.find (x); - m.erase (itr); -} - -// ----------------------- - -// subtask - - -// ----------------------- - - -int main () -{ - if (fopen (taskname"".inp"", ""r"")) - { - freopen (taskname"".inp"", ""r"", stdin); - freopen (taskname"".out"", ""w"", stdout); - } - - ios_base :: sync_with_stdio (false); - cin.tie (NULL); - cout.tie (NULL); - - ll t; cin >> t; - while (t--) { - for (int i = 1; i <= n; i ++) adj[i].clear (); - m.clear (); - res = 0; - - cin >> n; - for (int i = 1; i <= n - 1; i ++){ - ll x, y; cin >> x >> y; - adj[x].pb (y), adj[y].pb (x); - } - - - for (int i = 1; i <= n; i ++) - m.insert (adj[i].size()); - - for (int i = 1; i <= n; i ++) { - ll ans = adj[i].size(); - del (ans); - - for (auto u : adj[i]) { - del (adj[u].size()); - m.insert (adj[u].size() - 1); - } - - ll maxx = *m.rbegin(); - // cout << maxx << el; - ans += maxx - 1; - maximize (res, ans); - - m.insert (adj[i].size()); - for (auto u : adj[i]) { - m.insert (adj[u].size()); - del (adj[u].size() - 1); - } - } - - cout << res << el; - } - return 0; -} - -/* -{\_/} -(>.<) -/>AC -*/ -",2 -Shresth_Sharma-2015,2063C - Remove Exactly Two,c++23 ,304228950,304238126,"#include -using namespace std; -#define ll long long -#define endl '\n' -#define mod 1000000007 - -vector is_prime; - -void sieve(ll n) { - is_prime.assign(n + 1, true); - is_prime[0] = is_prime[1] = false; - for (ll i = 2; i * i <= n; i++) { - if (is_prime[i]) { - for (ll j = i * i; j <= n; j += i) - is_prime[j] = false; - } - } -} - -ll lcm(ll a, ll b) { - return (a / __gcd(a, b)) * b; -} - -/* -1. Read question carefully -2. generalize the logic -3. convert it to mathematical equation -4. !!!!! don't think (CHECK) again until you get wrong answer -5. write the code -*/ - -void solve() { - ll n; - cin>>n; // number of nodes; - vector>edges(n-1); - map,ll>mp; - for(ll i=0;i>edges[i].first>>edges[i].second; - if(edges[i].first>edges[i].second){ - swap(edges[i].first,edges[i].second); - } - mp[{edges[i].first,edges[i].second}]=1; - } - - // prepraing adjacency list - vectordegree(n,0); - vector>list(n,vector()); - for(ll i=0;i>ans; - - // degree,node - - for(ll i=0;ihelp; - - for(ll i=1;iunconet; - vectorcon; - - for(ll i=0;i> test; - while (test--) { - solve(); - } - return 0; -}","#include -using namespace std; -#define ll long long -#define endl '\n' -#define mod 1000000007 - -vector is_prime; - -void sieve(ll n) { - is_prime.assign(n + 1, true); - is_prime[0] = is_prime[1] = false; - for (ll i = 2; i * i <= n; i++) { - if (is_prime[i]) { - for (ll j = i * i; j <= n; j += i) - is_prime[j] = false; - } - } -} - -ll lcm(ll a, ll b) { - return (a / __gcd(a, b)) * b; -} - -/* -1. Read question carefully -2. generalize the logic -3. convert it to mathematical equation -4. !!!!! don't think (CHECK) again until you get wrong answer -5. write the code -*/ - -void solve() { - ll n; - cin>>n; // number of nodes; - vector>edges(n-1); - map,ll>mp; - for(ll i=0;i>edges[i].first>>edges[i].second; - if(edges[i].first>edges[i].second){ - swap(edges[i].first,edges[i].second); - } - mp[{edges[i].first,edges[i].second}]=1; - } - - // prepraing adjacency list - vectordegree(n,0); - vector>list(n,vector()); - for(ll i=0;i>ans; - - // degree,node - - for(ll i=0;ihelp; - - for(ll i=0;i=3){ - maxi=max(maxi,2*degree[help[0]]-1); - } - else{ - if(mp.find({help[0]+1,help[1]+1})!=mp.end() || mp.find({help[1]+1,help[0]+1})!=mp.end()){ - maxi=max(maxi,2*degree[help[0]]-2); - } - else{ - maxi=max(maxi,2*degree[help[0]]-1); - - } - } - cout<help; - ll max1=ans[0].second; - - - for(ll i=1;i> test; - while (test--) { - solve(); - } - return 0; -}",2 -ZnZrYb,2063C - Remove Exactly Two,c++17 ,305602802,305604041,"// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/contest/2063/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// by znzryb -// -// Powered by CP Editor (https://cpeditor.org) - -#include -#define FOR(i, a, b) for (int i = (a); i <= (b); ++i) -#define ROF(i, a, b) for (int i = (a); i >= (b); --i) -#define all(x) x.begin(), x.end() -#define CLR(i, a) memset(i, a, sizeof(i)) -#define fi first -#define se second -#define pb push_back -#define SZ(a) ((int)a.size()) -#define LOCAL - -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pll; -typedef array arr; -typedef double DB; -typedef pair pdd; -constexpr ll MAXN = static_cast(2e5) + 10, INF = static_cast(5e18) + 3; - -ll N, M, T; -vector g[MAXN]; -ll edges[MAXN]; - -inline void solve() { - cin >> N; - map cnt; - // 初始化 - FOR(i, 1, N) { g[i].clear(); } - FOR(i, 1, N - 1) { - ll u, v; - cin >> u >> v; - g[u].pb(v); - g[v].pb(u); - } - if (N == 2) { - cout << 0 << '\n'; - return; - } - ll mx = 0, mxN = 1; - FOR(i, 1, N) { - edges[i] = SZ(g[i]); - cnt[edges[i]] = cnt.find(edges[i]) == cnt.end() ? 1 : cnt[edges[i]] + 1; - } - ll ans = 0; - map backup = cnt; - FOR(i, 1, N) { - ll lans = edges[i]; -// #ifdef LOCAL - // cerr << i << ' ' << edges[i] << '\n'; -// #endif - cnt[edges[i]] -= 1; - if (cnt[edges[i]] == 0) { - cnt.erase(edges[i]); - } - FOR(j, 0, SZ(g[i]) - 1) { - ll node = g[i][j]; - cnt[edges[node]] -= 1; - cnt[edges[node] - 1] = cnt.find(edges[node] - 1) == cnt.end() ? 1 : cnt[edges[node] - 1] + 1; - if (cnt[edges[node]] == 0) { - cnt.erase(edges[node]); - } - } - lans -= 1; // 先不管我们这个要做第二个操作的联通块 - if (cnt.rbegin()->fi > 1) { - // #ifdef LOCAL - // cerr << lans << '\n'; - // #endif - lans += cnt.rbegin()->se; - } else if (cnt.rbegin()->fi == 1) { - lans += cnt.rbegin()->se - 1; - } - -// #ifdef LOCAL - // cerr << i << ' ' << lans << '\n'; -// #endif - ans = max(ans, lans); - cnt = backup; - } - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cin >> T; - while (T--) { - solve(); -#ifdef LOCAL - cerr << '\n'; -#endif - } - return 0; -} -/* - -*/","// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/contest/2063/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// by znzryb -// -// Powered by CP Editor (https://cpeditor.org) - -#include -#define FOR(i, a, b) for (int i = (a); i <= (b); ++i) -#define ROF(i, a, b) for (int i = (a); i >= (b); --i) -#define all(x) x.begin(), x.end() -#define CLR(i, a) memset(i, a, sizeof(i)) -#define fi first -#define se second -#define pb push_back -#define SZ(a) ((int)a.size()) -#define LOCAL - -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pll; -typedef array arr; -typedef double DB; -typedef pair pdd; -constexpr ll MAXN = static_cast(2e5) + 10, INF = static_cast(5e18) + 3; - -ll N, M, T; -vector g[MAXN]; -ll edges[MAXN]; - -inline void solve() { - cin >> N; - map cnt; - // 初始化 - FOR(i, 1, N) { g[i].clear(); } - FOR(i, 1, N - 1) { - ll u, v; - cin >> u >> v; - g[u].pb(v); - g[v].pb(u); - } - if (N == 2) { - cout << 0 << '\n'; - return; - } - ll mx = 0, mxN = 1; - FOR(i, 1, N) { - edges[i] = SZ(g[i]); - cnt[edges[i]] = cnt.find(edges[i]) == cnt.end() ? 1 : cnt[edges[i]] + 1; - } - ll ans = 0; - map backup = cnt; - FOR(i, 1, N) { - ll lans = edges[i]; - // #ifdef LOCAL - // cerr << i << ' ' << edges[i] << '\n'; - // #endif - cnt[edges[i]] -= 1; - if (cnt[edges[i]] == 0) { - cnt.erase(edges[i]); - } - FOR(j, 0, SZ(g[i]) - 1) { - ll node = g[i][j]; - cnt[edges[node]] -= 1; - cnt[edges[node] - 1] = cnt.find(edges[node] - 1) == cnt.end() ? 1 : cnt[edges[node] - 1] + 1; - if (cnt[edges[node]] == 0) { - cnt.erase(edges[node]); - } - } - lans -= 1; // 先不管我们这个要做第二个操作的联通块 - if (cnt.rbegin()->fi > 1) { - // #ifdef LOCAL - // cerr << lans << '\n'; - // #endif - lans += cnt.rbegin()->fi; - } else if (cnt.rbegin()->fi == 1) { - // #ifdef LOCAL - // cerr<<""In if:"" << i << ' ' << lans << '\n'; - // #endif - lans += cnt.rbegin()->fi - 1; - } - - // #ifdef LOCAL - // cerr << i << ' ' << lans << '\n'; - // #endif - ans = max(ans, lans); - cnt = backup; - } - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - cin >> T; - while (T--) { - solve(); -#ifdef LOCAL - cerr << '\n'; -#endif - } - return 0; -} -/* - -*/",2 -abu.saleh,2063C - Remove Exactly Two,c++17 ,304012260,304010196,"#include -using namespace std; - -void solve(){ - int n;cin>>n; - vector> adj(n+1); - vector edges(n+1); - for(int i=0; i>a>>b; - adj[a].push_back(b); - adj[b].push_back(a); - edges[a]++; - edges[b]++; - } - if(n==2){ - cout<<0< max){ - node = i; - max = edges[i]; - } - } - bool flag = false; - for(auto it: adj[node]){ - if(edges[it] == max){ - - if(flag){ - cout<max2 && i != node){ - node2=i; - max2=edges[i]; - } - } - cout<>t; - while(t--){ - solve(); - } -}","#include -using namespace std; - -void solve(){ - int n;cin>>n; - vector> adj(n+1); - vector edges(n+1); - for(int i=0; i>a>>b; - adj[a].push_back(b); - adj[b].push_back(a); - edges[a]++; - edges[b]++; - } - if(n==2){ - cout<<0< max){ - node = i; - max = edges[i]; - } - } - for(auto it: adj[node]){ - edges[it]--; - } - - long long max2=-1,node2=-1; - for(int i=1; i<=n; i++){ - if(edges[i]>max2 && i != node){ - node2=i; - max2=edges[i]; - } - } - cout<>t; - while(t--){ - solve(); - } -}",1 -mangos194,2063C - Remove Exactly Two,java,304631389,304634397,"import java.util.*; -import java.io.*; -import java.math.*; - -public class sub { - - static int mod = 998244353; - - public static void main(String args[]) throws IOException { - int t = sc.nextInt(); - while(t-->0) { - int n = sc.nextInt(); - ArrayList> adj = new ArrayList(); - for(int i = 0;i pq = new PriorityQueue(Collections.reverseOrder()); - for(int i = 0;i { - long cost; - int u, v; - Node(long cost, int u, int v) { - this.cost = cost; - this.u = u; - this.v = v; - } - public int compareTo(Node o) { - return Long.compare(this.cost, o.cost); - } - } - - static long pow(long a, long b, long mod) { - if (b == 0) { - return 1L; - } - long val = pow(a, b / 2, mod); - if (b % 2 == 0) { - return val * val % mod; - } - return val * val % mod * a % mod; - } - - static long gcd(long a, long b) { - if (b == 0) { - return a; - } - return gcd(b, a % b); - } - - static long lcm(long a, long b) { - return a * b / gcd(a, b); - } - - static Kattio sc = new Kattio(); - static PrintWriter out = new PrintWriter(System.out); - - static class Kattio { - - static BufferedReader r; - static StringTokenizer st; - - public Kattio() { - r = new BufferedReader(new InputStreamReader(System.in)); - } - - public String next() { - try { - while (st == null || !st.hasMoreTokens()) { - st = new StringTokenizer(r.readLine()); - } - return st.nextToken(); - } catch (Exception e) { - return null; - } - } - - public int nextInt() { - return Integer.parseInt(next()); - } - - public long nextLong() { - return Long.parseLong(next()); - } - - public double nextDouble() { - return Double.parseDouble(next()); - } - } -}","import java.util.*; -import java.io.*; -import java.math.*; - -public class sub { - - static int mod = 998244353; - - public static void main(String args[]) throws IOException { - int t = sc.nextInt(); - while(t-->0) { - int n = sc.nextInt(); - ArrayList> adj = new ArrayList(); - for(int i = 0;i tm = new TreeMap(Collections.reverseOrder()); - for(int i = 0;i -#include -#include - -#include - -#include -#include - -#ifdef GRINDSET -#include ""../debug.h"" -#else -#define debug(...) ; -#define print(...) ; -#endif - -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pii; -typedef pair pll; - -typedef vector vi; -typedef vector> vvi; -typedef vector>> vvvi; -typedef vector vll; -typedef vector> vvll; -typedef vector>> vvvll; - -template -concept iterable = - requires(T a) { - { std::begin(a) } -> std::input_iterator; - { std::end(a) } -> std::sentinel_for; - } && - !std::convertible_to; - -template -requires iterable -std::ostream& operator<<(std::ostream& out, const T& a); - -template -std::ostream& operator<<(std::ostream& out, const std::pair& a); - -template -requires iterable -std::istream& operator>>(std::istream& in, T& a); - -template -std::istream& operator>>(std::istream& in, std::pair& a); - -template -requires iterable -std::ostream& operator<<(std::ostream& out, const T& a) { - for (auto& e : a) { - out << e << "" ""; - } - out << ""\n""; - return out; -} - -template -std::ostream& operator<<(std::ostream& out, const std::pair& a) { - out << a.first << "": "" << a.second << ""\n""; - return out; -} - -template -requires iterable -std::istream& operator>>(std::istream& in, T& a) { - for (auto& e : a) { - in >> e; - } - return in; -} - -template -std::istream& operator>>(std::istream& in, std::pair& a) { - in >> a.first >> a.second; - return in; -} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int kMaxN = 2e5 + 5; -vi g[kMaxN]; -int snd[kMaxN]; -int low[kMaxN]; - -void DFS(int v, int p = 0) { - low[v] = -1; - int max_low = -1; - int max_deg = 0; - for (int u : g[v]) { - if (u != p) { - DFS(u, v); - max_low = max(max_low, low[u]); - low[v] = max({low[v], low[u]}); - if (g[u].size() > 1) { - low[v] = max(low[v], (int)g[u].size()); - } - max_deg = max(max_deg, (int)g[u].size()); - } - } - debug(v, snd[v]); - if (g[v].size() > 1 || !p) { - snd[v] = max((int)g[v].size() + max_low - 1, (int)(g[v].size()) - 2 + max_deg); - } else { - snd[v] = 0; - } - debug(snd[v], max_low, low[v]); -} - -void Solve() { - int n; - cin >> n; - - for (int i = 1; i <= n; ++i) { - g[i].clear(); - } - - for (int i = 1; i < n; ++i) { - int u, v; - cin >> u >> v; - g[u].push_back(v); - g[v].push_back(u); - } - - DFS(1); - // for (int i = 1; i <= n; ++i) { - // cout << snd[i] << "" ""; - // } - // cout << ""\n""; - cout << *std::max_element(snd + 1, snd + 1 + n) << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) { - Solve(); - } -} -","#include -#include -#include - -#include - -#include -#include - -#ifdef GRINDSET -#include ""../debug.h"" -#else -#define debug(...) ; -#define print(...) ; -#endif - -using namespace std; - -typedef long long ll; -typedef unsigned long long ull; -typedef pair pii; -typedef pair pll; - -typedef vector vi; -typedef vector> vvi; -typedef vector>> vvvi; -typedef vector vll; -typedef vector> vvll; -typedef vector>> vvvll; - -template -concept iterable = - requires(T a) { - { std::begin(a) } -> std::input_iterator; - { std::end(a) } -> std::sentinel_for; - } && - !std::convertible_to; - -template -requires iterable -std::ostream& operator<<(std::ostream& out, const T& a); - -template -std::ostream& operator<<(std::ostream& out, const std::pair& a); - -template -requires iterable -std::istream& operator>>(std::istream& in, T& a); - -template -std::istream& operator>>(std::istream& in, std::pair& a); - -template -requires iterable -std::ostream& operator<<(std::ostream& out, const T& a) { - for (auto& e : a) { - out << e << "" ""; - } - out << ""\n""; - return out; -} - -template -std::ostream& operator<<(std::ostream& out, const std::pair& a) { - out << a.first << "": "" << a.second << ""\n""; - return out; -} - -template -requires iterable -std::istream& operator>>(std::istream& in, T& a) { - for (auto& e : a) { - in >> e; - } - return in; -} - -template -std::istream& operator>>(std::istream& in, std::pair& a) { - in >> a.first >> a.second; - return in; -} - -mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); - -const int kMaxN = 2e5 + 5; -vi g[kMaxN]; -int par[kMaxN]; - -void DFS(int v, int p = 0) { - par[v] = p; - for (int u : g[v]) { - if (u != p) { - DFS(u, v); - } - } -} - -void Solve() { - int n; - cin >> n; - - for (int i = 1; i <= n; ++i) { - g[i].clear(); - } - - for (int i = 1; i < n; ++i) { - int u, v; - cin >> u >> v; - g[u].push_back(v); - g[v].push_back(u); - } - - vi ord(n + 1); - iota(ord.begin(), ord.end(), 0); - sort(ord.begin() + 1, ord.end(), [] (int i, int j) { return g[i].size() > g[j].size(); }); - - int ans = g[ord[1]].size() + g[ord[2]].size() - 2; - DFS(ord[1]); - - bool ok = false; - for (int i = 2; i <= n; ++i) { - if (par[ord[i]] != ord[1] && g[ord[i]].size() == g[ord[2]].size()) { - ans++; - ok = true; - break; - } - } - - if (!ok && g[ord[2]].size() == g[ord[1]].size()) { - DFS(ord[2]); - for (int i = 1; i <= n; ++i) { - if (i != 2 && par[ord[i]] != ord[2] && g[ord[i]].size() == g[ord[2]].size()) { - ans++; - break; - } - } - } - - cout << ans << ""\n""; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) { - Solve(); - } -} -",2 -Mr.Doap,2063C - Remove Exactly Two,c++17 ,306318294,306319713,"#include - -using namespace std; - -bool isInSet(pair pr, set> &s) { - return s.find(pr) != s.end(); -} - -void solve(){ - int n; - cin>>n; - set> edge_set; - vector> deg(n); - for(int i=0;i>u>>v; - --u,--v; - edge_set.insert(make_pair(u,v)); - edge_set.insert(make_pair(v,u)); - deg[u].first++; - deg[v].first++; - } - if (n==2) { - cout<<""0\n""; - return; - } - sort(deg.begin(), deg.end()); - int ans = 0; - for(int i=n-1;i>=n-3;i--) { - for(int j=i-1;j>=n-3;j--) { - ans = max(ans, deg[i].first + deg[j].first - (isInSet(make_pair(deg[i].second, deg[j].second), edge_set) ? 1: 0)); - } - } - cout<<(ans-1)<<'\n'; -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t=1; - cin>>t; - while(t--){ - solve(); - } - return 0; -}","#include - -using namespace std; - -bool isInSet(pair pr, set> &s) { - return s.find(pr) != s.end(); -} - -void solve(){ - int n; - cin>>n; - set> edge_set; - vector> deg(n); - for(int i=0;i>u>>v; - --u,--v; - edge_set.insert(make_pair(u,v)); - edge_set.insert(make_pair(v,u)); - deg[u].first++; - deg[v].first++; - } - if (n==2) { - cout<<""0\n""; - return; - } - sort(deg.begin(), deg.end()); - int ans = 0; - for(int i=n-2;i>=0;i--) { - int j=n-1; - ans = max(ans, deg[i].first + deg[j].first - (isInSet(make_pair(deg[i].second, deg[j].second), edge_set) ? 1: 0)); - } - ans = max(ans, deg[n-2].first + deg[n-3].first - (isInSet(make_pair(deg[n-2].second, deg[n-3].second), edge_set) ? 1: 0)); - cout<<(ans-1)<<'\n'; -} - -int main(){ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int t=1; - cin>>t; - while(t--){ - solve(); - } - return 0; -}",2 -roshan_saini_18,2063C - Remove Exactly Two,c++20 ,306071863,306076574,"#include -using namespace std; -#define ll long long int - -int main() { - ll t; - cin >> t; - - while (t--) { - ll z; - cin >> z; - vector> tree(z + 1); - - for (ll i = 0; i < z - 1; i++) { - ll x, y; - cin >> x >> y; - tree[x].insert(y); - tree[y].insert(x); - } - - ll connected = 0, idx = 1; - - // Finding the most connected node - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ll ans = 0; - ans += tree[idx].size(); - - // Remove first selected node's edges - for (auto x : tree[idx]) { - tree[x].erase(idx); - } - tree[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ans += tree[idx].size(); - cout << ans-1 << endl; - } - - return 0; -} -","#include -using namespace std; -#define ll long long int - -int main() { - ll t; - cin >> t; - - while (t--) { - ll z; - cin >> z; - vector> tree(z + 1); - - for (ll i = 0; i < z - 1; i++) { - ll x, y; - cin >> x >> y; - tree[x].insert(y); - tree[y].insert(x); - } - vector> tree1=tree; - ll connected = 0, idx = 1; - - // Finding the most connected node - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ll ans = 1; - ans += tree[idx].size()-1; - // Remove first selected node's edges - for (auto x : tree[idx]) { - tree[x].erase(idx); - } - tree[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ans += tree[idx].size()-1; - - - connected = 0; - idx = 1; - - // Finding the most connected node - for (ll i = z; i >=1; i--) { - if (connected < (ll)tree1[i].size()) { - connected = tree1[i].size(); - idx = i; - } - } - - ll ans1 = 1; - ans1 += tree1[idx].size()-1; - // Remove first selected node's edges - for (auto x : tree1[idx]) { - tree1[x].erase(idx); - } - tree1[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree1[i].size()) { - connected = tree1[i].size(); - idx = i; - } - } - - ans1 += tree1[idx].size()-1; - cout < - -using namespace std; -using ll = long long; - -int main(){ - ll t; - cin>>t; - while(t--){ - ll n, x, y, ans = 0, maxNeighbors = -1, eleRemoved = 1; - cin>>n; - vector> adj(n + 1); - vector neighbors(n + 1, 0); - for(ll i = 0 ; i < n - 1 ; i++){ - cin>>x>>y; - adj[x].push_back(y); - adj[y].push_back(x); - } - for(ll i = 1 ; i <= n ; i++) neighbors[i] = adj[i].size(); - for(ll k = 1 ; k <= 2 ; k++){ - maxNeighbors = -1, eleRemoved = 1; - for(ll i = 1 ; i <= n ; i++){ - if(maxNeighbors < neighbors[i]){ - maxNeighbors = neighbors[i]; - eleRemoved = i; - } - } - ans += maxNeighbors; - for(auto it : adj[eleRemoved]) neighbors[it]--; - neighbors[eleRemoved] = -1; - } - ans -= 1; - cout< - -using namespace std; -using ll = long long; - -int main(){ - ll t; - cin>>t; - while(t--){ - ll n, x, y, ans = 0, maxNeighbors = -1, eleRemoved = 1; - cin>>n; - vector> adj(n + 1); - vector neighbors(n + 1, 0); - for(ll i = 0 ; i < n - 1 ; i++){ - cin>>x>>y; - adj[x].push_back(y); - adj[y].push_back(x); - } - for(ll i = 1 ; i <= n ; i++) neighbors[i] = adj[i].size(); - for(ll k = 1 ; k <= 2 ; k++){ - maxNeighbors = -1, eleRemoved = 1; - for(ll i = 1 ; i <= n ; i++){ - if(maxNeighbors < neighbors[i]){ - maxNeighbors = neighbors[i]; - eleRemoved = i; - } - else if(maxNeighbors == neighbors[i]){ - ll sum1 = 0, sum2 = 0; - for(auto it : adj[eleRemoved]) sum1 += neighbors[it]; - for(auto it : adj[i]) sum2 += neighbors[it]; - if(sum2 < sum1) eleRemoved = i; - } - } - ans += maxNeighbors; - for(auto it : adj[eleRemoved]) neighbors[it]--; - neighbors[eleRemoved] = -1; - } - ans -= 1; - cout< -using namespace std; -vector num; -int cmp(int a,int b) -{ - if(num[a]>num[b]) return 1; - else return 0; -} -int main() -{ - cin.tie(0); - ios::sync_with_stdio(false); - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - num.resize(n+1); - for(int i=1;i<=n;i++) - { - num[i] = 0; - } - vector big(n+1); - for(int i=1;i<=n;i++) - { - big[i] = i; - } - map,int> mp; - for(int i=1;i> u >> v; - mp[{v,u}]++; - mp[{u,v}]++; - num[u]++; - num[v]++; - } - int ans = 1; - sort(big.begin()+1,big.end(),cmp); - if(num[big[1]]!=num[big[2]]) - { - // cout <<""num ""<< num[big[1]] << ' ' << num[big[2]] <<'\n'; - ans += num[big[1]]+num[big[2]]-3; - int i = 2; - while(i<=n&&num[big[i]]==num[big[2]]) - { - if(!mp[{big[i],big[1]}]) - { - ans++; - break; - } - i++; - } - cout << ans <<'\n'; - } - else - { - ans += 2*num[big[1]]-3; - int k = 2; - while(k<=n&&num[big[k]]==num[big[1]]) - { - k++; - } - k--; - if(k>=3) ans++; - else - { - if(mp[{big[1],big[2]}]==0) ans++; - } - // int edge = 0; - // for(auto& [a,_] : mp) - // { - // if(a.first<=k&&a.second<=k) edge++; - // } - - // if() - cout << ans << '\n'; - } - } - return 0; -}","#include -using namespace std; -vector num; -int cmp(int a,int b) -{ - if(num[a]>num[b]) return 1; - else return 0; -} -int main() -{ - cin.tie(0); - ios::sync_with_stdio(false); - int t; - cin >> t; - while(t--) - { - int n; - cin >> n; - num.resize(n+1); - for(int i=1;i<=n;i++) - { - num[i] = 0; - } - vector big(n+1); - for(int i=1;i<=n;i++) - { - big[i] = i; - } - map,int> mp; - for(int i=1;i> u >> v; - mp[{v,u}]++; - mp[{u,v}]++; - num[u]++; - num[v]++; - } - int ans = 1; - sort(big.begin()+1,big.end(),cmp); - if(num[big[1]]!=num[big[2]]) - { - // cout <<""num ""<< num[big[1]] << ' ' << num[big[2]] <<'\n'; - ans += num[big[1]]+num[big[2]]-3; - int i = 2; - while(i<=n&&num[big[i]]==num[big[2]]) - { - if(!mp[{big[i],big[1]}]) - { - ans++; - break; - } - i++; - } - cout << ans <<'\n'; - } - else - { - ans += 2*num[big[1]]-3; - int k = 2; - while(k<=n&&num[big[k]]==num[big[1]]) - { - k++; - } - k--; - if(k>=3) ans++; - // int edge = 0; - // for(auto& [a,_] : mp) - // { - // if(a.first<=k&&a.second<=k) edge++; - // } - - // if() - cout << ans << '\n'; - } - } - return 0; -}",1 -Brachistochron3,2063C - Remove Exactly Two,c++17 ,305381105,305381128,"#pragma GCC optimize(""Ofast"") -#pragma GCC target(""avx,avx2,fma"") -#include -using namespace std; -/*#include -#include - typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, - __gnu_pbds::tree_order_statistics_node_update> ordered_set;*/ -typedef long long ll; -#define pb push_back -typedef long double ld; -/*int smallestdivisor(int n) -{ - // if divisible by 2 - if (n % 2 == 0) - return 2; - - // iterate from 3 to sqrt(n) - for (int i = 3; i * i <= n; i += 2) { - if (n % i == 0) - return i; - } - - return n; -}*/ -/*int parent[200005]; -int siz[200005]; -void make_set(ll n){ -for(int i=1;i<=n;i++){parent[i]=i;siz[i]=1;} -} - -int find_set(ll v){ - if(v==parent[v]) - return v; - return parent[v]=find_set(parent[v]); - -} - -void union_set(ll a,ll b){ - a=find_set(a); - b=find_set(b); - if(a!=b){ - if(siz[a]>>& edges,ll n){ - sort(edges.begin(),edges.end()); - make_set(n); - ll sum=0; - for(auto x:edges){ - if(find_set(x.second.first)==find_set(x.second.second)) continue; - union_set(x.second.first,x.second.second); - sum+=x.first; - } - return sum; -}*/ -int vis[300005];//vector level(300005); -//queue q; -/*void bfs(vector>& adj,ll& ans){ - ll src=0; - vis[src]=1; - // level[src]=0; - q.push(src); - while(!q.empty()){ - u=q.top(); - q.pop();vis[u]=1; - for(int v:adj[u]){ - if(vis[v]==1) continue; - // level[v]=level[u]+1; - q.push(v); - } - } -}*/ -void dfs(ll u,vector>& adj){ - vis[u]=1; - - for(auto v:adj[u]){ - - if(vis[v]==1) continue; - - dfs(v,adj); - - - } - - //saari v se action lene k baad kuch u ka check krna h toh this pos-->dp or any - -} -/*void dijkstras(vector>> adj,ll point,vector> &dis){ - - priority_queue> pq; - int src=point; - dis[src][src]=0; - pq.push({0,src}); - - while(!pq.empty()){ - - int u=pq.top().second; - int d=-pq.top().first; - pq.pop(); - - if(dis[src][u]>tt;string pi = ""3.141592653589793238462643383279""; -while(tt--){ ll n;cin>>n;vector> adj(n);vector> p;map,int> m; -for(int i=0;i>x>>y;x--;y--;p.pb({x,y});m[{x,y}]++;m[{y,x}]++; - adj[x].pb(y);adj[y].pb(x); - -} -vector> v; -for(int i=0;i>>>>DSU..................... -int parent[n]; -int size[n]; -void make_set(int n){ -for(int i=1;i<=n;i++){parent[i]=i;size[i]=1;} -} - -int find_set(int v){ - if(v==parent[v]) - return v; - return parent[v]=find_set(parent[v]); - -} - -void union_set(int a,int b){ - a=find_set(a); - b=find_set(b); - if(a!=b){ - if(size[a]>>& adj,vector& s,vector>& dis,ll& n){ - vector> vis(n,vector (n,0)); - priority_queue>> pq; - int src=0; - dis[src][0]=0; - pq.push({0,{src,0}}); - - while(!pq.empty()){ - ll u=pq.top().second.first; - ll d=-pq.top().first; - ll bike= pq.top().second.second; - - pq.pop(); - - - if(vis[u][bike]!=0) continue;// this is an useful optimisation - - for(auto v:adj[u]){ - if(s[u]>s[bike]){ - dis[v.first][bike]=min(dis[v.first][bike],dis[u][bike]+v.second*s[bike]); - pq.push({-dis[v.first][bike],{v.first,bike}}); - } - else{ - dis[v.first][u]=min(dis[v.first][u],dis[u][bike]+v.second*s[u]); - pq.push({-dis[v.first][u],{v.first,u}}); - } - vis[u][bike]++; - - - } - } -}*/ - - - - - - - - - - - -/*ll sum_digit(ll n) -{ - ll num=0; - while(n>0) - { - num+=n%10; - n=n/10; - } - return num; -}*/ -//kisi bhi tough prob me max ya min value k liye binary search is always there to help..... -//first bit of any number is always a divisor of that number........ -//What is convex hull trick????????????????? -//dp mein hum kya krna chah rhe iski puri info honi chahiye kisi bhi point par aese sochna pdega.....states k liye>>>>>>> - -//r.insert(r.begin(), 1 - d);----------->>>>to insert element in starting of an vevtor.......... -/*for(auto it=m.rbegin();it!=m.rend();++it){ - for(int i=0;isecond.size();i++){ - v2.pb(it->second[i]); - } -}*/ -//largest power of a prime number that divides fact! is legendres formula......... -/*#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -*/ -//sometimes long long ko int krne par tle nhi aata(kaafi ajeeb :()) - // Binary search me r=n+1,l=0&&condition:l+1>=1; - } - return res; -}*/ -/*for(int i=0;i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>............................................ -/*ll n,k;cin>>n>>k; - if(n%2==0){ - if(k%n)cout< p(N,0); - vector> g(N); - void dfs(ll vertex){ - for(int child: g[vertex]){ - if(child!=p[vertex]){ - p[child]=vertex; - dfs(child); - a[vertex]+=a[child]; - } - } - if(g[vertex].size()==1&&a[vertex]==0){ - a[vertex]++; - } - }*/ - /*#include -//#include -using namespace std; -//using namespace __gnu_pbds; -//template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define vll vector -#define vvll vector> -#define mll map -#define max(a,b) ((a>b)?a:b) -#define min(a,b) ((a>b)?b:a) -#define pb push_back -#define prll pair -typedef long long ll; -typedef long double ld; -#define int long long -#define mini(x,y) x = min(x,y) -#define maxi(x,y) x = max(x,y) -const ll infl = 0x3f3f3f3f3f3f3f3fLL; -#define ff first -#define ss second -#define rep(i,a,n) for(ll i=a; i=a; i--) -typedef map msl; -#define all(con) con.begin(),con.end() -#define done(x) {cout << x << endl;return;} -#define sz(x) ((long long)x.size()) -#define trav(a,x) for(auto &a:x) -const ll mx=200005; -const ll mod=1e9 + 7; -const ld PI = 3.141592653589793238460; -//DEBUG FUNCTIONS START -#define cerr cout -void __print(ll x) {cerr << x;} -void __print(double x) {cerr << x;} -void __print(long double x) {cerr << x;} -void __print(char x) {cerr << '\'' << x << '\'';} -void __print(const char *x) {cerr << '\""' << x << '\""';} -void __print(const string &x) {cerr << '\""' << x << '\""';} -void __print(bool x) {cerr << (x ? ""true"" : ""false"");} -template -void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} -template -void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "","" : """"), __print(i); cerr << ""}"";} -void _print() {cerr << ""\n"";} -template -void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << "", ""; _print(v...);} -#ifndef ONLINE_JUDGE -//#define deb(x...) cerr << ""["" << #x << ""] = ""; _print(x) -#define deb(x...) _print(x) -#else -#define deb(x...) -#endif -// DEBUG FUNCTIONS END -mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); -uniform_int_distribution rng(0,1); -// ll x=rng(mt); -ll gcd(ll a, ll b){ - if (b == 0) - return a; - return gcd(b, a % b); -} -ll extgcd(ll a,ll b,ll& x,ll& y) { - if (b == 0) { - x = 1; - y = 0; - return a; - } - ll x1, y1; - ll d = extgcd(b, a % b, x1, y1); - x = y1; - y = x1 - y1 * (a / b); - return d; -} -bool isPrime(ll n){ - if (n <= 1) - return false; - if (n <= 3) - return true; - if (n % 2 == 0 || n % 3 == 0) - return false; - for (ll i = 5; i * i <= n; i = i + 6) - if (n % i == 0 || n % (i + 2) == 0) - return false; - return true; -} -bool isPowerOfTwo(ll n) { - if(n==0) - return false; - return ((ll)ceil(log2(n)) == (ll)floor(log2(n))); -} -ll powm(ll a,ll b) { - ll res = 1; - while (b) { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b >>= 1; - } - return res; -} -ll divide(ll a,ll b) { - return (a % mod) * powm(b, mod - 2) % mod; -} -ll mul(ll a,ll b) { - return ((a % mod) * (b % mod)) % mod; -} - -ll add(ll a,ll b) { - return (a % mod + b % mod) % mod; -} -ll Totfun(ll n){ - ll z=n; - if(n%2==0){ - while(n%2==0){ - n/=2; - } - z/=2; - } - for(ll i=3;i*i<=n;i+=2){ - if(isPrime(i)&&n%i==0){ - while(n%i==0){ - n/=i; - } - z-=z/i; - } - } - if(n>1){ - z-=z/n; - } - return z; -} -ll fact[mx]; -ll nCr(ll n,ll r){ - if(r>n||r<0) return 0; - ll z=fact[n]; - z=mul(z,powm(fact[n-r],mod-2)); - z=mul(z,powm(fact[r],mod-2)); - return z; -} -/* -fact[0]=1; -rep(i,1,mx){ - fact[i]=mul(i,fact[i-1]); -} -*/ -/* -vll a[mx]; -ll l[mx],d[mx]; -void dfs(ll x,ll y){ - l[x]=1; d[x]=y; - for(ll i:a[x]) - if(!l[i]) - dfs(i,y+1); -} -void bfs(ll x){ - queue q; - q.push(x); - l[x]=1; - d[x]=0; - while(!q.empty()){ - ll cur=q.front(); - q.pop(); - for(ll i : a[cur]){ - if(1-l[i]){ - q.push(i); - d[i]=d[cur]+1; - l[i]=1; - } - } - } -} -*/ - -/*struct fenwick{ - - int n; - vll bit; - - fenwick(int _n){ - n = _n + 5; - bit.resize(n); - } - - int qry(int i){ - int res = 0; - for(++i; i; i -= i & - i) - res += bit[i]; - return res; - } - - void upd(int i, int val){ - for(++i; i < n; i += i & -i) - bit[i] += val; - } -}; -ll m; -void dfs(ll x,vector>& adj,vector>& dp){ - rep(i,1,m+1) dp[x][i]=1; - for(ll i:adj[x]){ - dfs(i,adj,dp); - if(i>n; - ll a[n]; - //ll m; - cin>>m; - rep(i,0,n) cin>>a[i]; - vll pos[m+1]; - rep(i,0,n){ - pos[a[i]].pb(i); - } - fenwick ft(n); - ll pr[n]; - for(int i=m;i>0;i--){ - for(int j:pos[i]){ - ll lo,hi,mid,l=-1,r=-1; - if(ft.qry(n-1)-ft.qry(j)>0){ - lo=j+1; - hi=n-1; - while(lo0) hi=mid; - else lo=mid+1; - } - l=lo; - } - if(ft.qry(j)>0){ - lo=0; - hi=j-1; - while(lo0) lo=mid; - else hi=mid-1; - } - r=lo; - } - if(l==-1&&r==-1) pr[j]=-1; - else if(l==-1) pr[j]=r; - else if(r==-1) pr[j]=l; - else{ - if(a[r]> adj; - adj.resize(n); - vector> dp(n,vector(m+1)); - ll x=0; - rep(i,0,n){ - if(pr[i]!=-1) adj[pr[i]].pb(i); - else{ - x=i; - } - } - //rep(i,0,n) cout<> t; - while (t--) - solve(); - return 0; -}*/ - ","#pragma GCC optimize(""Ofast"") -#pragma GCC target(""avx,avx2,fma"") -#include -using namespace std; -/*#include -#include - typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, - __gnu_pbds::tree_order_statistics_node_update> ordered_set;*/ -typedef long long ll; -#define pb push_back -typedef long double ld; -/*int smallestdivisor(int n) -{ - // if divisible by 2 - if (n % 2 == 0) - return 2; - - // iterate from 3 to sqrt(n) - for (int i = 3; i * i <= n; i += 2) { - if (n % i == 0) - return i; - } - - return n; -}*/ -/*int parent[200005]; -int siz[200005]; -void make_set(ll n){ -for(int i=1;i<=n;i++){parent[i]=i;siz[i]=1;} -} - -int find_set(ll v){ - if(v==parent[v]) - return v; - return parent[v]=find_set(parent[v]); - -} - -void union_set(ll a,ll b){ - a=find_set(a); - b=find_set(b); - if(a!=b){ - if(siz[a]>>& edges,ll n){ - sort(edges.begin(),edges.end()); - make_set(n); - ll sum=0; - for(auto x:edges){ - if(find_set(x.second.first)==find_set(x.second.second)) continue; - union_set(x.second.first,x.second.second); - sum+=x.first; - } - return sum; -}*/ -int vis[300005];//vector level(300005); -//queue q; -/*void bfs(vector>& adj,ll& ans){ - ll src=0; - vis[src]=1; - // level[src]=0; - q.push(src); - while(!q.empty()){ - u=q.top(); - q.pop();vis[u]=1; - for(int v:adj[u]){ - if(vis[v]==1) continue; - // level[v]=level[u]+1; - q.push(v); - } - } -}*/ -void dfs(ll u,vector>& adj){ - vis[u]=1; - - for(auto v:adj[u]){ - - if(vis[v]==1) continue; - - dfs(v,adj); - - - } - - //saari v se action lene k baad kuch u ka check krna h toh this pos-->dp or any - -} -/*void dijkstras(vector>> adj,ll point,vector> &dis){ - - priority_queue> pq; - int src=point; - dis[src][src]=0; - pq.push({0,src}); - - while(!pq.empty()){ - - int u=pq.top().second; - int d=-pq.top().first; - pq.pop(); - - if(dis[src][u]>tt;string pi = ""3.141592653589793238462643383279""; -while(tt--){ ll n;cin>>n;vector> adj(n);vector> p;map,int> m; -for(int i=0;i>x>>y;x--;y--;p.pb({x,y});m[{x,y}]++;m[{y,x}]++; - adj[x].pb(y);adj[y].pb(x); - -} -vector> v; -for(int i=0;i>>>>DSU..................... -int parent[n]; -int size[n]; -void make_set(int n){ -for(int i=1;i<=n;i++){parent[i]=i;size[i]=1;} -} - -int find_set(int v){ - if(v==parent[v]) - return v; - return parent[v]=find_set(parent[v]); - -} - -void union_set(int a,int b){ - a=find_set(a); - b=find_set(b); - if(a!=b){ - if(size[a]>>& adj,vector& s,vector>& dis,ll& n){ - vector> vis(n,vector (n,0)); - priority_queue>> pq; - int src=0; - dis[src][0]=0; - pq.push({0,{src,0}}); - - while(!pq.empty()){ - ll u=pq.top().second.first; - ll d=-pq.top().first; - ll bike= pq.top().second.second; - - pq.pop(); - - - if(vis[u][bike]!=0) continue;// this is an useful optimisation - - for(auto v:adj[u]){ - if(s[u]>s[bike]){ - dis[v.first][bike]=min(dis[v.first][bike],dis[u][bike]+v.second*s[bike]); - pq.push({-dis[v.first][bike],{v.first,bike}}); - } - else{ - dis[v.first][u]=min(dis[v.first][u],dis[u][bike]+v.second*s[u]); - pq.push({-dis[v.first][u],{v.first,u}}); - } - vis[u][bike]++; - - - } - } -}*/ - - - - - - - - - - - -/*ll sum_digit(ll n) -{ - ll num=0; - while(n>0) - { - num+=n%10; - n=n/10; - } - return num; -}*/ -//kisi bhi tough prob me max ya min value k liye binary search is always there to help..... -//first bit of any number is always a divisor of that number........ -//What is convex hull trick????????????????? -//dp mein hum kya krna chah rhe iski puri info honi chahiye kisi bhi point par aese sochna pdega.....states k liye>>>>>>> - -//r.insert(r.begin(), 1 - d);----------->>>>to insert element in starting of an vevtor.......... -/*for(auto it=m.rbegin();it!=m.rend();++it){ - for(int i=0;isecond.size();i++){ - v2.pb(it->second[i]); - } -}*/ -//largest power of a prime number that divides fact! is legendres formula......... -/*#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -*/ -//sometimes long long ko int krne par tle nhi aata(kaafi ajeeb :()) - // Binary search me r=n+1,l=0&&condition:l+1>=1; - } - return res; -}*/ -/*for(int i=0;i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>............................................ -/*ll n,k;cin>>n>>k; - if(n%2==0){ - if(k%n)cout< p(N,0); - vector> g(N); - void dfs(ll vertex){ - for(int child: g[vertex]){ - if(child!=p[vertex]){ - p[child]=vertex; - dfs(child); - a[vertex]+=a[child]; - } - } - if(g[vertex].size()==1&&a[vertex]==0){ - a[vertex]++; - } - }*/ - /*#include -//#include -using namespace std; -//using namespace __gnu_pbds; -//template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -#define vll vector -#define vvll vector> -#define mll map -#define max(a,b) ((a>b)?a:b) -#define min(a,b) ((a>b)?b:a) -#define pb push_back -#define prll pair -typedef long long ll; -typedef long double ld; -#define int long long -#define mini(x,y) x = min(x,y) -#define maxi(x,y) x = max(x,y) -const ll infl = 0x3f3f3f3f3f3f3f3fLL; -#define ff first -#define ss second -#define rep(i,a,n) for(ll i=a; i=a; i--) -typedef map msl; -#define all(con) con.begin(),con.end() -#define done(x) {cout << x << endl;return;} -#define sz(x) ((long long)x.size()) -#define trav(a,x) for(auto &a:x) -const ll mx=200005; -const ll mod=1e9 + 7; -const ld PI = 3.141592653589793238460; -//DEBUG FUNCTIONS START -#define cerr cout -void __print(ll x) {cerr << x;} -void __print(double x) {cerr << x;} -void __print(long double x) {cerr << x;} -void __print(char x) {cerr << '\'' << x << '\'';} -void __print(const char *x) {cerr << '\""' << x << '\""';} -void __print(const string &x) {cerr << '\""' << x << '\""';} -void __print(bool x) {cerr << (x ? ""true"" : ""false"");} -template -void __print(const pair &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} -template -void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "","" : """"), __print(i); cerr << ""}"";} -void _print() {cerr << ""\n"";} -template -void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << "", ""; _print(v...);} -#ifndef ONLINE_JUDGE -//#define deb(x...) cerr << ""["" << #x << ""] = ""; _print(x) -#define deb(x...) _print(x) -#else -#define deb(x...) -#endif -// DEBUG FUNCTIONS END -mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); -uniform_int_distribution rng(0,1); -// ll x=rng(mt); -ll gcd(ll a, ll b){ - if (b == 0) - return a; - return gcd(b, a % b); -} -ll extgcd(ll a,ll b,ll& x,ll& y) { - if (b == 0) { - x = 1; - y = 0; - return a; - } - ll x1, y1; - ll d = extgcd(b, a % b, x1, y1); - x = y1; - y = x1 - y1 * (a / b); - return d; -} -bool isPrime(ll n){ - if (n <= 1) - return false; - if (n <= 3) - return true; - if (n % 2 == 0 || n % 3 == 0) - return false; - for (ll i = 5; i * i <= n; i = i + 6) - if (n % i == 0 || n % (i + 2) == 0) - return false; - return true; -} -bool isPowerOfTwo(ll n) { - if(n==0) - return false; - return ((ll)ceil(log2(n)) == (ll)floor(log2(n))); -} -ll powm(ll a,ll b) { - ll res = 1; - while (b) { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b >>= 1; - } - return res; -} -ll divide(ll a,ll b) { - return (a % mod) * powm(b, mod - 2) % mod; -} -ll mul(ll a,ll b) { - return ((a % mod) * (b % mod)) % mod; -} - -ll add(ll a,ll b) { - return (a % mod + b % mod) % mod; -} -ll Totfun(ll n){ - ll z=n; - if(n%2==0){ - while(n%2==0){ - n/=2; - } - z/=2; - } - for(ll i=3;i*i<=n;i+=2){ - if(isPrime(i)&&n%i==0){ - while(n%i==0){ - n/=i; - } - z-=z/i; - } - } - if(n>1){ - z-=z/n; - } - return z; -} -ll fact[mx]; -ll nCr(ll n,ll r){ - if(r>n||r<0) return 0; - ll z=fact[n]; - z=mul(z,powm(fact[n-r],mod-2)); - z=mul(z,powm(fact[r],mod-2)); - return z; -} -/* -fact[0]=1; -rep(i,1,mx){ - fact[i]=mul(i,fact[i-1]); -} -*/ -/* -vll a[mx]; -ll l[mx],d[mx]; -void dfs(ll x,ll y){ - l[x]=1; d[x]=y; - for(ll i:a[x]) - if(!l[i]) - dfs(i,y+1); -} -void bfs(ll x){ - queue q; - q.push(x); - l[x]=1; - d[x]=0; - while(!q.empty()){ - ll cur=q.front(); - q.pop(); - for(ll i : a[cur]){ - if(1-l[i]){ - q.push(i); - d[i]=d[cur]+1; - l[i]=1; - } - } - } -} -*/ - -/*struct fenwick{ - - int n; - vll bit; - - fenwick(int _n){ - n = _n + 5; - bit.resize(n); - } - - int qry(int i){ - int res = 0; - for(++i; i; i -= i & - i) - res += bit[i]; - return res; - } - - void upd(int i, int val){ - for(++i; i < n; i += i & -i) - bit[i] += val; - } -}; -ll m; -void dfs(ll x,vector>& adj,vector>& dp){ - rep(i,1,m+1) dp[x][i]=1; - for(ll i:adj[x]){ - dfs(i,adj,dp); - if(i>n; - ll a[n]; - //ll m; - cin>>m; - rep(i,0,n) cin>>a[i]; - vll pos[m+1]; - rep(i,0,n){ - pos[a[i]].pb(i); - } - fenwick ft(n); - ll pr[n]; - for(int i=m;i>0;i--){ - for(int j:pos[i]){ - ll lo,hi,mid,l=-1,r=-1; - if(ft.qry(n-1)-ft.qry(j)>0){ - lo=j+1; - hi=n-1; - while(lo0) hi=mid; - else lo=mid+1; - } - l=lo; - } - if(ft.qry(j)>0){ - lo=0; - hi=j-1; - while(lo0) lo=mid; - else hi=mid-1; - } - r=lo; - } - if(l==-1&&r==-1) pr[j]=-1; - else if(l==-1) pr[j]=r; - else if(r==-1) pr[j]=l; - else{ - if(a[r]> adj; - adj.resize(n); - vector> dp(n,vector(m+1)); - ll x=0; - rep(i,0,n){ - if(pr[i]!=-1) adj[pr[i]].pb(i); - else{ - x=i; - } - } - //rep(i,0,n) cout<> t; - while (t--) - solve(); - return 0; -}*/ - ",2 -supermakslikegta5,2063C - Remove Exactly Two,c++23 ,305931598,305930979,"#include -using namespace std; -using ll = long long; -void solve() -{ - int n; - cin >> n; - vector> e(n); - vector deg(n); - for (int i = 1;i < n;i++) - { - int v,u; - cin >> v >> u; - v--; - u--; - e[u].push_back(v); - e[v].push_back(u); - deg[u]++; - deg[v]++; - } - sort(e.begin(),e.end(),[](vector a,vector b) {return a.size() > b.size();}); - int mx = e[0].size(); - int premx = -1; - int cntmx = 0; - int cntpremx = 0; - for (int i = 0;i < n;i++) - { - if (e[i].size() == mx) cntmx++; - if (i && e[i - 1].size() == mx && e[i].size() != mx) premx = e[i].size(); - if (e[i].size() == premx) cntpremx++; - } - int ans = 0; - for (int i = 0;e[i].size() == mx;i++) - { - int curcntmx = 0; - int curcntpremx = 0; - for (auto& adj : e[i]) - { - if (deg[adj] == mx) curcntmx++; - else if (deg[adj] == premx) curcntpremx++; - } - if (cntmx - curcntmx - 1 > 0) ans = max(ans,mx * 2 - 1); - else if (cntpremx - curcntpremx > 0) ans = max(ans,mx + premx - 1); - if (i != 0) ans = max(ans,mx * 2 - 2); - else ans = max(ans,mx + premx - 2); - } - cout << ans << '\n'; -} -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while(t--) solve(); - return 0; -}","#include -using namespace std; -using ll = long long; -void solve() -{ - int n; - cin >> n; - vector> e(n); - vector deg(n); - for (int i = 1;i < n;i++) - { - int v,u; - cin >> v >> u; - v--; - u--; - e[u].push_back(v); - e[v].push_back(u); - deg[u]++; - deg[v]++; - } - sort(e.begin(),e.end(),[](vector a,vector b) {return a.size() > b.size();}); - int mx = e[0].size(); - int premx = -1; - int cntmx = 0; - int cntpremx = 0; - for (int i = 0;i < n;i++) - { - if (e[i].size() == mx) cntmx++; - if (i && e[i - 1].size() == mx && e[i].size() != mx) premx = e[i].size(); - if (e[i].size() == premx) cntpremx++; - } - int ans = 0; - for (int i = 0; i < n && e[i].size() == mx;i++) - { - int curcntmx = 0; - int curcntpremx = 0; - for (auto& adj : e[i]) - { - if (deg[adj] == mx) curcntmx++; - else if (deg[adj] == premx) curcntpremx++; - } - if (cntmx - curcntmx - 1 > 0) ans = max(ans,mx * 2 - 1); - else if (cntpremx - curcntpremx > 0) ans = max(ans,mx + premx - 1); - else if (i != 0) ans = max(ans,mx * 2 - 2); - else ans = max(ans,mx + premx - 2); - } - cout << ans << '\n'; -} -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while(t--) solve(); - return 0; -}",1 -Yash-G#,2063C - Remove Exactly Two,c++17 ,305579409,305582552,"#include -using namespace std; - -#define int long long -// -#define pb push_back -#define ppb pop_back -#define pii pair -#define vi vector -#define all(v) v.begin(),v.end() -#define ff first -#define ss second -#define vvi(v,n,m,k) vectorv(n,vi(m,k)); -#define endl ""\n"" -#define MOD 998244353 -#define print(v) for(int i=0;i>n; - vectoradj(n); - for(int i=0;i>x>>y; - x--; - y--; - adj[x].pb(y); - adj[y].pb(x); - } - vectorv; - vi incoming(n,0); - for(int i=0;i> t; - while(t--){ - solve(); - } -}","#include -using namespace std; - -#define int long long -// -#define pb push_back -#define ppb pop_back -#define pii pair -#define vi vector -#define all(v) v.begin(),v.end() -#define ff first -#define ss second -#define vvi(v,n,m,k) vectorv(n,vi(m,k)); -#define endl ""\n"" -#define MOD 998244353 -#define print(v) for(int i=0;i>n; - vectoradj(n); - for(int i=0;i>x>>y; - x--; - y--; - adj[x].pb(y); - adj[y].pb(x); - } - vectorv; - vi incoming(n,0); - for(int i=0;i> t; - while(t--){ - solve(); - } -}",2 -VARKALA_THOMA,2063C - Remove Exactly Two,python,304828026,303749743,""""""" -For God so loved the world that he gave his one and only Son, -that whoever believes in him shall not perish but have eternal life. -JOHN 3:16 -"""""" -import random -from math import * -from functools import lru_cache -from itertools import accumulate -from fractions import Fraction -from bisect import bisect_left as bl -from bisect import bisect_right as br -from operator import itemgetter -from collections import Counter,deque,defaultdict -from heapq import heappop as hpop, heappush as hpush -# constants -p = 10**9 + 7 -ANS = ['NO','YES'] -import sys -input = sys.stdin.readline -output = sys.stdout.write -#sys.setrecursionlimit(110000) -# #For large input -# input = sys.stdin.read -# data = input().split() -# Shortcut for input() -def I(): return int(input()) -def S(): return input().strip() -def F(): return float(input()) -def MI(): return map(int, input().split()) -def MS(): return map(str, input().split()) -def MF(): return map(float,input().split()) -def LI(): return list(map(int, input().split())) -def LS(): return list(map(str, input().split())) -def LF(): return list(map(float , input().split())) -# Shortcut for output() -res = [] -def OI(res): output(""\n"".join(res)) -def OL(res): output(""\n"".join("" "".join(i) for i in res)) - - - - - - -t = I() -for _ in range(t): - n = I() - deg = [0]*(n+1) - g = [[] for _ in range(n+1)] - for _ in range(n-1): - u,v = MI() - deg[u] += 1 - deg[v]+=1 - g[u].append(v) - g[v].append(u) - m = max(deg) - if deg.count(m) >= 3: - print(2*m-1) - continue - ans = m - node = deg.index(m) - deg[node] = 0 - for child in g[node]:deg[child]-=1 - ans += (max(deg) - 1) - print(ans) -",""""""" -For God so loved the world that he gave his one and only Son, -that whoever believes in him shall not perish but have eternal life. -JOHN 3:16 -"""""" -import random -from math import * -from functools import lru_cache -from itertools import accumulate -from fractions import Fraction -from bisect import bisect_left as bl -from bisect import bisect_right as br -from operator import itemgetter -from collections import Counter,deque,defaultdict -from heapq import heappop as hpop, heappush as hpush -# constants -p = 10**9 + 7 -ANS = ['NO','YES'] -import sys -input = sys.stdin.readline -output = sys.stdout.write -#sys.setrecursionlimit(110000) -# #For large input -# input = sys.stdin.read -# data = input().split() -# Shortcut for input() -def I(): return int(input()) -def S(): return input().strip() -def F(): return float(input()) -def MI(): return map(int, input().split()) -def MS(): return map(str, input().split()) -def MF(): return map(float,input().split()) -def LI(): return list(map(int, input().split())) -def LS(): return list(map(str, input().split())) -def LF(): return list(map(float , input().split())) -# Shortcut for output() -res = [] -def OI(res): output(""\n"".join(res)) -def OL(res): output(""\n"".join("" "".join(i) for i in res)) - - - - - - -t = I() -while t: - n = I() - deg = [0]*n - g = defaultdict(set) - for _ in range(n-1): - u,v = MI() - g[u-1].add(v-1) - g[v-1].add(u-1) - deg[u-1]+=1 - deg[v-1]+=1 - ans = 0 - #when nodes are adjacent - for node in g: - for child in g[node]: - ans = max(ans,deg[node] + deg[child]-2) - #when two nodes are not adjacent - s = sorted([(deg[i],i) for i in range(n)],reverse = 1) - for _,node1 in s: - for _,node2 in s: - if node1 == node2 or node1 in g[node2]: continue - ans = max(ans, deg[node1] + deg[node2] - 1) - break - print(ans) - t-=1",1 -noir2003,2063C - Remove Exactly Two,c++23 ,304370139,304587795,"#include -#define int long long -using namespace std; -const int mod = 998244353; - -void solve() -{ - int n; - cin>>n; - - vector subTreeMax(n+1,0); - vector tree[n+1]; - - for(int i = 0; i < n-1; ++i) { - int u,v; - cin>>u>>v; - - tree[u].push_back(v); - tree[v].push_back(u); - } - - int res = 0; - - function dfs = [&](int node, int parent) { - for(auto child : tree[node]) { - if(child == parent) continue; - dfs(child,node); - subTreeMax[node] = max(subTreeMax[node], (int)tree[child].size()); - subTreeMax[node] = max(subTreeMax[node], subTreeMax[child]); - } - }; - - function dfs2 = [&](int node, int parent) { - for(auto child : tree[node]) { - if(child == parent) continue; - res = max(res,(int)tree[child].size() + (int)tree[node].size() - 2ll); - res = max(res,(int)tree[node].size() + subTreeMax[child] - 1); - dfs(child,node); - } - }; - - dfs(1,-1); - dfs2(1,-1); - - // for(int i = 1; i <= n; ++i) { - // cout<> tc; - while (tc--) - { - solve(); - } - return 0; -}","#include -#define int long long -using namespace std; -const int mod = 998244353; - -void solve() -{ - int n; - cin>>n; - - vectortree[n+1]; - vector degree(n+1); - - for(int i = 1; i < n; ++i) { - int u,v; - cin>>u>>v; - - tree[u].push_back(v); - tree[v].push_back(u); - - degree[u]++; - degree[v]++; - } - - vector sorted_degree = degree; - sort(sorted_degree.begin(),sorted_degree.end()); - - int res = 1; - int ans = 0; - - for(int first_node = 1; first_node <= n; ++first_node) { - res = degree[first_node]; - - vector near_nodes; - near_nodes.push_back(degree[first_node]); - - for(auto child : tree[first_node]) { - near_nodes.push_back(degree[child]); - } - - sort(near_nodes.rbegin(),near_nodes.rend()); - - vector rem; - int mx = -1; - - for(auto deg : near_nodes) { - if(deg == sorted_degree[(int)sorted_degree.size() - 1]){ - sorted_degree.pop_back(); - rem.push_back(deg); - } - } - - if(sorted_degree.size()) { - mx = max(mx, sorted_degree[(int)sorted_degree.size() - 1]); - } - - for(auto child : tree[first_node]) { - mx = max(mx, degree[child] - 1); - } - - reverse(rem.begin(),rem.end()); - - for(auto it : rem) { - sorted_degree.push_back(it); - } - - ans = max(ans, res + mx - 1); - } - - cout<> tc; - while (tc--) - { - solve(); - } - return 0; -}",2 -Nehal21,2063C - Remove Exactly Two,c++17 ,306558140,306556078," -// Author // - -// Md Nehal // - - - - -#include - - - -using namespace std; - - - -void solve(){ - int n; - cin>>n; - int arr[n+10]; - for(int i=0;i<=n+6;++i){ - arr[i] =0; - } - vectorgraph[n+10]; - for(int i=1;i>u>>v; - graph[v].push_back(u); - graph[u].push_back(v); - arr[u]++,arr[v]++; - } - int maxi =0; - for(int i=1;i<=n;++i){ - maxi = max(arr[i],maxi); - } - int cnt =0; - for(int i=1;i<=n;++i){ - if(arr[i] == maxi){ - cnt++; - } - } - if(cnt>2){ - cout<>t; - while(t--){ - solve(); - } - return 0; -}"," -// Author // - -// Md Nehal // - - - - -#include - - - -using namespace std; - - - -void solve(){ - int n; - cin>>n; - int arr[n+10]; - for(int i=0;i<=n+6;++i){ - arr[i] =0; - } - vectorgraph[n+10]; - for(int i=1;i>u>>v; - graph[v].push_back(u); - graph[u].push_back(v); - arr[u]++,arr[v]++; - } - int maxi =0; - for(int i=1;i<=n;++i){ - maxi = max(arr[i],maxi); - } - int result =maxi,ind=0; - for(int i=1;i<=n;++i){ - if(arr[i] == maxi){ - ind = i; - for(auto &child:graph[i]){ - arr[child]--; - } - break ; - } - } - maxi =0; - for(int i=1;i<=n;++i){ - if(i == ind){ - continue; - } - maxi = max(maxi,arr[i]); - } - cout<>t; - while(t--){ - solve(); - } - return 0; -}",1 -Pradeepkj154,2063C - Remove Exactly Two,c++23 ,304228101,304216308,"#include -#define ll int64_t -using namespace std; - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) - { - int n; - cin >> n; - set> edges; - vector indegree(n + 1, 0); - for (int i = 0; i < n - 1; i++) - { - int first, second; - cin >> first >> second; - indegree[first]++; - indegree[second]++; - edges.insert({first, second}); - edges.insert({second, first}); - } - vector> degree; - for (int i = 1; i <= n; i++) - { - degree.push_back({indegree[i], i}); - } - sort(degree.rbegin(), degree.rend()); - - int res = 0; - // first we will do for non adjacent - for (int i = 0; i < n; i++) - { - int degree1 = degree[i].first; - int ele1 = degree[i].second; - for (int j = i + 1; j < n; j++) - { - int degree2 = degree[j].first; - int ele2 = degree[j].second; - if (edges.count({ele1, ele2})) - continue; - else - { - res = max(res, degree1 + degree2 - 1); - break; - } - } - } - // now we will do for adjacent elements - for (auto a : edges) - { - int first = a.first; - int second = a.second; - int degree1 = indegree[first]; - int degree2 = indegree[second]; - res = max(res, degree1 + degree2 - 2); - } - cout << res << endl; - } - - return 0; -} -","#include -#define ll int64_t -using namespace std; - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - ll t; - cin >> t; - while (t--) - { - int n; - cin >> n; - - vector> adj(n + 1); - for (int i = 0; i < n - 1; i++) - { - int first, second; - cin >> first >> second; - adj[first].insert(second); - adj[second].insert(first); - } - int maxi = 0, index = 0; - - for (int i = 1; i <= n; i++) - { - int key = i; - unordered_set &neighbors = adj[i]; - if (neighbors.size() > maxi) - { - maxi = neighbors.size(); - index = key; - } - } - unordered_set &byebye = adj[index]; - // cout << index << endl; - for (auto a : byebye) - { - int currele = a; - adj[currele].erase(index); - } - byebye.clear(); - byebye.insert(-1); - - maxi = -1, index = 0; - - for (int i = 1; i <= n; i++) - { - int key = i; - unordered_set &neighbors = adj[i]; - if (neighbors.count(-1)) - { - // cout << i << endl; - continue; - } - - if ((int)neighbors.size() > maxi) - { - - maxi = neighbors.size(); - index = i; - } - } - - unordered_set &byebye2 = adj[index]; - // cout << index << endl; - for (auto a : byebye2) - { - int currele = a; - adj[currele].erase(index); - } - byebye2.clear(); - byebye2.insert(-1); - int res = 0; - unordered_set selected; - for (int i = 1; i <= n; i++) - { - unordered_set &neighbors = adj[i]; - if (neighbors.count(-1) || selected.count(i)) - continue; - selected.insert(i); - for (auto a : neighbors) - { - selected.insert(a); - } - res++; - } - cout << res << endl; - } - return 0; -} -",1 -Twits,2063C - Remove Exactly Two,c++20 ,305016229,305017298,"#include -using namespace std; -#define fi first -#define sec second - -void solve(){ - int n; - cin>>n; - - - vector adj[n+2]; - - for(int i=0; i>u>>v; - adj[u].push_back(v); - adj[v].push_back(u); - } - - vector ch(n+2); - vector> x; - - for(int i=1; i<=n; i++){ - x.push_back({adj[i].size(), i}); - } - - sort(x.begin(), x.end()); - reverse(x.begin(), x.end()); - - if(x[0].fi == 1){ - cout<<""0\n""; - return; - } - - for(auto k : adj[x[0].sec]){ - ch[k] = 1; - } - int ans = x[0].fi; - int mx = -2; - - for(int i=1; i>t; - while(t--){ - solve(); - } - - return 0; -} -","#include -using namespace std; - -#define fi first -#define sec second -#define ll long long - -void solve(){ - ll n; - cin>>n; - - vector adj[n+2]; - - for(ll i=0; i>u>>v; - adj[u].push_back(v); - adj[v].push_back(u); - } - - vector> x; - - for(ll i=1; i<=n; i++){ - x.push_back({adj[i].size(), i}); - } - - sort(x.begin(), x.end()); - reverse(x.begin(), x.end()); - - if(x[0].fi == 1){ - cout<<""0\n""; - return; - } - - ll real_ans = 0; - for(ll j=0; j ch(n+2); - for(auto k : adj[x[j].sec]){ - ch[k] = 1; - } - - ll ans = x[j].fi; - ll mx = -2; - - for(ll i=j+1; i>t; - while(t--){ - solve(); - } - - return 0; -} -",2 -EricW#,2063C - Remove Exactly Two,c++23 ,304368855,304370254,"#include -#define endl '\n' -#define int long long -using namespace std; - -const int inf = INT_MAX; -const int mod = 998244353; - -void solve() { - int n; cin >> n; - vector> adj(n + 1); - vector deg(n + 1); - vector mx(n + 1), dp(n + 1); - for (int i = 1, u, v;i < n;i++) { - cin >> u >> v; - adj[u].emplace_back(v); - adj[v].emplace_back(u); - deg[u] += 1, deg[v] += 1; - } - auto dfs = [&](auto &&self, int u, int pre) -> void { - vector degs; - for (auto &v : adj[u]) { - if (v == pre) continue; - self(self, v, u); - degs.emplace_back(deg[v]); - dp[u] = max(dp[u], dp[v]); - dp[u] = max(deg[u] + deg[v] - 2, dp[u]); - dp[u] = max(dp[u], deg[u] + mx[v] - 1); - mx[u] = max({mx[u], mx[v], deg[v]}); - } - sort(degs.begin(), degs.end(), greater()); - if (degs.size() >= 2) - dp[u] = max(dp[u], degs[0] + degs[1] - 1); - }; - dfs(dfs, 1, 0); - cout << dp[1] << endl; -} - -signed main() { - ios::sync_with_stdio(false), cin.tie(0); - int T = 1; cin >> T; - while (T--) solve(); - return 0; -}","#include -#define endl '\n' -#define int long long -using namespace std; - -const int inf = INT_MAX; -const int mod = 998244353; - -void solve() { - int n; cin >> n; - vector> adj(n + 1); - vector deg(n + 1); - vector mx(n + 1), dp(n + 1); - for (int i = 1, u, v;i < n;i++) { - cin >> u >> v; - adj[u].emplace_back(v); - adj[v].emplace_back(u); - deg[u] += 1, deg[v] += 1; - } - auto dfs = [&](auto &&self, int u, int pre) -> void { - int maxdeg = 0, maxdeg2 = 0; - for (auto &v : adj[u]) { - if (v == pre) continue; - self(self, v, u); - dp[u] = max(dp[u], dp[v]); - dp[u] = max(deg[u] + deg[v] - 2, dp[u]); - dp[u] = max(dp[u], deg[u] + mx[v] - 1); - dp[u] = max(dp[u], deg[v] + maxdeg - 1); - dp[u] = max(dp[u], maxdeg2 + deg[v] - 1); - dp[u] = max(dp[u], mx[v] + maxdeg - 1); - dp[u] = max(dp[u], mx[v] + maxdeg2 - 1); - mx[u] = max({mx[u], mx[v], deg[v]}); - maxdeg2 = max(maxdeg2, mx[u]); - maxdeg = max(maxdeg, deg[v]); - } - }; - dfs(dfs, 1, 0); - cout << dp[1] << endl; -} - -signed main() { - ios::sync_with_stdio(false), cin.tie(0); - int T = 1; cin >> T; - while (T--) solve(); - return 0; -}",2 -jgmeet#,2063C - Remove Exactly Two,c++20 ,305032867,305027834,"#include -#include -#include -#include -#include -#include - -using namespace std; - -#define endl ""\n"" -#define ll long long -#define dl double long -#define pb push_back -const int mod = 998244353; - -void solve() { - - int n; - cin >> n; - - unordered_set adj[n+1]; - vector> edges; - - for(int i=1; i> u >> v; - edges.pb({u,v}); - - adj[u].insert(v); - adj[v].insert(u); - } - - int ans = 0; - - for(auto& it: edges) { - int eu = adj[it.first].size(); - int ev = adj[it.second].size(); - - ans = max(ans, eu+ev-2); - } - - vector> numOfAdjEdges(n+1); - numOfAdjEdges[0] = {0,0}; - - for(int i=1; i<=n; i++) { - numOfAdjEdges[i] = {-adj[i].size(), i}; - } - - sort(numOfAdjEdges.begin(), numOfAdjEdges.end()); - - - - - for(int j=0; j> testCases; - - while(testCases--) solve(); - return 0; -}","#include -#include -#include -#include -#include -#include - -using namespace std; - -#define endl ""\n"" -#define ll long long -#define dl double long -#define pb push_back -const int mod = 998244353; - -int getVertex(int& n, unordered_set adj[]) { - -} - -void solve() { - - int n; - cin >> n; - - unordered_set adj[n+1]; - - for(int i=1; i> u >> v; - - adj[u].insert(v); - adj[v].insert(u); - } - - vector> numOfAdjEdges(n+1); - numOfAdjEdges[0] = {0,0}; - - for(int i=1; i<=n; i++) { - numOfAdjEdges[i] = {-adj[i].size(), i}; - } - - sort(numOfAdjEdges.begin(), numOfAdjEdges.end()); - // for(int i=0; i> testCases; - - while(testCases--) solve(); - return 0; -}",1 -VoidRunner,2063C - Remove Exactly Two,c++17 ,305989646,305990096,"#include -using namespace std; - -#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL) -#define int long long int -#define dec greater>() -#define all(x) (x).begin(), (x).end() -#define mod 1000000007 -bool sortbysec(const pair &a, const pair &b) { return (a.second < b.second); } - -void solve() -{ - int n; - cin>>n; - vector in_degree(n + 1); - map,int>mp; - for(int i=0; i>u>>v; - in_degree[u]++; - in_degree[v]++; - mp[{u,v}]++; - mp[{v,u}]++; - } - vector>vp; - for(int i=1; i<=n; i++){ - vp.push_back({in_degree[i],i}); - } - sort(all(vp),dec); - //for(auto &[x,y] : vp)cout<>t; - while(t--) - solve(); -}","#include -using namespace std; - -#include -#include -using namespace __gnu_pbds; -#define ordered_set tree, rb_tree_tag, tree_order_statistics_node_update> - -#define fast ios_base::sync_with_stdio(false);cin.tie(NULL) -#define int long long int -#define dec greater>() -#define all(x) (x).begin(), (x).end() -#define mod 1000000007 -bool sortbysec(const pair &a, const pair &b) { return (a.second < b.second); } - -void solve() -{ - int n; - cin>>n; - vector in_degree(n + 1); - map,int>mp; - for(int i=0; i>u>>v; - in_degree[u]++; - in_degree[v]++; - mp[{u,v}]++; - mp[{v,u}]++; - } - vector>vp; - for(int i=1; i<=n; i++){ - vp.push_back({in_degree[i],i}); - } - sort(all(vp),dec); - //for(auto &[x,y] : vp)cout<>t; - while(t--) - solve(); -}",2 -nbqu,2063C - Remove Exactly Two,c++20 ,304523432,304503323,"#include -using namespace std; - -#define fr(i,s,e) for(ll i=s ; i=e ; i--) -#define ff first -#define ss second -#define pb push_back -typedef long long ll; -typedef vector vll; - -ll MOD=998244353; - -ll fastpow(ll base , ll power){ - ll ans=1; - while(power>0){ - if(power&1){ - ans*=base; - ans%=MOD; - } - power>>=1; - base*=base; - base%=MOD; - } - return ans; -} - -void solve(){ - ll n; - cin >> n; - vector v(n); - vll si(n); - fr(i, 0, n-1){ - ll a, b; - cin >> a >> b; - si[--a]++; - si[--b]++; - v[a].pb(b); - v[b].pb(a); - } - sort(si.begin(), si.end()); - ll cnt = 0, k=0; - fr(i, 0 , n) if(si[n-2] == v[i].size()) cnt++; - fr(i, 0 , n){ - if(si[n-1] == v[i].size()){ - ll c = 0; - for(auto x : v[i]){ - if(v[x].size() == si[n-2]) c++; - } - if(c == cnt) k = 1; - if(si[n-1] == si[n-2] && c != cnt-1) k=-1; - } - } - cout << si[n-1] + si[n-2] - 1 - (si[n-1]==si[n-2]) - k << endl; - -} - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); cout.tie(nullptr); - ll tt=1; - cin >> tt; - while(tt--){ - solve(); - } -}","#include -using namespace std; - -#define fr(i,s,e) for(ll i=s ; i=e ; i--) -#define ff first -#define ss second -#define pb push_back -typedef long long ll; -typedef vector vll; - -ll MOD=998244353; - -ll fastpow(ll base , ll power){ - ll ans=1; - while(power>0){ - if(power&1){ - ans*=base; - ans%=MOD; - } - power>>=1; - base*=base; - base%=MOD; - } - return ans; -} - -void solve(){ - ll n; - cin >> n; - vector v(n+1); - vll used(n+1); - fr(i, 1, n+1) v[i].pb(i); - fr(i, 0, n-1){ - ll a,b; - cin >> a >> b; - v[a].pb(b); - v[b].pb(a); - } - vector v1(v.begin(), v.end()); - sort(v.begin(), v.end(), [](vll a, vll b){return a.size() < b.size();}); - fr(i, 1, v[n].size()){ - v1[v[n][i]].erase( find(v1[v[n][i]].begin(), v1[v[n][i]].end(), v[n][0]) ); - } - v1.erase(v1.begin() + v[n][0]); - vector v2(v1.begin(), v1.end()); - sort(v1.begin(), v1.end(), [](vll a, vll b){return a.size() < b.size();}); - fr(i, 1, v1[n-1].size()){ - fr(j, 1, v2.size()){ - if(v2[j][0] == v1[n-1][i]) v2[j].erase( find(v2[j].begin(), v2[j].end(), v1[n-1][0]) ); - } - } - fr(j, 1, v2.size()){ - if(v2[j][0] == v1[n-1][0]) v2.erase( v2.begin() + j); - } - if(v2.size()==1){cout << ""0\n""; return;} - ll cnt = 0; - fr(i, 1, v2.size()){ - if( !used[v2[i][0]] ){ - cnt++; - for(auto x : v2[i]) used[x] = 1;; - } - } - cout << cnt << endl; -} - -int main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); cout.tie(nullptr); - ll tt=1; - cin >> tt; - while(tt--){ - solve(); - } -}",1 -srsahu45,2063C - Remove Exactly Two,c++17 ,304664779,304663547,"#include -using namespace std; -#define ll long long - -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - ll T; - cin >> T; - while(T--) { - ll n; - cin >> n; - vector> adj(n); - vector deg(n); - for(ll i = 0; i < n - 1; i++) { - ll u, v; - cin >> u >> v; - u--; - v--; - adj[u].insert(v); - adj[v].insert(u); - deg[u]++; - deg[v]++; - } - vector> e; - for(ll i = 0; i < n; i++) { - e.push_back({deg[i], i}); - } - sort(e.rbegin(), e.rend()); - ll ans = 0; - for(ll i = 0; i < n; i++) { - for(ll j = i + 1; j < n; j++) { - ll u = e[i].second; - ll v = e[j].second; - if(adj[u].count(v)) { - continue; - } - ans = max(ans, deg[u] + deg[v] - 1); - break; - } - } - for(ll i = 0; i < n; i++) { - for(ll j: adj[i]) { - ans = max(ans, deg[i] + deg[j] - 2); - } - } - cout << ans << '\n'; - } - return 0; -}","#include -using namespace std; -#define ll long long - -int main() -{ -#ifndef ONLINE_JUDGE - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); -#endif - ios_base::sync_with_stdio(false); - cin.tie(NULL); - - ll T; - cin >> T; - while(T--) { - ll n; - cin >> n; - vector> adj(n); - vector deg(n); - for(ll i = 0; i < n - 1; i++) { - ll u, v; - cin >> u >> v; - u--; - v--; - adj[u].insert(v); - adj[v].insert(u); - deg[u]++; - deg[v]++; - } - vector> e; - for(ll i = 0; i < n; i++) { - e.push_back({deg[i], i}); - } - sort(e.rbegin(), e.rend()); - ll ans = 0; - for(ll i = 0; i < n; i++) { - for(ll j = i + 1; j < n; j++) { - ll u = e[i].second; - ll v = e[j].second; - if(adj[u].count(v)) { - continue; - } - ans = max(ans, deg[u] + deg[v] - 1); - } - } - for(ll i = 0; i < n; i++) { - for(ll j: adj[i]) { - ans = max(ans, deg[i] + deg[j] - 2); - } - } - cout << ans << '\n'; - } - return 0; -}",1 -orca17124,2063C - Remove Exactly Two,c++17 ,303974050,303972846,"// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/contest/2063/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// Author: alchemist_17 - - -#include -// #include -#include -using namespace std; -using namespace __gnu_pbds; -#define sped ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -#define ln '\n' -#define ld long double -#define int long long -#define f first -#define s second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define mii map -#define pii pair -#define vi vector -#define vpii vector -#define vvi vector -#define pb push_back -#define sara(x) cout << #x << "" = "" << x << ""\n"" -#define setbitsll(n) __builtin_popcountll(n) //counts all set bits in (int)num, setbitsll(num)==1 i.e no. is power of 2 -#define setbits(n) __builtin_popcount(n) -#define msb(x) __builtin_clzll(x) // to count leading 0 , to find index = 64-msb(n)-1 -#define lsb(x) __builtin_ctzll(x) // to count trailing 0 , to find index = lsb(n) -#define yesno(f) f?cout<<""YES\n"":cout<<""NO\n"" -#define mx(v) *max_element(v.begin(),v.end()) -#define mn(v) *min_element(v.begin(),v.end()) -#define loop(n) for(int i=0; i, rb_tree_tag, tree_order_statistics_node_update> - -/* - If mod operations performed , divide won't work instead of / , * by its mod inverse -*/ -/* ordered_set st - st.order_of_key(k) : no. of elements < k - *st.find_by_order(i) : value at index i (0-based) -*/ -/* In Interactive problem use : - endl (flushes buffer automatically)(provide o/p for each query) - or use '\n' (provide o/p for all query at once) along with cout.flush(); -*/ - -/* n=10010010 - 0010(want till ith) - extracted no.=(n%(1<<(i+1))) i.e.0010 - remaining no.=n^((n%(1<<(i+1)))) i.e. 10010000 - ct of ith → (i+1)*(n-i) // no. of subarrays containing the ith element, total subarrays = n*(n+1)/2 - n % 2ʲ -> last j bits of n -*/ - -// upper bound of factors:cbrt(n) - -const long long M = 1000000007; -const int N = 1000000; -vector isprime(N + 1, true); -vector spf(N + 1, 0); - -int lcm(int a, int b){int g=__gcd(a, b); return a/g*b;} - -int factorial(int n){n%=M; if(n<=1) return 1; return n*factorial(n-1)%M;} - -int binexp(int a, int b , int m) { - if (b == 0) return 1; - if (b == 1) return (a) % m; - int res = binexp(a, b / 2 , m); - if (b % 2 == 0) return (res * res) % m; - return ((res * res) % m * (a) % m) % m; -} - -int modinv(int a, int p) -{return binexp(a, p - 2, p);} - -long double ncr(int n,int r){if(n - -int32_t main() { - sped - int t; - cin >> t; - while (t--) { - int n; - cin>>n; - vvi adj(n); - for(int i=0;i>u>>v; - --u; - --v; - adj[u].pb(v); - adj[v].pb(u); - } - set s; - vpii b; - for(int i=0;i temp=s; - pii p1={adj[i].size(),i}; - int a1=max(0ll,p1.f); - s.erase(s.find(p1)); - for(auto it:adj[i]){ - pii p1={adj[it].size(),it}; - s.erase(s.find(p1)); - pii p2={adj[it].size()-1,it}; - s.insert(p2); - } - auto it=(--s.end()); - int a2=max(0ll,it->f); - ans=max(ans,a1+a2-1); - s=temp; - } - cout << ans << ln; - } -} - -","// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/contest/2063/problem/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// Author: alchemist_17 - - -#include -// #include -#include -using namespace std; -using namespace __gnu_pbds; -#define sped ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); - -#define ln '\n' -#define ld long double -#define int long long -#define f first -#define s second -#define all(x) (x).begin(), (x).end() -#define rall(x) (x).rbegin(), (x).rend() -#define mii map -#define pii pair -#define vi vector -#define vpii vector -#define vvi vector -#define pb push_back -#define sara(x) cout << #x << "" = "" << x << ""\n"" -#define setbitsll(n) __builtin_popcountll(n) //counts all set bits in (int)num, setbitsll(num)==1 i.e no. is power of 2 -#define setbits(n) __builtin_popcount(n) -#define msb(x) __builtin_clzll(x) // to count leading 0 , to find index = 64-msb(n)-1 -#define lsb(x) __builtin_ctzll(x) // to count trailing 0 , to find index = lsb(n) -#define yesno(f) f?cout<<""YES\n"":cout<<""NO\n"" -#define mx(v) *max_element(v.begin(),v.end()) -#define mn(v) *min_element(v.begin(),v.end()) -#define loop(n) for(int i=0; i, rb_tree_tag, tree_order_statistics_node_update> - -/* - If mod operations performed , divide won't work instead of / , * by its mod inverse -*/ -/* ordered_set st - st.order_of_key(k) : no. of elements < k - *st.find_by_order(i) : value at index i (0-based) -*/ -/* In Interactive problem use : - endl (flushes buffer automatically)(provide o/p for each query) - or use '\n' (provide o/p for all query at once) along with cout.flush(); -*/ - -/* n=10010010 - 0010(want till ith) - extracted no.=(n%(1<<(i+1))) i.e.0010 - remaining no.=n^((n%(1<<(i+1)))) i.e. 10010000 - ct of ith → (i+1)*(n-i) // no. of subarrays containing the ith element, total subarrays = n*(n+1)/2 - n % 2ʲ -> last j bits of n -*/ - -// upper bound of factors:cbrt(n) - -const long long M = 1000000007; -const int N = 1000000; -vector isprime(N + 1, true); -vector spf(N + 1, 0); - -int lcm(int a, int b){int g=__gcd(a, b); return a/g*b;} - -int factorial(int n){n%=M; if(n<=1) return 1; return n*factorial(n-1)%M;} - -int binexp(int a, int b , int m) { - if (b == 0) return 1; - if (b == 1) return (a) % m; - int res = binexp(a, b / 2 , m); - if (b % 2 == 0) return (res * res) % m; - return ((res * res) % m * (a) % m) % m; -} - -int modinv(int a, int p) -{return binexp(a, p - 2, p);} - -long double ncr(int n,int r){if(n - -int32_t main(){ - //sieve(); - // SPF(); - sped - int t; - cin>>t; - while(t--){ - int n;cin>>n; - vector> adj(n+1); - for(int i=1;i<=n-1;++i){ - int u,v;cin>>u>>v; - adj[u].pb(v); - adj[v].pb(u); - } - int ans=0; - set> st; - for(int i=1;i<=n;++i){ - st.insert({adj[i].size(),i}); - } - for(int i=1;i<=n;++i){ - pii p={adj[i].size(),i}; - set temp = st; - int a1=adj[i].size(); - temp.erase(p); - for(auto x:adj[i]){ - pii p1={adj[x].size(),x}; - temp.erase(temp.find(p1)); - pii p2={adj[x].size()-1,x}; - temp.insert(p2); - } - if (!temp.empty()) { - auto x = *prev(temp.end()); - int a2 = x.first; - ans = max(ans, a1 + a2 - 1); - } - } - cout< -#include -struct edge -{ - int to,next; -}e[400010]; -int head[200010]; -int sum; -void add(int from,int to) -{ - e[++sum].to=to; - e[sum].next=head[from]; - head[from]=sum; -} -int size[200010]; -int main() -{ - int T; - scanf(""%d"",&T); - while(T--) - { - int n; - sum=0; - scanf(""%d"",&n); - for(int i=1;i<=n;i++) - { - size[i]=0; - head[i]=0; - } - for(int i=1;i mul; - for(int i=1;i<=n;i++) - mul.insert(size[i]); - int maxn=0; - for(int i=1;i<=n;i++) - { - int sze=size[i]; - mul.erase(size[i]); - for(int j=head[i];j;j=e[j].next) - { - mul.erase(size[e[j].to]); - mul.insert(size[e[j].to]-1); - } - std::multiset::iterator it; - it=mul.end(); - it--; - maxn=std::max(maxn,sze+*it-1); - for(int j=head[i];j;j=e[j].next) - { - mul.erase(size[e[j].to]-1); - mul.insert(size[e[j].to]); - } - mul.insert(size[i]); - } - printf(""%d\n"",maxn); - } - return 0; -} -","#include -#include -struct edge -{ - int to,next; -}e[400010]; -int head[200010]; -int sum; -void add(int from,int to) -{ - e[++sum].to=to; - e[sum].next=head[from]; - head[from]=sum; -} -int size[200010]; -int main() -{ - int T; - scanf(""%d"",&T); - while(T--) - { - int n; - sum=0; - scanf(""%d"",&n); - for(int i=1;i<=n;i++) - { - size[i]=0; - head[i]=0; - } - for(int i=1;i mul; - for(int i=1;i<=n;i++) - mul.insert(size[i]); - int maxn=0; - for(int i=1;i<=n;i++) - { -// for(auto it:mul) -// printf(""%d "",it); -// printf(""\n""); - int sze=size[i]; - mul.erase(mul.find(size[i])); - for(int j=head[i];j;j=e[j].next) - { - mul.erase(mul.find(size[e[j].to])); - mul.insert(size[e[j].to]-1); - } - std::multiset::iterator it; - it=mul.end(); - it--; - maxn=std::max(maxn,sze+*it-1); - for(int j=head[i];j;j=e[j].next) - { - mul.erase(mul.find(size[e[j].to]-1)); - mul.insert(size[e[j].to]); - } - mul.insert(size[i]); - } - printf(""%d\n"",maxn); - } - return 0; -} -",2 -aaditya02,2063C - Remove Exactly Two,c++23 ,305786462,305782355,"#include -#include -#include -#include -using namespace std; - -void solve() { - int n; - cin >> n; - - vector< vector > g(n + 1); - for(int i = 0; i < n - 1; i++) { - int a, b; - cin >> a >> b; - - g[a].push_back(b); - g[b].push_back(a); - } - - if(n == 2) { - cout << 0 << endl; - return; - } - - if(n == 3) { - cout << 1 << endl; - return; - } - - priority_queue pq; - - for(auto &itr: g) { - pq.push(itr.size()); - } - - int maxi = pq.top(); - pq.pop(); - int second_maxi = pq.top(); - pq.pop(); - - int count = 0; - for(auto &node: g) { - if(node.size() == second_maxi) { - count++; - } - } - - bool found = false; - for(auto &node: g) { - if(node.size() != maxi) continue; - - int current_count = 0; - for(auto &neigh: node) { - if(g[neigh].size() == second_maxi) { - current_count++; - } - } - - if(maxi == second_maxi) { - if(current_count < count - 1) { - found = true; - break; - } - } else { - if(current_count < count) { - found = true; - break; - } - } - } - - if(found) { - cout << maxi + second_maxi - 1<< endl; - } else { - cout << maxi + second_maxi - 2 << endl; - } - - return; -} - - - -int main() { - int t; - cin >> t; - - while(t-- > 0) { - solve(); - } - - return 0; -} -","#include -#include -#include -#include -using namespace std; - -void solve() { - int n; - cin >> n; - - vector< vector > g(n + 1); - for(int i = 0; i < n - 1; i++) { - int a, b; - cin >> a >> b; - - g[a].push_back(b); - g[b].push_back(a); - } - - priority_queue pq; - - for(auto &itr: g) { - pq.push(itr.size()); - } - - int maxi = pq.top(); - pq.pop(); - int second_maxi = pq.top(); - pq.pop(); - - bool global_found = false; - for(auto &node: g) { - if(node.size() != maxi) continue; - - bool found = false; - for(auto &neigh: node) { - if(g[neigh].size() == second_maxi) { - found = true; - break; - } - } - - if(found) continue; - global_found = true; - } - - if(global_found) { - cout << maxi + second_maxi - (maxi == 1) - (second_maxi == 1) << endl; - } else { - cout << maxi + second_maxi - 1 - (second_maxi == 1) << endl; - } - - return; -} - - - -int main() { - int t; - cin >> t; - - while(t-- > 0) { - solve(); - } - - return 0; -} -",1 -SachanSagar,2063C - Remove Exactly Two,c++23 ,307157117,307166365,"#include -using namespace std; - -#define all(v) v.begin(), v.end() -#define debug(x) cout << #x << '=' << x << endl; -#define pb push_back -#define int long long -const long long M = 998244353; - -void solve(){ - int n; cin>>n; - - vector> vec(n+1); - unordered_set st; - for(int i = 1; i >a>>b; - vec[a].push_back(b); - vec[b].push_back(a); - st.insert((a*1e6+b)); - st.insert((b*1e6+a)); - } - if(n<=4){ - cout<> sz; - for(int i = 1; i <=n; i++){ - sz.push_back({vec[i].size(), i}); - } - sort(sz.begin(), sz.end()); - - for(int i = n-2; i >=0; i--){ - if(sz[i].first < sz[n-2].first){ - break; - } - if(st.count((sz[n-1].second*1e6 + sz[i].second)) == 0){ - cout<> t; - while (t--) solve(); - - return 0; -} -","#include -using namespace std; - -#define all(v) v.begin(), v.end() -#define debug(x) cout << #x << '=' << x << endl; -#define pb push_back -#define int long long -const long long M = 998244353; - -void solve(){ - int n; cin>>n; - - vector> vec(n+1); - unordered_set st; - for(int i = 1; i >a>>b; - vec[a].push_back(b); - vec[b].push_back(a); - st.insert((a*1e6+b)); - st.insert((b*1e6+a)); - } - if(n<=4){ - cout<> sz; - for(int i = 1; i <=n; i++){ - // cout<=0; i--){ - if(st.count((sz[n-1].second*1e6+sz[i].second)) == 0) ans = max(ans, sz[n-1].first+sz[i].first-1); - else ans = max(ans, sz[n-1].first+sz[i].first-2); - - if(st.count((sz[n-2].second*1e6+sz[i].second)) == 0) ans = max(ans, sz[n-2].first+sz[i].first-1); - else ans = max(ans, sz[n-2].first+sz[i].first-2); - } - - - cout<> t; - while (t--) solve(); - - return 0; -} -",2 -msrssaini,2063C - Remove Exactly Two,c++23 ,306076522,306075085,"#include -using namespace std; -#define ll long long int - -int main() { - ll t; - cin >> t; - - while (t--) { - ll z; - cin >> z; - vector> tree(z + 1); - - for (ll i = 0; i < z - 1; i++) { - ll x, y; - cin >> x >> y; - tree[x].insert(y); - tree[y].insert(x); - } - vector> tree1=tree; - ll connected = 0, idx = 1; - - // Finding the most connected node - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ll ans = 1; - ans += tree[idx].size()-1; - // Remove first selected node's edges - for (auto x : tree[idx]) { - tree[x].erase(idx); - } - tree[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ans += tree[idx].size()-1; - - - connected = 0; - idx = 1; - - // Finding the most connected node - for (ll i = z; i >=1; i--) { - if (connected < (ll)tree1[i].size()) { - connected = tree1[i].size(); - idx = i; - } - } - - ll ans1 = 1; - ans1 += tree1[idx].size()-1; - // Remove first selected node's edges - for (auto x : tree1[idx]) { - tree1[x].erase(idx); - } - tree1[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree1[i].size()) { - connected = tree1[i].size(); - idx = i; - } - } - - ans1 += tree1[idx].size()-1; - cout < -using namespace std; -#define ll long long int - -int main() { - ll t; - cin >> t; - - for(ll j=1;j<=t;j++) { - ll z; - cin >> z; - vector> tree(z + 1); - vector v; - for (ll i = 0; i < z - 1; i++) { - ll x, y; - cin >> x >> y; - v.push_back(x); - v.push_back(y); - tree[x].insert(y); - tree[y].insert(x); - } - if(j==1142) - { - for(ll i=0;i=5&&count2==z-2&&count1==2) - { - isall2=1; - } - ll connected = 0, idx = 1; - - // Finding the most connected node - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ll ans = 1; - ans += tree[idx].size()-1; - // Remove first selected node's edges - for (auto x : tree[idx]) { - tree[x].erase(idx); - } - tree[idx].clear(); - - // Find the next most connected node - connected = 0, idx = 1; - for (ll i = 1; i <= z; i++) { - if (connected < (ll)tree[i].size()) { - connected = tree[i].size(); - idx = i; - } - } - - ans += tree[idx].size()-1; - if(isall2) - { - cout<<""3""< -using namespace std; -#define pii pair -#define mp(x,y) make_pair(x,y) -#define inf (1e9) -#define INF (1e18) -#define eps (1e-8) -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -#define ull unsigned long long -#define int long long -#define Int __int128 -typedef long long LL; -mt19937 rnd(time(0)); -const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7; -int n, in[N]; -vector g[N]; - -void solve() -{ - int ans = 0; - cin >> n; - for (int i = 1; i <= n; i++) { - g[i].clear(); - in[i] = 0; - } - for (int i = 1; i < n; i++) { - int x, y; - cin >> x >> y; - g[x].push_back(y); - in[y]++; - g[y].push_back(x); - in[x]++; - } - multiset s; - for (int i = 1; i <= n; i++) { - s.insert(in[i]); - } - for (int i = 1; i <= n; i++) { - int res = 0; - s.erase(s.find(in[i])); - for (auto j : g[i]) { - s.erase(s.find(in[j])); - s.insert(in[j] - 1); - } - res = in[i] + *s.rbegin() - 1; - ans = max(ans, res); - for (auto j : g[i]) { - s.erase(s.find(in[j] - 1)); - s.insert(in[j]); - } - s.insert(in[i]); - } - cout << ans << endl; - return; -} - -signed main() -{ - // IOS; - // init(); - int __; - cin >> __; - while (__ --) - solve(); - - return 0; -} -//-Wl,--stack=1998244353 - - -/* - -*/","#include -using namespace std; -#define pii pair -#define mp(x,y) make_pair(x,y) -#define inf (1e9) -#define INF (1e18) -#define eps (1e-8) -#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); -#define ull unsigned long long -#define int long long -#define Int __int128 -typedef long long LL; -mt19937 rnd(time(0)); -const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7; -int n, in[N], ver, mx = 0; -vector g[N]; - -void dfs(int u, int fa) { - if (g[u].size() > mx) { - mx = g[u].size(); - ver = u; - } - for (int v : g[u]) { - if (v == fa) continue; - dfs(v, u); - } -} - -void solve() -{ - int ans = 1; - cin >> n; - for (int i = 1; i <= n; i++) { - g[i].clear(); - in[i] = 0; - } - for (int i = 1; i < n; i++) { - int x, y; - cin >> x >> y; - g[x].push_back(y); - in[y]++; - g[y].push_back(x); - in[x]++; - } - mx = 0; - for (int i = 1; i <= n; i++) { - if (g[i].size() == 1) { - dfs(i, -1); - break; - } - } - ans = g[ver].size(); - for (int v : g[ver]) { - in[v]--; - } - mx = 0; - for (int i = 1; i <= n; i++) { - if (i == ver) continue; - mx = max(mx, in[i]); - } - ans += mx - 1; - cout << ans << endl; - return; -} - -signed main() -{ - // IOS; - // init(); - int __; - cin >> __; - while (__ --) - solve(); - - return 0; -} -//-Wl,--stack=1998244353 - - -/* - -*/",1 -VangTruong,2063C - Remove Exactly Two,c++17 ,306035176,306036210,"#if 1 -#ifdef ONLINE_JUDGE -#define vangtruong ios_base::sync_with_stdio(false); cin.tie(nullptr)//Expert --> delete -#define debug(x) //*** debug ***// -#define debugVi(x) //*** debug ***// -#define debugVvi(x) //*** debug ***// -#else -#include ""D:/05.Learning/01.Algorithm/01.Algorithms/debug.h"" -#endif -#include -using namespace std; -//*** define ***// -#define int long long -#define INF LONG_LONG_MAX -#define MP make_pair -#define FOR(_i,_a,_b) for(int _i = (_a); _i < (_b); _i++) -#define FORI(_i,_a,_b) for(int _i = (_a); _i <= (_b); _i++) -#define FORE(it,x) for(auto it = x.begin(); it != x.end(); ++it) -using vb = vector; using vvb = vector; using vi = vector; using vvi = vector; -using vc = vector; using vvc = vector; using pi = pair; int itemp = 0; string stemp = """"; -#endif -//**************************** CODING SPACE ****************************// -bool cmp(pi a, pi b){ - return a.first > b.first; -} -int getAns(pi a, pi b, vvi& adj){ - // giam tat ca. - // neu a b ke nhau return 1 + a - 1 + b - 2 = a.F + b.F -2// ko ke a+b - bool isAdj = false; - for(auto u: adj[a.second]) if(u == b.second) isAdj = true; - return isAdj ? a.first + b.first -2ll : a.first + b.first -1ll; -} -void solve() { - int n; cin >> n; - vector L(n+1); - vvi adj(n+1); - vi D(n+1,0); - FOR(i,0,n-1){ - int a, b; cin >> a >> b; - D[a]++; D[b]++; - adj[a].push_back(b); adj[b].push_back(a); - } - // make pi - FOR(i,1,n+1) L[i] = MP(D[i],i); - sort(L.begin(), L.end(), cmp); - - if(n == 2) { - cout << ""0\n""; return; - } - pi a = L[0], b = L[1], c = L[2]; - int ans = -INF; - ans = max(ans, getAns(a, b, adj)); - ans = max(ans, getAns(a, c, adj)); - ans = max(ans, getAns(b, c, adj)); - cout << ans << ""\n""; -} - -int32_t main() { - vangtruong; int tcs = 1; cin >> tcs; - while (tcs--) {solve();}return 0; }","#if 1 -#ifdef ONLINE_JUDGE -#define vangtruong ios_base::sync_with_stdio(false); cin.tie(nullptr)//Expert --> delete -#define debug(x) //*** debug ***// -#define debugVi(x) //*** debug ***// -#define debugVvi(x) //*** debug ***// -#else -#include ""D:/05.Learning/01.Algorithm/01.Algorithms/debug.h"" -#endif -#include -using namespace std; -//*** define ***// -#define int long long -#define INF LONG_LONG_MAX -#define MP make_pair -#define FOR(_i,_a,_b) for(int _i = (_a); _i < (_b); _i++) -#define FORI(_i,_a,_b) for(int _i = (_a); _i <= (_b); _i++) -#define FORE(it,x) for(auto it = x.begin(); it != x.end(); ++it) -using vb = vector; using vvb = vector; using vi = vector; using vvi = vector; -using vc = vector; using vvc = vector; using pi = pair; int itemp = 0; string stemp = """"; -#endif -//**************************** CODING SPACE ****************************// -bool cmp(pi a, pi b){ - return a.first > b.first; -} -int getAns(pi a, vvi& adj, vi D){ - int res = D[a.second]; - D[a.second] = 0; - for(auto u: adj[a.second]){ - D[u]--; - } - vector L(D.size()); - FOR(i,1,D.size()) L[i] = MP(D[i],i); - sort(L.begin(), L.end(), cmp); - // for(auto x : L) debug(x); - res += L[0].first - 1ll; - return res; -} -void solve() { - int n; cin >> n; - vector L(n+1); - vvi adj(n+1); - vi D(n+1,0); - FOR(i,0,n-1){ - int a, b; cin >> a >> b; - D[a]++; D[b]++; - adj[a].push_back(b); adj[b].push_back(a); - } - // make pi - FOR(i,1,n+1) L[i] = MP(D[i],i); - sort(L.begin(), L.end(), cmp); - if(n == 2) { - cout << ""0\n""; return; - } - pi a = L[0], b = L[1], c = L[2]; - int ans = -INF; - ans = max(ans, getAns(a, adj, D)); - ans = max(ans, getAns(b, adj, D)); - ans = max(ans, getAns(c, adj, D)); - cout << ans << ""\n""; -} - -int32_t main() { - vangtruong; int tcs = 1; cin >> tcs; - while (tcs--) {solve();}return 0; }",2 -JalapenoVI9,2063C - Remove Exactly Two,c++17 ,304468036,304469216,"#include -using namespace std; - - -#define ll long long int -#define pb push_back -#define mp make_pair -#define all(v) (v).begin(), (v).end() -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define vii vector -#define F first -#define S second -#define sz(x) ((int)(x).size()) -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -const int MOD = 1e9 + 7; -const ll INF = 1e18; - - -template -void debug(vector v) { for(auto i: v) cout << i << "" ""; cout << endl; } - -template -void debug(vector> v) { for(auto i: v) cout << ""("" << i.F << "","" << i.S << "") ""; cout << endl; } - - -int main() { - fast_io; - - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector>neighbours(n,vector()); - vectordeg(n,0); - for(int i=0;i>a>>b; - neighbours[a-1].push_back(b-1); - neighbours[b-1].push_back(a-1); - deg[a-1]++; - deg[b-1]++; - } - int maxi = 0; - int conn = 1; - vectorminis(n,INT_MAX); - priority_queue< pair ,vector> , greater> > pq; - for(int i=0;i p =pq.top(); - pq.pop(); - int node = p.second; - int dist =p.first; - for(auto e : neighbours[node]){ - if(minis[e] > minis[node] + 1){ - minis[e] = minis[node] + 1; - pq.push({minis[e] , e}); - } - } - - } - - for(int i =1;i -using namespace std; - - -#define ll long long int -#define pb push_back -#define mp make_pair -#define all(v) (v).begin(), (v).end() -#define pii pair -#define pll pair -#define vi vector -#define vll vector -#define vii vector -#define F first -#define S second -#define sz(x) ((int)(x).size()) -#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) - -const int MOD = 1e9 + 7; -const ll INF = 1e18; - - -template -void debug(vector v) { for(auto i: v) cout << i << "" ""; cout << endl; } - -template -void debug(vector> v) { for(auto i: v) cout << ""("" << i.F << "","" << i.S << "") ""; cout << endl; } - - -int main() { - fast_io; - - int t; - cin >> t; - while (t--) { - int n; - cin >> n; - vector>neighbours(n,vector()); - vectordeg(n,0); - for(int i=0;i>a>>b; - neighbours[a-1].push_back(b-1); - neighbours[b-1].push_back(a-1); - deg[a-1]++; - deg[b-1]++; - } - if(n <= 2){ - cout<<0<>s; - for(int i=0;ip = {deg[i] , i}; - s.erase(p); - for(auto e : neighbours[i]){ - s.erase({deg[e],e}); - s.insert({deg[e]-1,e}); - } - int deg_max = s.rbegin()->first; - - conn = max(conn , -1 + deg[i] + deg_max); - s.insert(p); - for(auto e : neighbours[i]){ - s.erase({deg[e]-1,e}); - s.insert({deg[e],e}); - } - - } - - cout< - -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""Ash.cpp"" -#else -#define dbg(...) -#endif - -void solve(int cs) { - int n; - cin >> n; - vector> g(n); - vector deg(n, 0); - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v, --u, --v; - ++deg[u], ++deg[v]; - g[u].push_back(v); - g[v].push_back(u); - } - multiset ms(deg.begin(), deg.end()); - int ans = 0; - for (int i = 0; i < n; i++) { - ms.erase(ms.find(deg[i])); - for (auto &j : g[i]) { - ms.erase(ms.find(deg[j])); - ms.insert(deg[j] - 1); - } - ans = max(ans, deg[i] + *ms.rbegin() - 1); - for (auto &j : g[i]) { - ms.erase(ms.find(deg[j] - 1)); - ms.insert(deg[j]); - } - ms.insert(deg[i]); - } - cout << ans << ""\n""; -} - -int32_t main() { - ios::sync_with_stdio(!cin.tie(0)); - int t = 1; - cin >> t; - for (int i = 1; i <= t; ++i) { - solve(i); - } - return 0; -}","#include - -using namespace std; - -#ifndef ONLINE_JUDGE -#include ""Ash.cpp"" -#else -#define dbg(...) -#endif - -void solve(int cs) { - int n; - cin >> n; - vector> g(n); - vector deg(n, 0); - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v, --u, --v; - ++deg[u], ++deg[v]; - g[u].insert(v); - g[v].insert(u); - } - if (n == 2) { - cout << ""0\n""; return; - } - int mx = *max_element(deg.begin(), deg.end()); - int who = -1; - for (int i = 0; i < n; i++) { - if (deg[i] == mx) { - who = i; - } - } - for (auto &them : g[who]) { - g[them].erase(who); - } - g[who].clear(), deg.clear(); - for (int i = 0; i < n; i++) { - deg[i] = g[i].size(); - } - mx = *max_element(deg.begin(), deg.end()); - assert(deg[who] == 0); - int second = -1; - for (int i = 0; i < n; i++) { - if (deg[i] == mx && i != who) { - second = i; - } - } - for (auto &them : g[second]) { - g[them].erase(second); - } - g[second].clear(); - int ans = 0; - vector vis(n, false); - auto dfs = [&](auto &&self, int node) -> void { - vis[node] = true; - for (auto &son : g[node]) { - if (!vis[son]) { - self(self, son); - } - } - }; - for (int i = 0; i < n; i++) { - if (!vis[i]) { - ++ans, dfs(dfs, i); - } - } - cout << ans - 2 << ""\n""; -} - -int32_t main() { - ios::sync_with_stdio(!cin.tie(0)); - int t = 1; - cin >> t; - for (int i = 1; i <= t; ++i) { - solve(i); - } - return 0; -}",1 -kartik__sethi,2063C - Remove Exactly Two,java,304914528,304915872," -/* package codechef; // don't place package name! */ - -import java.util.*; -import java.lang.*; -import java.io.*; - -public class Main { - - //------------------------------------------main--------------------------------------------------// - public static void main(String[] args) throws java.lang.Exception { - OutputStream outputStream = System.out; - PrintWriter out = new PrintWriter(outputStream); - FastReader sc = new FastReader(); - Task s = new Task(sc, out); - s.solve(); - out.close(); - // your code goes here"" - } -} - -class FastReader { - - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - public int[] readIntArray(int n) throws IOException { - int[] arr = new int[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextInt(); - } - return arr; - } - - public long[] readLongArray(int n) throws IOException { - long[] arr = new long[n]; - for (int i = 0; i < n; i++) { - arr[i] = nextLong(); - } - return arr; - } -} - -class Task { - - PrintWriter out; - FastReader sc; - - Task(FastReader sc, PrintWriter out) { - this.sc = sc; - this.out = out; - } - //----------------------------------------------inputfunction------------------------------------------// - - String st() { - return sc.nextLine(); - } - - int i() { - return sc.nextInt(); - } - - long l() { - return sc.nextLong(); - } - - double d() { - return sc.nextDouble(); - } - - //---------------------------------------------absolute----------------------------------------------// - public long abs(long a) { - return a < 0 ? -a : a; - } - - public int abs(int a) { - return a < 0 ? -a : a; - } - - //-------------------------------------------max--------------------------------------------------// - public int max(int a, int b) { - return a >= b ? a : b; - } - - public long max(long a, long b) { - return a >= b ? a : b; - } - - public int max(int a, int b, int c) { - return Math.max(a, Math.max(b, c)); - } - - public long max(long a, long b, long c) { - return Math.max(a, Math.max(b, c)); - } - - //------------------------------------------min---------------------------------------------------// - public int min(int a, int b) { - return a <= b ? a : b; - } - - public long min(long a, long b) { - return a <= b ? a : b; - } - - public int min(int a, int b, int c) { - return Math.min(a, Math.min(b, c)); - } - - public long min(long a, long b, long c) { - return Math.min(a, Math.min(b, c)); - } - - //----------------------------------------sortingfunction---------------------------------------------// - private void sort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - //---------------------------------------power----------------------------------------------------// - - public long pow(long a, int b) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans *= a; - } - a *= a; - b >>= 1; - } - return b; - } - //----------------------------------------binary_exponentiation-----------------------------------// - - public long exp(long a, long b, long mod) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans; - } - - int t, n; - int[] cal(int[] in, int n){ - int max = 0, v = 0; - for(int i = 1;i<=n;i++){ - if(in[i]>=max){ - max = in[i]; - v = i; - } - } - return new int[]{max-1, v}; - } - public void solve() throws IOException { - t = sc.nextInt(); - while (t-- > 0) { - int n = i(); - int[] in = new int[n+1]; - List edge = new ArrayList<>(); - for(int i = 1;i= b ? a : b; - } - - public long max(long a, long b) { - return a >= b ? a : b; - } - - public int max(int a, int b, int c) { - return Math.max(a, Math.max(b, c)); - } - - public long max(long a, long b, long c) { - return Math.max(a, Math.max(b, c)); - } - - //------------------------------------------min---------------------------------------------------// - public int min(int a, int b) { - return a <= b ? a : b; - } - - public long min(long a, long b) { - return a <= b ? a : b; - } - - public int min(int a, int b, int c) { - return Math.min(a, Math.min(b, c)); - } - - public long min(long a, long b, long c) { - return Math.min(a, Math.min(b, c)); - } - - //----------------------------------------sortingfunction---------------------------------------------// - private void sort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(char[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(int[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void sort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - - private void rsort(long[] arr) { - int n = arr.length; - List list = new ArrayList<>(); - for (int i = 0; i < n; i++) { - list.add(arr[i]); - } - Collections.sort(list, Collections.reverseOrder()); - for (int i = 0; i < n; i++) { - arr[i] = list.get(i); - } - } - //---------------------------------------power----------------------------------------------------// - - public long pow(long a, int b) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans *= a; - } - a *= a; - b >>= 1; - } - return b; - } - //----------------------------------------binary_exponentiation-----------------------------------// - - public long exp(long a, long b, long mod) { - long ans = 1L; - while (b > 0) { - if ((b & 1) > 0) { - ans = (ans * a) % mod; - } - a = (a * a) % mod; - b >>= 1; - } - return ans; - } - int t; - public void solve() throws IOException { - t = sc.nextInt(); - while (t-- > 0) { - int n = i(); - List> a = new ArrayList<>(); - int[][] in = new int[n+1][2]; - for(int i =0;i<=n;i++){ - a.add(new HashSet<>()); - in[i][1] = i; - } - for(int i = 1;i y[0] - x[0]); - int ans = 0; - for(int i = 1;i<=n;i++){ - for(int e: a.get(i)){ - ans = max(ans, a.get(i).size() + a.get(e).size() - 2); - } - } - for(int i = 0;i -#define ull unsigned long long -#define ul unsigned long -#define l long -#define ll long long -using namespace std; -struct vertex{ - vector v; - int degree; -}; -vertex graph[200010]; -int main() -{ - ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); - int t; - cin>>t; - while(t--) - { - multiset dg; - dg.clear(); - int n; - cin>>n; - int maxdegree=0; - for(int i=1;i<=n;i++) - { - graph[i].v.clear(); - graph[i].degree=0; - } - for(int i=1;i>u>>v; - graph[u].v.push_back(v); - graph[u].degree++; - graph[v].v.push_back(u); - graph[v].degree++; - if(graph[u].degree>maxdegree) - maxdegree=graph[u].degree; - if(graph[v].degree>maxdegree) - maxdegree=graph[v].degree; - } - for(int i=1;i<=n;i++)dg.insert(graph[i].degree); - int ans=0; - for(int i=1;i<=n;i++) - { - dg.erase(dg.find(graph[i].degree)); - for(auto it=graph[i].v.begin();it!=graph[i].v.end();it++) - { - int vv=*it; - dg.erase(dg.find(graph[vv].degree)); - dg.insert(graph[vv].degree-1); - } - ans=max(ans,graph[i].degree+*dg.rbegin()-1); - for(auto it=graph[i].v.begin();it!=graph[i].v.end();it++) - { - int vv=*it; - dg.erase(dg.find(graph[vv].degree-1)); - dg.insert(graph[vv].degree); - } - dg.insert(graph[i].degree); - } - cout< -#define ull unsigned long long -#define ul unsigned long -#define l long -#define ll long long -using namespace std; -struct vertex{ - vector v; - int degree; -}; -vertex graph[200010]; -int main() -{ - ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); - int t; - cin>>t; - while(t--) - { - int n; - cin>>n; - int maxdegree=0,maxsite; - for(int i=1;i<=n;i++) - { - graph[i].v.clear(); - graph[i].degree=0; - } - for(int i=1;i>u>>v; - graph[u].v.push_back(v); - graph[u].degree++; - graph[v].v.push_back(u); - graph[v].degree++; - if(graph[u].degree>maxdegree) - { - maxdegree=graph[u].degree; - maxsite=u; - } - if(graph[v].degree>maxdegree) - { - maxdegree=graph[v].degree; - maxsite=v; - } - } - int ans=1; - ans+=maxdegree-1; - graph[maxsite].degree=0; - for(auto it=graph[maxsite].v.begin();it!=graph[maxsite].v.end();it++) - { - int vv=*it; - graph[vv].degree--; - } - maxdegree=0; - for(int i=1;i<=n;i++) - { - if(graph[i].degree>maxdegree) - maxdegree=graph[i].degree; - } - ans+=maxdegree-1; - cout< -using namespace std; -//#pragma GCC target(""sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"") -//#pragma GCC optimize(""Ofast,unroll-loops,fast-math,O3"") - -#define pb push_back -#define ll long long -//#define sort(all(v)) sort(v.begin(),v.end()) - -int mod = 998244353; -const int N = 4e5 + 10; -const int inf = 1e9; -int fact[200001]; -ll binpow(ll a, ll b){ - if(b == 0) return 1; - else if(b % 2 == 1) return (a * binpow(a, b - 1)) % mod; - ll p = binpow(a,b / 2); - return (p * p) % mod; -} -vector g[N]; -int sum[N],was[N]; -void dfs(int u){ - was[u] = 1; - if(sum[u] == 0 && u != 1) sum[u]++; - for(int to : g[u]){ - if(was[to] != 0) continue; - sum[u]++; - dfs(to); - } -} -signed main(){ - //freopen(""mootube.in"", ""r"", stdin); - //freopen(""mootube.out"", ""w"", stdout); - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - for(int i = 1; i < n; i++){ - int u,v; - cin >> u >> v; - g[u].pb(v); - g[v].pb(u); - } - dfs(1); - int mx = 0; - multiset mt; - for(int i = 1; i <= n; i++){ - mx = max(mx,sum[i]); - mt.insert(sum[i]); - } - int mx1 = 0,v = 0,ans = 1; - for(int i = 1; i <= n; i++){ - if(sum[i] == mx){ - for(int to : g[i]){ - mt.erase(mt.find(sum[to])); - mt.insert(sum[to] - 1); - } - if(mx1 <= *mt.rbegin()){ - mx1 = *mt.rbegin(); - v = i; - } - for(int to : g[i]){ - mt.erase(mt.find(sum[to] - 1)); - mt.insert(sum[to]); - } - } - } - ans += mx - 1; - for(int to : g[v]){ - sum[to]--; - } - mx = 0; - for(int i = 1; i <= n; i++){ - if(v == i) continue; - mx = max(mx,sum[i]); - } - cout << ans + mx - 1 << '\n'; - for(int i = 1; i <= n; i++){ - sum[i] = was[i] = 0; - g[i].clear(); - } - } -}","#include -using namespace std; -//#pragma GCC target(""sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native"") -//#pragma GCC optimize(""Ofast,unroll-loops,fast-math,O3"") - -#define pb push_back -#define ll long long -//#define sort(all(v)) sort(v.begin(),v.end()) - -int mod = 998244353; -const int N = 4e5 + 10; -const int inf = 1e9; -int fact[200001]; -ll binpow(ll a, ll b){ - if(b == 0) return 1; - else if(b % 2 == 1) return (a * binpow(a, b - 1)) % mod; - ll p = binpow(a,b / 2); - return (p * p) % mod; -} -vector g[N]; -int sum[N],was[N]; -void dfs(int u){ - was[u] = 1; - if(sum[u] == 0 && u != 1) sum[u]++; - for(int to : g[u]){ - if(was[to] != 0) continue; - sum[u]++; - dfs(to); - } -} -signed main(){ - //freopen(""mootube.in"", ""r"", stdin); - //freopen(""mootube.out"", ""w"", stdout); - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - for(int i = 1; i < n; i++){ - int u,v; - cin >> u >> v; - g[u].pb(v); - g[v].pb(u); - } - dfs(1); - multiset mt; - for(int i = 1; i <= n; i++)mt.insert(sum[i]); - int ans = 0; - for(int i = 1; i <= n; i++){ - mt.erase(mt.find(sum[i])); - for(int to : g[i]){ - mt.erase(mt.find(sum[to])); - mt.insert(sum[to] - 1); - } - ans = max(ans,*mt.rbegin() + sum[i] - 1); - for(int to : g[i]){ - mt.erase(mt.find(sum[to] - 1)); - mt.insert(sum[to]); - } - mt.insert(sum[i]); - } - cout << ans << '\n'; - for(int i = 1; i <= n; i++){ - sum[i] = was[i] = 0; - g[i].clear(); - } - } -}",2 -fart_smella,2063C - Remove Exactly Two,c++20 ,307323698,307323282,"#include -using namespace std; -using ll = long long; - -void solve() { - int n; - cin >> n; - - vector> adj(n + 1); - vector> indeg; - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - adj[u].insert(v); - adj[v].insert(u); - } - for (int i = 1; i <= n; i++) { - indeg.push_back({(int)adj[i].size(), i}); - } - sort(indeg.rbegin(), indeg.rend()); - int ans = 0; - for (int i = 0; i > T; - while (T--) solve(); -} -","#include -using namespace std; -using ll = long long; - -void solve() { - int n; - cin >> n; - vector> adj(n + 1); - map> indeg; - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - adj[u].insert(v);adj[v].insert(u); - indeg[u]++; indeg[v]++; - } - int ans = 0; - for (int i = 1; i <= n; i++) { - for (auto &[node, degree] : indeg) { - if(node==i) continue; - else if (adj[i].count(node) ) { - ans = max(ans, indeg[node] + indeg[i] - 2); - } else { - ans = max(ans, indeg[node] + indeg[i] - 1); - } - } - } - cout << ans << endl; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int T; - cin >> T; - while (T--) solve(); -} -",1 -gambit001,2063C - Remove Exactly Two,c++17 ,303757656,304318565,"#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef vector vll; -#define reg(i,a,b) for(ll i=a;i -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -void solve() { - ll n; - cin>>n; - vector adjL(n); - map f; - - reg(i,0,n - 1){ - ll u, v; - cin>>u>>v; - u--; - v--; - adjL[u].push_back(v); - adjL[v].push_back(u); - f[u]++; - f[v]++; - } - set> cont; - for(auto it : f) cont.insert({it.second, it.first}); - ll node = (*cont.rbegin()).second; - ll fre = f[node]; - ll ans = fre; - cont.erase({fre, node}); - for(auto nxt: adjL[node]){ - cont.erase({f[nxt], nxt}); - f[nxt]--; - cont.insert({f[nxt], nxt}); - } - - node = (*cont.rbegin()).second; - fre = f[node]; - ans += fre; - ans--; - cout<>ts; - while (ts--) { - solve(); - } - return 0; -} -","#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef vector vll; -#define reg(i,a,b) for(ll i=a;i -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; - -ll s(set> &cont, ll node, map &f, vector &adjL){ - ll ans = 0; - ll fre = f[node]; - ans = fre; - cont.erase({fre, node}); - for(auto nxt: adjL[node]){ - cont.erase({f[nxt], nxt}); - f[nxt]--; - cont.insert({f[nxt], nxt}); - } - - ans += (*cont.rbegin()).first; - ans--; - for(auto nxt: adjL[node]){ - cont.erase({f[nxt], nxt}); - f[nxt]++; - cont.insert({f[nxt], nxt}); - } - return ans; -} - -void solve() { - ll n; - cin>>n; - vector adjL(n); - map f; - - reg(i,0,n - 1){ - ll u, v; - cin>>u>>v; - u--; - v--; - adjL[u].push_back(v); - adjL[v].push_back(u); - f[u]++; - f[v]++; - } - set> cont; - for(auto it : f) cont.insert({it.second, it.first}); - //ll node = (*cont.rbegin()).second; - ll fre = (*cont.rbegin()).first; - // cout<> temp(cont.begin(), cont.end()); - for(ll i = temp.size() - 1; i>=0; i--){ - if(temp[i].first < fre) break; - // cout<<""chala""<>ts; - while (ts--) { - solve(); - } - return 0; -} -",2 -Amadeus027#,2063C - Remove Exactly Two,c++20 ,306049089,306051542,"#include -using namespace std; - -#define gcd(a, b) __gcd(a, b) -#define lcm(a, b) a / gcd(a, b) * b -#define N cout << ""No\n"" -#define Y cout << ""Yes\n"" -#define endl '\n' -#define all(a) a.begin(),a.end() -#define int long long -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) -#define ll long long - -void solve() { - int n; - cin >> n; - vector > a(n+1); - for (int i=1; i> u >> v; - a[u].push_back(v); - a[v].push_back(u); - } - if (n == 2) { - cout << 0 << endl; - } else if (n == 3){ - cout << 1 << endl; - } else if (n == 4) { - cout << 2 << endl; - } else { - int res = 1; - vector > num(n+1); - for (int i=1; i<=n; i++) { - num[i].first = a[i].size(); - num[i].second = i; - } - sort(all(num)); - res += num[n].first - 1; - vector > kk(n+1); - for (int i=1; i<=n; i++) { - if (i == num[n].second) { - continue; - } - kk[i].first = a[i].size(); - kk[i].second = i; - } - for (auto x : a[num[n].second]) { - kk[x].first--; - } - sort(all(kk)); - res += kk[n].first - 1; - cout << res << endl; - } -} - -signed main () -{ - IOS; - int t = 1; - cin >> t; - while(t--){ - solve(); - } - return 0; -} -","#include -using namespace std; - -#define gcd(a, b) __gcd(a, b) -#define lcm(a, b) a / gcd(a, b) * b -#define N cout << ""No\n"" -#define Y cout << ""Yes\n"" -#define endl '\n' -#define all(a) a.begin(),a.end() -#define int long long -#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) -#define ll long long - -void solve() { - int n; - cin >> n; - vector > a(n+1); - for (int i=1; i> u >> v; - a[u].push_back(v); - a[v].push_back(u); - } - if (n == 2) { - cout << 0 << endl; - } else if (n == 3){ - cout << 1 << endl; - } else if (n == 4) { - cout << 2 << endl; - } else { - int ans = 1; - vector > num(n+1); - for (int i=1; i<=n; i++) { - num[i].first = a[i].size(); - num[i].second = i; - } - sort(all(num)); - int p = n; - int cnt = 0; - while (num[p].first == num[n].first && cnt < 10) { - int res = 1; - res += num[p].first - 1; - vector > kk(n+1); - for (int i=1; i<=n; i++) { - if (i == num[p].second) { - continue; - } - kk[i].first = a[i].size(); - kk[i].second = i; - } - for (auto x : a[num[p].second]) { - kk[x].first--; - } - sort(all(kk)); - res += kk[n].first - 1; - ans = max(ans, res); - p--; - cnt++; - } - cout << ans << endl; - } -} - -signed main () -{ - IOS; - int t = 1; - cin >> t; - while(t--){ - solve(); - } - return 0; -} -",2 -a_garg#,2063C - Remove Exactly Two,c++20 ,303831700,303832038,"#include -using namespace std; -// #include -// #include -// using namespace __gnu_pbds; - -// template -// using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using ordered_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -typedef long long int ll; -ll M = 1e9+7; -const ll N = 2e5 + 5; -#define pb push_back -#define in insert -#define vll vector -#define pll pair -#define vbl vector -#define vpll vector> -#define vvll vector> -#define sll set -#define all(c) c.begin(),c.end() -#define msll multiset -#define repr(i,n) for(ll i=n-1;i>=0;i--) -#define rep(i,n) for(ll i=0;i>c[i]; -#define endl ""\n"" - -int main(){ - ll tt = 1 ; - cin >> tt ; - while(tt--){ - ll n ; cin >> n ; - map m ; - vpll v; - ll ct[n+1]={0}; - rep(i,n-1){ - ll x,y ; cin >> x>> y; - ct[x]++; - ct[y]++; - m[{x,y}]++; - m[{y,x}]++; - } - rep1(i,n)v.pb({ct[i],i}); - sort(all(v)); - reverse(all(v)); - ll ans = v[0].first; - rep1(i,v.size()-1){ - if(m[{v[0].second,v[i].second}])ans=max(ans,v[0].first+v[i].first-1); - else ans=max(ans,v[0].first+v[i].first); - } - cout< -using namespace std; -// #include -// #include -// using namespace __gnu_pbds; - -// template -// using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; -// template -// using ordered_multiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -typedef long long int ll; -ll M = 1e9+7; -const ll N = 2e5 + 5; -#define pb push_back -#define in insert -#define vll vector -#define pll pair -#define vbl vector -#define vpll vector> -#define vvll vector> -#define sll set -#define all(c) c.begin(),c.end() -#define msll multiset -#define repr(i,n) for(ll i=n-1;i>=0;i--) -#define rep(i,n) for(ll i=0;i>c[i]; -#define endl ""\n"" - -int main(){ - ll tt = 1 ; - cin >> tt ; - while(tt--){ - ll n ; cin >> n ; - map m ; - vpll v; - ll ct[n+1]={0}; - rep(i,n-1){ - ll x,y ; cin >> x>> y; - ct[x]++; - ct[y]++; - m[{x,y}]++; - m[{y,x}]++; - } - rep1(i,n)v.pb({ct[i],i}); - sort(all(v)); - reverse(all(v)); - ll ans = v[0].first; - rep1(i,v.size()-1){ - if(m[{v[0].second,v[i].second}])ans=max(ans,v[0].first+v[i].first-1); - else ans=max(ans,v[0].first+v[i].first); - if(i>1){ - if(m[{v[1].second,v[i].second}])ans=max(ans,v[1].first+v[i].first-1); - else ans=max(ans,v[1].first+v[i].first); - } - } - cout< -#include -#include -#include -#include -#include - -using namespace std; -typedef long long ll; - -void solve() -{ - int n; - cin>>n; - vector> g(n+1); - vector ind(n+1,0); - - for(int i=0,u,v;i>u>>v; - g[u].push_back(v),g[v].push_back(u); - ind[u]++,ind[v]++; - } - - int tag=0,cnt=0; - for(int i=1;i<=n;++i) - if(ind[i]>ind[tag]) tag=i,cnt=1; - else if(ind[i]==ind[tag]) cnt++; - - if(cnt>=3) cout<>t; - while(t--) solve(); - - return 0; -} -","#include -#include -#include -#include -#include -#include - -using namespace std; -typedef long long ll; - -void solve() -{ - int n; - cin>>n; - vector> g(n+1); - vector ind(n+1,0); - - for(int i=0,u,v;i>u>>v; - g[u].push_back(v),g[v].push_back(u); - ind[u]++,ind[v]++; - } - - int tag=0,cnt=0; - for(int i=1;i<=n;++i) - if(ind[i]>ind[tag]) tag=i,cnt=1; - else if(ind[i]==ind[tag]) cnt++; - - if(cnt>=3) cout<>t; - while(t--) solve(); - - return 0; -} -",1 -RH_Shaudho,2063C - Remove Exactly Two,c++17 ,304908585,304908056,"#include -using namespace std; -#define ll long long -#define pb push_back -bool cmp(paira,pairb){ -return a.second>b.second; -} -void solve(ll tc) -{ - ll n,i,x,y,s=0,qq,ww,s2=0,ee,m; - cin>>n; - vector>p(n+9); - for(i=1;i<=n;i++) p[i].first=i,p[i].second=0; - vector> ps(n+3); - for(i=1;i>x>>y; - p[x].second++; - p[y].second++; - ps[x].insert(y); - ps[y].insert(x); - } - sort(p.begin(),p.end(),cmp); - - s=p[0].second; - qq=p[0].first; - m=min(n,s+2); - for(i=1;i>tc; - for(ll i=1; i<=tc; i++) - { - solve(i); - } -} -","#include -using namespace std; -#define ll long long -#define pb push_back -bool cmp(paira,pairb){ -return a.second>b.second; -} -void solve(ll tc) -{ - ll n,i,x,y,s=0,qq,ww,s2=0,ee; - cin>>n; - vector>p(n+3); - for(i=1;i<=n;i++) p[i].first=i,p[i].second=0; - vector> ps(n+3); - for(i=1;i>x>>y; - p[x].second++; - p[y].second++; - ps[x].insert(y); - ps[y].insert(x); - } - sort(p.begin(),p.end(),cmp); - - s=p[0].second; - qq=p[0].first; - for(i=1;i>tc; - for(ll i=1; i<=tc; i++) - { - solve(i); - } -} -",1 -fly_1,2063C - Remove Exactly Two,c++17 ,307141727,307141275,"#include -using namespace std; - -#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); -#define in_ freopen(""input.txt"", ""r"", stdin); -#define all(a) a.begin(), a.end() -#define cout2(a) for(int i = 0; i < a.size(); ++ i) cout << a[i] << "" ""; cout << ""\n""; -#define cout1(a, s, e) for(int i = s; i < e; ++ i) cout << a[i] << "" ""; cout << ""\n""; -#define debug1(x) cout << x << ""!!!\n""; -#define debug2(x) cout << x << ""###\n""; - -typedef long long ll; -const int N = 200005; -typedef pair PII; - -#define x1 first -#define y1 second - -void deal() { - - int n; - cin >> n; - - vector deg(n), a; - vector e(n); - - for(int i = 0; i < n - 1; ++ i) { - int u, v; - cin >> u >> v; - - u --, v --; - deg[u] ++, deg[v] ++; - - e.push_back({u, v}); - } - - int ans = 0; -// for(auto it : e) { -// ans = max(ans, it.x1 + it.y1 - 2); -// } -// - int vmax = *max_element(deg.begin(), deg.end()); - - for(int i = 0; i < n; ++ i) if(deg[i] == vmax) a.push_back(i); - - if(a.size() >= 3) { - cout << 2 * vmax - 1 << ""\n""; - return; - } - - for(int j = 0; j < a.size(); ++j) { - vmax = a[j]; - - vector ok(n); - ok[vmax] = 1; - - for(auto it : e) { - if(it.x1 == vmax) ok[it.y1] = 1; - if(it.y1 == vmax) ok[it.x1] = 1; - } - - for(int i = 0; i < n; ++ i) { - if(i == vmax) continue; - if(ok[i]) ans = max(ans, deg[vmax] + deg[i] - 2); - else ans = max(ans, deg[vmax] + deg[i] - 1); - } - } - - cout << ans << ""\n""; - -} - -int main() { - - #ifndef ONLINE_JUDGE - in_; -// freopen(""out.txt"", ""w"", stdout); - #endif - - IOS; - - int t; - cin >> t; - while(t--) - deal(); - - return 0; -} - -/* - /\_/\ - (= ._.) - /> \> !!!!!! - author :: fly - -*/ ","#include -using namespace std; - -#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); -#define in_ freopen(""input.txt"", ""r"", stdin); -#define all(a) a.begin(), a.end() -#define cout2(a) for(int i = 0; i < a.size(); ++ i) cout << a[i] << "" ""; cout << ""\n""; -#define cout1(a, s, e) for(int i = s; i < e; ++ i) cout << a[i] << "" ""; cout << ""\n""; -#define debug1(x) cout << x << ""!!!\n""; -#define debug2(x) cout << x << ""###\n""; - -typedef long long ll; -const int N = 200005; -typedef pair PII; - -#define x1 first -#define y1 second - -void deal() { - - int n; - cin >> n; - - vector deg(n), a; - vector e(n); - - for(int i = 0; i < n - 1; ++ i) { - int u, v; - cin >> u >> v; - - u --, v --; - deg[u] ++, deg[v] ++; - - e.push_back({u, v}); - } - - int ans = 0; -// for(auto it : e) { -// ans = max(ans, it.x1 + it.y1 - 2); -// } -// - int vmax = *max_element(deg.begin(), deg.end()); - - for(int i = 0; i < n; ++ i) if(deg[i] == vmax) a.push_back(i); - - for(int j = 0; j < a.size(); ++j) { - vmax = a[j]; - - vector ok(n); - ok[vmax] = 1; - - for(auto it : e) { - if(it.x1 == vmax) ok[it.y1] = 1; - if(it.y1 == vmax) ok[it.x1] = 1; - } - - for(int i = 0; i < n; ++ i) { - if(i == vmax) continue; - if(ok[i]) ans = max(ans, deg[vmax] + deg[i] - 2); - else ans = max(ans, deg[vmax] + deg[i] - 1); - } - } - - cout << ans << ""\n""; - -} - -int main() { - - #ifndef ONLINE_JUDGE - in_; -// freopen(""out.txt"", ""w"", stdout); - #endif - - IOS; - - int t; - cin >> t; - while(t--) - deal(); - - return 0; -} - -/* - /\_/\ - (= ._.) - /> \> !!!!!! - author :: fly - -*/ ",1 -avi258719,2063C - Remove Exactly Two,c++23 ,307130207,307129940,"#include -using namespace std; -#define int long long - -int32_t main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - if(n == 1){ - cout << 0 << ""\n""; - continue; - } - - - vector> adj(n+1); - vector degree(n+1, 0);vector>v1(n-1); - for(int i = 0; i < n-1; i++){ - int u, v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - degree[u]++; - degree[v]++; - v1[i].first=u,v1[i].second=v; - } - - - for (int i = 1; i <= n; i++){ - sort(adj[i].begin(), adj[i].end()); - } - - - vector> vertices; - vertices.reserve(n); - for(int i = 1; i <= n; i++){ - vertices.push_back({degree[i], i}); - } - sort(vertices.begin(), vertices.end(), [&](auto &a, auto &b){ - return a.first > b.first; - }); - - // We only need to check the top k candidates. - int k = n; - int ans = 0; - - auto isAdjacent = [&](int u, int v) -> bool { - - return binary_search(adj[u].begin(), adj[u].end(), v); - }; - - - for (int i = 0; i < k; i++){ - for (int j = i + 1; j < k; j++){ - int u = vertices[i].second; - int v = vertices[j].second; - if (!isAdjacent(u, v)){ - ans = max(ans, vertices[i].first + vertices[j].first); - - break; - } - } - } - int maxi=0; - for(int i=0;i -using namespace std; -#define int long long - -int32_t main(){ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while(t--){ - int n; - cin >> n; - if(n == 1){ - cout << 0 << ""\n""; - continue; - } - - - vector> adj(n+1); - vector degree(n+1, 0);vector>v1(n-1); - for(int i = 0; i < n-1; i++){ - int u, v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - degree[u]++; - degree[v]++; - v1[i].first=u,v1[i].second=v; - } - - - for (int i = 1; i <= n; i++){ - sort(adj[i].begin(), adj[i].end()); - } - - - vector> vertices; - vertices.reserve(n); - for(int i = 1; i <= n; i++){ - vertices.push_back({degree[i], i}); - } - sort(vertices.begin(), vertices.end(), [&](auto &a, auto &b){ - return a.first > b.first; - }); - - - int k = min(n, (int)5000); - int ans = 0; - - auto isAdjacent = [&](int u, int v) -> bool { - - return binary_search(adj[u].begin(), adj[u].end(), v); - }; - - - for (int i = 0; i < k; i++){ - for (int j = i + 1; j < k; j++){ - int u = vertices[i].second; - int v = vertices[j].second; - if (!isAdjacent(u, v)){ - ans = max(ans, vertices[i].first + vertices[j].first); - - break; - } - } - } - int maxi=0; - for(int i=0;i -#include -#include - -using namespace std; -using namespace chrono; -using namespace __gnu_pbds; - -template using oset = tree, rb_tree_tag, tree_order_statistics_node_update >; // *find_by_order, order_of_key -- gives the number of elements smaller than the number searched - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -#define forn(i,a,n) for (long long i=a; i>a[i]} -#define seev(v,n) for (long long i=0; i>x; v.push_back(x);} -#define sees(s,n) for (long long i=0; i>x; s.insert(x);} - -#define yeah cout<<""YES\n"" -#define nah cout<<""NO\n"" -#define nl cout<<""\n"" -#define endl ""\n"" - -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define PI 3.141592653589793238462 - - -#define debug(x) cerr << #x<<"" ""; _print(x); cerr << endl; - -void _print(int t) {cerr< void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - -bool isPrime(int n){ for (int i = 2; i * i <= n; i++){ if (n % i == 0){ return false; }} return true; } -int nextPrime(int n){ n++; while(!isPrime(n)){ n++; } return n; } -int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} -int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} -int mminvprime(int a, int b) {return expo(a, b - 2, b);} -int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m - -// int a[300001], b[300001]; -void solve(){ - -int n,ans = 0; - cin>>n; -mapdegree; -vector>vec; -set>edge; -map>mp; -int m1 = 0,m2 = 0,maxx = 0; - -for (int i = 1; i < n; i++) -{ - int u,v;cin>>u>>v;degree[u]++;degree[v]++; - mp[u].pb(v); mp[v].pb(u); - edge.insert({u,v}); - edge.insert({v,u}); -} - -for (int i = 1; i <= n; i++) -{ - for (auto j : mp[i]) - { - ans = max(ans, degree[i] + degree[j] - 2); - } - vec.pb({degree[i],i}); - } - -sort(vec.begin(),vec.end()); - -for (int i = n-1; i >= 0; i--) -{ int j = i-1; - for (; j >= 0 && edge.find({vec[i].second,vec[j].second}) != edge.end(); j--) - { - 1; - } - if(j >= 0){ - ans = max(ans, vec[i].first+vec[j].first - 1); - } -} - - -cout<>t; - -for (int i = 0; i < t; i++) -{ - solve(); - -} - - - - return 0; -}"," -#pragma GCC optimize(""O3,unroll-loops"") - -#include -#include -#include - -using namespace std; -using namespace chrono; -using namespace __gnu_pbds; - -template using oset = tree, rb_tree_tag, tree_order_statistics_node_update >; // *find_by_order, order_of_key -- gives the number of elements smaller than the number searched - -#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) - -#define forn(i,a,n) for (long long i=a; i>a[i]} -#define seev(v,n) for (long long i=0; i>x; v.push_back(x);} -#define sees(s,n) for (long long i=0; i>x; s.insert(x);} - -#define yeah cout<<""YES\n"" -#define nah cout<<""NO\n"" -#define nl cout<<""\n"" -#define endl ""\n"" - -#define MOD 1000000007 -#define MOD1 998244353 -#define INF 1e18 -#define PI 3.141592653589793238462 - - -#define debug(x) cerr << #x<<"" ""; _print(x); cerr << endl; - -void _print(int t) {cerr< void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - - -bool isPrime(int n){ for (int i = 2; i * i <= n; i++){ if (n % i == 0){ return false; }} return true; } -int nextPrime(int n){ n++; while(!isPrime(n)){ n++; } return n; } -int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} -int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} -int mminvprime(int a, int b) {return expo(a, b - 2, b);} -int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m - -// int a[300001], b[300001]; -void solve(){ - -int n; cin>>n; -mapdegree; -map>mp; -int m1 = 0,m2 = 0,maxx; -for (int i = 1; i < n; i++) -{ - int u,v;cin>>u>>v;degree[u]++;degree[v]++; - mp[u].pb(v); mp[v].pb(u); -} -for (int i = 1; i <= n; i++) -{ - if(degree[i] >= m1){maxx = i; m1 = degree[i];} - // else{m2 = max(degree[i],m2);} -} - -for (auto i : mp[maxx]){degree[i]--;} - - -for (int i = 1; i <= n && i != maxx; i++) -{ - if(degree[i] >= m2){ m2 = degree[i];} -} - - - - - - -// cout<>t; - -for (int i = 0; i < t; i++) -{ - solve(); - -} - - - - return 0; -}",1 -WrongAnswerOnTestCase2,2063C - Remove Exactly Two,java,304673310,304678003,"import java.util.*; -import java.lang.*; -import java.io.*; -public class Codechef - { - static FastScanner fs = null; - static ArrayList> list; - static int co[]; - public static void main(String[] args) { - fs = new FastScanner(); - PrintWriter out = new PrintWriter(System.out); - int t = fs.nextInt(); - while(t-->0){ - list = new ArrayList<>(); - int n = fs.nextInt(); - co = new int[n+1]; - for(int i = 0;i<=n;i++){ - Set se = new HashSet<>(); - list.add(se); - } - for(int i = 1;i(mx-dif)){ - dif = -1; - mx = sz; - } - else{ - mx = mx; - dif = 0; - } - int ans = 0; - if(par!=-1){ - ans = d1+d2+sz-1; - } - for(Integer p:list.get(node)){ - if(p==par) - continue; - int re = dfs(p,node,mx,dif); - ans = Math.max(ans,re); - } - - //System.out.println(d1+"" -- ""+d2+"" --- ""+node+"" -- ""+par+"" -- ""+sz); - return ans; - } - static void sort(int[] a) { - ArrayList l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l); - for (int i=0; i> list; - static int co[]; - static Map map; - static TreeSet ts; - static int inf = (int)1e8; - static boolean vis[]; - public static void main(String[] args) { - fs = new FastScanner(); - - PrintWriter out = new PrintWriter(System.out); - int t = fs.nextInt(); - while(t-->0){ - list = new ArrayList<>(); - int n = fs.nextInt(); - co = new int[n+1]; - ts = new TreeSet<>(); - map = new HashMap<>(); - vis = new boolean[n+1]; - Arrays.fill(vis,false); - for(int i = 0;i<=n;i++){ - Set se = new HashSet<>(); - list.add(se); - } - for(int i = 1;i l=new ArrayList<>(); - for (int i:a) l.add(i); - Collections.sort(l); - for (int i=0; i -using namespace std; -#define ll long long - -const ll MOD = 1e9 + 7; -const ll MAX_N = 5e5; - -int main() { - ll t; - cin >> t; - while (t--) { - ll n; - cin >> n; - ll temp = n - 1; - map> m; - - // Read input and construct adjacency list - while (temp--) { - ll l, r; - cin >> l >> r; - m[l].insert(r); - m[r].insert(l); - } - - ll v = -1; - ll maxx = 0; - ll ans = 0; - - for (auto& i : m) { - if (i.second.size() > maxx) { - maxx = i.second.size(); - v = i.first; - } - } - - if (v != -1) { - for (auto i : m[v]) { - if (m.find(i) != m.end()) { - m[i].erase(v); - } - } - m.erase(v); - ans += maxx; - } - - maxx = 0; - v = -1; - - - for (auto& i : m) { - if (i.second.size() > maxx) { - maxx = i.second.size(); - v = i.first; - } - } - - if (v != -1) { - for (auto i : m[v]) { - if (m.find(i) != m.end()) { - m[i].erase(v); - } - } - m.erase(v); - ans += maxx; - } - - cout << ans - 1 << endl; - } - return 0; -} -","#include -using namespace std; -#define ll long long - -const ll MOD = 1e9 + 7; -const ll MAX_N = 5e5; - -int main() { - ll t; - cin >> t; - while (t--) { - ll n; - cin >> n; - ll temp = n - 1; - map> m; - - while (temp--) { - ll l, r; - cin >> l >> r; - m[l].insert(r); - m[r].insert(l); - } - // for(auto i :m){ - // cout< maxx) { - maxx = i.second.size(); - v = i.first; - } - } - for(auto i : m){ - if(i.second.size() == maxx){ - cnt++; - } - } - if(cnt>=3){ - cout<<2*maxx - 1< maxx) { - maxx = i.second.size(); - v = i.first; - } - } - - if (v != -1) { - for (auto i : m[v]) { - if (m.find(i) != m.end()) { - m[i].erase(v); - } - } - m.erase(v); - ans += maxx; - } - // for(auto i :m){ - // cout< -using namespace std; -#define Sort(a) sort(a.begin(),a.end()); -#define all(a) a.begin(),a.end() -#define pb(x) push_back(x) -#define printvec(v) for(auto x : v) cout<>x;} - -typedef long long ll; -#define int long long int -const int mod=1e9+7; -const int N=2e5+7; -vector graph[N]; -vector vis(N,0); - struct val{ - int self=0,child=0; - }; -void solve(){ - - //Start writing from here - int n;cin>>n; - vector tree[n+1]; - for(int i=0;i>u>>v; - tree[u].push_back(v); - tree[v].push_back(u); - } - int best=0; - vector deg(n+1,0); - for(int i=1;i<=n;i++) deg[i]=tree[i].size(); - multiset mst; - for(auto x: deg) mst.insert(x); - for(int node=1;node<=n;node++){ - //if remove this vertex - //choose to remove the second vertex that is adj - mst.erase(mst.find(deg[node])); - for(auto x : tree[node]){ - best=max(best,deg[node]+deg[x]-2); - } - //choose to remove the vertex not adj - vector temp(1,deg[node]); - for(auto x : tree[node]){ - temp.push_back(deg[x]); - mst.erase(mst.find(deg[x])); - } - best=max(best,*prev(mst.end())+deg[node]-1); - for(auto x: temp) mst.insert(x); - } - cout<> t; - while (t--) - { - - solve(); - } - return 0; -}","#include -using namespace std; -#define Sort(a) sort(a.begin(),a.end()); -#define all(a) a.begin(),a.end() -#define pb(x) push_back(x) -#define printvec(v) for(auto x : v) cout<>x;} - -typedef long long ll; -#define int long long int -const int mod=1e9+7; -const int N=2e5+7; -vector graph[N]; -vector vis(N,0); - struct val{ - int self=0,child=0; - }; -void solve(){ - - //Start writing from here - int n;cin>>n; - vector tree[n+1]; - for(int i=0;i>u>>v; - tree[u].push_back(v); - tree[v].push_back(u); - } - int best=0; - vector temp(n+1); - function dfs1=[&](int node,int par)->int { - int total=0; - for(auto child : tree[node]){ - if(child !=par){ - total=max(dfs1(child,node),total); - } - } - temp[node].child=total; - total=max(total,(int)tree[node].size()); - temp[node].self=total; - return total; - }; - dfs1(1,0); - function dfs=[&](int node,int par)->void { - for(auto child : tree[node]){ - if(child !=par){ - best=max(best,(int)(temp[child].child+tree[node].size()-1)); - best=max(best,(int)(tree[node].size()+tree[child].size()-2)); - dfs(child,node); - } - } - }; - dfs(1,0); - //non adjacent - cout<> t; - while (t--) - { - - solve(); - } - return 0; -}",1 -Variant373,2063C - Remove Exactly Two,c++23 ,305119443,305122042,"#include - -#define fastio \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) - -#define endl ""\n"" -#define fraction() \ - cout.unsetf(ios::floatfield); \ - cout.precision(10); \ - cout.setf(ios::fixed, ios::floatfield); -#define mem(a, b) memset(a, b, sizeof(a)) - -using namespace std; - -typedef long long ll; -typedef double dl; -class tree -{ - vector> adj; - // map size; - int n; - -public: - tree(int n) : n(n) - { - adj.resize(n + 1); - // size.resize(n+1); - input(); - } - void input() - { - for (int i = 1; i < n; i++) - { - int u, v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - // size[u]++; - // size[v]++; - } - solve(); - } - - void solve() - { - - ll ans = 0; - vector> v; - for (int i = 1; i < adj.size(); i++)// 1 indexed 1->n - { - v.push_back({adj[i].size(), i}); - } - // cout< m_connected_to_ele1; - for (int i = 0; i < adj[ele1].size(); i++) - { - m_connected_to_ele1[adj[ele1][i]] = true; - } - // cout<first; - // it++; - // ele2=it->second; - - // cout<> n; - tree t(n); -} - -int main() -{ - fastio; - ll t = 1; - cin >> t; - - for (int i = 1; i <= t; i++) - { - solve(i); - } - return 0; -}","#include - -#define fastio \ - ios_base::sync_with_stdio(false); \ - cin.tie(NULL) - -#define endl ""\n"" -#define fraction() \ - cout.unsetf(ios::floatfield); \ - cout.precision(10); \ - cout.setf(ios::fixed, ios::floatfield); -#define mem(a, b) memset(a, b, sizeof(a)) - -using namespace std; - -typedef long long ll; -typedef double dl; -class tree -{ - vector> adj; - // map size; - ll n; - -public: - tree(ll n) : n(n) - { - adj.resize(n + 1); - // size.resize(n+1); - input(); - } - void input() - { - for (ll i = 1; i < n; i++) - { - ll u, v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - // size[u]++; - // size[v]++; - } - solve(); - } - - ll ret(vector> &v, int ii) - { - ll ans = 0; - - ll ele1 = v[ii].second; // ele with max child - ans = adj[ele1].size(); - - map m_connected_to_ele1; - for (ll i = 0; i < adj[ele1].size(); i++) - { - m_connected_to_ele1[adj[ele1][i]] = true; - } - // cout<> v; - for (ll i = 1; i < adj.size(); i++) // 1 indexed 1->n - { - v.push_back({adj[i].size(), i}); - } - // cout<first; - // it++; - // ele2=it->second; - - // cout<> n; - tree t(n); -} - -int main() -{ - fastio; - ll t = 1; - cin >> t; - - for (ll i = 1; i <= t; i++) - { - solve(i); - } - return 0; -}",2 -raghav_misr,2063C - Remove Exactly Two,c++20 ,304261158,304259102,"#include -using namespace std; -#define int long long -#define vi vector -#define pb push_back -#define all(x) (x).begin(), (x).end() - -void solve() { - int n; - cin >> n; - vi adj[n + 1]; - vi f(n + 1, 0); - - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - adj[u].pb(v); - adj[v].pb(u); - f[u]++; - f[v]++; - } - - if (n <= 2) { - cout << 0 << endl; - return; - } - if (n == 3) { - cout << 1 << endl; - return; - } - - int ind = max_element(all(f)) - f.begin(); - int ans = f[ind]; - - int ct = 0; - for (auto it : adj[ind]) { - if (f[it] == ans) - ct++; - } - - if (ct >= 2) { - cout << (ans + ans - 1) << endl; - return; - } - - for (auto it : adj[ind]) { - f[it]--; - } - f[ind] = 0; - - int ind1 = max_element(all(f)) - f.begin(); - ans += (f[ind1] - 1); - cout << ans << endl; -} - -signed main() { - ios::sync_with_stdio(false); - cin.tie(0); - int tc; - cin >> tc; - while (tc--) solve(); - return 0; -} -","#include -using namespace std; -#define int long long -#define vi vector -#define pb push_back -#define all(x) (x).begin(), (x).end() - -void solve() { - int n; - cin >> n; - vi adj[n + 1]; - vi f(n + 1, 0); - - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - adj[u].pb(v); - adj[v].pb(u); - f[u]++; - f[v]++; - } - f[1]=1; - - if (n <= 2) { - cout << 0 << endl; - return; - } - // if (n == 3) { - // cout << 1 << endl; - // return; - // } - - int mx = max_element(f.begin() + 1, f.end()) - f.begin(); - // cout<""<> tc; - while (tc--) solve(); - return 0; -} -",1 -Anshu_jaiswal,2063C - Remove Exactly Two,c++17 ,304403065,304256805,"// Name-Anshu Raj Jaiswal -// Scholar id-2212172 -#include -using namespace std; -typedef long long ll; -typedef long double ld; -#define pb push_back -#define ff first -#define ss second -#define mpq priority_queue,greater> -#define mpqp priority_queue,vector>,greater>> -#define Mpq priority_queue -#define Mpqp priority_queue> -#define all(x) (x).begin(), (x).end() -const ll MOD=998244353; -const ll N=200000; -ll ceil(ll a,ll b){return (a+b-1)/b;} -void solve() -{ - ll n; - cin>>n; - vectortemp(n+1,0); - vectortemp2(n+1,0); - vector>arr(n-1); - mapmy; - for(ll i=0;i>u>>v; - temp[u]++;temp[v]++; - arr[i]={u,v}; - } - ll ans=0; - ll in=-1; - for(ll i=1;i<=n;i++) - { - if(temp[i]>ans) - { - ans=temp[i]; - in=i; - } - my[temp[i]]++; - } - if(my[ans]>2) - { - cout<<2*ans-1<>t; - while(t--) - { - solve(); - } - return 0; -} ","// Name-Anshu Raj Jaiswal -// Scholar id-2212172 -#include -using namespace std; -typedef long long ll; -typedef long double ld; -#define pb push_back -#define ff first -#define ss second -#define mpq priority_queue,greater> -#define mpqp priority_queue,vector>,greater>> -#define Mpq priority_queue -#define Mpqp priority_queue> -#define all(x) (x).begin(), (x).end() -const ll MOD=998244353; -const ll N=200000; -ll ceil(ll a,ll b){return (a+b-1)/b;} -ll pi=0; -void dfs(ll node,vector&vis,vector&temp2,vector>&adj) -{ - vis[node]=1; - for(auto it:adj[node]) - { - if(!vis[it]) - { - temp2[node]++; - temp2[it]++; - dfs(it,vis,temp2,adj); - } - } - return; -} -void solve() -{ - ll n; - cin>>n; - vector>adj(n+1); - vectortemp(n+1,0); - vector>arr(n-1); - for(ll i=0;i>u>>v; - temp[u]++;temp[v]++; - arr[i]={u,v}; - } - ll ans=0; - ll in=-1; - for(int i=0;ians) - { - ans=temp[i]; - in=i; - } - } - ans--; - for(ll i=0;ivis(n+1,0); - vectortemp2(n+1,0); - for(ll i=0;i>t; - while(t--) - { - solve(); - } - return 0; -} ",1 -hyfhaha,2063C - Remove Exactly Two,c++17 ,305598123,305599798,"#include -#define endl '\n' -#define int long long -#define unmap unordered_map -#define unset unordered_set -#define MAXQ priority_queue -using namespace std; -template using MINQ=priority_queue,greater >; -using pii=pair; -using vi=vector; -using vii=vector; - -#define maxn 1000010 - -int n; -int cnt,from[maxn],to[maxn],Next[maxn],head[maxn]; -int f[maxn][2][2]; - -void add(int u,int v){ - cnt++; - from[cnt]=u; to[cnt]=v; - Next[cnt]=head[u]; head[u]=cnt; -} - -void dfs(int u,int fa){ - int son=0,maxx=-1e9,maxy=-1e9; - for(int i=head[u];i!=-1;i=Next[i]){ - int v=to[i]; if(v==fa)continue; - dfs(v,u);son++; - int x=max(f[v][1][0]-1,f[v][1][1]); - if(x>maxx){ - maxy=maxx; - maxx=x; - }else{ - if(x>maxy)maxy=x; - } - } - f[u][0][0]=1; - f[u][1][1]=son;f[u][1][0]=-1e9; - f[u][2][0]=f[u][2][1]=-1e9; - f[u][2][0]=max(f[u][2][0],maxx+maxy+1); - for(int i=head[u];i!=-1;i=Next[i]){ - int v=to[i]; if(v==fa)continue; - f[u][2][0]=max(f[u][2][0],max(f[v][2][1]+1,f[v][2][0])); - f[u][2][1]=max(f[u][2][1],max(f[v][1][0]+son-1,f[v][1][1]+son-1)); - f[u][1][0]=max(f[u][1][0],max(f[v][1][1]+1,f[v][1][0])); - } -} - -void solve(){cnt=0; - cin>>n; - for(int i=1;i<=n;i++)head[i]=-1; - for(int i=1;i<=n-1;i++){ - int u,v; - cin>>u>>v; - add(u,v); - } - dfs(1,0); - // for(int i=1;i<=n;i++)cout<>_t; - //cout< -#define endl '\n' -#define int long long -#define unmap unordered_map -#define unset unordered_set -#define MAXQ priority_queue -using namespace std; -template using MINQ=priority_queue,greater >; -using pii=pair; -using vi=vector; -using vii=vector; - -#define maxn 1000010 - -int n; -int cnt,from[maxn],to[maxn],Next[maxn],head[maxn]; -int f[maxn][3][3]; - -void add(int u,int v){ - cnt++; - from[cnt]=u; to[cnt]=v; - Next[cnt]=head[u]; head[u]=cnt; -} - -void dfs(int u,int fa){ - int son=0,maxx=-1e9,maxy=-1e9; - for(int i=head[u];i!=-1;i=Next[i]){ - int v=to[i]; if(v==fa)continue; - dfs(v,u);son++; - int x=max(f[v][1][0]-1,f[v][1][1]); - if(x>=maxx){ - maxy=maxx; - maxx=x; - }else{ - if(x>=maxy)maxy=x; - } - } - f[u][0][0]=1; - f[u][1][1]=son;f[u][1][0]=-1e9; - f[u][2][0]=f[u][2][1]=-1e9; - if(son>=2)f[u][2][0]=max(f[u][2][0],maxx+maxy+1); - for(int i=head[u];i!=-1;i=Next[i]){ - int v=to[i]; if(v==fa)continue; - f[u][2][0]=max(f[u][2][0],max(f[v][2][1]+1,f[v][2][0])); - f[u][2][1]=max(f[u][2][1],max(f[v][1][0]+son-1,f[v][1][1]+son-1)); - f[u][1][0]=max(f[u][1][0],max(f[v][1][1]+1,f[v][1][0])); - } -} - -void solve(){cnt=0; - cin>>n; - for(int i=1;i<=n;i++)head[i]=-1; - for(int i=1;i<=n-1;i++){ - int u,v; - cin>>u>>v; - add(u,v);add(v,u); - } - dfs(1,0); - // for(int i=1;i<=n;i++)cout<>_t; - //cout< -using namespace std; -#define int long long -#define nl ""\n"" -#define forn(a, c) for (int a = 0; a < c; a++) -#define forl(a, b, c) for (int a = b; a <= c; a++) -#define forr(a, b, c) for (int a = b; a >= c; a--) -#define cin(v) for(auto &i:v){cin>>i;} -#define cout(v) for(auto &i:v){cout<>n; - std::vector> v; - map mp; - int mx = 0; - int e1 = 0; - forn(i,n-1){ - int x,y;cin>>x>>y; - v.push_back({min(x,y),max(x,y)}); - mp[x]++; - mp[y]++; - if( mx < mp[x]){mx = mp[x];e1 = x;} - if(mx < mp[y]){mx = mp[y];e1 = y;} - } - sort(v.begin(),v.end()); - int mx2 = 0; - int e2 = 0; - for(auto &i:mp){ - if(mx-mx2 > mx-i.second && e1 != i.first){mx2 = i.second;e2 = i.first;} - } - int cn1=0,cn2=0; - for(auto &i:mp){ - if(i.second == mx)cn1++; - if(i.second == mx2)cn2++; - } - - // cout< p = {e1,e2}; - pair pp = {e2,e1}; - if(mx2 == mx){ - if(cn1 > 2){cout< pr = {min(e1,i.first),max(e1,i.first)}; - if(binary_search(v.begin(),v.end(),pr) == false){cout<>tt; - while(tt--){ - solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; -} -","#include -using namespace std; -#define int long long -#define nl ""\n"" -#define forn(a, c) for (int a = 0; a < c; a++) -#define forl(a, b, c) for (int a = b; a <= c; a++) -#define forr(a, b, c) for (int a = b; a >= c; a--) -#define cin(v) for(auto &i:v){cin>>i;} -#define cout(v) for(auto &i:v){cout<>n; - std::vector> v; - map mp; - int mx = 0; - int e1 = 0; - forn(i,n-1){ - int x,y;cin>>x>>y; - v.push_back({min(x,y),max(x,y)}); - mp[x]++; - mp[y]++; - if( mx < mp[x]){mx = mp[x];e1 = x;} - if(mx < mp[y]){mx = mp[y];e1 = y;} - } - sort(v.begin(),v.end()); - int mx2 = 0; - int e2 = 0; - for(auto &i:mp){ - if(mx-mx2 > mx-i.second && e1 != i.first){mx2 = i.second;e2 = i.first;} - } - int cn1=0,cn2=0; - for(auto &i:mp){ - if(i.second == mx)cn1++; - if(i.second == mx2)cn2++; - } - - // cout< p = {e1,e2}; - pair pp = {e2,e1}; - if(mx2 == mx){ - if(cn1 > 2){cout< pr = {max(e1,i.first),min(e1,i.first)}; - if(binary_search(v.begin(),v.end(),pr) == false){cout<>tt; - while(tt--){ - solve(); - } - auto end = std::chrono::high_resolution_clock::now(); - auto elapsed = std::chrono::duration_cast(end - begin); - cerr << ""Time measured: "" << elapsed.count() * 1e-9 << "" seconds.\n""; -} -",1 -hyjhyj111,2063C - Remove Exactly Two,c++23 ,305131841,305128637,"#include -using i64 = long long; -#ifndef ATCODER -consteval auto operator"""" _f(const char* str, std::size_t len) { - return [fmt = std::string_view(str, len)](auto&&... args) { - return std::vformat(fmt, std::make_format_args(args...)); - }; -} -#endif - -void solve() { - int n; - std::cin >> n; - - std::vector> adj(n); - std::vector max(n); - for (int i = 1, u, v;i < n;i ++) { - std::cin >> u >> v; - u --, v --; - adj[u].push_back(v); - adj[v].push_back(u); - } - - int ans = 0; - auto dfs = [&](this auto &&self, int ind, int p) -> void{ - int mx1 = 0, mx2 = 0; - for (auto &to : adj[ind]) { - if (to == p) continue; - self(to, ind); - max[ind] = std::max(max[ind], std::max(max[to], int(adj[to].size()))); - ans = std::max(ans, int(adj[ind].size() + adj[to].size()) - 2); - ans = std::max(ans, int(adj[ind].size()) + max[to] - 1); - int smx = std::max(max[to], int(adj[to].size())); - if (mx1 <= smx) { - mx2 = mx1; - mx1 = smx; - } else if (mx2 < smx) { - mx2 = smx; - } - } - ans = std::max(ans, mx1 + mx2 - 1); - }; - dfs(0, -1); - - std::cout << ans << ""\n""; -} -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - std::cin >> t; - - while (t --) { - solve(); - } - return 0; -}","#include -using i64 = long long; -#ifndef ATCODER -consteval auto operator"""" _f(const char* str, std::size_t len) { - return [fmt = std::string_view(str, len)](auto&&... args) { - return std::vformat(fmt, std::make_format_args(args...)); - }; -} -#endif - -void solve() { - int n; - std::cin >> n; - - std::vector> adj(n); - std::vector> a(n); - for (int i = 1, u, v;i < n;i ++) { - std::cin >> u >> v; - u --, v --; - adj[u].push_back(v); - adj[v].push_back(u); - } - for (int i = 0;i < n;i ++) { - a[i] = {int(adj[i].size()), i}; - } - - std::sort(a.begin(), a.end()); - auto [d, id] = a.back(); - a.pop_back(); - std::sort(adj[id].begin(), adj[id].end()); - - int ans = 0; - while (a.size()) { - int to = a.back()[1]; - if (auto it = std::lower_bound(adj[id].begin(), adj[id].end(), a.back()[1]); it != adj[id].end() and *it == a.back()[1]) { - ans = std::max(ans, d + int(adj[to].size()) - 2); - } else { - ans = std::max(ans, d + int(adj[to].size()) - 1); - } - a.pop_back(); - } - std::cout << ans << ""\n""; -} -int32_t main() { - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - - int t = 1; - std::cin >> t; - - while (t --) { - solve(); - } - return 0; -}",1 -InvMod,2063C - Remove Exactly Two,c++17 ,304587767,304578391,"#include -using namespace std; - -#define fi first -#define se second -#define gcd __gcd -#define sz(v) (int) v.size() -#define pb push_back -#define pi pair -#define all(v) (v).begin(), (v).end() -#define compact(v) (v).erase(unique(all(v)), (v).end()) -#define FOR(i, a, b) for(int i = (a); i <= (b); i++) -#define REV(i, a, b) for(int i = (a); i >= (b); i--) -#define dbg(x) ""["" #x "" = "" << (x) << ""]"" -///#define int long long - -using ll = long long; -using ld = long double; -using ull = unsigned long long; - -template bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} -template bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} - -const int N = 2e5+5; -const ll MOD = 1e9+7; -const ll INF = 1e18; - - - - -void solve() -{ - int n; cin >> n; - - vector> adj(n+1, vector()); - FOR(i, 1, n - 1){ - int u,v; cin >> u >> v; - adj[u].pb(v), adj[v].pb(u); - } - - multiset s; - FOR(i, 1, n){ - s.insert(sz(adj[i])); - } - - int answer = 0; - FOR(x, 1, n){ - s.erase(s.find(sz(adj[x]))); - for(int v : adj[x]){ - answer = max(answer, sz(adj[x]) + sz(adj[v]) - 2); - s.erase(s.find(sz(adj[v]))); - } - - if(s.size() > 0) - answer = max(answer, sz(adj[x]) + (*(--(s.end()))) - 1); - - for(int v : adj[x]){ - s.insert(sz(adj[v])); - } - s.insert(sz(adj[x])); - } - - cout << answer << ""\n""; - - return; -} - -signed main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - #define name ""InvMOD"" - if(fopen(name"".INP"", ""r"")){ - freopen(name"".INP"",""r"",stdin); - freopen(name"".OUT"",""w"",stdout); - } - - int t = 1; cin >> t; - while(t--) solve(); - return 0; -} -","#include -using namespace std; - -#define fi first -#define se second -#define gcd __gcd -#define sz(v) (int) v.size() -#define pb push_back -#define pi pair -#define all(v) (v).begin(), (v).end() -#define compact(v) (v).erase(unique(all(v)), (v).end()) -#define FOR(i, a, b) for(int i = (a); i <= (b); i++) -#define REV(i, a, b) for(int i = (a); i >= (b); i--) -#define dbg(x) ""["" #x "" = "" << (x) << ""]"" -///#define int long long - -using ll = long long; -using ld = long double; -using ull = unsigned long long; - -template bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} -template bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} - -const int N = 2e5+5; -const ll MOD = 1e9+7; -const ll INF = 1e18; - - - - -void solve() -{ - int n; cin >> n; - - vector> adj(n + 1, vector()); - FOR(i, 1, n - 1){ - int u,v; cin >> u >> v; - adj[u].pb(v), adj[v].pb(u); - } - - vector f(n + 1, -1e9); - - int answer = 0; - - auto dfs = [&](auto&& dfs, int x, int p) -> void{ - for(int v : adj[x])if(v != p){ - dfs(dfs, v, x); - - f[x] = max(f[x], max(sz(adj[v]) - 1, f[v])); - answer = max(answer, sz(adj[x]) + sz(adj[v]) - 2); - answer = max(answer, sz(adj[x]) + f[v]); - } - }; - - dfs(dfs, 1, -1); - - cout << answer << ""\n""; -} - -signed main() -{ - ios_base::sync_with_stdio(0); - cin.tie(0); - cout.tie(0); - - #define name ""InvMOD"" - if(fopen(name"".INP"", ""r"")){ - freopen(name"".INP"",""r"",stdin); - freopen(name"".OUT"",""w"",stdout); - } - - int t = 1; cin >> t; - while(t--) solve(); - return 0; -} -",1 -Arav205,2063C - Remove Exactly Two,c++17 ,303815002,303796684,"#include -#define ll long long -using namespace std; - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) { - ll n; - cin >> n; - vector> adj(n); - set> s; - - for (int i = 0; i < n - 1; i++) { - ll a, b; - cin >> a >> b; - a--; - b--; - adj[a].push_back(b); - adj[b].push_back(a); - } - - if (n == 2) { - cout << 0 << endl; - continue; - } - - for (int i = 0; i < n; i++) { - s.insert({adj[i].size(), i}); - } - - int maxi = INT_MIN; - - for (int i = 0; i < n; i++) { - - s.erase({adj[i].size(),i}); - for (auto x : adj[i]) { - maxi = max(maxi, (int)(adj[i].size() + adj[x].size() - 1)); - s.erase({adj[x].size(), x}); - } - - if (!s.empty()) { - auto maxElement = *s.rbegin(); - maxi = max(maxi, (int)(adj[i].size() + maxElement.first)); - } - for (auto x : adj[i]) { - - s.insert({adj[x].size(), x}); - } - s.insert({adj[i].size(),i}); - - - } - - cout << maxi - 1 << endl; - } - - return 0; -} -","#include -#define ll long long -using namespace std; - -ll f(vector>& adj, ll node, ll count, ll n, ll pre) { - if (count == 0) { - return 0; - } - if (node >= n) { - return 0; - } - - ll rem = 0, notrem = 0; - - if (pre == -1) { - rem = adj[node].size() + f(adj, node + 1, count - 1, n, node); - } else { - rem = adj[node].size(); - if (find(adj[node].begin(), adj[node].end(), pre) != adj[node].end()) { - rem--; - } - rem += f(adj, node + 1, count - 1, n, node); - } - - notrem = f(adj, node + 1, count, n, pre); - return max(rem, notrem); -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - - while (t--) { - ll n; - cin >> n; - vector> adj(n); - - for (int i = 0; i < n - 1; i++) { - ll a, b; - cin >> a >> b; - a--; - b--; - adj[a].push_back(b); - adj[b].push_back(a); - } - - if (n == 2) { - cout << 0 << endl; - continue; - } - - cout << f(adj, 0, 2, n, -1)-1 << endl; - } - - return 0; -} -",1 -_Djhhh,2063C - Remove Exactly Two,java,304848905,304849509,"import javax.swing.tree.TreeNode; -import java.io.*; -import java.util.*; - -/** - * @Author: _Djhhh - * @Introduction: - */ - -public class Main { - static FastReader fr = new FastReader(); - static FastWriter fw = new FastWriter(); - - public static void solve() { - int n=fr.nextInt(); - int[] in = new int[n]; - ArrayList> to = new ArrayList<>(); - for(int i=0;i()); - } - for(int i=0;i=mx){ - mx=in[i]; - int cnt=0; - for(var y:to.get(i)){ - if(in[y]==mx)cnt++; - } - if(cnt>=2)break; - id1=i; - } - } - for(var y:to.get(id1)){ - in[y]--; - } - in[id1]=0; - int mn=0; - for(int i=0;i=mn&&i!=id1){ - mn=in[i]; - } - } - fw.println((mx+mn-1)); - } - - public static void main(String[] args) { - int t = 1; - t = fr.nextInt(); - while (t-- > 0) solve(); - } -} - -class DSU { - int n; - int[] fa; - int[] dep; - int[] siz; - int[] edges; - boolean[] v; - DSU(int n) { - fa = new int[n]; - dep = new int[n]; - siz = new int[n]; - edges = new int[n]; - v = new boolean[n]; - for (int i = 0; i < n; i++) { - fa[i] = i; - dep[i] = 0; - siz[i] = 1; - edges[i] = 0; - v[i]=false; - } - } - int look(int x) { - if (fa[x] == x) return x; - else return fa[x] = look(fa[x]); - } - void merge(int x, int y) { - v[x]=v[y]=true; - int xx = look(x); - int yy = look(y); - if (xx == yy) return; - edges[xx] += edges[yy] + 1; - siz[xx] += siz[yy]; - if (dep[xx] < dep[yy]) { - fa[xx] = yy; - } else { - fa[yy] = xx; - } - - if (dep[xx] == dep[yy]) dep[xx]++; - } - boolean isMerge(int x, int y) { - return look(x) == look(y); - } - int getSize(int x) { - return siz[look(x)]; - } - int getEdges(int x) { - return edges[look(x)]; - } -} -class Pair { - private T1 first; - private T2 second; - - public Pair(T1 first, T2 second) { - this.first = first; - this.second = second; - } - public void setFirst(T1 first) { - this.first=first; - } - - public void setSecond(T2 second) { - this.second=second; - } - public T1 getFirst() { - return first; - } - - public T2 getSecond() { - return second; - } -} -class Algorithm { - /** - * 查找第一个大于等于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于等于 x 的位置 - */ - public static int lowBs(int[] arr, long x, int L, int R){ - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] >= x){ - res = mid; - r = mid - 1; - } - else{ - l = mid + 1; - } - } - return res; - } - - /** - * 查找第一个大于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于 x 的位置 - */ - public static int highBs(int[] arr, long x, int L, int R) { - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] > x){ - res = mid; - r = mid -1; - } - else{ - l = mid +1; - } - } - return res; - } -} -class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - int[] nextIntArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - int[] arr = new int[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Integer.parseInt(strNums[i]); - } - return arr; - } - - long[] nextLongArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - long[] arr = new long[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Long.parseLong(strNums[i]); - } - return arr; - } - - char[] nextCharArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - char[] arr = new char[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = strNums[i].charAt(0); - } - return arr; - } - - char[] StringtoChar() { - String line = nextLine(); - return line.toCharArray(); - } -} -class FastWriter { - private final PrintWriter writer; - - public FastWriter() { - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); - } - - public void print(Object object) { - writer.print(object); - } - - public void println(Object object) { - writer.println(object); - } - - public void flush() { - writer.flush(); - } -}","import javax.swing.tree.TreeNode; -import java.io.*; -import java.util.*; - -/** - * @Author: _Djhhh - * @Introduction: - */ - -public class Main { - static FastReader fr = new FastReader(); - static FastWriter fw = new FastWriter(); - - public static void solve() { - int n=fr.nextInt(); - int[] in = new int[n]; - ArrayList> to = new ArrayList<>(); - for(int i=0;i()); - } - for(int i=0;i=mx){ - mx=in[i]; - int cnt=0; - for(var y:to.get(i)){ - if(in[y]==mx)cnt++; - } - if(cnt>=2)continue; - id1=i; - } - } - for(var y:to.get(id1)){ - in[y]--; - } - in[id1]=0; - int mn=0; - for(int i=0;i=mn&&i!=id1){ - mn=in[i]; - } - } - fw.println((mx+mn-1)); - } - - public static void main(String[] args) { - int t = 1; - t = fr.nextInt(); - while (t-- > 0) solve(); - } -} - -class DSU { - int n; - int[] fa; - int[] dep; - int[] siz; - int[] edges; - boolean[] v; - DSU(int n) { - fa = new int[n]; - dep = new int[n]; - siz = new int[n]; - edges = new int[n]; - v = new boolean[n]; - for (int i = 0; i < n; i++) { - fa[i] = i; - dep[i] = 0; - siz[i] = 1; - edges[i] = 0; - v[i]=false; - } - } - int look(int x) { - if (fa[x] == x) return x; - else return fa[x] = look(fa[x]); - } - void merge(int x, int y) { - v[x]=v[y]=true; - int xx = look(x); - int yy = look(y); - if (xx == yy) return; - edges[xx] += edges[yy] + 1; - siz[xx] += siz[yy]; - if (dep[xx] < dep[yy]) { - fa[xx] = yy; - } else { - fa[yy] = xx; - } - - if (dep[xx] == dep[yy]) dep[xx]++; - } - boolean isMerge(int x, int y) { - return look(x) == look(y); - } - int getSize(int x) { - return siz[look(x)]; - } - int getEdges(int x) { - return edges[look(x)]; - } -} -class Pair { - private T1 first; - private T2 second; - - public Pair(T1 first, T2 second) { - this.first = first; - this.second = second; - } - public void setFirst(T1 first) { - this.first=first; - } - - public void setSecond(T2 second) { - this.second=second; - } - public T1 getFirst() { - return first; - } - - public T2 getSecond() { - return second; - } -} -class Algorithm { - /** - * 查找第一个大于等于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一���大于等于 x 的位置 - */ - public static int lowBs(int[] arr, long x, int L, int R){ - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] >= x){ - res = mid; - r = mid - 1; - } - else{ - l = mid + 1; - } - } - return res; - } - - /** - * 查找第一个大于 x 的位置 - * @param arr 查找数组 - * @param x 值 - * @param L 左边界 - * @param R 右边界 - * @return 第一个大于 x 的位置 - */ - public static int highBs(int[] arr, long x, int L, int R) { - int l = L; - int r = R; - int res = R + 1; - while(l <= r){ - int mid = l+r>>1; - if(arr[mid] > x){ - res = mid; - r = mid -1; - } - else{ - l = mid +1; - } - } - return res; - } -} -class FastReader { - BufferedReader br; - StringTokenizer st; - - public FastReader() { - br = new BufferedReader(new InputStreamReader(System.in)); - } - - String next() { - while (st == null || !st.hasMoreElements()) { - try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { - e.printStackTrace(); - } - } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); - } - - long nextLong() { - return Long.parseLong(next()); - } - - double nextDouble() { - return Double.parseDouble(next()); - } - - String nextLine() { - String str = """"; - try { - str = br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return str; - } - - int[] nextIntArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - int[] arr = new int[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Integer.parseInt(strNums[i]); - } - return arr; - } - - long[] nextLongArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - long[] arr = new long[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = Long.parseLong(strNums[i]); - } - return arr; - } - - char[] nextCharArray() { - String line = nextLine(); - String[] strNums = line.split(""\\s+""); - char[] arr = new char[strNums.length]; - for (int i = 0; i < strNums.length; i++) { - arr[i] = strNums[i].charAt(0); - } - return arr; - } - - char[] StringtoChar() { - String line = nextLine(); - return line.toCharArray(); - } -} -class FastWriter { - private final PrintWriter writer; - - public FastWriter() { - writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true); - } - - public void print(Object object) { - writer.print(object); - } - - public void println(Object object) { - writer.println(object); - } - - public void flush() { - writer.flush(); - } -}",2 -NinjaDoggy#,2063C - Remove Exactly Two,c++23 ,304932052,304932868,"#include -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -#ifndef LOCAL_STRESS_TEST -struct IOPre { static constexpr int TEN = 10, SZ = TEN * TEN * TEN * TEN; std::array num; constexpr IOPre() : num{} { for (int i = 0; i < SZ; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i * 4 + j] = static_cast(n % TEN + '0'); n /= TEN; } } } }; struct IO { -#if !HAVE_DECL_FREAD_UNLOCKED -#define fread_unlocked fread -#endif -#if !HAVE_DECL_FWRITE_UNLOCKED -#define fwrite_unlocked fwrite -#endif - static constexpr int SZ = 1 << 17, LEN = 32, TEN = 10, HUNDRED = TEN * TEN, THOUSAND = HUNDRED * TEN, TENTHOUSAND = THOUSAND * TEN, MAGIC_MULTIPLY = 205, MAGIC_SHIFT = 11, MASK = 15, TWELVE = 12, SIXTEEN = 16; static constexpr IOPre io_pre = {}; std::array input_buffer, output_buffer; int input_ptr_left, input_ptr_right, output_ptr_right; std::stringstream ss; IO() : input_buffer{}, output_buffer{}, input_ptr_left{}, input_ptr_right{}, output_ptr_right{} {} IO(const IO&) = delete; IO(IO&&) = delete; IO& operator=(const IO&) = delete; IO& operator=(IO&&) = delete; ~IO() { flush(); } template struct is_char { static constexpr bool value = std::is_same_v; }; template struct is_bool { static constexpr bool value = std::is_same_v; }; template struct is_string { static constexpr bool value = std::is_same_v || std::is_same_v || std::is_same_v; }; template struct is_custom { static constexpr bool value = false; }; template struct is_custom> { static constexpr bool value = true; }; template struct is_default { static constexpr bool value = is_char::value || is_bool::value || is_string::value || std::is_integral_v; }; template struct is_iterable { static constexpr bool value = false; }; template struct is_iterable< T, typename std::void_t()))>> { static constexpr bool value = true; }; template struct is_applyable { static constexpr bool value = false; }; template struct is_applyable::type>, std::void_t(std::declval()))>> { static constexpr bool value = true; }; template static constexpr bool needs_newline = (is_iterable::value || is_applyable::value) && (!is_default::value); template struct any_needs_newline { static constexpr bool value = false; }; template struct any_needs_newline> { static constexpr bool value = false; }; template struct any_needs_newline> { static constexpr bool value = needs_newline(std::declval()))> || any_needs_newline>::value; }; inline void load() { memmove(std::begin(input_buffer), std::begin(input_buffer) + input_ptr_left, input_ptr_right - input_ptr_left); input_ptr_right = input_ptr_right - input_ptr_left + static_cast(fread_unlocked(std::begin(input_buffer) + input_ptr_right - input_ptr_left, 1, SZ - input_ptr_right + input_ptr_left, stdin)); input_ptr_left = 0; } inline void read_char(char& c) { if (input_ptr_left + LEN > input_ptr_right) load(); c = input_buffer[input_ptr_left++]; } inline void read_string(std::string& x) { char c; while (read_char(c), c < '!') continue; x = c; while (read_char(c), c >= '!') x += c; } template inline std::enable_if_t, void> read_int(T& x) { if (input_ptr_left + LEN > input_ptr_right) load(); char c = 0; do c = input_buffer[input_ptr_left++]; while (c < '-'); [[maybe_unused]] bool minus = false; if constexpr (std::is_signed::value == true) if (c == '-') minus = true, c = input_buffer[input_ptr_left++]; x = 0; while (c >= '0') x = x * TEN + (c & MASK), c = input_buffer[input_ptr_left++]; if constexpr (std::is_signed::value == true) if (minus) x = -x; } inline void skip_space() { if (input_ptr_left + LEN > input_ptr_right) load(); while (input_buffer[input_ptr_left] <= ' ') input_ptr_left++; } inline void flush() { fwrite_unlocked(std::begin(output_buffer), 1, output_ptr_right, stdout); output_ptr_right = 0; } inline void write_char(char c) { if (output_ptr_right > SZ - LEN) flush(); output_buffer[output_ptr_right++] = c; } inline void write_bool(bool b) { if (output_ptr_right > SZ - LEN) flush(); output_buffer[output_ptr_right++] = b ? '1' : '0'; } inline void write_string(const std::string& s) { for (auto x : s) write_char(x); } inline void write_string(const char* s) { while (*s) write_char(*s++); } inline void write_string(char* s) { while (*s) write_char(*s++); } template inline std::enable_if_t, void> write_int(T x) { if (output_ptr_right > SZ - LEN) flush(); if (!x) { output_buffer[output_ptr_right++] = '0'; return; } if constexpr (std::is_signed::value == true) if (x < 0) output_buffer[output_ptr_right++] = '-', x = -x; int i = TWELVE; std::array buf{}; while (x >= TENTHOUSAND) { memcpy(std::begin(buf) + i, std::begin(io_pre.num) + (x % TENTHOUSAND) * 4, 4); x /= TENTHOUSAND; i -= 4; } if (x < HUNDRED) { if (x < TEN) { output_buffer[output_ptr_right++] = static_cast('0' + x); } else { std::uint32_t q = (static_cast(x) * MAGIC_MULTIPLY) >> MAGIC_SHIFT; std::uint32_t r = static_cast(x) - q * TEN; output_buffer[output_ptr_right] = static_cast('0' + q); output_buffer[output_ptr_right + 1] = static_cast('0' + r); output_ptr_right += 2; } } else { if (x < THOUSAND) { memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2) + 1, 3), output_ptr_right += 3; } else { memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2), 4), output_ptr_right += 4; } } memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(buf) + i + 4, TWELVE - i); output_ptr_right += TWELVE - i; } inline IO& operator<<(std::ostream& (*pf)(std::ostream&)) { if (pf == static_cast(std::endl)) write_char('\n'); return *this; } template IO& operator<<(T_&& x) { using T = typename std::remove_cv::type>::type; if constexpr (is_custom::value) { write_int(x.get()); } else if constexpr (is_default::value) { if constexpr (is_bool::value) { write_bool(x); } else if constexpr (is_string::value) { write_string(x); } else if constexpr (is_char::value) { write_char(x); } else if constexpr (std::is_integral_v) { write_int(x); } } else if constexpr (is_iterable::value) { using E = decltype(*std::begin(x)); constexpr char sep = needs_newline ? '\n' : ' '; int i = 0; for (const auto& y : x) { if (i++) write_char(sep); operator<<(y); } } else if constexpr (is_applyable::value) { constexpr char sep = (any_needs_newline< T, std::make_index_sequence>>::value) ? '\n' : ' '; int i = 0; std::apply([this, &sep, &i] (auto const &... y) { (((i++ ? write_char(sep) : void()), this->operator<<(y)), ...); }, x); } else { ss.str(""""); ss << x; write_string(ss.str()); } return *this; } template IO& operator>>(T& x) { static_assert(is_custom::value or is_default::value or is_iterable::value or is_applyable::value); static_assert(!is_bool::value); if constexpr (is_custom::value) { typename T::internal_value_type y; read_int(y); x = y; } else if constexpr (is_default::value) { if constexpr (is_string::value) { read_string(x); } else if constexpr (is_char::value) { read_char(x); } else if constexpr (std::is_integral_v) { read_int(x); } } else if constexpr (is_iterable::value) { for (auto& y : x) operator>>(y); } else if constexpr (is_applyable::value) { std::apply([this] (auto &... y) { ((this->operator>>(y)), ...); }, x); } return *this; } IO* tie(std::nullptr_t) { return this; } void sync_with_stdio(bool) {} -}; IO io; -#define cin io -#define cout io -#endif -#define int long long -#define GET_MACRO(_1, _2, _3, NAME, ...) NAME -#define FOR(...) GET_MACRO(__VA_ARGS__, _FOR3, _FOR2)(__VA_ARGS__) -#define _FOR2(i, n) for (int i = 0; i < (n); i++) -#define _FOR3(i, a, n) for (int i = (a); i < (n); i++) -#define ALL(arr) arr.begin(), arr.end() -#define SZ(arr) (int)arr.size() -using namespace std; template struct Arr : public array { Arr() = default; Arr(const T& v) : array{} { this->fill(v); } Arr(initializer_list i) : array{} { copy(i.begin(), i.end(), this->begin()); } template > Arr(A&&... a) : array{static_cast(a)...} {} Arr& operator=(const T& v) { this->fill(v); return *this; } Arr& operator+=(const Arr& o) { FOR(i, N)(*this)[i] += o[i]; return *this; } Arr& operator-=(const Arr& o) { FOR(i, N)(*this)[i] -= o[i]; return *this; } Arr operator+(const Arr& o) const { Arr r = *this; r += o; return r; } Arr operator-(const Arr& o) const { Arr r = *this; r -= o; return r; } friend istream& operator>>(istream& in, Arr& a) { FOR(i, N) in >> a[i]; return in; } friend ostream& operator<<(ostream& out, const Arr& a) { FOR(i, N) out << a[i] << "" \n""[i == N - 1]; return out; } }; namespace std { template struct tuple_size> : integral_constant {}; template struct tuple_element> { using type = T; }; template T get(const Arr& a) { return a[I]; } }; template struct MVec : vector> { MVec() : MVec(0) {} template MVec(U n = U(), Args... args) : vector>(n, MVec(args...)) {} friend ostream& operator<<(ostream& s, const MVec& v) { for (auto& e : v) s << e; return s; } void Fill(const T& x) { for (auto& v : *this) v.Fill(x); } MVec& operator+=(const MVec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } MVec& operator-=(const MVec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } MVec operator+(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] + o[i]; return r; } MVec operator-(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] - o[i]; return r; } friend istream& operator>>(istream& is, MVec& v) { for (auto& e : v) is >> e; return is; } }; template using Vec = MVec<1, T>; template ostream& operator<<(ostream& os, const MVec<1, T>& vec) noexcept { FOR(i, SZ(vec)) os << vec[i] << (i + 1 == SZ(vec) ? ""\n"" : "" ""); return os; } template ostream& operator<<(ostream& os, const MVec<1, Arr>& vec) noexcept { for (auto& arr : vec) os << arr; return os; } template struct MVec<1, T> : vector { MVec() : MVec(0) {} using vector::vector; MVec(initializer_list l) : vector(l) {} void Fill(const T& x) { fill(this->begin(), this->end(), x); } MVec operator+(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] + o[i]; return r; } MVec operator-(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] - o[i]; return r; } MVec& operator+=(const MVec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } MVec& operator-=(const MVec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } friend istream& operator>>(istream& s, MVec& v) { for (auto& e : v) s >> e; return s; } }; template struct Graph { struct OutgoingEdges { const Graph* g; int l, r; OutgoingEdges(const Graph* g, int l, int r) : g(g), l(l), r(r) {} const Edge* begin() const { return l == r ? nullptr : &g->prepared_edges[l]; } const Edge* end() const { return l == r ? nullptr : &g->prepared_edges[r]; } }; vector prepared_edges; vector> edges; vector start; int N; inline int size() { return N - 1; } Graph() {} Graph(int N) : N(N + 1), start(N + 2) {} void AddEdge(int from, const Edge& e) { edges.emplace_back(from, e); } void Prepare() { for (const auto& e : edges) ++start[e.first + 1]; for (int i = 1; i < N; ++i) start[i] += start[i - 1]; prepared_edges.resize(edges.size() + 1); auto counter = start; for (const auto& e : edges) prepared_edges[counter[e.first]++] = e.second; } OutgoingEdges operator[](int from) const { return (from < 0 || from + 1 >= start.size()) ? OutgoingEdges(this, 0, 0) : OutgoingEdges(this, start[from], start[from + 1]); } }; inline Graph ReadGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph adj(N); FOR(i, M) { int a, b; cin >> a >> b; if (one_indexed) { a--; b--; } adj.AddEdge(a, b); if (undirected) { adj.AddEdge(b, a); } } adj.Prepare(); return adj; } inline Graph> ReadWeightedGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph> adj(N); FOR(i, M) { int a, b, d; cin >> a >> b >> d; if (one_indexed) { a--; b--; } adj.AddEdge(a, { b, d }); if (undirected) { adj.AddEdge(b, { a, d }); } } adj.Prepare(); return adj; } template bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } -const string YN[2] = { ""NO\n"", ""YES\n"" }; -const int oo = 4000000002701507200LL; - -struct Solution { - const static bool kReadTestCases = 1; - - inline void Solve(int test_case = 0) { - int N;cin >> N; - Vec> adj(N); - FOR(i, N - 1) { - int a, b;cin >> a >> b;a--;b--; - adj[a].insert(b); - adj[b].insert(a); - } - int comps = 1; - FOR(iter, 2) { - int best = -1; - int best_node = -1; - FOR(i, N) { - if (SZ(adj[i]) > best) { - best = SZ(adj[i]); - best_node = i; - } - } - comps--; - comps += best; - for (int x : adj[best_node]) { - adj[x].erase(best_node); - } - adj[best_node].clear(); - } - cout << comps << endl; - } - Solution() { - - } - inline void Run() { - cout << fixed << setprecision(20); - int num_test_cases = 1; - if (kReadTestCases) cin >> num_test_cases; - FOR(test_case, 1, num_test_cases + 1) Solve(test_case); - } -}; -#ifndef LOCAL_STRESS_TEST -Solution solution;int32_t main() { solution.Run(); } -#else -#include ""./_run_folder/_StressTester.h"" -int32_t main() { StressTester stress_tester;stress_tester.Run(__FILE__); } -#endif","#include -//#pragma GCC optimize(""O3,unroll-loops"") -//#pragma GCC target(""avx2,bmi,bmi2,lzcnt,popcnt"") -#ifndef LOCAL_STRESS_TEST -struct IOPre { static constexpr int TEN = 10, SZ = TEN * TEN * TEN * TEN; std::array num; constexpr IOPre() : num{} { for (int i = 0; i < SZ; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i * 4 + j] = static_cast(n % TEN + '0'); n /= TEN; } } } }; struct IO { -#if !HAVE_DECL_FREAD_UNLOCKED -#define fread_unlocked fread -#endif -#if !HAVE_DECL_FWRITE_UNLOCKED -#define fwrite_unlocked fwrite -#endif - static constexpr int SZ = 1 << 17, LEN = 32, TEN = 10, HUNDRED = TEN * TEN, THOUSAND = HUNDRED * TEN, TENTHOUSAND = THOUSAND * TEN, MAGIC_MULTIPLY = 205, MAGIC_SHIFT = 11, MASK = 15, TWELVE = 12, SIXTEEN = 16; static constexpr IOPre io_pre = {}; std::array input_buffer, output_buffer; int input_ptr_left, input_ptr_right, output_ptr_right; std::stringstream ss; IO() : input_buffer{}, output_buffer{}, input_ptr_left{}, input_ptr_right{}, output_ptr_right{} {} IO(const IO&) = delete; IO(IO&&) = delete; IO& operator=(const IO&) = delete; IO& operator=(IO&&) = delete; ~IO() { flush(); } template struct is_char { static constexpr bool value = std::is_same_v; }; template struct is_bool { static constexpr bool value = std::is_same_v; }; template struct is_string { static constexpr bool value = std::is_same_v || std::is_same_v || std::is_same_v; }; template struct is_custom { static constexpr bool value = false; }; template struct is_custom> { static constexpr bool value = true; }; template struct is_default { static constexpr bool value = is_char::value || is_bool::value || is_string::value || std::is_integral_v; }; template struct is_iterable { static constexpr bool value = false; }; template struct is_iterable< T, typename std::void_t()))>> { static constexpr bool value = true; }; template struct is_applyable { static constexpr bool value = false; }; template struct is_applyable::type>, std::void_t(std::declval()))>> { static constexpr bool value = true; }; template static constexpr bool needs_newline = (is_iterable::value || is_applyable::value) && (!is_default::value); template struct any_needs_newline { static constexpr bool value = false; }; template struct any_needs_newline> { static constexpr bool value = false; }; template struct any_needs_newline> { static constexpr bool value = needs_newline(std::declval()))> || any_needs_newline>::value; }; inline void load() { memmove(std::begin(input_buffer), std::begin(input_buffer) + input_ptr_left, input_ptr_right - input_ptr_left); input_ptr_right = input_ptr_right - input_ptr_left + static_cast(fread_unlocked(std::begin(input_buffer) + input_ptr_right - input_ptr_left, 1, SZ - input_ptr_right + input_ptr_left, stdin)); input_ptr_left = 0; } inline void read_char(char& c) { if (input_ptr_left + LEN > input_ptr_right) load(); c = input_buffer[input_ptr_left++]; } inline void read_string(std::string& x) { char c; while (read_char(c), c < '!') continue; x = c; while (read_char(c), c >= '!') x += c; } template inline std::enable_if_t, void> read_int(T& x) { if (input_ptr_left + LEN > input_ptr_right) load(); char c = 0; do c = input_buffer[input_ptr_left++]; while (c < '-'); [[maybe_unused]] bool minus = false; if constexpr (std::is_signed::value == true) if (c == '-') minus = true, c = input_buffer[input_ptr_left++]; x = 0; while (c >= '0') x = x * TEN + (c & MASK), c = input_buffer[input_ptr_left++]; if constexpr (std::is_signed::value == true) if (minus) x = -x; } inline void skip_space() { if (input_ptr_left + LEN > input_ptr_right) load(); while (input_buffer[input_ptr_left] <= ' ') input_ptr_left++; } inline void flush() { fwrite_unlocked(std::begin(output_buffer), 1, output_ptr_right, stdout); output_ptr_right = 0; } inline void write_char(char c) { if (output_ptr_right > SZ - LEN) flush(); output_buffer[output_ptr_right++] = c; } inline void write_bool(bool b) { if (output_ptr_right > SZ - LEN) flush(); output_buffer[output_ptr_right++] = b ? '1' : '0'; } inline void write_string(const std::string& s) { for (auto x : s) write_char(x); } inline void write_string(const char* s) { while (*s) write_char(*s++); } inline void write_string(char* s) { while (*s) write_char(*s++); } template inline std::enable_if_t, void> write_int(T x) { if (output_ptr_right > SZ - LEN) flush(); if (!x) { output_buffer[output_ptr_right++] = '0'; return; } if constexpr (std::is_signed::value == true) if (x < 0) output_buffer[output_ptr_right++] = '-', x = -x; int i = TWELVE; std::array buf{}; while (x >= TENTHOUSAND) { memcpy(std::begin(buf) + i, std::begin(io_pre.num) + (x % TENTHOUSAND) * 4, 4); x /= TENTHOUSAND; i -= 4; } if (x < HUNDRED) { if (x < TEN) { output_buffer[output_ptr_right++] = static_cast('0' + x); } else { std::uint32_t q = (static_cast(x) * MAGIC_MULTIPLY) >> MAGIC_SHIFT; std::uint32_t r = static_cast(x) - q * TEN; output_buffer[output_ptr_right] = static_cast('0' + q); output_buffer[output_ptr_right + 1] = static_cast('0' + r); output_ptr_right += 2; } } else { if (x < THOUSAND) { memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2) + 1, 3), output_ptr_right += 3; } else { memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(io_pre.num) + (x << 2), 4), output_ptr_right += 4; } } memcpy(std::begin(output_buffer) + output_ptr_right, std::begin(buf) + i + 4, TWELVE - i); output_ptr_right += TWELVE - i; } inline IO& operator<<(std::ostream& (*pf)(std::ostream&)) { if (pf == static_cast(std::endl)) write_char('\n'); return *this; } template IO& operator<<(T_&& x) { using T = typename std::remove_cv::type>::type; if constexpr (is_custom::value) { write_int(x.get()); } else if constexpr (is_default::value) { if constexpr (is_bool::value) { write_bool(x); } else if constexpr (is_string::value) { write_string(x); } else if constexpr (is_char::value) { write_char(x); } else if constexpr (std::is_integral_v) { write_int(x); } } else if constexpr (is_iterable::value) { using E = decltype(*std::begin(x)); constexpr char sep = needs_newline ? '\n' : ' '; int i = 0; for (const auto& y : x) { if (i++) write_char(sep); operator<<(y); } } else if constexpr (is_applyable::value) { constexpr char sep = (any_needs_newline< T, std::make_index_sequence>>::value) ? '\n' : ' '; int i = 0; std::apply([this, &sep, &i] (auto const &... y) { (((i++ ? write_char(sep) : void()), this->operator<<(y)), ...); }, x); } else { ss.str(""""); ss << x; write_string(ss.str()); } return *this; } template IO& operator>>(T& x) { static_assert(is_custom::value or is_default::value or is_iterable::value or is_applyable::value); static_assert(!is_bool::value); if constexpr (is_custom::value) { typename T::internal_value_type y; read_int(y); x = y; } else if constexpr (is_default::value) { if constexpr (is_string::value) { read_string(x); } else if constexpr (is_char::value) { read_char(x); } else if constexpr (std::is_integral_v) { read_int(x); } } else if constexpr (is_iterable::value) { for (auto& y : x) operator>>(y); } else if constexpr (is_applyable::value) { std::apply([this] (auto &... y) { ((this->operator>>(y)), ...); }, x); } return *this; } IO* tie(std::nullptr_t) { return this; } void sync_with_stdio(bool) {} -}; IO io; -#define cin io -#define cout io -#endif -#define int long long -#define GET_MACRO(_1, _2, _3, NAME, ...) NAME -#define FOR(...) GET_MACRO(__VA_ARGS__, _FOR3, _FOR2)(__VA_ARGS__) -#define _FOR2(i, n) for (int i = 0; i < (n); i++) -#define _FOR3(i, a, n) for (int i = (a); i < (n); i++) -#define ALL(arr) arr.begin(), arr.end() -#define SZ(arr) (int)arr.size() -using namespace std; template struct Arr : public array { Arr() = default; Arr(const T& v) : array{} { this->fill(v); } Arr(initializer_list i) : array{} { copy(i.begin(), i.end(), this->begin()); } template > Arr(A&&... a) : array{static_cast(a)...} {} Arr& operator=(const T& v) { this->fill(v); return *this; } Arr& operator+=(const Arr& o) { FOR(i, N)(*this)[i] += o[i]; return *this; } Arr& operator-=(const Arr& o) { FOR(i, N)(*this)[i] -= o[i]; return *this; } Arr operator+(const Arr& o) const { Arr r = *this; r += o; return r; } Arr operator-(const Arr& o) const { Arr r = *this; r -= o; return r; } friend istream& operator>>(istream& in, Arr& a) { FOR(i, N) in >> a[i]; return in; } friend ostream& operator<<(ostream& out, const Arr& a) { FOR(i, N) out << a[i] << "" \n""[i == N - 1]; return out; } }; namespace std { template struct tuple_size> : integral_constant {}; template struct tuple_element> { using type = T; }; template T get(const Arr& a) { return a[I]; } }; template struct MVec : vector> { MVec() : MVec(0) {} template MVec(U n = U(), Args... args) : vector>(n, MVec(args...)) {} friend ostream& operator<<(ostream& s, const MVec& v) { for (auto& e : v) s << e; return s; } void Fill(const T& x) { for (auto& v : *this) v.Fill(x); } MVec& operator+=(const MVec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } MVec& operator-=(const MVec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } MVec operator+(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] + o[i]; return r; } MVec operator-(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] - o[i]; return r; } friend istream& operator>>(istream& is, MVec& v) { for (auto& e : v) is >> e; return is; } }; template using Vec = MVec<1, T>; template ostream& operator<<(ostream& os, const MVec<1, T>& vec) noexcept { FOR(i, SZ(vec)) os << vec[i] << (i + 1 == SZ(vec) ? ""\n"" : "" ""); return os; } template ostream& operator<<(ostream& os, const MVec<1, Arr>& vec) noexcept { for (auto& arr : vec) os << arr; return os; } template struct MVec<1, T> : vector { MVec() : MVec(0) {} using vector::vector; MVec(initializer_list l) : vector(l) {} void Fill(const T& x) { fill(this->begin(), this->end(), x); } MVec operator+(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] + o[i]; return r; } MVec operator-(const MVec& o) const { MVec r(this->size()); FOR(i, this->size()) r[i] = (*this)[i] - o[i]; return r; } MVec& operator+=(const MVec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } MVec& operator-=(const MVec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } friend istream& operator>>(istream& s, MVec& v) { for (auto& e : v) s >> e; return s; } }; template struct Graph { struct OutgoingEdges { const Graph* g; int l, r; OutgoingEdges(const Graph* g, int l, int r) : g(g), l(l), r(r) {} const Edge* begin() const { return l == r ? nullptr : &g->prepared_edges[l]; } const Edge* end() const { return l == r ? nullptr : &g->prepared_edges[r]; } }; vector prepared_edges; vector> edges; vector start; int N; inline int size() { return N - 1; } Graph() {} Graph(int N) : N(N + 1), start(N + 2) {} void AddEdge(int from, const Edge& e) { edges.emplace_back(from, e); } void Prepare() { for (const auto& e : edges) ++start[e.first + 1]; for (int i = 1; i < N; ++i) start[i] += start[i - 1]; prepared_edges.resize(edges.size() + 1); auto counter = start; for (const auto& e : edges) prepared_edges[counter[e.first]++] = e.second; } OutgoingEdges operator[](int from) const { return (from < 0 || from + 1 >= start.size()) ? OutgoingEdges(this, 0, 0) : OutgoingEdges(this, start[from], start[from + 1]); } }; inline Graph ReadGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph adj(N); FOR(i, M) { int a, b; cin >> a >> b; if (one_indexed) { a--; b--; } adj.AddEdge(a, b); if (undirected) { adj.AddEdge(b, a); } } adj.Prepare(); return adj; } inline Graph> ReadWeightedGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph> adj(N); FOR(i, M) { int a, b, d; cin >> a >> b >> d; if (one_indexed) { a--; b--; } adj.AddEdge(a, { b, d }); if (undirected) { adj.AddEdge(b, { a, d }); } } adj.Prepare(); return adj; } template bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } -const string YN[2] = { ""NO\n"", ""YES\n"" }; -const int oo = 4000000002701507200LL; - -struct Solution { - const static bool kReadTestCases = 1; - - inline void Solve(int test_case = 0) { - int N;cin >> N; - Vec> adj(N); - FOR(i, N - 1) { - int a, b;cin >> a >> b;a--;b--; - adj[a].insert(b); - adj[b].insert(a); - } - multiset sizes; - int best = -oo; - FOR(i, N) { - sizes.insert(SZ(adj[i])); - } - FOR(i, N) { - int ans = -1; - ans += SZ(adj[i]); - sizes.erase(sizes.find(SZ(adj[i]))); - for (int j : adj[i]) { - sizes.erase(sizes.find(SZ(adj[j]))); - sizes.insert(SZ(adj[j]) - 1); - } - ans += *sizes.rbegin(); - sizes.insert(SZ(adj[i])); - for (int j : adj[i]) { - sizes.insert(SZ(adj[j])); - sizes.erase(sizes.find(SZ(adj[j]) - 1)); - } - ckmax(best, ans); - } - cout << best << endl; - - } - Solution() { - - } - inline void Run() { - cout << fixed << setprecision(20); - int num_test_cases = 1; - if (kReadTestCases) cin >> num_test_cases; - FOR(test_case, 1, num_test_cases + 1) Solve(test_case); - } -}; -#ifndef LOCAL_STRESS_TEST -Solution solution;int32_t main() { solution.Run(); } -#else -#include ""./_run_folder/_StressTester.h"" -int32_t main() { StressTester stress_tester;stress_tester.Run(__FILE__); } -#endif",2 -_rohith_,2063C - Remove Exactly Two,c++17 ,305066170,305066130,"#include -#define ll long long -#define ld long double -#define fi first -#define se second -#define pb push_back -#define ppb pop_back -#define pf push_front -#define ppf pop_front -#define nline ""\n"" -#define all(x) (x).begin(),(x).end() -#define uniq(v) (v).erase(unique(all(v)),(v).end()) -#define srt(x) sort(all(x)) -#define mem(a,val) memset(a, val, sizeof(a)) -#define Up(v,n) upper_bound(v.begin(),v.end(),n) -#define Low(v,n) lower_bound(v.begin(),v.end(),n) -#define PRE(x) fixed << setprecision(x) -#define watch(x) cout << (#x) << "" is "" << (x) << endl -using namespace std; - -long long powM(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; -} - -// GCD(A,B) = GCD(B,A-B) -> here A>=B or GCD(A,B) = GCD(B-A,A) -> here A<=B -ll gcd(ll a, ll b) { if (b == 0) {return a;} return gcd(b, a % b);} -ll modinv(ll a, ll m) { return powM(a, m - 2, m);} -ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -ll moddiv(ll a, ll b, ll m) {a = a % m; b = b % m; -return (mod_mul(a, modinv(b, m), m) + m) % m;}//m is prime - -const long long INF=1e18; -const int32_t M=1e9+7; -const int32_t MM=998244353; - -void solve(){ - int n; cin >> n; - vectora[n+1]; - priority_queue>pq; - int ans = 0, maxi = 0, maxi_cnt = 0, tot = 0; - - for(int i=0;i> u >> v; - a[u].push_back(v); a[v].push_back(u); - } - for(int i=0;i<=n;i++) maxi = max(maxi, (int)a[i].size()); - for(int i=0;i<=n;i++) { - if(a[i].size() == maxi) maxi_cnt++; - pq.push({a[i].size(), i}); - } - if(maxi_cnt > 2) { - cout << pq.top().first*2-1 << '\n'; - return; - } - vectorvis(n+1,0); - // removed one element - ans = (pq.top().fi) - 1; - for(auto e:a[pq.top().second]) vis[e]++; - pq.pop(); - while(!pq.empty()) { - int cnt = ans; - pairp = pq.top(); pq.pop(); - cnt = (cnt + (p.first) - vis[p.second]); - tot = max(tot, cnt); - } - cout << tot << '\n'; -} - -signed main(){ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); - cout.precision(20), cout.setf(ios::fixed); - int t=1; - cin>>t; - while(t--){ - solve(); - } - cerr << setprecision(4) << fixed; - cerr<<""Time taken : ""<<(float)clock()/CLOCKS_PER_SEC<<"" secs""< -#define ll long long -#define ld long double -#define fi first -#define se second -#define pb push_back -#define ppb pop_back -#define pf push_front -#define ppf pop_front -#define nline ""\n"" -#define all(x) (x).begin(),(x).end() -#define uniq(v) (v).erase(unique(all(v)),(v).end()) -#define srt(x) sort(all(x)) -#define mem(a,val) memset(a, val, sizeof(a)) -#define Up(v,n) upper_bound(v.begin(),v.end(),n) -#define Low(v,n) lower_bound(v.begin(),v.end(),n) -#define PRE(x) fixed << setprecision(x) -#define watch(x) cout << (#x) << "" is "" << (x) << endl -using namespace std; - -long long powM(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; -} - -// GCD(A,B) = GCD(B,A-B) -> here A>=B or GCD(A,B) = GCD(B-A,A) -> here A<=B -ll gcd(ll a, ll b) { if (b == 0) {return a;} return gcd(b, a % b);} -ll modinv(ll a, ll m) { return powM(a, m - 2, m);} -ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} -ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} -ll moddiv(ll a, ll b, ll m) {a = a % m; b = b % m; -return (mod_mul(a, modinv(b, m), m) + m) % m;}//m is prime - -const long long INF=1e18; -const int32_t M=1e9+7; -const int32_t MM=998244353; - -void solve(){ - int n; cin >> n; - vectora[n+1]; - priority_queue>pq; - int ans = 0, maxi = 0, maxi_cnt = 0, tot = 0; - - for(int i=0;i> u >> v; - a[u].push_back(v); a[v].push_back(u); - } - for(int i=0;i<=n;i++) maxi = max(maxi, (int)a[i].size()); - for(int i=0;i<=n;i++) { - if(a[i].size() == maxi) maxi_cnt++; - pq.push({a[i].size(), i}); - } - if(maxi_cnt > 2) { - cout << pq.top().first*2-1 << '\n'; - return; - } - vectorvis(n+1,0); - // removed one element - ans = (pq.top().fi) - 1; - for(auto e:a[pq.top().second]) vis[e]++; - pq.pop(); - while(!pq.empty()) { - int cnt = ans; - pairp = pq.top(); pq.pop(); - cnt = (cnt + (p.first) - vis[p.second]); - tot = max(tot, cnt); - } - cout << tot << '\n'; -} - -signed main(){ - ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); - cout.precision(20), cout.setf(ios::fixed); - int t=1; - cin>>t; - while(t--){ - solve(); - } - cerr << setprecision(4) << fixed; - cerr<<""Time taken : ""<<(float)clock()/CLOCKS_PER_SEC<<"" secs""< -#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define pii pair -#define ll long long int -#define SIZE 200005 -#define all(v) v.begin(), v.end() -#define pb push_back -#define MOD 1000000007 -#define INF 1000000007 -using namespace std; - -int n , ma[SIZE] , val[SIZE] , ans; -vector g[SIZE] , child[SIZE]; - -void init() { - ans=0; - for (int i = 1; i <= n; i++) { - g[i].clear(); - child[i].clear(); - ma[i] = 0; - } -} - -void dfs(int here ,int pa) { - val[here] = 1; - for (auto t : g[here]) { - if (t == pa) continue; - val[here]++; - child[here].pb(t); - dfs(t , here); - } -} - -void solve(int here) { - for (auto t : child[here]) solve(t); - vector tmp; - for (auto t : child[here]) tmp.pb(ma[t]); - sort(all(tmp)); - reverse(all(tmp)); - if (tmp.size() >= 2) ans = max(ans , tmp[0]+tmp[1]-1); - for (auto t : child[here]) { - ans = max(ans , ma[t]+val[here]-1-((here==1))-(child[t].size()==0)); - } - ma[here] = max(val[here] , (tmp.size() > 0 ? tmp[0] : -1)); -} - -void solve() { - cin >> n; - for (int i = 1; i <= n-1; i++) { - int u , v; cin >> u >> v; - g[u].pb(v); g[v].pb(u); - } - - if (n == 2) { - cout << ""0\n""; - return; - } - - dfs(1 , -1); - val[1]--; - //for (int i = 1; i <= n; i++) printf(""%d "" , val[i]); - //printf(""\n""); - solve(1); - - cout << ans << ""\n""; -} - -int main() { - FastIO; - - int t; cin >> t; - while(t--) { - init(); - solve(); - } - - return 0; -}","#include -#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); -#define pii pair -#define ll long long int -#define SIZE 200005 -#define all(v) v.begin(), v.end() -#define pb push_back -#define MOD 1000000007 -#define INF 1000000007 -using namespace std; - -int n , ma1[SIZE] , deg[SIZE] , ans , ma2[SIZE]; -vector g[SIZE] , child[SIZE]; - -void init() { - ans=0; - for (int i = 1; i <= n; i++) { - g[i].clear(); - child[i].clear(); - ma1[i] = ma2[i] = deg[i] = 0; - } -} - -void dfs(int here ,int pa) { - multiset st1 , st2; - for (auto t : g[here]) { - if (t == pa) continue; - ans = max(ans , deg[here]+deg[t]-2); - dfs(t , here); - ma2[here] = max(ma2[here] , ma1[t]); - st1.insert(-ma1[t]); - st2.insert(ma2[t]); - } - if (st2.size() > 0) ans = max(ans , deg[here]+(*st2.rbegin())-1); - if (st1.size() >= 2) { - int ret=0; - auto it = st1.begin(); - ret += -(*it); - it++; - ret += -(*it); ret--; - ans = max(ans , ret); - } - ma1[here] = max(deg[here] , ma2[here]); -} - -void solve() { - cin >> n; - for (int i = 1; i <= n-1; i++) { - int u , v; cin >> u >> v; - g[u].pb(v); g[v].pb(u); - deg[u]++; deg[v]++; - } - - if (n == 2) { - cout << ""0\n""; - return; - } - - dfs(1 , -1); - - cout << ans << ""\n""; -} - -int main() { - FastIO; - - int t; cin >> t; - while(t--) { - init(); - solve(); - } - - return 0; -}",2 -IanPardo,2063C - Remove Exactly Two,c++17 ,304494773,304479564,"using namespace std; -#include - -#define all(A) A.begin(),A.end() -#define fori(i, k, n) for (int i = k; i < n; i++) -#define ln ""\n"" - - -vector > adj; -vector > deg; -vector visited; -int n, ans; - -void dfs(int u) { - visited[u] = true; - for (const auto &v: adj[u]) - if (!visited[v]) { - ans = max(ans, deg[u].first + deg[v].first - 2); - dfs(v); - } -} - -bool vecinos(int u, int v) { - return adj[u].find(v) != adj[u].end(); -} - - -void solve() { - cin >> n; - adj.assign(n, unordered_set()); - deg.assign(n, {0, 0}); - visited.assign(n, false); - fori(i, 0, n) - deg[i].second = i; - fori(i, 0, n-1) { - int a, b; - cin >> a >> b; - a--; - b--; - adj[a].insert(b); - adj[b].insert(a); - deg[a].first++; - deg[b].first++; - } - ans = 0; - dfs(0); - sort(all(deg), greater >()); - fori(i, 0, n) { - fori(j, i+1, n) { - if (vecinos(deg[i].second, deg[j].second)) - continue; - ans = max(ans, deg[i].first + deg[j].first - 1); - break; - } - } - cout << ans << ln; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) - solve(); - return 0; -} -","using namespace std; -#include - -#define all(A) A.begin(),A.end() -#define fori(i, k, n) for (int i = k; i < n; i++) -#define ln ""\n"" - - -vector > adj; -vector deg; -vector visited; -int n, U, V; - -void removeVertex(int u) { - deg[u] = 0; - for (const auto &v: adj[u]) { - adj[v].erase(remove(all(adj[v]), u), adj[v].end()); - deg[v]--; - } - adj[u].clear(); -} - -void dfs(int u) { - visited[u] = true; - for (const auto &v: adj[u]) - if (!visited[v]) - dfs(v); -} - -void printGraph() { - fori(u, 0, n) { - cout << (u + 1) << ""->""; - for (const auto &v: adj[u]) - cout << (v + 1) << "", ""; - cout << ln; - } -} - - -void solve() { - cin >> n; - adj.assign(n, vector()); - deg.assign(n, 0); - fori(i, 0, n-1) { - int a, b; - cin >> a >> b; - a--; - b--; - adj[a].push_back(b); - adj[b].push_back(a); - deg[a]++; - deg[b]++; - } - set > tree; - fori(u, 0, n) - tree.insert({deg[u], u}); - auto first = prev(tree.end()); - tree.erase(first); - U = first->second; - removeVertex(U); - tree.clear(); - fori(u, 0, n) { - if (u == U) - continue; - tree.insert({deg[u], u}); - } - V = prev(tree.end())->second; - removeVertex(V); - visited.assign(n, false); - // cout << ""U: "" << U + 1 << "" V: "" << V + 1 << ln; - int ans = 0; - fori(u, 0, n) { - if (u != U && u != V && !visited[u]) { - //cout << ""u: "" << u + 1 << ln; - dfs(u); - ans++; - } - } - cout << ans << ln; -} - -int main() { - ios_base::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) - solve(); - return 0; -} -",1 -Encode_Hridoy,2063C - Remove Exactly Two,c++23 ,305003502,305001823,"#include -using namespace std; -#include -#include -using namespace __gnu_pbds; - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL) -#define ll long long -#define all(v) (v).begin(),(v).end() -#define yes cout<<""YES""<> n; - vector deg(n+1); - set> st; - for(int i=0; i> u >> v; - deg[u]++; - deg[v]++; - if(u>v) swap(u,v); - st.insert({u,v}); - } - - vector> vp; - for(int i=1; i<=n; i++){ - vp.pb({deg[i],i}); - } - sort(all(vp), greater>()); - - int ans =-1; - for(int i=0; iv) swap(u,v); - if(!st.count({u,v})){ - ans = max(ans, vp[i].fi+vp[j].fi-1); - break; - } - } - } - for(auto [u,v]: st){ - ans = max(ans, deg[u]+deg[v]-2); - } - - cout << ans << endl; - -} - - -/*------------------ Today's decision might impact you Tomorrow !! ------------------*/ - -int32_t main(){ - fast_IO; - // #ifndef ONLINE_JUDGE - // freopen(""input.txt"", ""r"", stdin); - // // freopen(""output.txt"", ""w"", stdout); - // #endif - - int tc = 1; - cin >> tc; - for(int kase = 1; kase <= tc; kase++){ - // cout << ""Case "" << kase << "": \n""; - Hrid_solve(); - } - - return 0; -}","#include -using namespace std; -#include -#include -using namespace __gnu_pbds; - -#define ordered_set tree, rb_tree_tag,tree_order_statistics_node_update> -#define fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL) -#define ll long long -#define all(v) (v).begin(),(v).end() -#define yes cout<<""YES""<> n; - vector deg(n+1); - set> st; - for(int i=0; i> u >> v; - deg[u]++; - deg[v]++; - st.insert({u,v}); - st.insert({v,u}); - } - - vector> vp; - for(int i=1; i<=n; i++){ - vp.pb({deg[i],i}); - } - sort(all(vp), greater>()); - - ll ans =0; - for(int i=1; i> tc; - for(int kase = 1; kase <= tc; kase++){ - // cout << ""Case "" << kase << "": \n""; - Hrid_solve(); - } - - return 0; -}",1 -arthpatwari,2063C - Remove Exactly Two,c++20 ,305567933,305566126," #pragma GCC optimize(""O2"") -#include -using namespace std; -typedef long long ll; -typedef long double ld; -typedef unsigned long long ull; -const long double pi = 3.141592653589793238462643383279; -//#define max(a,b) (a>b?a:b) -//#define min(a,b) (a-1;i--) -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define vi vector -#define vll vector -#define vvi vector> -#define vvll vector > -#define vb vector -#define vvb vector> -#define vc vector -#define vvc vector> -#define pb push_back -const ll mod= 1e9+7; - -void _print(ll t) {cerr<< t;} -void _print(int 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 printll(vector a){ - ll n=a.size(); - fo(i,n){ - cout< a){ - ll n=a.size(); - fo(i,n) cout<b)swap(a,b); - ll rem=b%a; - while(rem){ - b=a; - a=rem; - rem=b%a; - } - return a; -} - -ll lcm(ll a, ll b){ - return (a*b)/gcd(a,b); -} -ll power(ll a,ll b){ - ll res=1; - while(b){ - if(b&1)res=res*a%mod; - b>>=1; - a=a*a%mod; - } - return res; -} - ll factorial(ll n) - { - ll res = 1, i; - - for (i = 2; i <= n; i++) - res = (res*1ll* i)%mod; - return res; - } - - -void solve() { - ll n; - cin>>n; - vectoradj(n+1); - vll in(n+1,0); - fo(i,n-1){ - ll a,b; - cin>>a>>b; - in[a]++; - in[b]++; - adj[a].push_back(b); - adj[b].push_back(a); - } - if(n==2){ - cout<<0<>st; - forb(i,1,n+1) - { - mx=max(mx,in[i]); - st.insert({in[i],i}); - } - -ll ans=0; - forb(i,1,n+1){ - if(in[i]==mx){ - st.erase({in[i],i}); - ll tmp=0; - tmp+=in[i]-1; - - for(auto x:adj[i]){ - st.erase({in[x],x}); - in[x]--; - st.insert({in[x],x}); - } - tmp+=(*st.rbegin()).first; - ans=max(ans,tmp); - - st.insert({in[i],i}); - for(auto x:adj[i]){ - st.erase({in[x],x}); - in[x]++; - st.insert({in[x],x}); - } - } - } - cout<> t; - while (t--) { - solve(); - } - return 0; -}"," #pragma GCC optimize(""O2"") -#include -using namespace std; -typedef long long ll; -typedef long double ld; -typedef unsigned long long ull; -const long double pi = 3.141592653589793238462643383279; -//#define max(a,b) (a>b?a:b) -//#define min(a,b) (a-1;i--) -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define vi vector -#define vll vector -#define vvi vector> -#define vvll vector > -#define vb vector -#define vvb vector> -#define vc vector -#define vvc vector> -#define pb push_back -const ll mod= 1e9+7; - -void _print(ll t) {cerr<< t;} -void _print(int 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 printll(vector a){ - ll n=a.size(); - fo(i,n){ - cout< a){ - ll n=a.size(); - fo(i,n) cout<b)swap(a,b); - ll rem=b%a; - while(rem){ - b=a; - a=rem; - rem=b%a; - } - return a; -} - -ll lcm(ll a, ll b){ - return (a*b)/gcd(a,b); -} -ll power(ll a,ll b){ - ll res=1; - while(b){ - if(b&1)res=res*a%mod; - b>>=1; - a=a*a%mod; - } - return res; -} - ll factorial(ll n) - { - ll res = 1, i; - - for (i = 2; i <= n; i++) - res = (res*1ll* i)%mod; - return res; - } - - -void solve() { - ll n; - cin>>n; - vectoradj(n); - vll indeg(n,0); - fo(i,n-1){ - ll u,v; - cin>>u>>v; - u--;v--; - adj[u].pb(v); - adj[v].pb(u); - indeg[u]++; - indeg[v]++; - } - ll ans=0; - ll maxi=0,ind=0; - fo(i,n){ - maxi=max(maxi,indeg[i]); - if(maxi==indeg[i]){ - ind=i; - } - } - indeg[ind]=0; - ans+=maxi; - for(auto it:adj[ind]){ - indeg[it]--; - } - sort(indeg.begin(),indeg.end()); - ans+=indeg.back(); - cout<> t; - while (t--) { - solve(); - } - return 0; -}",1 -Ssaranshh13,2063C - Remove Exactly Two,c++17 ,306791034,304298967,"#include -using namespace std; - -#define ll long long -#define ar array - -const int mod = 1e9+7; - -void solve(){ - int n;cin>>n; - vector adj[n]; - vector degree(n,0); - map,int> m; - - for(int i=0;i>x>>y; - x--,y--; - m[{x,y}]++; - degree[x]++,degree[y]++; - } - map,int> m2; - for(auto i: m){ - int x = degree[i.first.first], y = degree[i.first.second]; - if(x>y)swap(x,y); - m2[{x,y}]++; - } - sort(degree.begin(),degree.end()); - int x = degree[n-1], y = degree[n-2]; - if(x == 1)cout<<""0\n""; - else if(x == y){ - ll freq = count(degree.begin(),degree.end(),x); - ll num = m2[{y,x}]; - int ans = 2*x - 1; - ll choice = (1LL*(freq)*(freq-1))/2; - if(num>=choice) { - ans--; - } - cout<=choice) ans--; - cout<>t; - while(t--) - solve(); - return 0; -}","// time-limit: 3000 -#include -using namespace std; - -#define ll long long -#define ar array - -const int mod = 1e9+7; - -void solve(){ - int n;cin>>n; - vector adj[n]; - vector degree(n,0); - map,int> m; - - for(int i=0;i>x>>y; - x--,y--; - m[{x,y}]++; - degree[x]++,degree[y]++; - } - map,int> m2; - for(auto i: m){ - int x = degree[i.first.first], y = degree[i.first.second]; - if(x>y)swap(x,y); - m2[{x,y}]++; - } - int idx = distance(degree.begin(),max_element(degree.begin(), degree.end())); - vector degree2 = degree; - sort(degree.begin(),degree.end()); - int x = degree[n-1], y = degree[n-2]; - if(x == 1)cout<<""0\n""; - else if(x == y){ - int freq = count(degree.begin(),degree.end(),x); - int num = m2[{y,x}]; - int ans = 2*x - 1; - int choice = (1LL*(freq)*(freq-1))/2; - if(num>=choice) { - ans--; - } - cout<>t; - while(t--) - solve(); - return 0; -} -",1 -ckling,2063C - Remove Exactly Two,c++20 ,304206875,304207755,"#include -using namespace std; -#define endl '\n' -#define Yes cout<<""Yes""< pii; -const int dx[4]={1,-1,0,0}; -const int dy[4]={0,0,1,-1}; - -const int N=5e5+100; -vectora[N]; - -void solve(){ - int n; - cin>>n; - vectorin(n+1); - for(int i=1;i<=n;i++)a[i].clear(); - for(int i=1;i>u>>v; - a[u].push_back(v); - a[v].push_back(u); - in[u]++,in[v]++; - } - int id=0; - int mx=0; - vector>pos(n+1); - for(int i=1;i<=n;i++){ - int x=0; - int num=0; - for(auto v:a[i]){ - int y=a[v].size(); - if(y>x){ - x=v; - num=1; - } - else if(y==x){ - num++; - } - } - pos[i]={(int)a[i].size(),x,num,i}; - } - sort(All(pos),[&](arrayx,arrayy){ - if(x[0]!=y[0])return x[0]>y[0]; - if(x[1]!=y[1])return x[1]>t; - while(t--)solve(); - return 0; -}","#include -using namespace std; -#define endl '\n' -#define Yes cout<<""Yes""< pii; -const int dx[4]={1,-1,0,0}; -const int dy[4]={0,0,1,-1}; - -const int N=5e5+100; -vectora[N]; - -void solve(){ - int n; - cin>>n; - vectorin(n+1); - for(int i=1;i<=n;i++)a[i].clear(); - - for(int i=1;i>u>>v; - a[u].push_back(v); - a[v].push_back(u); - } - mapmp; - for(int i=1;i<=n;i++){ - mp[a[i].size()]++; - } - int ans=0; - for(int i=1;i<=n;i++){ - mp[a[i].size()]--; - if(mp[a[i].size()]==0)mp.erase(a[i].size()); - for(auto v:a[i]){ - mp[a[v].size()]--; - mp[a[v].size()-1]++; - if(mp[a[v].size()]==0)mp.erase(a[v].size()); - } - - auto [u,v]=*mp.rbegin(); - int now=a[i].size()+u-1; - ans=max(ans,now); - - mp[a[i].size()]++; - for(auto v:a[i]){ - mp[a[v].size()]++; - mp[a[v].size()-1]--; - if(mp[a[v].size()-1]==0)mp.erase(a[v].size()-1); - } - } - cout<>t; - while(t--)solve(); - return 0; -}",2 -harshscool955952,2063C - Remove Exactly Two,c++17 ,304343266,304348321,"#include -#include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -using namespace std; -#include -#include -using namespace __gnu_pbds; -#define int long long -const int MOD = 1e9 + 7; -const int INF = LONG_MAX >> 1; -typedef pair pchar; -typedef pair pint; -typedef vector v; -typedef vector vpint; -typedef vector vs; -typedef unordered_map ump; -typedef map mp; -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define fl(i,n) for(int i=0;i=m;i--) -#define py cout << ""YES\n""; -#define pn cout << ""NO\n""; -#define pimp cout << ""IMPOSSIBLE\n""; -#define vr(v) v.begin(), v.end() -#define rv(v) v.end(), v.begin() -#define debug(x) cerr << #x << "" ""; cerr << x << "" ""; cerr << endl; -int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } -int lcm(int a, int b) { return (a / gcd(a, b) * b); } -int moduloMultiplication(int a, int b, int mod) { int res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; b >>= 1; a = (a * 2) % mod; } return res; } -int powermod(int x, 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; x = (x * x) % p; } return res; } - -// Utility functions -void pv(const vector& v) { for(auto x: v) cout << x << "" ""; cout << ""\n""; } -void pap(const pair ap[],int n) { for(int i=0; i"" << ap[i].second << ""\n""; } -void pm(const map& m) { for(auto x: m) cout << x.first << ""->"" << x.second << ""\n""; } -void pa(const int a[], int n) { for (int i = 0; i < n; ++i) cout << a[i] << "" ""; cout << ""\n""; } -bool sorta(const pair& a, const pair& b) { return (a.second < b.second); } -bool sortd(const pair& a, const pair& b) { return (a.second > b.second); } - -// Bits -string decToBinary(int n) { string s=""""; while (n > 0) { s = to_string(n % 2) + s; n = n / 2; } return s; } -int binaryToDecimal(const string& n) { int dec_value = 0; int base = 1; int len = n.length(); for(int i = len - 1; i >= 0; i--) { if (n[i] == '1') dec_value += base; base = base * 2; } return dec_value; } - -// Check functions -bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (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; } -bool isPowerOfTwo(int n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } -bool isPerfectSquare(int x) { if (x >= 0) { int sr = sqrt(x); return (sr * sr == x); } return false; } -void nl() { cout << ""\n""; } -void yn(int x) { if (x == 1) cout << ""YES"" << ""\n""; else cout << ""NO"" << ""\n""; } -void yes() { cout << ""YES"" << ""\n""; } -void no() { cout << ""NO"" << ""\n""; } -void print(int x) { cout << x << ""\n""; } -bool sortbysec(const pair& a, const pair& b) { return (a.second < b.second); } - - -class dsu{ - - vector parent,size; - public: - - void make_set(int n){ - for (int i = 0; i <=n; ++i) - { - parent.push_back(i); - size.push_back(1); - } - } - - int findPar(int node){ - if(parent[node]==node) return node; - return parent[node]=findPar(parent[node]);//path compression - } - - - void union_sets(int a,int b){ - a=findPar(a); - b=findPar(b); - if(a!=b) parent[b]=a; - } - - void unionSize(int u,int v){ - int pu=findPar(u); - int pv=findPar(v); - if(pu==pv) return; - - if(size[pu] a) - val--; - return val; -} - -bool isSubSeqRec(const string& s1, const string& s2, int m, int n) -{ - // Base Cases - if (m == 0) - return true; - if (n == 0) - return false; - - // If last characters of two strings are matching - if (s1[m - 1] == s2[n - 1]) - return isSubSeqRec(s1, s2, m - 1, n - 1); - - // If last characters are not matching - return isSubSeqRec(s1, s2, m, n - 1); -} - -// bool check(int n,int k,int sum,int a[]){ - -// } - -void dfs(int u,map> mp,set &vis){ - vis.insert(u); - for(auto x: mp[u]){ - if(vis.find(x)==vis.end()){ - dfs(x,mp,vis); - } - } -} -signed main() - { -ios::sync_with_stdio(false); -cin.tie(NULL); - - - int tc; - cin>>tc; - while(tc--){ - int n; - cin>>n; - map> mp; - for (int i = 1; i < n; ++i) - { - int a,b; - cin>>a>>b; - mp[a].insert(b); - mp[b].insert(a); - } - - int mxs=-1,u=0; - for(auto x: mp){ - int sz=x.second.size(); - if(sz>mxs){ - u=x.first; - mxs=x.second.size(); - } - } - set st=mp[u]; - // cout<""; - for(auto x: st){ - mp[x].erase(u); - } - mp.erase(u); - mxs=INT_MIN,u=0; - - for(auto x: mp){ - int sz=x.second.size(); - if(sz>mxs){ - u=x.first; - mxs=x.second.size(); - } - } - st=mp[u]; - - for(auto x: st){ - mp[x].erase(u); - } - set vis; - mp.erase(u); - int cnt=0; - - for (auto x: mp) - { - - int u=x.first; - // cout< -#include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -using namespace std; -#include -#include -using namespace __gnu_pbds; -#define int long long -const int MOD = 1e9 + 7; -const int INF = LONG_MAX >> 1; -typedef pair pchar; -typedef pair pint; -typedef vector v; -typedef vector vpint; -typedef vector vs; -typedef unordered_map ump; -typedef map mp; -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; -#define ff first -#define ss second -#define pb push_back -#define mp make_pair -#define fl(i,n) for(int i=0;i=m;i--) -#define py cout << ""YES\n""; -#define pn cout << ""NO\n""; -#define pimp cout << ""IMPOSSIBLE\n""; -#define vr(v) v.begin(), v.end() -#define rv(v) v.end(), v.begin() -#define debug(x) cerr << #x << "" ""; cerr << x << "" ""; cerr << endl; -int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } -int lcm(int a, int b) { return (a / gcd(a, b) * b); } -int moduloMultiplication(int a, int b, int mod) { int res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; b >>= 1; a = (a * 2) % mod; } return res; } -int powermod(int x, 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; x = (x * x) % p; } return res; } - -// Utility functions -void pv(const vector& v) { for(auto x: v) cout << x << "" ""; cout << ""\n""; } -void pap(const pair ap[],int n) { for(int i=0; i"" << ap[i].second << ""\n""; } -void pm(const map& m) { for(auto x: m) cout << x.first << ""->"" << x.second << ""\n""; } -void pa(const int a[], int n) { for (int i = 0; i < n; ++i) cout << a[i] << "" ""; cout << ""\n""; } -bool sorta(const pair& a, const pair& b) { return (a.second < b.second); } -bool sortd(const pair& a, const pair& b) { return (a.second > b.second); } - -// Bits -string decToBinary(int n) { string s=""""; while (n > 0) { s = to_string(n % 2) + s; n = n / 2; } return s; } -int binaryToDecimal(const string& n) { int dec_value = 0; int base = 1; int len = n.length(); for(int i = len - 1; i >= 0; i--) { if (n[i] == '1') dec_value += base; base = base * 2; } return dec_value; } - -// Check functions -bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (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; } -bool isPowerOfTwo(int n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } -bool isPerfectSquare(int x) { if (x >= 0) { int sr = sqrt(x); return (sr * sr == x); } return false; } -void nl() { cout << ""\n""; } -void yn(int x) { if (x == 1) cout << ""YES"" << ""\n""; else cout << ""NO"" << ""\n""; } -void yes() { cout << ""YES"" << ""\n""; } -void no() { cout << ""NO"" << ""\n""; } -void print(int x) { cout << x << ""\n""; } -bool sortbysec(const pair& a, const pair& b) { return (a.second < b.second); } - - -class dsu{ - - vector parent,size; - public: - - void make_set(int n){ - for (int i = 0; i <=n; ++i) - { - parent.push_back(i); - size.push_back(1); - } - } - - int findPar(int node){ - if(parent[node]==node) return node; - return parent[node]=findPar(parent[node]);//path compression - } - - - void union_sets(int a,int b){ - a=findPar(a); - b=findPar(b); - if(a!=b) parent[b]=a; - } - - void unionSize(int u,int v){ - int pu=findPar(u); - int pv=findPar(v); - if(pu==pv) return; - - if(size[pu] a) - val--; - return val; -} - -bool isSubSeqRec(const string& s1, const string& s2, int m, int n) -{ - // Base Cases - if (m == 0) - return true; - if (n == 0) - return false; - - // If last characters of two strings are matching - if (s1[m - 1] == s2[n - 1]) - return isSubSeqRec(s1, s2, m - 1, n - 1); - - // If last characters are not matching - return isSubSeqRec(s1, s2, m, n - 1); -} - -// bool check(int n,int k,int sum,int a[]){ - -// } - -void dfs(int u,map> mp,set &vis){ - vis.insert(u); - for(auto x: mp[u]){ - if(vis.find(x)==vis.end()){ - dfs(x,mp,vis); - } - } -} -signed main() - { -ios::sync_with_stdio(false); -cin.tie(NULL); - - - int tc; - cin>>tc; - while(tc--){ - int n; - cin>>n; - int cnt[n+1]{}; - map> mp; - set> st; - for (int i = 1; i < n; ++i) - { - int a,b; - cin>>a>>b; - st.insert({a,b}); - st.insert({b,a}); - mp[a].insert(b); - mp[b].insert(a); - cnt[a]++,cnt[b]++; - } - - - vector> v; - for (int i = 1; i <=n; ++i) - { - v.push_back({cnt[i],i}); - } - - sort(rbegin(v),rend(v)); - - int ans=-1; - for (int i = 0; i < v.size(); ++i) - { - for(int j=i+1; j -using ll = long long; -using ld = long double; -using namespace std; -const int maxN = 1e6 + 5; -const int Mod = 1e9 + 7; -const int LG = 21; -int n,mx,mx1,d[maxN]; -bool avail[maxN]; -vector adj[maxN]; -void input() -{ - cin >> n; - for (int i = 0;i <= n;++i) - { - adj[i].clear(); - d[i] = 0; - avail[i] = true; - } - mx = 0;mx1 = 0; - for (int i = 1;i < n;++i) - { - int u,v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - if (adj[mx].size() < adj[u].size()) mx = u; - if (adj[mx].size() < adj[v].size()) mx = v; - } - avail[mx] = false; -} -void dfs(int u) -{ - avail[u] = false; - for (int v : adj[u]) - { - if (!avail[v] || v == mx || v == mx1) continue; - d[u]++; - dfs(v); - } -} -void solve() -{ - mx1 = 0; - if (n <= 2) {cout << 0 << ""\n"";return;} - for (int i = 1;i <= n;++i) if (avail[i]) dfs(i); - if (mx == 1) mx1 = n; - else mx1 = 1; - for (int i = 1;i <= n;++i) if (d[mx1] < d[i]) mx1 = i; - fill(avail + 1,avail + n + 1,true); - int res = 0; - //cerr << mx << "" "" << mx1 << ""aa\n""; - avail[mx] = false; - avail[mx1] = false; - for (int i = 1;i <= n;++i) - { - if (avail[i]) - { - dfs(i); - ++res; - } - } - cout << res << ""\n""; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); -// freopen(""1.inp"",""r"",stdin); -// freopen(""1.out"",""w"",stdout); - int t; - cin >> t; - while (t--) - { - input(); - solve(); - } -} - - - -","#include -using ll = long long; -using ld = long double; -using namespace std; -const int maxN = 1e6 + 5; -const int Mod = 1e9 + 7; -const int LG = 21; -int n,mx,mx1,d[maxN]; -bool avail[maxN]; -vector adj[maxN],p; -priority_queue> q; -void input() -{ - cin >> n; - while (!q.empty()) q.pop(); - p.clear(); - mx = 0; - for (int i = 0;i <= n;++i) adj[i].clear(); - for (int i = 1;i < n;++i) - { - int u,v; - cin >> u >> v; - adj[u].push_back(v); - adj[v].push_back(u); - if (adj[mx].size() < adj[u].size()) mx = u; - if (adj[mx].size() < adj[v].size()) mx = v; - } - for (int i = 1;i <= n;++i) - { - if (adj[i].size() == adj[mx].size()) p.push_back(i); - d[i] = adj[i].size(); - q.push({d[i],i}); - } -} -void solve() -{ - if (n <= 2) {cout << 0 << ""\n"";return;} - int res = -1e9; - for (int u : p) - { - bool flag = false; - for (int v : adj[u]) - { - q.push({d[v] - 1,v}); - --d[v]; - } - while (!q.empty() && (q.top().first != d[q.top().second] || q.top().second == u)) - { - if (q.top().second == u) flag = true; - q.pop(); - } - //cerr << q.size() << "" "" << u << "" "" << q.top().second << ""\n""; - res = max(res,d[u] + q.top().first - 1); - for (int v : adj[u]) - { - q.push({d[v] + 1,v}); - ++d[v]; - } - if (flag) q.push({d[u],u}); - } - cout << res << ""\n""; -} - -int main() -{ - ios_base::sync_with_stdio(false); - cin.tie(nullptr); -// freopen(""1.inp"",""r"",stdin); -// freopen(""1.out"",""w"",stdout); - int t; - cin >> t; - while (t--) - { - input(); - solve(); - } -} - - - -",2 -runrev22,2063C - Remove Exactly Two,c++20 ,304497489,304327461,"#include -using namespace std; -#define int long long - - - -signed main(){ - int t; - cin>>t; - - while(t--){ - - int n ; cin>>n ; - vectorindegree(n+1,0); - vector>edges; - map>mp; - for(int i =1 ; i<= (n-1) ; i++){ - int u,v ; - cin>>u>>v; - edges.push_back({u,v}); - indegree[u]++; - indegree[v]++; - mp[u].insert(v); - mp[v].insert(u); - } - - int ans = 0 ; - for(int i = 0 ; i>vec; - for(int i = 1 ; i<=n ; i++){ - vec.push_back({indegree[i],i}); - } - - sort(vec.rbegin(),vec.rend()); - - for(int i = 0 ; i -using namespace std; -#define int long long - -void dfs(int node, int pp , vector&vis, vectorgraph[]){ - - vis[node] = 1; - for(auto ch : graph[node]){ - if(ch == pp)continue ; - if(!vis[ch]){ - dfs(ch,node,vis,graph); - } - } -} - -signed main(){ - int t; - cin>>t; - - while(t--){ - - int n ; cin>>n ; - - - vectorindegree(n+1,0); - - priority_queuepq; - for(int i = 1 ; i <= (n-1); i++){ - int u,v ; - cin>>u>>v; - indegree[u]++; - indegree[v]++; - } - - for(int i =1 ; i<=n ; i++){ - pq.push(indegree[i]); - } - - if(n == 2){ - cout<<0< -using namespace std; -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx,avx2,sse,sse2"") -typedef long long ll; -#define inf 1e18 - -/* ------------------------------ordered set-------------------- -#include // Common file -#include -#include // for less -#include -using namespace __gnu_pbds; -using namespace std; - -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; -*/ - -/*-----------------PRIME FACTOR------------- -for (int i = 2; i*i <= n; i = i+2) -{ - // While i divides n, print i and divide n - while (n%i == 0) - { - printf(""%d "", i); - n = n/i; - } -} -*/ - -/*-----------------------sieve---------------- -vector prime(MAXN, false); -vector used(MAXN, false); -void precalc() { - for (int i = 2; i < MAXN; ++i) { - if (!used[i]) { - prime[i] = true; - for (int j = i; j < MAXN; j += i) { - used[j] = true; - } - } - } -} -*/ - -/*--------------------------------sqrt function------------------------ -ll my_sqrt(ll a) -{ - ll l=0,r=5000000001; - while(r-l>1) - { - ll mid=(l+r)/2; - if(1ll*mid*mid<=a)l=mid; - else r=mid; - } - return l; -} - -ll getclosest(ll x) -{ - ll n = sqrt(x); - if(n*n==x) - { - return 0; - } - else - { - return (n+1)*(n+1) - x; - } -} -ll cur = 0; - for(ll i=1;i>a>>x; - cur+=x; - cout<>divisors(MAXN); -void precomp() -{ - for(int i=2;i -using namespace std; - -void solve() -{ - int n; - cin >> n; - - vector> graph(n + 1); - vector degree(n + 1); - for (int i = 0; i < n - 1; i++) - { - int u, v; - cin >> u >> v; - graph[u].push_back(v); - graph[v].push_back(u); - degree[u]++; - degree[v]++; - } - multiset work; - for (int i = 1; i <= n; i++) - { - work.insert(degree[i]); - } - int comp = 0; - for (int i = 1; i <= n; i++) - { - vectorin,rem; - int cur = 0; - work.erase(work.find(degree[i])); - in.push_back(degree[i]); - cur += degree[i]; - for (auto v : graph[i]) { - work.erase(work.find(degree[v])); - work.insert(degree[v] - 1); - rem.push_back(degree[v]-1); - in.push_back(degree[v]); - } - if (!work.empty()) - { - cur += (*work.rbegin())-1; - } - for(auto p:in) - { - work.insert(p); - } - for(auto p:rem) - { - work.erase(work.find(p)); - } - comp = max(comp, cur); - } - - cout << comp << endl; -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(nullptr); - - int t; - cin >> t; - while (t--) { - solve(); - } - - return 0; -} -","//JAI SHREE RAM -#include -using namespace std; -#pragma GCC optimize(""O3,unroll-loops"") -#pragma GCC target(""avx,avx2,sse,sse2"") -typedef long long ll; -#define inf 1e18 - -/* ------------------------------ordered set-------------------- -#include // Common file -#include -#include // for less -#include -using namespace __gnu_pbds; -using namespace std; - -typedef tree, rb_tree_tag, - tree_order_statistics_node_update> - ordered_set; -*/ - -/*-----------------PRIME FACTOR------------- -for (int i = 2; i*i <= n; i = i+2) -{ - // While i divides n, print i and divide n - while (n%i == 0) - { - printf(""%d "", i); - n = n/i; - } -} -*/ - -/*-----------------------sieve---------------- -vector prime(MAXN, false); -vector used(MAXN, false); -void precalc() { - for (int i = 2; i < MAXN; ++i) { - if (!used[i]) { - prime[i] = true; - for (int j = i; j < MAXN; j += i) { - used[j] = true; - } - } - } -} -*/ - -/*--------------------------------sqrt function------------------------ -ll my_sqrt(ll a) -{ - ll l=0,r=5000000001; - while(r-l>1) - { - ll mid=(l+r)/2; - if(1ll*mid*mid<=a)l=mid; - else r=mid; - } - return l; -} - -ll getclosest(ll x) -{ - ll n = sqrt(x); - if(n*n==x) - { - return 0; - } - else - { - return (n+1)*(n+1) - x; - } -} -ll cur = 0; - for(ll i=1;i>a>>x; - cur+=x; - cout<>divisors(MAXN); -void precomp() -{ - for(int i=2;i>n; - vector>val(n+1); - for(int i=0;i>u>>v; - val[u].push_back(v); - val[v].push_back(u); - } - /* - for(int i=1;i<=n;i++) - { - cout<>degree,degree2; - for(int i=1;i<=n;i++) - { - degree.push_back({val[i].size(),i}); - } - sort(degree.begin(),degree.end()); - int comp = 0; - if(degree.back().first==0) - { - if(degree.size()==1) - { - cout<<0<cur; - for(auto p:val[del]) - { - cur.insert(p); - } - for(int i=0;i> t; - while (t--) { - solve(); - } - - return 0; -} -",1 -Michi_Numberz,2063C - Remove Exactly Two,c++17 ,306141265,306142961,"#include -using namespace std; -#define ll long long - -void solve(int n) { - vector> adj(n+1); - vector deg(n+1, 0); - for (int i = 0; i < n-1; i++) { - int a, b; - cin >> a >> b; - adj[a].push_back(b); - adj[b].push_back(a); - deg[a]++; deg[b]++; - } - int mx1 = 0; - for (int i = 1; i <= n; i++) if (deg[i] > deg[mx1]) mx1 = i; - int ans = deg[mx1]; - deg[mx1] = 0; - for (int u : adj[mx1]) deg[u]--; - int mx2 = 0; - for (int i = 1; i <= n; i++) if (deg[i] > deg[mx2]) mx2 = i; - ans += deg[mx2] - 1; - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int tt; - cin >> tt; - while (tt--) { - int n; - cin >> n; - solve(n); - } - - return 0; -}","#include -using namespace std; -#define ll long long - -void solve(int n) { - vector> adj(n+1); - vector deg(n+1, 0); - for (int i = 0; i < n-1; i++) { - int a, b; - cin >> a >> b; - adj[a].push_back(b); - adj[b].push_back(a); - deg[a]++; deg[b]++; - } - - int c1 = 0, c2 = 0; - for (int i = 1; i <= n; i++) { - if (deg[i] >= deg[c2]) { - c2 = i; - if (deg[c2] >= deg[c1]) swap(c1, c2); - } - } - - int ans1 = 0, ans2 = 0; - for (int u : adj[c1]) deg[u]--; - for (int i = 1; i <= n; i++) if (i != c1) ans1 = max(ans1, deg[i]); - for (int u : adj[c1]) deg[u]++; - ans1 += (deg[c1]-1); - for (int u : adj[c2]) deg[u]--; - for (int i = 1; i <= n; i++) if (i != c2) ans2 = max(ans2, deg[i]); - ans2 += (deg[c2]-1); - cout << max(ans1, ans2) << '\n'; -} - -int main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - - int tt; - cin >> tt; - while (tt--) { - int n; - cin >> n; - solve(n); - } - - return 0; -}",2 -Adham_Ibrahim,2063C - Remove Exactly Two,c++23 ,307293918,307297551,"#include - -using namespace std; -//#define endl ""\n"" -#define speeed ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); -#define ld long double - -#define ll long long -#define sz(s) (int)size(s) -//#define int ll - -void File() { -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif -} - -ll tc = 1; -#define OO LLONG_MAX -#define ONBit(n, k) (n|(1ll<>k)&1ll) -#define twopower(n) (1ll<= 0 && i < n && j >= 0 && j < m; } - -long long mul(long long x, long long y, const long long MOD = MOD1) { return ((x % MOD) * (y % MOD)) % MOD; } - -long long add_MOD(long long x, long long y, long long MOD = MOD1) { - return (((x % MOD) + (y % MOD)) % MOD + MOD) % MOD; -} - -long long sub(long long a, long long b, long long m = MOD1) { - return ((a % m) - (b % m) + m) % m; -} - -ll SafeMul(ll a, ll b, ll m) { - if (b == 0)return 0; - ll res = SafeMul(a, b / 2, m); - res = add_MOD(res, res, m); - if (b & 1)return add_MOD(res, a, m); - else return res; -} - -ll fast_power(ll a, ll b, ll m) { - if (b == 0)return 1; - ll res = fast_power(a, b / 2, m); - res = (res * res) % m; - if (b & 1)return (res * a) % m; - else return res; -} - -/*ll fast_power(ll x, ll n, ll m) { - ll result = 1; - while (n > 0) { - if (n % 2 == 1) { - result = SafeMul(result, x, m); - } - x = SafeMul(x, x, m); - n = n / 2; - } - return result; -}*/ - -int log2_floor(long long i) { return i ? __builtin_clzll(1) - __builtin_clzll(i) : 0; } - -int power_of_2(int n) { return __builtin_popcountll(n) == 1; } - -bool line_checking(int a1, int b1, int a2, int b2, int a3, int b3) { - return (b2 - b1) * (a2 - a3) == (b2 - b3) * (a2 - a1); -} - -pair rotate(int i, int j, int n) { return make_pair(j, n - 1 - i); } - -int comp_double(double a, double b, double error = 1e-7) { - if (fabs(a - b) <= error)return 0; - if (a < b)return 1; - return -1; -} - -int round(int x, int y) { - if (y < 0)x *= -1, y *= -1; - if (x < 0) { - return (2 * x - y + 1) / (2 * y); - } - return (2 * x + y - 1) / (2 * y); -} - -int floor(int x, int y) { - return x / y; -} - -int ceil(int x, int y) { - return (x + y - 1) / y; -} - -/*int round(int m,int x){return round(m/x)*x;}*/ - - -int dx[]{0, 0, 1, -1, -1, -1, 1, 1}; -int dy[]{1, -1, 0, 0, 1, -1, -1, 1}; - - -ll egcd(ll a, ll b, ll &x, ll &y) { /// ax + by = gcd(a,b) - if (!b) { - x = 1; - y = 0; - return a; - } - ll g = egcd(b, a % b, y, x); - y -= (a / b) * x; - return g; -} - -ll modInverse(ll a, ll m) { /// (a/b)%m = ((a%m)*(modInverse(b)%m))%m - ll x, y, g; - g = egcd(a, m, x, y); - if (g > 1) - return -1; - return (x + m) % m; -} - -void print(vector &v) { - for (auto item: v) { - cout << item << "" ""; - } - cout << endl; -} - -struct pair_hash { - template - std::size_t operator()(const std::pair &p) const { - auto h1 = std::hash{}(p.first); - auto h2 = std::hash{}(p.second); - - // Mainly for demonstration purposes, i.e. works but is overly simple - // In the real world, use sth. like boost.hash_combine - return h1 ^ h2; - } -}; - - -int F(vector> &adj, vector &vis) { - int mx = 0, node = 1; - for (int i = 1; i < adj.size(); ++i) { - if (mx <= adj[i].size() and !vis[i]) { - mx = adj[i].size(); - node = i; - } - } - return node; -} - -void dfs(int node, vector &vis, vector> &adj) { - vis[node] = true; - for (auto child: adj[node]) { - if (!vis[child]) { - dfs(child, vis, adj); - } - } -} - - -void main_() { - int n; - cin >> n; - vector> adj(n + 1); - for (int u, v, i = 0; i < n - 1; ++i) { - cin >> u >> v; - adj[u].insert(v); - adj[v].insert(u); - } - int ans = 0; - for (int node = 1; node <= n; ++node) { - int curr = 0; - for (auto child: adj[node]) { - curr = max(adj[child].size(), curr); - } - ans = max(ans, curr + adj[node].size() - 2); - } - vector vis(n + 1, false); - int node = F(adj, vis); - for (auto child: adj[node]) { - adj[child].erase(node); - } - adj[node].clear(); - vis[node] = 1; - node = F(adj, vis); - for (auto child: adj[node]) { - adj[child].erase(node); - } - adj[node].clear(); - vis[node] = 1; - int curr = 0; - for (int i = 1; i <= n; ++i) { - if (!vis[i]) { - ++curr; - dfs(i, vis, adj); - } - } - ans= max(ans,curr); - cout << ans; -} - -void preprocessing() { - -} - - -signed main() { - speeed - File(); -// freopen(""business.in"", ""r"", stdin); - int t = 1; - preprocessing(); - cin >> t; - for (int i = 1; i <= t; ++i) { -// cout << ""Case #""< - -using namespace std; -//#define endl ""\n"" -#define speeed ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0); -#define ld long double - -#define ll long long -#define sz(s) (int)size(s) -//#define int ll - -void File() { -#ifndef ONLINE_JUDGE - - freopen(""input.txt"", ""r"", stdin); - freopen(""output.txt"", ""w"", stdout); - freopen(""error.txt"", ""w"", stderr); -#endif -} - -ll tc = 1; -#define OO LLONG_MAX -#define ONBit(n, k) (n|(1ll<>k)&1ll) -#define twopower(n) (1ll<= 0 && i < n && j >= 0 && j < m; } - -long long mul(long long x, long long y, const long long MOD = MOD1) { return ((x % MOD) * (y % MOD)) % MOD; } - -long long add_MOD(long long x, long long y, long long MOD = MOD1) { - return (((x % MOD) + (y % MOD)) % MOD + MOD) % MOD; -} - -long long sub(long long a, long long b, long long m = MOD1) { - return ((a % m) - (b % m) + m) % m; -} - -ll SafeMul(ll a, ll b, ll m) { - if (b == 0)return 0; - ll res = SafeMul(a, b / 2, m); - res = add_MOD(res, res, m); - if (b & 1)return add_MOD(res, a, m); - else return res; -} - -ll fast_power(ll a, ll b, ll m) { - if (b == 0)return 1; - ll res = fast_power(a, b / 2, m); - res = (res * res) % m; - if (b & 1)return (res * a) % m; - else return res; -} - -/*ll fast_power(ll x, ll n, ll m) { - ll result = 1; - while (n > 0) { - if (n % 2 == 1) { - result = SafeMul(result, x, m); - } - x = SafeMul(x, x, m); - n = n / 2; - } - return result; -}*/ - -int log2_floor(long long i) { return i ? __builtin_clzll(1) - __builtin_clzll(i) : 0; } - -int power_of_2(int n) { return __builtin_popcountll(n) == 1; } - -bool line_checking(int a1, int b1, int a2, int b2, int a3, int b3) { - return (b2 - b1) * (a2 - a3) == (b2 - b3) * (a2 - a1); -} - -pair rotate(int i, int j, int n) { return make_pair(j, n - 1 - i); } - -int comp_double(double a, double b, double error = 1e-7) { - if (fabs(a - b) <= error)return 0; - if (a < b)return 1; - return -1; -} - -int round(int x, int y) { - if (y < 0)x *= -1, y *= -1; - if (x < 0) { - return (2 * x - y + 1) / (2 * y); - } - return (2 * x + y - 1) / (2 * y); -} - -int floor(int x, int y) { - return x / y; -} - -int ceil(int x, int y) { - return (x + y - 1) / y; -} - -/*int round(int m,int x){return round(m/x)*x;}*/ - - -int dx[]{0, 0, 1, -1, -1, -1, 1, 1}; -int dy[]{1, -1, 0, 0, 1, -1, -1, 1}; - - -ll egcd(ll a, ll b, ll &x, ll &y) { /// ax + by = gcd(a,b) - if (!b) { - x = 1; - y = 0; - return a; - } - ll g = egcd(b, a % b, y, x); - y -= (a / b) * x; - return g; -} - -ll modInverse(ll a, ll m) { /// (a/b)%m = ((a%m)*(modInverse(b)%m))%m - ll x, y, g; - g = egcd(a, m, x, y); - if (g > 1) - return -1; - return (x + m) % m; -} - -void print(vector &v) { - for (auto item: v) { - cout << item << "" ""; - } - cout << endl; -} - -struct pair_hash { - template - std::size_t operator()(const std::pair &p) const { - auto h1 = std::hash{}(p.first); - auto h2 = std::hash{}(p.second); - - // Mainly for demonstration purposes, i.e. works but is overly simple - // In the real world, use sth. like boost.hash_combine - return h1 ^ h2; - } -}; - - -void main_() { - int n; - cin >> n; - vector> adj(n + 1); - vectordeg(n+1); - multiset,greater<>>multiset1; - for (int u, v, i = 0; i < n - 1; ++i) { - cin >> u >> v; - adj[u].insert(v); - adj[v].insert(u); - deg[u]++; - deg[v]++; - } - - for (int i = 1; i <= n ; ++i) { - multiset1.insert({deg[i],i}); - } - - int ans = 0; - for (int node = 1; node <= n ; ++node) { - multiset1.erase({deg[node], node}); - for (auto child:adj[node]) { - ans = max(ans, deg[node] + deg[child] - 2); - multiset1.erase({deg[child],child}); - } - - int mx = multiset1.begin()->first; - ans = max(ans, mx + deg[node] - 1); - - - for (auto child:adj[node]) { - ans = max(ans, deg[node] + deg[child] - 2); - multiset1.insert({deg[child],child}); - } - - multiset1.insert({deg[node], node}); - } - - cout<> t; - for (int i = 1; i <= t; ++i) { -// cout << ""Case #""< -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include - - -/* -#include -#include - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - -ordered_set st; -*/ - -// g++-13 -std=c++11 codeforce.cpp -o codeforce -// g++ -std=c++11 codeforce.cpp -o codeforce -// ./codeforce manacher_odd(string s) { - int n = s.size(); - s = ""$"" + s + ""^""; - vector p(n + 2); - int l = 1, r = 1; - for(int i = 1; i <= n; i++) { - p[i] = max(0, min(r - i, p[l + (r - i)])); - while(s[i - p[i]] == s[i + p[i]]) { - p[i]++; - } - if(i + p[i] > r) { - l = i - p[i], r = i + p[i]; - } - } - return vector(begin(p) + 1, end(p) - 1); -} -vector manacher(string s) { - string t; - for(auto c: s) { - t += string(""#"") + c; - } - auto res = manacher_odd(t + ""#""); - return vector(begin(res) + 1, end(res) - 1); -} - -// mt19937_64 rnd(98275314); -// ll gen(){ -// ll x=0; -// while(x==0){ -// x=rnd(); -// } -// return x; -// } -vector z_function(string s) { - int n = s.size(); - vector z(n); - int l = 0, r = 0; - for(int i = 1; i < n; i++) { - if(i < r) { - z[i] = min(r - i, z[i - l]); - } - while(i + z[i] < n && s[z[i]] == s[i + z[i]]) { - z[i]++; - } - if(i + z[i] > r) { - l = i; - r = i + z[i]; - } - } - return z; -} -/* -template -struct MaxFlow { - struct _Edge { - int to; - T cap; - _Edge(int to, T cap) : to(to), cap(cap) {} - }; - int n; - std::vector<_Edge> e; - std::vector > g; - std::vector cur, h; - MaxFlow() {} - MaxFlow(int n) { - init(n); - } - void init(int n) { - this->n = n; - e.clear(); - g.assign(n, {}); - cur.resize(n); - h.resize(n); - } - bool bfs(int s, int t) { - h.assign(n, -1); - std::queue que; - h[s] = 0; - que.push(s); - while (!que.empty()) { - const int u = que.front(); - que.pop(); - for (int i : g[u]) { - auto [v, c] = e[i]; - if (c > 0 && h[v] == -1) { - h[v] = h[u] + 1; - if (v == t) { - return true; - } - que.push(v); - } - } - } - return false; - } - T dfs(int u, int t, T f) { - if (u == t) { - return f; - } - auto r = f; - for (int &i = cur[u]; i < int(g[u].size()); ++i) { - const int j = g[u][i]; - auto [v, c] = e[j]; - if (c > 0 && h[v] == h[u] + 1) { - auto a = dfs(v, t, std::min(r, c)); - e[j].cap -= a; - e[j ^ 1].cap += a; - r -= a; - if (r == 0) { - return f; - } - } - } - return f - r; - } - void addEdge(int u, int v, T c) { - g[u].push_back(e.size()); - e.emplace_back(v, c); - g[v].push_back(e.size()); - e.emplace_back(u, 0); - } - T flow(int s, int t) { - T ans = 0; - while (bfs(s, t)) { - cur.assign(n, 0); - ans += dfs(s, t, std::numeric_limits::max()); - } - return ans; - } - std::vector minCut() { - std::vector c(n); - for (int i = 0; i < n; i++) { - c[i] = (h[i] != -1); - } - return c; - } - struct Edge { - int from; - int to; - T cap; - T flow; - }; - std::vector edges() { - std::vector a; - for (int i = 0; i < e.size(); i += 2) { - Edge x; - x.from = e[i + 1].to; - x.to = e[i].to; - x.cap = e[i].cap + e[i + 1].cap; - x.flow = e[i + 1].cap; - a.push_back(x); - } - return a; - } -}; -*/ -// std::mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()}; -const int N=2e5; -vectorG[N]; -void solve(){ - int n; - cin>>n; - vectordeg(n); - for(int i=0;i>u>>v; - --u,--v; - G[u].push_back(v); - G[v].push_back(u); - deg[u]++; - deg[v]++; - } - vectoridx(n); - int mx=*max_element(deg.begin(),deg.end()); - iota(idx.begin(),idx.end(),0); - sort(idx.begin(),idx.end(), [&](int a, int b){ - return deg[a]>deg[b]; - }); - int ans=0; - for(int j=0;j>t; - while(t--){ - solve(); - } -} - -/* - -FOR ICPC style rounds, read all problems! don't get stuck on 1. -*/ -/*prvb -nice trick: -up is down? - -Fenwick -int lowbit(int i) { // gets the lowest set bit - return (-i)&i; -} -adds 1 from [1,i]; -void bitadd(int i) { - for(;i<=n;i+=lowbit(i)) bit[i]++; -} -queries [1,i]; -int bitqu(int i) { - int ans=0; - for(;i;i-=lowbit(i)) ans+=bit[i]; - return ans; -} -*/","#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include - - -/* -#include -#include - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; - -ordered_set st; -*/ - -// g++-13 -std=c++11 codeforce.cpp -o codeforce -// g++ -std=c++11 codeforce.cpp -o codeforce -// ./codeforce manacher_odd(string s) { - int n = s.size(); - s = ""$"" + s + ""^""; - vector p(n + 2); - int l = 1, r = 1; - for(int i = 1; i <= n; i++) { - p[i] = max(0, min(r - i, p[l + (r - i)])); - while(s[i - p[i]] == s[i + p[i]]) { - p[i]++; - } - if(i + p[i] > r) { - l = i - p[i], r = i + p[i]; - } - } - return vector(begin(p) + 1, end(p) - 1); -} -vector manacher(string s) { - string t; - for(auto c: s) { - t += string(""#"") + c; - } - auto res = manacher_odd(t + ""#""); - return vector(begin(res) + 1, end(res) - 1); -} - -// mt19937_64 rnd(98275314); -// ll gen(){ -// ll x=0; -// while(x==0){ -// x=rnd(); -// } -// return x; -// } -vector z_function(string s) { - int n = s.size(); - vector z(n); - int l = 0, r = 0; - for(int i = 1; i < n; i++) { - if(i < r) { - z[i] = min(r - i, z[i - l]); - } - while(i + z[i] < n && s[z[i]] == s[i + z[i]]) { - z[i]++; - } - if(i + z[i] > r) { - l = i; - r = i + z[i]; - } - } - return z; -} -/* -template -struct MaxFlow { - struct _Edge { - int to; - T cap; - _Edge(int to, T cap) : to(to), cap(cap) {} - }; - int n; - std::vector<_Edge> e; - std::vector > g; - std::vector cur, h; - MaxFlow() {} - MaxFlow(int n) { - init(n); - } - void init(int n) { - this->n = n; - e.clear(); - g.assign(n, {}); - cur.resize(n); - h.resize(n); - } - bool bfs(int s, int t) { - h.assign(n, -1); - std::queue que; - h[s] = 0; - que.push(s); - while (!que.empty()) { - const int u = que.front(); - que.pop(); - for (int i : g[u]) { - auto [v, c] = e[i]; - if (c > 0 && h[v] == -1) { - h[v] = h[u] + 1; - if (v == t) { - return true; - } - que.push(v); - } - } - } - return false; - } - T dfs(int u, int t, T f) { - if (u == t) { - return f; - } - auto r = f; - for (int &i = cur[u]; i < int(g[u].size()); ++i) { - const int j = g[u][i]; - auto [v, c] = e[j]; - if (c > 0 && h[v] == h[u] + 1) { - auto a = dfs(v, t, std::min(r, c)); - e[j].cap -= a; - e[j ^ 1].cap += a; - r -= a; - if (r == 0) { - return f; - } - } - } - return f - r; - } - void addEdge(int u, int v, T c) { - g[u].push_back(e.size()); - e.emplace_back(v, c); - g[v].push_back(e.size()); - e.emplace_back(u, 0); - } - T flow(int s, int t) { - T ans = 0; - while (bfs(s, t)) { - cur.assign(n, 0); - ans += dfs(s, t, std::numeric_limits::max()); - } - return ans; - } - std::vector minCut() { - std::vector c(n); - for (int i = 0; i < n; i++) { - c[i] = (h[i] != -1); - } - return c; - } - struct Edge { - int from; - int to; - T cap; - T flow; - }; - std::vector edges() { - std::vector a; - for (int i = 0; i < e.size(); i += 2) { - Edge x; - x.from = e[i + 1].to; - x.to = e[i].to; - x.cap = e[i].cap + e[i + 1].cap; - x.flow = e[i + 1].cap; - a.push_back(x); - } - return a; - } -}; -*/ -// std::mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()}; -const int N=2e5; -vectorG[N]; -void solve(){ - int n; - cin>>n; - vectordeg(n); - for(int i=0;i>u>>v; - --u,--v; - G[u].push_back(v); - G[v].push_back(u); - deg[u]++; - deg[v]++; - } - vectoridx(n); - int mx=*max_element(deg.begin(),deg.end()); - iota(idx.begin(),idx.end(),0); - sort(idx.begin(),idx.end(), [&](int a, int b){ - return deg[a]>deg[b]; - }); - int ans=0; - for(int j=0;j=mx-1;++j){ - for(int i=0;i>t; - while(t--){ - solve(); - } -} - -/* - -FOR ICPC style rounds, read all problems! don't get stuck on 1. -*/ -/*prvb -nice trick: -up is down? - -Fenwick -int lowbit(int i) { // gets the lowest set bit - return (-i)&i; -} -adds 1 from [1,i]; -void bitadd(int i) { - for(;i<=n;i+=lowbit(i)) bit[i]++; -} -queries [1,i]; -int bitqu(int i) { - int ans=0; - for(;i;i-=lowbit(i)) ans+=bit[i]; - return ans; -} -*/",1 -VidGa,2063C - Remove Exactly Two,c++23 ,304091171,304098863,"#include -using namespace std; - -void solve() { - int n; cin >> n; - vector> b; - set> edges; - vector degree(n,0); - - for (int i = 0; i < n-1; i++) { - int u,v; - cin >> u >> v; - u--; v--; - - degree[u]++; - degree[v]++; - edges.insert(make_pair(u,v)); - edges.insert(make_pair(v,u)); - } - - for (int i = 0; i <= n-1; i++) { - b.push_back(make_pair(degree[i],i)); - } - sort(b.begin(), b.end(), greater>()); - - if (n == 2) {cout << 0 << endl; return;} - - int M = b[0].first, N = b[1].first, K = b[2].first; - - if (M == N && N == K) { - cout << 2*M - 1 << endl; - return; - } else if (M == N && N > K) { - if (edges.find(make_pair(b[0].second, b[1].second)) != edges.end()) { - cout << M+N-1 << endl; - } else { - cout << 2*M - 1 << endl; - } - return; - } else if (M > N && N == K) { - int flag = 0; - for (int i = 1; i < n; i++) { - if (b[i].first != b[1].first) break; - if (edges.find(make_pair(b[0].second, b[i].second)) == edges.end()) { - flag = 1; - break; - } - } - - if (flag) { - cout << M+N-1 << endl; - } else { - cout << M+N-2 << endl; - } - return; - } else { - cout << M+N-1 << endl; - return; - } - - return; -} - -int main() { - int t; cin >> t; - while (t--) { - solve(); - } -}","#include -using namespace std; - -void solve() { - int n; cin >> n; - vector> b; - set> edges; - vector degree(n,0); - - for (int i = 0; i < n-1; i++) { - int u,v; - cin >> u >> v; - u--; v--; - - degree[u]++; - degree[v]++; - edges.insert(make_pair(u,v)); - edges.insert(make_pair(v,u)); - } - - for (int i = 0; i <= n-1; i++) { - b.push_back(make_pair(degree[i],i)); - } - sort(b.begin(), b.end(), greater>()); - - if (n == 2) {cout << 0 << endl; return;} - - int M = b[0].first, N = b[1].first, K = b[2].first; - - if (M == N && N == K) { - cout << 2*M - 1 << endl; - return; - } else if (M == N && N > K) { - if (edges.find(make_pair(b[0].second, b[1].second)) != edges.end()) { - cout << M+N-2 << endl; - } else { - cout << 2*M-1 << endl; - } - return; - } else if (M > N) { - int flag = 0; - for (int i = 1; i < n; i++) { - if (b[i].first != b[1].first) break; - if (edges.find(make_pair(b[0].second, b[i].second)) == edges.end()) { - flag = 1; - break; - } - } - - if (flag) { - cout << M+N-1 << endl; - } else { - cout << M+N-2 << endl; - } - return; - } - - return; -} - -int main() { - int t; cin >> t; - while (t--) { - solve(); - } -}",2 -Champ_x78,2063C - Remove Exactly Two,c++20 ,305850883,305831547,"#include -using namespace std; -#define int long long - -vector> adj; -vector degree; - -// void dfs(int node, int par) { -// for (auto v : adj[node]) { -// if (v != par) { -// degree[node]++; -// dfs(v,node); -// } -// } -// } - - -signed main() { - int t; - cin>>t; - while (t--) - { - - int n; - cin>>n; - // adj.clear(); - // adj.resize(n + 1); - degree.assign(n+1,0); - set> s; - - - for (int i = 1; i < n; i++) { - int a,b; - cin >> a>>b; - degree[a]++; - degree[b]++; - // adj[a].push_back(b); - // adj[b].push_back(a); - s.insert({a,b}); - s.insert({b,a}); - } - - vector> arr; - - for(int i=1;i<=n;i++) arr.push_back({degree[i],i}); - sort(arr.rbegin(),arr.rend()); - int ans=0; - - for(int i=0;i -using namespace std; -#define int long long - -vector> adj; -vector degree; - -void dfs(int node, int par) { - for (auto v : adj[node]) { - if (v != par) { - degree[node]++; - dfs(v,node); - } - } -} - - -signed main() { - int t; - cin>>t; - while (t--) - { - - int n; - cin>>n; - adj.clear(); - adj.resize(n + 1); - degree.assign(n+1,1); - - degree[1]=0; - - for (int i = 1; i < n; i++) { - int a,b; - cin >> a>>b; - adj[a].push_back(b); - adj[b].push_back(a); - } - - dfs(1, -1); - - int element=0,deg=0; - - for(int i=1;i<=n;i++){ - if(degree[i]>deg) element=i,deg=degree[i]; - } - //cout<deg) element=i,deg=degree[i]; - } - - ans+=deg-1; - cout< -#include -#include -#define add(a,b) e[a].push_back(b) -#define rep for(int v:e[i]) -#define siz(a) e[a].size() -using namespace std; - -const int N=1e6+5; - -int t; - -vectore[N]; -multisets; - - -inline void work(){ - s.clear(); - int n,ans=0; - cin>>n; - for(int i=0;i<=n;++i)e[i].clear(); - for(int i=1;i>u>>v; - add(u,v),add(v,u); - } - for(int i=1;i<=n;++i){ - s.insert(siz(i)); - } - for(int i=1;i<=n;++i){ - s.erase(s.find(siz(i))); - rep{ - s.erase(s.find(siz(v))); - s.insert(siz(v)-1); - } - ans=max(ans,(int)siz(i)+*s.rbegin()-1); - s.insert(siz(i)); - rep{ - s.erase(s.find(siz(v)-1)); - s.insert(siz(v)); - } - } - cout<>t; - while(t--)work(); - return 0; -}","#include -#include -#include -#define add(a,b) e[a].push_back(b) -#define rep for(int v:e[i]) -#define siz(a) e[a].size() -using namespace std; - -const int N=1e5+5; - -int t; - -vectore[N]; -multisets; - - -inline void work(){ - s.clear(); - for(int i=0;i>n; - for(int i=1;i>u>>v; - add(u,v),add(v,u); - } - for(int i=1;i<=n;++i){ - s.insert(siz(i)); - } - for(int i=1;i<=n;++i){ - s.erase(s.find(siz(i))); - rep{ - s.erase(s.find(siz(v))); - s.insert(siz(v)-1); - } - ans=max(ans,(int)siz(i)+*s.rbegin()-1); - s.insert(siz(i)); - rep{ - s.erase(s.find(siz(v)-1)); - s.insert(e[v].size()); - } - } - cout<>t; - while(t--)work(); - return 0; -}",1 -PzzZ,2063C - Remove Exactly Two,c++23 ,306901461,306898870,"#include - -using namespace std; -const int N = 2e5 + 5; -int t; -int n, u, v, ans, d[N]; -set > c; -vector a[N]; -void dfs(int u, int p) { - for(auto& v : a[u]) { - if(v != p) { - dfs(v, u); - ans = max(ans, (int) a[v].size() + (int) a[u].size() - 2); - } - } -} -bool cmp(int x, int y) { - if(a[x].size() == a[y].size())return x < y; - return a[x].size() > a[y].size(); -} -void solve() { - ans = 0; - dfs(1, 0); - sort(d + 1, d + n + 1, cmp); - for(int i = 1; i <= n; i++) { - for(int j = i + 1; j <= n; j++) { - if(c.find({d[i], d[j]}) == c.end()) { - ans = max(ans, (int) a[d[i]].size() + (int) a[d[j]].size() - 1); - break; - } - } - } - cout << ans << '\n'; -} -void input() { - cin >> t; - while(t--) { - cin >> n; - c.clear(); - for(int i = 1; i <= n; i++) { - a[i].clear(); - d[i] = i; - } - for(int i = 1; i <= n - 1; i++) { - cin >> u >> v; - c.insert({u, v}); - c.insert({v, u}); - a[u].push_back(v); - a[v].push_back(u); - } - solve(); - } -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - input(); - return 0; -} -","#include - -using namespace std; -const int N = 2e5 + 5; -int t; -int n, u, v, ans, d[N], d1[N]; -vector a[N]; -void dfs(int u, int p) { - d[u] = a[u].size(); - int mx = 0, mx1 = 0; - for(auto& v : a[u]) { - if(v != p) { - dfs(v, u); - d[u] = max(d[u], d[v]); - d1[u] = max(d1[u], (int) a[v].size()); - mx1 = max(mx1, d1[v]); - ans = max(ans, (int) a[v].size() + (int) a[u].size() - 2); - ans = max(ans, mx + d[v] - 1); - mx = max(mx, d[v]); - } - } - ans = max(ans, mx1 + (int) a[u].size() - 1); -} -void solve() { - ans = 0; - dfs(1, 0); - cout << ans << '\n'; -} -void input() { - cin >> t; - while(t--) { - cin >> n; - for(int i = 1; i <= n; i++) { - a[i].clear(); - d[i] = 0; - d1[i] = 0; - } - for(int i = 1; i <= n - 1; i++) { - cin >> u >> v; - a[u].push_back(v); - a[v].push_back(u); - } - solve(); - } -} - -int main() { - ios_base::sync_with_stdio(0); - cin.tie(0); cout.tie(0); - input(); - return 0; -} -",1 -reijnnn,2063C - Remove Exactly Two,python,303956779,303952810,"import io -import os -import sys - - -inf = 10 ** 18 -mod = 10 ** 9 + 7 - -ONLINE_JUDGE = __debug__ - -if ONLINE_JUDGE: - R = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline - - - def _input() -> str: - return R().decode() -else: - R = sys.stdin.readline - - - def _input() -> str: - return R() - - -def get_int() -> int: - return int(_input()) - - -def get_str() -> str: - return _input().strip() - - -def get_int_list() -> list[int]: - return list(map(int, _input().strip().split())) - - -def init_matrix(n_, m_, value_=0) -> list[list]: - return [[value_] * m_ for _ in range(n_)] - - -def solve() -> None: - n = get_int() - - g = init_matrix(n, 0) - cnt = [0] * n - pairs = set() - for i in range(n - 1): - u, v = get_int_list() - u -= 1 - v -= 1 - g[v].append(u) - g[u].append(v) - cnt[u] += 1 - cnt[v] += 1 - pairs.add((u, v)) - pairs.add((v, u)) - - order = sorted( - range(len(cnt)), - key=lambda x: cnt[x], - reverse=True, - ) - u, v = order[:2] - h = [] - for i in range(n): - if cnt[i] == cnt[v]: - h.append(i) - - if cnt[u] != cnt[v]: - for w in h: - if (u, w) not in pairs: - print(cnt[u] + cnt[v] - 1) - return - - print(cnt[u] + cnt[v] - 2) - else: - for i in range(len(h)): - for j in range(i + 1, len(h)): - if (h[i], h[j]) not in pairs: - print(cnt[u] + cnt[v] - 1) - return - - print(cnt[u] + cnt[v] - 2) - - -for _ in range(get_int()): - solve() -","import io -import os -import sys - - -inf = 10 ** 18 -mod = 10 ** 9 + 7 - -ONLINE_JUDGE = __debug__ - -if ONLINE_JUDGE: - R = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline - - - def _input() -> str: - return R().decode() -else: - R = sys.stdin.readline - - - def _input() -> str: - return R() - - -def get_int() -> int: - return int(_input()) - - -def get_str() -> str: - return _input().strip() - - -def get_int_list() -> list[int]: - return list(map(int, _input().strip().split())) - - -def init_matrix(n_, m_, value_=0) -> list[list]: - return [[value_] * m_ for _ in range(n_)] - - -def solve() -> None: - n = get_int() - - g = init_matrix(n, 0) - cnt = [0] * n - pairs = set() - for i in range(n - 1): - u, v = get_int_list() - u -= 1 - v -= 1 - g[v].append(u) - g[u].append(v) - cnt[u] += 1 - cnt[v] += 1 - pairs.add((u, v)) - pairs.add((v, u)) - - order = sorted( - range(len(cnt)), - key=lambda x: cnt[x], - reverse=True, - ) - u, v = order[:2] - h = [] - for i in range(n): - if cnt[i] == cnt[v]: - h.append(i) - - if cnt[u] != cnt[v]: - for w in h: - if (u, w) not in pairs: - print(cnt[u] + cnt[v] - 1) - return - - print(cnt[u] + cnt[v] - 2) - else: - for i in range(len(h)): - for j in range(i + 1, len(h)): - if (i, j) not in pairs: - print(cnt[u] + cnt[v] - 1) - return - - print(cnt[u] + cnt[v] - 2) - - -for _ in range(get_int()): - solve() -",1 -k_san#,2063C - Remove Exactly Two,c++17 ,305484094,305487227,"#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define pii pair -using namespace std; - -const int LM=200100; -int n; -vectorG[LM]; - -int C(int x, int y){ - for(int i:G[x])if(y==i)return 1; - return 0; -} - -void solve(){ - scanf(""%d"",&n); - for(int i=1; i<=n; i++)G[i].clear(); - for(int i=1; iv[LM]; - for(int i=1; i<=n; i++){ - si[i]=G[i].size(); - Ms=max(Ms,si[i]); - v[si[i]].push_back(i); - } - int MsSi=v[Ms].size(); - if(MsSi>=3) - printf(""%d\n"",Ms*2-1); - if(MsSi==2){ - printf(""%d\n"",Ms*2-C(v[Ms][0],v[Ms][1])-1); - } - else{ - int ws=Ms-1; - while(v[ws].size()==0)ws--; - for(int i:v[ws]){ - if(C(i,v[Ms][0])==0){ - printf(""%d\n"",Ms+ws-1); - return; - } - } - printf(""%d\n"",Ms+ws-2); - } -} - -int main(){ - int tc; - scanf(""%d"", &tc); - for(;tc>0;tc--)solve(); -} -","#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define pii pair -using namespace std; - -const int LM=200100; -int n; -vectorG[LM]; -set S[LM]; -vectorv[LM]; - -int C(int x, int y){ - return S[x].find(y)!=S[x].end(); -} - -void solve(){ - scanf(""%d"",&n); - for(int i=1; i<=n; i++)G[i].clear(),v[i].clear(),S[i].clear(); - for(int i=1; i=3) - printf(""%d\n"",Ms*2-1); - else if(MsSi==2){ - printf(""%d\n"",Ms*2-C(v[Ms][0],v[Ms][1])-1); - } - else{ - int ws=Ms-1; - while(v[ws].empty())ws--; - for(int i:v[ws]){ - if(C(i,v[Ms][0])==0){ - printf(""%d\n"",Ms+ws-1); - return; - } - } - printf(""%d\n"",Ms+ws-2); - } -} - -int main(){ - int tc; - scanf(""%d"", &tc); - for(;tc>0;tc--)solve(); -} -",2 -hauntingBeasT,2063C - Remove Exactly Two,c++17 ,304393288,304426329,"#include -// #include -// #include -// using namespace __gnu_pbds; - -using namespace std; - -// typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key -#define int long long -#define pb push_back -#define vi vector -#define loop(i, n1, n) for (int i = n1; i < n; i++) -#define revloop(i, n, n1) for (int i = n; i >= n1; i--) -#define endl ""\n"" -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define sortv(v) sort(v.begin(), v.end()) -#define pii pair -#define vinp(v, n) \ - for (int i = 0; i < n; i++) \ - { \ - int k; \ - cin >> k; \ - v.pb(k); \ - } -#define mii map -// #define m 1e9+7 -#define nl cout << endl -#define vdebug(v) \ - for (auto i : v) \ - cout << i << "" ""; \ - nl - -#define vall(v) v.begin(), v.end() -#define vsort(v) sort(vall(v)) -#define print(v) cout << v << endl; -double pi = 2 * acos(0.0); -int max(int a, int b) -{ - if (a > b) - return a; - else - return b; -} -int min(int a, int b) -{ - if (a > b) - return b; - else - return a; -} -bool isPalindrome(string S) -{ - - string P = S; - - reverse(P.begin(), P.end()); - - if (S == P) - { - - return 1; - } - - else - { - - return 0; - } -} -// void build(vector v){ -// int n=v.size(); -// vector> s(n,vector(17)); -// for(int i=0;i &arr, int target) -{ - int left = 0, right = arr.size() - 1; - while (left <= right) - { - int mid = left + (right - left) / 2; - if (arr[mid] == target) - { - return mid; - } - else if (arr[mid] < target) - { - left = mid + 1; - } - else - { - right = mid - 1; - } - } - return -1; -} - -int RSB(int n) -{ - return log2(n & -n); -} - -int factorial(int b) -{ - if (b == 1 || b == 0) - return 1; - return (b)*factorial(b - 1); -} - -void multiply(int a[3][3], int b[3][3]) -{ - int mul[3][3]; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - mul[i][j] = 0; - for (int k = 0; k < 3; k++) - { - mul[i][j] += a[i][k] * b[k][j]; - } - } - } - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - a[i][j] = mul[i][j]; - } - } -} - -int power(int F[3][3], int n) -{ - int M[3][3] = {{1, 1, 0}, {1, 0, 0}, {0, 1, 0}}; - if (n == 1) - return F[0][0] + F[0][1]; - power(F, n / 2); - multiply(F, F); - if (n % 2 != 0) - multiply(F, M); - return F[0][0] + F[0][1]; -} - -int fibo(int n) -{ - --n; - int F[3][3] = {{1, 1, 0}, {1, 0, 0}, {0, 1, 0}}; - if (n == 0) - return 0; - if (n == 1 || n == 2) - return 1; - return power(F, n - 2); -} -int gcd(int a, int b) -{ - if (b == 0) - return a; - return gcd(b, a % b); -} -int lcm(int a, int b) -{ - return (a * b / gcd(a, b)); -} -int prime(int n) -{ - int x = 2; - - while (x <= sqrt(n)) - { - if ((n % x) == 0) - { - - return x; - } - x++; - } - return -1; -} - -double codist(int x1, int y1, int x2, int y2) -{ - return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); -} -int NC2(int x) -{ - return max(x * (x - 1) / 2, 0); -} -int NC3(int x) -{ - return max(x * (x - 1) * (x - 2) / 6, 0); -} -void fact(int n, vector &v) -{ - for (int i = 1; i <= sqrt(n); i++) - { - if (n % i == 0) - { - v.pb(i); - v.pb(n / i); - } - } -} - -bool check(int k, int n, const vector> &op) -{ - int chec = -1; - for (int i = 0; i <= n - k; ++i) - { - int j = log2(k); - int o = op[i][j] | op[i + k - (1 << j)][j]; - if (chec == -1) - chec = o; - if (chec != o) - return false; - } - return true; -} - -void solve() -{ - int n; - cin >> n; - mii mp; - mii adj; - for (int i = 0; i < n - 1; i++) - { - int a, b; - cin >> a >> b; - mp[a]++; - mp[b]++; - adj[a] = b; - adj[b] = a; - } - priority_queue pq; - for (auto i : mp) - { - pq.push({i.second, i.first}); - } - - int x = pq.top().first; - int e1 = pq.top().second; - pq.pop(); - int y = pq.top().first; - int e2 = pq.top().second; - if (adj[e1] == e2) - cout << x + y - 2 << endl; - else - cout << x + y - 1 << endl; -} - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int T; - cin >> T; - // T=1; - while (T--) - { - solve(); - } - return 0; -} -","#include -// #include -// #include -// using namespace __gnu_pbds; - -using namespace std; - -// typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key -#define int long long -#define pb push_back -#define vi vector -#define loop(i, n1, n) for (int i = n1; i < n; i++) -#define revloop(i, n, n1) for (int i = n; i >= n1; i--) -#define endl ""\n"" -#define yes cout << ""YES"" << endl -#define no cout << ""NO"" << endl -#define sortv(v) sort(v.begin(), v.end()) -#define pii pair -#define vinp(v, n) \ - for (int i = 0; i < n; i++) \ - { \ - int k; \ - cin >> k; \ - v.pb(k); \ - } -#define mii map -// #define m 1e9+7 -#define nl cout << endl -#define vdebug(v) \ - for (auto i : v) \ - cout << i << "" ""; \ - nl - -#define vall(v) v.begin(), v.end() -#define vsort(v) sort(vall(v)) -#define print(v) cout << v << endl; -double pi = 2 * acos(0.0); -int max(int a, int b) -{ - if (a > b) - return a; - else - return b; -} -int min(int a, int b) -{ - if (a > b) - return b; - else - return a; -} -bool isPalindrome(string S) -{ - - string P = S; - - reverse(P.begin(), P.end()); - - if (S == P) - { - - return 1; - } - - else - { - - return 0; - } -} -// void build(vector v){ -// int n=v.size(); -// vector> s(n,vector(17)); -// for(int i=0;i &arr, int target) -{ - int left = 0, right = arr.size() - 1; - while (left <= right) - { - int mid = left + (right - left) / 2; - if (arr[mid] == target) - { - return mid; - } - else if (arr[mid] < target) - { - left = mid + 1; - } - else - { - right = mid - 1; - } - } - return -1; -} - -int RSB(int n) -{ - return log2(n & -n); -} - -int factorial(int b) -{ - if (b == 1 || b == 0) - return 1; - return (b)*factorial(b - 1); -} - -void multiply(int a[3][3], int b[3][3]) -{ - int mul[3][3]; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - mul[i][j] = 0; - for (int k = 0; k < 3; k++) - { - mul[i][j] += a[i][k] * b[k][j]; - } - } - } - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - a[i][j] = mul[i][j]; - } - } -} - -int power(int F[3][3], int n) -{ - int M[3][3] = {{1, 1, 0}, {1, 0, 0}, {0, 1, 0}}; - if (n == 1) - return F[0][0] + F[0][1]; - power(F, n / 2); - multiply(F, F); - if (n % 2 != 0) - multiply(F, M); - return F[0][0] + F[0][1]; -} - -int fibo(int n) -{ - --n; - int F[3][3] = {{1, 1, 0}, {1, 0, 0}, {0, 1, 0}}; - if (n == 0) - return 0; - if (n == 1 || n == 2) - return 1; - return power(F, n - 2); -} -int gcd(int a, int b) -{ - if (b == 0) - return a; - return gcd(b, a % b); -} -int lcm(int a, int b) -{ - return (a * b / gcd(a, b)); -} -int prime(int n) -{ - int x = 2; - - while (x <= sqrt(n)) - { - if ((n % x) == 0) - { - - return x; - } - x++; - } - return -1; -} - -double codist(int x1, int y1, int x2, int y2) -{ - return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); -} -int NC2(int x) -{ - return max(x * (x - 1) / 2, 0); -} -int NC3(int x) -{ - return max(x * (x - 1) * (x - 2) / 6, 0); -} -void fact(int n, vector &v) -{ - for (int i = 1; i <= sqrt(n); i++) - { - if (n % i == 0) - { - v.pb(i); - v.pb(n / i); - } - } -} - -bool check(int k, int n, const vector> &op) -{ - int chec = -1; - for (int i = 0; i <= n - k; ++i) - { - int j = log2(k); - int o = op[i][j] | op[i + k - (1 << j)][j]; - if (chec == -1) - chec = o; - if (chec != o) - return false; - } - return true; -} - -void solve() -{ - int n; - cin >> n; - vector g[n + 1]; - for (int i = 0; i < n - 1; i++) - { - int x, y; - cin >> x >> y; - g[x].pb(y); - g[y].pb(x); - } - int ans = 0, mx = 0, id; - for (int i = 1; i <= n; i++) - { - int sz = g[i].size(); - mx = max(mx, sz); - if (g[i].size() == mx) - id = i; - } - int cnt = 0; - for (int i = 1; i <= n; i++) - { - int sz = g[i].size(); - if (sz == mx) - cnt++; - } - if (cnt >= 3) - { - cout << 2 * mx - 1 << endl; - return; - } - ans += mx; - set se; - mx = 0; - for (auto x : g[id]) - se.insert(x); - for (int i = 1; i <= n; i++) - { - if (i == id) - continue; - int sz = g[i].size(); - if (se.find(i) != se.end()) - { - mx = max(mx, sz - 1); - } - else - mx = max(mx, sz); - } - - ans += (mx - 1); - cout << ans << endl; -} - -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(NULL); - int T; - cin >> T; - // T=1; - while (T--) - { - solve(); - } - return 0; -} -",2 -tarsh.16052003,2063C - Remove Exactly Two,c++20 ,304037961,304035679,"#include -#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef long double ld; -typedef vector> VI; -ll mod = 1e9 + 7; -const ll INF = 5e18; - -vi inputVector(int n) -{ - vi vec(n); - for (int i = 0; i < n; ++i) - { - cin >> vec[i]; - } - return vec; -} -vi inputVector2(int n) -{ - vi vec(n + 1); - for (int i = 1; i <= n; ++i) - { - cin >> vec[i]; - } - return vec; -} -VI input2D(ll n, ll m) -{ - VI vec(n, vi(m)); - for (int i = 0; i < n; i++) - { - for (int j = 0; j < m; j++) - { - cin >> vec[i][j]; - } - } - return vec; -} -ll power(ll x, ll y) -{ - ll res = 1; - while (y > 0) - { - if (y % 2 == 1) - res = ((res % mod) * (x % mod)) % mod; - - y = y >> 1; - x = ((x % mod) * (x % mod)) % mod; - } - return res % mod; -} -ll fn(ll node, set> &st, ll n, vi &in) -{ - ll ans = 0; - for (ll i = 1; i <= n; i++) - { - if (i == node) - { - continue; - } - if (st.find({node, i}) == st.end()) - { - ans = max(ans, 1 + in[node] - 1 + in[i] - 1); - } - else - { - ans = max(ans, 1 + in[node] - 1 + in[i] - 1 - 1); - } - } - return ans; -} -int main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - ll t; - cin >> t; - while (t--) - { - ll n; - cin >> n; - VI adj(n + 1); - vi in(n + 1, 0); - set> st; - for (ll i = 1; i < n; i++) - { - ll x, y; - cin >> x >> y; - // adj[x].push_back(y); - // adj[y].push_back(x); - st.insert({x, y}); - st.insert({y, x}); - in[x]++; - in[y]++; - } - ll maxi = 0, smaxi = 0; - ll n1 = 0, n2 = 0; - for (ll i = 1; i <= n; i++) - { - if (in[i] >= maxi) - { - n2 = n1; - smaxi = maxi; - maxi = in[i]; - n1 = i; - } - else if (in[i] > smaxi) - { - smaxi = in[i]; - n2 = i; - } - } - ll ans = fn(n1, st, n, in); - ans = max(ans, fn(n2, st, n, in)); - cout << ans << endl; - } -} -","#include -#include -using namespace std; -typedef long long ll; -typedef vector vi; -typedef long double ld; -typedef vector> VI; -ll mod = 1e9 + 7; -const ll INF = 5e18; - -vi inputVector(int n) -{ - vi vec(n); - for (int i = 0; i < n; ++i) - { - cin >> vec[i]; - } - return vec; -} -vi inputVector2(int n) -{ - vi vec(n + 1); - for (int i = 1; i <= n; ++i) - { - cin >> vec[i]; - } - return vec; -} -VI input2D(ll n, ll m) -{ - VI vec(n, vi(m)); - for (int i = 0; i < n; i++) - { - for (int j = 0; j < m; j++) - { - cin >> vec[i][j]; - } - } - return vec; -} -ll power(ll x, ll y) -{ - ll res = 1; - while (y > 0) - { - if (y % 2 == 1) - res = ((res % mod) * (x % mod)) % mod; - - y = y >> 1; - x = ((x % mod) * (x % mod)) % mod; - } - return res % mod; -} - -int main() -{ - ios::sync_with_stdio(false); - cin.tie(0); - cout.tie(0); - ll t; - cin >> t; - while (t--) - { - ll n; - cin >> n; - VI adj(n + 1); - vi in(n + 1, 0); - for (ll i = 1; i < n; i++) - { - ll x, y; - cin >> x >> y; - adj[x].push_back(y); - adj[y].push_back(x); - in[x]++; - in[y]++; - } - ll ans = 1, node = 0; - for (ll i = 1; i <= n; i++) - { - if (in[i] > in[node]) - { - node = i; - } - } - ans += in[node] - 1; - in[node] = 0; - for (auto it : adj[node]) - { - in[it]--; - } - node = 0; - for (ll i = 1; i <= n; i++) - { - if (in[i] > in[node]) - { - node = i; - } - } - ans += in[node] - 1; - cout << ans << endl; - } -} -",1 -WilliamFung,2063C - Remove Exactly Two,c++20 ,305000553,304970689,"#include -#define endl ""\n"" -#define all(a) a.begin(), a.end() -#define ll long long -#define ull unsigned long long -#define inf 0x7fffffff; -#define rep(i, l, r) for (int i = l; i <= r; ++i) -#define rrp(i, l, r) for (int i = l; i >= r; --i) -#define fucking_go(x) \ - int t; \ - cin >> t; \ - while (t--) \ - x() -using namespace std; -using vi = vector; -using vl = vector; -using vvi = vector>; -using vvl = vector>; -using vpii = vector>; -using vpll = vector>; -using pii = pair; -const ll mod = 1e9 + 7; -// const ll mod = 998244353; -const ll INF = 1e18; - -int n; -set g[200010]; -int a[200010]; -void solve() -{ - cin >> n; - for (int i = 1; i <= n; i++) g[i].clear(), a[i] = 0; - for (int i = 1; i <= n - 1; i++) - { - int u, v; - cin >> u >> v; - g[u].insert(v); - g[v].insert(u); - a[u]++; - a[v]++; - } - multiset st; - for (int i = 1; i <= n; i++) - { - st.insert(a[i]); - } - int ans = 0; - for (int i = 1; i <= n; i++) - { - int now = 0; - st.erase(st.find(a[i])); - for (int v : g[i]) - { - st.erase(st.find(a[v])); - st.insert(a[v] - 1); - } - now += a[i]; - now += (*st.rbegin()) - 1; - for (int v : g[i]) - { - st.erase(st.find(a[v] - 1)); - st.insert(a[v]); - } - st.insert(a[i]); - ans = max(ans, now); - } - cout << ans << endl; -} - -int main() -{ - std::ios::sync_with_stdio(false); - std::cin.tie(nullptr); - std::cout.tie(nullptr); - // helper(); - // init(); - fucking_go(solve); - // solve(); - - return 0; -}","#include -#define endl ""\n"" -#define all(a) a.begin(), a.end() -#define ll long long -#define ull unsigned long long -#define inf 0x7fffffff; -#define rep(i, l, r) for(int i = l; i <= r; ++i) -#define rrp(i, l, r) for(int i = l; i >= r; --i) -#define fucking_go(x) int t; cin >> t; while(t--) x() -using namespace std; -using vi = vector; -using vl = vector; -using vvi = vector >; -using vvl = vector >; -using vpii = vector >; -using vpll = vector >; -using pii = pair; -const ll mod = 1e9 + 7; -//const ll mod = 998244353; -const ll INF = 1e18; - -int n; -set g[200010]; -void solve() { - cin >> n; - for (int i = 1; i <= n; i++) g[i].clear(); - for (int i = 1; i <= n - 1; i++) { - int u, v; - cin >> u >> v; - g[u].insert(v); - g[v].insert(u); - } - // if (n == 2) { - // cout << 0 << endl; - // return; - // } - vi del(n + 1); - vi cnt(n + 1); - for (int i = 1; i <= n; i++) { - if (g[i].size() == 1) cnt[(*g[i].begin())]++; - } - int mx = -1, index = 0; - for (int i = 1; i <= n; i++) { - if (cnt[i] > mx) { - mx = cnt[i]; - index = i; - } - } - del[index] = 1; - vi tmp; - for (int x : g[index]) { - tmp.push_back(x); - } - for (int x : tmp) { - g[x].erase(index); - g[index].erase(x); - if (g[x].size() == 1) { - cnt[(*g[x].begin())]++; - } - } - mx = -1, index = 0; - for (int i = 1; i <= n; i++) { - if (del[i] == 0) { - if (cnt[i] > mx) { - mx = cnt[i]; - index = i; - } - } - } - if (mx == -1) { - for (int i = 1; i <= n; i++) { - if (del[i] == 0) { - del[i] = 1; - break; - } - } - } - else { - del[index] = 1; - tmp.clear(); - for (int x : g[index]) { - tmp.push_back(x); - } - for (int x : tmp) { - g[index].erase(x); - g[x].erase(index); - } - } - int ans = 0; - vi flag(n + 1); - queue q; - for (int i = 1; i <= n; i++) { - if (del[i] == 0) { - q.push(i); - ans++; - while (!q.empty()) { - int x = q.front(); - q.pop(); - del[x] = 1; - for (int y : g[x]) { - if (del[y] == 0) { - q.push(y); - } - } - } - } - } - cout << ans << endl; -} - -int main() { -std::ios::sync_with_stdio(false); -std::cin.tie(nullptr); -std::cout.tie(nullptr); -// helper(); -// init(); -fucking_go(solve); -//solve(); - -return 0; -}",1 -hungdt,2063C - Remove Exactly Two,c++17 ,304579818,304579150,"#include - -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--){ - int n; - cin >> n; - vector> edges; - int counting[200015]; // counting[i] denotes the number of edges that connects to edge i - bool adj[200015]; // adj[i] denotes whether node i is adjacent to the maxnode - for (int i=1; i<=n; i++){ // reset counting and adj - counting[i] = 0; - adj[i] = false; - } - vector> cnt; // counting, index - int dem = 1; // number of connected components - vector maxnode2; - - for (int i=1; i> x >> y; - edges.push_back({x,y}); - counting[x]++; - counting[y]++; - } - - for (int i=1; i<=n; i++) cnt.push_back({counting[i], i}); - sort(cnt.begin(),cnt.end()); - - int maxnode = cnt.back().second; - for (auto edge: edges){ - int x = edge.first; - int y = edge.second; - - if (x == maxnode || y == maxnode) adj[x + y - maxnode] = true; - } - - for (int i=cnt.size() - 2; i >= 0; i--){ - if (cnt[i].first == cnt[cnt.size() - 2].first) maxnode2.push_back(cnt[i].second); - } - - dem = cnt.back().first + counting[maxnode2[0]] - 1; - - if (cnt.back().first == counting[maxnode2[0]] && maxnode2.size() > 1) dem += 0; // more than 3 max nodes so ignore updates - else{ - bool check = false; // true = there is a node in maxnode2 that doesnt directly connect to maxnode - - for (auto x : maxnode2){ - if (adj[x] == false) check = true; - } - - if (!check) dem--; - } - - // clearing for next test case - cnt.clear(); - edges.clear(); - maxnode2.clear(); - - cout << dem << endl; - } - - return 0; -} -","#include - -using namespace std; - -int main() -{ - int t; - cin >> t; - while (t--){ - int n; - cin >> n; - vector> edges; - int counting[200015]; // counting[i] denotes the number of edges that connects to edge i - bool adj[200015]; // adj[i] denotes whether node i is adjacent to the maxnode - for (int i=1; i<=n; i++){ // reset counting and adj - counting[i] = 0; - adj[i] = false; - } - vector> cnt; // counting, index - int dem = 1; // number of connected components - vector maxnode2; - - for (int i=1; i> x >> y; - edges.push_back({x,y}); - counting[x]++; - counting[y]++; - } - - for (int i=1; i<=n; i++) cnt.push_back({counting[i], i}); - sort(cnt.begin(),cnt.end()); - - int maxnode = cnt.back().second; - for (auto edge: edges){ - int x = edge.first; - int y = edge.second; - - if (x == maxnode || y == maxnode) adj[x + y - maxnode] = true; - } - - for (int i=cnt.size() - 2; i >= 0; i--){ - if (cnt[i].first == cnt[cnt.size() - 2].first) maxnode2.push_back(cnt[i].second); - } - - dem = cnt.back().first + counting[maxnode2[0]] - 1; - - if (cnt.back().first == counting[maxnode2[0]] && maxnode2.size() > 1) continue; // more than 3 max nodes - else{ - bool check = false; // true = there is a node in maxnode2 that doesnt directly connect to maxnode - - for (auto x : maxnode2){ - if (adj[x] == false) check = true; - } - - if (!check) dem--; - } - - // clearing for next test case - cnt.clear(); - edges.clear(); - maxnode2.clear(); - - cout << dem << endl; - } - - return 0; -} -",1 -TheMaysan,2063C - Remove Exactly Two,c++20 ,306137884,306140827,"// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/problemset/problem/2063/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -#define NoTLE ios_base::sync_with_stdio(false);cin.tie(NULL); -#define ld long double -#define ll long long -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define nl '\n' -#define YES cout << ""YES"" -#define NO cout << ""NO"" -#define fx(i) fixed< > & tree ) -{ - vector < int > leafs ; - vector < int > dgr ( tree.size() + 1 ); - for ( auto el : tree ) - { - dgr[el.F] = el.S.size() ; - } - for ( int i = 1 ; i <= tree.size() ; i++ ) - { - if ( dgr[i] == 1 ) leafs.pb(i) ; - } - int ans = 2 ; - while ( leafs.size() > 0 ) - { - vector < int > new_leafs ; - for ( auto el : leafs ) - { - for ( auto nd : tree[el] ) - { - dgr[nd] -- ; - if ( dgr[nd] == 1 ) new_leafs.pb(nd) ; - } - } - leafs = new_leafs ; - if ( leafs.size() > 1 ) ans += 2 ; - else if ( leafs.size() == 1 ) ans += 1 ; - } - return leafs[0] ; -} - -void solve() -{ - int n ; cin >> n ; - map < int , vector < int > > tree ; - vector < int > dig ( n + 1 ) ; - int cur = 0 ; - int ma = 0 ; - for ( int i = 0 ; i < n - 1 ; i++ ) - { - int a , b ; cin >> a >> b ; - tree[a].pb(b) ; - tree[b].pb(a) ; - dig[a]++ ; - dig[b]++ ; - if ( ma < dig[a] ) - { - ma = dig[a] ; - cur = a ; - } - if ( ma < dig[b] ) - { - ma = dig[b] ; - cur = b ; - } - } - int tmp = center(tree) ; - if ( tmp == cur ) - { - for ( int i = 1 ; i <= n ; i++ ) - { - if ( dig[i] == ma && i != tmp ) - { - cur = i ; - } - } - } - - int ans = ma - 1 ; - for ( auto el : tree[cur] ) - { - dig[el]-- ; - } - int mn = 0 ; - for ( int i = 1 ; i <= n ; i++ ) - { - if ( i != cur ) - mn = max ( mn , dig[i] ) ; - } - ans += mn ; - cout << ans ; -} - -signed main() -{ - NoTLE - //freopen( ""input.txt"" , ""r"" , stdin ); - //freopen( ""output.txt"" , ""w"" , stdout ); - int T = 1; - cin >> T ; - //int X = T; - while( T-- ) - { - // int ctest = X-T ; - //noBrainer() ; - solve(); - cout << nl ; - } - return 0; -}","// Problem: C. Remove Exactly Two -// Contest: Codeforces - Codeforces Round 1000 (Div. 2) -// URL: https://codeforces.com/problemset/problem/2063/C -// Memory Limit: 256 MB -// Time Limit: 2000 ms -// -// Powered by CP Editor (https://cpeditor.org) - -#include - -#define NoTLE ios_base::sync_with_stdio(false);cin.tie(NULL); - -#define ld long double -#define ll long long -#define F first -#define S second -#define pb push_back -#define all(x) x.begin(),x.end() -#define nl '\n' -#define YES cout << ""YES"" -#define NO cout << ""NO"" -#define fx(i) fixed< > & tree , vector < int >& lvl ) -{ - vector < int > leafs ; - vector < int > dgr ( tree.size() + 1 ); - for ( auto el : tree ) - { - dgr[el.F] = el.S.size() ; - } - for ( int i = 1 ; i <= tree.size() ; i++ ) - { - if ( dgr[i] == 1 ) leafs.pb(i) , lvl[i] = 1 ; - } - int ans = 2 ; - while ( leafs.size() > 0 ) - { - - vector < int > new_leafs ; - for ( auto el : leafs ) - { - for ( auto nd : tree[el] ) - { - dgr[nd] -- ; - if ( dgr[nd] == 1 ) new_leafs.pb(nd) , lvl[nd] = lvl[el]+1 ; - } - } - leafs = new_leafs ; - if ( leafs.size() > 1 ) ans += 2 ; - else if ( leafs.size() == 1 ) ans += 1 ; - } -} - - -void solve() -{ - int n ; cin >> n; - map < int , vector < int > > tree ; - vector < int > dgr ( n + 1 ) ; - for ( int i = 1 ; i < n ; i++ ) - { - int a , b ; cin >> a >> b ; - tree[a].pb(b) ; - tree[b].pb(a) ; - dgr[a]++ ; - dgr[b]++ ; - } - - vector < int > lvl ( n + 1 ) ; - center( tree , lvl ) ; - - int mnl = 1e6 , mx = 0 ; - int del = 0 ; - for ( int i = 1 ; i <= n ; i++ ) - { - if ( dgr[i] > mx ) - { - mx = dgr[i] ; - mnl = lvl[i] ; - del = i ; - } - if ( dgr[i] == mx && mnl > lvl[i] ) - { - mx = dgr[i] ; - mnl = lvl[i] ; - del = i ; - } - } - int ans = mx - 1 ; - for ( auto el : tree[del] ) - { - dgr[el]-- ; - } - dgr[del] = 0 ; - int t = 0 ; - for ( int i = 1 ; i <= n ; i++ ) - { - t = max ( t , dgr[i] ) ; - } - cout << ans + t ; -} - -signed main() -{ - NoTLE - //freopen( ""input.txt"" , ""r"" , stdin ); - //freopen( ""output.txt"" , ""w"" , stdout ); - int T = 1; - cin >> T ; - //int X = T; - while( T-- ) - { - // int ctest = X-T ; - //noBrainer() ; - solve(); - cout << nl ; - } - return 0; -}",2 -an1ma,2063C - Remove Exactly Two,c++17 ,304311492,304307494,"#include -#include -using namespace std; -#ifndef InfernoStinger -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif -#define all(x) (x).begin() , (x).end() -#define ll long long -#define int long long -#define mod 1000000007 -#define mod1 998244353 -#define inf 1e18 -#define pb push_back -#define ppb pop_back -#define mp make_pair -#define ff first -#define ss second -void _print(int t) {cerr << t;} -void _print(string t) {cerr << t;} -void _print(char t) {cerr << t;} -void _print(long double t) {cerr << t;} -void _print(double t) {cerr << t;} -void _print(bool t) {cerr << t;} -void _print(unsigned long long t) {cerr << t;} -template bool ckmin(T&a, const T&b) { bool B = a > b; a = min(a,b); return B; } -template bool ckmax(T&a, const T&b) { bool B = a < b; a = max(a,b); return B; } -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -int solve() -{ - int n; - cin>>n; - vector> g(n+1); - vector deg(n+1, 0); - multiset curs; - for(int i=0;i>v>>u; - g[v].insert(u); - g[u].insert(v); - deg[u]++;deg[v]++; - } - for(int i=1;i<=n;i++){ - curs.insert(deg[i]); - } - int ans=0; - for(int i=1;i<=n;i++){ - int temp=deg[i]; - curs.erase(curs.find(deg[i])); - for(auto nei:g[i]){ - curs.erase(curs.find(deg[nei])); - curs.insert(deg[nei]-1); - } - ans=max(ans, temp+*curs.rbegin()); - for(auto nei:g[i]){ - curs.erase(curs.find(deg[nei]-1)); - curs.insert(deg[nei]); - } - curs.insert(temp); - } - cout<>t; - for(int tc=0;tc -#include -using namespace std; -#ifndef InfernoStinger -#define debug(x) cerr << #x <<"" ""; _print(x); cerr << endl; -#else -#define debug(x) -#endif -#define all(x) (x).begin() , (x).end() -#define ll long long -#define int long long -#define mod 1000000007 -#define mod1 998244353 -#define inf 1e18 -#define pb push_back -#define ppb pop_back -#define mp make_pair -#define ff first -#define ss second -void _print(int t) {cerr << t;} -void _print(string t) {cerr << t;} -void _print(char t) {cerr << t;} -void _print(long double t) {cerr << t;} -void _print(double t) {cerr << t;} -void _print(bool t) {cerr << t;} -void _print(unsigned long long t) {cerr << t;} -template bool ckmin(T&a, const T&b) { bool B = a > b; a = min(a,b); return B; } -template bool ckmax(T&a, const T&b) { bool B = a < b; a = max(a,b); return B; } -template void _print(pair p); -template void _print(vector v); -template void _print(set v); -template void _print(map v); -template void _print(multiset v); -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} - -int solve() -{ - int n; - cin>>n; - vector> g(n+1); - vector deg(n+1, 0); - set cur; - for(int i=1;i<=n;i++){ - cur.insert(i); - } - for(int i=0;i>v>>u; - g[v].insert(u); - g[u].insert(v); - deg[u]++;deg[v]++; - } - auto red = [&]() -> void { - int val=0; - for(auto i:cur){ - if(deg[i]>=deg[val]){ - val=i; - } - } - vector torem; - for(auto ver:g[val]){ - torem.pb(ver); - } - for(auto rem:torem){ - g[rem].erase(val); - g[val].erase(rem); - deg[rem]--;deg[val]--; - } - cur.erase(val); - }; - red(); - red(); - queue q; - vector vis(n+1, false); - int ans=0; - for(auto i:cur){ - if(vis[i]) continue; - q.push(i); - ans++; - while(q.size()){ - int node=q.front(); - q.pop(); - vis[node]=true; - for(auto ver:g[node]){ - if(!vis[ver]) q.push(ver); - } - } - } - cout<>t; - for(int tc=0;tc -#define FOR(i,j,k) for(int i=j, r##i=k; i<=r##i; ++i) -#define ROF(i,j,k) for(int i=j, l##i=k; i>=l##i; --i) -inline int read (void) { - int x = 0, f = 1, ch = getchar(); - while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); } - while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } - return x * f; -} -const int maxn = 200005; -int tot_edge, head[maxn], to[maxn<<1], link[maxn<<1]; -inline void add_edge (int x, int y) { - to[++tot_edge] = y; - link[tot_edge] = head[x]; - head[x] = tot_edge; -} -using pii = std::pair ; -int d[maxn]; -pii p[maxn]; -bool flag[maxn]; -int main (void) { - int t = read(); - while(t--) { - int n = read(); - FOR(i,2,n) { - int x = read(), y = read(); - add_edge (x, y); - add_edge (y, x); - ++ d[x], ++ d[y]; - } - FOR(i,1,n) p[i] = pii (d[i], i); - std::sort(p+1, p+n+1, std::greater()); - int c = -1 << 20, c2 = -1 << 20, uc = -1 << 20; - for(int now=head[p[1].second]; now; now=link[now]) - flag[to[now]] = 1; - FOR(i,2,n) - if(flag[p[i].second]) { - if(c == -1 << 20) c = p[i].first; - else if(c2 == -1 << 20) c2 = p[i].first; - } else - if(uc == -1 << 20) uc = p[i].first; - printf(""%d\n"", std::max (c + c2 - 1, std::max (p[1].first + c - 2, p[1].first + uc - 1))); - FOR(i,1,n) d[i] = flag[i] = head[i] = 0; - tot_edge = 0; - } - return 0; -} -","#include -#define FOR(i,j,k) for(int i=j, r##i=k; i<=r##i; ++i) -#define ROF(i,j,k) for(int i=j, l##i=k; i>=l##i; --i) -inline int read (void) { - int x = 0, f = 1, ch = getchar(); - while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); } - while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } - return x * f; -} -const int maxn = 200005; -int tot_edge, head[maxn], to[maxn], link[maxn]; -inline void add_edge (int x, int y) { - to[++tot_edge] = y; - link[tot_edge] = head[x]; - head[x] = tot_edge; -} -using pii = std::pair ; -int d[maxn]; -pii p[maxn]; -bool flag[maxn]; -int main (void) { - int t = read(); - while(t--) { - int n = read(); - FOR(i,2,n) { - int x = read(), y = read(); - add_edge (x, y); - add_edge (y, x); - ++ d[x], ++ d[y]; - } - FOR(i,1,n) p[i] = pii (d[i], i); - std::sort(p+1, p+n+1, std::greater()); - int c = -1 << 20, c2 = -1 << 20, uc = -1 << 20; - for(int now=head[p[1].second]; now; now=link[now]) - flag[to[now]] = 1; - FOR(i,2,n) - if(flag[p[i].second]) { - if(c == -1 << 20) c = p[i].first; - else if(c2 == -1 << 20) c2 = p[i].first; - } else - if(uc == -1 << 20) uc = p[i].first; - printf(""%d\n"", std::max (c + c2 - 1, std::max (p[1].first + c - 2, p[1].first + uc - 1))); - FOR(i,1,n) d[i] = flag[i] = 0; - } - return 0; -} -",1 -big_hongbao1,2063C - Remove Exactly Two,c++17 ,304583684,304582646,"#include -#define int long long -using namespace std; -const int N=2e5+5; -void solve(){ - int n; - cin>>n; - set > s; - map mp; - vector > vc; - for(int i=1;i<=n-1;i++){ - int u,v; - cin>>u>>v; - s.insert({u,v}); - s.insert({v,u}); - mp[u]++; - mp[v]++; - } - for(auto it:mp){ - vc.push_back({it.second,it.first}); - } - sort(vc.begin(),vc.end()); - int ans=0; - for(int i=n-1;vc[i].first>=vc[n-1].first&&i>=0;i--){ - for(int j=i-1;vc[j].first>=vc[i-1].first&&j>=0;j--){ - int temp=vc[i].first+vc[j].first; - //cout<>t; - while(t--){ - solve(); - } -}","#include -#define int long long -using namespace std; -const int N=2e5+5; -void solve(){ - int n; - cin>>n; - set > s; - map mp; - vector > vc; - for(int i=1;i<=n-1;i++){ - int u,v; - cin>>u>>v; - s.insert({u,v}); - s.insert({v,u}); - mp[u]++; - mp[v]++; - } - for(auto it:mp){ - vc.push_back({it.second,it.first}); - } - sort(vc.begin(),vc.end()); - int ans=0; - for(int i=n-1;vc[i].first>=vc[n-1].first&&i>=0;i--){ - for(int j=i-1;vc[j].first>=vc[i-1].first&&j>=0;j--){ - int temp=vc[i].first+vc[j].first; - //cout<>t; - while(t--){ - solve(); - } -}",1 -readyToFail,2063C - Remove Exactly Two,c++17 ,304372835,303755647,"#include -using namespace std; -#define F(i, s, e) for(int i = s; i < e; i++) -#define vi vector -#define pb push_back -#define int int_fast64_t -#define sp <<' '<< -#define pii pair -#define fi first -#define se second -#define line cout<<""---------------------------------\n""; - -const int inf = 1e15; -const int N = 2e5+5; -const int mod = 998244353; - -vi adj[N]; - -void solve() { - int n; - cin >> n; - F(i, 0, n) adj[i].clear(); - F(i, 0, n-1) { - int u, v; - cin >> u >> v; - u--, v--; - adj[u].pb(v); - adj[v].pb(u); - } - - multiset> cnt; - - F(i, 0, n) cnt.insert(adj[i].size()); - - int ans = 0; - F(i, 0, n) { - cnt.erase(cnt.find(adj[i].size())); - for(int nei : adj[i]) cnt.erase(cnt.find(adj[nei].size())), cnt.insert(adj[nei].size() - 1); - ans = max(ans, (int) adj[i].size() + *cnt.begin() - 1); - for(int nei : adj[i]) cnt.erase(cnt.find(adj[nei].size() - 1)), cnt.insert(adj[nei].size()); - cnt.insert(adj[i].size()); - } - - cout << ans << endl; -} - -int32_t main() { - #ifdef Local - freopen(""io.in"", ""r"", stdin); - freopen(""io.out"", ""w"", stdout); - #endif - - int t = 1; - cin >> t; - while(t--) solve(); -}","#include -using namespace std; -#define F(i, s, e) for(int i = s; i < e; i++) -#define int long long -#define vi vector -#define pb push_back -#define sp <<' '<< -#define endl '\n' -#define pii pair -#define fi first -#define se second - -const int inf = 1e15; -const int N = 1e5 + 5; - -vi adj[N]; -int dp[N][2][2]; -int p[N]; - -void dfs(int node, int par) { - p[node] = par; - int chsize = adj[node].size() - (node != 0); - dp[node][0][1] = chsize; - pii best1 = {-inf, -inf}, best2 = {-inf, -inf}; - for(int ch : adj[node]) if(ch != par) { - dfs(ch, node); - dp[node][0][0] = max(dp[node][0][0], max(dp[ch][0][0], dp[ch][0][1] + 1)); - - dp[node][1][1] = max(dp[node][1][1], chsize - 1 + max(dp[ch][0][0], dp[ch][0][1])); - - pii me = max(pii{dp[ch][0][0], 0}, pii{dp[ch][0][1], 1}); - if(best1.fi < 0) { - best1 = me; - } else { - if(best2.fi < 0) best2 = me; - else { - if(me > best2) { - best2 = me; - if(best2 > best1) swap(best1, best2); - } - } - } - } - if(best1.se == 1 && best2.se == 1) { - dp[node][1][0] = best1.fi + best2.fi + 1; - } else { - dp[node][1][0] = best1.fi + best2.fi; - } -} - -void solve() { - int n; - cin >> n; - - F(i, 0, n) adj[i].clear(); - F(i, 0, n) F(j, 0, 2) F(k, 0, 2) dp[i][j][k] = -inf; - - F(i, 0, n-1) { - int u, v; - cin >> u >> v; - u--, v--; - adj[u].pb(v); - adj[v].pb(u); - } - - dfs(0, 0); - - //F(i, 0, n) { - // F(j, 0, 2) F(k, 0, 2) cout << dp[i][j][k] << "" ""; - // cout << endl; - //} - - int ans = max(dp[0][1][0], dp[0][1][1]); - - cout << max(ans, 0ll) << endl; -} - -int32_t main() { - cin.tie(0); ios_base::sync_with_stdio(0); - #ifdef Local - - freopen(""io.in"", ""r"", stdin); - freopen(""io.out"", ""w"", stdout); - #endif - int t = 1; - cin >> t; - while(t--) solve(); -}",1 -1UnStAbLe1,2063C - Remove Exactly Two,c++17 ,307156446,307156737," -#include -using namespace std; - -#define int long long int -#define pi pair -#define all(n) n.begin(), n.end() -#define rall(n) n.begin(), n.end(), greater() -#define fr(i,a,b,c) for(int i=a;i=b;i-=c) -#define pb push_back -// Input Functions -templatestd::vector input(int n) {std::vector v(n);for (int i = 0; i < n; ++i) {std::cin >> v[i];}return v;} -templatestd::vector> input(int n) {std::vector> v;for (int i = 0; i < n; ++i) {A first;B second;std::cin >> first >> second;v.emplace_back(first, second);}return v;} -templatestd::vector> input(int n, int m) {std::vector> vv(n, std::vector(m));for (int i = 0; i < n; ++i) {for (int j = 0; j < m; ++j) {std::cin >> vv[i][j];}}return vv;} - - -// Debugging -templatevoid printContainer(const std::vector& v) {std::cout << ""Vector : "";std::cout << ""[ "";for (const T& value : v) {std::cout << value << "" "";}std::cout << ""]"" << std::endl;} -templatevoid printContainer(const std::vector>& v) {std::cout << ""Vector of Pairs: "";std::cout << ""[ "";for (const auto& p : v) {std::cout << ""("" << p.first << "", "" << p.second << "") "";}std::cout << ""]"" << std::endl;} -templatevoid printContainer(const std::vector>& vv) {std::cout << ""Vector of Vectors:"" << std::endl;for (const auto& row : vv) {for (const T& value : row) {std::cout << value << "" "";}std::cout << std::endl;}} -template void printContainer(const map& m) { std::cout << ""Map : "";cout << ""[""; for (auto it = m.begin(); it != m.end(); ++it) { if (it != m.begin()) cout << "", ""; cout << ""[""<first << ""->"" << it->second<<""]""; } cout << ""]""<void printContainer(const std::priority_queue& pq) {std::priority_queue temp = pq;std::cout << ""Priority Queue: "";while (!temp.empty()) {std::cout << temp.top() << "" "";temp.pop();}std::cout << std::endl;} -template void printContainer(stack stk) { cout << ""[""; while (!stk.empty()) { if (stk.size() != sz(stk)) cout << "", ""; cout << stk.top(); stk.pop(); } cout << ""]""; } -template void printContainer(const std::queue& q) {std::queue temp = q; std::cout << ""Queue: "";while (!temp.empty()) {std::cout << temp.front() << "" "";temp.pop();} std::cout << std::endl;} -templatevoid printContainer(const std::queue>& q) {std::queue> temp = q; std::cout << ""Queue of Pairs: "";while (!temp.empty()) {std::cout << ""("" << temp.front().first << "", "" << temp.front().second << "") "";temp.pop();}std::cout << std::endl;} -templatevoid printContainer(const std::stack>& s) {std::stack> temp = s; std::cout << ""Stack of Pairs: "";while (!temp.empty()) {std::cout << ""("" << temp.top().first << "", "" << temp.top().second << "") "";temp.pop();}std::cout << std::endl;} - -// Printing -templatevoid print(const std::vector& v) {for (const T& value : v) {std::cout << value << "" "";}std::cout << endl;} -templatevoid print(const std::vector>& vv) {for (const auto& row : vv) {for (const T& value : row) {std::cout << value << "" "";}std::cout << std::endl;}} - - -int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -vectorfactorial(int n,int m){vectorv(n);v[0]=1;for(int i=1;i=0;i--){cout<<((num>>i)&1);}} -int N = 1e6; -vector isPrime(N+1,1);void prime(){isPrime[0] = isPrime[1]=false;for(int i=2;i<=N;i++){if(isPrime[i]){for(int j=2*i;j<=N;j+=i){isPrime[j] = 0;}}}} -vectordivisor(int n){vectorres;for (int i=1; i<=sqrt(n); i++){if (n%i == 0){if (n/i == i) res.push_back(i);else{res.push_back(i);res.push_back(n/i);} }}return res;} -bool cmp(pair x, pair y){if (x.first != y.first)return x.first < y.first; else return x.second < y.second; } -int meraceil(int a,int b){if(a%b==0) return a/b;return (a/b)+1;} -int power(int x,int y,int p){int res=1;while(y>0){if(y&1)res = (res * x)%p;y = y >> 1;x = (x * x)%p;}return (res%p);} -vector primeDivisors(int val){vector res;if(val%2==0) res.pb(2);while(val%2==0){val/=2;}for(int j=3;j<=sqrt(val);j+=2){if(val%j==0) res.pb(j);while(val%j==0){val/=j;}}if(val>2) res.pb(val);return res;} - -//-------------------------CODE---------------------- -void Shiremonoga(){ - int n; - cin >> n; - set adj[n+1]; - fr(i,0,n-1,1){ - int u, v; - cin >> u >> v; - adj[u].insert(v); - adj[v].insert(u); - } - int mx = INT_MIN, mx2 = INT_MIN; - map> mp; - fr(i,1,n+1,1){ - int sz = adj[i].size(); - mp[sz].push_back(i); - if(sz >= mx){ - mx2 = mx, mx = sz; - } - else if(sz > mx2) mx2 = sz; - } - int ans = INT_MIN; - for(auto &mxNode : mp[mx]){ - for(auto &mxNode2 : mp[mx2]){ - if(mxNode2==mxNode) continue; - int curr = 0; - if(adj[mxNode].find(mxNode2) != adj[mxNode].end()){ - curr = mx2-2; - }else{ - curr = mx2-1; - } - ans = max(ans, mx+curr); - } - } - cout << ans << endl; - - } -signed main() -{ -ios_base::sync_with_stdio(false); -cin.tie(NULL); -cout.tie(NULL); - int t=1; - cin >> t; - while (t--) - { - Shiremonoga(); - } - return 0; -}"," -#include -using namespace std; - -#define int long long int -#define pi pair -#define all(n) n.begin(), n.end() -#define rall(n) n.begin(), n.end(), greater() -#define fr(i,a,b,c) for(int i=a;i=b;i-=c) -#define pb push_back -// Input Functions -templatestd::vector input(int n) {std::vector v(n);for (int i = 0; i < n; ++i) {std::cin >> v[i];}return v;} -templatestd::vector> input(int n) {std::vector> v;for (int i = 0; i < n; ++i) {A first;B second;std::cin >> first >> second;v.emplace_back(first, second);}return v;} -templatestd::vector> input(int n, int m) {std::vector> vv(n, std::vector(m));for (int i = 0; i < n; ++i) {for (int j = 0; j < m; ++j) {std::cin >> vv[i][j];}}return vv;} - - -// Debugging -templatevoid printContainer(const std::vector& v) {std::cout << ""Vector : "";std::cout << ""[ "";for (const T& value : v) {std::cout << value << "" "";}std::cout << ""]"" << std::endl;} -templatevoid printContainer(const std::vector>& v) {std::cout << ""Vector of Pairs: "";std::cout << ""[ "";for (const auto& p : v) {std::cout << ""("" << p.first << "", "" << p.second << "") "";}std::cout << ""]"" << std::endl;} -templatevoid printContainer(const std::vector>& vv) {std::cout << ""Vector of Vectors:"" << std::endl;for (const auto& row : vv) {for (const T& value : row) {std::cout << value << "" "";}std::cout << std::endl;}} -template void printContainer(const map& m) { std::cout << ""Map : "";cout << ""[""; for (auto it = m.begin(); it != m.end(); ++it) { if (it != m.begin()) cout << "", ""; cout << ""[""<first << ""->"" << it->second<<""]""; } cout << ""]""<void printContainer(const std::priority_queue& pq) {std::priority_queue temp = pq;std::cout << ""Priority Queue: "";while (!temp.empty()) {std::cout << temp.top() << "" "";temp.pop();}std::cout << std::endl;} -template void printContainer(stack stk) { cout << ""[""; while (!stk.empty()) { if (stk.size() != sz(stk)) cout << "", ""; cout << stk.top(); stk.pop(); } cout << ""]""; } -template void printContainer(const std::queue& q) {std::queue temp = q; std::cout << ""Queue: "";while (!temp.empty()) {std::cout << temp.front() << "" "";temp.pop();} std::cout << std::endl;} -templatevoid printContainer(const std::queue>& q) {std::queue> temp = q; std::cout << ""Queue of Pairs: "";while (!temp.empty()) {std::cout << ""("" << temp.front().first << "", "" << temp.front().second << "") "";temp.pop();}std::cout << std::endl;} -templatevoid printContainer(const std::stack>& s) {std::stack> temp = s; std::cout << ""Stack of Pairs: "";while (!temp.empty()) {std::cout << ""("" << temp.top().first << "", "" << temp.top().second << "") "";temp.pop();}std::cout << std::endl;} - -// Printing -templatevoid print(const std::vector& v) {for (const T& value : v) {std::cout << value << "" "";}std::cout << endl;} -templatevoid print(const std::vector>& vv) {for (const auto& row : vv) {for (const T& value : row) {std::cout << value << "" "";}std::cout << std::endl;}} - - -int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} -vectorfactorial(int n,int m){vectorv(n);v[0]=1;for(int i=1;i=0;i--){cout<<((num>>i)&1);}} -int N = 1e6; -vector isPrime(N+1,1);void prime(){isPrime[0] = isPrime[1]=false;for(int i=2;i<=N;i++){if(isPrime[i]){for(int j=2*i;j<=N;j+=i){isPrime[j] = 0;}}}} -vectordivisor(int n){vectorres;for (int i=1; i<=sqrt(n); i++){if (n%i == 0){if (n/i == i) res.push_back(i);else{res.push_back(i);res.push_back(n/i);} }}return res;} -bool cmp(pair x, pair y){if (x.first != y.first)return x.first < y.first; else return x.second < y.second; } -int meraceil(int a,int b){if(a%b==0) return a/b;return (a/b)+1;} -int power(int x,int y,int p){int res=1;while(y>0){if(y&1)res = (res * x)%p;y = y >> 1;x = (x * x)%p;}return (res%p);} -vector primeDivisors(int val){vector res;if(val%2==0) res.pb(2);while(val%2==0){val/=2;}for(int j=3;j<=sqrt(val);j+=2){if(val%j==0) res.pb(j);while(val%j==0){val/=j;}}if(val>2) res.pb(val);return res;} - -//-------------------------CODE---------------------- -void Shiremonoga(){ - int n; - cin >> n; - set adj[n+1]; - fr(i,0,n-1,1){ - int u, v; - cin >> u >> v; - adj[u].insert(v); - adj[v].insert(u); - } - int mx = INT_MIN, mx2 = INT_MIN; - map> mp; - fr(i,1,n+1,1){ - int sz = adj[i].size(); - mp[sz].push_back(i); - if(sz >= mx){ - mx2 = mx, mx = sz; - } - else if(sz > mx2) mx2 = sz; - } - int ans = INT_MIN; - for(auto &mxNode : mp[mx]){ - bool chk = false; - for(auto &mxNode2 : mp[mx2]){ - if(mxNode2==mxNode) continue; - int curr = 0; - if(adj[mxNode].find(mxNode2) != adj[mxNode].end()){ - curr = mx2-2; - ans = max(ans, mx+curr); - }else{ - curr = mx2-1; - ans = max(ans, mx+curr); - chk = true; - break; - } - } - if(chk) break; - } - cout << ans << endl; - - } -signed main() -{ -ios_base::sync_with_stdio(false); -cin.tie(NULL); -cout.tie(NULL); - int t=1; - cin >> t; - while (t--) - { - Shiremonoga(); - } - return 0; -}",2 -yuvraj357,2063C - Remove Exactly Two,c++17 ,303778143,303927288,"#include -#define all(s) s.begin(), s.end() -using namespace std; -using ll = long long; -using ull = unsigned long long; -const int _N = 1e5 + 5; -ll n; - -void check(ll v, vector> &adj){ - for(ll i=1; i> &adj, vector &vis){ - vis[node]=1; - for(auto i: adj[node]){ - if(vis[i]) continue; - dfs(i,adj,vis); - } -} - -int main(){ - int t; - cin>>t; - while(t--){ - cin>>n; - ll ans1,ans2; - ll maxi=0; - vector> adj(n+1); - set> st; - for(ll i=0; i>u>>v; - st.insert({u,v}); - adj[u].insert(v); - adj[v].insert(u); - } - - for(ll i=1; i<=n; i++){ - if(adj[i].size()>maxi){ - maxi=adj[i].size(); - } - } - - vector v; - for(ll i=1; i<=n; i++){ - if(adj[i].size()==maxi) v.push_back(i); - } - - if(v.size()>2){ - ll x=v[0],y=v[1],z=v[2]; - if(st.find({x,y})==st.end()){ - ans1=x; - ans2=y; - } - if(st.find({y,z})==st.end()){ - ans1=y; - ans2=z; - } - if(st.find({x,z})==st.end()){ - ans1=x; - ans2=z; - } - check(ans1,adj); - check(ans2,adj); - } - if(v.size()==2){ - ans1=v[0],ans2=v[1]; - check(ans1,adj); - check(ans2,adj); - } - if(v.size()==1){ - ans1=v[0]; - check(ans1,adj); - maxi=0; - for(ll i=1; i<=n; i++){ - if(i==ans1) continue; - if(adj[i].size()>maxi){ - maxi=adj[i].size(); - } - } - for(ll i=1; i<=n; i++){ - if(adj[i].size()==maxi) ans2=i; - } - check(ans2,adj); - } - - ll ans=0; - vector vis(n+1,0); - vis[ans1]=1; - vis[ans2]=1; - for(ll i=1; i<=n; i++){ - if(!vis[i]){ - dfs(i,adj,vis); - ans++; - } - } - - cout< -#define all(s) s.begin(), s.end() -using namespace std; -using ll = long long; -using ull = unsigned long long; -const int _N = 1e5 + 5; -ll n; - -void check(ll v, vector> &adj){ - for(ll i=1; i> &adj, vector &vis){ - vis[node]=1; - for(auto i: adj[node]){ - if(vis[i]) continue; - dfs(i,adj,vis); - } -} - -int main(){ - int t; - cin>>t; - while(t--){ - cin>>n; - ll ans1,ans2; - ll maxi=0; - vector> adj(n+1); - set> st; - for(ll i=0; i>u>>v; - st.insert({u,v}); - adj[u].insert(v); - adj[v].insert(u); - } - - for(ll i=1; i<=n; i++){ - if(adj[i].size()>maxi){ - maxi=adj[i].size(); - } - } - - vector v; - for(ll i=1; i<=n; i++){ - if(adj[i].size()==maxi) v.push_back(i); - } - - if(v.size()>2){ - ll x=v[0],y=v[1],z=v[2]; - if(st.find({x,y})==st.end() && st.find({y,x})==st.end()){ - ans1=x; - ans2=y; - } - if(st.find({y,z})==st.end() && st.find({z,y})==st.end()){ - ans1=y; - ans2=z; - } - if(st.find({x,z})==st.end() && st.find({z,x})==st.end()){ - ans1=x; - ans2=z; - } - } - else if(v.size()==2){ - ans1=v[0],ans2=v[1]; - } - else{ - ans1=v[0]; - check(ans1,adj); - maxi=0; - vector temp; - for(ll i=1; i<=n; i++){ - if(i==ans1) continue; - if(adj[i].size()>=maxi){ - maxi=adj[i].size(); - } - } - for(ll i=1; i<=n; i++){ - if(adj[i].size()==maxi && i!=ans1) temp.push_back(i); - } - ans2=temp[0]; - for(ll i=0; i vis(n+1,0); - vis[ans1]=1; - vis[ans2]=1; - for(ll i=1; i<=n; i++){ - if(!vis[i]){ - dfs(i,adj,vis); - ans++; - } - } - - cout< -using namespace std; -using i64=long long; -using u64=unsigned long long; -#define ll long long -const int inf=1e9; -const ll inff=1e18; -using i128=__int128; - -void solve() { - int n; - cin>>n; - vector deg(n); - vector> adj(n); - for(int i=0;i>x>>y; - x--,y--; - deg[x]++,deg[y]++; - adj[x].emplace_back(y); - adj[y].emplace_back(x); - } - auto cmp=[&](int x,int y){ - return deg[x],decltype(cmp)> pq(cmp); - for(int i=0;i>t; - while(t--){ - solve(); - } - return 0; -}","#include -using namespace std; -using i64=long long; -using u64=unsigned long long; -#define ll long long -const int inf=1e9; -const ll inff=1e18; -using i128=__int128; - -void solve() { - int n; - cin>>n; - vector deg(n); - vector> adj(n); - for(int i=0;i>x>>y; - x--,y--; - deg[x]++,deg[y]++; - adj[x].emplace_back(y); - adj[y].emplace_back(x); - } - vector it(n); - iota(it.begin(),it.end(),0); - sort(it.begin(),it.end(),[&](int x,int y){ - return deg[x]>deg[y]; - }); - if(n==2){ - cout<<0<<'\n'; - return; - } - int a=it[0],b=it[1],c=it[2]; - if(deg[a]==deg[b] && deg[b]==deg[c]){ - cout<deg[y]; - }); - cout< st(cmp); - // for(int i=0;i>t; - while(t--){ - solve(); - } - return 0; -}",2 -hsb757,2063C - Remove Exactly Two,c++17 ,304266343,304265610,"#include -#include -#include - -using namespace std; -using namespace chrono; - -using namespace __gnu_pbds; - - -template -using orderedSet = tree, rb_tree_tag, tree_order_statistics_node_update>; -template -using orderedMultiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// find_by_order(k) -> iterator at k -// order_of_key(k) -> number of items that are strictly smaller than k - - -#define FASTIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD1 1000000007 -#define MOD9 998244353 -#define INF 1e9 -#define INF1 1e18 -#define endl ""\n"" -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define lb lower_bound -#define ub upper_bound -#define fcout cout< vi; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector > vvi; -typedef vector vpii; -typedef vector vpll; -template using PQ = priority_queue; -template using QP = priority_queue, greater>; -// ---------------------------------------------------------------------------------- - -// ---------------------------------- OPERATOR OVERLOADING --------------------------------------- -template -istream& operator>>(istream &istream, vector &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &x : v) cout << x << "" ""; return ostream; } -template -istream& operator>>(istream &istream, pair &p) { return (istream >> p.ff >> p.ss); } -template -ostream& operator<<(ostream &ostream, const pair &p) { return (ostream << p.ff << "" "" << p.ss); } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -// ------------------------------------------------------------------------------------------------ - - -// ------------------------------------------ DEBUG ------------------------------------------------ -#ifndef ONLINE_JUDGE -#define debug(x...) cerr <<__func__<<"":""<<__LINE__<<"" ["" << #x << ""] = ""; _print(x); cerr << endl; -#define HERE cerr <<__func__<<"":""<<__LINE__<<"" [ here ] ""; cerr << endl; -#else -#define debug(x...) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(vector > v) {cerr << ""{ ""; for (vector i : v) {cerr << ""[ ""; for (T j : i) {_print(j); cerr << "" "";}; cerr << ""] "";} cerr << ""}"";} -template void _print(vector < pair > vp) {cerr << ""{ ""; for (pair i : vp) {cerr << ""[ ""; ""{""; _print(i.ff); cerr << "",""; _print(i.ss); cerr << "" ] "";} cerr << ""}"";} -template void _print(stack st) {cerr << ""[ ""; while (!st.empty()) {_print(st.top()); st.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(queue q) {cerr << ""[ ""; while (!q.empty()) {_print(q.front()); q.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(deque dq) {cerr << ""[ ""; while (!dq.empty()) {_print(dq.front()); dq.pop_front(); cerr << "" "";} cerr << ""]"";} -template void _print(PQ pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(QP pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -//--------------------------------------------------------------------------------------------------- - - -void solve() { - - //solution starts from here - int n; - cin>>n; - - vvi adj(n); - vi deg(n); - - for (int i = 0; i < n-1; ++i) - { - int u,v; - cin>>u>>v; - u--,v--; - adj[u].pb(v); - adj[v].pb(u); - deg[u]++; - deg[v]++; - } - - set st; - for(int i=0;i> t; - int T = t; - while (t--) - { - #ifndef ONLINE_JUDGE - cerr<<""Test ""<<(T-t)<<"" :""<(stop1 - start1); -#ifndef ONLINE_JUDGE - cerr << ""Time elapsed : "" << (duration . count() / 1000000) << '.' << (duration . count() % 1000000) << endl; -#endif - -}","#include -#include -#include - -using namespace std; -using namespace chrono; - -using namespace __gnu_pbds; - - -template -using orderedSet = tree, rb_tree_tag, tree_order_statistics_node_update>; -template -using orderedMultiset = tree, rb_tree_tag, tree_order_statistics_node_update>; -// find_by_order(k) -> iterator at k -// order_of_key(k) -> number of items that are strictly smaller than k - - -#define FASTIO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) -#define MOD1 1000000007 -#define MOD9 998244353 -#define INF 1e9 -#define INF1 1e18 -#define endl ""\n"" -#define pb push_back -#define ppb pop_back -#define ff first -#define ss second -#define PI 3.141592653589793238462 -#define set_bits __builtin_popcountll -#define all(x) (x).begin(), (x).end() -#define lb lower_bound -#define ub upper_bound -#define fcout cout< vi; -typedef vector vll; -typedef pair pii; -typedef pair pll; -typedef vector > vvi; -typedef vector vpii; -typedef vector vpll; -template using PQ = priority_queue; -template using QP = priority_queue, greater>; -// ---------------------------------------------------------------------------------- - -// ---------------------------------- OPERATOR OVERLOADING --------------------------------------- -template -istream& operator>>(istream &istream, vector &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector &v) { for (auto &x : v) cout << x << "" ""; return ostream; } -template -istream& operator>>(istream &istream, pair &p) { return (istream >> p.ff >> p.ss); } -template -ostream& operator<<(ostream &ostream, const pair &p) { return (ostream << p.ff << "" "" << p.ss); } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -template -istream& operator>>(istream &istream, vector> &v) {for (auto &x : v)cin >> x; return istream;} -template -ostream& operator<<(ostream &ostream, const vector> &v) { for (auto &x : v) cout << x << endl; return ostream; } -// ------------------------------------------------------------------------------------------------ - - -// ------------------------------------------ DEBUG ------------------------------------------------ -#ifndef ONLINE_JUDGE -#define debug(x...) cerr <<__func__<<"":""<<__LINE__<<"" ["" << #x << ""] = ""; _print(x); cerr << endl; -#define HERE cerr <<__func__<<"":""<<__LINE__<<"" [ here ] ""; cerr << endl; -#else -#define debug(x...) -#endif - -void _print(ll t) {cerr << t;} -void _print(int 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;} - -template void _print(pair p) {cerr << ""{""; _print(p.ff); cerr << "",""; _print(p.ss); cerr << ""}"";} -template void _print(vector v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(set v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(multiset v) {cerr << ""[ ""; for (T i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(map v) {cerr << ""[ ""; for (auto i : v) {_print(i); cerr << "" "";} cerr << ""]"";} -template void _print(vector > v) {cerr << ""{ ""; for (vector i : v) {cerr << ""[ ""; for (T j : i) {_print(j); cerr << "" "";}; cerr << ""] "";} cerr << ""}"";} -template void _print(vector < pair > vp) {cerr << ""{ ""; for (pair i : vp) {cerr << ""[ ""; ""{""; _print(i.ff); cerr << "",""; _print(i.ss); cerr << "" ] "";} cerr << ""}"";} -template void _print(stack st) {cerr << ""[ ""; while (!st.empty()) {_print(st.top()); st.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(queue q) {cerr << ""[ ""; while (!q.empty()) {_print(q.front()); q.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(deque dq) {cerr << ""[ ""; while (!dq.empty()) {_print(dq.front()); dq.pop_front(); cerr << "" "";} cerr << ""]"";} -template void _print(PQ pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -template void _print(QP pq) {cerr << ""[ ""; while (!pq.empty()) {_print(pq.top()); pq.pop(); cerr << "" "";} cerr << ""]"";} -//--------------------------------------------------------------------------------------------------- - - -void solve() { - - //solution starts from here - int n; - cin>>n; - - vvi adj(n); - vi deg(n); - - for (int i = 0; i < n-1; ++i) - { - int u,v; - cin>>u>>v; - u--,v--; - adj[u].pb(v); - adj[v].pb(u); - deg[u]++; - deg[v]++; - } - - set st; - for(int i=0;i temp = st; - int ans = 0; - for (int i = 0; i < n; ++i) - { - st = temp; - int first = deg[i]; - st.erase({deg[i],i}); - vpii store; - for(auto child : adj[i]) { - st.erase({deg[child],child}); - st.insert({deg[child] -1,child}); - } - store.pb({deg[i], i}); - debug(st) - int second = (*prev(st.end())).ff; - ans = max(ans,first + second -1); - } - cout<> t; - int T = t; - while (t--) - { - #ifndef ONLINE_JUDGE - cerr<<""Test ""<<(T-t)<<"" :""<(stop1 - start1); -#ifndef ONLINE_JUDGE - cerr << ""Time elapsed : "" << (duration . count() / 1000000) << '.' << (duration . count() % 1000000) << endl; -#endif - -}",1 -Poimidorka#,2063C - Remove Exactly Two,c++20 ,304666796,304667490,"#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef long long ll; - -#define x first -#define y second -#define int long long - -const int MAXN = 2e5 + 100; -vector g[MAXN]; - -int power[MAXN]; -int used[MAXN]; - -void solve() { - int n; - cin >> n; - for (int i = 0; i < n; i++) { - g[i].clear(); - power[i] = 0; - } - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - u--; - v--; - g[u].push_back(v); - g[v].push_back(u); - } - set> s; - for (int i = 0; i < n; i++) { - power[i] = g[i].size(); - s.insert({power[i], i}); - } - int ans = 0; - for (int i = 0; i < n; i++) { - for (int u : g[i]) { - s.erase({-power[u], u}); - power[u]--; - s.insert({-power[u], u}); - } - s.erase({-power[i], i}); - ans = max(ans, power[i] + -(s.begin()->x) - 1); - s.insert({power[i], i}); - for (int u : g[i]) { - s.erase({-power[u], u}); - power[u]++; - s.insert({-power[u], u}); - } - } - cout << ans << '\n'; -} - -signed main() { - ios ::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef long long ll; - -#define x first -#define y second -#define int long long - -const int MAXN = 2e5 + 100; -vector g[MAXN]; - -int power[MAXN]; -int used[MAXN]; - -void solve() { - int n; - cin >> n; - for (int i = 0; i < n; i++) { - g[i].clear(); - power[i] = 0; - } - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - u--; - v--; - g[u].push_back(v); - g[v].push_back(u); - } - set> s; - for (int i = 0; i < n; i++) { - power[i] = g[i].size(); - s.insert({power[i], i}); - } - int ans = 0; - for (int i = 0; i < n; i++) { - for (int u : g[i]) { - s.erase({-power[u], u}); - power[u]--; - s.insert({-power[u], u}); - } - s.erase({-power[i], i}); - ans = max(ans, power[i] + -(s.begin()->x) - 1); - s.insert({-power[i], i}); - for (int u : g[i]) { - s.erase({-power[u], u}); - power[u]++; - s.insert({-power[u], u}); - } - } - cout << ans << '\n'; -} - -signed main() { - ios ::sync_with_stdio(false); - cin.tie(0); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",2 -HelloFromMars#,2063C - Remove Exactly Two,c++17 ,304307634,304312850,"#include -#include -#include -#include -using namespace std; -typedef long long ll; -vector> g; -vector vis; -void dfs (int v) { - vis[v] = 1; - for (int u : g[v]) { - if (!vis[u]) dfs(u); - } -} -void solve() { - int n; cin >> n; - g = vector> (n); - for (int i = 1; i < n; i++) { - int u, v; cin >> u >> v; - g[--u].insert(--v), g[v].insert(u); - } - vector> cnt; - for (int i = 0; i < n; i++) cnt.push_back({g[i].size(), i}); - sort(cnt.rbegin(), cnt.rend()); - int del = cnt.begin()->second; - for (int x : g[del]) { - g[x].erase(del); - } - g[del].clear(); - cnt.clear(); - for (int i = 0; i < n; i++) { - if (i == del) continue; - cnt.push_back({g[i].size(), i}); - } - sort(cnt.rbegin(), cnt.rend()); - int del2 = cnt.begin()->second; - for (int x : g[del2]) { - g[x].erase(del2); - } - g[del2].clear(); - int ans = 0; - vis = vector (n); - for (int i = 0; i < n; i++) { - if (!vis[i] and i != del and i != del2) ans++, dfs(i); - } - cout << ans << '\n'; -} -int main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - int t = 1; cin >> t; - while (t--) solve(); - -} - - -","#include -#include -#include -using namespace std; -typedef long long ll; -void solve() { - int n; cin >> n; - vector> g(n); - for (int i = 1; i < n; i++) { - int u, v; cin >> u >> v; - g[--u].insert(--v), g[v].insert(u); - } - multiset> s; - for (auto x : g) s.insert(x.size()); - int ans = 0; - for (int i = 0; i < n; i++) { - for (int j : g[i]) ans = max(ans, (int)g[i].size() + (int)g[j].size() - 2); - } - for (int i = 0; i < n; i++) { - s.erase(s.find(g[i].size())); - for (int j : g[i]) s.erase(s.find(g[j].size())); - if (s.size()) { - ans = max(ans, (int)g[i].size() + *s.begin() - 1); - } - for (int j : g[i]) s.insert(g[j].size()); - s.insert(g[i].size()); - } - cout << ans << '\n'; -} -int main() { - ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); - int t = 1; cin >> t; - while (t--) solve(); - -} - - -",2 -amanjaiswal,2063C - Remove Exactly Two,c++20 ,303941800,303939763,"#include -using namespace std; -using ll = long long; - -void solve() { - int n; - cin >> n; - vector> graph(n + 1); - vector degree(n + 1, 0); - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - graph[u].push_back(v); - graph[v].push_back(u); - degree[u]++; - degree[v]++; - } - for (int u = 1; u <= n; u++) - sort(graph[u].begin(), graph[u].end()); - vector> L; - L.reserve(n); - for (int u = 1; u <= n; u++) - L.push_back({degree[u], u}); - sort(L.rbegin(), L.rend()); - ll best_nonadj = -1; - for (int u = 1; u <= n; u++) { - ll candidate = -1; - for (auto &p : L) { - int v = p.second; - if (v == u) continue; - if (binary_search(graph[u].begin(), graph[u].end(), v)) continue; - candidate = (ll)degree[u] + degree[v] - 1; - break; - } - best_nonadj = max(best_nonadj, candidate); - } - ll best_adj = -1; - for (int u = 1; u <= n; u++) { - for (int v : graph[u]) - if (v > u) - best_adj = max(best_adj, (ll)degree[u] + degree[v] - 2); - } - ll ans = max(best_nonadj, best_adj); - cout << ans << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -} -","#include -using namespace std; -using ll = long long; - -void solve() { - int n; - cin >> n; - - vector> graph(n + 1); - vector degree(n + 1, 0); - - for (int i = 0; i < n - 1; i++) { - int u, v; - cin >> u >> v; - graph[u].push_back(v); - graph[v].push_back(u); - - degree[u]++; - degree[v]++; - } - - vector> candidates; - for (int i = 1; i <= n; i++) - candidates.push_back({degree[i], i}); - - sort(candidates.rbegin(), candidates.rend()); - - int k = min(n, 200); - vector> topcans(candidates.begin(), candidates.begin() + k); - - vector> neighbors(k); - for (int i = 0; i < k; i++) { - int v = topcans[i].second; - for (int neighbor : graph[v]) - neighbors[i].insert(neighbor); - } - - ll best = 0; - for (int i = 0; i < k; i++) { - for (int j = i + 1; j < k; j++) { - int u = topcans[i].second; - int v = topcans[j].second; - - bool adj = (neighbors[i].find(v) != neighbors[i].end()); - ll current = degree[u] + degree[v] - 1 - (adj ? 1 : 0); - - best = max(best, current); - } - } - - cout << best << '\n'; -} - -int main() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - int t; - cin >> t; - while (t--) { - solve(); - } - return 0; -}",1 -sheenji,2063C - Remove Exactly Two,c++17 ,304033105,304032781,"// -// Created by Jiwon Sheen on 2025-02-02 -// -#include -#include -#include - -using namespace std; - -inline void fastIo() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - -using pii = pair; - -int main() { - int t; - int n; - int ans; - vector> v; - vector de, de2; - vector chk; - priority_queue pq; - - fastIo(); - - cin >> t; - - while (t--) { - cin >> n; - - ans = 1; - v.assign(n + 1, vector()); - de.assign(n + 1, 0); - de2.assign(n + 1, 0); - chk.assign(n + 1, false); - - for (int i = 0; i < n - 1; i++) { - int a, b; - cin >> a >> b; - de[a]++, de[b]++; - de2[a]++, de2[b]++; - v[a].push_back(b); - v[b].push_back(a); - } - - - for (int i = 1; i <= n; i++) - pq.emplace(de[i], i); - - for (int k = 0; k < 2; k++) { - while (pq.top().first != de[pq.top().second]) - pq.pop(); - auto [cd, idx] = pq.top(); - pq.pop(); - chk[idx] = true; - - ans += cd - 1; - for (const auto &nxt: v[idx]) { - if (!chk[nxt]) - pq.emplace(--de[nxt], nxt); - } - } - - while (!pq.empty()) - pq.pop(); - - if (n >= 3) { - int ans2 = 1; - - for (int i = 1; i <= n; i++) - pq.emplace(de2[i], i); - - chk.assign(n + 1, false); - chk[pq.top().second] = true; - pq.pop(); - - for (int k = 0; k < 2; k++) { - while (pq.top().first != de2[pq.top().second]) - pq.pop(); - auto [cd, idx] = pq.top(); - pq.pop(); - chk[idx] = true; - - ans2 += cd - 1; - for (const auto &nxt: v[idx]) { - if (!chk[nxt]) - pq.emplace(--de2[nxt], nxt); - } - } - ans = max(ans, ans2); - - while (!pq.empty()) - pq.pop(); - } - - cout << ans << '\n'; - } - - return 0; -} -","// -// Created by Jiwon Sheen on 2025-02-02 -// -#include -#include -#include - -using namespace std; - -inline void fastIo() { - ios::sync_with_stdio(false); - cin.tie(nullptr); - cout.tie(nullptr); -} - -using pii = pair; - -int main() { - int t; - int n; - int ans; - vector> v; - vector de, de2; - vector chk; - priority_queue pq; - - fastIo(); - - cin >> t; - - while (t--) { - cin >> n; - - ans = 1; - v.assign(n + 1, vector()); - de.assign(n + 1, 0); - de2.assign(n + 1, 0); - chk.assign(n + 1, false); - - for (int i = 0; i < n - 1; i++) { - int a, b; - cin >> a >> b; - de[a]++, de[b]++; - de2[a]++, de2[b]++; - v[a].push_back(b); - v[b].push_back(a); - } - - - for (int i = 1; i <= n; i++) - pq.emplace(de[i], i); - - for (int k = 0; k < 2; k++) { - while (pq.top().first != de[pq.top().second]) - pq.pop(); - auto [cd, idx] = pq.top(); - pq.pop(); - chk[idx] = true; - - ans += cd - 1; - for (const auto &nxt: v[idx]) { - if (!chk[nxt]) - pq.emplace(--de[nxt], nxt); - } - } - - while (!pq.empty()) - pq.pop(); - - if (n >= 3) { - int ans2 = 1; - - for (int i = 1; i <= n; i++) - pq.emplace(de2[i], i); - - chk.assign(n + 1, false); - chk[pq.top().second] = true; - pq.pop(); - - for (int k = 0; k < 2; k++) { - while (pq.top().first != de2[pq.top().second]) - pq.pop(); - auto [cd, idx] = pq.top(); - pq.pop(); - chk[idx] = true; - - ans2 += cd - 1; - for (const auto &nxt: v[idx]) { - if (!chk[nxt]) - pq.emplace(--de2[nxt], nxt); - } - } - ans = max(ans, ans2); - } - - cout << ans << '\n'; - } - - return 0; -} -",1 -asdfssr,2063C - Remove Exactly Two,c++17 ,304273207,304283650,"#include -#include -#include -#include -#include -#include -#include -#define int long long -using namespace std; -int mod=998244353; -int INF=-1e10; -void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){ - for(auto v:adj[u]){ - if(v==p) continue; - dfs(v,u,adj,dp,dgr); - dp[u][1][0]=max({dp[u][1][0],dp[v][1][1],dp[v][1][0]}); - dp[u][2][0]=max({dp[u][2][0],dp[v][2][0],dp[v][2][1]}); - dp[u][1][1]=dgr[u]; - dp[u][2][1]=max({dp[u][2][1],dp[v][1][1]+dgr[u]-2,dp[v][1][0]+dgr[u]-1}); - } - if(dgr[u]==1 && u!=0){ - dp[u][1][0] = 0; - dp[u][2][0] = 0; - dp[u][1][1] = 1; - dp[u][2][1] = 0; - } -} -void solve(){ - int n; - cin>>n; - vector> adj(n); - vector>> dp(n,vector>(3,vector(2,0))); - vector dgr(n,0); - for(int i=0;i>u>>v; - u--;v--; - dgr[u]++; - dgr[v]++; - adj[u].push_back(v); - adj[v].push_back(u); - } - dfs(0,-1,adj,dp,dgr); - //cout<>t; - while(t--){ - solve(); - } -} -","#include -#include -#include -#include -#include -#include -#include -#define int long long -using namespace std; -int mod=998244353; -int INF=-1e10; -void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){ - int m1=0; - int m2=0; - for(auto v:adj[u]){ - if(v==p) continue; - dfs(v,u,adj,dp,dgr); - if(m1<=max(dp[v][1][1],dp[v][1][0])){ - m2=m1; - m1=max(dp[v][1][1],dp[v][1][0]); - } - else if(m2>n; - vector> adj(n); - vector>> dp(n,vector>(3,vector(2,0))); - vector dgr(n,0); - for(int i=0;i>u>>v; - u--;v--; - dgr[u]++; - dgr[v]++; - adj[u].push_back(v); - adj[v].push_back(u); - } - dfs(0,-1,adj,dp,dgr); - cout<>t; - while(t--){ - solve(); - } -} -",2 -roshanlakra19122000,2063C - Remove Exactly Two,c++23 ,304566158,304573150,"#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pb push_back -#define ppb pop_back -#define mp make_pair -using namespace std; -using vpi = vector>; -using pi = pair; -using vi = vector; -using vvi = vector>; -#define ff first -#define ss second -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x).size() -const int inf = 9e18; -const int mod = 1e9 + 7; -const int NUM = 1000030; -const int N = 10000000; -#define DEBUG(x) cerr << #x << "": "" << x << '\n' -template -istream &operator>>(istream &is, pair &p) -{ - is >> p.first >> p.second; - return is; -} -template -ostream &operator<<(ostream &os, pair p) -{ - os << p.first << ' ' << p.second << ' '; - return os; -} -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -vector lp, sieve; -vector pr; -vector power; -vector fact; -void initpow(int x) -{ - power.resize(NUM); - power[0] = 1; - for (int i = 1; i < NUM; i++) - { - power[i] = (power[i - 1] * (x % mod)) % mod; - } -} -void initFactorial() -{ - fact.resize(NUM); - fact[0] = 1; - for (int i = 1; i < NUM; i++) - { - fact[i] = (fact[i - 1] * i) % mod; - } -} -void calc_sieve() -{ - sieve.resize(NUM + 1, 0); - for (int x = 2; x <= NUM; x++) - { - if (sieve[x]) - continue; - for (int u = x; u <= NUM; u += x) - { - sieve[u] = x; - } - } -} -void primefactor() -{ - lp.resize(N + 1, 0); - for (int i = 2; i <= N; ++i) - { - if (lp[i] == 0) - { - lp[i] = i; - pr.push_back(i); - } - for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) - lp[i * pr[j]] = pr[j]; - } -} -int binpow(int a, int b) -{ - int res = 1; - while (b > 0) - { - if (b & 1) - res = res * a; - a = a * a; - b >>= 1; - } - return res; -} -int binpow(int a, int b, int mod) -{ - int res = 1; - while (b > 0) - { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b >>= 1; - } - return res % mod; -} -int gcd(int a, int b) -{ - if (b == 0) - return a; - else - return gcd(b, a % b); -} -int lcm(int a, int b) -{ - return ((a / gcd(a, b)) * b); -} -int inversemod(int a, int mod) -{ - return binpow(a, mod - 2, mod); -} -int divmod(int a, int b, int c) -{ - return ((a % c) * inversemod(b, c)) % c; -} -int combination(int n, int k) -{ - if (k > n) - return 0; - int p1 = (fact[n] * inversemod(fact[k], mod)) % mod; - int p2 = (1 * inversemod(fact[n - k], mod)) % mod; - return (p1 * p2) % mod; -} -void solve() -{ - int n; - cin >> n; - int deg[n]; - for (int i = 0; i < n; i++) - deg[i] = 0; - - vector> adj(n); - for (int i = 0; i < n - 1; i++) - { - int x, y; - cin >> x >> y; - x--, y--; - deg[x]++; - deg[y]++; - adj[x].push_back(y); - adj[y].push_back(x); - } - int ans = 0; - int maxver = -1; - int freq = 0; - for (int i = 0; i < n; i++) - { - if (freq < deg[i]) - { - freq = deg[i]; - maxver = i; - } - } - ans += freq; - deg[maxver] = 0; - - for (auto it : adj[maxver]) - { - deg[it]--; - } - freq = 0, maxver = -1; - for (int i = 0; i < n; i++) - { - if (freq < deg[i]) - { - freq = deg[i]; - maxver = i; - } - } - ans += freq; - cout << ans - 1 << ""\n""; -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t = 1; - cin >> t; - // ll a = 134, b = 132, c = 137; - // cout << (a ^ b + b ^ c + c ^ a) << endl; - while (t--) - solve(); - return 0; -}","#include -#include -#include -#include -#include -#include -#include -#include -#define ll long long -#define int long long -#define pb push_back -#define ppb pop_back -#define mp make_pair -using namespace std; -using vpi = vector>; -using pi = pair; -using vi = vector; -using vvi = vector>; -#define ff first -#define ss second -#define all(x) x.begin(), x.end() -#define sz(x) (int)(x).size() -const int inf = 9e18; -const int mod = 1e9 + 7; -const int NUM = 1000030; -const int N = 10000000; -#define DEBUG(x) cerr << #x << "": "" << x << '\n' -template -istream &operator>>(istream &is, pair &p) -{ - is >> p.first >> p.second; - return is; -} -template -ostream &operator<<(ostream &os, pair p) -{ - os << p.first << ' ' << p.second << ' '; - return os; -} -template -istream &operator>>(istream &is, vector &v) -{ - for (auto &i : v) - is >> i; - return is; -} -template -ostream &operator<<(ostream &os, vector v) -{ - for (auto &i : v) - os << i << ' '; - return os; -} -vector lp, sieve; -vector pr; -vector power; -vector fact; -void initpow(int x) -{ - power.resize(NUM); - power[0] = 1; - for (int i = 1; i < NUM; i++) - { - power[i] = (power[i - 1] * (x % mod)) % mod; - } -} -void initFactorial() -{ - fact.resize(NUM); - fact[0] = 1; - for (int i = 1; i < NUM; i++) - { - fact[i] = (fact[i - 1] * i) % mod; - } -} -void calc_sieve() -{ - sieve.resize(NUM + 1, 0); - for (int x = 2; x <= NUM; x++) - { - if (sieve[x]) - continue; - for (int u = x; u <= NUM; u += x) - { - sieve[u] = x; - } - } -} -void primefactor() -{ - lp.resize(N + 1, 0); - for (int i = 2; i <= N; ++i) - { - if (lp[i] == 0) - { - lp[i] = i; - pr.push_back(i); - } - for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j) - lp[i * pr[j]] = pr[j]; - } -} -int binpow(int a, int b) -{ - int res = 1; - while (b > 0) - { - if (b & 1) - res = res * a; - a = a * a; - b >>= 1; - } - return res; -} -int binpow(int a, int b, int mod) -{ - int res = 1; - while (b > 0) - { - if (b & 1) - res = (res * a) % mod; - a = (a * a) % mod; - b >>= 1; - } - return res % mod; -} -int gcd(int a, int b) -{ - if (b == 0) - return a; - else - return gcd(b, a % b); -} -int lcm(int a, int b) -{ - return ((a / gcd(a, b)) * b); -} -int inversemod(int a, int mod) -{ - return binpow(a, mod - 2, mod); -} -int divmod(int a, int b, int c) -{ - return ((a % c) * inversemod(b, c)) % c; -} -int combination(int n, int k) -{ - if (k > n) - return 0; - int p1 = (fact[n] * inversemod(fact[k], mod)) % mod; - int p2 = (1 * inversemod(fact[n - k], mod)) % mod; - return (p1 * p2) % mod; -} -void solve() -{ - int n; - cin >> n; - int deg[n]; - for (int i = 0; i < n; i++) - deg[i] = 0; - - set> vp; - for (int i = 0; i < n - 1; i++) - { - int x, y; - cin >> x >> y; - x--, y--; - deg[x]++; - deg[y]++; - vp.insert({x, y}); - vp.insert({y, x}); - } - int ans = 0; - vector> temp; - for (int i = 0; i < n; i++) - { - temp.push_back({-deg[i], i}); - } - sort(temp.begin(), temp.end()); - - for (int i = 0; i < n - 1; i++) - { - for (int j = i + 1; j < n; j++) - { - if (vp.find({temp[i].second, temp[j].second}) == vp.end()) - { - ans = max(ans, (-temp[i].first) + (-temp[j].first) - 1); - break; - } - } - } - for (auto it : vp) - { - ans = max(ans, deg[it.first] + deg[it.second] - 2); - } - cout << ans << ""\n""; -} -signed main() -{ - ios_base::sync_with_stdio(false); - cin.tie(0); - int t = 1; - cin >> t; - // ll a = 134, b = 132, c = 137; - // cout << (a ^ b + b ^ c + c ^ a) << endl; - while (t--) - solve(); - return 0; -}",2 -archer41156,2063C - Remove Exactly Two,c++17 ,304504438,304504289,"#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio;cin.tie(0); -#define PII pair -#define PLL pair -#define ll long long -#define lf double -#define MAX_NUM 10000 -void solve(){ - int n; - cin>>n; - mapdu; -// mapreserve_du; - map>child; - for(int i=1;i<=n-1;i++){ - int a,b; - cin>>a>>b; - du[a]+=1; - du[b]+=1; - child[a].insert(b); - child[b].insert(a); - } - - vectorans_arr; - int max_du=-1; - int cnt=5; - for(auto x:du)max_du=max(max_du,x.second); - for(auto x:du){ - if(x.second!=max_du)continue; - int ord=x.first; - for(int i=1;i<=n;i++){ - if(i==ord)continue; - if(child[ord].find(i)!=child[ord].end()){ - ans_arr.push_back(du[ord]+du[i]-2); - }else { - ans_arr.push_back(du[ord]+du[i]-1); - } - } - if(cnt--==0)break; - } - int ans=-1; - for(auto x:ans_arr){ - ans=max(ans,x); - } - cout<>T; -// T=1; - while(T--){ - solve(); - } - return 0; -} -","#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; -#define IOS ios::sync_with_stdio;cin.tie(0); -#define PII pair -#define PLL pair -#define ll long long -#define lf double -#define MAX_NUM 10000 -void solve(){ - int n; - cin>>n; - mapdu; -// mapreserve_du; - map>child; - for(int i=1;i<=n-1;i++){ - int a,b; - cin>>a>>b; - du[a]+=1; - du[b]+=1; - child[a].insert(b); - child[b].insert(a); - } - - vectorans_arr; - int max_du=-1; - for(auto x:du)max_du=max(max_du,x.second); - for(auto x:du){ - if(x.second!=max_du)continue; - int ord=x.first; - for(int i=1;i<=n;i++){ - if(i==ord)continue; - if(child[ord].find(i)!=child[ord].end()){ - ans_arr.push_back(du[ord]+du[i]-2); - }else { - ans_arr.push_back(du[ord]+du[i]-1); - } - } - } - int ans=-1; - for(auto x:ans_arr){ - ans=max(ans,x); - } - cout<>T; -// T=1; - while(T--){ - solve(); - } - return 0; -} -",1 -Dark_Knight0026#,2063C - Remove Exactly Two,c++20 ,304733296,304727880,"#include -#include -#include - -#pragma GCC optimize(""O3,unroll-loops"") - -using namespace std; - -#define ll long long -#define endl '\n' -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define fr(i, j, n) for (int i = j; i < n; i++) -#define fastIO ios::sync_with_stdio(false), cin.tie(NULL); -#define ll1 (ll)1 -#define ff first -#define ss second -#define YES cout << ""YES\n"" -#define NO cout << ""NO\n"" - -#ifndef ONLINE_JUDGE -#include ""template.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -const int MOD = 1e9 + 7; - -/* -unordered_map mp1; -mp.reserve(1024); -mp.max_load_factor(0.25); -*/ - -template -T _gcd(T __m, T __n) -{ - while (__n != 0) - { - T __t = __m % __n; - __m = __n; - __n = __t; - } - return __m; -} -template -T Set(T N, T pos) { return N = N | (1 << pos); } -template -T reset(T N, T pos) { return N = N & ~(1 << pos); } -template -bool check(T N, T pos) { return (bool)(N & (1 << pos)); } - -int32_t main() -{ - fastIO; - int t = 1; - cin >> t; - while (t--) - { - ll n, u, v; - cin >> n; - set> st; - vector degree(n + 1); - vector> adj(n + 1); - for (int i = 1; i < n; i++) - { - cin >> u >> v; - adj[u].push_back(v), adj[v].push_back(u); - degree[u]++, degree[v]++; - } - for (int i = 1; i <= n; i++) - { - st.insert({degree[i], i}); - } - set ans; - for (int i = 1; i <= n; i++) - { - vector> nst; - nst.push_back({degree[i], i}); - st.extract({degree[i], i}); - for (auto it : adj[i]) - { - ans.insert(degree[i] + degree[it] - 2); - nst.push_back({degree[it], it}); - st.extract({degree[it], it}); - } - if (!st.empty()) - { - auto it = *st.rbegin(); - ans.insert(degree[i] + it.ff - 1); - } - for (auto it : nst) - { - st.insert({it.ff, it.ss}); - } - } - cout << *ans.rbegin() << endl; - } - return 0; -}","#include -#include -#include - -#pragma GCC optimize(""O3,unroll-loops"") - -using namespace std; - -#define ll long long -#define endl '\n' -#define all(x) x.begin(), x.end() -#define rall(x) x.rbegin(), x.rend() -#define fr(i, j, n) for (int i = j; i < n; i++) -#define fastIO ios::sync_with_stdio(false), cin.tie(NULL); -#define ll1 (ll)1 -#define ff first -#define ss second -#define YES cout << ""YES\n"" -#define NO cout << ""NO\n"" - -#ifndef ONLINE_JUDGE -#include ""template.cpp"" -#else -#define debug(...) -#define debugArr(...) -#endif - -typedef __gnu_pbds::tree, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set; -const int MOD = 1e9 + 7; - -/* -unordered_map mp1; -mp.reserve(1024); -mp.max_load_factor(0.25); -*/ - -template -T _gcd(T __m, T __n) -{ - while (__n != 0) - { - T __t = __m % __n; - __m = __n; - __n = __t; - } - return __m; -} -template -T Set(T N, T pos) { return N = N | (1 << pos); } -template -T reset(T N, T pos) { return N = N & ~(1 << pos); } -template -bool check(T N, T pos) { return (bool)(N & (1 << pos)); } - -int32_t main() -{ - fastIO; - int t = 1; - cin >> t; - while (t--) - { - ll n, u, v; - cin >> n; - vector degree(n + 1); - vector> adj(n + 1); - for (int i = 1; i < n; i++) - { - cin >> u >> v; - adj[u].insert(v), adj[v].insert(u); - degree[u]++, degree[v]++; - } - vector> ndeg; - for (int i = 1; i <= n; i++) - { - ndeg.push_back({degree[i], i}); - } - sort(rall(ndeg)); - ll secondMax = ndeg[1].ff, ans = ndeg[0].ff, root = ndeg[0].ss, i = 1; - set val; - while (i < ndeg.size()) - { - if (adj[root].find(ndeg[i].ss) != adj[root].end()) - { - val.insert(ans + ndeg[i].ff - 2); - } - else - { - val.insert(ans + ndeg[i].ff - 1); - } - i++; - } - assert(!val.empty()); - cout << *val.rbegin() << endl; - } - return 0; -}",1 -mickeygiaogiaoroom#,2063C - Remove Exactly Two,c++17 ,303800665,303801119,"#include -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int N=1e5+200; -sete[N]; -vector>v; -int a[N]; -bool cmp(pairx,pairy){ - return x.second>y.second; -} -int main(){ - int t; - cin>>t; - while(t--){ - ll n; - cin>>n; - v.clear(); - for(int i=1;i<=n;++i){ - a[i]=0; - e[i].clear(); - } - int mx=0; - for(int i=1;i>x>>y; - e[x].insert(y); - e[y].insert(x); - a[x]++; - a[y]++; - } - for(int i=1;i<=n;++i) v.push_back({i,a[i]}); - sort(v.begin(),v.end(),cmp); - int ans=1; - int cnt=0; - while(cnt -#include -#include -#include -#include -using namespace std; -typedef long long ll; -const int N=2e5+200; -sete[N]; -vector>v; -int a[N]; -bool cmp(pairx,pairy){ - return x.second>y.second; -} -int main(){ - int t; - cin>>t; - while(t--){ - ll n; - cin>>n; - v.clear(); - for(int i=1;i<=n;++i){ - a[i]=0; - e[i].clear(); - } - int mx=0; - for(int i=1;i>x>>y; - e[x].insert(y); - e[y].insert(x); - a[x]++; - a[y]++; - } - for(int i=1;i<=n;++i) v.push_back({i,a[i]}); - sort(v.begin(),v.end(),cmp); - int ans=1; - int cnt=0; - while(cnt