Snippets Collections
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main() {
    double w, x, y, b, c, d, expo, sr, absolute_double, ceiling, fl;
    int a, z, absolute;
    long abs_long;
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    
    cout << "Enter the values of the following : \n"
        << "-------------------------------\n"
        << "pow(x, y)\n"
        << "x: ";
    cin >> x;
    cout << "y: ";
    cin >> y;
    cout << "sqrt(w)\n"
        << "w: ";
    cin >> w;
    cout << "abs(z)\n"
        << "z: ";
    cin >> z;
    cout << "labs(a)\n"
        << "a: ";
    cin >> a;
    cout << "fabs(b)\n"
        << "b: ";
    cin >> b;
    cout << "ceil(c)\n"
        << "c: ";
    cin >> c;
    cout << "floor(d)\n"
        << "d: ";
    cin >> d;
    
    expo = pow(x, y);
    cout << "___________________________\n"
    << "pow(x, y) = pow(" << x << ", " 
    << y << ") "<< " = " << expo << endl;
    
    sr = sqrt(w);
    cout << "sqrt(w) = sqrt(" << w
    << ") "<< " = " << sr << endl;
    
    absolute = abs(z);
    cout << "abs(z) = abs(" << z
    << ") "<< " = " << absolute << endl;
    
    abs_long = labs(a);
    cout << "labs(a) = labs(" << a
    << ") "<< " = " << abs_long << endl;
    
    absolute_double = fabs(b);
    cout << "fabs(b) = fabs(" << b
    << ") "<< " = " << absolute_double << endl;
    
    ceiling = ceil(c);
    cout << "ceil(c) = ceil(" << c
    << ") "<< " = " << ceiling << endl;
    
    fl = floor(d);
    cout << "floor(d) = floor(" << d
    << ") "<< " = " << fl << endl;
    
    return 0;
}
#include <iostream>
using namespace std;

double var(int x, double y) {
    return ((x + y)/2);
}

int main()
{
    double y, ave;
    int x;
    
    cout << "Average of two arguements\n"
        << "----------------------------\n"
        << "Please enter arguement x: ";
    cin >> x;
    cout << "Please enter arguement y: ";
    cin >> y;
    
    ave = var(x, y);
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    cout << "____________________________\n"
        << "The average of these two numbers are "
        << ave << endl;
    
    return 0;
}
#include<iostream>
using namespace std;

class Element
{
public:
	int row;
	int col;
	int data;

};

class List
{
public:
	int row;
	int col;
	int data;
	List*next;
};



class  Sparse
{

public:
	int countElements;
	Element * elementArr = new Element[10000];
	Sparse()
	{
		countElements = 0;
	}


	void insert(int row	, int col, int data)
	{
		Element newElem;
		newElem.row = row;
		newElem.col = col;
		newElem.data = data;
		elementArr[countElements] = newElem;
		elementArr[0].data = countElements;
		countElements++;
	}

	// void add()


};

void display(Sparse* sp)
{
	for (int i = 0; i <= sp->elementArr[0].data  ; ++i)
	{
		cout << sp->elementArr[i].row << " " << sp->elementArr[i].col << "  " << sp->elementArr[i].data;
		cout  << endl;

	}

}

void add ( Sparse *s1 , Sparse *s2 , Sparse *s3)
{
	s3->elementArr[0].row = s1->elementArr[0].row;
	s3->elementArr[0].col = s1->elementArr[0].col;

	int i = 1; //points to sp1
	int j = 1; //points to sp2
	int k = 1; //points to sp3
	while (i <= s1->elementArr[0].data && j <= s2->elementArr[0].data )
	{
		if (s1->elementArr[i].row < s2->elementArr[j].row)
		{
			s3->elementArr[i].row = s1->elementArr[j].row;
			s3->elementArr[i].col = s1->elementArr[j].col;
			s3->elementArr[k++] = s1->elementArr[i++];
			s3->elementArr[0].data ++;
			s3->countElements++;
		}
		else if (s1->elementArr[i].row > s2->elementArr[j].row)
		{
			s3->elementArr[k].row = s2->elementArr[j].row;
			s3->elementArr[k].col = s2->elementArr[j].col;
			s3->elementArr[k++] = s2->elementArr[j++];
			s3->elementArr[0].data ++;
			s3->countElements++;
		}
		else if (s1->elementArr[i].row == s2->elementArr[j].row)
		{
			if (s1->elementArr[i].col < s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s1->elementArr[j].row;
				s3->elementArr[k].col = s1->elementArr[j].col;
				s3->elementArr[k++] = s1->elementArr[i++];
				s3->elementArr[0].data ++;
				s3->countElements++;
			}
			else if (s1->elementArr[i].col > s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s2->elementArr[j].row;
				s3->elementArr[k].col = s2->elementArr[j].col;
				s3->elementArr[k++] = s2->elementArr[j++];
				s3->elementArr[0].data ++;
				s3->countElements++;
			}
			else if (s1->elementArr[i].col == s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s2->elementArr[j].row;
				s3->elementArr[k].col = s2->elementArr[j].col;
				s3->elementArr[k++].data = s2->elementArr[j++].data + s1->elementArr[i++].data;
				s3->elementArr[0].data ++;
				s3->countElements++;
			}

		}
		cout << "hi" << endl;
		display(s3);
		cout << endl;
	}



}
// void display(Sparse* sp)
// {
// 	for (int i = 0; i <= sp->elementArr[0].data  ; ++i)
// 	{
// 		cout << sp->elementArr[i].row << " " << sp->elementArr[i].col << "  " << sp->elementArr[i].data;
// 		cout  << endl;

// 	}

// }

void transpose(Sparse *s1, Sparse*s3)
{
	//no. of elements in each col of s1
	int col_count_s1 = s1->elementArr[0].col + 1;
	int *col_s1 = new int [col_count_s1] {0};
	col_s1[0] = s1->elementArr[0].col;
	for (int i = 1; i <= s1->elementArr[0].data; ++i)
	{
		col_s1[s1->elementArr[i].col]++;
		//it will act as row element for s2
	}

	// for (int i = 0; i < col_count_s1; ++i)
	// {
	// 	cout << col_s1[i] << " ";
	// 	//it will act as row element for s2
	// }
	cout << endl;
	int *row_index = new int [col_count_s1 + 1];
	//one size greater than col_s1;
	row_index[1] = 1;
	for (int i = 2; i <= col_count_s1   ; ++i)
	{
		row_index[i] = row_index[i - 1] + col_s1[i - 1];
	}
	// for (int i = 0 ; i <= col_count_s1; ++i)
	// {
	// 	cout << row_index[i] << " ";
	// 	//it will act as row element for s2
	// }
	cout << endl;
	cout << endl;


	for (int i = 0; i <= s1->elementArr[0].data; ++i)
	{
		if (i == 0)
		{
			s3->elementArr[i].row = s1->elementArr[i].col;
			s3->elementArr[i].col = s1->elementArr[i].row;
			s3->elementArr[i].data = s1->elementArr[i].data;
		}
		else
		{
			int r_index  = s1->elementArr[i].col;
			int index = row_index[r_index];
			s3->elementArr[index].row = s1->elementArr[i].col;
			s3->elementArr[index].col = s1->elementArr[i].row;
			s3->elementArr[index].data = s1->elementArr[i].data;
			row_index[r_index]++;
		}
	}
}

void matrix(Sparse *s)
{
	int k = 1;
	for (int i = 1; i <= s->elementArr[0].row; ++i)
	{
		for (int j = 1; j <= s->elementArr[0].col; j++)
		{
			if (i == s->elementArr[k].row && j == s->elementArr[k].col)
				cout << s->elementArr[k++].data << " ";
			else
				cout << "0 ";
		}
		cout << endl;
	}
}


void multiply ( Sparse *s1 , Sparse *s2 , Sparse *s3)
{
	Sparse *s4 = new Sparse();
	display(s1); cout << endl;
	display(s2); cout << endl;
	s3->insert(s1->elementArr[0].row , s2->elementArr[0].col , 0 );
	for (int i = 1; i <= s1->elementArr[0].data; i++ )
	{

		int sum = 0;

		for (int j = 1; j <= s2->elementArr[0].data; j++)
		{
			int sum = 0;
			if (s1->elementArr[i].col == s2->elementArr[j].row)
			{
				sum = s1->elementArr[i].data * s2->elementArr[j].data;
				s3->insert(s1->elementArr[i].row , s2->elementArr[j].col , sum);
			}
		}
	}


	display(s3);


	cout << endl;
	cout << endl;
	transpose (s3, s4);//saved in new transpose matrix s4
	transpose (s4, s3);//saved in new transpose matrix s3
	//now s3 is in sorted order
	Sparse *s5 = new Sparse();
	for (int i = 0; i <= s3->elementArr[0].data; ++i)
	{
		if (i == 0)
		{
			s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, 0);
		}
		else if (i == 1)
		{
			s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, s3->elementArr[i].data);
		}
		else
		{
			int flag = 0;
			for (int k = 1; k <= s5->elementArr[0].data; k++)
			{
				if (s3->elementArr[i].row == s5->elementArr[k].row && s3->elementArr[i].col == s5->elementArr[k].col)
				{
					s5->elementArr[k].data += s3->elementArr[i].data;
					flag = 1;
					break;
				}
			}
			if (flag == 0)
			{
				s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, s3->elementArr[i].data);

			}
		}

	}





	display(s3);
	cout << endl;
	s3 = s5;
	display(s3);
	cout << endl;
	matrix(s3);
	cout << s3->elementArr[0].row ;

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	int type;
	int op;
	int R1, R2, C1, C2;
	// do {
	cout << "What operation do you want to perform? " <<
	     " Select Option number. Enter 0 to exit." << endl;
	cout << "1. Array" << endl;
	cout << "2. Link list" << endl;
	cout << "Enter datastructure to use :\n";
	cin >> type;
	cout << "Type of operation :\n";
	cout << "1. Addition" << endl;
	cout << "2. Transpose " << endl;
	cout << "3. Multiplication  " << endl;
	cin >> op;
	int data;


	Sparse *sp1 = new Sparse();
	Sparse *sp2 = new Sparse();

	int n = 0;
	if (type == 1 )
	{
		//MATRIX 1
		cin >> R1 >> C1;
		sp1->insert(R1, C1, 0);// FOR Checking #r , #c , #elements
		for (int i = 1; i <= R1; ++i)
		{
			for (int j = 1; j <= C1; ++j)
			{
				cin >> data;
				if (data != 0)
					sp1->insert(i, j, data);
			}
		}
		if (op == 2)//transpose
		{
			Sparse*sp3 = new Sparse();
			transpose(sp1 , sp3);
			display(sp1);
			cout << endl;
			display(sp3);
			cout << endl;
			// sp1 = sp3; //after transpose just change the pointer
			matrix(sp1);
			cout << endl;
			matrix(sp3);
			cout << endl;
		}

		if (op == 1 || op == 3)//addition or mul
		{
			//MATRIX 2
			cin >> R2 >> C2;
			sp2->insert(R2, C2, 0);
			for (int i = 1; i <= R2; ++i)
				for (int j = 1; j <= C2; ++j)
				{
					cin >> data;
					if (data != 0)
						sp2->insert(i, j, data);
				}
			Sparse *sp3 = new Sparse();;
			if (op == 1) //add
			{
				if (R1 != R2 || C1 != C2)
				{
					cout << " wrong matrix sizes: \n";
					return 0;
				}
				add(sp1, sp2, sp3);
				cout << endl;
				display(sp1);
				cout << endl;
				display(sp2);
				cout << endl;
				display(sp3);
				cout << endl;
				cout << sp1->elementArr[0].data << endl;
				cout << sp2->elementArr[0].data << endl ;
				cout << sp3->elementArr[0].data << endl ;
				matrix(sp1);
				cout << endl;
				matrix(sp2);
				cout << endl;
				matrix(sp3);
				cout << endl;
			}
			else if (op == 3) //multiplication
			{
				if (C1 != R2)
				{
					cout << " wrong matrix sizes: \n";
					return 0;
				}
				multiply(sp1, sp2, sp3);
				cout << endl;
				// 	display(sp1);
				// 	cout << endl;
				// 	display(sp2);
				// 	cout << endl;
				// 	display(sp3);
				// 	cout << endl;
				// 	matrix(sp1);
				// 	cout << endl;
				// 	matrix(sp2);
				// 	cout << endl;
				// 	matrix(sp3);
				// 	cout << endl;
			}





			// for (int i = 0; i < 5 ; ++i)
			// {
			// 	cout << sp3->elementArr[i].row << " " << sp3->elementArr[i].col << "  " << sp3->elementArr[i].data;
			// 	cout  << endl;
			// }
			// cout << sp3->elementArr[0].row << " " << sp3->elementArr[0].col << "  " << sp3->elementArr[0].data;


		}
	}





// 	switch (option) {
// 	case 0:
// 		break;
// 	case 1:
// 		cout << "Enter VALUE of TREE sp to INSERT in AVL Tree: ";
// 		cin >> val;

// 		obj_avl.root = obj_avl.insert(val);
// 		cout << endl;
// 		break;

// 	case 2:
// 		cout << "Enter VALUE of TREE sp to delete in AVL Tree: ";
// 		cin >> val;
// 		obj_avl.root = obj_avl.deleteData(val);
// 		break;


// 	case 3:
// 		cout << "Enter VALUE of TREE sp to search in AVL: ";
// 		cin >> val;
// 		cout << obj_avl.search(val);
// 		break;

// 	default:
// 		cout << "Enter Proper Option number " << endl;
// 	}

// } while (option != 0);



	return 0;
}
#include <iostream>
using namespace std;

int add(int x, int y, int z) {
    return (x + y + z);
}

int main()
{
    int x, y, z, sum;
    
    cout << "Sum of three arguements\n"
        << "----------------------------\n"
        << "Please enter three arguements: ";
    cin >> x >> y >> z;
    
    sum = add(x, y,z);
 
    cout << "____________________________\n"
        << x << " + " << y << " + "
        << z << endl
        << "The sum these three arguements are: " << sum;

    return 0;
    
}
#include <iostream>
using namespace std;

double total_cost(int number_par, double price_par) {
}

int main()
{
    double price, bill;
    int number;
    
    cout << "Enter the number of items purchased: ";
    cin >> number;
    cout << "Enter the price per item $";
    cin >> price;
    
    bill = total_cost(number, price);
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    cout << number << " items at "
    << "$" << price << " each.\n"
    << "Final bill, including tax, is $" << bill
    << endl;
    
    return 0;
}
#include<iostream>
using namespace std;

class Element
{
public:
	int row;
	int col;
	int data;

};



class  Sparse
{

public:
	int countElements;
	Element * elementArr = new Element[10000];
	Sparse()
	{
		countElements = 0;
	}


	void insert(int row	, int col, int data)
	{
		Element newElem;
		newElem.row = row;
		newElem.col = col;
		newElem.data = data;
		elementArr[countElements] = newElem;
		elementArr[0].data = countElements;
		countElements++;
	}

	// void add()


};

void display(Sparse* sp)
{
	for (int i = 0; i <= sp->elementArr[0].data  ; ++i)
	{
		cout << sp->elementArr[i].row << " " << sp->elementArr[i].col << "  " << sp->elementArr[i].data;
		cout  << endl;

	}

}

void add ( Sparse *s1 , Sparse *s2 , Sparse *s3)
{
	s3->elementArr[0].row = s1->elementArr[0].row;
	s3->elementArr[0].col = s1->elementArr[0].col;

	int i = 1; //points to sp1
	int j = 1; //points to sp2
	int k = 1; //points to sp3
	while (i <= s1->elementArr[0].data && j <= s2->elementArr[0].data )
	{
		if (s1->elementArr[i].row < s2->elementArr[j].row)
		{
			s3->elementArr[i].row = s1->elementArr[j].row;
			s3->elementArr[i].col = s1->elementArr[j].col;
			s3->elementArr[k++] = s1->elementArr[i++];
			s3->elementArr[0].data ++;
			s3->countElements++;
		}
		else if (s1->elementArr[i].row > s2->elementArr[j].row)
		{
			s3->elementArr[k].row = s2->elementArr[j].row;
			s3->elementArr[k].col = s2->elementArr[j].col;
			s3->elementArr[k++] = s2->elementArr[j++];
			s3->elementArr[0].data ++;
			s3->countElements++;
		}
		else if (s1->elementArr[i].row == s2->elementArr[j].row)
		{
			if (s1->elementArr[i].col < s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s1->elementArr[j].row;
				s3->elementArr[k].col = s1->elementArr[j].col;
				s3->elementArr[k++] = s1->elementArr[i++];
				s3->elementArr[0].data ++;
				s3->countElements++;
			}
			else if (s1->elementArr[i].col > s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s2->elementArr[j].row;
				s3->elementArr[k].col = s2->elementArr[j].col;
				s3->elementArr[k++] = s2->elementArr[j++];
				s3->elementArr[0].data ++;
				s3->countElements++;
			}
			else if (s1->elementArr[i].col == s2->elementArr[j].col)
			{
				s3->elementArr[k].row = s2->elementArr[j].row;
				s3->elementArr[k].col = s2->elementArr[j].col;
				s3->elementArr[k++].data = s2->elementArr[j++].data + s1->elementArr[i++].data;
				s3->elementArr[0].data ++;
				s3->countElements++;
			}

		}
		cout << "hi" << endl;
		display(s3);
		cout << endl;
	}



}
// void display(Sparse* sp)
// {
// 	for (int i = 0; i <= sp->elementArr[0].data  ; ++i)
// 	{
// 		cout << sp->elementArr[i].row << " " << sp->elementArr[i].col << "  " << sp->elementArr[i].data;
// 		cout  << endl;

// 	}

// }

void transpose(Sparse *s1, Sparse*s3)
{
	//no. of elements in each col of s1
	int col_count_s1 = s1->elementArr[0].col + 1;
	int *col_s1 = new int [col_count_s1] {0};
	col_s1[0] = s1->elementArr[0].col;
	for (int i = 1; i <= s1->elementArr[0].data; ++i)
	{
		col_s1[s1->elementArr[i].col]++;
		//it will act as row element for s2
	}

	// for (int i = 0; i < col_count_s1; ++i)
	// {
	// 	cout << col_s1[i] << " ";
	// 	//it will act as row element for s2
	// }
	cout << endl;
	int *row_index = new int [col_count_s1 + 1];
	//one size greater than col_s1;
	row_index[1] = 1;
	for (int i = 2; i <= col_count_s1   ; ++i)
	{
		row_index[i] = row_index[i - 1] + col_s1[i - 1];
	}
	// for (int i = 0 ; i <= col_count_s1; ++i)
	// {
	// 	cout << row_index[i] << " ";
	// 	//it will act as row element for s2
	// }
	cout << endl;
	cout << endl;


	for (int i = 0; i <= s1->elementArr[0].data; ++i)
	{
		if (i == 0)
		{
			s3->elementArr[i].row = s1->elementArr[i].col;
			s3->elementArr[i].col = s1->elementArr[i].row;
			s3->elementArr[i].data = s1->elementArr[i].data;
		}
		else
		{
			int r_index  = s1->elementArr[i].col;
			int index = row_index[r_index];
			s3->elementArr[index].row = s1->elementArr[i].col;
			s3->elementArr[index].col = s1->elementArr[i].row;
			s3->elementArr[index].data = s1->elementArr[i].data;
			row_index[r_index]++;
		}
	}
}

void matrix(Sparse *s)
{
	int k = 1;
	for (int i = 1; i <= s->elementArr[0].row; ++i)
	{
		for (int j = 1; j <= s->elementArr[0].col; j++)
		{
			if (i == s->elementArr[k].row && j == s->elementArr[k].col)
				cout << s->elementArr[k++].data << " ";
			else
				cout << "0 ";
		}
		cout << endl;
	}
}


void multiply ( Sparse *s1 , Sparse *s2 , Sparse *s3)
{
	Sparse *s4 = new Sparse();
	display(s1); cout << endl;
	display(s2); cout << endl;
	s3->insert(s1->elementArr[0].row , s2->elementArr[0].col , 0 );
	for (int i = 1; i <= s1->elementArr[0].data; i++ )
	{

		int sum = 0;

		for (int j = 1; j <= s2->elementArr[0].data; j++)
		{
			int sum = 0;
			if (s1->elementArr[i].col == s2->elementArr[j].row)
			{
				sum = s1->elementArr[i].data * s2->elementArr[j].data;
				s3->insert(s1->elementArr[i].row , s2->elementArr[j].col , sum);
			}
		}
	}


	display(s3);


	cout << endl;
	cout << endl;
	transpose (s3, s4);//saved in new transpose matrix s4
	transpose (s4, s3);//saved in new transpose matrix s3
	//now s3 is in sorted order
	Sparse *s5 = new Sparse();
	for (int i = 0; i <= s3->elementArr[0].data; ++i)
	{
		if (i == 0)
		{
			s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, 0);
		}
		else if (i == 1)
		{
			s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, s3->elementArr[i].data);
		}
		else
		{
			int flag = 0;
			for (int k = 1; k <= s5->elementArr[0].data; k++)
			{
				if (s3->elementArr[i].row == s5->elementArr[k].row && s3->elementArr[i].col == s5->elementArr[k].col)
				{
					s5->elementArr[k].data += s3->elementArr[i].data;
					flag = 1;
					break;
				}
			}
			if (flag == 0)
			{
				s5->insert(s3->elementArr[i].row, s3->elementArr[i].col, s3->elementArr[i].data);

			}
		}

	}





	display(s3);
	cout << endl;
	s3 = s5;
	display(s3);
	cout << endl;
	matrix(s3);
	cout << s3->elementArr[0].row ;

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	int type;
	int op;
	int R1, R2, C1, C2;
	// do {
	cout << "What operation do you want to perform? " <<
	     " Select Option number. Enter 0 to exit." << endl;
	cout << "1. Array" << endl;
	cout << "2. Link list" << endl;
	cout << "Enter datastructure to use :\n";
	cin >> type;
	cout << "Type of operation :\n";
	cout << "1. Addition" << endl;
	cout << "2. Transpose " << endl;
	cout << "3. Multiplication  " << endl;
	cin >> op;
	int data;


	Sparse *sp1 = new Sparse();
	Sparse *sp2 = new Sparse();

	int n = 0;
	if (type == 1 )
	{
		//MATRIX 1
		cin >> R1 >> C1;
		sp1->insert(R1, C1, 0);// FOR Checking #r , #c , #elements
		for (int i = 1; i <= R1; ++i)
		{
			for (int j = 1; j <= C1; ++j)
			{
				cin >> data;
				if (data != 0)
					sp1->insert(i, j, data);
			}
		}
		if (op == 2)//transpose
		{
			Sparse*sp3 = new Sparse();
			transpose(sp1 , sp3);
			display(sp1);
			cout << endl;
			display(sp3);
			cout << endl;
			// sp1 = sp3; //after transpose just change the pointer
			matrix(sp1);
			cout << endl;
			matrix(sp3);
			cout << endl;
		}

		if (op == 1 || op == 3)//addition or mul
		{
			//MATRIX 2
			cin >> R2 >> C2;
			sp2->insert(R2, C2, 0);
			for (int i = 1; i <= R2; ++i)
				for (int j = 1; j <= C2; ++j)
				{
					cin >> data;
					if (data != 0)
						sp2->insert(i, j, data);
				}
			Sparse *sp3 = new Sparse();;
			if (op == 1) //add
			{
				if (R1 != R2 || C1 != C2)
				{
					cout << " wrong matrix sizes: \n";
					return 0;
				}
				add(sp1, sp2, sp3);
				cout << endl;
				display(sp1);
				cout << endl;
				display(sp2);
				cout << endl;
				display(sp3);
				cout << endl;
				cout << sp1->elementArr[0].data << endl;
				cout << sp2->elementArr[0].data << endl ;
				cout << sp3->elementArr[0].data << endl ;
				matrix(sp1);
				cout << endl;
				matrix(sp2);
				cout << endl;
				matrix(sp3);
				cout << endl;
			}
			else if (op == 3) //multiplication
			{
				if (C1 != R2)
				{
					cout << " wrong matrix sizes: \n";
					return 0;
				}
				multiply(sp1, sp2, sp3);
				cout << endl;
				// 	display(sp1);
				// 	cout << endl;
				// 	display(sp2);
				// 	cout << endl;
				// 	display(sp3);
				// 	cout << endl;
				// 	matrix(sp1);
				// 	cout << endl;
				// 	matrix(sp2);
				// 	cout << endl;
				// 	matrix(sp3);
				// 	cout << endl;
			}





			// for (int i = 0; i < 5 ; ++i)
			// {
			// 	cout << sp3->elementArr[i].row << " " << sp3->elementArr[i].col << "  " << sp3->elementArr[i].data;
			// 	cout  << endl;
			// }
			// cout << sp3->elementArr[0].row << " " << sp3->elementArr[0].col << "  " << sp3->elementArr[0].data;


		}
	}





// 	switch (option) {
// 	case 0:
// 		break;
// 	case 1:
// 		cout << "Enter VALUE of TREE sp to INSERT in AVL Tree: ";
// 		cin >> val;

// 		obj_avl.root = obj_avl.insert(val);
// 		cout << endl;
// 		break;

// 	case 2:
// 		cout << "Enter VALUE of TREE sp to delete in AVL Tree: ";
// 		cin >> val;
// 		obj_avl.root = obj_avl.deleteData(val);
// 		break;


// 	case 3:
// 		cout << "Enter VALUE of TREE sp to search in AVL: ";
// 		cin >> val;
// 		cout << obj_avl.search(val);
// 		break;

// 	default:
// 		cout << "Enter Proper Option number " << endl;
// 	}

// } while (option != 0);



	return 0;
}
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double a, b, c, ex, bac, sum1, sr, sum2, prod, quo;
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    
    cout << "Using the Quadratic Formula.\n"
    << "Please enter the value of a: ";
    cin >> a;
    cout << "Please enter the value of b: ";
    cin >> b;
    cout << "Please enter the value of c: ";
    cin >> c;
    
    ex = pow(b,2);
    bac = -4 * a * c;
    sum1 = ex + bac;
    sr = sqrt(sum1);
   
    if (sr > 0) { 
        sum2 = -b + sr;
        prod = 2 * a;
        quo = sum2 / prod;
        cout << "x = " << quo << endl;
    }
    
    else {
    cout << " - Undefined -" << endl 
        << "The square root of a negative number does not exist" << endl 
        << "in the set of real numbers." << endl;
    }
    
    return 0;
}
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double a, b, c, ex, bac, sum1, sr, sum2, prod, quo;
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    
    cout << "Using the Quadratic Formula.\n"
    << "-----------------------------------\n" 
    << "Please enter the value of a: ";
    cin >> a;
    cout << "Please enter the value of b: ";
    cin >> b;
    cout << "Please enter the value of c: ";
    cin >> c;
    
    ex = pow(b,2);
    cout << "-----------------------------------\n" 
    << "Evaluate the power of b,\n"
    << b << " ^ 2 = " << ex << endl;
    
    bac = -4 * a * c;
    cout << "Calculate the product of -4(a)(c), \n"
    << "-4(a)(c) = -4(" << a << ")("
    << c << ") = " << bac << endl;
    
    sum1 = ex + bac;
    cout << "Add the product of b and -4(a)(c), \n"
    << ex << " + " << bac << " = " << sum1 << endl;
    
    sr = sqrt(sum1);
    cout << "Evaluate the square root of " << sum1 << "," <<endl
    << "√" << sum1 << " = " << sr << endl;
   
    if (sr > 0) { 
        sum2 = -b + sr;
        cout << "Calculate the sum of -" << b << " and " << sr << "," << endl
        << "-" << b << " + " << sr << " = " << sum2 << endl;
    
        prod = 2 * a;
        cout << "Multiply for the product of 2 and (a), \n"
        << "2(" << a << ") = " << prod << endl;
    
        quo = sum2 / prod;
        cout << "Calculate the quotient of " << sum2 << " and "<< prod << "," << endl
        << sum2 << " / " << prod << " = " << quo << endl
        << "-----------------------------------\n"
        << "x = " << quo << endl 
        << "-----------------------------------\n";
    }
    
    else {
        cout << "-----------------------------------\n" 
        << " - Undefined -" << endl 
        << "The square root of a negative number does not exist" << endl 
        << "in the set of real numbers." << endl 
        << "-----------------------------------\n";
    }
    
    return 0;
}
#include<iostream>
using namespace std;
void getMinMax(int arr[], int arrSize, int *minVal, int *maxVal)
{
  for (int i = 1; i < arrSize; i++)
  {
    if (arr[i] > *maxVal)
    {
      *maxVal = arr[i];
    }
    if (arr[i] < *minVal)
    {
      *minVal = arr[i];
    }

  }
}
int main()
{
  int arr[5] = { 1, 2, -9, 45, 0};
  int max = arr[0];
  int min = arr[0];
  getMinMax(arr, 5, &min, &max);
  cout << min << " " << max << endl;
  return 0;
}
#include<iostream>
using namespace std;
int main(){
  int arr[5] = { 1,2,3,4,5 };
  cout << arr << endl;
  return 0;
}
#include<iostream>
using namespace std;
void printData(void *ptr, char dataType){
  switch (dataType)
  {
    case 'i':
      cout << *((int *)ptr) << endl;
      break;

    case 'c':
      cout << *(static_cast<char *>(ptr)) << endl;
      break;
  }
}
int main(){
  int n = 7;
  char b = 'b';
  printData(&n, 'i');
  printData(&b, 'c');
  return 0;
}
#include<iostream>
using namespace std;
int main(){
  int *ptr;
  *ptr = 6;
  cout << *ptr << endl;
  return 0;
}
#include<iostream>
using namespace std;
int main(){
  int n = 6;
  float *ptr = &n;
  *ptr = 10;
  cout << *ptr << " " << n << endl;
  return 0;
}
#include<iostream>
using namespace std;
int main(){
  int n = 6;
  int *ptr = &n;
  *ptr = 10;
  cout << *ptr << " " << n << endl;
  return 0;
}
#include<bits/stdc++.h>
using namespace std;

class BinaryTreeNode
{
public:
	int data;
	BinaryTreeNode * left;
	BinaryTreeNode *right;
	int height;

	// BinaryTreeNode()
	// {
	// 	data = 0;
	// 	left = NULL;
	// 	right = NULL;
	// }
	BinaryTreeNode(int data)
	{
		this->data = data;
		left = NULL;
		right = NULL;
	}
	~BinaryTreeNode()
	{
		delete left;
		delete right;
	}

};


class AVL
{
public:
	BinaryTreeNode *root;
	AVL()
	{
		this->root = NULL;
	}


	int getheight(BinaryTreeNode* root)
	{
		if (root == NULL)
			return 0;

		return 1 + max(getheight(root->left) , getheight(root->right));
	}

	int getbalanceFactor(BinaryTreeNode* node)
	{
		if ( node == NULL)
			return 0;
		return getheight(node->left) - getheight(node->right);
	}

	BinaryTreeNode* rightRotate(BinaryTreeNode* y)
	{


		/*

			 	y           x
			   / \		   / \
			  x   T3 ---->T1  y
			 / \			 / \
			T1  T2			T2  T3
			*/
		BinaryTreeNode* x = y->left;
		BinaryTreeNode *T2 = x->right;
		// T1 & T3 not required because their ptr not changes
		x->right = y;
		y->left = T2;
		//updation to heights
		// y->height = 1 + max(getHeight(y->left) , getHeight(y->right));
		// X->height = 1 + max(getHeight(x > left) , getHeight(x->right));
		return x;
		//as now x is root node
	}
	BinaryTreeNode* leftRotate(BinaryTreeNode* x)
	{
		/*  	y           x
			   / \		   / \
			  x   T3 <--- T1  y
			 / \			 / \
			T1  T2			T2  T3
			*/
		//before rotation
		BinaryTreeNode* y = x->right;
		BinaryTreeNode *T2 = y->left;
		// T1 & T3 not required because their ptr not changes
		//changes to rotation
		y->left = x;
		x->right = T2;
		//updation to heights
		// y->height = 1 + max(getHeight(y->left) , getHeight(y->right));
		// X->height = 1 + max(getHeight(x > left) , getHeight(x->right));
		return y;
		//as now y is root node
	}


// 1. insert
private:
	BinaryTreeNode * insert(BinaryTreeNode* node, int data)
	{
		if ( node == NULL)
		{
			BinaryTreeNode* newnode = new BinaryTreeNode (data);
			return newnode;
		}

		if (data <= node->data)
			node->left = this->insert( node->left , data);
		else if (data > node->data)
			node->right = this->insert(node->right , data);
		else
			return node;

		// node->height = 1 + max(getHeight(node > left) , getHeight(node->right));
		// //height update krni padegi as it is req in balfac

		int balfac =  getbalanceFactor(node) ;
		// left left case ..bf= leftH -rightH >1
		if (balfac > 1 && data < node->left->data)
		{	//insertion takes place at LST
			return this->rightRotate(node);
		}

		//right right case , bf= leftH -rightH < -1
		if (balfac < -1 && node->right->data < data)
		{
			return this->leftRotate(node);
		}

		//left rightcase,bf= leftH -rightH >1
		if (balfac > 1 && node->left->data < data)//bf>1 tabhi root k left me imbal
		{
			/*
				 r= 30          30     25
				   /   			/	  /	  \
				 20	   	   	  25     20	  30
				  \			 /
			  data=25		20
			*/

			node->left = leftRotate(node->left); //
			return this->rightRotate(node);
		}


		//right left case bf= leftH -rightH <-1
		if (balfac > 1 && node->left->data < data)//bf>1 tabhi root k left me imbal
		{
			/*
				 r= 20           20         25
				      \   		   \       /  \
				 	  30	   	    25    20   30
					 /	             \
			  data=25		          30
			*/

			node->right = rightRotate(node->right); //
			//now RR imbalance
			return this->leftRotate(node);
		}
		return node;
	}




public:
	BinaryTreeNode* insert ( int data)
	{
		// BinaryTreeNode *node = new BinaryTreeNode(data);
		this->root = insert(this->root , data);
		return  root;
	}



	//2. delete : trick think node as leaf or any internal node
private:
	BinaryTreeNode * deleteData(BinaryTreeNode* node , int data)
	{
		if (node == NULL)
			return NULL;
		if (data < node->data)
		{
			node ->left = deleteData(node->left , data);
			return node;
		}
		else if (node->data < data)
		{
			node->right = deleteData(node -> right , data);
			return node;
		}
		else // if value matche
		{
			if (node->left == NULL && node->right == NULL) //a leaf
			{
				delete node;
				return NULL;
			}
			else if (node->left == NULL)
			{
				BinaryTreeNode *rightsubtree = node->right;
				node ->right = NULL;
				delete node;
				return rightsubtree;
			}
			else if (node->right == NULL)
			{
				BinaryTreeNode *leftsubtree = node->left;
				node->left = NULL;
				delete node;
				return leftsubtree;
			}
			else // both rst and lst exists
			{
				BinaryTreeNode * minNode = node ->right;
				while (minNode->left != NULL)
				{
					minNode = minNode->left;
				}
				int minFromRST = minNode->data;
				node->data = minFromRST;
				node->right = deleteData(node->right, minFromRST);
				return node;
			}
		}


		int balfac = getbalanceFactor(node);

		if (balfac == 2 && getbalanceFactor(node->left ) >= 0)
		{
			/*
				 r= 30         			 30                 30      20
				   / \  				/ \	                /	   /  \
				 20	  40**del 	or    20   40 **del =     20	  10   30
				 /\					 /					 /
			   10  25				10					10
			*/
			// 25 case will be taken care by rightrotate

			BinaryTreeNode*newnode = rightRotate(node);
			return newnode;
		}
		else if (balfac == 2 && getbalanceFactor(node->left) == -1)
		{
			/*
				 r= 30         			 30                        25
				   / \  				/ 	                 	  /  \
			(-1) 20	  40**del or (-1) 20  	lr imbalance	=    20	  30
				  \					 	\
			      25					 25
			*/
			// 25 case will be taken care by rightrotate

			node->left = leftRotate(node->left);
			BinaryTreeNode*newnode = rightRotate(node);
			return newnode;
		}
		else if (balfac == -2 && getbalanceFactor(node->right) <= 0)
		{
			/*
			 20			20		   	 30
			/ \			/ \		     / \
			del 10  30  del(10) 30        20  40
			   /\			 \
			  25 40 		 40

			  // 25 case will be taken care by leftrotate
			*/
			BinaryTreeNode * newnode = leftRotate(node);
			return newnode;
		}
		else if (balfac == -2 && getbalanceFactor(node->right) == 1)
		{
			/*
			 20			 	 20                25
			/ \			 	   \			   / \
			del 10  30 (1)          30	rl imbal  20  30
			   / 			 	/
			  25 		  	  25
			  	*/
			node->right  =  leftRotate(node->right);
			BinaryTreeNode * newnode = leftRotate(node);
			return newnode;
		}
	}
public:
	BinaryTreeNode* deleteData( int data)
	{
		this->root = deleteData(this->root , data);
		return root;
	}


	//3.search
private:
	bool search(BinaryTreeNode* node , int data)
	{
		if (node == NULL)
			return false;
		if (node->data == data)
			return true;
		else if (node->data < data)
			return search (node->right , data);
		else
			return search(node->left , data);
	}
public:
	bool search(int data)
	{
		return search(root, data);
	}



	//4. occurences
private :
	int count_occurence(BinaryTreeNode*node , int data)
	{
		if (node == NULL)
			return 0;

		if (node ->data == data)
			return 1 + count_occurence(node->left, data) + count_occurence(node->right, data);
		else if (node->data < data)
			return count_occurence(node->right, data);
		else if (data < node->data )
			return count_occurence(node->left, data);
		return 0;
	}

public:
	int count_occurence(int data)
	{
		return count_occurence(this->root , data);
	}

private:
	int upper_bound(BinaryTreeNode*node, int data)
	{
		if (node == NULL)
			return 0;

		//leaf data=15  leaf=14(node->data)(rightmost)
		if (node->left == NULL && node->right == NULL && node->data <= data)
		{
			return 0;
		}

		//data=12 ex=  null (12) 13(root)  or   11 (12) 13(root) or 12 (12) 13(root)
		if ((data < node->data && node->left == NULL) || (node->left->data <= data && data < node->data))
		{
			return node->data;
		}
		//data=12  11(root) (12)  or   12(root) (12)
		if (node->data <= data)
		{	//node->left->data se compare wali cond already checked above
			return upper_bound(node->right, data);
		}
		else if (data < node->data)
		{
			//data=12  14(root->left)  15(root)
			return upper_bound(node->left , data);
		}
		return 0;
	}
public:
	int upper_bound(int data)
	{
		return upper_bound(this->root , data);
	}


private:
	int lower_bound(BinaryTreeNode*node, int data)
	{
		if (node == NULL)
			return 0;

		//reachd to leaf data =14 leaf=15(node->data) leftmost node
		if (node->left == NULL && node->right == NULL &&  data < node->data )
		{
			return 0;
		}
		//itsef a leaf
		if (node->left == NULL  && node->right == NULL &&  data == node->data)
			return node->data;

		//data=12  11(root) null or   11(root) 13  or  12(root)   13
		if ((node->data < data   && node->right == NULL) || (node->data < data && data < node->right->data))
		{
			return node->data;
		}
		//data=12  12 13(root)  or   (12)   12(root)
		if ( data <= node->data)
		{
			return lower_bound(node->left, data);
		}
		else if ( node->data < data)
		{	//node->right->data se compare wali cond already checked above
			//data=12  10(root)  11(root->right) 12
			return lower_bound(node->right, data);
		}
		return 0;
	}
public:
	int lower_bound(int data)
	{
		return lower_bound(this->root , data);
	}

public:
	int lesser_bound(BinaryTreeNode*node , int data)
	{
		if (node == NULL)
			return 0;

		//reachd to leaf data =14 leaf=15(node->data) leftmost node
		if (node->left == NULL && node->right == NULL &&  data < node->data )
		{
			return 0;
		}
		//itsef a leaf
		if (node->left == NULL  && node->right == NULL &&  data == node->data)
			return 0;

		//data=12  11(root) null or   11(root) 13  or  12(root)   13
		if ((node->data < data   && node->right == NULL) || (node->data < data && data < node->right->data))
		{
			return node->data;
		}
		//data=12  12 13(root)  or   (12)   12(root)
		if ( data <= node->data)
		{
			return lesser_bound(node->left, data);
		}
		else if ( node->data < data)
		{	//node->right->data se compare wali cond already checked above
			//data=12  10(root)  11(root->right) 12
			return lesser_bound(node->right, data);
		}
		return 0;
	}



private:
	int closest_element(BinaryTreeNode*node , int data)
	{
		if (node == NULL)
			return -1;
		if (node->data == data)
			return node->data;
		int x = upper_bound(node, data);
		int y = lesser_bound(node, data);
		//y----------data ---------x
		if (y != 0 && x != 0)
			return (data - y) > (x - data) ? x : y;
		else if (y == 0 && x != 0)
			return x;
		else
			return y;

	}
public:
	int closest_element(int data)
	{
		return closest_element(this->root , data);
	}


private:
	BinaryTreeNode* Element_Kth_largest(BinaryTreeNode*node , int &k)
	{
		// if (node == NULL || c > k )
		// 	return -1;
		// //reverse inorder traversal
		// Element_Kth_largest(node->right, k, c );
		// c++;
		// if (k == c)
		// 	return node->data;
		// Element_Kth_largest(node->left, k , c);
		// return -1;
		if (node == NULL)
			return NULL;

		BinaryTreeNode* newnode = Element_Kth_largest(node->right, k);
		if (newnode  != NULL)
			return newnode;
		k--;

		if (k == 0)
			return node;

		return Element_Kth_largest(node->left, k);
	}
public:
	int Element_Kth_largest(int k)
	{

		BinaryTreeNode*newnode = Element_Kth_largest(this->root, k );
		int c = -1;
		if (newnode == NULL)
			return c;
		else
			c = newnode->data;
		return c;
	}

private:
	int count_range(BinaryTreeNode*node, int eLeft, int eRight)
	{
		if (node == NULL)
			return 0;
		// if (node->data == eLeft && node->data == eRight)
		// 	return 1;

		int count = 0;
		// Special Optional case for improving efficiency
		// if (eLeft <= node->data  && node->data <= eRight)
		// 	return 1 + count_range(node->left , eLeft, eRight) + count_range(root->right , eLeft, eRight);

		if (eLeft <= node->data  && node->data <= eRight)
			count += 1;
		count += count_range(node->left , eLeft, eRight);

		return count + count_range(node->right , eLeft, eRight);
		// else if (node->data < eLeft )
		// 	return count_range(node->right, eLeft, eRight)	;
		// else
		// 	return count_range(root->left , eLeft, eRight);
	}
public:
	int count_range(int eLeft , int eRight)
	{
		return count_range(this->root, eLeft, eRight);
	}


};



void preorder(BinaryTreeNode * root)
{
	if (root == NULL)
		return;
	cout << root->data << " ";
	preorder(root->left);
	preorder(root->right);
}
void inorder(BinaryTreeNode * root)
{
	if (root == NULL)
		return;
	inorder(root->left);
	cout << root->data << " ";
	inorder(root->right);
}



int main()
{
#ifdef ONLINE_JUDGE
	freeopen("input.txt", "r", stdin);
	freeopen("output.txt", "r", stdin);
#endif


	AVL obj_avl;


	//segmentationfault state
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(31);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(60);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(30);
	// obj_avl.root = obj_avl.insert(40);


	// int option;
	// do {
	// 	cout << "What operation do you want to perform? " <<
	// 	     " Select Option number. Enter 0 to exit." << endl;
	// 	cout << "1. Insert Node" << endl;
	// 	cout << "2. Delete Node" << endl;
	// 	cout << "3. Search Node" << endl;
	// 	cout << "4.  " << endl;
	// 	cout << "5.  " << endl;
	// 	cout << "6.  " << endl;
	// 	cout << "0. Exit Program" << endl;
	// 	cin >> option;
	// 	//Node n1;
	// 	int val;

	// 	switch (option) {
	// 	case 0:
	// 		break;
	// 	case 1:
	// 		cout << "Enter VALUE of TREE NODE to INSERT in AVL Tree: ";
	// 		cin >> val;

	// 		obj_avl.root = obj_avl.insert(val);
	// 		cout << endl;
	// 		break;

	// 	case 2:
	// 		cout << "Enter VALUE of TREE NODE to delete in AVL Tree: ";
	// 		cin >> val;
	// 		obj_avl.root = obj_avl.deleteData(val);
	// 		break;


	// 	case 3:
	// 		cout << "Enter VALUE of TREE NODE to search in AVL: ";
	// 		cin >> val;
	// 		cout << obj_avl.search(val);
	// 		break;

	// 	default:
	// 		cout << "Enter Proper Option number " << endl;
	// 	}

	// } while (option != 0);




	int n = 5;
	int ins[11] = {1, 12, 23, 34, 45, 63, 67, 30, 89, 39, 4};
	for (int i = 0; i < n; ++i)
	{
		obj_avl.root = obj_avl.insert(ins[i]);
	}


	cout << endl;
	cout << "\npreorder :";
	preorder(obj_avl.root);
	cout << "\ninorder  :";
	inorder(obj_avl.root);
	cout << endl;

	int arr[10] = { -1, 9, 20, 23 , 44 , 5, 6 , 40, 50, 67 };
	int k = 7;
	int lar[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	// for (int i = 0; i < k; ++i)
	// {
	// 	int u;
	// 	int e = lar[i];
	// 	cout << "\nkth largest element : " << e  ;
	// 	u = obj_avl.Element_Kth_largest(e);
	// 	cout << " is:" << u;
	// }
	cout << endl;

	for (int i = 2; i < 8; ++i)
	{
		int l = arr[i];
		int h = arr[i + 1];
		if (l > h)
			swap(l, h);
		cout << "Count of nodes between [" << l << ", " << h << "] is " << obj_avl.count_range(l, h) << endl;
	}

	// for (int i = 0; i < k; ++i)
	// {
	// 	int u;
	// 	int e = arr[i];
	// 	cout << "\nclosest element to : " << e  ;
	// 	u = obj_avl.closest_element(e);
	// 	cout << " is:" << u;
	// }
	// cout << endl;

	// for (int i = 0; i < k; ++i)
	// {
	// 	int u;
	// 	int e = arr[i];
	// 	cout << "\nlower bound of : " << e  ;
	// 	u = obj_avl.lower_bound(e);
	// 	cout << " is:" << u;
	// }
	// cout << endl;
	// for (int i = 0; i < k; ++i)
	// {
	// 	int u;
	// 	int e = arr[i];
	// 	cout << "\nupper bound of :" << e  ;
	// 	u = obj_avl.upper_bound(e);
	// 	cout << ":" << u;
	// }


	// int count_o[10] = {30, 55, 38, 40, 60, 89, 31, 35, 47, 69};
	// for (int i = 0; i < 10; ++i)
	// {
	// 	int s = count_o[i];
	// 	int r  ;

	// 	cout << "\n\ncount:" << s;
	// 	r = obj_avl.count_occurence(s);
	// 	cout << "\nnumber of  " << s << " are :" << r  ;
	// }



	// int find[10] = {30, 55, 38, 40, 60, 89, 31, 35, 47, 69};
	// for (int i = 0; i < 10; ++i)
	// {
	// 	int s = find[i];
	// 	int r = 0;
	// 	cout << "\n\nsearch:" << s;
	// 	r = obj_avl.search(s);
	// 	if (r)
	// 		cout << "\nyes " << s << " is found";
	// 	else
	// 		cout << "\nno. :" << s << " is not found";
	// }


	// cout << endl;
	// cout << "\npreorder :";
	// preorder(obj_avl.root);
	// cout << "\ninorder  :";
	// inorder(obj_avl.root);

	// int del[10] = {50, 38, 60, 56, 3, 30, 60};
	// for (int i = 0; i < 10; ++i)
	// {
	// 	int v = find[i];
	// 	int r = 0;
	// 	cout << "\n\ndelete :" << v << endl;
	// 	r = obj_avl.search(v);
	// 	if (!r)
	// 	{

	// 		cout << "no.    :" << v << " is not found";
	// 	}
	// 	else
	// 	{
	// 		obj_avl.root = obj_avl.deleteData(v);
	// 		cout << "sucessfully deleted :" << v << endl;
	// 		cout << "preorder :";
	// 		preorder(obj_avl.root);
	// 		cout << "\ninorder  :";
	// 		inorder(obj_avl.root);
	// 	}

	// }





	return 0;
}
#include <iostream>
using namespace std;
int main()
{
  int array[] = {10, 20, 30};
  cout << -2[array];
  return 0;
}
#include<iostream>
using namespace std;
int main()
{
  int a = 5, b = 10, c = 15;
  int arr[3] = {&a, &b, &c};
  cout << *arr[*arr[1] - 8];
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  char *ptr;
  char Str[] = "abcdefg";
  ptr = Str;
  ptr += 4;
  cout << ptr;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  char arr[20];
  int i;
  for(i = 0; i < 10; i++)
    *(arr + i) = 65 + i;
  cout << arr;
  return(0);
}
#include <iostream>
using namespace std;
int main()
{
  int a = 5, b = 10, c = 15;
  int *arr[ ] = {&a, &b, &c};
  cout << arr[1];
  return 0;
}
string* x, y;
int (*fp)(char*)
#include <iostream>
using namespace std;
enum channel {star, sony, zee};
enum symbol {hash, star};
int main()
{
  int i = 0;
  for (i = star; i <= zee; i++) 
  {
    printf("%d ", i);
  }
  return 0;
}
#include <iostream>
using namespace std;
enum colour 
{
  green, red, blue, white, yellow, pink
};
int main()
{
  cout << green << " " <<
  red << " " << blue << " " << 
  white << " " << yellow << " " << pink;
  return 0;
}
#include <iostream>
using namespace std;
enum test 
{
  A = 12, B, C
};
int main()
{
  cout << A << " " << B << " " << C;
  return 0;
}
#include <iostream>
using namespace std;
enum  cat 
{
  temp = 6
};
int main()
{
  int age = 12;
  age /= temp;
  cout << "If you were cat, you would be " << age << endl;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  void a = 10, b = 10;
  int c;
  c = a + b;
  cout << c;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  void a;
  a = 5;
  cout << a << endl;
  return 0;
}
// program 1
#include <iostream>
using namespace std;
int main()
{
  register int i = 1;
  int ptr = i;
  cout << ptr;
  return 0;
}

// program 2
#include <iostream>
using namespace std;
int main()
{
  register int i = 1;
  int *ptr = &i;
  cout << *ptr;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  int i = 6;
  int l = i / -5;
  int k = i % -5;
  cout << l << " " << k;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  int a = 8;
  cout << "AND integer 'a' with 'true' :" << (a && true);
  cout << endl;
  cout << "AND integer 'a' with 'true' :" << a && true;
  return 0;
}
#include <iostream>
using namespace std;
int main()
{
  unsigned int x = 1;
  int y = -2;

  if(x > y) 
  {
    cout << "x is greater";
  }
  else 
  {
    cout << "y is greater";
  }      
}
#include <iostream>
using namespace std;
int main()
{
  int p;
  bool a = true;
  bool b = false;
  int x = 10;
  int y = 5;
  p = ((x | y) + (a + b));
  cout << p << endl;
  return 0;
}
#include <iostream>
using namespace std;
int f(int p, int q)
{
  if (p > q)
    return p;
  else
    return q;
}
main()
{
  int a = 5, b = 10;
  int k;
  bool x = true;
  bool y = f(a, b);
  k =((a * b) + (x + y));
  cout << k;
}
#include <iostream>
using namespace std;
class Point
{
    int x, y;
  public:
   Point(int i = 0, int j =0)
   { x = i; y = j;  }
   int getX() const { return x; }
   int getY() {return y;}
};
 
int main()
{
    const Point t;
    cout << t.getX() << " ";
    cout << t.getY();
    return 0;
}
#include <iostream>
class Test
{
   public:
     void fun();
};
static void Test::fun()   
{
    std::cout<<"fun() is static";
}
int main()
{
    Test::fun();   
    return 0;
}
#include<iostream>
using namespace std;
class Test
{
   private:
     static int count;
   public:
     Test& fun(); 
};
int Test::count = 0;
Test& Test::fun()
{
    Test::count++;
    cout << Test::count << " ";
    return *this;
}
int main()
{
    Test t;
    t.fun().fun().fun().fun();
    return 0;
}
#include <iostream>
using namespace std;
​
int main() {
  int myAge = 35;
  cout << "I am " << myAge << " years old.";
  return 0;
}
​
#include <iostream>
using namespace std;
class A
{
   private:
     int x;
   public:
     A(int _x)  {  x = _x; }
     int get()  { return x; }
};
class B
{
    static A a;
  public:
   static int get()
   {  return a.get(); }
}; 
int main(void)
{
    B b;
    cout << b.get();
    return 0;
}
#include <iostream>
using namespace std;
class Player
{
  private:
    int id;
    static int next_id;
  public:
    int getID() { return id; }
    Player()  {  id = next_id++; }
};
int Player::next_id = 1;
int main()
{
  Player p1;
  Player p2;
  Player p3;
  cout << p1.getID() << " ";
  cout << p2.getID() << " ";
  cout << p3.getID();
  return 0;
}
#include <iostream>
using namespace std;
class Test
{
    static int x;
  public:
    Test() { x++; }
    static int getX() {return x;}
};
int Test::x = 0;
int main()
{
    cout << Test::getX() << " ";
    Test t[5];
    cout << Test::getX();
}
// Program 1
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	cout<<"Hello World";
	return 0;
}

// Program 2
#include <iostream>
int main(int argc, char const *argv[])
{
	std::cout<<"Hello World";
	return 0;
}
#include<stdio.h>
struct STRUCT
{
  int static a;
};
int main()
{
  struct STRUCT s;
  return 0;
}
#include<stdio.h>
struct STRUCT
{
  int a;
  int func()
  {
      printf("HELLO THIS IS STRUCTURE\n");
  }
};
int main()
{
  struct STRUCT s;
  s.func();
  return 0;
}
#include<iostream>
using namespace std;
int main ()
{
   int cin;
   cin >> cin;
   cout << "cin: " << cin;
   return 0;
}
#include<iostream>
using namespace std;
int x[100];
int main()
{
    cout << x[99] << endl;
}
#include<iostream>
using namespace std;
class A
{
  ~A(){
     cout<<"Destructor called\n";
   }
};
int main()
{
    A *a1 = new A();
    A *a2 = new A();
    return 0;
}
#include<iostream>
using namespace std;
class A
{
  ~A(){
    cout<<"Destructor called\n";
  }
};
int main()
{
    A a;
    return 0;
}
#include<iostream>
using namespace std;
int x = 1;
int main()
{
    int x = 2;
    {
        int x = 3;
        cout << ::x << endl;
    }
    return 0;
}
// First program
#include<stdio.h>
int main(int argc, char const *argv[])
{
	printf("%d\n", (int)sizeof('a'));
	return 0;
}

// Second program
#include<stdio.h>
int main(int argc, char const *argv[])
{
	char a = 'a';
	printf("%d\n", (int)sizeof(a));
	return 0;
}
#include <stdio.h> 
void func()
{
	printf("Hello");
}
void main() 
{ 
	func();
	func(2);
}
#include <stdio.h> 
void func(void)
{
	printf("Hello");
}
void main() 
{ 
	func();
	func(2);
}
#include <stdio.h> 
void main() 
{ 
	printf("Hello World"); 
}
#include <stdio.h> 
int main(void) 
{ 
         int new = 5;
         printf("%d", new); 
}
int *p = malloc(10);
#include <stdio.h> 
int main(void) 
{
	const int j = 20; 
	int *ptr = &j;
	printf("*ptr: %d\n", *ptr); 
	return 0; 
}
#include<stdio.h> 
int main() 
{ 
   foo();
}  
int foo() 
{ 
   printf("Hello"); 
   return 0;  
}
int *ptr = new int;
delete ptr;
delete ptr;
int *ptr = NULL;
delete ptr;
#include <iostream>
using namespace std;
 
class A 
{
  int a;
  A() {
    a = 5;
  }
};
 
int main()
{
  A *obj = new A;
  cout << obj->a;
}
#include<iostream> 
using namespace std; 
class Base { 
public: 
  Base() {
    cout << "Constructing Base \n";
  } 
  virtual~Base() {
    cout << "Destructing Base \n";
  }	 
}; 
class Derived: public Base { 
public:
  Derived() {
    cout << "Constructing Derived \n";
  } 
  ~Derived() {
    cout << "Destructing Derived \n";
  } 
}; 
 
int main(void) 
{ 
	Derived *d = new Derived(); 
	Base *b = d; 
	delete b; 
	return 0; 
}
#include<iostream> 
using namespace std; 
class Base { 
public: 
  Base() { 
    cout<<"Constructing Base \n"; 
  } 
  ~Base() { 
    cout<<"Destructing Base \n"; 
  }	 
}; 
class Derived: public Base { 
public: 
  Derived() {
    cout<<"Constructing Derived \n"; 
  } 
  ~Derived() {
    cout<<"Destructing Derived \n"; 
  } 
}; 
 
int main(void) 
{ 
	Derived *d = new Derived(); 
	Base *b = d; 
	delete b; 
	return 0; 
}
#include <iostream>
using namespace std;
class A{
public:
	A(){
		cout<<"Constructor called\n";
	   }
	~A(){
		cout<<"Destructor called\n";
	    } 
};
int main(int argc, char const *argv[])
{
	A *a = new A[5];
	delete[] a;
	return 0;
}
		SHOW DATABASES;
		USE ssd_assignment_2;

					CREATE TABLE PERSON (
							EmpID int NOT NULL PRIMARY KEY,
							NamePrefix varchar(10),
							FirstName varchar(255),
							MiddleInitial varchar(10),
							LastName varchar(255),
							Gender varchar(10),
							Email varchar(255),
							FatherName varchar(255),
							MotherName varchar(255),
							MotherMaidenName varchar(255),
							DOB varchar(12),
							TimeOfBirth varchar(12),
							WeightInKgs int,
							DateOfJoining varchar(12),TimeOfBirth
							Salary int,
							LastHike varchar(10),  
							PlaceName varchar(255),
							Country varchar(255),
							City varchar(255),
							State varchar(255),
							Region varchar(255)
						);
    -- SELECTING PERSON TABLE    
    select * from PERSON;
    
    
    
    --   1.A-----------------------------------
   -- CREATING  hike2022 table   
						   CREATE TABLE hike2022 (
							HikePK int AUTO_INCREMENT PRIMARY KEY,
							EmpIDFK INT ,
							FirstName varchar(255),
							LastName varchar(255),
							Gender varchar(255),
							WeightInKg INT,
							LastHike varchar(10),
							LastSalary INT,
							NewHike varchar(10),
							NewSalary INT ,
							FOREIGN KEY ( EmpIDFK) REFERENCES PERSON ( EmpID) 	
							);
    
 -- drop hike2022 table   
    drop table hike2022;
    
 -- INSERTING FROM TABLE PERSON 
				INSERT INTO hike2022 ( EmpIDFK, FirstName, LastName, Gender, WeightInKg,  LastHike, LastSalary )
								select EmpID,   FirstName, LastName, Gender, WeightInKgs, LastHike, Salary from  PERSON
                                       WHERE WeightInKgs < 50;
                  
   -- SELECTING FROM hike2022 table 
				SELECT * FROM hike2022;
    
 
  -- PROCEDURE FOR UPDATE_HIKE ---------
					drop PROCEDURE UPDATE_HIKE;
				DELIMITER //
					CREATE PROCEDURE UPDATE_HIKE()
					BEGIN
						UPDATE hike2022 
							SET NewHike = CONCAT(cast(CAST(substring(LastHike, 1, length(LastHike)-1) AS unsigned) + 2 as char) , "%" )
								where HikePK != 0 ;
					
						UPDATE hike2022
							SET Newsalary = LastSalary  + (LastSalary * CAST(substring(NewHike, 1, length(NewHike)-1) AS unsigned)) / 100 
								where HikePK != 0 ;
					END  //
				DELIMITER ;					
-- PROCEDURE ENDED

-- EXECUTE AND PRINT HIKE TABLE 
			call `UPDATE_HIKE`();
			select * from hike2022;
            
            -- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
            
            
            drop table PersonJoining;
    --  1.B.---------------------------------------------------------------------
    
					CREATE TABLE PersonJoining (
                       PJoinPK  int AUTO_INCREMENT PRIMARY KEY,
                       EmpIDFK INT ,
                       FirstName varchar(255),
                       LastName varchar(255),
                       DateofBirth varchar(12),
                       Age INT ,
                       DateofJoining varchar(255),
                       DayofJoining varchar(255),
                       MonthofJoining varchar(255),
                       YearofJoining varchar(255),
                       WorkExpinDays varchar(255) ,
                       FOREIGN KEY ( EmpIDFK) REFERENCES PERSON ( EmpID)
                       );
                       
     -- INSERTING FROM TABLE PERSON  TO PERSON JOINING
				INSERT INTO PersonJoining ( EmpIDFK, FirstName, LastName, DateofBirth, DateofJoining )
								     select EmpID,   FirstName, LastName, DOB, 		   DateofJoining
                                          from  PERSON ;
                                       
      -- SELECT FROM PERSONJIONING
              SELECT * FROM PersonJoining ;
              
   -- PROCEDURE FOR UPDATE_DATES ---------
					drop PROCEDURE UPDATE_DATES;
				DELIMITER //
					CREATE PROCEDURE UPDATE_DATES()
					BEGIN
						UPDATE PersonJoining
                         SET AGE =(DATEDIFF(CURRENT_DATE, STR_TO_DATE(DateofBirth, '%m/%d/%Y'))/365.25)							
								where PJoinPK != 0 ;  
                                
                       UPDATE PersonJoining
                         SET   DayofJoining =  substring(DateofJoining,length(DateofJoining)-6, 2) 
                          where PJoinPK != 0 ;
                         
					  UPDATE PersonJoining
                         SET    MonthofJoining =  monthname(STR_TO_DATE(DateofJoining, '%m/%d/%Y'))
                          where PJoinPK != 0 ;
                           
					  UPDATE PersonJoining
                         SET   YearofJoining = substring(DateofJoining,length(DateofJoining)-3, length(DateofJoining) )    
                          where PJoinPK != 0 ;
                          
                      UPDATE PersonJoining
                         SET   WorkExpinDays = (DATEDIFF(CURRENT_DATE, STR_TO_DATE(DateofJoining, '%m/%d/%Y')))							
								where PJoinPK != 0 ;    
					
					END  //
				DELIMITER ;					
-- PROCEDURE ENDED

-- EXECUTE AND PRINT HIKE TABLE 
			call `UPDATE_DATES`();
			select * from PersonJoining;
        
                            
                            
                            
                            
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
 
 DESC PERSON;
 
drop TABLE PersonTransfer ;
 -- 1.c ------------>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
				CREATE TABLE PersonTransfer  (
                       PTPK int AUTO_INCREMENT PRIMARY KEY,
                       EmpIDFK INT,
                       FirstName varchar(255),
                       LastName varchar(255),
                       Gender varchar(10),
                       DateofJoining varchar(12),
                       CurrentRegion varchar(255),
                       NewRegion varchar(255), 
                       WorkExpinYear int ,
                       FOREIGN KEY ( EmpIDFK) REFERENCES PERSON ( EmpID)
                       );
						 
	  -- INSERTING FROM TABLE PERSON  TO PERSON JOINING
				INSERT INTO PersonTransfer ( EmpIDFK, FirstName, LastName, Gender, DateofJoining, CurrentRegion )
								      select EmpID,   FirstName, LastName, Gender, DateofJoining, Region
                                          from  PERSON ;
                                          
                                          
                                                                                 
      -- SELECT FROM PERSONJIONING
              SELECT * FROM PersonTransfer ;
    --           Populate NewRegion column to “DC” using your stored procedure
-- for employees with Gender “F” whose Work Experience is more than 10 years. Populate
-- the NewRegion column to “Capitol” using the same stored procedure for employees with
-- Gender “M” whose Work Experience is more than 20 years. Re-running the storedprocedure should delete the data from existing PersonTransfer table and should
-- repopulate the PersonTransfer tabl
   -- PROCEDURE FOR UPDATE_DATES ---------
					drop PROCEDURE UPDATE_Transfer_city;
				DELIMITER //
					CREATE PROCEDURE UPDATE_Transfer_city()
					BEGIN
						UPDATE PersonTransfer
                         SET WorkExpinYear = (DATEDIFF(CURRENT_DATE, STR_TO_DATE(DateofJoining, '%m/%d/%Y'))/365.25)
                         where PTPK != 0 ;
                        
                        UPDATE PersonTransfer
                         SET NewRegion = "DC"						
								where PTPK != 0 AND Gender ="F" AND WorkExpinYear >10   ;
                                
                         UPDATE PersonTransfer
                         SET NewRegion = "Capitol"						
								where PTPK != 0 AND Gender ="M" AND WorkExpinYear > 20  ;         
					
					END  //
				DELIMITER ;					
-- PROCEDURE ENDED

-- EXECUTE AND PRINT HIKE TABLE 
			call `UPDATE_Transfer_city`();
			select * from PersonTransfer;
            
            
            
            
            
            
            
                            
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
-- =============================================================================================================================
 Q3--->


 SELECT REGION ,TIME_A
   FROM PERSON
    
 
 
 
 
 -- dummy
 
 DROP PROCEDURE IF EXISTS Person_T;
DELIMITER //
CREATE PROCEDURE Person_T()
BEGIN
-- Drop Table IF exists PersonTransfer;
CREATE TABLE PersonTransfer1(
			PT int PRIMARY KEY AUTO_INCREMENT,
            emp_ID int,
            FOREIGN KEY (emp_ID) REFERENCES PERSON(EmpID),
            FirstName varchar(200),
            LastName varchar(200),
            Gender varchar(10),
            DateofJoining date,
            CurrentRegion varchar(200),
            NewRegion varchar (200)
            );
            
INSERT INTO PersonTransfer1(emp_ID, FirstName,LastName,Gender,	DateofJoining,				    CurrentRegion)
					SELECT EmpID,  FirstName,LastName,Gender,STR_TO_DATE(DateofJoining, "%m/%d/%Y"),Region
									FROM PERSON;
UPDATE PersonTransfer1 set NewRegion="DC"
WHERE PT!=0 AND Gender="F" AND (DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),DateofJoining)), '%Y') + 0)>10;

END //
DELIMITER ;

CALL Person_T();
select * from PersonTransfer1 ;


UPDATE   PERSON 
 SET TimeOfBirth =  STR_TO_DATE( TimeofBirth , ' %h:%i:%s %p' )
	where EmpID != 0;
    
    
SELECT Region, 
   COUNT(case when time_format(TimeOfBirth,"%T") between '00:00:00' and '08:00:00' then 1 else 0 end) as daystart,
   COUNT(case when time_format(TimeOfBirth,"%T") between '08:01:00' and '15:00:00' then 1 else 0 end) as midday,
   COUNT(case when time_format(TimeOfBirth,"%T") between '15:01:00' and '23:59:00' then 1 else 0 end) as lastday   
  FROM PERSON
  --  where TimeofBirth between 00: 
  GROUP BY Region;
  
  
  
  				 
						 
	  
                                          
                                                                                 
    
		 
            
            
            
            
            
            
            


#include <iostream>
using namespace std;
class A{
public:
	A(){
		cout<<"Constructor called\n";
	   }
	~A(){
		cout<<"Destructor called\n";
	    }
};
int main(int argc, char const *argv[])
{
	A *a = new A[5];
	delete a;
	return 0;
}
class A
{
    int i;
    public:
    void print(){
      cout<<"hello"<<i;
    }
}
 
class B: public A
{
    int j;
    public:
    void assign(int a){
      j = a;
    }
}
int func(float);
float func(int, int, char);
void test(int arg); //arg is a formal parameter

int main()
{
    int val = 1;
    test(val);  //val is an actual parameter
}
// this is comment

/* 
this 
is
also
comment
*/
// this is comment

/* 
this 
is
also
comment
*/
// case i
var_name
VARNAME
VAR_1234
var_Name

// case ii
1var_name
22VARNAME
987VAR_1234
23var_Name

// case iii
@var_name
+VARNAME
%VAR_1234
!var_Name
// case i
int var_name
VARNAME
VAR_1234
var_Name

// case ii
1var_name
22VARNAME
987VAR_1234
23var_Name

// case iii
@var_name
#VARNAME
%VAR_1234
!var_Name
// case i
var_name
VARNAME
VAR_1234
var_Name

// case ii
1var_name
22VARNAME
987VAR_1234
23var_Name

// case iii
@var_name
#VARNAME
%VAR_1234
!var_Name
#include "header1"
#include "fileHeader"
#include "libraryKita"
#include <iostream>
using namespace std;
​
int main() {
  cout << "Hello World! \n";
  cout << "I am learning C++";
  return 0;
}
​
#include <iostream>
using namespace std;
​
int main() {
  cout << "Hello World!";
  return 0;
}
​
class LRUCache
{
public:
	struct  Node
	{
		int key;
		int value;
		Node *prev;
		Node *next;
	};

	Node *head;
	Node *tail;
	int size , capacity;
	unordered_map<int , Node*>mapi;
	LRUCache(int capacity)
	{
		this->capacity = capacity;
		head = new Node();
		tail = new Node();
		head->next = tail;
		tail->prev = head;
		size =0;
	}

	Node* insertNode(int k , int v)
	{
		Node*newnode = new Node();
		newnode ->key = k;
		newnode->value=v;
		newnode->prev =head;
		newnode->next = head->next;
		newnode->next->prev = newnode;
		head->next = newnode;
		// // unordered_map<int , Node*>mapi
		// pair<int , int> p(k,v);
		mapi.erase(k);
		mapi[k] = newnode; 
		return newnode;
	}

	void pushtowardsHead(Node * newnode)
	{
		if(head->next == newnode)
			return;
		newnode->prev->next = newnode->next;
		newnode->next->prev = newnode->prev;
		newnode->prev =head;
		newnode->next = head->next;
		newnode->next->prev = newnode;
		head->next = newnode;
	}

	void removeTail()
	{
		Node*newnode = tail ->prev;
		tail->prev = newnode ->prev;
		newnode->prev->next= tail;
		mapi.erase(newnode->key);
	}

	int get(int k)
	{
		if(mapi.find(k) == mapi.end())
			return -1;
		Node* newnode =mapi[k];
		pushtowardsHead(newnode);
		return newnode->value;
	}

	void put(int k ,int v)
	{
		if(mapi.find(k)!=mapi.end())
		{//already present
			Node*newnode = mapi[k];
			newnode->value = v;
			pushtowardsHead(newnode);
			return;
		}

		insertNode(k,v);
		if(size <capacity)
		{
			size++;
			return;
		}
		else
		{
			removeTail();
		}
	}
};	
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    public:
    vector<int> subarraySum(int arr[], int n, long long s)
    {
    
        long long sum=0;
        for(long long int i=0;i<n;i++){
            sum=arr[i];
            if(sum==s) return {i+1,i+1};
            for(long long int j=i+1;j<n;j++){
                sum+=arr[j];
                if(sum==s) return {i+1 , j+1};
                else if(sum>s) break;
            }
        }
        return {-1};
       
    }
};

int main()
 {
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        long long s;
        cin>>n>>s;
        int arr[n];
        const int mx = 1e9;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        Solution ob;
        vector<int>res;
        res = ob.subarraySum(arr, n, s);
        
        for(int i = 0;i<res.size();i++)
            cout<<res[i]<<" ";
        cout<<endl;
        
    }
	return 0;
}
#include<bits/stdc++.h>
using namespace std;


struct Node{
    int data;
    struct Node *next;
    Node(int data){
        this->data = data;
        next = NULL;
    }
};
    
    
struct LinkedList {
    
    Node *head;
    LinkedList() { head = NULL;}
    
    
    void reverse()
    {
        Node *current = head;
        Node *prev = NULL;
        Node *next = NULL;
        
        while(current != NULL) {
            next = current->next;
            current-> next = prev;
            prev = current;
            current = next;
        }
        head = prev;
    }
    
    
    void print()
    {
        struct Node* temp = head;
        while(temp != NULL){
            cout << temp->data << " ";
            temp = temp->next;
        }
    }
    
    
    void push(int data)
    {
        Node *temp = new Node(data);
        temp -> next = head;
        head = temp;
    }
};
    
int main()
{
    LinkedList ll;
    ll.push(1);
    ll.push(2);
    ll.push(3);
    ll.push(4);
    
    
    ll.print();
    cout << endl;
    
    ll.reverse();
    ll.print();
    
    return 0;
}
//----------------------------header files------------
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<termios.h>
#include<unistd.h>
#include<ctype.h>
#include<limits.h>
#include<dirent.h>
#include<sys/stat.h>
#include<algorithm>
#include<iomanip>
#include<sys/ioctl.h>
#include<stack>
#include<pwd.h>
#include<grp.h>
#include<signal.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<fstream>
#include<fcntl.h>
#include <cmath>
#include<iomanip>
#include <pwd.h>
#include <grp.h>
#include <time.h>
#include<cstring>
#include<dirent.h>
using namespace std;

//--------------------user defined--------
#define UP 65
#define DOWN 66
#define RIGHT 67
#define LEFT 68
#define ENTER 10
#define MODE 0777
#define BUF_SIZE 8192


//---------global items-----------------

vector<string>vec_dir_list;
int directory_position = 1;
stack<string>back_stack;
stack<string>forward_stack;
string curr_dir ;
int LIST_SIZE ;
stack <string>st;



//---------stat------------------

static struct termios term, oterm;
struct termios raw;
struct termios raw_out;
struct termios orig_termios;


//----------------FUNCTION PROTOTYPES------------

void keys(string  );
void enableRawMode() ;
void disableRawMode();
void enableRawMode2() ;
void createdir(string , string);
int search(string , string);
vector<string> getcommand();
void create_file(string , string);
void create_dir(string , string);
void delete_dir(string );
void keys(string);
void copy_file(string , string );
void copy_dir(string , string );
void move_file(string , string );
void move_dir(string , string );
void delete_file( string );
void delete_dir(string );
string name_of_folder(string );//get path from back upto 1st '/'
void rename(string, int , vector<string>);

//-----------------RAW MODE ----------------
void disableRawMode();
void enableRawMode();
void editorRefreshScreen()
{
	write(STDOUT_FILENO, "\x1b[2J", 4);
}

string cwd()
{
	// string a = get_current_dir_name();
	// return a;
	char cwd[100];
	getcwd(cwd, sizeof(cwd));
	string a = cwd;
	return a;
}
string prnt = cwd();

int isfolder(string fileName)
{
	struct stat path;

	stat(fileName.c_str(), &path);

	return S_ISREG(path.st_mode);
}


int isDir(const char* fileName)
{
	struct stat path;

	stat(fileName, &path);

	return S_ISREG(path.st_mode);
}

void clear()
{
	cout << "\033[2J\033[1;1H";
	// printf(" \033[%d;%dH", 4, 0);
}

string output_permissions(mode_t st)
{
	string s = "";

	s += ( st & S_IRUSR ? "r" : "-" );
	s += ( st & S_IWUSR ? "w" : "-" );
	s += ( st & S_IXUSR ? "x" : "-" );
	s += ( st & S_IRGRP ? "r" : "-" );
	s += ( st & S_IWGRP ? "w" : "-" );
	s += ( st & S_IXGRP ? "x" : "-" );
	s += ( st & S_IROTH ? "r" : "-" );
	s += ( st & S_IWOTH ? "w" : "-" );
	s += ( st & S_IXOTH ? "x" : "-" );
	return s;
}
string check_tilda(string s)
{
	string t = "";
	t += s[0];
	if (t == "~")
	{
		t = s.substr(1, s.length() - 1);
		const char *homedir;
		if ((homedir = getenv("HOME")) == NULL)
		{
			homedir = getpwuid(getuid())->pw_dir;
		}
		t = homedir + t;
		return t;
	}
	else if (t == "/")
	{
		return s;
	}
	return "";
}


//---PRINT DATA OF A PARTICULAR FILE
void print ()
{
	struct group *grp;
	struct passwd *pwd;
	struct stat st;
	for (int i = 0; i < vec_dir_list.size(); i++)
	{
		stat(vec_dir_list[i].c_str(), &st);
		string perm = output_permissions(st.st_mode);

		cout << setw(2) << perm << "\t";

		//2.links
		string link =  to_string(st.st_nlink);
		cout << setw(2) << link << "\t";

		//3.group id
		grp = getgrgid(st.st_uid );
		//printf(" %s", grp->gr_name);
		//temp.push_back(grp->gr_name);
		cout << setw(2) << grp->gr_name << "\t";

		//4.person id
		pwd = getpwuid(st.st_gid);
		//printf(" %s", pwd->pw_name);
		cout << setw(2) << pwd->pw_name << "\t  ";

		//5.size
		int size = st.st_size;
		float a = size / 1024.0;
		cout << setw(6) << fixed << setprecision(2) << a << " KB\t  ";


		//6.modified time
		string time = ctime(&st.st_mtime) ;
		string t2 = time.substr(0, time.length() - 1);
		cout << setw(2) << t2 << "\t";

		cout << left << setw(10) << vec_dir_list[i];
		cout << endl;
	}
}

//-------------Push all files of Current dir to vector------------------
void listFiles(string dir_name)
{
	clear();

	vec_dir_list.clear();
	DIR * dir = opendir(dir_name.c_str());
	if (dir == NULL)
		return ;

	dirent *entity;
	entity = readdir(dir);

	struct stat st;

	while ( entity != NULL)
	{
		stat(entity->d_name, &st);
		vec_dir_list.push_back(entity->d_name);
		entity = readdir(dir);
	}

	//Sort on basis of name
	sort(vec_dir_list.begin(), vec_dir_list.end());
	// sort(file_name.begin(), file_name.end());

	closedir(dir);
	print();
}



//------------********keys -*****-(most important)--------------

void keys(string pwd)
{
	LIST_SIZE = vec_dir_list.size();
	cout << LIST_SIZE << endl;
	int pos = 0;
	char ch;
	curr_dir = cwd();
	printf(" \e[H");
	while (1)
	{
		ch = cin.get();
		if (ch == DOWN)
		{
			if (pos < LIST_SIZE)
			{

				pos++;
				directory_position = pos;

				printf("%c[%d;%df", 0x1B, pos, 1);
				// cout << pos;
			}
		}
		else if (ch == UP)
		{
			if (pos >= 0)
			{
				pos--;
				directory_position = pos;


				printf("%c[%d;%df", 0x1B, pos, 1);
				// cout << pos;
			}
		}
		else if (ch == ENTER)
		{
			struct stat st;


			string s = pwd;
			s += "/" + vec_dir_list[directory_position - 1];

			stat(s.c_str(), &st);


			if ((st.st_mode & S_IFMT) == S_IFDIR)
			{

				back_stack.push(pwd);
				pwd = s;
				curr_dir = pwd;
				cout << "curr_dir :" << curr_dir << endl;
				clear();
				vec_dir_list.clear();
				// cout << s << "-----------------" << endl;
				directory_position = 1;
				listFiles(s);
				keys(s);
			}
			else if ((st.st_mode & S_IFMT) == S_IFREG)
			{
				pid_t pid = fork();
				if (pid == 0)
				{
					execlp("xdg-open", "xdg-open", s.c_str(), NULL);
					exit(0);
				}

			}


		}
		else if (ch == LEFT)
		{
			if (!back_stack.empty())
			{
				clear();
				string s = back_stack.top();
				forward_stack.push(s);//current push to forward
				back_stack.pop();
				listFiles(s);
				keys(s);

			}
		}
		else if (ch == RIGHT)
		{

			if (!forward_stack.empty())
			{
				clear();
				string s = forward_stack.top();
				forward_stack.pop();
				back_stack.push(pwd);
				listFiles(s);
				keys(s);
			}
		}
		else if ( ch ==  127) //backspace
		{
			clear();

			// int i;
			// for (i = prnt.length() - 1; prnt[i] != '/' && i >= 0; i--);
			// prnt = prnt.substr(0, i);
			back_stack.push(curr_dir);
			// pwd = prnt;
			curr_dir += "/";
			curr_dir += "..";
			listFiles(curr_dir);
		}
		else if (ch == 104) //home directrotry
		{
			clear();
			const char *homedir;

			if ((homedir = getenv("HOME")) == NULL)
			{
				homedir = getpwuid(getuid())->pw_dir;
			}
			back_stack.push(curr_dir);
			pwd = string(homedir);

			curr_dir = string(homedir);
			listFiles(pwd);
			keys(pwd);
		}
		else if (ch == 'q')
		{
			printf("\033c");
			return;
		}
		else if (ch == ':')
		{
			// clear();
			disableRawMode();
			enableRawMode2();
			// editorRefreshScreen();
			// cout << "YOU ARE IN COMMAND MODE : \n";
			// char c = cin.get();

			struct winsize w;
			ioctl(0, TIOCGWINSZ, &w);
			int rows = w.ws_row;
			int a = rows - 12;


			printf("\033[%d;1H", a);
			printf("\033[0;36m""COMMAND MODE STARTED:\n ");
			cout << "CURRENT PATH IS :" << curr_dir << endl;
			cout << "$ ";

			while (1)
			{
				char c;
				vector <string> v;
				v = getcommand();

				if (v[0] == "rename")
				{
					if (v.size() != 3)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG FILE NAME :\n";
						break;
					}
					rename(pwd, a, v);
				}
				else if (v[0] == "27")//to escape
				{

					enableRawMode();
					clear();
					listFiles(curr_dir);
					keys(curr_dir);
				}
				else if (v[0] == "quit")
				{	//write quit then space then enter to quit

					printf("\033c");
					return;
				}
				else if (v[0] == "goto")
				{

					if (v.size() != 2)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}

					curr_dir = check_tilda(v[1]);
					pwd = curr_dir;
					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string s = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << s << endl;
					cout << "$ ";
				}
				else if (v[0] == "create_file")
				{
					if (v.size() != 3)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					string path = check_tilda(v[2]);

					create_file(v[1] , path);
					pwd = curr_dir;
					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string s = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << s << endl;
					cout << "$ ";
				}
				else if ( v[0] == "create_dir")//create_dir
				{

					if (v.size() != 3)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					string path = check_tilda(v[2]);
					create_dir(v[1], path);
					pwd = curr_dir;
					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string s = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << s << endl;
					cout << "$ ";
				}
				else if (v[0] == "search") //search file or folder
				{
					if (v.size() != 2)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					int t = search(v[1] , ".");
					if (t == 1)
						cout << "TRUE";
					else
						cout << "FALSE";
				}
				else if (v[0] == "delete_file")
				{
					if (v.size() != 2)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					string s = check_tilda(v[1]);
					s += "/" + v[1];
					if (remove(v[1].c_str()))
						cout << "fail";
					else
						cout << "success";

					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string st = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << st << endl;
					cout << "$ ";
				}
				else if (v[0] == "delete_dir")
				{
					if (v.size() != 2)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					// string s = check_tilda(v[1]);
					// s += "/" + v[1];
					delete_dir(v[1]);//complete path name pr hi kaam karega


					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string st = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << st << endl;
					cout << "$ ";
				}
				else if (v[0] == "copy")
				{
					if (v.size() < 3)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					for (int i = 1; i <= v.size() - 2; i++)
					{
						string des_path = check_tilda(v[v.size() - 1]);
						
						
						
						if (!isfolder(v[i])) //opposite return true k liye 0
						{
							des_path += "/" + v[i];
							mkdir( des_path.c_str(), 0777 );

							string sa = get_current_dir_name();
							string source_foldr = sa + "/" + v[i];

							copy_dir(source_foldr, des_path );
						}
						else
						{
							string s = curr_dir + "/" + v[i];
							cout << "\n\n\n\n\n\n\n:::::: " << curr_dir << "  \n:::\n\n\n\n\n";
							copy_file(s, des_path);
						}
					}
					pwd = curr_dir;
					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string s = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << s << endl;
					cout << "$ ";

				}
				else if (v[0] == "move")
				{
					if (v.size() < 3)
					{
						clear();
						pwd = curr_dir;
						listFiles(pwd);
						printf("\033[%d;1H", a);
						printf("\033[0;36m""COMMAND MODE STARTED:\n ");
						cout << "WRONG COMMAND :\n";
						cout << "CURRENT PATH IS :" << curr_dir << endl;
						cout << "$ ";
						break;
					}
					for (int i = 1; i <= v.size() - 2; i++)
					{
						string des_path = check_tilda(v[v.size() - 1]);
						if (!isfolder(des_path)) //opposite return true k liye 0
						{
							string folder_n = curr_dir + "/" + v[i];
							des_path += "/" + v[i];
							move_dir(folder_n , des_path );
						}
						else
						{
							string s = curr_dir + "/" + v[i];
							move_file(s, des_path);
						}
					}
					pwd = curr_dir;
					clear();
					listFiles(pwd);
					// keys(pwd);
					printf("\033[%d;1H", a);
					printf("\033[0;36m""COMMAND MODE STARTED:\n ");
					string s = realpath(curr_dir.c_str(), NULL);
					cout << "CURRENT PATH IS :" << s << endl;
					cout << "$ ";
				}

			}
		}

	}
}

void rename(string pwd, int a, vector<string>v)
{
	string s = curr_dir;
	cout << "curr_dir: " << curr_dir << endl;
	string aa = "";
	string b = "";
	aa += s + "/" + v[1];
	b += s + "/" + v[2];
	int result = rename(aa.c_str() , b.c_str() );
	clear();
	pwd = curr_dir;
	listFiles(pwd);
	printf("\033[%d;1H", a);
	printf("\033[0;36m""COMMAND MODE STARTED:\n ");
	string ss = realpath(curr_dir.c_str(), NULL);
	if (result == 0)
		cout << "successful rename\n";
	else
		cout << "Write file name carefully\n";
	cout << "CURRENT PATH IS :" << ss << endl;
	cout << "$ ";
}
void move_file(string fileName, string destination)
{
	copy_file(fileName , destination);


	if (remove(fileName.c_str()))
		cout << "fail";
	else
		cout << "success";
	return;
}

void move_dir(string source , string destination)
{

	int result = rename(source.c_str() , destination.c_str() );
	if (result == 0)
		cout << "success";
	else
		cout << "something went wrong";
}

void copy_file(string sr, string dt)
{


  int src, dst, in, out;
  char buf[BUF_SIZE];
  // if (argc != 3) exit(1);

  src = open(sr.c_str(), O_RDONLY);
  if (src < 0)
    exit(2);
  // dt += "/" + sr;//complete path +name
  dst = creat(dt.c_str(), MODE);
  if (dst < 0)
    exit(3);
  while (1) {
    in = read(src, buf, BUF_SIZE);
    if (in <= 0) break;
    out = write(dst, buf, in);
    if (out <= 0) break;
  }
  close(src); close(dst); return;
}



void copy_dir(string folderName, string destination)
{

	DIR* dir = opendir(folderName.c_str());
	if (dir == NULL)
	{
		printf("no such source directory found\n");
		return;
	}
	// cout << folderName << endl;

	struct dirent* entity;
	while ((entity = readdir(dir)) != NULL )
	{
		// printf("%hhd  %s\n", entity->d_type,   entity->d_name);
		if ( string(entity->d_name) == "." || string(entity->d_name) == "..")
		{
			// cout << string(entity->d_name) << endl;
			continue;
		}
		else
		{
			string s = string(entity->d_name);
			string source_path = folderName + "/" + entity->d_name;
			struct stat tmp;
			if (stat(source_path.c_str(), &tmp) == -1)
			{
				printf(" cannot get souurce  stat\n");
				continue;
			}
			if (!isfolder(source_path))
			{
				string dest_path = destination + "/" + entity->d_name;
				mkdir( dest_path.c_str(), 0777 );
				copy_dir(source_path, dest_path );
			}
			else
			{
				string dest_path = destination + "/" + entity->d_name;
				copy_file(source_path, dest_path);
			}

			// cout << "entity name: " << s << endl;
			// cout << "source_path:" << source_path << endl;
			// cout << "destination_path" << dest_path << endl;
		}


	}
	closedir(dir);

	return;
}


void create_file(string  Name , string folder)//create_file
{
	string s = folder;
	s += "/" + Name;
	FILE* file = fopen(s.c_str(), "w+");
	fclose(file);

}


void create_dir(string Name , string folder)
{

	string s = folder;
	s += "/" + Name;
	mkdir( s.c_str(), 0775 );
}


string name_of_folder(string path)//last piche se folder 
{
	string a = "";
	for (int i = path.length() - 1; i >= 0 ; -- i)
	{
		string m = "";
		m += path[i];
		if (m != "/")
			a += m;
		else
			break;
	}

	path = "";
	for (int i = a.length() - 1; i >= 0; i--)
	{
		path += a[i];
	}
	return path;

}


int  search(string Name , string folder)
{
	DIR* dir = opendir(folder.c_str());
	if (dir == NULL) {
		return 0;
	}
	struct dirent* entity;
	entity = readdir(dir);
	while (entity != NULL)
	{
		if (entity->d_type == DT_DIR && strcmp(entity->d_name, ".") != 0 && strcmp(entity->d_name, "..") != 0)
		{
			string folder_name = name_of_folder(folder);
			if (Name == entity->d_name)
			{
				return 1;
			}


			char path[100] = { 0 };
			strcat(path, folder.c_str());
			strcat(path, "/");
			strcat(path, entity->d_name);
			if ((search(Name , path)))
				return 1;
		}
		else
		{
			if (entity->d_name == Name)
			{
				return 1;
			}
		}
		entity = readdir(dir);
	}
	closedir(dir);
	return 0;
}

void delete_dir(string dirname)
{
	DIR* dir = opendir(dirname.c_str());
	if (dir == NULL) {
		return;
	}

	int count = 5;
	// printf("Reading files in: %s\n", dirname);

	struct dirent* entity;
	while ((entity = readdir(dir)) != NULL && (count-- > 0))
	{
		if (entity->d_name == "."  || entity->d_name == "..")
			continue;
		else if (entity->d_type == DT_DIR && strcmp(entity->d_name, ".") != 0 && strcmp(entity->d_name, "..") != 0)
		{
			string path = dirname + "/" + entity->d_name;
			// cout << "foldr_name: " << entity->d_name << endl;
			delete_dir(path);
		}
		else
		{
			string path = dirname + "/" + entity->d_name;
			// cout << "\n--fiile:  " << entity->d_name << endl;
			// cout << "file_path: " << path << endl;
			if (strcmp(entity->d_name, ".") != 0 && strcmp(entity->d_name, "..") != 0)
			{
				int status = remove(path.c_str());
				if (status == 0)
					cout << "\nFile Deleted Successfully!\n";
				else
					cout << "\nIN FILE Error Occurred!\n";
			}
		}

	}
	closedir(dir);

	// string path = dirname + "/" + entity->d_name;
	// cout << "foldr_name: " << dirname << endl;
	int status = remove(dirname.c_str());

	if (status == 0)
		cout << "\nFOLDER Deleted Successfully!\n";
	else
		cout << "\nIN FOLDER Error Occurred!\n";
	return;
}










void enableRawMode2() {
	tcgetattr(STDIN_FILENO, &orig_termios);
	atexit(disableRawMode);
	struct termios raw = orig_termios;
	raw.c_lflag &= ~(ICANON);
	tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}


void disableRawMode() {
	tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
}


void enableRawMode() {
	tcgetattr(STDIN_FILENO, &orig_termios);
	atexit(disableRawMode);
	struct termios raw = orig_termios;
	raw.c_lflag &= ~(ECHO | ICANON);
	tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}

vector<string> getcommand()
{

	char ch;
	string s ;

	getline (cin , s);

	//-------------------------------------------------
	// string s = "";
	// char c;
	// c = cin.get();
	// while (c != 10)
	// {
	// 	if (c != 127)
	// 	{
	// 		s += c;
	// 	}
	// 	else if (c == 127)
	// 	{
	// 		printf ("\033[0K");
	// 		s = s.substr(0, s.length() - 1);
	// 		cout << s;
	// 	}
	// 	c = cin.get();
	// }
	//---------------------------------------------------------
	vector<string> v;
	string input = "";
	for (int i = 0; i < s.length() ; ++i)
	{
		string m = "";
		m += s[i];
		if (m != " ")
		{
			input += m;

		}
		else if (m == " ")
		{
			v.push_back(input);
			input = "";
		}


	}
	v.push_back(input);
	return v;

}



int main()
{
	clear();
	enableRawMode();//enable to get into canonicall mode
	// /get_current_dir_name()
	curr_dir = get_current_dir_name(); //global path
	back_stack.push(curr_dir);
	listFiles(curr_dir);
	keys(curr_dir);
	return 0;
}
// if you want to know a distance between the number and divisor of other number
int n,m;
n = 3, m = 17;
int mod = 17 % 3;     //3 is a divisor of 15 and distance between 15 and 18 is 2 
cout<<mod;            // 2
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;

int Partition(int *A, int start, int end)
{
    int pivot = A[end];
    int partitionIndex = start;
    for(int i =start; i < end; i++)
    {
        if(A[i]<= pivot)
        {
            swap(A[i], A[partitionIndex]);
            partitionIndex++;
        }
    }
    swap(A[partitionIndex], A[end]);
    return partitionIndex;
}

void QuickSort(int *A, int start, int end)
{
    if(start < end)
    {
        int pertitionIndex = Partition(A, start, end);
        QuickSort(A, start, pertitionIndex-1);
        QuickSort(A, pertitionIndex+1, end);
    }
}

int main() {
    int A[] = {7,6,5,4,3,2,1,0};
    QuickSort(A, 0, 7);
    for (int i = 0; i<8; i++) cout<<A[i]<<" ";
    return 0;
}
void ABolter::BeginPlay()
{
	Super::BeginPlay();
	
	CurrentAmmoWithYou = FMath::DivideAndRoundUp(MaxAmmoCarry, 2);
	CurrentAmmoInMagazine = MaxAmmoMagazine;
	CurrentAmmoWithYou -= CurrentAmmoInMagazine;
}

void ABolter::Fire()
{
	if (CurrentAmmoInMagazine <= 0)
	{
		UGameplayStatics::PlaySoundAtLocation(SkeletalMesh, EmptyMagazineSound, 
        this->GetActorLocation(), 
        this->GetActorRotation());
		return;
	}
  
	--CurrentAmmoInMagazine;
}

void ABolter::StopFireRate()
{
	if (!GetWorldTimerManager().IsTimerActive(FireRateTimerHandle)) { return; }

	GetWorldTimerManager().ClearTimer(FireRateTimerHandle);
}

bool ABolter::IsShooting()
{
	return GetWorldTimerManager().IsTimerActive(FireRateTimerHandle);
}

void ABolter::Reload()
{
	OwnerCharacterSpaceMarine = Cast<ASpaceMarineCharacter>(GetOwner());

	if (CurrentAmmoWithYou > 0 && CurrentAmmoInMagazine != MaxAmmoMagazine && !IsShooting())
	{
		if (!OwnerCharacterSpaceMarine) { return; }

		OwnerCharacterSpaceMarine->SetIsReloading(true);
		OwnerCharacterSpaceMarine->GetCharacterMovement()->MaxWalkSpeed = 300.f;

		UGameplayStatics::PlaySoundAtLocation(SkeletalMesh, ReloadSound, this->GetActorLocation(), this->GetActorRotation());
		GetWorldTimerManager().SetTimer(ReloadTimer, this, &ABolter::CalculateBulletsAmountToReload, ReloadTime);
	}
}

void ABolter::CalculateBulletsAmountToReload()
{
	OwnerCharacterSpaceMarine->SetIsReloading(false);
	OwnerCharacterSpaceMarine->GetCharacterMovement()->MaxWalkSpeed = 600.f;

	int32 AmmoToReload = MaxAmmoMagazine - CurrentAmmoInMagazine;

	if (CurrentAmmoWithYou < AmmoToReload)
	{
		CurrentAmmoInMagazine += CurrentAmmoWithYou;
		CurrentAmmoWithYou = 0;
	}
	else
	{
		CurrentAmmoInMagazine += AmmoToReload;
		CurrentAmmoWithYou -= AmmoToReload;

		if (CurrentAmmoWithYou < 0)
		{
			CurrentAmmoWithYou = 0;
		}
	}
}

int32 ABolter::GetAmmoInMagazineValue()
{
	return CurrentAmmoInMagazine;
}

int32 ABolter::GetAmmoWithYouValue()
{
	return CurrentAmmoWithYou;
}

void ABolter::ReplenishAmmo()
{
	if (CurrentAmmoWithYou < MaxAmmoCarry)
	{
		UGameplayStatics::PlaySoundAtLocation(SkeletalMesh, TakeAmmo, this->GetActorLocation(), this->GetActorRotation());

		CurrentAmmoWithYou = MaxAmmoCarry;
	}
}
private:
	int32 CurrentAmmoWithYou;
	int32 CurrentAmmoInMagazine;

	UPROPERTY(EditAnywhere, Category = "Statistics")
	float ReloadTime = 1.6f;
	UPROPERTY(EditAnywhere, Category="Statistics")
	float MaxDistance = 100.f;
	UPROPERTY(EditAnywhere, Category = "Statistics")
	float Damage = 10.f;
	UPROPERTY(EditAnywhere, Category = "Statistics")
	int32 MaxAmmoCarry = 360;
	UPROPERTY(EditAnywhere, Category = "Statistics")
	int32 MaxAmmoMagazine = 15;
	UPROPERTY(EditAnywhere, Category = "Statistics")
	float AccuracyMin = 0;
	UPROPERTY(EditAnywhere, Category = "Statistics")
	float AccuracyMax = 0;

	FTimerHandle ReloadTimer;

	void CalculateBulletsAmountToReload();

public:	
	bool IsShooting();
	void ReplenishAmmo();

	int32 GetAmmoInMagazineValue();
	int32 GetAmmoWithYouValue();
//general approach Template
void Backtrack(int start)
{
    //Base case 

// loop for all possible values
{
    //include the current element at this position if possible in the ans 
	//More generally, make a choice 

    Backtrack(start+1) 

    //backtrack by removing current element 
}
                            ------------------------------------------------

//Generate all subsets (non dublicated)
int n;
void GenerateSubs(vector<int> &a, int s, vector<int> &subset, vector<vector<int>> &ans) {
    for (int i = s; i < n; i++) {
        subset.push_back(a[i]); //include element at ith position
        GenerateSubs(a, i + 1, subset, ans); //generate all subsets including ith element
        subset.pop_back(); //backtrack
    }
    ans.push_back(subset);
}

vector<vector<int>> subsets(vector<int> &a) {
    vector<vector<int>> ans;
    vector<int> subset;
    n = a.size();

    GenerateSubs(a, 0, subset, ans);
    return ans;
}

int main() {
    fast;
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> ans(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ans = subsets(a);
    for (vector<int> i: ans) {
        for (int j: i) {
            cout << j;
        }
        cout << '\n';
    }
}
// i/p :
  //3
  //1,2,3
// o/p : 
                              ------------------------------------------------

//Generate all subsets (dublicated)
int n;
void GenerateSubs(vector<int>&a,int s,vector<int>&subset,vector<vector<int>>&ans)
{
    for(int i=s;i<n;i++)
    {
        if(i==s||a[i]!=a[i-1])
        {
            subset.push_back(a[i]); //include element at ith position
            GenerateSubs(a,i+1,subset,ans); //generate all subsets including ith element
            subset.pop_back(); //backtrack
        }
    }
    ans.push_back(subset);
}
vector<vector<int>> subsetsWithDup(vector<int> &a) {
    vector<vector<int>> ans;
    vector<int> subset;
    n = a.size();

    sort(a.begin(), a.end()); //sort the elements so that we can keep track of duplicates
    GenerateSubs(a, 0, subset, ans);
    return ans;
}

int main() {
    fast;
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
    freopen("Error.txt", "w", stderr);
#endif
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> ans(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ans = subsetsWithDup(a);
    for (vector<int> i: ans) {
        for (int j: i) {
            cout << j;
        }
        cout << '\n';
    }
}
// i/p :
  //4
  //1 2 3 2
/* o/p :
1223
122
123
12
13
1
223
22
23
2
3
  */
                              ------------------------------------------------
                              ------------------------------------------------

//---------------------------------------Examples--------------------------------------------------
//Generate all subset instead '?'
string s;
string o;

void solve(int i) {
    //base case
    if (i == s.length()) {
        for (int j = 0; j < s.length(); ++j) {
            cout << o[j];
        }
        cout << '\n';
        return;
    }
    if (s[i] != '?') {
        o[i] = s[i];
        solve(i + 1);
    } else {
        for (int j = 'a'; j <= 'z'; ++j) {
            o[i] = j;
            solve(i + 1);
        }
    }
}


int main() {
    cin >> s;
    solve(0);
}
---------------------------------------------------------------------------------------------------
//Generating Permutations Using next_permutation

int n;
int const N = 11;
bool taken[N];
int stk[N];

void prm(int i) {
    //base case
    if (i == n) {
        for (int j = 0; j < n; ++j) {
            cout << stk[j] << ' ';
        }
        cout << el;
        return;
    }
    for (int j = 1; j <= n; ++j) {
        if (!taken[j]) {
            taken[j] = true;
            stk[i] = j;
            prm(i + 1);
            taken[j] = false;
        }
    }
}


int main() {

    fast;
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
    freopen("Error.txt", "w", stderr);
#endif
    cin >> n;
    prm(0);
}
---------------------------------------------------------------------------------------------------
//  
// Left shift ---> Multiplying by 2 
int x = 6;
x <<= 1;
cout << x;   // 12
--------------------------------------------------------------------------------------------------
//Right shift ---> Divide by 2 
int x = 12;
x >>= 1;
cout << x;   // 6
--------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------
//  Checking if given 32 bit integer is power of 2 
// if true return 1 else return 0
int isPowerof2(int x)
{
    return (x && !(x & x-1));
}
--------------------------------------------------------------------------------------------------
// Find log base 2 of 32 bit integer
// log2(8)=3 when 2^3 = 8
int log2(int x)
{
    int res = 0;
    while (x >>= 1)
        res++;
    return res;
}
--------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;

int main(){

//finding the length of the string

    string para = "I am Rishi";
    cout << para.length() << endl;

//finding according to the index of the string

    cout << para[2] << endl;

// replacing a string

    para[0] = 'G';
    cout << para << endl;

//substring

    cout  << para.substr(3, 4);

// creating another variable for the substring

    string parasub = para.substr(3, 4);
    cout << parasub << endl;

    return 0;
}

//1- (string) ---> (int)
stoi("String name");
 
//2- (int) ---> (string)
int n;
cin>>n;
String s = to_string(n);
cout<<s;
 
//3- (char) ---> (int)
String str;
cin>>str;
for(int i; str[i], i++){
  char ch = str[i]-'0';   //note:(str[i]-'0') to convert str[i] character to integer
  cout<<ch;
}
  
//3- (int) ---> (char)
int n;
cin>>n;
char ch = (char) n;
cout<<ch;
 
//4- (int) ---> (long long)
int a;
a = a*1LL;
 
//5- (double) ---> (int) && flooring number
double n = 7.99999999;
n = (int) n;
//Binary Search implementation //Time Complexity: O (log n) //return int {-1 , mid index}
int binarySearch(int tar, vector<int>& arr){
int lo=0, md, hi=arr.size()-1;
while(hi>=lo){
md=(lo+hi)/2;
if(arr[md]==tar) return md;
else if(arr[md]<tar) lo=md+1;
   		else hi=md-1;
}
return -1;
}
---------------------------------------------------------------------------------------------------
//Binary Search by using Stls //Time Complexity: O (log n)
// for binary search in containers like vector (let target element=6)
binary_search(v.begin(), v.end(), 6); 
// return 1 or 0 as present or not
---------------------------------------------------------------------------------------------------
//binary search with lower and upper bound by using stls
int x, ans; //x is passing value, ans is a value you want, v --> vector or any container
ans = lower_bound(v.begin(), v.end(), x) - v.begin(); //ans >= x (equal number or first number after x)
ans = upper_bound(v.begin(), v.end(), x) - v.begin(); // ans > x (first number after x)
---------------------------------------------------------------------------------------------------
// Two Pointer implementation
// Two pointer technique based solution to find
// if there is a pair in A[0..N-1] with a given sum.
int isPairSum(int A[], int N, int X)
{
    // represents first pointer
    int i = 0;
  
    // represents second pointer
    int j = N - 1;
  
    while (i < j) {
      
        int curSum = A[i]+arr[j];
      
        // If we find a pair
        if curSum == X)
            return 1;
  
        // If sum of elements at current
        // pointers is less, we move towards
        // higher values by doing i++
        else if (curSum < X)
            i++;
  
        // If sum of elements at current
        // pointers is more, we move towards
        // lower values by doing j--
        else
            j--;
    }
    return 0;
}
//Sum of numbers from 1 ---> n
int n, sum;
sum = (n*(n+1))/2;
 
//flooring integer number (int)        "floor أرضيه"
int a=5, b=2;
int n = a/b; // n= 2
 
//Ceiling integer number (int)          "ceil سقف"
int a=5, b=2;
int ans = (a+(b-1))/b; //n=3
 
//Division Theory 
int a=10, b=3;     // a ---> numerator البسط / b ---> denominator المقام
int ans = a/b;     // n= 3
//meaning:
//1- you can give everyone of b ans
//2- ans is a number of numbers from 1--> a which is divisible by b (find multiple in Range)
 
//Number of Steps
//Power function //Complexity: O(exponent).
double x = 6.1, y = 4.8;
double result = pow(x, y);
--------------------------------------------------------------------------------------------------- 
// modulous a floating number types (n % dn)
double n = fmod(num , denum);
---------------------------------------------------------------------------------------------------
//limits of integer types and help you when you handle (min/max)
int n1 =INT_MAX;  //+2147483647 //== 2*1e9 
int n2 =INT_MIN;  //-2147483647 //== -2*1e9
---------------------------------------------------------------------------------------------------
//Ceiling and flooring with double numbers
//1- Flooring
double a = 2.3;  a = floor(a);  //2
double b = -2.3; b = floor(b);  //-3
//2- ceiling
double a = 2.3;  a = ceil(a);  //3
double b = -2.3; b = ceil(b);  //-2
---------------------------------------------------------------------------------------------------
// Square Root //Time Complexity: θ(log(N))
int x = 24;
double answer;
answer = sqrt(x);
---------------------------------------------------------------------------------------------------
// max/min of three numbers //Time Complexity: O(1)
ans = max(a,max(b,c));
ans = min(a, min(b,c));
---------------------------------------------------------------------------------------------------
//GCD //Library: 'algorithm' //Time Complexity: O(log(max(value1, value2))))
int a = 6, b = 20;
int ans = __gcd(a, b); //gcd(6, 20) = 2
---------------------------------------------------------------------------------------------------
//Lowercase and Uppercase handle  //Time Complexity: O(1)
// convert 'a' to uppercase
char ch = toupper('a');  //A
// convert 'A' to lowercase
char ch = tolower('A');  //a
---------------------------------------------------------------------------------------------------
//Rounding numbers // return double type
double dUp = round(2.6);
double dDown = round(2.4);
cout << dUp;   //3
cout << dDown;   //2
---------------------------------------------------------------------------------------------------
//search for x
find(vect.begin(), vect.end(),x);
//note 
// find() returns iterator to last address if element not present
find(vect.begin(), vect.end(),5) != vect.end()?
                         cout << "\nElement found": cout << "\nElement not found";
---------------------------------------------------------------------------------------------------
// for binary search in containers like vector (let target element=6)
binary_search(v.begin(), v.end(), 6); 
// return 1 or 0 as present or not
---------------------------------------------------------------------------------------------------
//binary search with lower and upper bound
int x, ans; //x is passing value, ans is a value you want, v --> vector or any container
ans = lower_bound(v.begin(), v.end(), x) - v.begin(); //>= x (equal number or first number after x)
ans = upper_bound(v.begin(), v.end(), x) - v.begin(); // > x (first number after x)
---------------------------------------------------------------------------------------------------
//Example on Binary Search() , lower_bound() and upper_bound
  
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    // Initializing vector with array values
    int arr[] = {5, 10, 15, 20, 20, 23, 42, 45};
    int n = sizeof(arr)/sizeof(arr[0]);
    vector<int> vect(arr, arr+n);
 
    // Sort the array to make sure that lower_bound()
    // and upper_bound() work.
    sort(vect.begin(), vect.end());
 
    // Returns the first occurrence of 20
    auto q = lower_bound(vect.begin(), vect.end(), 20);  //3
 
    // Returns the last occurrence of 20
    auto p = upper_bound(vect.begin(), vect.end(), 20);  //5
 
    //The lower bound is at index
    cout << q-vect.begin() << endl;  // O/P : 3
 
    // upper bound is at index
    cout << p-vect.begin() << endl;  // O/P : 5
 
    return 0;
}
--------------------------------------------------------------------------------------------------
// swap two numbers //Time Complexity: O(1)
swap(a,b);
---------------------------------------------------------------------------------------------------
// rotate containers like vector, strings by n position
rotate(v.begin(), v.begin()+n, v.end());
---------------------------------------------------------------------------------------------------
// sort arrays of size n
sort(arr, arr+n);
---------------------------------------------------------------------------------------------------
// sort containers like vector, strings(based on intro sort)
sort(v.begin(), v.end());
---------------------------------------------------------------------------------------------------
// reverse containers like vectors, strings
reverse(v.begin(), v.end());
---------------------------------------------------------------------------------------------------
//find the maximum element of a vector.
*max_element(v.begin(), v.end());
---------------------------------------------------------------------------------------------------
//find the minimum element of a vector.
*min_element(v.begin(), v.end());
---------------------------------------------------------------------------------------------------
//Does the summation of vector elements
accumulate(vect.begin(), vect.end(), 0);
---------------------------------------------------------------------------------------------------
//Example on sort(), reverse(), *max_element(), *min_element() and accumulate()
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric> //For accumulate operation
using namespace std;

int main()
{
	// Initializing vector with array values
	int arr[] = {10, 20, 5, 23 ,42 , 15};
	int n = sizeof(arr)/sizeof(arr[0]);
	vector<int> vect(arr, arr+n);

	//print Vector 
	for (int i=0; i<n; i++)
		cout << vect[i] << " ";   // O/P: 10 20 5 23 42 15

	// Sorting the Vector in Ascending order
	sort(vect.begin(), vect.end());

  	// Print Vector after sorting
	for (int i=0; i<n; i++)
	cout << vect[i] << " ";       // O/P: 10 20 5 23 42 15

	// Reversing the Vector
	reverse(vect.begin(), vect.end());

	// Print Vector after reversing
	for (int i=0; i<n; i++)
		cout << vect[i] << " ";             // O/P : 42 23 20 15 10 5 

	//Maximum element of vector
	cout << *max_element(vect.begin(), vect.end());  //42

	//Minimum element of vector
	cout << *min_element(vect.begin(), vect.end());  //5

	// Starting the summation from 0
	//The summation of vector elements
	cout << accumulate(vect.begin(), vect.end(), 0);  //115

	return 0;
}
---------------------------------------------------------------------------------------------------
// Count from first to end
count (begin(v),end(v),true);  // true or any boolean
---------------------------------------------------------------------------------------------------
// Remove all elments
v.clear();
---------------------------------------------------------------------------------------------------
//erase() in vector
//Time Complexity: O(N)
//erases selected element in vector and shifts and resizes the vector elements accordingly.
v.erase();

// Example 1: working of erase() function
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	vector<int> myvector{ 1, 2, 3, 4, 5 };
	vector<int>::iterator it;

	it = myvector.begin();
	myvector.erase(it);

	// Printing the Vector
	for (auto it = myvector.begin(); it != myvector.end(); ++it)
		cout << ' ' << *it;   // O/P : 2 3 4 5
	return 0;
}
                            -----------------------------------------
                              
//Example 2: removing elements within a range
#include <iostream>
#include <vector>
using namespace std;
  
int main()
{
    vector<int> myvector{ 1, 2, 3, 4, 5 };
    vector<int>::iterator it1, it2;
  
    it1 = myvector.begin();
    it2 = myvector.end();
    it2--;
    it2--;
  
    myvector.erase(it1, it2);
  
    // Printing the Vector
    for (auto it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;    //4 5
    return 0;
}
                            -----------------------------------------
// Example 3:  remove all the even elements from the vector and print the vector. 
#include <iostream>
#include <vector>
using namespace std;
  
int main()
{
    vector<int> myvector{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  
    for (auto i = myvector.begin(); i != myvector.end(); ++i) {
        if (*i % 2 == 0) {
            myvector.erase(i);
            i--;
        }
    }
  
    // Printing the vector
    for (auto it = myvector.begin(); it != myvector.end(); ++it)
        cout << ' ' << *it;                     // O/P : 1 3 5 7 9
    return 0;
}

---------------------------------------------------------------------------------------------------
// erase in map
#include<iostream>
#include<map> // for map operations
using namespace std;
  
int main()
{
    // declaring map
    // of char and int
    map< char, int > mp;
      
    // declaring iterators
    map<char, int>::iterator it ;
    map<char, int>::iterator it1;
    map<char, int>::iterator it2;
      
    // inserting values 
    mp['a']=5;
    mp['b']=10;
    mp['c']=15;
    mp['d']=20;
    mp['e']=30;
  
    it = mp.begin();
  
    // erasing element using iterator
    // erases 2nd element
    // 'b'
    ++it;
    mp.erase(it);
      
    // printing map elements after deletion      
    for (it1 = mp.begin(); it1!=mp.end(); ++it1)
        cout << "(" << it1->first << " : " << it1->second <<") ";
    // O/P : (a : 5) (c : 15) (d : 20) (e : 30) 
      
    // erasing element using value 
    int c = mp.erase('c');
      
    // printing map elements after deletion
    for (it1 = mp.begin(); it1!=mp.end(); ++it1)
        cout << it1->first << "->" << it1->second << endl;
    // O/P : (a : 5) (d : 20) (e : 30)
      
    //The number of elements deleted in 2nd deletion are
    cout << c << endl; // O/P : 1
      
    // erasing element using not present value 
    int d = mp.erase('w');
      
    // printing map elements after deletion      
    for (it1 = mp.begin(); it1!=mp.end(); ++it1)
        cout << it1->first << "->" << it1->second << endl;
    // O/P : (a : 5) (d : 20) (e : 30)
  
    //The number of elements deleted in 3rd deletion are
    cout << d << endl; // O/P : 0
      
    ++it;
    ++it;
      
    // erasing element using range iterator
    // deletes "d" and "e" keys
    mp.erase(it, mp.end());
      
    // printing map elements 4th deletion
    for (it1 = mp.begin(); it1!=mp.end(); ++it1)
        cout << it1->first << "->" << it1->second << endl;
    // O/P : (a : 5)  
    cout << endl;
      
}
---------------------------------------------------------------------------------------------------
//unique 
//erase (uniqe()) 
//next_permutation() 
// prev_permutation() 
// distance()
// intialize frequency container
void countFreq(int a[], int n, unordered_map<int, int> &hm) {
    // Insert elements and their
    // frequencies in hash map.
    for (int i = 0; i < n; i++)
        hm[a[i]]++;
}//O(n)

// return frequency number
int freqQuery(int x, unordered_map<int, int> hm) {
    return hm[x];
}//O(1)


int main() {
    int a[] = {1, 3, 2, 4, 2, 1};
    unordered_map<int, int> hm;  //create frequency container
    countFreq(a, 6, hm);         // intialize frequency container

    cout << freqQuery(2, hm) << endl;  // 2
    cout << freqQuery(3, hm) << endl;  // 1
    cout << freqQuery(5, hm) << endl;  // 0
}
//prefix Sum 
void pSum(ll a[], ll n, ll pSum[]) {
    pSum[0] = 0;
    for (int i = 0; i < n; i++)
        pSum[i + 1] = pSum[i] + a[i];

}//Time Complexity: O(n)

int main() {
    int n;
    cin >> n;
    ll a[n], p[n + 1];

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
  
    pSum(a, n, p);
}
---------------------------------------------------------------------------------------------------
 //to sum part of array 
 //1- choose left index (L) and right (R); 
 //2- use prefix Sum array
 prefix[R]−prefix[L−1] //prefixSum(L-1 --> R) if array based 1
prefix[R]−prefix[L] //prefixSum(L --> R)  if orginal array based 0
---------------------------------------------------------------------------------------------------  
// c++ program to create a linked list insert element at head, at tail and delete element from
// tail, head and specific key
#include <iostream>
using namespace std;
struct Node
{
public:
    int data;
    Node *next;
    Node(int data)
    {
        this->data = data;
        this->next = NULL;
    }
};
void insertAtHead(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    NewNode->next = head;
    head = NewNode;
}
void insertAtTail(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    if (head == NULL)
    {
        NewNode->next = head;
        head = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->next != NULL)
    {
        temp = temp->next;
    }
    temp->next = NewNode;

    cout << "the value of temp next is " << temp->data << endl;
}
void insertAtKey(Node *&head, int key, int data)
{
    Node *NewNode = new Node(data);
    if (head->data == key)
    {

        NewNode->next = head->next;
        head->next = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->data != key)
    {
        temp = temp->next;
        if (temp == NULL)
            return;
    }
    NewNode->next = temp->next;
    temp->next = NewNode;
}
void print(Node *&head)
{
    if (head == NULL)
    {
        cout << head->data << " ->  ";
    }
    Node *temp = head;
    while (temp != NULL)
    {
        /* code */
        cout << temp->data << " -> ";
        temp = temp->next;
    }
}

void deleteNode(Node *&head, int key)
{
    if (head == NULL)
        return;

    if (head->data == key)
    {
        Node *temp = head;
        head = head->next;
        delete temp;
    }
    deleteNode(head->next, key);
}
// recursive approach to reverse the linked list
Node *Reverse(Node *&head)
{
    if (head == NULL || head->next == NULL)
        return head;
    Node *NewHead = Reverse(head->next);
    head->next->next = head;
    head->next = NULL;
    return NewHead;
}
//this function reverse the k nodes in linked list
Node*Reversek(Node*&head,int k){
//first we have to make three node pointers

Node *prevPtr = NULL;//the prev ptr points to Null
Node *currPtr = head;//the next ptr should points toward the prev ptr because we have to reverse 
//the nodes this is possible if we point the next node towards the prev node
Node *nextptr=NULL;//we will assign the value to nextptr in the loop 
int count = 0;
while(currPtr!=NULL && count<k)
{
    nextptr = currPtr->next;
    currPtr->next = prevPtr;
    prevPtr = currPtr;
    currPtr = nextptr;
    count++;
}
if(nextptr!=NULL){
head->next = Reversek(nextptr, k);
}
return prevPtr;
}
int main()
{
    Node *head = NULL;
    cout << "insert At head" << endl;
    insertAtHead(head, 3);
    insertAtHead(head, 2);
    print(head);
    cout << endl;
    cout << "Insert at Tail " << endl;
    insertAtTail(head, 4);
    insertAtTail(head, 5);
    insertAtTail(head, 6);
    insertAtTail(head, 10);
    insertAtTail(head, 9);
    insertAtKey(head, 10, 45);
    print(head);

    deleteNode(head, 2);
    cout << "deleting the head" << endl;
    print(head);
    cout << endl;
    cout << "reversing the linked list " << endl;
    Node *NewHead = Reverse(head);
    print(NewHead);
    cout << endl;
    cout << "reversing the k nodes in linked list " << endl;
    Node *NewRev = Reversek(NewHead,2);
    print(NewRev);
}
Node*Reversek(Node*&head,int k){
//first we have to make three node pointers

Node *prevPtr = NULL;//the prev ptr points to Null
Node *currPtr = head;//the next ptr should points toward the prev ptr because we have to reverse 
//the nodes this is possible if we point the next node towards the prev node
Node *nextptr=NULL;//we will assign the value to nextptr in the loop 
int count = 0;
while(currPtr!=NULL && count<k)
{
    nextptr = currPtr->next;
    currPtr->next = prevPtr;
    prevPtr = currPtr;
    currPtr = nextptr;
    count++;
}
if(nextptr!=NULL){
head->next = Reversek(nextptr, k);
}
return prevPtr;
}
// c++ program to create a linked list insert element at head, at tail and delete element from
// tail, head and specific key
#include <iostream>
using namespace std;
struct Node
{
public:
    int data;
    Node *next;
    Node(int data)
    {
        this->data = data;
        this->next = NULL;
    }
};
void insertAtHead(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    NewNode->next = head;
    head = NewNode;
}
void insertAtTail(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    if (head == NULL)
    {
        NewNode->next = head;
        head = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->next != NULL)
    {
        temp = temp->next;
    }
    temp->next = NewNode;

    cout << "the value of temp next is " << temp->data << endl;
}
void insertAtKey(Node *&head, int key, int data)
{
    Node *NewNode = new Node(data);
    if (head->data == key)
    {

        NewNode->next = head->next;
        head->next = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->data != key)
    {
        temp = temp->next;
        if (temp == NULL)
            return;
    }
    NewNode->next = temp->next;
    temp->next = NewNode;
}
void print(Node *&head)
{
    if (head == NULL)
    {
        cout << head->data << " ->  ";
    }
    Node *temp = head;
    while (temp != NULL)
    {
        /* code */
        cout << temp->data << " -> ";
        temp = temp->next;
    }
}

void deleteNode(Node *&head, int key)
{
    if (head == NULL)
        return;

    if (head->data == key)
    {
        Node *temp = head;
        head = head->next;
        delete temp;
    }
    deleteNode(head->next, key);
}
// recursive approach to reverse the linked list
Node *Reverse(Node *&head)
{
    if (head == NULL || head->next == NULL)
        return head;
    Node *NewHead = Reverse(head->next);
    head->next->next = head;
    head->next = NULL;
    return NewHead;
}
int main()
{
    Node *head = NULL;
    cout << "insert At head" << endl;
    insertAtHead(head, 3);
    insertAtHead(head, 2);
    print(head);
    cout << endl;
    cout << "Insert at Tail " << endl;
    insertAtTail(head, 4);
    insertAtTail(head, 5);
    insertAtTail(head, 6);
    insertAtTail(head, 10);
    insertAtTail(head, 9);
    insertAtKey(head, 10, 45);
    print(head);

    deleteNode(head, 2);
    cout << "deleting the head" << endl;
    print(head);
    cout << endl;
    cout << "reversing the linked list " << endl;
    Node *NewHead = Reverse(head);

    print(NewHead);
}
Node *Reverse(Node *&head)
{
    if (head == NULL || head->next == NULL)
        return head;
    Node *NewHead = Reverse(head->next);
    head->next->next = head;
    head->next = NULL;
    return NewHead;
}
//in main the previous head becomes the last node
int main(){
  Node*newHead=Reverse(head);
  print(newhead);
}
// c++ program to create a linked list insert element at head, at tail and delete element from
// tail, head and specific key
#include <iostream>
using namespace std;
struct Node
{
public:
    int data;
    Node *next;
    Node(int data)
    {
        this->data = data;
        this->next = NULL;
    }
};
void insertAtHead(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    NewNode->next = head;
    head = NewNode;
}
void insertAtTail(Node *&head, int data)
{
    Node *NewNode = new Node(data);
    if (head == NULL)
    {
        NewNode->next = head;
        head = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->next != NULL)
    {
        temp = temp->next;
    }
    temp->next = NewNode;

    cout << "the value of temp next is " << temp->data << endl;
}
void insertAtKey(Node *&head, int key, int data)
{
    Node *NewNode = new Node(data);
    if (head->data == key)
    {

        NewNode->next = head->next;
        head->next = NewNode;
        return;
    }
    Node *temp = head;
    while (temp->data != key)
    {
        temp = temp->next;
        if (temp == NULL)
            return;
    }
    NewNode->next = temp->next;
    temp->next = NewNode;
}
void print(Node *&head)
{
    if (head == NULL)
    {
        cout << head->data << " ->  ";
    }
    Node *temp = head;
    while (temp != NULL)
    {
        /* code */
        cout << temp->data << " -> ";
        temp = temp->next;
    }
}

void deleteNode(Node *&head, int key)
{
    if (head == NULL)
        return;

    if (head->data == key)
    {
        Node *temp = head;
        head = head->next;
        delete temp;
    }
    deleteNode(head->next, key);
}
int main()
{
    Node *head = NULL;
    cout << "insert At head" << endl;
    insertAtHead(head, 3);
    insertAtHead(head, 2);
    print(head);
    cout << endl;
    cout << "Insert at Tail " << endl;
    insertAtTail(head, 4);
    insertAtTail(head, 5);
    insertAtTail(head, 6);
    insertAtTail(head, 10);
    insertAtTail(head, 9);
    insertAtKey(head, 10, 45);
    print(head);

    deleteNode(head, 2);
    cout << "deleting the head" << endl;
    print(head);
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a=0b101;
   int b=0b10110;
   b<<=4;        //means b=101100000 shifting of b by 4
   int c=a|b;
   int d=a&b;
   int e=a^b;
   cout<<bitset<9>(c)<<"\n";
   cout<<bitset<9>(d)<<"\n";
   cout<<bitset<10>(e)<<"\n";
   return 0;
}
class Solution {
public:
    int equalPairs(vector<vector<int>>& grid) {
        int c=0;
        int k=grid.size()-1;
        while(k>=0)
        {
       
            vector<int>vr;
            vr=grid[k];
            for(int i=0;i<grid.size();i++)
            {
                vector<int>vc;
                for(int j=0;j<grid.size();j++)
                {
                    vc.push_back(grid[j][i]);
                }
                if(vr==vc) c++;
            }
        
            k--;
        }
        return c;
    }
};
class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, long long int target) {
        int n=nums.size();
        set<vector<int>>s;
        sort(nums.begin(),nums.end());
        for(int i=0;i<n-3;i++)
        {
            
           for(int j=i+1;j<n-2;j++)
           {
              
               int k=j+1;
               int l=n-1;
               while(k<l)
               {
                   long long int t=0LL+nums[i]+nums[j]+nums[k]+nums[l];
                   if(t==target)
                   {
                       vector<int>v;
                       v.push_back(nums[i]);
                       v.push_back(nums[j]);
                       v.push_back(nums[k]);
                       v.push_back(nums[l]);
                       s.insert(v);
                      
                       
                   }
                   if(t>target) l--;
                   else k++;
               }
           }
        }
        vector<vector<int>>v1;
        set<vector<int>>::iterator it;
        for(it=s.begin();it!=s.end();it++)
        {
            v1.push_back(*it);
        }
        return v1;
    }
};
class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        priority_queue<int,vector<int>,greater<int>>minH;
        for(int i=0;i<nums.size();i++)
        {
            minH.push(nums[i]);
            if(minH.size()>k)
            {
                minH.pop();
            }
        }
    return minH.top();
    }
};
class Solution{
    public:
    // arr : given array
    // l : starting index of the array i.e 0
    // r : ending index of the array i.e size-1
    // k : find kth smallest element and return using this function
    int kthSmallest(int arr[], int l, int r, int k) {
       priority_queue<int>maxpq;
       for(int i=l;i<=r;i++)
       {
           maxpq.push(arr[i]);
           if(maxpq.size()>k)
           {
              maxpq.pop();
           }
           
       }
       return maxpq.top();
        
    }
};
int flipBits(int* arr, int n) 
{  int count = 0;
   for(int i = 0; i<n; i++){
       if(arr[i] == 1){
           count++;
       }
   }
 int sum = 0;
 int max = 0;
   for(int i = 0; i<n; i++){
       if(arr[i] == 0){
         sum++;
           
       }else{
           sum--;
       }
    
       if(sum < 0){
           sum = 0;
       }
       if(sum > max){
          max = sum;
       }
   }
 
 return count + max;
}
  int e,v;
    cin>>v>>e;
    int** arr = new int*[v];
    for(int i = 0; i<v; i++){
        arr[i] = new int [v];
        for(int j = 0; j<v; j++){
            arr[i][j] = 0;
        }
    }
    int x, y;
     for(int i = 0; i<e; i++){
         cin>>x>>y;
         arr[x][y] = 1;
         arr[y][x] = 1;
     }
    
#include<iostream>
using namespace std;
struct Node {
public:
	int data;
	Node* next;
	Node(int data=0)
	{
		this->data = data;
		this->next = NULL;
	}
};
void push(Node** head_ref, int data) {
	//creating the new node and by using constructor we 
	//are storing the value of the data
	//firstly the next pointer of this new node points to NULL
	//as declared in the constructor
	//then we are pointing the pointer of this node to the new node
	//and lastly we are equating the new insert node to the previous 
	//node to connect it to the list
	Node* new_node = new Node(data);
	new_node->next =(* head_ref);
	*(head_ref) = new_node;

}
void print(Node*& head) {

	Node* temp =  head;
	while (temp != NULL)
	{
		cout << "the value of the data is " << temp->data << endl;
		temp = temp->next;
	}

}

int main() {
	Node* node;
	node = NULL;
	push(&node, 5);
	push(&node, 6);
	push(&node, 7);
	print(node);
	return 0;


}
#include<iostream>
using namespace std;
void sort(int* array, int size) {
	int key = 0, j = 0;
	for (int i = 1; i < size; i++)
	{
		key = array[i];
		j = i - 1;
		while (j >= 0 && array[j] > key)
		{
			array[j + 1] = array[j];
			j = j - 1;
		}
		array[j + 1] = key;
	}
	for (int i = 0; i < size; i++)
		cout << array[i] << "  ";
}
int main() {
	int size = 0;
	cout << "Enter size of the array " << endl;
	cin >> size;
	int* array = new int[size];
	cout << "Enter elements of the array " << endl;
	for (int i = 0; i < size; i++)
		cin >> array[i];
	sort(array, size);
}
#include<iostream>
using namespace std;
template<typename T>
T* addArray(T* array, int size);
template<typename T>
T primeNumber(T number);
template<typename T>
T Factorial(T number);
 
 
int main() {
 
	int IntNum, Size;
	float FloatNum;
	
	cout << "Enter an integer " << endl;
	cin >> IntNum;
	cout << "Enter a float number " << endl;
	cin >> FloatNum;
	cout << "Enter size of the array " << endl;
	cin >> Size;
	int* Array = new int[Size];
	cout << "Enter elements of the array " << endl;
	for (int i = 0; i < Size; i++)
		cin >> Array[i];
	addArray<>(Array, Size);
	if (primeNumber<int>(IntNum) == true);
	cout << IntNum << " is a prime number " << endl;
	if(primeNumber<int>(IntNum) == false)
		cout << IntNum << " is not  a prime number " << endl;
	cout<<"Factorial of the "<<IntNum<<" is "<<Factorial<int>(IntNum);
	
	return 0;
}
template<typename T>
T primeNumber(T number) {
	bool flag = false;
	for (int i = 2; i < number; i++)
		if (number % i == 0)
			return flag;
	flag = true;
	return true;
}
 
template<typename T>
T Factorial(T number) {
	if (number >=1)
		return number * Factorial(number - 1);
	else {
		return 1;
		
	}
		
}
 
template<typename T>
T* addArray(T* array, int size) {
	T* newarray = new int[size];
	for (int i = 0; i < size; i++)
		newarray[i] = array[i] + array[i];
	return newarray;
}
 
#include<iostream>
using namespace std;
void sets(int* array, int size);
int main() {
	int size = 0;
	cout << "Enter size of the array" << endl;
	cin >> size;
	int* array = new int[size];
	cout << "Enter elements of the array " << endl;
	for (int i = 0; i < size; i++)
		cin >> array[i];
	sets(array, size);
	return 0;
}
void sets(int* array, int size) {
	int* newarray1 = nullptr;
	int* newarray2 = nullptr;
	int median = size / 2;
	if (size % 2 == 0) {
		 newarray1 = new int[median];
		 newarray2 = new int[median];
	}
	else if (size % 2 != 0)
	{
		 newarray1 = new int[median+1];
		 newarray2 = new int[median];
	}
	//applying the insertion sort to sort the elements in ascending order
	int key;
	for (int i = 1; i < size; i++)
	{
		key = array[i];
		int j = i - 1;
		while (j>=0&&array[j]>key)
		{
			array[j + 1] = array[j];
			j = j - 1;
		}
		array[j + 1] = key;
		
	}
	for (int i = 0; i < size; i++)
				cout << array[i] << "  ";
	
	if (size % 2 == 0) {
		for (int i = 0; i < median; i++)
		{
			newarray1[i] = array[i];
		}
		for (int i = median; i < size; i++)

			newarray2[i-median] = array[i];
	}

	if (size % 2 != 0)
	{
		for (int i = 0; i < median + 1; i++)
			newarray1[i] = array[i];

		for (int j = median + 1; j < size; j++)
			newarray2[j - median + 1] = array[j];
	}

	cout << endl;
	if (size % 2 == 0) {
		for (int i = 0; i < median; i++)
		{
			cout << newarray1[i] <<  "  " << endl;
		}
		cout << endl;
		for (int i = median; i < size; i++)

			cout << newarray2[i - median] <<"  " << endl;

		cout << endl;
	}

	if (size % 2 != 0)
	{
		for (int i = 0; i < median + 1; i++)
			cout << newarray1[i] << "  "  << "  " << endl;
		cout << endl;
		for (int j = median + 1; j < size; j++)
			cout << newarray2[j - median + 1] << "   "  << endl;
	}
	


}
#include<iostream>
using namespace std;
template<typename T>
T* addArray(T* array, int size);
template<typename T>
T primeNumber(T number);
template<typename T>
T Factorial(T number);


int main() {

	int IntNum, Size;
	float FloatNum;
	
	cout << "Enter an integer " << endl;
	cin >> IntNum;
	cout << "Enter a float number " << endl;
	cin >> FloatNum;
	cout << "Enter size of the array " << endl;
	cin >> Size;
	int* Array = new int[Size];
	cout << "Enter elements of the array " << endl;
	for (int i = 0; i < Size; i++)
		cin >> Array[i];
	addArray<>(Array, Size);
	if (primeNumber<int>(IntNum) == true);
	cout << IntNum << " is a prime number " << endl;
	if(primeNumber<int>(IntNum) == false)
		cout << IntNum << " is not  a prime number " << endl;
	cout<<"Factorial of the "<<IntNum<<" is "<<Factorial<int>(IntNum);
	
	return 0;
}
template<typename T>
T primeNumber(T number) {
	bool flag = false;
	for (int i = 2; i < number; i++)
		if (number % i == 0)
			return flag;
	flag = true;
	return true;
}

template<typename T>
T Factorial(T number) {
	if (number >=1)
		return number * Factorial(number - 1);
	else {
		return 1;
		
	}
		
}

template<typename T>
T* addArray(T* array, int size) {
	T* newarray = new int[size];
	for (int i = 0; i < size; i++)
		newarray[i] = array[i] + array[i];
	return newarray;
}

#include<iostream>
using namespace std;
template<typename T>
void swap(T* xp, T* yp);
template<typename T>
void sort(T* array, int size);
template<typename T>
void print(T* array, int size);
int main() {
	int size;//for taking size of the array 
	cout << "enter size of the array " << endl;
	cin >> size;
	int* array = new int[size];
	//taking input
	cout << "Enter values of the array " << endl;
	for (int i = 0; i < size; i++)
		cin >> array[i];
	//calling sort function
	sort<int>(array, size);
	//calling print function
	print<int>(array, size);
	return 0;
}

template<typename T>
void swap(T* xp, T*yp) {
	T temp;
	temp = *xp;
	*xp = *yp;
	*yp = temp;
}
template<typename T>
void sort(T* array, int size) {

	for (int i = 0; i < size-1; i++)
	{
		for (int j = i + 1; j < size; j++) {
			if (array[i] > array[j])
				swap(&array[j], &array[i]);
			
		}
	}


}
template<typename T>
void print(T* array, int size) {
	for (int i = 0; i < size; i++)
		cout << array[i] << "  ";
}

#include<iostream>
using namespace std;
template<typename T>
void sort(T* array, int size);
template<typename T>
void swap(T* xp, T* yp);
template<typename T>
void print(T* array, int size);
int main() {
	int size;
	cout << "enter size of the array " << endl;
	cin >> size;
	int* array = new int[size];
	cout << "enter elements of the array " << endl;
	for (int i = 0; i < size; i++)
		cin >> array[i];
	sort<int>(array, size);
	print<int>(array, size);
	return 0;
}
template<typename T>
void swap(T* xp, T* yp) {
	T temp;
	temp = *xp;
	*xp = *yp;
	*yp = temp;
}
template<typename T>
void sort(T* array, int size) {
	int min_index;
	for (int i = 0; i < size-1; i++)

	{
		min_index = i;
		for (int j = i + 1; j < size; j++)
			if (array[j] < array[min_index])
				min_index = j;
		swap(&array[min_index], &array[i]);
				

	}

}
template<typename T>
void print(T* array, int size) {
	for (int i = 0; i < size; i++)
		cout << array[i] << "  ";

}
#include <iostream>
using namespace std;
int main(){
  cout << "Print data" << endl;
  cerr << "Print error" << endl;
  clog << "Print log" << endl;
  int nilai;
  cin >> nilai;
  cout << "Nilai: " << nilai << endl;
  return 0;
}
/* Ini adalah program C++
untuk menampilkan Hello World di layar */

#include<iostream> 		// File header yang berisi fungsi untuk operasi i/o (input/output)
using namespace std; 		// Namespace
int main(){ 			// Eksekusi program dimulai dari sini
  cout << "Hello World" << endl;// Ini akan mencetak Hello World di layar
  int nilai = 97;		// variabel
  cout << nilai << endl;	// Ini akan mencetak 97 di layar
  return 0; 			// Eksekusi program berhasil
}
class Solution
{
    public:
    //Function to check if two trees are identical.
    bool isIdentical(Node *r1, Node *r2)
    {
        if(r1==NULL && r2==NULL) return 1;
        if(r1!=NULL && r2!=NULL)
        { return
          (r1->data==r2->data 
          && isIdentical(r1->left,r2->left) 
          && isIdentical(r1->right,r2->right));
        }
        return 0;
        //Your Code here
    }
};
class Solution {
  public:
  int height(Node* temp)
  {
      if(temp==NULL)
      return 0;
      int lh= height(temp->left);
      int rh=height(temp->right);
      
      return 1+max(lh,rh);
  }
    // Function to return the diameter of a Binary Tree.
    int diameter(Node* root) {
        if(root==NULL) return 0;
        int lh=height(root->left);
        int rh=height(root->right);
        
        int ld=diameter(root->left);
        int rd=diameter(root->right);
        
        return max(lh+rh+1,max(ld,rd));
        // Your code here
    }
};
class Solution{
    public:
    int height(Node * temp)
    {
        if(temp==NULL) return 0;
        int lh=height(temp->left);
        int rh=height(temp->right);
        return 1+max(lh,rh);
    }
    //Function to check whether a binary tree is balanced or not.
    bool isBalanced(Node *root)
    {
        
        if(root==NULL) return 1;
        int lh=height(root->left);
        int rh=height(root->right);
        if(abs(lh-rh)<=1 && isBalanced(root->left) && isBalanced(root->right)) return 1;
        return 0;
        //  Your Code here
    }
};
class Solution{
    public:
    //Function to find the height of a binary tree.
    int depth(Node* temp)
    {
        if(temp==NULL) return 0;
        int lh=depth(temp->left);
        int rh=depth(temp->right);
        return 1+max(lh,rh);
    }
    int height(struct Node* node){
         int ans=depth(node);
         return ans;
        // code here 
    }
};
#include <bits/stdc++.h>
using namespace std;

class node
{
    public:
    int data;
    node *left,*right;
    
    node(int d)
    {
        this->data=d;
        this->left=NULL;
        this->left=NULL;
    }
};

void deletetree(node* temp)
{
    if(temp==NULL)
    return;
    deletetree(temp->left);
    deletetree(temp->right);
    cout << "\n Deleting node: " << temp->data;
    delete temp;
}
int main() {
    node *root=new node(6);
    root->left=new node(8);
    root->right=new node(7);
    root->left->left=new node(5);
    root->left->right=new node(2);
    root->right->left=new node(8);
    root->right->right=new node(3);
    deletetree(root);
    root=NULL;
    
    cout << "\n Tree deleted ";
	return 0;
}
// Balanced Bracket Problem Method2.

#include<bits/stdc++.h>
using namespace std ;


bool isBalanced(string str)
{
    map<char, int> m ;
    m['('] = -1 ; m['{'] = -2 ; m['['] = -3 ; m[')'] = 1 ; m['}'] = 2 ; m[']'] = 3 ; 
    stack<int> s; 
    for(int i=0; i<str.length(); i++){
        if(m[str[i]] < 0) s.push(m[str[i]]) ;
        else {
            if(s.empty()) return false ;
            else if(m[str[i]]+s.top() != 0) return false ;
            else s.pop() ;
        }
    }
    return (s.empty()) ;
}

int main()
{
    string s ; cin >> s ;
    cout << isBalanced(s) << endl ;
    
    
    return 0 ;
}
// Balanced Bracket Problem 

#include<bits/stdc++.h>
using namespace std ;

bool matching(char a, char b)
{
    return ((a == '(' and b == ')') ||
            (a == '{' and b == '}') ||
            (a == '[' and b == ']')  ) ;
}

bool isBalanced(string str)
{
    stack<int> s; 
    for(int i=0; i<str.length(); i++){
        if(str[i] == '(' or str[i] == '{' or str[i] == '[')
        s.push(str[i]) ;
        else {
            if(s.empty()) return false ;
            else if(!matching(s.top(), str[i])) return false ;
            else s.pop() ;
        }
    }
    return (s.empty()) ;
}

int main()
{
    string s ; cin >> s ;
    cout << isBalanced(s) << endl ;
    
    
    return 0 ;
}
// [ 1 0 1 1 1 0 0 ]  => [ 1 -1 1 1 1 -1 -1 ]
// Longest Subarray for sum = 0  
// longest Subarray with equal number of zeros and one 

#include<bits/stdc++.h>
using namespace std ;

int marLen(int a[], int n)
{
    unordered_map<int, int> m ; vector <int> v ; 
    int pre_sum = 0 ; int res = 0 ; cout << "res = " ;
    for(int i=0; i<n; i++){
        pre_sum += a[i] ; v.push_back(pre_sum) ; 
        if(pre_sum == 0) res = i+1 ;
        
        if(m.find(pre_sum) == m.end())
        m.insert(make_pair(pre_sum, i)) ;
        
        if(m.find(pre_sum) != m.end())
        res = max(res, i-m[pre_sum]) ;
        
        cout << res << " " ;
    } cout << endl ;
    for(int x : v) cout << x << "  " ;
    cout << endl ;
    return res ;
}

int main()
{
    
    int n ; cin >> n ; int a[n] = {0} ;
    for(int i=0; i<n; i++) cin >> a[i] ;
    for(int i=0; i<n; i++){
        if(!a[i]) a[i] = -1 ;
    }
    cout << marLen(a, n) << endl ;
    
    return 0 ;
}

/* Input -- 7
            1 0 1 1 1 0 0
            
            res = 0 2 2 2 2 2 6 
            1  0  1  2  3  2  1  
            6
*/

// Longest Subarray with equal number of 0s and 1s
// Naive Solution 

#include<bits/stdc++.h>
using namespace std ;

int longestSub(int a[], int n)
{
    int res = 0 ; //cout << "max = " ; //int x = 0 ; int y = 0 ;
    for(int i=0; i<n; i++){
        int c0 = 0 ; int c1 = 0 ;
        for(int j=i; j<n; j++){
            if(a[j] == 0) c0++ ;
            else c1++ ;
            
            if(c0 == c1) res = max(res, j-i+1) ;
        }
        //x = c0 ; y = c1 ;
        //cout << res << " " ;
    }
    //cout << endl ; cout << "c0 = " << x << " c1 = " << y << endl ;
    return res ;
}

int main()
{
    int n ; cin >> n ; int a[n] = {0} ;
    for(int i=0; i<n; i++) cin >> a[i] ;
    
    cout << longestSub(a, n) << endl ;
    
    return 0 ;
}
// Longest Subarray for given sum   

#include<bits/stdc++.h>
using namespace std ;

int marLen(int a[], int n, int sum)
{
    unordered_map<int, int> m ; vector <int> v ; vector <int> v1 ;
    int pre_sum = 0 ; int res = 0 ; cout << "res = " ;
    for(int i=0; i<n; i++){
        pre_sum += a[i] ; v.push_back(pre_sum) ; v1.push_back(pre_sum - sum) ; 
        if(pre_sum == sum) res = i+1 ;
        
        if(m.find(pre_sum) == m.end())
        m.insert(make_pair(pre_sum, i)) ;
        
        if(m.find(pre_sum-sum) != m.end())
        res = max(res, i-m[pre_sum-sum]) ;
        
        cout << res << " " ;
    } cout << endl ;
    for(int x : v) cout << x << "  " ;
    cout << endl ;
    for(int x : v1) cout << x << "  " ;
    cout << endl ;
    return res ;
}

int main()
{
    
    int n ; cin >> n ; int a[n] = {0} ;
    int sum ; cin >> sum ;
    for(int i=0; i<n; i++) cin >> a[i] ;
    
    cout << marLen(a, n, sum) << endl ;
    
    return 0 ;
}

/* Input -- 8 4
            8 3 1 5 -6 6 2 2
            
    Output -- 
    res = 0 0 2 2 2 2 2 4 
    8  11  12  17  11  17  19  21  
    4  7  8  13  7  13  15  17  
    4
    
*/

// Subarray sum Problem  

#include<bits/stdc++.h>
using namespace std ;

bool isSumSubarray(int a[], int n, int sum)
{
    unordered_set<int> s ; //cout << "sum = " << sum << endl ;
    int pre_sum = 0 ;
    for(int i=0; i<n; i++){
        
        pre_sum += a[i] ;
        if(pre_sum == sum) return true ;
        if(s.find(pre_sum - sum) != s.end()) return true ;
        s.insert(pre_sum) ;
    }
    return false ;
}

int main()
{
    
    int n ; cin >> n ; int a[n] = {0} ;
    int sum ; cin >> sum ;
    for(int i=0; i<n; i++) cin >> a[i] ;
    
    bool ans = isSumSubarray(a, n, sum) ;
    cout << ans << endl ;
    
    return 0 ;
}
// Subarray with zero sum array (distinct) 
// [ -3,  4,  -3,  -1,  1  ]
//    a0, a1, .... ai-1,  ai, ai+1  .....  aj 
//    <-PreSum1.....->    <-....Sum[i:j]...->
//    <-............PreSum2................->   
// if Sum[i:j] = 0 , PreSum1 = PreSum2  

#include<bits/stdc++.h>
using namespace std ;

bool isZeroSubarray(int a[], int n)
{
    bool ans = false ;   vector<int> pre ;
    unordered_set<int> h ;
    int pre_sum = 0 ;  int x = 0 ; int y = 0 ;
    for(int i=0; i<n; i++){
        pre_sum += a[i] ;  pre.push_back(pre_sum) ;
        //cout << pre_sum << "  " ;
        if(h.find(pre_sum) != h.end()){
            auto it = h.find(pre_sum) ; x = *it ; y = i ;
            ans = true ; break ;
        }
        if(pre_sum == 0) {
            ans = true ; break ;
        } 
        h.insert(pre_sum) ;
    }
    cout << "x = " << x << "y = " << y << endl ;
    for(auto a : pre) cout << a << "  " ;
    cout << endl ;
    for(int i =x; i<=y; i++) cout << a[i] << "  " ;
    //cout << endl ;
    return ans ;
    
}

int main()
{
    
    int n ; cin >> n ; int a[n] = {0} ;
    for(int i=0; i<n; i++) cin >> a[i] ;
    
    bool ans = isZeroSubarray(a, n) ;
    cout << endl << ans << endl ;
    
    return 0 ;
}
// { Driver Code Starts
// C program to find n'th Node in linked list
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
using namespace std;

/* Link list Node */
struct Node {
  int data;
  struct Node *next;
  Node(int x) {
    data = x;
    next = NULL;
  }
};


/* Function to get the nth node from the last of a linked list*/
int getNthFromLast(struct Node* head, int n);



/* Driver program to test above function*/
int main()
{
  int T,i,n,l,k;

    cin>>T;

    while(T--){
    struct Node *head = NULL,  *tail = NULL;

        cin>>n>>k;
        int firstdata;
        cin>>firstdata;
        head = new Node(firstdata);
        tail = head;
        for(i=1;i<n;i++)
        {
            cin>>l;
            tail->next = new Node(l);
            tail = tail->next;
        }

    cout<<getNthFromLast(head, k)<<endl;
    }
    return 0;
}// } Driver Code Ends


/* struct Node {
  int data;
  struct Node *next;
  Node(int x) {
    data = x;
    next = NULL;
  }
};
*/

//Function to find the data of nth node from the end of a linked list.
int getNthFromLast(Node *head, int n)
{
       // Your code here
    int count=0;
    Node* i=head;
    Node* t=head;
    while(i!=NULL)
    {
        count++;
        i=i->next;
    }
    int c=1;
    if(n>count ) return -1;
    count = count-n;
    for(int k=0;k<count;k++)
    t=t->next;
    return t->data;
  
}

data_type *var_name = 
       reinterpret_cast <data_type *>(pointer_variable);
class Solution{
    public:
    //Function to find if there exists a triplet in the 
    //array A[] which sums up to X.
    bool find3Numbers(int A[], int n, int X)
    {
        //Your Code Here
         int j;
    int k;
    //Your Code Here
    sort(A,A+n);
    for(int i=0;i<n-2;i++)
    {
       j=i+1;
       k=n-1;
       while(j<k)
       {
         if(A[i]+A[j]+A[k]==X) return 1;
         if(A[i]+A[j]+A[k]>X) k--;
         else j++;
       }
    }
    return 0;
    }

};
vector<vector<int> > Solution::threeSum(vector<int> &A) {
    vector<int>v1;
    set<vector<int>>s;
    int n=A.size();
    sort(A.begin(),A.end());
    for(int i=0;i<n-2;i++)
    {
        int j=i+1;
        int k=n-1;
        while(j<k)
        {  
            long long sum = 0LL+A[i]+A[j]+A[k];
            if(sum==0)
            {
            v1.push_back(A[i]);
            v1.push_back(A[j]);
            v1.push_back(A[k]);
            s.insert(v1);
            v1.clear();
            }
            if(A[i]+A[j]+A[k]<0) j++;
            else k--; 
        }
        
    }
    vector<vector<int>>v2(s.begin(),s.end());
    return v2;
}
#include <bits/stdc++.h>
using namespace std;

class base
{
   public:
   int x;
   void show()
   {
      cout<<x<<"\n";
   }
};

class derived:public base       //Inheritance
{
   public:
   int y;
   
   void display()
   {
      cout<<x<<" "<<y<<"\n";
   }
};
int main()
{
	base b;
	b.x=4;
	b.show();
	derived d;
	d.x=10;
	d.y=5;
	d.show();
	d.display();
	
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

class Complex
{
   public:
    int real;
    int img;
   
   Complex(int r=0,int i=0)
   {
      real=r;
      img=i;
   }
   friend Complex operator+(Complex c1,Complex c2);  //friend 
   void display()                          //operator overloading
   {
      
   }
};
Complex operator+(Complex c1,Complex c2)  //operator overloading
    {
      Complex temp;
      temp.real=c1.real+c2.real;
      temp.img=c1.img+c2.img;
      return temp;
    }
int main()
{
   Complex c1(2,5),c2(3,5),c3;
   
   c3=c1+c2;
   cout<<c3.real<<"+i"<<c3.img<<endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

class Complex
{
   public:
    int real;
    int img;
   
   Complex(int r=0,int i=0)
   {
      real=r;
      img=i;
   }
   Complex operator+(Complex c)  //operator overloading or
    {                            //(Complex add(Complex c)
      Complex temp;
      temp.real=real+c.real;
      temp.img=img+c.img;
      return temp;
    }
};
int main()
{
   Complex c1(2,5),c2(3,5),c3;
   
   c3=c1+c2;                     // or c3=c1.add(c2);
   cout<<c3.real<<"+i"<<c3.img<<endl;
	return 0;
}
//There have 3 constructors with same name called overloading
                  

#include <bits/stdc++.h>
using namespace std;
class rectangle             //class
{
   private:
   int length;
   int breadth;
   public:
   
   rectangle()              //non-parameterised constructor
   {
      length=5;
      breadth=4;
   }
   rectagle(int l=5,int b)        //parameterised constructor
   {
      setLength(l);
      setBreadth(b);
   }
   rectangle(rectangle &r)       //copy constructor
   {
      length=r.length;
      breadth=r.breadth;
   }
   void setLength(int l)
   {
      if(l>0) length=l;
      else length=1;
   }
   void setBreadth(int b)
   {
      if(b>0) breadth=b;
      else breadth=1;
   }
   int getLength()
   {
      return length;
   }
   int getBreadth();     //Define outside class with scope resolution

   int area()
   {
      return length*breadth;
   }
   int perimeter();      //Define outside class with scope resolution
};

int rectangle::perimeter()   //Define outside class with scope            {                                    // resolution
      return 2*(length+breadth);
     }
                            
  
int rectangle::getBreadth()   //Define outside class with scope          {                                  //resolution
      return breadth;
   }

int main()
{
rectangle r1;                 //object r1
r1.setLength(15);
r1.setBreadth(2);
rectangle r2(r1);             //object r2
cout<<r1.area()<<"\n";
cout<<r1.perimeter()<<"\n";
cout<<r2.perimeter()<<"\n";
	return 0;
}
class Solution {
public:
    string convertToTitle(int n) {
        string result="";
        while(n){
            char c='A'+(n-1)%26;
            result=c+result;
            n=(n-1)/26;
        }
        return result;
    }
};
class Solution {
public:
    int titleToNumber(string columnTitle) {
        int sum=0;
        
        int n=columnTitle.size();
        for(int i=0;i<n-1;i++)
        {
            sum=sum+pow(26,(n-i-1))*(columnTitle[i]-'A'+1);
        }
        sum=sum+(columnTitle[n-1]-'A'+1);
        return sum;
    }
};
class Solution {
public:
    bool isPalindrome(int x) {
        string s1=to_string(x);
      string s=to_string(x);
        int n=s.length();
        for(int i=0;i<n/2;i++)
        {
            swap(s[i],s[n-1-i]);
        }
        if(s1==s) return true;
        else return false;
    }
};
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int j=0;
        for(int i=0;i<nums.size();i++)
        {
            if(nums[i]!=0) 
            {
                nums[j]=nums[i];
                j++;
            }
        }
        for(int i=j+1;j<nums.size();j++)
        {
            nums[j]=0;
        }
    }
};
int mxl[size];
int mxr[size];
mxl[0]=arr[0];
for(int i=1;i<size;i++)
  {
    mxl[i]=max(mal[i-1],arr[i]);
  }
mxr[size-1]=arr[size-1];
for(int i=size-2;i>=0;i--)
  {
    mxr[i]=max(mxr[i+1],arr[i])
  }
int water[size];
for(int i=0;i<size;i++)
  water[i]=min(mxl[i],mxr[i])-arr[i];
int sum=0;
for(int i=0;i<size;i++)
  sum=sum+water[i];
return sum;
//input arr[n][m];

vector<int>v;
for(int j=0;j<m;j++)
  v.push_back(arr[0][j])
int max=MAH(v);

for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
      {
        if(arr[i][j]==0)
          v[j]=0;
        else v[j]=v[j]+arr[i][j];
      }
    max=max(max,MAH(V));
  }
return max;            //final answer

            //MAH FUNCTION
vector<int>left;
stack<pair<int,int>>s;
int pseudo_index=-1;
for(int i=0;i<n;i++)
  {
    if(s.size()==0)
      {
        left.push_back(pseudo_index);
      }
    else if(s.size()>0 && s.top().first<arr[i])
      {
        left.push_back(s.top());
      }
    else if(s.size()>0 && s.top().first>=arr[i])
      {
        while(s.size()>0 && s.top().fisrt>=arr[i])
          {
            s.pop();
          }
        if(s.size()==0)
          left.push_back(s.top().second);
      }
    s.push(arr[i];)
  }
return left;               //NSL completed

vector<int>right;          //NSR doing
stack<pair<int,int>>s2;
int pseudo_index=7;
for(int i=size-1;i>=0;i--)
  {
    if(s2.size()==0)
      {
        right.push_back(pseudo_index);
      }
    else if(s2.size()>0 && s2.top().first<arr[i])
      {
        right.push_back(s.top());
      }
    else if(s2.size()>0 && s2.top().first>=arr[i])
      {
        while(s2.size()>0 && s2.top().fisrt>=arr[i])
          {
            s2.pop();
          }
        if(s2.size()==0)
          right.push_back(s2.top().second);
      }
    s2.push(arr[i];)
  }
reverse (right.begin(),right.end());
return right;           //NSR completed
 

for(int i=0;i<size;i++)
  {
    width[i]=right[i]-left[i]-1;
  }
for(int i=0;i<size;i++){
  area[i]=arr[i]*width[i];
}
return max of area[i];       //MAH FINAL VALUE
vector<int>left;
stack<pair<int,int>>s;
int pseudo_index=-1;
for(int i=0;i<n;i++)
  {
    if(s.size()==0)
      {
        left.push_back(pseudo_index);
      }
    else if(s.size()>0 && s.top().first<arr[i])
      {
        left.push_back(s.top());
      }
    else if(s.size()>0 && s.top().first>=arr[i])
      {
        while(s.size()>0 && s.top().fisrt>=arr[i])
          {
            s.pop();
          }
        if(s.size()==0)
          left.push_back(s.top().second);
      }
    s.push(arr[i];)
  }
return left;               //NSL completed

vector<int>right;          //NSR doing
stack<pair<int,int>>s2;
int pseudo_index=7;
for(int i=size-1;i>=0;i--)
  {
    if(s2.size()==0)
      {
        right.push_back(pseudo_index);
      }
    else if(s2.size()>0 && s2.top().first<arr[i])
      {
        right.push_back(s.top());
      }
    else if(s2.size()>0 && s2.top().first>=arr[i])
      {
        while(s2.size()>0 && s2.top().fisrt>=arr[i])
          {
            s2.pop();
          }
        if(s2.size()==0)
          right.push_back(s2.top().second);
      }
    s2.push(arr[i];)
  }
reverse (right.begin(),right.end());
return right;           //NSR completed
 

for(int i=0;i<size;i++)
  {
    width[i]=right[i]-left[i]-1;
  }
for(int i=0;i<size;i++){
  area[i]=arr[i]*width[i];
}
return max of area[i];       //final answer
vector<int> v;
stack<pair<int,int>> s;        //first is ngl and second is its index
for(int i=0;i<size;i++)
  {
    if(s.size()==0)
      {
        v.push_back(-1);
      }
    else if(s.size()>0 && s.top().first<=arr[i])
      {
        v.push_back(s.top().second)
      }
    else if(s.size()>0 && s.top().first<=arr[i])
      {
        while(s.size()>0 && s.top().first<=arr[i])
          {
            s.pop();
          }
        if(s.size()==0)
          v.push_back(-1);
        else v.push_back(s.top().second)
      }
    s.push({arr[i],i});
  }
  return v;                         //NGL we got

for(int i=0;i<v.size();i++)
  {
    v[i]=i-v[i];
  }
return v;                           //final answer
vector<int>v;
stack<int>s;

for(int i=size-1;i>=0;i--)
{
   if(s.size()==0)
   {
      v.push_back(-1);
   }
   else if(s.size()>0&&s.top()<arr[i])
   {
      v.push_back(s.top())
   }
   else if(s.size()>0&&s.top()>=arr[i])
   {
      while(s.size()>0&&s.top>=arr[i])
      {
         s.pop();
      }
      if(s.size()==0)
      {
         v.push_back(-1);
      }
      else{
         v.push_back(s.top());
      }
   }
   s.push(arr[i]);
}
reverse(v.begin(),v.end());
vector<int>v;
stack<int>s;

for(int i=0;i<n;i++)
{
   if(s.size()==0)
   {
      v.push_back(-1);
   }
   else if(s.size()>0&&s.top()<arr[i])
   {
      v.push_back(s.top())
   }
   else if(s.size()>0&&s.top()>=arr[i])
   {
      while(s.size()>0&&s.top>=arr[i])
      {
         s.pop();
      }
      if(s.size()==0)
      {
         v.push_back(-1);
      }
      else{
         v.push_back(s.top());
      }
   }
   s.push(arr[i]);
}
vector<int>v;
stack<int>s;

for(int i=0;i<n;i++)
{
   if(s.size()==0)
   {
      v.push_back(-1);
   }
   else if(s.size()>0&&s.top()>arr[i])
   {
      v.push_back(s.top())
   }
   else if(s.size()>0&&s.top()<=arr[i])
   {
      while(s.size()>0&&s.top<=arr[i])
      {
         s.pop();
      }
      if(s.size()==0)
      {
         v.push_back(-1);
      }
      else{
         v.push_back(s.top());
      }
   }
   s.push(arr[i]);
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void deleteNode(ListNode* node) {
       ListNode* temp;
        node->val=node->next->val;
        temp=node->next->next;
        delete(node->next);
        node->next=temp;
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* middleNode(ListNode* head) {
        int count=0;
        ListNode *i=head;
        
        while(i!=NULL)
        {
            count++;
            i=i->next;
        }
        for(int i=0;i<count/2;i++)
        {
            head=head->next;
        }
        return head;
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    int getDecimalValue(ListNode* head) 
    {
Method 1;
       int count=0;
       int sum=0;
       ListNode *temp=head;
       while(temp!=NULL)
       {
           count++;
               temp=temp->next;
       }
        ListNode *temp2=head;
        while(temp2!=NULL)
        {
            sum+= temp2->val*pow(2,(count-1));
            temp2=temp2->next;
            count--;
        }
        return sum;
Method 2;
        int ans = 0;
        while(head)
        {
            ans = ans*2+head->val;
            head = head->next;
        }
        return ans;
    }
};
class Solution {
public:
    int getDecimalValue(ListNode* head) {
      ListNode* temp=head;
        int sum=0;
        int count =0;
        while(temp!=NULL)
        {
          count++;
          temp=temp->next;
        }
         ListNode* temp2=head;
        while(temp2!=NULL)
        {
            if(temp2->val==1)
            {
              sum+=(pow(2,count-1));
            }
            temp2=temp2->next;
            count--;
        }   
          return sum;
    }
};
vector<int>v;
stack<int>s;

for(int i=size-1;i>=0;i--)
{
   if(s.size()==0)
   {
      v.push_back(-1);
   }
   else if(s.size()>0&&s.top()>arr[i])
   {
      v.push_back(s.top())
   }
   else if(s.size()>0&&s.top()<=arr[i])
   {
      while(s.size()>0&&s.top<=arr[i])
      {
         s.pop();
      }
      if(s.size()==0)
      {
         v.push_back(-1);
      }
      else{
         v.push_back(s.top());
      }
   }
   s.push(arr[i]);
}
reverse(v.begin(),v.end());
class Solution
{
public:
void f(int i, vector<int> &a,
       int n,int sum,
       vector<int> &v,vector<int> &vv)
{
    if(i == n)
    {
        vv.push_back(sum);
        return;
    }
    f(i+1,a,n,sum+a[i],v,vv);
    f(i+1,a,n,sum,v,vv);
}
    vector<int> subsetSums(vector<int> arr, int n)
    {
        vector<int> v;
        vector<int> vv;
        f(0,arr,n,0,v,vv);
        sort(vv.begin(),vv.end());
        return vv;
    }
};
class Solution {
public:
    
    void f(int i,vector<int>&c, int k, 
           vector<int> &v,int sum,
           vector<vector<int>> &m)
    {
        if(i == c.size())
        {
            if(k == 0)
                m.push_back(v);
            return;
        }
        if(c[i] <= k)
        {
            v.push_back(c[i]);
            f(i,c,k-c[i],v,sum,m);
            v.pop_back();
        }
        f(i+1,c,k,v,sum,m);
    }
    vector<vector<int>> 
    combinationSum(vector<int>& c, int k)
    {
        vector<int> v;
        vector<vector<int>> m;
        f(0,c,k,v,0,m);
        return m;
    }
};
#include <bits/stdc++.h>
using namespace std;

struct node
{
   struct node* prev;
   int data;
   struct node* next;
   
}*first=NULL;
void create(int a[],int n)
{
   struct node *t,*last;
   int i;
   first=new node;
   first->data=a[0];
   first->prev=first->next=NULL;
   last=first;
   
   for(i=0;i<n;i++)
   {
      t=new node;
      t->data=a[i];
      t->next=last->next;
      t->prev=last;
      last->next=t;
      last=t;
   }
}

int lenth(struct node *p)
{
   int len=0;
   
   while(p)
   {
      len++;
      p=p->next;
   }
   return len;
}
int main()
{
	int a[]={10,20,30,40,50};
	create(a,5);
	cout<<length(first);
	display(first);
	return 0;
}
class Solution{
public:	
	// Function to check if array has 2 elements
	// whose sum is equal to the given value
	bool hasArrayTwoCandidates(int arr[], int n, int x) {
	    sort(arr,arr+n);
	    int i=0,j=n-1;
	    while(i<j)
	    {
	      if(arr[i]+arr[j]==x)
	      return 1;
	      if(arr[i]+arr[j]>x)
	      j--;
	      if(arr[i]+arr[j]<x)
	      i++;
	    }
	    return 0;
	    
	    // code here
	}
};
void deleteNode(Node *ptr)
{
 //creating temporary pointer
 Node *temp;
  //Pointing temp to link part of current node i.e. next node
 temp=ptr->next;
 //copy data and link part of next node to current node
 ptr->data=temp->data;
 //point current node to link part of next node
 ptr->next=temp->next;
 //Delete current node
 free(temp);

}
int findLoop (Node *head)
{
Node *slow, *fast;
slow=head;
fast=head;
 while (fast!=NULL && fast->next!=NULL )
 {
 fast= fast->next->next;
 slow = slow->next;
  if (slow ==  fast)
  {
  return 1;   //loop found
  }
 }
return 0;      //No loop, reached end of list
#include <iostream>
using namespace std;

//Creating Node Structure
struct Node{
 int data;
 Node *link;
};

Node *head=NULL;

//Function to reverse linked list
void reverseList()
{
Node *p,*c,*n;
p=NULL;
c=head;
while(c!=NULL)
{

 n=c->link;
 c->link=p;
 p=c;
 c=n;
}
head=p;
}

//Function to insert at the end of linked list
void insertEnd (int d)
{

 Node *ptr = new Node();
 ptr->data=d;
 ptr->link=NULL;

 if(head==NULL)
 head=ptr;
 else
 {
  Node *temp = head;
  while(temp->link != NULL)
  {
   temp=temp->link;
  }
  temp->link=ptr;

 }

}

//Function to display linked list
void displayList()
{
 Node *ptr=head;
 while(ptr!=NULL)
 {
  cout<<ptr->data<<" ";
  ptr=ptr->link;
 }
 cout<<"\n";
}

//Main Function
int main()
{
 insertEnd(1);
 insertEnd(2);
 insertEnd(3);
 insertEnd(4);
 insertEnd(5);

 displayList();
 reverseList();
 displayList();
 return 0;
}
#include <iostream>
using namespace std;

//Creating Node Structure
struct Node{
 int data;
 Node *link;
};
//creating head pointer and equating to NULL
Node *head=NULL;

//Function to Display middle element
void showMid()
{
  Node *slow=head;
  Node *fast=head;

  if(head==NULL)
   cout<<"List is Empty";
  else
  {
   while(fast!=NULL && fast->link!=NULL)
   {
    slow=slow->link;
    fast=fast->link->link;
   }
   cout<<"Middle element is:"<<slow->data;
  }

}

//Function to insert at the end of linked list
void insertEnd (int d)
{

 Node *ptr = new Node();
 ptr->data=d;
 ptr->link=NULL;

 if(head==NULL)
 head=ptr;
 else
 {
  Node *temp = head;
  while(temp->link != NULL)
  {
   temp=temp->link;
  }
  temp->link=ptr;

 }

}

//Main Function
int main()
{
 insertEnd(2);
 insertEnd(9);
 insertEnd(1);
 insertEnd(3);
 insertEnd(7);

 showMid();
 return 0;
}
struct node
{
    int data;
    node* next;
};
node* head=NULL;

void deleteend()
{
    node *ptr,*prev;
    if(head==NULL)                 //empty list
    cout<<"list empty";
    else
    if(head->next==NULL)          //only one node in list
    {
        ptr=head;
        head=NULL;
        free(ptr);
    }
    else{                            //more than one node
        ptr=head;
        while(ptr->next!=NULL)
        {
            prev=ptr;
            ptr=ptr->next;
        }
        prev->next=NULL;
        free(ptr);
    }
}
struct node
{
    int data;
    node* next;
};
node* head=NULL;

void deleteheadnode()
{
    if(head==NULL)
    cout<<"List Empty";
    else
    {
        node* ptr=head;
        head=head->next;
        free(ptr);
    }
}
#include "SteamLibrary.h";

string userName;
string passWord;

string userA = "";
string userB = "";
string userC = "";
string userD = "";
string userE = "";

string passA = "";
string passB = "";
string passC = "";
string passD = "";
string passE = "";

string loginUserInfo[5] = { userA, userB, userC, userD, userE };
string loginPassInfo[5] = { passA, passB, passC, passD, passE };

steamLibrary sl;

int main()
{
	sl.loginPage();
}

void steamLibrary :: loginPage()
{
	string loginInput;

	cout << "Login page\nA) Login\nB) Signup\n";
	cin >> loginInput;

	if (loginInput == "A")
	{
		sl.login();
	}
	if (loginInput == "B")
	{
		sl.signup();
	}
	else if (loginInput != "A" || loginInput != "B")
	{
		cout << "Please answer with either A or B\n";
		sl.loginPage();
	}
}

void steamLibrary :: login()
{
	cout << "Please enter your Username\n";
	cin >> userName;
	cout << "Please enter your Password\n";
	cin >> passWord;

	for (int i = 0; i < 5; i++)
	{
		if (userName == loginUserInfo[i])
		{
			if (passWord == loginPassInfo[i])
			{
				sl.libraryInput();
			}
			else
			{
				cout << "Please try again\n";
				sl.loginPage();
			}
		}
		else
		{
			cout << "Please try again\n";
			sl.loginPage();
		}
	}
}

void steamLibrary :: signup()
{
	if (loginUserInfo[4] != "")
	{
		cout << "There are too many accounts at this time, please try again later or login\n";
		sl.loginPage();
	}

	cout << "Please create a new Username\n";
	cin >> userName;
	for (int i = 0; i < 5; i++)
	{
		if (userName == loginUserInfo[i])
		{
			cout << "Sorry but that is taken\n";
			sl.login();
		}
	}

	for (int o = 0; o < 5; o++)
	{
		if (loginUserInfo[o] == "")
		{
			loginUserInfo[o] = userName;

			cout << "Please create a Password\n";
			cin >> loginPassInfo[o];

			sl.loginPage();
			o = 6;
		}
	}
}

void steamLibrary :: libraryInput()
{
	string libraryInput;

	cout << "Welocme to the your Game Library\nWould you like to A)Sign out or B)Go to your Game Library?\n";
	cin >> libraryInput;

	if (libraryInput == "A")
	{
		sl.loginPage();
	}
	if (libraryInput == "B")
	{
		sl.gameLibrary();
	}
	else if (libraryInput != "A" || libraryInput != "B")
	{
		cout << "Please answer with either A or B\n";
		sl.libraryInput();
	}
}

void steamLibrary :: gameLibrary()
{
	string gameChoice;

	cout << "Game Library\nWould you like to view...\nA)Buba-G\nB)Two weeks\nor C)SUWI\n...and if you are done here type D to leave.";
	cin >> gameChoice;

	if (gameChoice == "A")
	{
		sl.bubaG();
	}
	if (gameChoice == "B")
	{
		sl.twoWeeks();
	}
	if (gameChoice == "C")
	{
		sl.suwi();
	}
	if (gameChoice == "D")
	{
		sl.libraryInput();
	}
	else if (gameChoice != "A" || gameChoice != "B" || gameChoice != "C" || gameChoice != "D")
	{
		cout << "Please answer with either A, B or C\n";
		sl.gameLibrary();
	}
}

void steamLibrary :: bubaG()
{
	string libraryReturn;

	cout << "Buba-G:\n	-This all new Battleroyal released by Mysterious People, is a realistic shooter in a Player vs Player environment where the only objective is to win\n	-The age rating of this game is 18\n	-Currently the only two playable characters are Jack the crack and Lord Lynham, but we all know who is the best...\n If you want to return to the Library please type A";
	cin >> libraryReturn;

	if (libraryReturn == "A")
	{
		sl.gameLibrary();
	}
	else
	{
		cout << "If you wish to return to the Library please type A";
		sl.bubaG();
	}
}

void steamLibrary::twoWeeks()
{
	string libraryReturn;

	cout << "Two Weeks:\n	-This game is about how zombies have taken over the world and the most physically fit man must survive two weeks in this world and wait till rescue, who are these men? Dan Lynham a.k.a 'Lyndog'\n	-The age rating of this game is 15\n	-Currently the game will recieve it's first DLC soon\n	If you want to return to the Library please type A";
	cin >> libraryReturn;

	if (libraryReturn == "A")
	{
		sl.gameLibrary();
	}
	else
	{
		cout << "If you wish to return to the Library please type A";
		sl.twoWeeks();
	}
}

void steamLibrary::suwi()
{
	string libraryReturn;

	cout << "SUWI:\n	-D-Street, humanities last hope against the vegan crisis and must ultimately kill his only rival, Dan Lynham\n	-The age rating for this is 12\n	The total game time for this game is 3 minutes as a fight between these two wouldn't last that long\n	If you want to return to the Library please type A";
	cin >> libraryReturn;

	if (libraryReturn == "A")
	{
		sl.gameLibrary();
	}
	else
	{
		cout << "If you wish to return to the Library please type A";
		sl.suwi();
	}
}
Calculate sum of two numbers by taking input from user
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> adj[n+1];
  for(int i=0;i<m;i++)
    {
      int u,v;
      cin>>u>>v;
      
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  return 0;
}
priority-queue<int> maxH;
for(int i=0;i<size;i++)
  {
    maxH.push(arr[i]);
    if(maxH.size()>k)
      {
        maxH.pop();
      }
  }
return maxH.top();
/* C++ program to print level
	order traversal using STL */
#include <bits/stdc++.h>
using namespace std;

// A Binary Tree Node
struct Node {
	int data;
	struct Node *left, *right;
};

// Iterative method to find height of Binary Tree
void printLevelOrder(Node* root)
{
	// Base Case
	if (root == NULL)
		return;

	// Create an empty queue for level order traversal
	queue<Node*> q;

	// Enqueue Root and initialize height
	q.push(root);

	while (q.empty() == false) {
		// Print front of queue and remove it from queue
		Node* node = q.front();
		cout << node->data << " ";
		q.pop();

		/* Enqueue left child */
		if (node->left != NULL)
			q.push(node->left);

		/*Enqueue right child */
		if (node->right != NULL)
			q.push(node->right);
	}
}

// Utility function to create a new tree node
Node* newNode(int data)
{
	Node* temp = new Node;
	temp->data = data;
	temp->left = temp->right = NULL;
	return temp;
}

// Driver program to test above functions
int main()
{
	// Let us create binary tree shown in above diagram
	Node* root = newNode(1);
	root->left = newNode(2);
	root->right = newNode(3);
	root->left->left = newNode(4);
	root->left->right = newNode(5);

	cout << "Level Order traversal of binary tree is \n";
	printLevelOrder(root);
	return 0;
}
// C++ program for different tree traversals
#include <iostream>
using namespace std;

/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct Node {
	int data;
	struct Node *left, *right;
};

//Utility function to create a new tree node
Node* newNode(int data)
{
	Node* temp = new Node;
	temp->data = data;
	temp->left = temp->right = NULL;
	return temp;
}

/* Given a binary tree, print its nodes according to the
"bottom-up" postorder traversal. */
void printPostorder(struct Node* node)
{
	if (node == NULL)
		return;

	// first recur on left subtree
	printPostorder(node->left);

	// then recur on right subtree
	printPostorder(node->right);

	// now deal with the node
	cout << node->data << " ";
}

/* Given a binary tree, print its nodes in inorder*/
void printInorder(struct Node* node)
{
	if (node == NULL)
		return;

	/* first recur on left child */
	printInorder(node->left);

	/* then print the data of node */
	cout << node->data << " ";

	/* now recur on right child */
	printInorder(node->right);
}

/* Given a binary tree, print its nodes in preorder*/
void printPreorder(struct Node* node)
{
	if (node == NULL)
		return;

	/* first print data of node */
	cout << node->data << " ";

	/* then recur on left subtree */
	printPreorder(node->left);

	/* now recur on right subtree */
	printPreorder(node->right);
}

/* Driver program to test above functions*/
int main()
{
	struct Node* root = newNode(1);
	root->left = newNode(2);
	root->right = newNode(3);
	root->left->left = newNode(4);
	root->left->right = newNode(5);

	cout << "\nPreorder traversal of binary tree is \n";
	printPreorder(root);

	cout << "\nInorder traversal of binary tree is \n";
	printInorder(root);

	cout << "\nPostorder traversal of binary tree is \n";
	printPostorder(root);

	return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct node{
   int data;
   struct node* left;
   struct node* right;
   node(int val)
   {
      data=val;
      left=right=NULL;
   }
};

int main()
{
struct node* root=new node(1);
root->left=new node(5);
root->right=new node(8);
root->left->right=new node(9);
cout<<root->left->right->data;
	return 0;
}
	void segregateEvenOdd(int arr[], int n) {
	    vector<int>v;
	   multiset<int>s1;
	    multiset<int>s2;
	    for(int i=0;i<n;i++)
	    {
	        if(arr[i]%2==0) s1.insert(arr[i]);
	        else s2.insert(arr[i]);
	    }
	   for(auto x:s1)
	    {
	    v.push_back(x);
	    }
	    for(auto x:s2)
	    {
	      v.push_back(x);   
	    }
	     for(int i=0;i<n;i++)
	     arr[i]=v[i];
	}
	
};
class Solution{
public:	

	void segregateEvenOdd(int arr[], int n) {
	    // code here
	    multiset<int>s1;
	    multiset<int>s2;
	    vector<int>v;
	    for(int i=0;i<n;i++)
	    {
	        if(arr[i]%2==0) s1.insert(arr[i]);
	        else s2.insert(arr[i]);
	    }
	   
	    for(auto i:s1)
	    {
	        v.push_back(i);
	    }
	    for(auto i:s2)
	    {
	        v.push_back(i);
	    }
	    
	    for(int i=0;i<n;i++)
	    {
	        arr[i]=v[i];
	    }
	    
	}
};
#include <bits/stdc++.h>

using namespace std;
struct node
{
    int d;
    node* next;
};
void printlinkedelements(node* i)
{
    while(i!=NULL)
    {
        cout<<i->d<<" "<<i<<" ";
        i=i->next;
        
    }
    cout<<endl;
}
void takeinput(node* i)
{
    while(i!=NULL)
    {
        cin>>i->d;
        i=i->next;
    }
}
void push(node** head_ref,int new_data)
{
   node* new_node=new node();
   new_node->d=new_data;
   new_node->next=(*head_ref);
   (*head_ref)=new_node;
}

int main()
{
    node* head=NULL;
    node* second=NULL;
    node* third=NULL;
     
    head=new node();
    second=new node();
    third=new node();
    
  
    head->next=second;

   second->next=third;
   
   third->next=NULL;
   takeinput(head);
   printlinkedelements(head);
   push(&head,8);
   printlinkedelements(head);
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
class node{
    public:
    int d;
    node* next;
};
void printlinkedelements(node* i)
{
    while(i!=NULL)
    {
        cout<<i->d<<" "<<i<<"\n";
        i=i->next;
        
    }
}
void takeinput(node* i)
{
    while(i!=NULL)
    {
        cin>>i->d;
        i=i->next;
    }
}
int main()
{
    node* head=NULL;
    node* second=NULL;
    node* third=NULL;
     
    head=new node();
    second=new node();
    third=new node();
    
  
    head->next=second;

   second->next=third;
   
   third->next=NULL;
   takeinput(head);
   printlinkedelements(head);
    return 0;
}
pair<long long, long long> getMinMax(long long a[], int n) {
    int long long max=INT_MIN;
    int  long long  min=INT_MAX;
    for(int i=0;i<n;i++)
    {
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
    }
    pair<int long long,int long long>pair1;
    pair1.first=min;
    pair1.second=max;
    return pair1;
    
    
}
pair<long long, long long> getMinMax(long long a[], int n) {
    int long long min=INT_MAX;
    int long long max=INT_MIN;
    for(int long long i=0;i<n;i++)
    {
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
        
    }
    pair<int long long,int long long>pair1={min,max};
   
    return pair1;
Method 1
string reverseWord(string str)
{
    int n=str.size();
    for(int i=0;i<n/2;i++)
    {
        swap(str[i],str[n-1-i]);
    }
    return str;
}


Method 2

string reverseWord(string str)
{
   reverse(str.begin(),str.end());
    return str;
}
class Solution
{
public:
    vector<int> singleNumber(vector<int> nums) 
    {
        // Code here.
        
        map<int,int>mp;
        for(int i=0;i<nums.size();i++)
        {
            mp[nums[i]]++;
        }
        vector<int>v;
        map<int,int>::iterator it;
        for(auto it:mp)
        {
            if(it.second==1) v.push_back(it.first);
        }
        return v;
    }
};
class Solution{
    public:
    vector<int> twoOddNum(int Arr[], int N)  
    {
        set<int>s;
        for(int i=0;i<N;i++)
        {
            s.insert(Arr[i]);
        }
        vector<int>v;
        set<int>::iterator i;
        for(i=s.begin();i!=s.end();i++)
        {
            v.push_back(*i);
        }
        vector<int>ans;
        for(int i=0;i<v.size();i++)
        {
            int count=0;
            for(int j=0;j<N;j++)
            {
                if(v[i]==Arr[j]) count++;
                
            }
            if(count%2==1) 
            {
                ans.push_back(v[i]);
            }
        }
        sort(ans.rbegin(),ans.rend());
        return ans;
        // code here
    }
};
#include <iostream>

int main () {
  int number;
  int lastNumber;
  std :: cout << "Введите число: ";
  std :: cin >> number;

  while (number != 0) {
    lastNumber = number % 10;
    if (lastNumber != 1 && lastNumber != 0) break;
    number /= 10;
  }

  if (lastNumber == 1 || lastNumber == 0) {
    std :: cout << "Робот все понял!\n";
  } else {
    std :: cout << "Машинный код состоит не только из 0 и 1. Ошибка!\n";
  }
}
#include <iostream>

int main() {
  int pin;
  std::cout<<"Введите число-пинкод\n";
  std::cin >> pin;
  int sum;
  while(pin !=42 ){
    std::cout << "Error try again:";
    std::cin >> pin;
    }
  if (sum==42){
  std::cout<<"пинкод верный работаем дальше";
    }
  }
#include <iostream>

using namespace std;

int main() {

int square;
  
  cout << "Введите площадь:\n";
  cin >> square;

  if (square > 1000000) cout << "Нет такого участка";
  else {

    int iteration = 0;
  
      while (iteration * iteration < square) {
      ++iteration;
      }

      if (iteration * iteration == square) cout << "Является точным квадратом";
        else cout << "Не является точным квадратом";
}


}
#include<iostream>
using namespace std;
class DATE{
    int day;
    int month;
    int year;
    public:
    DATE(){}
    DATE(char*);
    int operator-(DATE);
    DATE operator+(int);
    bool operator<(DATE);
    friend ostream& operator<<(ostream &,DATE&);
    ~DATE();
};
int main(){

    cout<<"Enter the first date in dd/mm/yyyy format: ";
    char input[20];
    cin>>input;
    DATE d1(input);
    cout<<d1<<endl;
    cout<<"Enter the second date in dd/mm/yyyy format: ";
    cin>>input;
    DATE d2(input);
    cout<<d2<<endl;
    int num_days = d2-d1;
    
    cout<<"Number of days in between is: "<<num_days<<endl;
    cout<<"Enter the number of days\n";
    int num;
    cin>>num;
    DATE d3 = d1 + num;
    cout<<d1<<" + "<<num<<" = "<<d3;
    return 0;
}
int my_stoi(char *input,int start,int len){
    int output =0;
    for(int i=start;i<start+len;i++){
        output = output*10 + input[i]-'0';
    }
    return output;
}
DATE::DATE(char *input){
    day = my_stoi(input,0,2);
    month = my_stoi(input,3,2);
    year = my_stoi(input,6,4);
}
inline bool is_leap_year(int yy){
    if(yy%400==0) return 0;
    return yy%4 ? 0: 1;
}
inline int days_in_year(int yy){
    return is_leap_year(yy) ? 366 : 365;
}
int days_in_month(int mo,int yy){
    switch(mo){
        case 1:case 3:case 5: case 7: case 8: case 10: case 12:
            return 31;
        case 4: case 6: case 9: case 11:
            return 30;
        case 2: 
            if(is_leap_year(yy)) return 29;
            else return 28;
    }
    return -1;
}
bool DATE::operator<(DATE d2){
    if(year<d2.year) return true;
    else if(year>d2.year) return false;
    if(month<d2.month) return true;
    else if(month>d2.month) return false;
    return day<d2.day;
}
int DATE::operator-(DATE d2){
    if(*this<d2) return d2-*this;

    int prefix_days_d1 =0;
    for(int i=1;i<month;i++) prefix_days_d1 += days_in_month(i,year);
    prefix_days_d1 += day;

    int suffix_days_d2=0;
    suffix_days_d2 += days_in_month(d2.month,d2.year)-d2.day;
    for(int i = d2.month+1;i<=12;i++) suffix_days_d2 += days_in_month(i,d2.year);

    int difference = suffix_days_d2 + prefix_days_d1;

    for(int i = d2.year+1 ; i<year ; i++){
        difference += days_in_year(i);
    }
    if(year==d2.year) difference -= days_in_year(year);   // overlap
    return difference;
}
ostream& operator<<(ostream &print,DATE &obj){
    if(obj.day/10 ==0) print<<"0";
    print<<obj.day;
    print<<"/";
    if(obj.month/10 ==0) print<<"0";
    print<<obj.month<<"/";
    print<<obj.year;
    return print;
}
DATE DATE::operator+(int add_days){
    DATE output;
    int dd = day;
    int mm = month;
    int yy = year;
    int current_days = days_in_month(mm,yy) - dd;
    if(add_days > current_days){  
                                    // rounding up the month
        add_days-=current_days;
        mm++;
        if(mm==13) {
            mm=1;
            yy++;
        }
    }
    else{
        dd +=add_days;
        add_days=0;
    }
    while(days_in_month(mm,yy)<add_days){
                                        // rounding up the year
        add_days-=days_in_month(mm,yy);
        mm++;
        if(mm==13) {
            mm=1;
            yy++;
            break;
        }
    }
    while(days_in_year(yy)<add_days){   //locating to the year
        add_days-=days_in_year(yy);
        yy++;
    }
    while(days_in_month(mm,yy)<add_days){ // locating to the month
        add_days-=days_in_month(mm,yy);
        mm++;
    }
    if(add_days!=0) dd = add_days;  // locating to the date
    output.day = dd;
    output.month = mm;
    output.year = yy;

    return output;
}
DATE::~DATE(){
    
}
#include<iostream>
using namespace std;

typedef struct NODE{
    int data;
    NODE *next;
}NODE;
class LIST{
    NODE *head;
    public:
    LIST();
    LIST& operator+(int);
    LIST& operator-(int);
    bool operator==(LIST&);
    LIST& operator++(int);
    LIST& operator--(int);
    friend ostream& operator<<(ostream&,LIST&);
    ~LIST();
};
int main(){
    LIST l;
    int choice,ele;
    while(1){
        cout<<"1. L = L + ele\n";
        cout<<"2. L = L - ele\n";
        cout<<"3. L = L++ \n";
        cout<<"4. L = L--\n";
        cout<<"-1: Exit\n";
        cin>>choice;
        switch(choice){
            case 1: 
                    cout<<"Enter the value of the element\n";
                    cin>>ele;
                    l = l + ele;
            break;
            case 2:
                    cout<<"Enter the value of the element\n";
                    cin>>ele;
                    l = l - ele;
            break;
            case 3:
                    l = l++;
            break;
            case 4: 
                    l = l--;
            break;
            case -1:
                    goto out;
            default:
                    cout<<"Invalid entry\n";
        }
        cout<<"List: "<<l;
    }
    out:
    return 0;
}

LIST::LIST(){
    head=NULL;
}
bool ispresent(NODE* chain,NODE *end,int key){
    NODE *temp = chain;
    while(temp!=end){
        if(temp->data==key) return true;
        temp = temp->next;
    }
    if(end!=NULL) return end->data == key ? 1:0;
    return false;
}
LIST& LIST::operator--(int){
    NODE *distinct_head = NULL;
    NODE *distinct_connect = NULL;
    NODE *duplicate_head=NULL;
    NODE *duplicate_connect = NULL;
    NODE *temp = head;
    while(temp){
        if(ispresent(distinct_head,distinct_connect,temp->data)){
            if(!duplicate_connect) duplicate_head = temp;
            else duplicate_connect->next = temp;
            duplicate_connect = temp;
        }
        else{
            if(!distinct_connect) distinct_head = temp;
            else distinct_connect->next = temp;
            distinct_connect = temp;
        }
        NODE *store = temp->next;
        temp->next = NULL;
        temp = store;
    }
    distinct_connect->next  = duplicate_head;
    head = distinct_head;
    return *this;
}
LIST& LIST::operator++(int){
    NODE *temp = head;
    while(temp){
        temp->data = temp->data +1;
        temp=temp->next;
    }
    return *this;
}
bool LIST::operator==(LIST &l2){
    NODE *temp1 = head;
    NODE *temp2 = l2.head;
    if(temp1 == NULL && temp2 == NULL) return true;
    if(temp1==NULL || temp2==NULL) return false;
    while(temp1 && temp2){
        if(temp1->data!=temp2->data) return false;
        temp1 = temp1->next;
        temp2 = temp2->next;
    }
    return temp1 || temp2 ? 0:1;
}
LIST& LIST::operator-(int element){
    NODE *temp = head;
    NODE *prev= NULL;
    while(temp){
        if(temp->data==element){
            if(!prev) head=head->next;
            else prev->next = temp->next;
            delete temp;
            return *this;
        }
        prev=temp;
        temp=temp->next;
    }
    return *this;
}
LIST& LIST::operator+(int element){
    NODE *current = new NODE;
    current->data = element;
    current->next = NULL;
    NODE *temp = head;
    if(!temp){
        head = current;
        return *this;
    }
    while(temp->next){
        temp = temp->next;
    }
    temp->next = current;
    return *this;
}
ostream& operator<<(ostream& print,LIST &l){
    NODE *temp= l.head;
    while(temp){
        print<<temp->data<<" ";
        temp = temp->next;
    }
    print<<endl;
    return print;
}
LIST::~LIST(){
    NODE *temp = head;
    while(temp){
        NODE *store = temp->next;
        delete temp;
        temp = store;
    }
}
#include<iostream>
using namespace std;

class MATRIX{
    int row;
    int col;
    int **array;
    public:
    MATRIX();
    MATRIX(const MATRIX&);
    MATRIX(int,int);
    void takeinput();
    MATRIX operator+(MATRIX);
    MATRIX operator-(MATRIX);
    bool operator==(MATRIX);
    friend ostream& operator<<(ostream&,MATRIX);
    ~MATRIX();
};
int main(){

    int r,c;
    cout<<"Enter number of rows for matrix m1: ";
    cin>>r;
    cout<<"Enter number of columns for matrix m1: ";
    cin>>c;
    MATRIX m1(r,c);
    m1.takeinput();
    cout<<"Enter number of rows for matrix m2: ";
    cin>>r;
    cout<<"Enter number of columns for matrix m2: ";
    cin>>c;
    MATRIX m2(r,c);
    m2.takeinput();
    cout<<"Matrix m1 :-"<<endl<<m1;
    cout<<"Matrix m2 :-"<<endl<<m2;
    MATRIX m3,m4;
    if(m1==m2){
        MATRIX m3 = m1 + m2;
        cout<<"Matrix m3 :-"<<endl;
        cout<<m3;
        MATRIX m4 = m1 - m2;
        cout<<"Matrix m4 :-"<<endl;
        cout<<m4;
    }
    else{
        cout<<"Error! The dimensions of both the operand matrices are not same\n";
    }
    return 0;
}

MATRIX::MATRIX(int r,int c){
    row = r;
    col = c;
    array = new int*[r];
    for(int i=0;i<r;i++){
        array[i] = new int[c];
        for(int j=0;j<c;j++) {
            array[i][j] = 0;
        }
    }
}
MATRIX::MATRIX(const MATRIX& obj){
    row = obj.row;
    col = obj.col;
    array = new int*[row];
    for(int i=0;i<row;i++){
        array[i] = new int[col];
        for(int j=0;j<col;j++){
            array[i][j] = obj.array[i][j];
        }
    }
}
void MATRIX::takeinput(){
    for(int i=1;i<=row;i++){
        for(int j=1;j<=col;j++){
            cout<<"Enter ("<<i<<", "<<j<<") element: ";
            cin>>array[i-1][j-1];
        }
    }
}
MATRIX::MATRIX(){
    row=0;
    col=0;
    array=NULL;
}
MATRIX MATRIX::operator+(MATRIX m2){
    MATRIX output(row,col);
    for(int i=0;i<row;i++){
        for(int j=0;j<col;j++){
            output.array[i][j] = array[i][j] + m2.array[i][j];
        }
    }
    return output;
}
MATRIX MATRIX::operator-(MATRIX m2){
    MATRIX output(row,col);
    for(int i=0;i<row;i++){
        for(int j=0;j<col;j++){
            output.array[i][j] = array[i][j] - m2.array[i][j];
        }
    }
    return output;
}
ostream& operator<<(ostream &print, MATRIX m){
    for(int i=0;i<m.row;i++){
        for(int j=0;j<m.col;j++){
            print<<m.array[i][j]<<" ";
        }
        print<<endl;
    }
    return print;
}
bool MATRIX::operator==(MATRIX m2){
    return (row==m2.row && col==m2.col) ? true:false;
}

MATRIX::~MATRIX(){
    for(int i=0;i<row;i++){
        delete []array[i];
    }
    delete []array;
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
int DayoftheWeek;

cout << "Введите День недели: ";
cin >> DayoftheWeek;
  
if(DayoftheWeek == 1)
	{
		cout << "***Понедельник***" << endl;
    cout << "Борщ" << endl;
    cout << "Салат с помидорами и огурцами" << endl;
    cout << "Чай" << endl;
	}
else if(DayoftheWeek == 2)
	{
		cout << "***Вторник***" << endl;
    cout << "Суп Щи" << endl;
    cout << "Пюрешка с котлетками" << endl;
    cout << "Компот с клюквой" << endl;
	}
else if(DayoftheWeek == 3)
	{
	  cout << "***Среда***" << endl;
    cout << "Суп Сырный" << endl;
    cout << "Гречневая каша" << endl;
    cout << "Сок яблочный" << endl;
	}
else if (DayoftheWeek == 4)
	{
		cout << "***Четверг***" << endl;
    cout << "ПЕЛЬМЕНИ" << endl;
    cout << "Салат Греческий" << endl;
    cout << "Компот вишнёвый" << endl;
	}
else if(DayoftheWeek == 5)
	{
		cout << "***Пятниц***" << endl;
    cout << "Сборня солянка" << endl;
    cout << "Макароны с тушёнкой" << endl;
    cout << "Чай" << endl;
	}
else if(DayoftheWeek == 6)
	{
	  cout << "***Суббота***" << endl;
    cout << "Суп Сырный" << endl;
    cout << "Компот с клюквой" << endl;
    cout << "Макароны с котлетами" << endl;
	}
else if (DayoftheWeek == 7)
	{
		cout << "***Восресенье***" << endl;
    cout << "ПЕЛЬМЕНИ" << endl;
    cout << "Салат с помидорами и огурцами" << endl;
    cout << "Чай" << endl;
  }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{

int a;
int b;

cout << "Введите целое число: ";
cin >> a;
 
cout << "Введите второе целое число: ";
cin >> b;
 
cout << "Остаток: " << a % b << endl;
 
if ((a % b) == 0)
	cout << a << " Делится на " << b << endl;
else
	cout << a << " Не делится на " << b << endl;
}
#include <iostream>

using std::cout;
using std::cin;

int main() 
{
  
int skill;

cout << "Введите скил пресонажа: ";
cin >> skill;
  
if (skill < 1000) {
  cout << "Lvl 1";
} 
else if (skill < 2500) {
  cout << "Lvl 2";
} 
else if(skill < 5000) {
  cout << "Lvl 3";
} 
 if (skill >= 5000) {
  cout << "Максимальный скил";
}
}
#include <iostream> 

using std::cout;
using std::cin;
using std::endl;
 
int main() 
{   
  int number; 
 
  cout << "Введите число " << endl; 
  cin >> number; 
 
  if( number % 2 == 0) 
    cout << "Чётное " << endl; 
  else 
    cout << "Нечётное " << endl; 
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
 int a = 0;
 int b = 0;
 int result;

 cout << "Введите пример: ";
 cin >> a >> b >> result;

  if(a + b == result)
  {
    cout << "Ответ верный";
  }
  else if( a + b != result)
  {
    cout << "Ответ не верный";
  }
} 
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{

int a = 0;
int b = 0;
int min = 0;
int equal;

  
cout << "Введите число a: ";
cin >> a;
cout<<"Введите число b: ";
cin >> b;
  
  
if (a < b){

    cout << "Наименьшим числом является " << a <<".";

  } else if (a > b){

    cout << "Наименьшим числом является " << b <<".";

  } else {
      cout << "Числа равны";
  }
}
#include <iostream>

using std::cout;
using std::cin;

int main() 
{
  int speed;
  int height;

  cout << "Введиите допустимую скорость в самолёта ";
  cin >> speed;
  cout << "Введите дрпустимую высоту(в тыс. метрах) ";
  cin >> height;

  if(speed < 750 && height < 9000){

    cout << "Данной скорости и высоты не достаточно для самолёта";
    
  }else if(speed > 850 && height > 9500){

    cout << "Данная скорость и высота превышает установленнную норму полёта ";
    
  }else{

    cout << "Данной скорости и высоты достаточно ";
  }
}
#include <iostream>

using std::cout;
using std::cin;

int main() 
{

int day;
int month;
  
  
cout << "Введите день месяца: ";
cin >> day;
cout <<"Введите день, с которого началаcя месяц ";
cin >> month;
 
if ((day >= 1 && day <=5 ) || (day >= 8 && day <=10)) {
  cout << "Праздничный день ";
} else if ( day <= 0 ||  day > 31 ||  month > 7){
 cout << "Некоректное значение";
} else if (((day + 1) % 7) == 0 || ((day + month - 1) % 7) == 0){
  cout << "Выходной день";
} else {
  cout << "Рабочий день";}
}
#include <iostream>

using std::cout;
using std::cin;

int main() 
{
  int maydate;
  int weekday;
  
  cout << "Введите дату \n";
  cin >> maydate;
  
  cout << "Введите день недели \n";
  cin >> weekday;
  
  if (((maydate>=1) && (maydate<=5)) || ((maydate>=8) && (maydate<=10))){
  cout << "Праздничный день";
  }else if ((maydate+weekday)%6==0 || (maydate+weekday)%7==0){
      cout << "Выходной день";
  }else {
      cout << "Рабочий день";
  }
}
#include <iostream>

using std::cout;
using std::cin;

int main()
{
  int Ruble = 0;
  
  cout << "Введите количество денег: ";
  cin >> Ruble;
  
  if (Ruble % 10 == 0 || Ruble % 10 >= 5 || (Ruble / 10) % 10 == 1){
    cout << Ruble << " рублей";
    }else if (Ruble % 10 == 1){
    cout << Ruble << " рубль";
    }else {
    cout << Ruble << " рубля";
    }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
  int a;
  int b;
  int c;
  
  cout << "Введите размеры первой коробки(которую надо пеместить в другую): ";
  cin >> a >> b >> c;

  int m;
  int n;
  int k;
  
  cout << "Введите размеры второй коробки(в которую надо засунуть): ";
  cin >> m >> n >> k;

  if (a <= m && b <= n && c <= k || a <= n && b <= m && c <= k) {
    cout << "Можно";
    }else if(a <= n && b <= m && c <= k || a <= m && b <= n && c <= k){
    cout << "Можно";
    }else if(c <= a && a <= c && k <= b || k <= c && n <= b && k <= a){
    cout << "Можно";
  } else {
    cout << "Нельзя";
  }
  
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
  int day;
  int month;
  int year;

  cout << "Введите день месяц и год рождения клиента: ";
  cin >> day >> month >> year;

  int dayCurrent;
  int monthCurrent;
  int yearCurrent;

  cout << "Введите текущий день, месяц, год: ";
  cin >> dayCurrent >> monthCurrent >> yearCurrent;

  if(yearCurrent - year < 18){
    cout << "Нельзя продавать. ";
  }else if(yearCurrent - year > 18){
    cout << "Можно продать. ";
  }else if(monthCurrent > month || (monthCurrent == month && dayCurrent > day)){
    cout << "Можно продать. ";
  }else{
    cout << "Нельзя продавать. ";
  }
}
#include <iostream>

using std:: cout;
using std:: cin;
using std:: endl;

int main() {
    int nominals[] = {5000, 2000, 1000, 500, 200, 100};
    int requested;
  
    cin >> requested; 
    cout << "Запрашиваемая сумма: " << requested << endl;
  
    if (requested % 100 != 0) {
        cout << " - Невозможно предоставить " << requested << ". Не должно быть меньше 100." << endl;
    } else if (requested > 150000) {
        cout << " - Невозможно предоставить " << requested << ". Не должно превышать 150000" << endl;
    } else {
        for (auto nominal : nominals) {
            cout << " - " << nominal << " x " << (requested / nominal) << endl;
            requested %= nominal;
          }
      }
}
#include <iostream>h>

using namespace std;
 
void checkTriangle(int x1, int y1, int x2,
                   int y2, int x3, int y3)
{
 
    int a = x1 * (y2 - y3)
            + x2 * (y3 - y1)
            + x3 * (y1 - y2);
 
    if (a == 0)
        cout << "No";
    else
        cout << "Yes";
}
 
int main()
{
    int x1 = 1, x2 = 1, x3 = 2,
        y1 = 1, y2 = 6, y3 = 5;
    checkTriangle(x1, y1, x2,
                  y2, x3, y3);
    
}
#include <iostream>

using namespace std;

int main()
{
  int count;

  cout << "Сколько чисел вы хотите суммировать" << endl;
  cin >> count;

  cout << "Вводите " << count << " чисел: " << endl;

  int interations = 0;
  int sum = 0;

      while(interations < count){

      int number;

      cin >> number;
      sum += number;
      interations += 1;
    
  }
  cout << "Сумма равна" << sum;
  
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
  int spirt;
  int aptechka;

  cout << "Введите нужное количечество спирта в миллитрах ";
  cin >> spirt;
  cout << "Введите нужное количество аптечек ";
  cin >> aptechka;

  if(spirt < 2000 && aptechka < 5){
    cout << "Не достаточно ";
    }
  else{
    cout << "Достаточно";
  }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int god;
  
printf("введите Год ");
scanf("%d",&god);
  
if (god%100 != 0 && god%400 == 0){
    printf("невисокосный год\n");
  }else
    if (god%4 == 0)
        printf("високосный Год\n");
    else printf("невисокосный Г,од\n");
    return 0;
}
#include <iostream>

int main() {
  int sum;

  std::cout << "Введите сумму, которую хотите обналичить : ";
  std::cin >> sum;

  if (sum > 150000) {
    std::cout << "Превышено максимальное число для вывода денег.";
  } else if ((sum % 5000 == 0) || ((sum - 5000) != 0)) {
    int remainder;
    remainder = sum - 5000;
    std::cout << sum / 5000 << " купюр по 5000";       //нужно как то поместить в if
  if (remainder == 0) {
    std::cout << "1 купюра по 5000";
  } else if (remainder % 2000 == 0) {
    std::cout << " и " << remainder / 2000 << " купюр по 2000";       //еще склонения купюр надо сделать
  } else if (remainder % 1000 == 0) {
    std::cout << " и " << remainder / 1000 << " купюр по 1000";
  } else if (remainder % 500 == 0) {
    std::cout << " и " << remainder / 500 << " купюр по 500";
  } else if (remainder % 200 == 0) {
    std::cout << " и " << remainder / 200 << " купюр по 200";
  } else if (remainder % 100 == 0) {
    std::cout << " и " << remainder / 100 << " купюр по 100";
  }

  
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl; 
int main()
{
    int x, y;
    while (true)
    {
        cin >> x >> y;
        if (y <= 2 - x * x && (y >= x || y >= 0)) cout << "Yes ";
        else cout << "No  ";
        if (x <= 0 && y >= 0 && y <= 2 - x * x) cout << "A";
        if (x >= 0 && y >= x && y <= 2 - x * x) cout << "B";
        if (x >= 0 && y >= 0 && y <= x && y <= 2 - x * x) cout << "C";
        if (x <= 0 && y <= 0 && y >= x && y <= 2 - x * x) cout << "D";
        if (y >= 0 && y >= x && y >= 2 - x * x) cout << "E";
        if (x <= 0 && y <= 0 && y >= x && y >= 2 - x * x) cout << "F";
        if (x <= 0 && y <= x && y >= 2 - x * x) cout << "G";
        if (y <= 0 && y <= x && y <= 2 - x * x) cout << "H";
        if (x >= 0 && y >= 0 && y <= x && y >= 2 - x * x) cout << "J";
        if (x >= 0 && y <= 0 && y >= 2 - x * x) cout << "K";
        cout << endl;
    }
}
#include <iostream>

using namespace std;

int main() {
  
 int a, b, c, d;
  cout<< "Введите 4 пин кода\n";
  
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  
   while (a+b+c+d !=42){std::cout << " Ввод некорректный, попробуйте еще раз\n";
     
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
     
   }
   std::cout << " Ввод коректный\n"; 
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
  int mansCount;
  int barbersCount;
  int mansPerBarber = 8; // один человек в час, смена 8 часов
  int mansPerBarberPerMonth = mansPerBarber * 30;    //подстрич за месяц

  cout << "Введите число мужчин в городе: ";
  cin >> mansCount;
  cout << "Сколько уже барберов удалось нанять?";
  cin >> barbersCount;
  cout << "Один барбер стрижет столько клиентов в месяц " << mansPerBarberPerMonth << "\n";

    // Сколько нужно барберов, чтобы постричь mansCount человек?
    int requiredBarbersCount = mansCount / mansPerBarberPerMonth;
    if (requiredBarbersCount * mansPerBarberPerMonth % mansCount) {
        requiredBarbersCount += 1;
    }

    cout << "Необходимое число барберов: " << requiredBarbersCount << "\n";

    // Сколько человек успеют посчтричь requiredBarbersCount за месяц?
    cout << requiredBarbersCount << " барбера могут постричь " << requiredBarbersCount * mansPerBarberPerMonth << " мужчин за месяц.\n";

  
  if (requiredBarbersCount > barbersCount) 
  {
    cout << "Нужно больше барберов!!!\n";
  } 
    else if (requiredBarbersCount == barbersCount) 
    {
      cout << "Барберов ровно столько, сколько нужно!!!\n";
    }   
      else 
      {
        cout << "Барберов хватает!!!\n";
      }

  if (barbersCount > requiredBarbersCount * 2) 
  {
    cout << "У вас работает в два раза больше барберов, чем это нужно!!!\n";
  }

  
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
int AmountofIncome; 
int taxrate = 0;
  
cout << "Введите размер дохода: ";
cin >> AmountofIncome;

if (AmountofIncome > 50000) {
  taxrate += (AmountofIncome - 50000) * 30 / 100;
  AmountofIncome = 50000;
  } 
  if (AmountofIncome > 10000) {
  taxrate += (AmountofIncome - 10000) * 20 / 100;
  AmountofIncome = 10000;
  }
  taxrate += AmountofIncome * 13 / 100;

  cout << "Размер налога будет составлять " << taxrate << " рублей" << endl;
}
#include <iostream>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
 
int main() 
{
  int a;
  int b;
  int c;
  int calculate = 1;
  int ArithmeticMean;
  int difference;

  cout << "Зарплата " << calculate << "-го сотрудника: ";
  calculate++;
  cin >>a;
  cout << "Зарплата " << calculate << "-го сотрудника: ";
  calculate++;
  cin >>b;
  cout << "Зарплата " << calculate << "-го сотрудника: ";
  calculate++;
  cin >>c;
  ArithmeticMean = (a+b+c)/3;
  
  int high = 0;
  if(a > b ) 
  {
    cout << "Самая высокая зарплата у 1-го сотрудника: "  << a << endl;
    high = a;
  } 
  else if(b < a) 
  {
    cout << "Самая высокая зарплата у 2-го сотрудника: "  << b << endl;
    high = b;
  }
  else if(c > b)
  {
    cout << "Самая высокая зарплата у 3-го сотрудника: "  << c << endl;
    high = c;
  }

  
  int low = 0;
  if(a < b ) 
  {
    cout << "Самая низкая зарплата у 1-го сотрудника: "  << a << endl;
    low = a;
  } 
  else if(b > a ) 
  {
    cout << "Самая низкая зарплата у 2-го сотрудника: "  << b << endl;
    low = b;
  }
  else if(c < b)
  {
    cout << "Самая низкая зарплата у 3-го сотрудника: "  << c << endl;
    low = c;
  } 
 
  difference = high - low;
  
  cout << "Разница между высокой и низкой зарплаты составляет: " << difference << endl;
  cout << "Средняя зарплата отдела является: " << ArithmeticMean;
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
int DayoftheWeek;

cout << "Введите День недели: ";
cin >> DayoftheWeek;
  
if(DayoftheWeek == 1)
	{
		cout << "***Понедельник***" << endl;
    cout << "Борщ" << endl;
    cout << "Салат с помидорами и огурцами" << endl;
    cout << "Чай" << endl;
	}
else if(DayoftheWeek == 2)
	{
		cout << "***Вторник***" << endl;
    cout << "Суп Щи" << endl;
    cout << "Пюрешка с котлетками" << endl;
    cout << "Компот с клюквой" << endl;
	}
else if(DayoftheWeek == 3)
	{
	  cout << "***Среда***" << endl;
    cout << "Суп Сырный" << endl;
    cout << "Гречневая каша" << endl;
    cout << "Сок яблочный" << endl;
	}
else if (DayoftheWeek == 4)
	{
		cout << "***Четверг***" << endl;
    cout << "ПЕЛЬМЕНИ" << endl;
    cout << "Салат Греческий" << endl;
    cout << "Компот вишнёвый" << endl;
	}
else if(DayoftheWeek == 5)
	{
		cout << "***Пятниц***" << endl;
    cout << "Сборня солянка" << endl;
    cout << "Макароны с тушёнкой" << endl;
    cout << "Чай" << endl;
	}
else if(DayoftheWeek == 6)
	{
	  cout << "***Суббота***" << endl;
    cout << "Суп Сырный" << endl;
    cout << "Компот с клюквой" << endl;
    cout << "Макароны с котлетами" << endl;
	}
else if (DayoftheWeek == 7)
	{
		cout << "***Восресенье***" << endl;
    cout << "ПЕЛЬМЕНИ" << endl;
    cout << "Салат с помидорами и огурцами" << endl;
    cout << "Чай" << endl;
  }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{

int a;
int b;

cout << "Введите целое число: ";
cin >> a;
 
cout << "Введите второе целое число: ";
cin >> b;
 
cout << "Остаток: " << a % b << endl;
 
if ((a % b) == 0)
	cout << a << " Делится на " << b << endl;
else
	cout << a << " Не делится на " << b << endl;
}
#include <iostream>

using std::cout;
using std::cin;

int main() 
{
  
int skill;

cout << "Введите скил пресонажа: ";
cin >> skill;
  
if (skill < 1000) {
  cout << "Lvl 1";
} 
else if (skill < 2500) {
  cout << "Lvl 2";
} 
else if(skill < 5000) {
  cout << "Lvl 3";
} 
 if (skill >= 5000) {
  cout << "Максимальный скил";
}
}
#include <iostream> 

using std::cout;
using std::cin;
using std::endl;
 
int main() 
{   
  int number; 
 
  cout << "Введите число " << endl; 
  cin >> number; 
 
  if( number % 2 == 0) 
    cout << "Чётное " << endl; 
  else 
    cout << "Нечётное " << endl; 
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
 int a = 0;
 int b = 0;
 int result;

 cout << "Введите пример: ";
 cin >> a >> b >> result;

  if(a + b == result)
  {
    cout << "Ответ верный";
  }
  else if( a + b != result)
  {
    cout << "Ответ не верный";
  }
} 
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{

int a = 0;
int b = 0;
int min = 0;
int equal;

  
cout << "Введите число a: ";
cin >> a;
cout<<"Введите число b: ";
cin >> b;
  
  
if (a < b){

    cout << "Наименьшим числом является " << a <<".";

  } else if (a > b){

    cout << "Наименьшим числом является " << b <<".";

  } else {
      cout << "Числа равны";
  }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{

  int Men;
  int HireBarriers;
  
  cout << "Ввести число мужчин в городе: " << endl;
  cin >> Men;

  cout << "Вести число нанятых барберов: " << endl;
  cin >> HireBarriers;

  int MenaDaytoCut = 8; //мужчин в день может подстрич, рабочая смена 8  часов.
  int MenPerDay = Men / 30; //подстрич за день
  int RequiredBarriers = MenPerDay /  MenaDaytoCut;

  cout << "Необходимое число барберов: " << RequiredBarriers << endl;

  if(RequiredBarriers > HireBarriers)
  {
    cout << "Не хватает барберов" << endl;
  }
    if(RequiredBarriers <= HireBarriers)
    {
      cout << "Барберов хватает" << endl;
    }
  
} 
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
  int  x;
  cout << "Введите ваше число ";
  cin >> x;
    
  if(x < 0)
  {
    x = -x;  
  }

    cout << " Модуль числа равен: " << x;
  
} 
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
  int speed;        //скорость автомобиля
  int distance;     //растояние 
  int time;         //время
  
  cout << "Введите скорость автомобиля: " << endl;
  cin >> speed;
  cout << "Введите растояние: " << endl;
  cin >> distance;
  cout << "Введите время: " << endl;
  cin >> time;


  distance = speed * time;
  speed = distance / time;
  time = distance / speed;
  
  if (speed < 90)
        cout << "Вы приехали : " << endl;

    if (speed > 60)
          cout << "Скорости не достаточно: " << endl;
}
#include <iostream>
using namespace std;
int main()
{
    int s,n,mas[100];
    cout << "Enter number = ";cin >> n;
    for(int i=0;i<n;i++)
    {
        cout << "Enter " << i+1 << " = ";
        cin >> mas[i];
    }
    cout << "Suma = ";cin >> s;
    cout << "Bankomat = ";
    for(int i=0;i<n;i++)
    {
        cout << mas[i] << " ";
    }
    cout << "\n";
    system("pause");
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::getline;

int main() {
  
  bool b = true;
  
  while (b) {
    
    int N;
    cout << "Сколько раз вам напомнить? ";
    cin >> N;
    
      if (N == -1) b = false;

      string str;
    
      cout << "Введите фразу напоминалку: ";
    
      getline(std::cin >> std::ws, str);
    
      int i = 0;
    
        while (i <= N) {
            i += 1;
          
            cout << "[" << i << "] " << str << endl;
        }
    }
}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() {

  int k;
  int n;
  int j;
  int t = 1;

  cout << "Введи число у которого хочешь узнать степени: " << endl;
  cin >> k;
  cout << "Введи количество степеней, которые ты хочешь узнать: " << endl;
  cin >> n;
  
  j = k;
  cout << "---------------------" << endl;
  cout << "Cтепень: " << t << " = " << k << endl;

  do {
    k *= j;
    cout << "Cтепень: " << t+1 << " = " << k << endl;
    t += 1;
  } while (n != t);

}
#include <iostream>

using std::cout;
using std::cin;
using std::string;
using std::getline;


int main() {
  
  string text;
  
  do {
  getline (cin, text);
  cout << "Все говорят " << text << ", а ты купи слона!\n";
  } while(text != " ");
}
#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{

setlocale(LC_ALL, "RUS");
   
int productCostOne;
int productCostTwo;
int productCostThree;
int deliveryCost;
int discount;
  

cout<<"Введите стоймость первого товара: ";
cin>> productCostOne;
cout<<"Введите стоймость второго товара: ";
cin>> productCostTwo;
cout<<"Введите стоймость третьего товара: ";
cin>> productCostThree;
cout << "Введите стоимость доставки: ";
cin >> deliveryCost;
cout << "Скидка: ";
cin >> discount;

   
 
if (productCostOne + productCostTwo + productCostThree > 10000) 
{
        
  deliveCost = price * 10 \ 100;
  std::cout << "Стоимость товаров превышает 10000 рублей, вам будет сделана скидка 10%." << endl;
  std::cout << "Поэтому вы получаете скидку на доставку!" << endl;
}
    
int price = productCostOne + productCostTwo + productCostThree + deliveryCost - discount;
    
std::cout << "--------------" << endl;
std::cout << "Полная стоимость товара: " << price << endl;
    
  return 0;
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{ 
int a = 5;
int b = 10; 

cout << "a = " << a << ", b = " << b << endl; 
a = a + b; b = a - b; a = a - b; 
cout << "a = " << a << ", b = " << b << endl; 

}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{
  int startHeight = 100;    //стартовая высота
	int growth = 50;         //рост бамбука в день
	int losses = 20;         //съедение бамбука

	
  int currentHeight = startHeight;


  int bambooHeight = 300;
  int day = (bambooHeight - startHeight) / (growth - losses);
  
  cout << "Высота бамбука будет составлять 3 метра на "  << day * 3 << " день " << endl;
  
} 
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main() 
{

int a = 5;
int b = 10;
int temp; 

cout << "a = " << a << ", b = " << b << endl; 
temp = a; a = b; b = temp; 
cout << "a = " << a << ", b = " << b << endl; 

}
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


int main()
{
    setlocale(LC_ALL, "rus");

    int total = 0;
    int mony = 0;
    int Passenger;

    cout << "Прибываем на остаановку Програмистов. В салоне пассажиров: " << total  << endl;
    cout << "Cколько пассажиров зашло на остановке? ";
    cin >> Passenger;
    total += Passenger;
    mony += Passenger;

    cout << "Отправляемся с остановки Улица Программистов. В салоне  " << total << endl;

    cout << "-----------Едем-----------" << endl;
    cout << "Прибываем на остановку Проспект Алгоритмов. В салоне  " << total << endl;
    cout << "===============================================================================" << endl;
    cout << "Прибываем на остаановку 1. В салоне пассажиров: " << total << "\n";

    cout << "Сколько пассажиров вышло на остановке? ";
    cin >> Passenger;
    total -= Passenger;
    cout << "Cколько пассажиров зашло на остановке? ";
    cin >> Passenger;
    total += Passenger;
    mony += Passenger;

    cout << "Отправляемся с остановки 1. В салоне  " << total << endl;
    cout << "-----------Едем-----------" << endl;
    cout << "Прибываем на остановку 2. В салоне  " << total << endl;
    cout << "===============================================================================" << endl;
    cout << "Прибываем на остаановку 3. В салоне пассажиров: " << total << "\n";

    cout << "Сколько пассажиров вышло на остановке? ";
    cin >> Passenger;
    total -= Passenger;
    cout << "Cколько пассажиров зашло на остановке? ";
    cin >> Passenger;
    total += Passenger;
    mony += Passenger;

    cout << "Отправляемся с остановки 3. В салоне  " << total << endl;
    cout << "-----------Едем-----------" << endl;
    cout << "Прибываем на остановку 4. В салоне  " << total << endl;
    cout << "===============================================================================" << endl;
    cout << "Прибываем на остаановку 5. В салоне пассажиров: " << total << "\n";

    cout << "Сколько пассажиров вышло на остановке? ";
    cin >> Passenger;
    total -= Passenger;
    cout << "Cколько пассажиров зашло на остановке? ";
    cin >> Passenger;
    total += Passenger;
    mony += Passenger;

    cout << "Отправляемся с остановки 5. В салоне  " << total << endl;
    cout << "-----------Едем-----------" << endl;
    cout << "Прибываем на остановку 6. В салоне  " << total << endl;
    cout << "===============================================================================" << endl;
    cout << "Прибываем на остаановку 7. В салоне пассажиров: " << total << "\n";

    cout << "Сколько пассажиров вышло на остановке? ";
    cin >> Passenger;
    total -= Passenger;
    cout << "Cколько пассажиров зашло на остановке? ";
    cin >> Passenger;
    total += Passenger;
    mony += Passenger;

    cout << "Отправляемся с остановки 7. В салоне  " << total << endl;
    cout << "-----------Едем-----------" << endl;
    cout << "Прибываем на остановку 8. В салоне  " << total << endl;
    cout << "===============================================================================" << endl;

    
    mony *= 20; // Подсчитываем общую сумму

    cout << "Всего заработали: " << mony << endl;
    cout << "Зарплата водителя: " << mony / 4 << endl;
    cout << "Расходы на топливо: " << mony / 5 << endl;
    cout << "Налоги: " << mony / 5 << endl;
    cout << "Расходы на ремонт машины: " << mony / 5 << endl;
    cout << "Итого доход: " << mony * 3 / 20 << endl;
    
}

/*Для  подсчёта общей платы необходимо сначала посчитать пассажиров:
mony += Passanger ...
А только затем умножить на плату 
mony*= 20
Чтобы получить mony = (Passanger + Passanger + ...) * 20
А иначе сейчас мы получаем:
mony = 20*Passanger*Passanger*Passanger...*/
#include <iostream>

using std::cout;
using std::cin;
using std::string;

int main()
{
	setlocale(LC_ALL, "rus");

	string Planet;
	cout << "Введите название планеты: ";
	cin >> Planet;

	string Star;
	cout << "Введите название зввёздной системы: ";
	cin >> Star;

	string Species;
	cout << "Введите Рассу: ";
	cin >> Species;

	string Ranger;
	cout << "Введите Имя Героя: ";
	cin >> Ranger;

	string Money;
	cout << "Введите Вознаграждение: ";
	cin >> Money;

	cout << "\n\n\n";

	cout << "Как вам, " << Ranger << " известно, мы — раса " << Species << " мирная,";
	cout << "поэтому на наших военных кораблях" "\n";
	cout << "используются наемники с других планет Система набора отработана давным-давно.";
	cout << "Обычно мы приглашаем на наши корабли людей с планеты " << Planet << " системы " << Star << "\n";
	cout << "Но случилась неприятность — в связи с большими потерями в последнее время престиж\n";
	cout << "профессии сильно упал, и теперь не так-то просто завербовать призывников.\n";
	cout << "Главный комиссар планеты " << Planet << ", впрочем, отлично справлялся,\n";
	cout << "но недавно его наградили орденом Сутулого с закруткой на спине, и его на радостях парализовало! Призыв под угрозой срыва!\n";
	cout << Ranger << " вы должны прибыть на планету " << Planet << " системы " << Star << " и помочь выполнить план призыва.";
	cout << "Мы готовы выплатить вам премию в размере " << Money << " кредитов за эту маленькую услугу.\n";
}
#include "iostream"
#include "string"
#define Answer "Да"

using namespace std;
 
int main()
{
    
    string Question;
  
    cout << "Выполнили ли Вы задание, которое задал вчера?\n";
    string variant;
  
    while(getline(cin, variant), variant != Answer)
    {
        cout << "Введите ответ:    " << endl;
    }
    cout << "Задача выполнена!!!";

}
// You Can Add more than condition at the same for loop
int j{};
string arr[] = { "Yes", "Yes", "Yes", "No", "Yes" };
for(j = 1; arr[j] == "Yes" && j < 5; j++);
cout << j <<endl;
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000;  //the value is a number of milliseconds
const byte ledPin = 13;    //using the built in LED

void setup()
{
  Serial.begin(115200);  //start Serial in case we need to print debugging info
  pinMode(ledPin, OUTPUT);
  startMillis = millis();  //initial start time
}

void loop()
{
  currentMillis = millis();  //get the current "time" (actually the number of milliseconds since the program started)
  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    digitalWrite(ledPin, !digitalRead(ledPin));  //if so, change the state of the LED.  Uses a neat trick to change the state
    startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
}
int period = 1000;
unsigned long time_now = 0;

void setup() {
    Serial.begin(115200);
}

void loop() {
    if(millis() > time_now + period){
        time_now = millis();
        Serial.println("Hello");
    }

    //Run other code
}
#define INTERVAL_MESSAGE1 5000
#define INTERVAL_MESSAGE2 7000
#define INTERVAL_MESSAGE3 11000
#define INTERVAL_MESSAGE4 13000

unsigned long time_1 = 0;
unsigned long time_2 = 0;
unsigned long time_3 = 0;
unsigned long time_4 = 0;

void print_time(unsigned long time_millis);

void setup() {
    Serial.begin(115200);
}

void loop() {
    if(millis() > time_1 + INTERVAL_MESSAGE1){
        time_1 = millis();
        print_time(time_1);
        Serial.println("I'm message number one!");
    }

    if(millis() > time_2 + INTERVAL_MESSAGE2){
        time_2 = millis();
        print_time(time_2);
        Serial.println("Hello, I'm the second message.");
    }

    if(millis() > time_3 + INTERVAL_MESSAGE3){
        time_3 = millis();
        print_time(time_3);
        Serial.println("My name is Message the third.");
    }

    if(millis() > time_4 + INTERVAL_MESSAGE4){
        time_4 = millis();
        print_time(time_4);
        Serial.println("Message four is in the house!");
    }
}

void print_time(unsigned long time_millis){
    Serial.print("Time: ");
    Serial.print(time_millis/1000);
    Serial.print("s - ");
}
#include<bits/stdc++.h>
using namespace std;

int mountainblue(int a[], int n)
{
sort(b,b+n);
  int k=0,m=0;
  vector<int> v;
  int mx = b[n-1];
  int mn = b[0];
  
  for(int i=0;i<n;i++)
  {
      if(a[i] == mx || a[i] == mn)
      {
          if(a[i] == mx)
          {
              int j;
              for(j=i;j<n;j++)
              {
              k++;
              if(a[j] == mn)
              break;
              }
          }
           if(a[i] == mn)
          {
              int j;
              for(j=i;j<n;j++)
              {
              k++;
              if(a[j] == mx)
              break;
              }
          }
      }
    //   cout << k <<" ";
      v.push_back(k);
    // s.insert(k);
      k=0;
  }
  
  sort(v.begin(),v.end());
//   cout << v[];
  for(int i=0;i<v.size();i++)
  if(v[i] > 1)
  {
  return v[i];
  }
  
  return -1;
}

int main()
{
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)
    cin >> a[i];
  
  cout << mountainblue(a,n);
}
#include<bits/stdc++.h>
using namespace std;
int mountainblue(string s)
{
string s = string;
   
   int ln = s.length();
   
   string ss="";
   string sr = s;
  
 int t = 1,k=0;
 
 string sb = sr.substr(ln-m, m);
     sr.erase(ln-m,m);
    sr = sb + sr;
       k++;
  
  while(sr != s)
  {
      if(t == 1)
      {
      string sb = sr.substr(ln-n, n);
     sr.erase(ln-n,n);
   
    sr = sb + sr;
       k++;
       t=0;
      }
      else
      {
          string sb = sr.substr(ln-m, m);
     sr.erase(ln-m,m);
   
    sr = sb + sr;
       k++;
       t=1; 
      }
  }
  return k;
}
int main()
{
  string s;
  cin >> s;
  cout << mountainblue(s);
}
#include <bits/stdc++.h>

using namespace std;
bool isp(long double x)
{
    
    if (x >= 0) {
 
        long long sr = sqrt(x);
         
        
        return (sr * sr == x);
    }
    
    return false;
}

int main()
{
    long long int n;
    cin >> n;
    long long int a[n];
    for(long long int i=0;i<n;i++)
    {
    cin >> a[i];
    if(isp(a[i]))
    cout <<a[i]<<" ";
    }
}
#include <iostream>
using namespace std;
  
int main() {
  
    int x = 19 ;
    (x & 1) ? cout<<"Odd" : cout<< "Even" ;
        
    return 0;
}
int maxSubArray(vector<int>& nums) {
        int cs = nums[0], ms = nums[0];
        for(int i=1; i<nums.size(); i++)
        {
            cs = max(nums[i], cs+nums[i]);
            ms = max(cs,ms);
        }
        return ms;
    } 
#include <limits>

file.ignore( std::numeric_limits<std::streamsize>::max() );
std::streamsize length = file.gcount();
file.clear();   //  Since ignore will have set eof.
file.seekg( 0, std::ios_base::beg );
#include <iostream>
#include <string>

void printValue(std::string& y) // type changed to std::string&
{
    std::cout << y << '\n';
} // y is destroyed here

int main()
{
    std::string x { "Hello, world!" };

    printValue(x); // x is now passed by reference into reference parameter y (inexpensive)

    return 0;
}
int var{};
int& ref1{ var };  // an lvalue reference bound to var
int& ref2{ ref1 }; // an lvalue reference bound to var
int main()
{
    int x { 5 };
    int& ref { x }; // valid: lvalue reference bound to a modifiable lvalue

    const int y { 5 };
    int& invalidRef { y };  // invalid: can't bind to a non-modifiable lvalue
    int& invalidRef2 { 0 }; // invalid: can't bind to an r-value

    return 0;
}
int main()
{
    int& invalidRef;   // error: references must be initialized

    int x { 5 };
    int& ref { x }; // okay: reference to int is bound to int variable

    return 0;
}
template <typename T> // this is the template parameter declaration
T max(T x, T y) // this is the function template definition for max<T>
{
    return (x > y) ? x : y;
}
if (std::cin.fail()) // has a previous extraction failed or overflowed?
{
    // yep, so let's handle the failure
    std::cin.clear(); // put us back in 'normal' operation mode
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // and remove the bad input
}
#include <iostream>
#include <utility>

int y(int &) { return 1; }
int y(int &&) { return 2; }

template <class T> int f(T &&x) { return y(x); }
template <class T> int g(T &&x) { return y(std::move(x)); }
template <class T> int h(T &&x) { return y(std::forward<T>(x)); }

int main() {
  int i = 10;
  std::cout << f(i) << f(20);
  std::cout << g(i) << g(20);
  std::cout << h(i) << h(20);
  return 0;
}
#include <iostream>
#include <limits>

int main() {
  unsigned int i = std::numeric_limits<unsigned int>::max();
  std::cout << ++i;
}
#include <iostream>

void f(int a = []() { static int b = 1; return b++; }())
{
   std::cout << a;
}

int main()
{
   f();
   f();
}
#include <iostream>

class A {
public:
  void f() { std::cout << "A"; }
};

class B : public A {
public:
  void f() { std::cout << "B"; }
};

void g(A &a) { a.f(); }

int main() {
  B b;
  g(b);
}
#include <iostream>

int main() {
  static int a;
  std::cout << a;
}
#include <iostream>
struct X {
  X() { std::cout << "X"; }
};

int main() { X x(); }
#include <iostream>
#include <type_traits>

using namespace std;

template<typename T, typename U>
void f(T, U) {
    cout << is_same_v<T, U>;
}

int main() {
    int i = 0;
    double d = 0.0;
    f(i, d); 
    f<int>(i, d); 
    f<double>(i, d); 
}
#include <iostream>

void f(char*&&) { std::cout << 1; }
void f(char*&) { std::cout << 2; }

int main() {
   char c = 'a';
   f(&c);
}
#include <iostream>
using namespace std;

size_t get_size_1(int* arr)
{
  return sizeof arr;
}

size_t get_size_2(int arr[])
{
  return sizeof arr;
}

size_t get_size_3(int (&arr)[10])
{
  return sizeof arr;
}

int main()
{
  int array[10];
  //Assume sizeof(int*) != sizeof(int[10])
  cout << (sizeof(array) == get_size_1(array));
  cout << (sizeof(array) == get_size_2(array));
  cout << (sizeof(array) == get_size_3(array));
}
#include <iostream>
#include <type_traits>

void g(int&) { std::cout << 'L'; }
void g(int&&) { std::cout << 'R'; }

template<typename T>
void f(T&& t) {
    if (std::is_same_v<T, int>) { std::cout << 1; } 
    if (std::is_same_v<T, int&>) { std::cout << 2; } 
    if (std::is_same_v<T, int&&>) { std::cout << 3; } 
    g(std::forward<T>(t));
}

int main() {
    f(42);
    int i = 0;
    f(i);
}
#include <iostream>

struct GeneralException {
  virtual void print() { std::cout << "G"; }
};

struct SpecialException : public GeneralException {
  void print() override { std::cout << "S"; }
};

void f() { throw SpecialException(); }

int main() {
  try {
    f();
  }
  catch (GeneralException e) {
    e.print();
  }
}
#include<iostream>

int foo()
{
  return 10;
}

struct foobar
{
  static int x;
  static int foo()
  {
    return 11;
  }
};

int foobar::x = foo();

int main()
{
    std::cout << foobar::x;
}
#include <iostream>
#include <vector>

int f() { std::cout << "f"; return 0;}
int g() { std::cout << "g"; return 0;}

void h(std::vector<int> v) {}

int main() {
    h({f(), g()});
}
#include <iostream>

void print(int x, int y)
{
    std::cout << x << y;
}

int main() {
    int i = 0;
    print(++i, ++i);
    return 0;
}
#include <iostream>
#include <vector>

int main() {
  std::vector<int> v1(1, 2);
  std::vector<int> v2{ 1, 2 };
  std::cout << v1.size() << v2.size();
}
#include <iostream>

struct X {
  X() { std::cout << "a"; }
  X(const X &x) { std::cout << "b"; }
  const X &operator=(const X &x) {
    std::cout << "c";
    return *this;
  }
};

int main() {
  X x;
  X y(x);
  X z = y;
  z = x;
}
#include <iostream>
#include <map>
using namespace std;

int main()
{
  map<bool,int> mb = {{1,2},{3,4},{5,0}};
  cout << mb.size(); 
  map<int,int> mi = {{1,2},{3,4},{5,0}};
  cout << mi.size();
}
#include <iostream>

struct S {
    int one;
    int two;
    int three;
};

int main() {
    S s{1,2};
    std::cout << s.one;
}
#include <iostream>

struct X {
    X() { std::cout << "1"; }
    X(const X &) { std::cout << "3"; }
    ~X() { std::cout << "2"; }

    void f() { std::cout << "4"; }

} object;

int main() {
    X(object);
    object.f();
}
#include <iostream>

template<class T>
void f(T) { std::cout << 1; }

template<>
void f<>(int*) { std::cout << 2; }

template<class T>
void f(T*) { std::cout << 3; }

int main() {
    int *p = nullptr; 
    f( p );
}
using namespace std;

template <class T> void f(T) {
  static int i = 0;
  cout << ++i;
}

int main() {
  f(1);
  f(1.0);
  f(1);
}
#include <bits/stdc++.h>
using namespace std;  

int uniquestring(string s)
{
      int a[26];
for(int i=0;i<26;i++)
a[i]=0;
for(int i =0;i<s.length();i++)
{
    int m = s[i];
    a[m - 97]++;
}

for(int i =0;i<s.length();i++)
{
    int t = s[i];
    if(a[t-97] == 1)
    {
   return i+1;
    }
}
return -1;
}
int main()  
{  
   map<char, int> wordFreq;
    string s, t;
    cin >> s;
 cout << uniquestring(s);
}  
// Binary Search in C++

#include <iostream>
using namespace std;

int binarySearch(int array[], int x, int low, int high) {
  
	// Repeat until the pointers low and high meet each other
  while (low <= high) {
    int mid = low + (high - low) / 2;

    if (array[mid] == x)
      return mid;

    if (array[mid] < x)
      low = mid + 1;

    else
      high = mid - 1;
  }

  return -1;
}

int main(void) {
  int array[] = {3, 4, 5, 6, 7, 8, 9};
  int x = 4;
  int n = sizeof(array) / sizeof(array[0]);
  int result = binarySearch(array, x, 0, n - 1);
  if (result == -1)
    printf("Not found");
  else
    printf("Element is found at index %d", result);
}
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int a , b;
    cin>>a>>b;
    
    for(int i =a; a<=b ; a++){
        string word[10] = {"" , "one", "two", "three" , "four" , "five" , "six" , "seven", "eight" , "nine"};
        
        if(a>=1 && a<=9){
            cout<<word[a]<<endl;
            
        }
        if(a>9){
            for(;a<=b;a++){
                if(a % 2 ==0){
                    cout<<"even"<<endl;
                    
                }
                if(a % 2 ==1){
                    cout<<"odd"<<endl;
                }
            }
        }
    }
    // Complete the code.
    return 0;
}
float rstoc(x) {
  float decimal = abs(x - trunc(x));

  float random_selector = (float)rand() / RAND_MAX;

  float adjustor;
  if (random_selector < decimal) adjustor = 1;
  else adjustor = 0;

  // consider sign
  if(x < 0) adjustor = -1 * adjustor;

  return trunc(x) + adjustor;
}
#include<bits/stdc++.h>
#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 ll long long
#define ull unsigned ll
#define take(n) ll int n;cin>>n
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define pp pop_back()
#define array(n,name) ll int *name=new ll int[n]
#define takearray(n,name) rep(i,0,n) cin>>name[i];
#define Zubin ios::sync_with_stdio(false);
#define Shah cin.tie(NULL);cout.tie(0);
#define nl cout<<endl;
using namespace std;

int xcor[4]={-1,0,0,+1};
int ycor[4]={0,-1,1,0};

ull int power(ull n,int x){
    if(x==0) return 1;
    return n * power(n,x-1);
}

int main(){

    Zubin Shah

    take(n);
    array(n,numbers);
    takearray(n,numbers);
    int maxcount=0;
    int count=0;
    int currmax=0;
    rep(i,0,n){
        if(numbers[i]>currmax){  //continuing the streak
            currmax = numbers[i];    // updating the max of current streak
            count++;   
        }
        else {  //streak broken
            count=1;
            currmax=numbers[i];
        }
        maxcount = max(maxcount,count);
    }
    cout<<maxcount<<endl;


return 0;
}
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(arr[j]<arr[i]){
                int temp=arr[j];
                arr[j]=arr[i];
                arr[i]=temp;
            }
        }
    }
    
    for(int i=0;i<n;i++)
    {
        cout<<arr[i]<<" ";
    }cout<<endl;
    
    return 0;
    
}
char a = 'a';
int ia = (int)a; 
/* note that the int cast is not necessary -- int ia = a would suffice */
void insertionsort(int A[], int size){
  int i, j;
  for(i=1; i<size; i++){
    key= A[i];
    j=i-1;
    
    while(j>=0 && A[j]> key){
      A[j+1]= A[j];
      j=j-1;
    }
    A[j+1]= key;
  }
}