Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define pi 3.141592654
- #define NUM 1e18
- #define Mod 1'000'000'007
- #define fixed(n) fixed<<setprecision(n)
- #define cin(v) for(auto &i:v) cin >> i ;
- #define cout(v) for(auto &i:v) cout << i <<" ";
- #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
- #define small(x) (x>=97&&x<=122)
- #define capital(x) (x>=65&&x<=90)
- #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
- #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
- #define all(v) ((v).begin()), ((v).end())
- #define allr(v) ((v).rbegin()), ((v).rend())
- #define updmax(a,b) a=max(a,b)
- #define updmin(a,b) a=min(a,b)
- #define ceil(a,b) ((a/b)+(a%b?1:0))
- /* asc -> 1 2 3 ,des -> 3 2 1 */
- /***********************************************************************************/
- using namespace std;
- void Rofyda_Elghadban(){
- #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);
- }
- struct com{
- bool operator()(int l,int r){
- return (l>=50)<(r>=50);
- }
- };
- void solve(){
- int n,counter=0;
- cin>>n;
- int c1;
- cin>>c1;
- deque<int>d1(c1),dd1(c1);
- cin(d1);
- dd1=d1;
- int c2;
- cin>>c2;
- deque<int>d2(c2),dd2(c2);
- cin(d2);
- dd2=d2;
- while(d1.size()>0&&d2.size()>0){
- if(d1.front()<d2.front()){
- d2.push_back(d1.front());
- d2.push_back(d2.front());
- d1.pop_front();
- d2.pop_front();
- c2++;
- c1--;
- }else if(d1.front()>d2.front()){
- d1.push_back(d2.front());
- d1.push_back(d1.front());
- d2.pop_front();
- d1.pop_front();
- c1++;
- c2--;
- }
- counter++;
- if((d1==dd1&&d2==dd2)||counter==106){
- cout<<-1<<"\n";
- return;
- }
- }cout<<counter<<" ";
- if(d1.size()==0){
- cout<<2<<"\n";
- }else{
- cout<<1<<"\n";
- }
- }
- int main(){
- Rofyda_Elghadban();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement