This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Memory_lib.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
int Memory(int N, int M) {
	//cout<<N<<" "<<M<<endl;
	if(M==0){
		return (3<<20);
	}
	int k = (M>>20);
	int t = M%(1<<20);
	int a = t/10000, b = (t/100)%100, c = (t%100);
	if(a>N-1 || b>N-1 || c>N-1)	return -2;
	char ch = Get(b+1);
	//cout<<k<<" "<<a<<" "<<b<<" "<<c<<" "<<ch<<endl;
	if(k==3){
		if(ch=='<'){
			a++;
		}else if(ch=='>'){
			a--; if(a<0)	return -2;
		}else if(ch=='['){
			c++;
		}else{
			c--; if(c<0)	return -2;
		}
		if(b==N+1){
			if(a!=0 || c!=0)	return -2;
			return (1<<20);
		}
		b++;
		int K = (k<<20) + a*10000 + b*100 + c;
		return K;
	}
	if(b==0 && k!=0){
		k = 0;
	}
	if(a==0){
		if(k==0){
			if(ch=='<')	k = 1;
			else if(ch=='[')	k = 2;
		}else{
			return -2;/*
			if(k==1){
				if(c!=0 || ch!='>'){
					return -2;
				}
			}else{
				if(c!=0 || ch!=']'){
					return -2;
				}
			}
			k = 0;
			c = 0;*/
		}
	}
	if(k==0){
		if(ch=='<' || ch=='['){
			a--;
			if(a<0)	return -2;
		}
		else{
			a++;
		}	
	}
	if(k!=0){
		if(ch=='<' || ch=='['){
			a++;
		}
		else{
			a--;
			if(a<0)	return -2;
		}	
		if(k==1){
			if(ch=='<'){
				c++;
			}else if(ch=='>'){
				c--;
				if(c<0)	return -2;
			}
		}else{
			if(ch=='['){
				c++;
			}else if(ch==']'){
				c--;
				if(c<0)	return -2;
			}
		}
		if(a==0 || c==0){
			if(a!=0 || c!=0)	return -2;
			k = 0;
		}
	}
	if(b==N-1){
		if(k!=0)	return -2;
		if(a==N-1)	return -1;
		b = 0;
		a++;
		c = 0;
	}else{
		b++;
	}
	int K = (k<<20) + a*10000 + b*100 + c;
	return K;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |