Snippets Collections
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();
class solution {
  public:
  vector<vector<int>>levelorder(treenode* root){
    vector<vector<int>> ans;
    queue<treenode*> q;
    q.push(root);
    while(!q.empty()){
      int size = q.size();
      vector<int> level;
      for(int i=0;i<size;i++)
        {
          treenode *node = q.front();
          q.pop();
          if(node->left != NULL) q.push(node->left);
          if(node->right !=NULL) q.push(node->right);
          level.push_back(node->val);
        }
      ans.push_back(level);
    }
    return ans;
  }
};
void postorder(node)
{
  if(node==null)
    return;
  
  postorder(node->left)
  postorder(node->right)
  print(node->data);
}
void inorder(node)
{
  if(node==null) return;
  
  inorder(node->left)
  print(node->data)
  inorder(node->right)
}
void preorder(node)
{
  if(node==null) return;
  
  print(node->data)
  preorder(node->left)
  preorder(node->right)
}
#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);

	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;
  }
}
#include<bits/stdc++.c>

int binarysearch(int arr[], int l, int r, int x){
  if(r>=l){
     int mid= l+(r-1)/2;
     if(arr[mid]== x){
       return mid;
     }
    if(x<arr[mid]){
      return binarysearch(arr, l ,mid-1, x);
    }
    if(x>arr[mid]){
      return binarysearch(arr, mid+1, r, x);
    }
  }
  return -1;
  
}

int main(){
  int arr[]= {10, 20, 30, 40, 50};
  int x= 30;
  int n= sizeof(arr)/ sizeof(arr[0]);
  int result= binarysearch(arr, 0, 1, n-1m, x);
  (result==-1)? cout<<"Element is not present" : cout<<"Element is present at"<<result;
  return 0;
  
}
#include <string>
using namespace std; 
std::string even_or_odd(int number) 
{
  string EvenOrOdd;
  if (number %2 == 0){
  EvenOrOdd = "Even"; 
  }else{
  EvenOrOdd = "Odd"; 
  }
  return EvenOrOdd;
}
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int d; 
    long ld; 
    char ch; 
    float f; 
    double lf; 
    
    
    scanf("%d %ld %c %f %lf",&d,&ld,&ch,&f,&lf);
    printf("%d\n%ld\n%c\n%f\n%lf",d,ld,ch,f,lf);
    return 0;
}
#include <stdio.h>

void update(int *a,int *b) {
     
    
    int ans = *a; 
    *a = *a + *b;
    *b = ans - *b; 
    if (*b <0){
        *b = -(*b);
    }
    
    //printf("*pb %d\n", *pb);
    //printf("*a %d\n",*a);
    //printf("*b %d\n",*b);
    //printf("*pa %d\n",*pa);
    //printf("\n"); 
    //    
}

int main() {
    int a, b;
    int *pa = &a, *pb = &b;
    
    scanf("%d %d", &a, &b);
    update(pa, pb);
    printf("%d\n%d", a, b);

    return 0;
}
// Online C++ compiler to run C++ program online
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
using namespace std;

class Maths {
public:
    int oneQty; 
    int twoQty;
    int sumTotal; 
    
    int width;
    int height; 
    int length;
    int areaTotal; 
    Maths(int Width, int Height, int Length, int OneQty, int TwoQty){
        width = Width; 
        height = Height; 
        length = Length;
        oneQty = OneQty; 
        twoQty = TwoQty; 
    }
    int MakeArea(int width, int height, int length) {
        areaTotal = width * height * length;
        return areaTotal;
    }
    void printArea() {
        cout << "Wigth: " << width << endl; 
        cout << "Height: " << height << endl; 
        cout << "length: " << length << endl; 
        cout << "" << endl;
        cout << "Total: "<< areaTotal << endl;
    }
    int subtraction(int oneQty, int twoQty) {
        sumTotal = oneQty - twoQty;
        return sumTotal; 
    }
    void printSum() {
        cout << "First Qty: " << oneQty << endl; 
        cout << "Second Qty: " << twoQty << endl; 
        cout << "" << endl; 
        cout << "Subtarction Totle: " << sumTotal << endl; 
    }

};

int main() {
    Maths One(4, 10, 13,3,4);
    One.MakeArea(3,1,1);
    One.subtraction(10, 7);
    One.printArea(); 
    
    One.printSum(); 
    
    return 0;
}
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
//using namespace std;
//std:: not using namespace exsample 
namespace Happy {
    int num = 32; 
    std::string name = "Jarod";
    
}
namespace Sad {
    int num = 42; 
    std::string name = "Sid"; 
}
int main() {
    std::cout << Happy::name << std::endl;
    std::cout << Happy::num << std::endl; 
    std::cout << "" << std::endl; 
    std::cout << Sad::name << std::endl; 
    std::cout << Sad::num << std::endl;
    return 0;
}
// Online C++ compiler to run C++ program online
#include <iostream>
//#include <cstdio>
//#include <vector>
//#include <iostream>
//#include <algorithm>
#include <list> // for arra list list<foodIdeams>....
using namespace std;

class foodList{
  public:
  string recipe;
  list<string> ingredient; 
  
  foodList(string Recipe){
      recipe = Recipe; 
  }
  
  void listMaker(){
      cout << "Recipe Name: "<< recipe << endl;
      cout << "" << endl; 
      cout << "Ingredients: " << endl; 
      for (string e : ingredient){
          cout << e << endl; 
      }
  }
};


int main() {
   
foodList recipe1("spaghetti"); 
recipe1.ingredient.push_back("1 pound lean ground meat like beef, turkey, chicken or lamb");
recipe1.ingredient.push_back("3 tablespoons olive oil");
recipe1.ingredient.push_back("1 cup (130 grams) chopped onion");
recipe1.ingredient.push_back("3 garlic cloves, minced (1 tablespoon)");
recipe1.ingredient.push_back("2 tablespoons tomato paste");
recipe1.ingredient.push_back("1/2 teaspoon dried oregano");
recipe1.ingredient.push_back("Pinch crushed red pepper flakes");
recipe1.ingredient.push_back("1 cup water, broth or dry red wine");
recipe1.ingredient.push_back("1 (28-ounce) can crushed tomatoes");
recipe1.ingredient.push_back("Salt and fresh ground black pepper");
recipe1.ingredient.push_back("Handful fresh basil leaves, plus more for serving");
recipe1.ingredient.push_back("12 ounces dried spaghetti or favorite pasta shape");
recipe1.ingredient.push_back("1/2 cup shredded parmesan cheese");
recipe1.listMaker();

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

int main() {
   int N; 
   cin >> N; 
   int arr[N]; 
   for (int i = 0; i < N; i++) {
        cin >> arr[i];        
    }
    for (int j = N - 1; j >= 0; j--) {
        cout << arr[j] << " ";
    }

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

int main() {
    cout << "Hello World!" << endl;
    return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;


string restWord(string str);

int main()
{	
	string str;
	cout << "Enter the string: " << endl;
	getline(cin, str);
	
	
	cout << restWord(str) << endl;

	return 0;
}

string  restWord(string str)
{
	int cnt=0;
	string result ="";

	for (int i = 0; !isspace(str[i]) && str.size(); i++)
	{
		++cnt ;
	}

	for (int j = cnt + 1; j < str.size(); j++)
	{
		result += str[j];
	}


	return result;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;


string firstWord(string str);

int main()
{	
	string str;
	cout << "Enter the string: " << endl;
	getline(cin, str);
	
	
	cout << firstWord(str) << endl;

	return 0;
}

string firstWord(string str)
{
	string result = "";

	for (int i = 0; !isspace(str[i]) && str.size(); i++)
	{
		result += str[i];
	}
	return result;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;



int main()
{	
	string str;
	cout << "Enter the string: " << endl;
	getline(cin, str);
	unsigned int len = str.size();  // intitilize len by its original size
	
	for (int i = 0; i < len ; i++) // keeps incrementing if there is no punctutation
	{
		if (ispunct(str[i]))
		{	
			str.erase(i, 1);   // erase the element i to one place.
			i--;   // new character takes place of the erased one. We are neglecting the effect of loop increment
			len = str.size(); // removing the punctutation shrinks the string size
		}						// length size changes with every iteration and we give new len value
	}
	
	cout << "The word without punctutation is " << str << endl;

	return 0;
}
string str;
	cout << "Enter the string: " << endl;
	getline(cin, str);
	
	
	for (auto & ind : str)
	{
		if (ispunct(ind))
			ind = ' ';
	}
	
	cout << str;
#include <iostream>
#include <string>
using namespace std;
using std::string;
const string hexdigits = "0123456789ABCDEF"; // possible hex digits


int main()
{
	
	cout << "Enter a series of numbers between 0 and 15"
		<< " separated by spaces. Hit ENTER when finished: "
		<< endl;
	string result = ""; // will hold the resulting hexify’d string
	unsigned int n; // hold numbers from the input
	

	while (cin >> n )
	{
		if (n < 16) // ignore invalid input
			result += hexdigits[n]; // fetch the indicated hex digit
		else if (n == 17)
			break;
	}

	cout << "Your hex number is: " << result << endl;

	return 0;
}

#include <iostream>
#include <string>
using namespace std;
using std::string;



int main()
{
	string str("helloWorld ");
	/*
	the for loop terminates at that very time when the condition is not met. 
	In our case for loop works until the whitespace is met or we go beyond str size
	decltype is the almost the same auto, find data type automatically of the expression!!!
	*/

	for (decltype(str.size()) i = 0; i != str.size() && !isspace(str[i]); i++)
	{
		str[i] = toupper(str[i]);
	}
	

	cout <<"The new string is " << str<< endl;
	return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;

/*
Remember that a reference is just
another name for a given object. When we use a reference as our control variable,
that variable is bound to each element in the sequence in turn. Using the reference,
we can change the character to which the reference is bound.

*/

int main()
{
	string str("HeLLo World");
	
	
	for (auto &n : str)
	{
		if (isupper(n))
			n=tolower(n);
		else
			n = toupper(n);
	}
	cout <<"The new string is " << str<< endl;
	return 0;
}
#include <iostream>
#include <string>
using namespace std;
using std::string;



int main()
{
	string str("AbZal NUrgAzy");
	
	
	for (auto n : str)
	{
		if (isupper(n))
			cout << (char)(tolower(n));
		else
			cout << (char)(toupper(n));
	}
	cout << endl;
	return 0;
}
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name, name1;
	char ch;

	cout << "Enter any sentence" << endl;    // printing the middle letter 
	getline(cin, name);
	ch = name[name.length()/2];
	cout << "The middle letter in the sentence is " << ch << endl;

	for (int i = 0; i <= (name.length() / 2)-1; i++)    // printing the first half of the sentence
	{
		cout << name[i];
	}
	cout << "\nThe second half " << endl;

	for (int i = (name.length() / 2 )+1; i <= name.length(); i++)    // printing the second half of the sentence
	{
		cout << name[i];
	}


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


int main()
{
    string day;
    int startTime, minutes;
    double cost, rate; 
    char ch ;

    cout << fixed << showpoint << setprecision(2);

    do {
        cout << "Enter start time of the call(For example, 2:30 = 2330):  " << endl;
        cin >> startTime;

        while (startTime<0 || startTime>2400) {

            cout << "\nInvalid time.";          // keep asking for time input until it is valid
            cout << "Enter start time of the call(For example, 2:30 = 2330): ";
            cin >> startTime;
        }

        cout << "Enter length of the call in minutes: ";
        cin >> minutes;
        cout << "Enter the day of the week: ";
        cin >> day;

        if (day == "monday" || day == "MONDAY" || day == "tuesday" || day == "TUESDAY" || day == "wednesday" || day == "WEDNESDAY"
            || day == "THURSDAY" || day == "thursday" || day == "friday" || day == "FRIDAY") {

            if (startTime >= 800 && startTime <= 1800)
                rate = 0.4;
            else
                rate = 0.25;
            cost = minutes * rate;

            cout << "\nRate for the call was " << "$" << rate << " a minute" << endl
                 << "Your total cost: " << "$" << cost << endl;
        }

        else if (day == "saturday" || day == "SATURDAY" || day == "sunday" || day == "SUNDAY")
        {
            rate = 0.15;
            cost = minutes * rate;
            cout << "\Rate for the call was " << "$" << rate << " a minute" << endl
                 << "Your total cost: " << "$" << cost;

        }

        else
            cout << "\nInvalid.";

        cout << "\nWould you like to calculate  your bill again ? (y / n) : ";
        cin >> ch;
        cout << endl;
        
        

    }


    while (ch == 'Y' || ch == 'y');
    cout << "End of programm" <<endl;

    return 0;
}
 do {
        :
        :
        :
		:
        else
        {
            cout << "\nInvalid.";
            cout << "\nWould you like to calculate  your bill again ? (y / n) : ";
            cin >> ch;
            cout << endl;
        }
        

    }


    while (ch == 'Y' || ch == 'y');
    cout << "End of programm" <<endl;
while (startTime<0 || startTime>2400) {

            cout << "\nInvalid time.";          // keep asking for time input until it is valid
            cout << "Enter start time of the call(For example, 2:30 = 2330): ";
            cin >> startTime;
        }
#include <iostream>
#include <string>
using namespace std;


int main()
{
    string userName;
    cout << "Enter the user name" << endl;
    getline(cin, userName);

    for (int ind = userName.length()-1; ind >= 0; ind--) {
        cout << userName[ind];
    }
    cout << endl;

    return 0;
}
#include <iostream>
using namespace std;
int const MAX = 60;
int maxinlst(int arr[], int sizeofArr); 

int main()
{
    int arr[MAX];
    int sizeofArr, currNum, maximum;

    cout << "Enter the size of the array " << endl;
    cin >> sizeofArr;
    cout << "Enter the list of numbers" << endl;
    for (int i = 0; i < sizeofArr; i++) {
        cin >> currNum;
        arr[i] = currNum;
    }

    maximum = maxinlst( arr,sizeofArr);
    cout << "The maximum is " << maximum << endl;


    return 0;
}

int maxinlst(int arr[], int sizeofArr) {

    int max = arr[0];
    for (int i = 1; i < sizeofArr; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }
    return max;
}
#include <iostream>
using namespace std;
const int MAX_ARRAY = 60;

int main()
{
    int numberofStudents, currGrade,sum;
    double average;
    int grades[MAX_ARRAY];

    cout << "Enter the number of students" << endl;
    cin >> numberofStudents;
    cout << "Enter the grades separated by a space" << endl;
    
    // Reading the grades one by one and uploading it inside the array
    for (int i = 0; i < numberofStudents; i++) {
        cin >> currGrade;
        grades[i] = currGrade;
    }
    // calculating the sum and average

    sum = 0;
    for (int i = 0; i < numberofStudents; i++) {
        sum += grades[i];
    }
    average = (double)sum / (double)numberofStudents;

    cout << "the average grade is " << average << endl;
    for (int i = 0; i < numberofStudents; i++) {
        if (grades[i] > average) {
            cout << "The grades that is more than the average is " << grades[i] << endl;
        }
    }
    
    return 0;
}
#include <iostream>
#include <cmath>
using namespace std;

const int NO_SOLUTION = 0;
const int ONE_REAL_SOLUTION = 1;
const int TWO_REAL_SOLUTIONS = 2;
const int ALL_REALS = 3;
const int NO_REAL_SOLUTIONS = 4;


int linear(double a, double b, double& outX);
int quadratic(double a, double b, double c, double& outX1, double& outX2);

int main()
{
	double a, b, c,x1,x2;
	cout << "Enter the quadratic equation coefficients" << endl;
	cin >> a >> b >> c;

	switch (quadratic(a,b,c,x1,x2)) {

		case NO_SOLUTION: 
			cout << "No solutions" << endl;
			break;

		case ONE_REAL_SOLUTION:
			cout << "One solution: " << x1 << endl;
			break;

		case TWO_REAL_SOLUTIONS:
			cout << "Two real solutions: " << x1 << " and " << x2 << endl;
			break;

		case ALL_REALS:
			cout << "All real number are solutions" << endl;
			break;

		case NO_REAL_SOLUTIONS:
			cout << "No real solutions" << endl;
			break;
	}


	return 0;
}

int quadratic(double a, double b, double c, double& outX1, double& outX2) {

	double delta, x1, x2;
	delta = b * b - 4 * a * c;

	if (delta != 0.0) {
		

		if (delta > 0) {
			x1 = (-b + sqrt(delta)) / (2 * a);
			x2 = (-b - sqrt(delta)) / (2 * a);
			outX1 = x1;
			outX2 = x2;
			return TWO_REAL_SOLUTIONS;
		}

		else if (delta == 0.0) {
			x1 = -b / (2 * a);
			return ONE_REAL_SOLUTION;
		}
		else
			return NO_REAL_SOLUTIONS;
	}
	else
		return linear(b, c, outX1);

	
}

int linear(double a, double b, double& outX) {
	double x;
		
	if (a != 0) {
		x = -b / a;
		outX = x;
		return ONE_REAL_SOLUTION;
	}
	else if ((a == 0) && (b == 0)) {
		x = 0;
		outX = x;
		return ALL_REALS;
	}
	else
		return NO_SOLUTION;

}
#include <iostream>
using namespace std;

int analyzeDigits(int num, int& outSum);

int main()
{

	int num;
	int sumDigits, countDigits;

	cout << "Enter any nymber to get its sum and number of digits" << endl;
	cin >> num;

	countDigits = analyzeDigits(num, sumDigits);

	cout << num << " has " << countDigits << " digits and their sum is " << sumDigits << endl;

	return 0;
}

int analyzeDigits(int num, int& outSum) {

	int count = 0, sum = 0;
	int currDig;

	while (num > 0) {
		currDig = num % 10;
		sum += currDig;
		count++;
		num = num / 10;

	}

	outSum = sum;    // directly changes main variable by reference while one of outputs is returned
	return count;

}
#include <iostream>
using namespace std;

int factorial(int num); // <-- remember to include semicolon  

// we use prototype of the function to hold the function itself after the main function and show that there is a function with similar name and fuctionality when come across first time.


int main()
{
	int n, k, result;

	cout << "Please enter the n and k by space" << endl;
	cin >> n >> k;


	result =  factorial(n) / (factorial(k)*factorial(n-k));

	cout << "The result is " << result << endl;

	return 0;
}

int factorial(int num) {
	int i, factRes;
	factRes = 1;

	for (i = 1; i <= num;i++) {
		factRes *= i;
	}

	return factRes;
#include <iostream>
using namespace std;

// n choose k, combination method using factorials

int main()
{
	int n, k, k_Fact, n_Fact, result, k_nFact;

	cout << "Please enter the n and k by space" << endl;
	cin >> n >> k;

	n_Fact = 1;
	for (int i = 1; i <= n; i++) {
		n_Fact *= i;
	}

	k_Fact = 1;
	for (int i = 1; i <= k; i++) {
		k_Fact *= i;
	}
	
	k_nFact = 1;
	for (int i = 1; i <= (n-k); i++) {
		k_nFact *= i;
	}

	result = n_Fact / (k_Fact* k_nFact);

	cout << "The result is " << result << endl;

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

// Fibonacci sequence 

int main()
{

	int first = 0, second = 1;
	int next, num;

	cout << "Enter the number of Fibonacci sequence" << endl;
	cin >> num;

	cout << "Fibonacci series is " << endl;

	for (int i = 1; i <= num; ++i) {

		cout << first << endl;
		next = first + second;
		first = second;
		second = next;

	}

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

// here we use flag method to count the average grade

int main()
{
	bool seenEndofInput;
	int numofStudents, sum;
	int curr;
	double average;

	cout << "Write grades by separated space" << endl;
	cout << "End of grades by typing -1" << endl;

	numofStudents = 0;
	sum = 0;

	seenEndofInput = false;

	while (seenEndofInput == false) {
		cin >> curr;

		if (curr == -1) {
			seenEndofInput == true;
		}
		else {
			sum += curr;
			numofStudents++;
		}
	}

	average = (double)sum / (double)numofStudents;


	cout << "The class average grade is " << average << endl;

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



int main()
{
    int numofStudents;
    int curr, sum=0;
    double average;

    cout << "Please enter number of students" << endl;
    cin >> numofStudents;
    cout << "Write grades" << endl;
    
    for (int count = 1; count <= numofStudents;++count) {
        cin >> curr;
        sum += curr;
    }
    average = (double)(sum / numofStudents);


    cout << "The average grade is "<<average << endl;

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

/*
375 / 10 = 37;
375 % 10 = 5 ;
So here you are separating one number in one loop from the main number

*/

int main()
{
    int countDigits = 0, countSum = 0;
    int num,currDigit;

    cout << "Enter any number" << endl;
    cin >> num;
    while (num>0) {
        currDigit = (num % 10);
        countSum += currDigit;
        countDigits++;
        num = num / 10;
    }

    cout << "The sum of digits is: " << countSum << " and the count of digits is: " << countDigits << endl;


    return 0;
}

#include <iostream>
#include <string>
using namespace std;


int main()
{
    int num;
    int even_cnt = 0, odd_cnt=0;
    cout << "Write any 4 numbers" << endl;;
    
    for (int i=1; i <= 4; ++i) {
        cin >> num;

        if (num % 2 == 0) {
            ++even_cnt;
        }
        else
            ++odd_cnt;
    }
    
    if (even_cnt > odd_cnt) {
        cout << "even numbers are more";
    }
    else if (even_cnt < odd_cnt) {
        cout << "odd numbers are more";
    }
    else 
        cout << "they are equal";
    return 0;
}

#include <iostream>
#include <string>
using namespace std;


int main()
{
    
    int hour24, minutes24;
    int hour12, minutes12;
    string period;
    char value;

    cout << "Enter the time in a 24-hour format \n";
    cin >> hour24 >> value >> minutes24;

    minutes12 = minutes24;

    if (hour24 >= 0 && hour24 <= 11) {
        period = "AM";
        if (hour24 == 0) {
            hour12 = 12;
        }
        else
            hour12 = hour24;
    }
    else
    {
        period = "PM";
        if (hour24 == 12) {
            hour12 = hour24;
        }
        else
            hour12 = hour24 - 12;
    }

    cout << hour24 << value << minutes24 << " is " << hour12 << value << minutes12<<" " << period << endl;

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


int main()
{
    
    char charVal;
    cout << "Enter the character"<< endl;
    cin >> charVal;
    if (charVal >= 'a' && charVal <= 'z') {

        cout << "The lowercase character";
    }
    else if (charVal >= 'A' && charVal <= 'Z') {
        cout << "The uppercase character";
    }
    else if (charVal >= '1' && charVal <= '9') {
        cout << "The numeric character";
    }
    else 
        cout << "The non alpha-numeric character";

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


int main()
{
    int dollar, cent, amount, leftover;
    int quarter, dime, nickel, penny;

    cout << "Write please amount of dollar through space";
    cin >> dollar >> cent;

    amount = 100 * dollar + cent;
    quarter = amount / 25;
    leftover = amount % 25;

    dime = leftover / 10;
    leftover = leftover % 10;

    nickel = leftover / 5;
    leftover = leftover % 5;

    penny = leftover; 

    cout << "Quarter: " << quarter << endl;
    cout << "Dime: " << dime << endl;
    cout << "Nickel: " << nickel << endl;
    cout << "Penny: " << penny << endl;

    return 0;
}

#include <iostream>
using namespace std;


int main()
{
    
    char lowerCase, upperCase;
    int offset;

    cout << "Enter lowercase letter \n";
    cin >> lowerCase;

    offset = (int)(lowerCase-'a');
    upperCase = (char)('A' + offset);
    cout << "Uppercase letter is " << upperCase << endl;


    return 0;
}
#include<bits/stdc++.h>
 
using namespace std;
 
struct node {
    int data;
    struct node *next;
};
 
// To create a demo we have to construct a linked list and this 
// function is to push the elements to the list. 
void push(struct node **head_ref, int data) {
    struct node *node;
    node = (struct node*)malloc(sizeof(struct node));
    node->data = data;
    node->next = (*head_ref);
    (*head_ref) = node;
}
 
// Function to reverse the list
void reverse(struct node **head_ref) {
    struct node *temp = NULL;
    struct node *prev = NULL;
    struct node *current = (*head_ref);
    while(current != NULL) {
        temp = current->next;
        current->next = prev;
        prev = current;
        current = temp;
    }
    (*head_ref) = prev;
}
 
// To check our program 
void printnodes(struct node *head) {
    while(head != NULL) {
        cout<<head->data<<" ";
        head = head->next;
    }
}
 
// Driver function
int main() {
    struct node *head = NULL;
    push(&head, 0);
    push(&head, 1);
    push(&head, 8);
    push(&head, 0);
    push(&head, 4);
    push(&head, 10);
    cout << "Linked List Before Reversing" << endl;
    printnodes(head);
    reverse(&head);
    cout << endl;
    cout << "Linked List After Reversing"<<endl;
    printnodes(head);
    return 0;
}
// rdtsc.cpp
// processor: x86, x64
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(__rdtsc)

int main()
{
    unsigned __int64 i;
    i = __rdtsc();
    printf_s("%I64d ticks\n", i);
}
{
	// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	"Print to console": {
		"prefix": "cpp boilerplate",
		"body": [
			"#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 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 Zubin ios::sync_with_stdio(false);",
			"#define Shah cin.tie(NULL);cout.tie(0);",
			"using namespace std;\n",
			"int main(){\n",
			"\tZubin Shah\n",
			"\tint N;",
			"\tcin>>N;",
			"\twhile(N--){",

			"\t\t$1",
			"\t}\n",
			"return 0;",
			"}",
		],
		"description": "Log output to console",
	}
}
	public:
	int findK(vector<vector<int>> &a, int n, int m, int k)
    {
        // 1 2 3 4 5 
        // 6 7 8 9 10
        //11 12 13 14 15
        //16 17 18 19 20
        //21 22 23 24 25
        // k=4
        // 1 2 3
        // 4 5 6
        // 7 8 9
        // Your code goes here
        // if(k==1) return a[0][0];
        int lrow=0;
        int lcol=0;
        int urow=n-1;
        int ucol=m-1;
        int count=0;
        int i=0,j=0;
        while(count!=k){
            //iterating from left to right
            for(j=lcol;j<=ucol;j++){
                // cout<<"i:"<<i<<"j:"<<j<<endl;
                count++;
                if(count==k) {
                    goto x;
                }
            }
            ucol--;
            j--;
            //iterating from up to down
            for(i=lrow+1;i<=urow;i++){
                // cout<<"i:"<<i<<"j:"<<j<<endl;
                count++;
                if(count==k) {
                    goto x;
                }
                
            }
            urow--;
            i--;
            //iterating from right to left
            for(j=ucol;j>=lcol;j--){
                // cout<<"i:"<<i<<"j:"<<j<<endl;
                count++;
                if(count==k) {
                    goto x;
                }
                
            }
            lcol++;
            j++;
            //iterating from down to up
             for(i=urow;i>=lrow+1;i--){
                //  cout<<"i:"<<i<<"j:"<<j<<endl;
                count++;
                if(count==k) {
            // cout<<"lrow:"<<lrow<<" urow:"<<urow<<" lcol:"<<lcol<<" ucol:"<<ucol<<endl;
                    goto x;
                }
                
            }
            lrow++;
            i++;
            
        }
        x:
        return a[i][j];
        
    }
class Solution {
public:
    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
        vector<vector<int>>ans(r,vector<int>(c));
        int n = mat.size(), m = mat[0].size();
        if(n*m != r*c)  return mat;
        int p = 0, q = 0;
        for(int i = 0; i < r; ++i) {
            for(int j = 0; j < c; ++j) {
                ans[i][j] = mat[p][q];
                q = (q + 1) % m;
                if(q == 0)  p = p + 1;
            }
        }
        return ans;
    }
};
// TC - O(n) || SC - O(1)
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int n = prices.size() - 1, ans = 0, minSoFar = INT_MAX;
        for(int i = 0; i < n; ++i)  {
            minSoFar = min(minSoFar, prices[i]);
            ans = max(ans, (prices[i] - minSoFar));
        }
        return ans;
    }
};

// we can use auxilary array and store maxSoFar value
class Solution {
public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
        unordered_map<int,int>mp;
        vector<int> ans;
        for(int i = 0; i < nums2.size(); ++i)   mp[nums2[i]]++;
    
        for(int i = 0; i < nums1.size(); ++i)   { 
            if(mp[nums1[i]] > 0)    {
                mp[nums1[i]]--;
                ans.push_back(nums1[i]);
            }
        }
        return ans;
    }
};
class Solution {
public:
    vector<int> twoSum(vector<int>& numbers, int target) {
        int i = 0, j = numbers.size() - 1;
        while(i < j) {
            int sum = numbers[i] + numbers[j];
            if(sum == target) return {i + 1, j + 1};
            else if(sum > target)  j--;
            else    i++;
        }
        return {};
    }
};
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        for(int i = 0, j = 0; i < nums.size(); i++) {
            if(nums[i]) {
                swap(nums[i],nums[j++]);
            }
        }
    }
};


//2nd approach
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        int zero = 0, one = 0, n = nums.size()-1;
        while(zero < n && one < n)  {
            while(zero < n && nums[zero] != 0)  {
                zero++;
            }
            one = zero;
            while(one < n && nums[one] == 0)    {
                one++;
            }
            swap(nums[zero],nums[one]);
            zero++; 

        }
    }
};
class Solution {
public:
    void myReverse(vector<int> &nums,int start, int end)   {
        while(start < end)  {
            swap(nums[start++], nums[end--]);
        }
    }
    void rotate(vector<int>& nums, int k) {
        if(nums.size()<2)   return;
        k = k % nums.size();
        myReverse(nums, 0, nums.size() - k - 1);
        myReverse(nums, nums.size()-k, nums.size() - 1);
        myReverse(nums, 0 , nums.size() - 1);
    }
};
class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int>ans(nums.size());
        int first = 0, second = nums.size() - 1;
        for(int ind = nums.size() - 1; ind >= 0; ind--)  {
            if(abs(nums[first]) < nums[second]) 
                ans[ind] = nums[second] * nums[second--];
            else    ans[ind] = nums[first] * nums[first++];
        }
        return ans;
        
    }
}


//2nd approch
class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int>ans;
        int first = 0,second = 0;
        while(first<nums.size() && nums[first]<0  ) {
            first++;
        }
        second = first;
        first -= 1;
        while(first>=0 && second<nums.size())   {
            if(abs(nums[first] * nums[first]) < (nums[second] * nums[second]))  {
                ans.push_back(nums[first] * nums[first]);
                first--;
            }
            else {
                ans.push_back(nums[second] * nums[second]);
                second++;
            }
        }
        while(first>=0) {
            ans.push_back(nums[first] * nums[first]);
            first--;
        }
        while(second<nums.size())   {
            ans.push_back(nums[second] * nums[second]);
            second++;
        }
        return ans;

    }
};
class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_set<int>st(nums.begin(), nums.end());
        cout<<nums.size()<<"  "<<st.size()<<endl;
        return (nums.size() == st.size()) ? false : true; 
    }
};
class Solution {
public:
    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
        int p = m-1, q = n-1, ind = nums1.size()-1;
        while(p>=0 && q>=0) {
            if(nums2[q] > nums1[p]) {
                nums1[ind--] = nums2[q];
                q--;
            }
            else    {
                nums1[ind--] = nums1[p];
                p--;
            }
        }
        while(q >= 0)    {
            nums1[ind--] = nums2[q--];
        }
    }
};
class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        int n = digits.size();
        for(int i = n-1; i >=0 ; --i)   {
            if((digits[i] + 1) > 9) {
                digits[i] = 0;
            }
            else    {
                digits[i] += 1;
                return digits;
            }
        }
        digits.push_back(0);
        digits[0] = 1;
        return digits;
    }
};
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size(), lMax = 0, gMax = nums[0];
        for(int i = 0; i < n; ++i)    {
            lMax += nums[i];
            gMax = max(gMax, lMax);
            if(lMax<0)  
                lMax = 0;
        }
        return gMax;
    }
};
// Using While Loop
class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int start = 0, end = nums.size()-1;
        while(start<=end)    {
            int mid = (start+end)/2;
            if(nums[mid] == target) return mid;
            else if(nums[mid] < target)    
                start = mid+1;
            else 
                end = mid-1;
        }
        return start;
    }
};


//Using Recursion
class Solution {
public:
    int BinSearch(vector<int>nums,int start, int end, int target) {
        if(end < start) {
            return start;
        }
        int mid = (start + end) / 2;
        if(nums[mid] == target) {
            return mid;
        }
        else if(nums[mid] < target) {
            return BinSearch(nums, mid+1, end, target);   
        }
        else {
            return BinSearch(nums, start, mid-1,target);
        }
    }
    int searchInsert(vector<int>& nums, int target) {
        return BinSearch(nums,0,nums.size()-1,target);  
    }
};
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int start = 0, end = nums.size(),ans=0;
        while(start < end)  {
            if(nums[start] == val)  {
                swap(nums[start],nums[end-1]);
                end--;
            }    
            else start++;
        }
        return end;
    }
};
SDL_Rect rsc{}, dst{};
	for (const Tile& tile : m_pTiles)
	{
		rsc.x = static_cast<int>((m_LevelNumber * m_TileSize.x * 3) + m_TileSize.x * int(tile.tileState));
		rsc.y = 0;
		rsc.w = static_cast<int>(m_TileSize.x);
		rsc.h = static_cast<int>(m_TileSize.y);

		dst.x = static_cast<int>(tile.pos.x);
		dst.y = static_cast<int>(tile.pos.y);
		dst.w = static_cast<int>(m_TileSize.x);
		dst.h = static_cast<int>(m_TileSize.y);

		kaas::Renderer::GetInstance().RenderTexture(*m_pTexture, dst, rsc);
	}

	for (const Disc& disc : m_pPossibleDiscLocations)
	{
		if (disc.level == m_LevelNumber)
		{
			kaas::Renderer::GetInstance().RenderTexture(*m_pDiscTexture, disc.pos.x, disc.pos.y);
		}
	}
#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 take(n) ll int n;cin>>n
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;

int main()
{
    // Zubin Shah
    int N;
    cin>>N;
    while(N--)
    {
        take(n);
        vector<int> vect;
        vect.pb(1);
        ll carry=0;
        int number_of_digits=1;
        rep(i,2,n+1){
            rep(j,0,number_of_digits){
                ll temp=(vect[j]*i)+carry;
                vect[j]=temp%10;
                carry=temp/10;
            }
            while(carry>0){
                ll temp=carry%10;
                vect.pb(temp);
                carry/=10;
                number_of_digits++;
            }
        }
        rrep(i,number_of_digits-1,0){
            cout<<vect[i];
        }
        cout<<endl;
    }


return 0;
}
vector* sum( vector* v, int n ) {
    vector* r = ( vector* )( malloc( sizeof( vector ) ) );
    for( i = 0; i < n; i++ ) {
        r = add( r, v + i );
    }
    
    return r;
}
typedef struct __vector {
    int x;
    int y;
} vector;

vector* add( vector* a, vector* b ) {
    vector* r = ( vector* )( malloc( sizeof( vector ) ) );
    r->x = a->x + b->x;
    r->y = a->y + b->y;
    
    return r;
}
a = a ^ b;
b = a ^ b;
a = a ^ b;
#include <iostream>

using namespace std;

int main()
{
    cout<<"Hello World";

    return 0;
}
// O(n) Linear search
void MinMaxValue(vector<int>arr)  {
    int mini = arr[0], maxi = arr[0];
    for(int i=1;i<arr.size();i++)   {
        if(arr[i]<mini) 
          mini = arr[i];
        if(arr[i]>maxi) 
          maxi = arr[i];
    }
    cout<<mini<<" "<<maxi;
}
// TWO POINTER APPROCH
void reverseString(vector<char>& s) {
  int start=0,end=s.size()-1;
  while(start<end)
    swap(s[start++],s[end--]);
}
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;
void merge(int *arr1,int *arr2,int n, int m){
    int i=0,j=0,k=0;
    int maxi=INT_MIN;
    rep(i,0,n) maxi=max(arr1[i],maxi);
    rep(i,0,m) maxi=max(arr2[i],maxi);
    maxi++;
    while(i<n && j<m){
        int x=arr1[i]%maxi;
        int y=arr2[j]%maxi;
        if(x<y){
            if(k<n)  arr1[k]+=x*maxi;
            else  arr2[k-n]+=x*maxi;
            k++;
            i++;
        }
        else{
            if(k<n)  arr1[k]+=y*maxi;
            else arr2[k-n]+=y*maxi;
            k++;
            j++;
        }
    }
    while(i<n){
        int x=arr1[i]%maxi;
        if(k<n) arr1[k]+=x*maxi;
        else arr2[k-n]+=x*maxi;
        k++;
        i++;
    }
    while(j<m){
        int x=arr2[j]%maxi;
        if(k<n) arr1[k]+=x*maxi;
        else  arr2[k-n]+=x*maxi;
        k++;
        j++;
    }
    rep(i,0,n) arr1[i]=arr1[i]/maxi;
    rep(i,0,m) arr2[i]=arr2[i]/maxi;
}
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int n,m;
        cin>>n>>m;
        int *arr1=new int[n];
        int *arr2=new int[m];
        rep(i,0,n) cin>>arr1[i];
        rep(i,0,m) cin>>arr2[i];
        merge(arr1,arr2,n,m);
        rep(i,0,n) cout<<arr1[i]<<" ";
        rep(i,0,m) cout<<arr2[i]<<" ";
        cout<<endl;
    }


return 0;
}
uint64_t rdtsc() {
  uint32_t hi, lo;
  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
 
  return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
 }
#include<iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  cout << "Hello!" << n;
  return 0;
}
class Solution {
public:
    bool isSubsequence(string s, string t) {
        int i = t.length()-1;
        int j = s.length() - 1;
        while(i>=0 & j>=0){
            if(t[i]==s[j]){
                i--;
                j--; 
            }
            else{
                i--;
            }
                       
        }
        if(j==-1){
            return true;
        }
        return false;
    }
};
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;
bool check(pair<ull,ull> timing1,pair<ull,ull> timing2){
    return timing1.first>timing2.first ? false:true;
}
int waiting_time(pair<ull,ull> *timing,ull time,int n){
    int s=0,e=n-1;
    while(s<=e){
        ull mid=(s+e)/2;
        if(timing[mid].first>time){
            if(mid==0 || timing[mid-1].second<=time){
            return timing[mid].first-time;
            }
            e=mid-1;
        }
        else if(timing[mid].first<time){
            if(timing[mid].second>time) return 0;
            s=mid+1;
        }
        else return 0;
    }
    return -1;
}
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int n,m;
        cin>>n>>m;
        pair<ull,ull> *timing=new pair<ull,ull>[n];
        rep(i,0,n) cin>>timing[i].first>>timing[i].second;
        sort(timing,timing+n,check);
        ull *people=new ull[m];
        rep(i,0,m)  {
          cin>>people[i];
          cout<<waiting_time(timing,people[i],n)<<endl;
       }
    }


return 0;
}
int ref = x;
        int y;
        int rev =0;
        if(x<0) return 0;
        if(x==0) return 1;
        if(x>INT_MIN || x<INT_MAX)
        {
            while(x)
        {
            y=x%10;
            x=x/10;
            if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0;
            if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0;
            rev=rev*10+y;
        }
        
        }
        cout <<rev<<"\n";
        if(ref == rev)
        return rev;
        else 
            return 0;
class Solution {
public:
    int reverse(int x) {
        int y;
        int rev =0;
        if(x>INT_MIN || x<INT_MAX)
        {
            while(x)
        {
            y=x%10;
            x=x/10;
            if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0;
            if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0;
            rev=rev*10+y;
        }
        
        }
        return rev;
    }
};
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> I;
        
        int y;
        for (int x=0; x<nums.size(); x++)
        {
            y=0;
            for (int z=x+1; z<nums.size(); z++)
            {
                y=nums[x]+nums[z];
            if(y==target)
            {
                I.push_back(x);
                I.push_back(z);
                break;
            }
            }
               
            
                
        }
        
        return I;
    }
};
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */
 
function reverseBetween(head: ListNode | null, left: number, right: number): ListNode | null {
    
    if (head === null)
        return null;
    
    let currPtr = head, prevPtr = null;
    
    while (left > 1) {
        prevPtr = currPtr;
        currPtr = currPtr.next;
        
        left--;
        right--;
    }
    
    let tailPtr = currPtr, connPtr = prevPtr, thirdPtr: ListNode | null = null;
    
    while (right > 0) {
        thirdPtr = currPtr.next;
        currPtr.next = prevPtr;
        prevPtr = currPtr;
        currPtr = thirdPtr;
        
        right--;
    }
    
    if (connPtr)
        connPtr.next = prevPtr;
    else
        head = prevPtr;
    
    tailPtr.next = currPtr;
    
    return head;
};
#include<iostream>
using namespace std;
bool issafe(int** arr,int x,int y,int n){
    for(int row=0;row<x;row++){
        if(arr[row][y]==1) return false;
    }
    int row=x-1;
    int col=y-1;
    while(row>=0 && col>=0){
        if(arr[row][col]==1)return false;
        row--;
        col--;
    }
     row=x-1;
     col=y+1;
    while(row>=0 && col<n){
        if(arr[row][col]==1)  return false;
        row--;
        col++;
    }
    return true ;
}
bool nqueen(int** arr,int n,int x=0){
    if(x>=n) return true;
    for(int col=0;col<n;col++){
        if(issafe(arr,x,col,n)){
            arr[x][col]=1;
            if(nqueen(arr,n,x+1)) return true;
            arr[x][col]=0;  //backtracking
        }
    }
    return false;
}
int main(){
    int n;
    cin>>n;
    int **arr=new int*[n];
    for(int i=0;i<n;i++){
        arr[i]=new int[n];
        for(int j=0;j<n;j++) arr[i][j]=0;
    }
    if(nqueen(arr,n)){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++) cout<<arr[i][j]<<" ";
            cout<<endl;
        }
    }
    return 0;
}
#include<iostream>
using namespace std;
bool issafe(int** arr,int x,int y,int n){
    for(int row=0;row<=x;row++){
        if(arr[x][y]==1){
            return false;
        }
    }
    int row=x;
    int col=y;
    while(row>=0 && col>=0){
        if(arr[row][col]==1){
            return false;
        }
        row--;
        col--;
    }
     row=x;
     col=y;
    while(row>=0 && col<n){
        if(arr[row][col]==1){
            return false;
        }
        row--;
        col++;
    }
    return true ;
}
bool nqueen(int** arr,int x,int n){
    if(x>=n){
        return true;
    }
    for(int col=0;col<=n;col++){
        if(issafe(arr,x,col,n)){
            arr[x][col]==1;
            if(nqueen(arr,x+1,n)){
                return true;
            }
            arr[x][col]=0;  //backtracking
            
        }
    }
    return false;
}
int main(){
    int n;
    cin>>n;
    int** arr=new int*[n];
    for(int i=0;i<n;i++){
        arr[i]=new int[n];
        for(int j=0;j<n;j++){
            arr[i][j]=0;

        }
    }
    if(nqueen(arr,0,n)){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<arr[i][j]<<"";
            }cout<<endl;
        }
    }


    return 0;
}
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
	int search(vector<int> arr,int n,int x){
		int low=0,high=n-1;
		while(low<=high){
			int mid=low+(high-low)/2;
			if(arr[mid]>x){
				high=mid-1;
			}
			else if(arr[mid]<x){
				low=mid+1;
			}
			else{
				return mid;
			}
		}
		return low;
	}
    vector<int> findClosestElements(vector<int>& arr, int k, int x) {
		vector<int> ans;
		int n=arr.size();
        int i=search(arr,n,x);
		int l=i-1,r=i;
		while(k>0){
			if(l<0 || (r<n && abs(arr[l]-x)>abs(arr[r]-x))){
				r++;
			}
			else{
				l--;
			}
			k--;
		}
		l++;
		while(l<r){
			ans.push_back(arr[l]);
			l++;
		}
		return ans;
    }
};
int main(){
	Solution s;
	vector<int> a={1,2,3,4,5};
	int k=3,x=2;
	vector<int> ans=s.findClosestElements(a,k,x);
	for(auto i:ans){
		cout<<i<<" ";
	}cout<<endl;
	return 0;
}
#include<iostream>
#include<unordered_map>
#include<queue>
#define rep(i,a,b) for(long int i=a;i<b;i++)
#define ull unsigned long long
using namespace std;

int main()
{
    long int a,b,c;
    cin>>a>>b>>c;
    unordered_map<int,int> um;
    // int *array1=new int[a];
    int *array1=new int[a];
    int *array2=new int[b];
    int *array3=new int[c];
    rep(i,0,a) {
        cin>>array1[i];
         um[array1[i]]++;
    }
    rep(i,0,b) {
        cin>>array2[i];
    }
    rep(i,0,c) {
        cin>>array3[i];
    }
    queue<int> output;
    long int count=0;
    long  int i=0,j=0;
    while(i<b && j<c){
        if(array2[i]>array3[j]){
            if(um.find(array3[j])!=um.end()){
                count++;
                output.push(array3[j]);
            } 
                j++;
        }
        else if(array2[i]<array3[j]){
            if(um.find(array2[i])!=um.end()){
                count++;
                output.push(array2[i]);
            } 
                i++;
        }
        else{
            count++;
            output.push(array2[i]);
            i++;
            j++;
        }
    }
    while(i<b){
        if(um.find(array2[i])!=um.end()) {
        count++;
        output.push(array2[i]);
        }
        i++;
    }
    while(j<c){
        if(um.find(array3[j])!=um.end()) {
        count++;
        output.push(array3[j]);
        }
        j++;
    }
    cout<<count<<endl;
   while(!output.empty())
   {
       cout<<output.front()<<endl;
       output.pop();
   }

return 0;
}
// python
def isbright(image, dim=10, thresh=0.5):
    # Resize image to 10x10
    image = cv2.resize(image, (dim, dim))
    # Convert color space to LAB format and extract L channel
    L, A, B = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2LAB))
    # Normalize L channel by dividing all pixel values with maximum pixel value
    L = L/np.max(L)
    # Return True if mean is greater than thresh else False
    return np.mean(L) > thresh

// c++
bool rockface_image_is_bright(cv::Mat img_mat, int dim, float threshold)
{
	// Resize image to 10x10
	cv::resize(img_mat, img_mat, { dim, dim });

	// Convert color space to LAB format and extract L channel
	cv::cvtColor(img_mat, img_mat, cv::COLOR_RGB2Lab);
	cv::Mat labchannel[3];
	cv::split(img_mat, labchannel);

	cv::imshow("L", labchannel[0]);
	cv::waitKey(0);

	// Normalize L channel by dividing all pixel values with maximum pixel value
	cv::Mat L;
	cv::normalize(labchannel[0], L, 0, 1, cv::NORM_MINMAX);

	// Return True if mean is greater than thresh else False
	float brightness = cv::mean(L).val[0];
	std::cout << "brightness: " << brightness << std::endl;
	return brightness > threshold;
}
void reverseStr(string& str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}
 
class Solution
{
    public:
    void merge(int arr[], int l, int m, int r)
    {
         int n1=m-l+1; 
         int n2=r-m;
         // Initialization of temp arrays
         int L[n1],R[n2];
         // Initialization of first subarray
         for(int i=0;i<n1;i++)
         L[i]=arr[l+i];
         // Initialization of second subarray
         for(int j=0;j<n2;j++)
         R[j]=arr[m+1+j];
         int i=0,j=0,k=l;
         //Sorting the array using subarrays
         while(i<n1&&j<n2){
             if(L[i]<R[j]){
                 arr[k]=L[i];
                 i++;
             }
             else {
                 arr[k]=R[j];
                 j++;
             }
             k++;
         }
         //Remaining elements added to the array
         while(i<n1){
             arr[k]=L[i];
             i++;k++;
         }
         while(j<n2){
             arr[k]=R[j];
             j++;k++;
         }
    }
    public:
    void mergeSort(int arr[], int l, int r)
    {
        if(l>=r)
        return; //returns recursively
        int m=l+(r-l)/2;
        mergeSort(arr,l,m);
        mergeSort(arr,m+1,r);
        merge(arr,l,m,r);
    }
};
class Solution
{
    public:
    void insertionSort(int arr[], int n)
    {
        int value,hole;
        for(int i=0;i<n;i++){
            value=arr[i];hole=i;
        while(hole>0&&arr[hole-1]>value){
            arr[hole]=arr[hole-1];
            hole--;
        }
        arr[hole]=value;
        }
    }
};
class Solution
{
    public:
    int select(int arr[], int i)
    {
        int max = arr[0], ind = 0;
    int j;
    for ( j=1; j<=i; j++)
    {
        if (arr[j] > max)
        {
           ind = j;
           max = arr[j];
        }
    }
    return ind;
    }
     
    void selectionSort(int arr[], int n)
    {
       int i, j;
   for (i = n-1; i >=0; i--)      
   {
        int j = select(arr, i);
        swap(&arr[i], &arr[j]);
   }
    }
};
class Solution
{
    public:
    //Function to sort the array using bubble sort algorithm.
    void bubbleSort(int arr[], int n)
    {
      int flag=0;
    for(int k=1;k<=n-1;k++){
        for(int j=0;j<=n-k-1;j++){
            if(arr[j]>arr[j+1]){
                swap(&arr[j],&arr[j+1]);
              flag=1;
            }
        }
      if(flag==0)
        break;
    }
    }
    void swap(int *xp,int *yp){
        int temp=*xp;
        *xp=*yp;
        *yp=temp;
    }
};
class int_ptr_wrapper
{
public:
    int_ptr_wrapper(int value = 0) :
    mInt(new int(value))
    {}

    // note! needs copy-constructor and copy-assignment operator!

    ~int_ptr_wrapper()
    {
        delete mInt;
    }

private:
    int* mInt;
};
class Wrapper
{
 private:
  CLib *lib;

 public:
  Wrapper() { lib = lib_init(); } // Lib initialisieren
  ~Wrapper() { lib_cleanup(&init); } // Lib freigeben

  std::string DoSomething() 
  { 
    char *cstr = lib_get_str(); // String anfordern (malloc!)

    std::string s = str;  // in std::string kopieren

    lib_free_str(cstr); // String freigeben (free)

    return s; // std::string zurückgeben. Alles easy.
  }
};
///LIBRARIES & SPECIFIC PARAMETERS
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <U8g2lib.h>

Adafruit_PWMServoDriver servo = Adafruit_PWMServoDriver(0x40);  //ServoMotor Driver Controller I2C Address
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //OLED Constructor

//- - - - VARIABLES & METHODS - - - -//

#define jky 13              //Joystick button pin
#define emgPin A0           //EMG signal pin
#define emgThreshold 500    //EMG signal detection threshold   

/*----OLED Display & Driver----*/
void u8g2_prepare(void) {
  u8g2.setFontMode(1);              //Enable Transparent Font
  u8g2.setFont(u8g2_font_6x13_tf);  //Set font Width: 6px / Height: 13px
  u8g2.setFontRefHeightExtendedText();    
  u8g2.setFontPosTop();             //Origin Position of Text
  u8g2.setFontDirection(0);         //Font direction 0º
}
//Custom Drawn Symbols
static const unsigned char back[] U8X8_PROGMEM  = {
  0x04, 0x06, 0x7F, 0x86, 0x84, 0x60, };

/*---- Servo Driver Variables ----*/
#define Freq (uint8_t) 50     //Servo working frequency

#define posMin 102
#define posMax 512

//Finger Number Assignation for Servo Control
#define thumb (uint8_t) 0
#define index (uint8_t) 1
#define middle (uint8_t) 2 
#define ring (uint8_t) 3
#define pinky (uint8_t) 4
#define wrist (uint8_t) 5

//Method to map servo position from pulses to degrees
void setServo(uint8_t n_servo, uint8_t angulo){
  int duty;
  duty=map(angulo, 0, 180, posMin, posMax);
  servo.setPWM(n_servo, 0, duty);
}

//Method for EMG signal detection and actuation
void emg(void (*pointer)()){
  if((analogRead(A0))>emgThreshold){
    pointer();    
  }
  else{
    openHand();
  }
}

/*---- Hand Movements Methods ----*/
void closeHand(void){
    setServo(thumb,170);
    setServo(index,170);
    setServo(middle,175);
    setServo(ring,151);
    setServo(pinky,161);
    setServo(wrist,180);
}
void openHand(void){
    setServo(thumb,13);
    setServo(index,10 );
    setServo(middle,13);
    setServo(ring,13);
    setServo(pinky,13);
    setServo(wrist,180);
}
void rock_servo(void){
    setServo(thumb,170);
    setServo(index,13);
    setServo(middle,175);
    setServo(ring,151);
    setServo(pinky,13);
    setServo(wrist,180);
}
void ronaldinho_servo(){
    setServo(thumb,13);
    setServo(index,156);
    setServo(middle,145);
    setServo(ring,151);
    setServo(pinky,13);
    while(analogRead(A0)>emgThreshold){
      setServo(wrist,150);
      delay(400);
      setServo(wrist,180);
      delay(500);
    }
}
void point_servo(void){
    setServo(thumb,170);
    setServo(index,13);
    setServo(middle,145);
    setServo(ring,151);
    setServo(pinky,161);
    setServo(wrist,180);
}
void thumbsUp_servo(void){
    setServo(thumb,13);
    setServo(index,156);
    setServo(middle,145);
    setServo(ring,151);
    setServo(pinky,161);
    setServo(wrist,180);
}

/*---- Joystick Button----*/
#define jkyX A1
#define jkyY A2

uint8_t swbtn_state=0;    // Memory Storage Byte
bool btn_val=0;           // Current state of the button
bool btn_oldVal=1;        // Previous state of the button  

//Joystick Button Method
void btn_Jky(uint8_t x){
  btn_val=digitalRead(jky);   // read pin button
  if (btn_val == LOW && btn_oldVal == HIGH){
      swbtn_state=x;    
      delay(10);   
  }
  btn_oldVal=btn_val;
}

/*- *- *- *- - MENU SYSTEM - -* -* -* -*/
uint8_t M1 = 0; //Memory variable to determine menu state
uint8_t F1 = 0; //Memory variable to determine menu state
uint8_t C1 = 0; //Memory variable to determine menu state

//Mode_options
#define openClose (uint8_t) 1
#define figures (uint8_t)   2
#define custom  (uint8_t)   3

//Figures_options
#define rock (uint8_t)       1
#define ronaldinho (uint8_t) 2
#define point (uint8_t)      3
#define thumbUp (uint8_t)    4
#define goBackF1 (uint8_t)   5

//Custom_options
#define thumb (uint8_t)    1
#define index (uint8_t)    2
#define middle (uint8_t)   3
#define ring (uint8_t)     4
#define pinky (uint8_t)    5
#define wrist (uint8_t)    6
#define goBackC1 (uint8_t) 7

/*---- 1.MODES Menu Methods / All Menu Systems ----*/
/*-- Read Joystic M1 Method --*/
void jkyM1(void){
  if (analogRead(jkyX)<=341 && analogRead(jkyY)>=1010){
    M1 = openClose;
  }
  else if (analogRead(jkyX)>=342 && analogRead(jkyX)<=682 && analogRead(jkyY)>=990){
    M1 = figures;
  }
  else if (analogRead(jkyX)>=683 && analogRead(jkyX)<=1023 && analogRead(jkyY)>=980){
    M1 = custom;
  } 
}

/*---- Modes Screen Methods ----*/
void M1_openClose(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(32, 45, "OPEN/CLOSE");
  
  u8g2.drawBox(8,0,31,31);   //Selected box
  u8g2.drawStr(21,9, "1");   //Selected string
  
  u8g2.drawFrame(47,0,31,31);
  u8g2.drawStr(60,9, "2");
  
  u8g2.drawFrame(86,0,31,31);
  u8g2.drawStr(99,9, "3");
  
  u8g2.sendBuffer();
}
void M1_openClose_in(){
  emg(closeHand); 
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(32, 16, "Squeeze to");
  u8g2.drawStr(32, 32, "CLOSE HAND");
  
  u8g2.sendBuffer();
}
void M1_figures(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(42, 45, "FIGURES");
  
  u8g2.drawFrame(8,0,31,31);   
  u8g2.drawStr(21,9, "1");
  
  u8g2.drawBox(47,0,31,31);   //Selected box
  u8g2.drawStr(60,9, "2");    //Selected string
  
  u8g2.drawFrame(86,0,31,31);
  u8g2.drawStr(99,9, "3");
  
  u8g2.sendBuffer();
}
void M1_custom(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(19, 45, "CUSTOM MOVEMENT");
  
  u8g2.drawFrame(8,0,31,31);   
  u8g2.drawStr(21,9, "1");
  
  u8g2.drawFrame(47,0,31,31);   
  u8g2.drawStr(60,9, "2");
  
  u8g2.drawBox(86,0,31,31);   //Selected box
  u8g2.drawStr(99,9, "3");    //Selected string
  
  u8g2.sendBuffer();
}

//MAIN MENU SYSTEM(MODES) METHOD
void modes_M1(){  
  switch (M1){
    case openClose:
      if(swbtn_state==1){
        M1_openClose_in();
        btn_Jky(0);
      }
      else{
        jkyM1();
        openHand();
        M1_openClose();
        btn_Jky(1);
      }
      break;

    case figures:
      if(swbtn_state==2 || swbtn_state==3){
        figures_F1();
      }
      else{
        jkyM1();
        openHand();
        M1_figures();
        btn_Jky(2);
      }
      break;

    case custom:
      if(swbtn_state==4 || swbtn_state==5){
        custom_C1();
      }
      else{
        jkyM1();
        openHand();
        M1_custom();
        btn_Jky(4);
      }
      break;
  }
}

/*---- 2.FIGURES Menu Methods ----*/
/*-- Read Joystic F1 Method --*/
void jkyF1(void){
  if (analogRead(jkyX)<=150 && analogRead(jkyY)>=1022){
    F1 = rock;
  }
  else if (analogRead(jkyX)>=151 && analogRead(jkyX)<=540 && analogRead(jkyY)>=1022){
    F1 = ronaldinho;
  }
  else if (analogRead(jkyX)>=541 && analogRead(jkyX)<=767 && analogRead(jkyY)>=1022){
    F1 = point;
  }
  else if (analogRead(jkyX)>=768 && analogRead(jkyX)<=1023 && analogRead(jkyY)>=1022){
    F1 = thumbUp;
  }
  else if (analogRead(jkyX)>=400 && analogRead(jkyX)<=1023 && analogRead(jkyY)<=400){
    F1 = goBackF1;
  } 
}

/*---- Figures Screen Methods ----*/
void F1_rock(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(32, 32, "ROCK'N ROLL");
  
  u8g2.drawBox(11,0,17,17);   //Selected box
  u8g2.drawStr(17,2, "1");    //Selected string 
  
  u8g2.drawFrame(39,0,17,17);
  u8g2.drawStr(45,2, "2");
  
  u8g2.drawFrame(67,0,17,17);
  u8g2.drawStr(73,2, "3");
  
  u8g2.drawFrame(95,0,17,17);
  u8g2.drawStr(101,2, "4");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();

}
void F1_rock_in(void){
  emg(rock_servo);
  btn_Jky(2);
  u8g2.clearBuffer();
  
  u8g2.drawStr(32, 16, "Squeeze to");
  u8g2.drawStr(32, 32, "ROCK'N ROLL");
  
  u8g2.sendBuffer();
}
void F1_ronaldinho(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(34, 32, "RONALDINHO");
  
  u8g2.drawFrame(11,0,17,17);
  u8g2.drawStr(17,2, "1");
  
  u8g2.drawBox(39,0,17,17);   //Selected box
  u8g2.drawStr(45,2, "2");    //Selected string
  
  u8g2.drawFrame(67,0,17,17);
  u8g2.drawStr(73,2, "3");
  
  u8g2.drawFrame(95,0,17,17);
  u8g2.drawStr(101,2, "4");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}
void F1_ronaldinho_in(void){
  emg(ronaldinho_servo);
  btn_Jky(2);
  u8g2.clearBuffer();
  
  u8g2.drawStr(32, 32, "RONALDINHO!");
  
  u8g2.sendBuffer();
}
void F1_point(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(49, 32, "POINT");
  
  u8g2.drawFrame(11,0,17,17);
  u8g2.drawStr(17,2, "1");
  
  u8g2.drawFrame(39,0,17,17);     
  u8g2.drawStr(45,2, "2");
  
  u8g2.drawBox(67,0,17,17);   //Selected box
  u8g2.drawStr(73,2, "3");    //Selected string
  
  u8g2.drawFrame(95,0,17,17);
  u8g2.drawStr(101,2, "4");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}
void F1_point_in(void){
  emg(point_servo);
  btn_Jky(2);
  u8g2.clearBuffer();
  
  u8g2.drawStr(32, 16, "Squeeze to");
  u8g2.drawStr(49, 32, "POINT");
  
  u8g2.sendBuffer();
}
void F1_thumbUp(){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(39, 32, "THUMBS UP");
  
  u8g2.drawFrame(11,0,17,17);
  u8g2.drawStr(17,2, "1");
  
  u8g2.drawFrame(39,0,17,17);     
  u8g2.drawStr(45,2, "2");
  
  u8g2.drawFrame(67,0,17,17);     
  u8g2.drawStr(73,2, "3");
  
  u8g2.drawBox(95,0,17,17);     //Selected box
  u8g2.drawStr(101,2, "4");     //Selected string
  
  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}
void F1_thumbUp_in(void){
  emg(thumbsUp_servo);
  btn_Jky(2);
  u8g2.clearBuffer();
  
  u8g2.drawStr(20, 16, "Squeeze to give");
  u8g2.drawStr(32, 30, "a THUMBS UP");
  
  u8g2.sendBuffer();
}
void F1_goBack(void){
  btn_Jky(0);  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(42, 32, "GO BACK");
  
  u8g2.drawFrame(11,0,17,17);
  u8g2.drawStr(17,2, "1");
  
  u8g2.drawFrame(39,0,17,17);     
  u8g2.drawStr(45,2, "2");
  
  u8g2.drawFrame(67,0,17,17);     
  u8g2.drawStr(73,2, "3");
  
  u8g2.drawFrame(95,0,17,17);
  u8g2.drawStr(101,2, "4");    

  u8g2.drawBox(115,51,12,10);   //Selected box
  
  u8g2.setDrawColor(0);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

//MAIN FIGURES METHOD
void figures_F1(){
  switch (F1){
    case rock:
      if(swbtn_state==3){ //s'ha de canviar!!
        F1_rock_in();
      }
      else{
        btn_Jky(3);
        jkyF1();
        F1_rock();  //print on display F1_rock
      }
      break;
    
    case ronaldinho: 
      if(swbtn_state==3){ //s'ha de canviar!!
        F1_ronaldinho_in(); 
      }
      else{
        btn_Jky(3);
        jkyF1();
        F1_ronaldinho(); //print on display F1_ronaldinho
      }
      break;
    
    case point:
      if(swbtn_state==3){ //s'ha de canviar!!
        F1_point_in(); 
      }
      else{
        btn_Jky(3);
        jkyF1();
        F1_point(); //print on display F1_ronaldinho
      }
      break;

     case thumbUp:
      if(swbtn_state==3){ //s'ha de canviar!!
        F1_thumbUp_in(); 
      }
      else{
        btn_Jky(3);
        jkyF1();
        F1_thumbUp(); //print on display F1_ronaldinho
      }
      break;

     case goBackF1:
        jkyF1();
        F1_goBack(); //print on display F1_ronaldinho
      break;
  }
}

/*---- 3.CUSTOM Menu Methods ----*/
/*-- Read Joystic C1 Method --*/
void jkyC1(void){
  if (analogRead(jkyX)<=170 && analogRead(jkyY)>=1023){
    C1 = thumb;
  }
  else if (analogRead(jkyX)>=171 && analogRead(jkyX)<=341 && analogRead(jkyY)>=1023){
    C1 = index;
  }
  else if (analogRead(jkyX)>=342 && analogRead(jkyX)<=511 && analogRead(jkyY)>=1023){
    C1 = middle;
  }
  else if (analogRead(jkyX)>=512 && analogRead(jkyX)<=682 && analogRead(jkyY)>=1023){
    C1 = ring;
  }
  else if (analogRead(jkyX)>=683 && analogRead(jkyX)<=853 && analogRead(jkyY)>=1023){
    C1 = pinky;
  }
  else if (analogRead(jkyX)>=854 && analogRead(jkyX)<=1023 && analogRead(jkyY)>=1023){
    C1 = wrist;
  }
  else if (analogRead(jkyX)>=512 && analogRead(jkyX)<=1023 && analogRead(jkyY)<=450){
    C1 = goBackC1;
  }
}
/*-- Movement State for Individual Fingers Method --*/
uint8_t movement=0;
void jky_servo_movement(void){
    if(analogRead(jkyY)>=600){
        movement=1;
    }
    else if(analogRead(jkyY)<=400){
        movement=2;
    }
    else if(analogRead(jkyY)>=401 && analogRead(jkyY)<=599){
        movement=0;
    }
}

/*---- Custom Screen Methods ----*/
void C1_thumb(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(49, 32, "THUMB");
  
  u8g2.drawBox(2,0,17,17);   //Selected box
  u8g2.drawStr(8,2, "1");    //Selected string
  
  u8g2.drawFrame(23,0,17,17);
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawFrame(44,0,17,17);
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

#define thumbMin 13
#define thumbMax 170
uint8_t thumb_angle=13;
uint8_t thumb_percentage=0;

void C1_thumb_in(void){
    jky_servo_movement();
    btn_Jky(4);
    if(movement==1 && thumb_angle<thumbMax){
        thumb_angle++;
    }
    else if(movement==2 && thumb_angle>thumbMin){
        thumb_angle--;
    }
    setServo(0,thumb_angle);
    thumb_percentage=map(thumb_angle, thumbMin, thumbMax, 0, 100);
    String percentage = String(thumb_percentage);
  
    u8g2.clearBuffer();
    u8g2.setDrawColor(2);
  
    u8g2.drawStr(16, 0, "Adjust Position");

    u8g2.drawStr(12,24, "Thumb:");
    u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
    u8g2.drawStr(82,24, "%");
    
    u8g2.drawFrame(12,40,102,17);
    u8g2.drawBox(13,41,thumb_percentage,15);   //x is percentage of map
    
    u8g2.sendBuffer();
  
}
void C1_index(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(49, 32, "INDEX");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawBox(23,0,17,17);   //Selected box
  u8g2.drawStr(29,2, "2");     //Selected string
  
  u8g2.drawFrame(44,0,17,17);
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);

  u8g2.sendBuffer();
}

#define indexMin 10
#define indexMax 170
uint8_t index_angle=10;
uint8_t index_percentage=0;

void C1_index_in(){
  jky_servo_movement();
  btn_Jky(4);
  if(movement==1 && index_angle<indexMax){
      index_angle++;
  }
  else if(movement==2 && index_angle>indexMin){
      index_angle--;
  }
  setServo(1,index_angle);
  index_percentage=map(index_angle, indexMin, indexMax, 0, 100);
  String percentage = String(index_percentage);
  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(16, 0, "Adjust Position");

  u8g2.drawStr(12,24, "Index:");
  u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
  u8g2.drawStr(82,24, "%");
    
  u8g2.drawFrame(12,40,102,17);
  u8g2.drawBox(13,41,index_percentage,15);   //x is percentage of map
    
  u8g2.sendBuffer();
}
void C1_middle(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(47, 32, "MIDDLE");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawFrame(23,0,17,17);   
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawBox(44,0,17,17);   //Selected box
  u8g2.drawStr(50,2, "3");    //Selected string
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

#define middleMin 13
#define middleMax 175
uint8_t middle_angle=13;
uint8_t middle_percentage=0;

void C1_middle_in(void){
  jky_servo_movement();
  btn_Jky(4);
  if(movement==1 && middle_angle<middleMax){
      middle_angle++;
  }
  else if(movement==2 && middle_angle>middleMin){
      middle_angle--;
  }
  setServo(2,middle_angle);
  middle_percentage=map(middle_angle, middleMin, middleMax, 0, 100);
  String percentage = String(middle_percentage);
  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(16, 0, "Adjust Position");

  u8g2.drawStr(12,24, "Middle:");
  u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
  u8g2.drawStr(82,24, "%");
    
  u8g2.drawFrame(12,40,102,17);
  u8g2.drawBox(13,41,middle_percentage,15);   //x is percentage of map
    
  u8g2.sendBuffer();
}
void C1_ring(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(52, 32, "RING");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawFrame(23,0,17,17);   
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawFrame(44,0,17,17);
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawBox(65,0,17,17);   //Selected box
  u8g2.drawStr(71,2, "4");    //Selected string
  
  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

#define ringMin 13
#define ringMax 151
uint8_t ring_angle=13;
uint8_t ring_percentage=0;

void C1_ring_in(void){
  jky_servo_movement();
  btn_Jky(4);
  if(movement==1 && ring_angle<ringMax){
      ring_angle++;
  }
  else if(movement==2 && ring_angle>ringMin){
      ring_angle--;
  }
  setServo(3,ring_angle);
  ring_percentage=map(ring_angle, ringMin, ringMax, 0, 100);
  String percentage = String(ring_percentage);
  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(16, 0, "Adjust Position");

  u8g2.drawStr(12,24, "Ring:");
  u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
  u8g2.drawStr(82,24, "%");
    
  u8g2.drawFrame(12,40,102,17);
  u8g2.drawBox(13,41,ring_percentage,15);   //x is percentage of map
    
  u8g2.sendBuffer();
}
void C1_pinky(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(49, 32, "PINKY");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawFrame(23,0,17,17);   
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawFrame(44,0,17,17);   
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawBox(86,0,17,17);   //Selected box
  u8g2.drawStr(92,2, "5");    //Selected string

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

#define pinkyMin 13
#define pinkyMax 161
uint8_t pinky_angle=13;
uint8_t pinky_percentage=0;

void C1_pinky_in(void){
  jky_servo_movement();
  btn_Jky(4);
  if(movement==1 && pinky_angle<pinkyMax){
      pinky_angle++;
  }
  else if(movement==2 && pinky_angle>pinkyMin){
      pinky_angle--;
  }
  setServo(4,pinky_angle);
  pinky_percentage=map(pinky_angle, pinkyMin, pinkyMax, 0, 100);
  String percentage = String(pinky_percentage);
  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(16, 0, "Adjust Position");

  u8g2.drawStr(12,24, "Pinky:");
  u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
  u8g2.drawStr(82,24, "%");
    
  u8g2.drawFrame(12,40,102,17);
  u8g2.drawBox(13,41,middle_percentage,15);   //x is percentage of map
    
  u8g2.sendBuffer();
}
void C1_wrist(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(49, 32, "WRIST");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawFrame(23,0,17,17);   
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawFrame(44,0,17,17);   
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawBox(107,0,17,17);    //Selected box
  u8g2.drawStr(113,2, "6");     //Selected string

  u8g2.drawFrame(115,51,12,10);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  
  u8g2.sendBuffer();
}

#define wristMin 180
#define wristMax 150
uint8_t wrist_angle=180;
uint8_t wrist_percentage=0;

void C1_wrist_in(void){
  jky_servo_movement();
  btn_Jky(4);
  if(movement==1 && wrist_angle>wristMax){
      wrist_angle--;
  }
  else if(movement==2 && wrist_angle<wristMin){
      wrist_angle++;
  }
  setServo(5,wrist_angle);
  wrist_percentage=map(wrist_angle, wristMin, wristMax, 0, 100);
  String percentage = String(wrist_percentage);
  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(16, 0, "Adjust Position");

  u8g2.drawStr(12,24, "Wrist:");
  u8g2.drawStr(64,24, percentage.c_str());   //map variable for %
  u8g2.drawStr(82,24, "%");
    
  u8g2.drawFrame(12,40,102,17);
  u8g2.drawBox(13,41,wrist_percentage,15);   //x is percentage of map
    
  u8g2.sendBuffer();
}
void C1_goBack(void){  
  u8g2.clearBuffer();
  u8g2.setDrawColor(2);
  
  u8g2.drawStr(43, 32, "GO BACK");
  
  u8g2.drawFrame(2,0,17,17);   
  u8g2.drawStr(8,2, "1");
  
  u8g2.drawFrame(23,0,17,17);   
  u8g2.drawStr(29,2, "2");
  
  u8g2.drawFrame(44,0,17,17);   
  u8g2.drawStr(50,2, "3");
  
  u8g2.drawFrame(65,0,17,17);
  u8g2.drawStr(71,2, "4");

  u8g2.drawFrame(86,0,17,17);
  u8g2.drawStr(92,2, "5");

  u8g2.drawFrame(107,0,17,17);
  u8g2.drawStr(113,2, "6");
  
  u8g2.drawBox(115,51,12,10);   //Selected box
  
  u8g2.setDrawColor(0);
  u8g2.drawXBMP(117, 53, 8, 6, back);
  u8g2.sendBuffer();
}

//MAIN CUSTOM METHOD
void custom_C1(void){
  switch(C1){
    case thumb:
      if(swbtn_state==5){
        jky_servo_movement();
        C1_thumb_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_thumb();  //print on display F1_rock
      }
      break;
    
    case index:
      if(swbtn_state==5){ //s'ha de canviar!!
        C1_index_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_index();  //print on display F1_rock
      }
      break;
    
    case middle:
      if(swbtn_state==5){ //s'ha de canviar!!
        C1_middle_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_middle();  //print on display F1_rock
      }
      break;

    case ring:
      if(swbtn_state==5){ //s'ha de canviar!!
        C1_ring_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_ring();  //print on display F1_rock
      }
      break;
    
    case pinky:
      if(swbtn_state==5){ //s'ha de canviar!!
        C1_pinky_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_pinky();  //print on display F1_rock
      }
      break;

    case wrist:
      if(swbtn_state==5){ //s'ha de canviar!!
        C1_wrist_in();
      }
      else{
        btn_Jky(5);
        jkyC1();
        C1_wrist();  //print on display F1_rock
      }
      break;

    case goBackC1:
        btn_Jky(0);
        jkyC1();
        C1_goBack();  //print on display F1_rock
      break;
  }
}

void setup(){
  u8g2.begin();
  u8g2_prepare();
  servo.begin();
  servo.setPWMFreq(Freq);
  pinMode(jky, INPUT_PULLUP);
  F1=rock;
  C1=thumb;
  M1=openClose;
  swbtn_state=0;
}

void loop(){ 
  modes_M1();
}
import numpy as np
p = np.array([1/2, 1/2])
ex = np.array([1, 2])
dot_prod = ex @ p
#ifdef __APPLE__
freopen("inputFilename.txt", "r", stdin);
freopen("outputFilename.txt", "w", stdout);
#endif
Part 1:

// Header.h
void func(); // Declares func()
 
// File1.cc
#include "Header.h"
void func() {   // Defines func()
   ...
}
 
// File2.cc
#include "Header.h"
...  // Do something else
func(); // Calls func()
  
  
  
  
  
  
Part 2:

// Header.h
inline void func() { // Defines func()
   ...
}
 
// File2.cc
#include "Header.h"
... // Do something else
... // Code for func()
bool operator<(const Person &other) const {
 if (name == other.name) { 
    return age < other.age;
 } else { 
        return name < other.name; 
    }
} 
 
//This fixes the problem: In template: invalid operands to binary     expression ('const Person' and 'const Person')
std::string test1 = "Baked";
std::string test2 = "Bake";  
bool compare = test1 < test2;
 
// Output: 0
/* Reason: There is no difference until the last letter so then it will compare the last letter with the blank space. 
Since blank space comes first before the letter d, this means that test1 is not less than test2 and that is why it returns false.*/
 
std::string test1 = "Baker";
std::string test2 = "Bdke";  
bool compare = test1 < test2;
 
// Output: 1
/* Reason: There is no difference until the second letter so then it will compare the second letter with the second letter of the other word.
Since the letter a comes first before the letter d, this means that test1 is less than test2 and that is why it returns true.*/
Example:

    people[0] = Person(3, "Bob");
    people[1] = Person(4, "Joe");
    people[2] = Person(5, "Sue");

Example 2:

	people.insert(std::pair <int, Person> (0, Person(3, "Bob")));
	people.insert(std::pair <int, Person> (1, Person(4, "Joe")));
	people.insert(std::pair <int, Person> (2, Person(5, "Sue")));
#include <iostream>

using namespace std;

struct student
{
	int age;
};

int main() {
	student steve;		//variable
	student *ken;		//ken is a pointer.  It points to the memory address which holds the ken struct.

	steve.age = 7;
	ken->age = 9;

	return;
}
#include <iostream>

using namespace std;

int main(){
  	
	cout << "Hello World";
  
  	return 0;
}
std::exception <exception> interface (debatable if you should catch this)
    std::bad_alloc <new> failure to allocate storage
        std::bad_array_new_length <new> invalid array length
    std::bad_cast <typeinfo> execution of an invalid dynamic-cast
    std::bad_exception <exception> signifies an incorrect exception was thrown
    std::bad_function_call <functional> thrown by "null" std::function
    std::bad_typeid <typeinfo> using typeinfo on a null pointer
    std::bad_weak_ptr <memory> constructing a shared_ptr from a bad weak_ptr
    std::logic_error <stdexcept> errors detectable before the program executes
        std::domain_error <stdexcept> parameter outside the valid range
        std::future_error <future> violated a std::promise/std::future condition
        std::invalid_argument <stdexcept> invalid argument
        std::length_error <stdexcept> length exceeds its maximum allowable size
        std::out_of_range <stdexcept> argument value not in its expected range
    std::runtime_error <stdexcept> errors detectable when the program executes
        std::overflow_error <stdexcept> arithmetic overflow error.
        std::underflow_error <stdexcept> arithmetic underflow error.
        std::range_error <stdexcept> range errors in internal computations
        std::regex_error <regex> errors from the regular expression library.
        std::system_error <system_error> from operating system or other C API
            std::ios_base::failure <ios> Input or output error
 int gcdYisLargerThanX(int x, int y)
{
  return x==0 ? y : gcd(y%x, x);
}
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop
	// any integer can be expressed as (6k + i), where i = -1, 0, 1, 2, 3, 4
	// (6k + 0), (6k + 2), (6k + 4) covered by n%2
	// (6k + 3) covered by n%3
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
	
	// Check for 6K + 1 and 6K - 1
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
 
    return true; 
}
int maxSubArray(vector<int>& nums) {
        int maxSum = nums[0], currSum = nums[0];
        
        for(int i=1; i < nums.size(); i++)
        {
            currSum += nums[i];
            if(nums[i] > currSum) currSum = nums[i];
            maxSum = (currSum > maxSum) ? currSum : maxSum;
        }
        return maxSum;
    }
int maxProduct(vector<int>& nums) {
        int32_t res=nums[0];
        
        for(int32_t i=1, min=res, max = res; i < nums.size(); i++)
        {
            if(nums[i] < 0)
                swap(min, max);
            max = std::max(nums[i] * max, nums[i]);
            min = std::min(nums[i] * min, nums[i]);
            res = std::max(res, max);
        }
        return res;
    }
#include<bits/stdc++.h>

using namespace std;
//Implement the class Box  
//l,b,h are integers representing the dimensions of the box

// The class should have the following functions : 

// Constructors: 
// Box();
// Box(int,int,int);
// Box(Box);


// int getLength(); // Return box's length
// int getBreadth (); // Return box's breadth
// int getHeight ();  //Return box's height
// long long CalculateVolume(); // Return the volume of the box

//Overload operator < as specified
//bool operator<(Box& b)

//Overload operator << as specified
//ostream& operator<<(ostream& out, Box& B)
class Box {
    private:
        int length;
        int breadth;
        int height;
    
    public:
        Box() {
            this->length = 0;
            this->breadth = 0;
            this->height = 0;
        }
        
        Box(int l, int b, int h) {
            this->length = l;
            this->breadth = b;
            this->height = h;
        }
};


void check2()
{
	int n;
	cin>>n;
	Box temp;
	for(int i=0;i<n;i++)
	{
		int type;
		cin>>type;
		if(type ==1)
		{
			cout<<temp<<endl;
		}
		if(type == 2)
		{
			int l,b,h;
			cin>>l>>b>>h;
			Box NewBox(l,b,h);
			temp=NewBox;
			cout<<temp<<endl;
		}
		if(type==3)
		{
			int l,b,h;
			cin>>l>>b>>h;
			Box NewBox(l,b,h);
			if(NewBox<temp)
			{
				cout<<"Lesser\n";
			}
			else
			{
				cout<<"Greater\n";
			}
		}
		if(type==4)
		{
			cout<<temp.CalculateVolume()<<endl;
		}
		if(type==5)
		{
			Box NewBox(temp);
			cout<<NewBox<<endl;
		}

	}
}

int main()
{
	check2();
}
int main(){
		// Initialization of list
	    std::list<int> demo_list;

	    // Assigning the value 100, 5 times
	    // to the list, list_demo.
	    demo_list.assign(5, 100);

	    // Displaying the list
	    for (int itr : demo_list) {
	        std::cout << itr << " ";
	    }

	    return 0;
	}
#pragma once
#ifndef MYVEC_H
#define MYVEC_H
#include <iostream>
#include<algorithm>

template <typename T>
class Myvec
{
public:
	Myvec();
	Myvec(int& size);
	Myvec(int& size, T& value);
	~Myvec();
	void push_back(T& value);
	void pop();
	unsigned int get_size()const;
	T at(int& index)const;
	bool empty()const;
	void clear();
	void swap(Myvec& v);
	void print();
private:
	T* elements;
	int size;
	int capacity;
	void ensureCapacity();
};
template<typename T>
Myvec<T>::Myvec():size(0),capacity(16)
{
	elements = new T[capacity];
}
template<typename T>
Myvec<T>::Myvec(int& size)
{
	size = size;
}
template<typename T>
Myvec<T>::Myvec(int& size, T& vlaue)
{
	size = size;
	elements[0] = vlaue;
}
template<typename T>
Myvec<T>::~Myvec()
{
	delete[] elements;
}
template<typename T>
void Myvec<T>::push_back(T& value)
{
	ensureCapacity();
	elements[size++] = value;
}
template < typename T>
void Myvec<T>::ensureCapacity()
{
	if (size >= capacity)
	{
		T* old = elements;
		capacity = 2 * size;
		elements = new T[size * 2];

		for (int i = 0; i < size; i++)
			elements[i] = old[i];

		delete[] old;
	}
}
template <typename T>
void Myvec<T>::pop()
{
	--size;
}
template <typename T>
unsigned int Myvec<T>::get_size()const
{
	return size;
}
template <typename T >
T Myvec<T>::at(int& index)const
{
	if(index < size)
		return elements[index];
}
template <typename T>
bool Myvec<T>::empty()const
{
	return size == 0;
}
template <typename T>
void Myvec<T>::clear()
{
	size = 0;
}
template <typename T>
void Myvec<T>::swap(Myvec& v)
{
	
	T* temp = new T[size];
	int s = this->size;
	for (int i = 0; i < s; i++)
	{
		temp[i] =this->elements[i];
	}
	
	this->clear();
	for (int i = 0; i < v.get_size(); i++)
	{
		this->push_back(v.elements[i]);
	}
	v.clear();
	for (int i = 0; i < s; i++)
	{
		v.push_back(temp[i]);
	}
	

	delete[]temp;
}
template<typename T>
void Myvec<T>::print()
{
	for (int i = 0; i < size; i++)
	{
		std::cout << this->at(i)<<" ";
	}
	std::cout << std::endl;
}
#endif // !MYVEC_H


#include <iostream>
#include <vector>
#include <string>
#include"Stack.h"
#include<algorithm>
#include "Myvec.h"

using namespace std;



int main()
{
	Myvec<int> v1;
	Myvec<int> v2;
	for (int i = 1; i < 50; i++)
	{
		v2.push_back(i);
	}
	for (int i = 0; i < 20; i++)
	{
		v1.push_back(i);
	}
	

	v1.print();
	cout << endl;
}
#include <iostream>
#include <string>
using namespace std;
#define ll long long



int main()
{
	srand(time(0));
	const int SIZE = 10;
	string words[SIZE] = { "skinny","skinny","three","arrange",
	"discussion", "squeeze" ,"flowers","credit","matter","visit"};
	int random = rand() % SIZE;
	string s = words[random];
	string astrid_word("");
	
		astrid_word = s;
		for (int i = 0; i < astrid_word.length(); i++)
		{
			astrid_word[i] = '*';
		}
		char guess;
		int tries = 1;
		bool youWin = false;
		int miss = 0;
		while ( tries <= 20)
		{
			int flag = 0;
			cout << tries<<" enter your guess " << astrid_word<<" ";
			cin >> guess;
			for (int i = 0; i < astrid_word.length(); i++)
					{
				if (s.at(i) == guess)
				{
					if (s.at(i) == astrid_word.at(i))
					{
					cout <<"   "<< guess << " is already in the word\n";
					}
					else
					{
						astrid_word.at(i) = guess;
						flag = 1;
					}
				}
			}
			if (flag == 0)
				miss++;
			if (astrid_word == s)
			{
				youWin = true;
				cout << "the word is " << astrid_word<<endl;
				break;
			}
			tries++;
		}
		if (youWin == true)
		{
			cout << " -------------------------------- \n";
			cout << "|                                |\n";
			cout << "|                                |\n";
			cout << "|   (:CONGRATULATIONS YOU WIN(:  |\n";
			cout << "|                                |\n";
			cout << "|                                |\n";
			cout << " -------------------------------- \n";
			cout << "you tried " << tries << " times \n";
			cout << "you miss " << miss << " time\n";

		}
		else
		{
			cout << "the word is " << s << "): you loose ):";
		}
		
		
	
}




#include <iostream>

#include <string>
using namespace std;
#define ll long long



int intOfEnd(string& s)
{
	int start = s.find("ATG");
	int end1 = s.find("TAG", start);
	int end2 = s.find("TAA", start);
	int end3 = s.find("TGA", start);

	int list[3] = { end1,end2,end3 };
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (list[i] < list[j] && list[i] != string::npos)
				return list[i];
		}
	}
	
	for (int i = 0; i < 3; i++)
	{
		if (list[i] != string::npos)
			return list[i];
	}
	return 0;
	

}
int main()
{
	string s;
	cin >> s;
	
	
	string ans("");
	int l = 0;
	
	for (int j = 0; j < s.length(); j++)
	{
			int start = s.find("ATG");
			if ((start != string::npos && intOfEnd(s) != 0))
			{
				for (int i = start + 3; i < intOfEnd(s); i++)
				{
					ans += s[i];
				}
				cout << "gene "<<ans << endl;

				s.erase(start, 6);
				ans.clear();
				l++;
			}
			
	}
	if (l == 0)
		cout << "no gene found ";
}




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
#include <vector>

using namespace std;

bool  isConsecutiveFour(char grid[][7]) {

    // checking rows
    for (int i = 0; i < 6; i++)
    {
        char current = grid[i][0];
        int rowCnsec = 0;
        for (int j = 0; j < 7; j++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                rowCnsec++;
                if (rowCnsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                rowCnsec = 1;
            }
        }
    }
    // check columns
    for (int j = 0; j < 7; j++)
    {
        char current = grid[0][j];
        int colConsec = 0;
        for (int i = 0; i < 6; i++)
        {
            if (current == grid[i][j] && grid[i][j] != ' ')
            {
                colConsec++;
                if (colConsec == 4) return true;
            }
            else
            {
                current = grid[i][j];
                colConsec = 1;
            }
        }
    }

    // check top Left side: going upright
    for (int i = 5; i >= 0 ; i--)
    {
        int consecutive = 0;
        int y = i;
        int x = 0;
        char current = grid[y][x];
        while (y >= 0)
        {
            if (grid[y][x] == current && grid[y][x] != ' ')
            {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else
            {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }
    // check bottom right side: going upright
    for (int j = 0; j < 7; j++) {
        int y = 6 - 1;
        int x = j;
        int consecutive = 0;
        int current = grid[y][x];

        while (x < 6 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x++;
            y--;
        }

    }

    // check bottom left side going up-left
    for (int j = 7 - 1; j > 0; j--) {

        int x = j;
        int y = 6 - 1;
        int current = grid[y][x];
        int consecutiveCount = 0;

        while (x >= 0 && y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                consecutiveCount = 1;
                current = grid[y][x];
            }

            x--;
            y--;
        }
    }
    // check bottom right side going up-left
    for (int row = 1; row < 6; row++) {
        int x = 7 - 1;
        int y = row;
        int consecutive = 0;
        int current = grid[y][x];

        while (y >= 0) {

            if (grid[y][x] == current && grid[y][x] != ' ') {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = grid[y][x];
            }
            x--;
            y--;
        }
    }
    return false;
}
// a function to show the grid
void show_grid(char grid[][7])
{
   
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            cout << "|" << grid[i][j];
        }
        cout << "|" << endl;
    }
}

void player1(char grid[][7], int x, int y)
{
    show_grid(grid);
    
    cout << "Drop a red disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'R';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'R';
    }
}

void player2(char grid[][7],int x,int y)
{
    show_grid(grid);

    cout << "Drop a yellow disk at column (0–6): ";
    cin >> y;
    if (grid[x][y] == ' ')
        grid[x][y] = 'Y';
    else {
        //make sure not to target the same row
        while (grid[x][y] != ' ')x--;
        grid[x][y] = 'Y';
    }
       
}
//check if it's a draw
bool is_draw(char grid[][7])
{
    for (int i = 0; i < 7; i++)
    {
      int count{0};
        if (grid[0][i] != ' ' && grid[1][i] != ' ' && grid[2][i] != ' '
            && grid[3][i] != ' ' && grid[4][i] != ' ' && grid[5][i] != ' ')
            count++;
      if(count == 6)
        return true;
        return false;
    }
}
int main()
{
	char grid[6][7];	
    //fill the grid with blank space
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            grid[i][j] = ' ';
        }
    }
    //to check the winner
    bool winner1 = false;
    bool winner2 = false;

    while (!is_draw(grid))
    {
        int x{ 5 };
        int y{ 0 };
        player1(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner1 = true;
            break;
        }
        player2(grid, x, y);
        if (isConsecutiveFour(grid))
        {
            winner2 = true;
            break;
        }
    }
    show_grid(grid);
    if (winner1 == true)
        cout << "player 1 wins ";
    else if (winner2 == true)
        cout << "player 2 wins ";
    else
        cout << "It's a draw ";

    
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


bool  isConsecutiveFour(int values[][7]) {

    // checking rows
    for (int i = 0; i < 6; i++) {
       
        int current = values[i][0];
        int consecutiveCount = 0; // values[i][0] starts count

        for (int j = 0; j < 7; j++) {
            
            if (values[i][j] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                current = values[i][j];
                consecutiveCount = 1;
            }
        }
    }
    // check columns
    for (int j = 0; j < 7; j++) {
        
        int consecutiveCount = 0; // values[0][j] starts count
        int current = values[0][j];

        for (int i = 0; i < 6; i++) {

            if (values[i][j] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                current = values[i][j];
                consecutiveCount = 1;
            }

        }
    }

    // check topLeft side: going upright
    for (int i = 6 - 1; i > 0; i--) {
        int y = i;
        int x = 0;
        int consecutive = 0;
        int current = values[y][x];

        while (y >= 0) {
           
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x++;
            y--;
        }
    }

    // check bottom right side: going upright
    for (int j = 0; j < 7; j++) {
        int y = 6 - 1;
        int x = j;
        int consecutive = 0;
        int current = values[y][x];

        while (x < 6 && y >= 0) {
            
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x++;
            y--;
        }

    }

    // check bottom left side going up-left
    for (int j = 7 - 1; j > 0; j--) {

        int x = j;
        int y = 6 - 1;
        int current = values[y][x];
        int consecutiveCount = 0;

        while (x >= 0 && y >= 0) {

            if (values[y][x] == current) {
                consecutiveCount++;
                if (consecutiveCount == 4) return true;
            }
            else {
                consecutiveCount = 1;
                current = values[y][x];
            }

            x--;
            y--;
        }
    }
    // check bottom right side going up-left
    for (int row = 1; row < 6; row++) {
        int x = 7 - 1;
        int y = row;
        int consecutive = 0;
        int current = values[y][x];

        while (y >= 0) {
            
            if (values[y][x] == current) {
                consecutive++;
                if (consecutive == 4) return true;
            }
            else {
                consecutive = 1;
                current = values[y][x];
            }
            x--;
            y--;
        }

    }
    return false;
}






// Driver code
int main()
{
    int m[6][7];
    for (int i = 0; i < 6; i++)
        for (int j = 0; j < 7; j++)
            cin >> m[i][j];
    if (isConsecutiveFour(m) == true)
        cout << "true";
    else 
        cout << "false";
  
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;




void decToBinary(int n)
{
    // array to store binary number 
    int binaryNum[3][3];
    
    //converting to binary 
    for (int i = 0; i < 3; i++) 
    {
        for (int j = 0; j < 3; j++)
        {
            binaryNum[i][j] = n % 2;
            n = n / 2;

        }
     }       

    // printing binary> array in reverse order 
    for (int i = 3-1; i >= 0; i--){
        for (int j = 3 - 1; j >= 0; j--)
        {
            if (binaryNum[i][j] == 0)
                cout << "H" << " ";
            else
                cout << "T" << " ";
        }
        cout << endl;
    }
    
 }

int main()
{
    int n;
    cout << "Enter a decimal number between 1 and 512 ";
    cin >> n;

    decToBinary(n);
    return 0;
}



//(Financial application: compute tax) Rewrite Listing 3.3, ComputeTax.cpp,
//using arrays. For each filing status, there are six tax rates. Each rate is applied
//to a certain amount of taxable income. For example, from the taxable income
//of $400,000 for a single filer, $8,350 is taxed at 10%, (33,950–8,350) at 15%,
//(82,250–33,950) at 25%, (171,550–82,550) at 28%, (372,550–82,250) at
//33%, and (400,000–372,950) at 36%. The six rates are the same for all filing
//statuses, which can be represented in the following array:
//double rates[] = {0.10, 0.15, 0.25, 0.28, 0.33, 0.36};
//The brackets for each rate for all the filing statuses can be represented in a twodimensional array as follows:
//i//nt brackets[4][5] =
//{
// {8350, 33950, 82250, 171550, 372950}, // Single filer
// //{16700, 67900, 137050, 20885, 372950}, // Married jointly
 // or qualifying
 // widow(er)
// {8350, 33950, 68525, 104425, 186475}, // Married separately
// {11950, 45500, 117450, 190200, 372950} // Head of household
//};
//Suppose the taxable income is $400,000 for single filers. The tax can be computed
//as follows:
//tax = brackets[0][0] * rates[0] +
// (brackets[0][1] – brackets[0][0]) * rates[1] +
 //(brackets[0][2] – brackets[0][1]) * rates[2] +
// (brackets[0][3] – brackets[0][2]) * rates[3] +
// (brackets[0][4] – brackets[0][3]) * rates[4] +
// (400000 – brackets[0][4]) * rates[5]


#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

double computeTax(int brackets[][5], double rates[],
    int status, double income);
int getStatus();


// Driver code
int main()
{
    double rates[] = { 0.10, 0.15, 0.25, 0.28, 0.33, 0.36 };

    int brackets[4][5] =
    {
     {8350, 33950, 82250, 171550, 372950}, // Single filer
     {16700, 67900, 137050, 20885, 372950}, // Married jointly
     // or qualifying
     // widow(er)
     {8350, 33950, 68525, 104425, 186475}, // Married separately
     {11950, 45500, 117450, 190200, 372950} // Head of household
    };
    
     cout << "(1-single filer, 2-married jointly, "
         << "or qualifying widow(er), " << endl
         << "3-married separately, 4-head of household)" << endl
         << "Enter the filing status: ";
     int status = getStatus();
 cout<< "Enter the taxable income: ";
 double income;
 cin >> income;
    cout << "The tax for your income " << income << " is " << computeTax(brackets, rates, status, income);
}

double computeTax(int brackets[][5], double rates[],
    int status, double income) {
    double tax = 0, incomeTaxed = 0;
    for (int i = 4; i >= 0; i--) {
        if (income > brackets[status][i])
            tax += (incomeTaxed = income - brackets[status][i]) * rates[i + 1];
        income -= incomeTaxed;
    }
    return tax += brackets[status][0] * rates[0];
}
int getStatus() {
   
    int status;
    do {
        cin >> status;
        if (status < 0 || status > 3)
            cout<<"Error: invalid status";
    } while (status < 0 || status > 3);
    return status;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


void sortRowWise(int m[][4],
    int r, int c)
{
    // loop for rows of matrix
    for (int i = 0; i < r; i++)
    {
        // loop for column of matrix
        for (int j = 0; j < c; j++)
        {
            // loop for comparison and swapping
            for (int k = 0; k < c - j - 1; k++)
            {
                if (m[i][k] > m[i][k + 1])
                {
                    // swapping of elements
                    swap(m[i][k], m[i][k + 1]);
                }
            }
        }
    }

    // printing the sorted matrix
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
            cout << m[i][j] << " ";
        cout << endl;
    }
}

// Driver code
int main()
{
    int m[4][4];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            cin >> m[i][j];
        }
    }
    int r = sizeof(m[0]) / sizeof(m[0][0]);
    int c = sizeof(m) / sizeof(m[0]);
    sortRowWise(m, r, c);
    return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);
int bin2Dec(int binNumber);
int dec2octal(const string& number);



void readASolution(int grid[][9]);
 bool isValid(const int grid[][9]);
 bool isValid(int i, int j, const int grid[][9]);

 int main()
{
	 // Read a Sudoku puzzle
		 int grid[9][9];
	 readASolution(grid);
	
		 cout << (isValid(grid) ? "Valid solution" : "Invalid solution");
	
		 return 0;
		 system("pause");
 }

 // Read a Sudoku puzzle from the keyboard
 void readASolution(int grid[][9])
 {
	 cout << "Enter a Sudoku puzzle:" << endl;
	 for (int i = 0; i < 9; i++)
		 for (int j = 0; j < 9; j++)
		 cin >> grid[i][j];
 }
 bool isValid(const int grid[][9])
	 {
	  for (int i = 0; i < 9; i++) 
		  for (int j = 0; j < 9; j++)
		  if (grid[i][j] < 1 || grid[i][j] > 9 ||
			  !isValid(i, j, grid))
		  return false;
	 
		  return true; // The fixed cells are valid
 }
 
	  // Check whether grid[i][j] is valid in the grid
 bool isValid(int i, int j, const int grid[][9])
 {
	 // Check whether grid[i][j] is valid at the i's row
	 for (int column = 0; column < 9; column++)
		 if (column != j && grid[i][column] == grid[i][j])
			 return false;

	 // Check whether grid[i][j] is valid at the j's column
	 for (int row = 0; row < 9; row++)
		 if (row != i && grid[row][j] == grid[i][j])
			 return false;

	 // Check whether grid[i][j] is valid in the 3-by-3 box
	 for (int row = (i / 3) * 3; row < (i / 3) * 3 + 3; row++)
		 for (int col = (j / 3) * 3; col < (j / 3) * 3 + 3; col++)
			 if (row != i && col != j && grid[row][col] == grid[i][j])
				 return false;

	 return true; // The current value at grid[i][j] is valid
 }
USTRUCT()
struct FMapRow {
	GENERATED_BODY()

		UPROPERTY()
		TArray<int8> Columns;

	FORCEINLINE int8& operator[] (int32 j)
	{
		return Columns[j];
	}

	void SetGridBase(int8 Block, int32 y)
	{
		Columns[y] = Block;
	}

	void AddNewColumn()
	{
		Columns.Add(0);
	}

	FMapRow()
	{

	}
};

USTRUCT() 
struct FMapLayer {
	GENERATED_BODY()

		UPROPERTY()
		TArray<FMapRow> Rows;

	FORCEINLINE FMapRow& operator[] (int32 i)
	{
		return Rows[i];
	}

	void AddNewRow()
	{
		Rows.Add(FMapRow());
	}

	void AddUninitialized(const int32 RowCount, const int32 ColCount)
	{
		Clear();
		//Add Rows
		for (int32 v = 0; v < RowCount; v++)
		{
			AddNewRow();
		}

		//Add Columns
		for (int32 v = 0; v < RowCount; v++)
		{
			for (int32 b = 0; b < ColCount; b++)
			{
				Rows[v].AddNewColumn();
			}
		}
	}

	void Clear()
	{
		if (Rows.Num() <= 0) return;
		//~~~~~~~~~~~~~~~

		//Destroy any Actors
		const int32 RowTotal = Rows.Num();
		const int32 ColTotal = Rows[0].Columns.Num();

		//Empty
		for (int32 v = 0; v < Rows.Num(); v++)
		{
			Rows[v].Columns.Empty();
		}
		Rows.Empty();
	}

	TTuple<int32, int32> NumLayerDimensions()
	{
		return TTuple<int32, int32>(Rows.Num(), Rows[0].Columns.Num());
	}

	//default properties
	FMapLayer()
	{

	}

	FMapLayer(int32 Rows, int32 Cols) 
	{
		AddUninitialized(Rows, Cols);
	}
};

USTRUCT()
struct FMapSector {
	GENERATED_BODY()

	UPROPERTY()
	TArray<FMapLayer> Layers;

	FORCEINLINE FMapLayer& operator[] (int32 i)
	{
		return Layers[i];
	}

	void AddNewLayer()
	{
		Layers.Add(FMapLayer());
	}

	void AddUnitialized(int32 LayerCount, int32 RowCount, int32 ColCount)
	{
		Clear();
		// Add Layers
		for (int32 l = 0; l < LayerCount; l++)
		{
			AddNewLayer();
		}

		// Add Rows
		for (int32 l = 0; l < LayerCount; l++)
		{
			for (int32 r = 0; r < RowCount; r++)
			{
				Layers[l].AddNewRow();
			}
		}

		// Add Rows
		for (int32 l = 0; l < LayerCount; l++)
		{
			for (int32 r = 0; r < RowCount; r++)
			{
				for (int32 c = 0; c < ColCount; c++)
				{
					Layers[l].Rows[r].AddNewColumn();
				}
			}
		}
	}

	void Clear()
	{
		if (Layers.Num() <= 0) return;
		//~~~~~~~~~~~~~~~

		//Destroy any Actors
		const int32 LayerTotal = Layers.Num();
		const int32 RowTotal = Layers[0].Rows.Num();
		const int32 ColTotal = Layers[0].Rows[0].Columns.Num();


		//Empty
		for (int32 l = 0; l < LayerTotal; l++)
		{
			for (int32 r = 0; r < RowTotal; r++)
			{
				Layers[l].Rows[r].Columns.Empty();
			}
		}
		for (int32 l = 0; l < LayerTotal; l++)
		{
			Layers[l].Rows.Empty();
		}

		Layers.Empty();
	}

	FMapSector()
	{
		AddUnitialized(3, 3, 3);
	}

	FMapSector(int32 size)
	{
		AddUnitialized(size, size, size);
	}

	FMapSector(int32 Layers, int32 Rows, int32 Cols)
	{
		AddUnitialized(Layers, Rows, Cols);
	}
};
#include <iostream>
#include<iomanip>
#include <string>

using namespace std;

void partisons(int list[], int listSize);


int main() 
{
	const int size1 = 6;
	
	
	int list1[size1];
	for (int i = 0; i <size1 ; i++)
	{
		cin >> list1[i];
	}
	 selectionSort(list1, size1);

	
	for (int i = 0; i < size1; i++)
	{
		cout << list1[i] << " ";
	}

	
}

void partisons(int list[], int listSize)
{
    int first = 0;
    int low = first + 1;
    int high = listSize - 1;
    int pivot = list[first];

    while (high > low) {

        while (low <= high && list[low] <= pivot)
        {
            low++;
        }
        while (low <= high && list[high] > pivot)
        {
            high--;
        }
        if (high > low) {
            int temp = list[high];
            list[high] = list[low];
            list[low] = temp;
        }
    }

    while (high >= low && list[high] >= pivot) high--;

    if (high > first) {
        int temp = list[high];
        list[high] = list[first];
        list[first] = temp;
        
    }
    
	 }
	
	


#include<iostream>
using namespace std;

int sum(int arr[], int a);

int main() {
    int arr[1000], n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        cout << sum(arr, n);
    }
}
int sum(int arr[], int a) {
    int i;
    sum = 0;
    for (i=0; i<n; ++i) {
        sum += arr[i];
    }
    return sum;
}#include<iostream>
using namespace std;

int sum(int arr[], int a);

int main() {
    int arr[1000], n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        cout << sum(arr, n);
    }
}
int sum(int arr[], int a) {
    int i;
    sum = 0;
    for (i=0; i<n; ++i) {
        sum += arr[i];
    }
    return sum;
}
"For Loop": {
    "prefix": "for",
    "body": [
        "for (var ${index} = 0; ${index} < ${array}.length; ${index}++) {",
        "\tvar ${element} = ${array}[${index}];",
        "\t$0",
        "}"
    ],
    "description": "For Loop"
},
#include <iostream>
#include<iomanip>

using namespace std;
void eightQueens(char board[], int size);
void shuffle(char list[], int size);
int linearSearch(char list[], char key, int arraySize);
int linearSearchInt(int list[], int key, int arraySize);




const int SIZE = 8;
int main()
{	char board[SIZE];

	srand(unsigned( time(0)));
	int x = rand()%SIZE;
	for (int i = 0; i < SIZE; i++)
	{
		if (i == x)
			board[i] = 'Q';
		else
			board[i] = ' ';
	}
		eightQueens(board, SIZE);
}
void eightQueens(char board[],int size)
{
	int count = 0, vale, test[SIZE];
	for (int i = 0; i < size ; i++)
	{
		 vale = linearSearch(board, 'Q', size);
		 bool flage = true;
		 
		for (int j = 0; j < count;j++)
		{
			if (test[j] == vale)
				flage = false;
		}
		if (flage == true)
		{
			for (int j = 0; j < size; j++)
			{
				cout  << "|";
				cout << board[j];
			}
			test[count] = vale;
			count++;
			shuffle(board, size);
		}
		else
		{
			int n = 0;
			for (int j = 0; j < 100; j++)
			{
				shuffle(board, size);
				if (linearSearchInt(test, linearSearch(board, 'Q', size), size) == -1)
				{
					n = linearSearch(board, 'Q', size);
					test[count] = n;
					count++;
					break;
				}
			}
			for (int j = 0; j < SIZE; j++)
			{
				if (j == n)
					board[j] = 'Q';
				else
					board[j] = ' ';
			}
			for (int j = 0; j < size; j++)
			{
				cout << "|";
				cout << board[j] ;
			}
			

		}
		cout <<'|'<< endl;
	}
	
}

int linearSearch( char list[], char key, int arraySize)
{
	for (int i = 0; i < arraySize; i++)
	{
			if (key == list[i])
				return i;
	}
	return -1;
}
int linearSearchInt(int list[], int key, int arraySize)
{
	for (int i = 0; i < arraySize; i++)
	{
		if (key == list[i])
			return i;
	}
	return -1;
}
void shuffle(char list[], int size)
{
	
	for (int i = size - 1; i > 0; i--)
	{
		// Generate an index j randomly with 0 <= j <=i
		int j = rand() % (i + 1);
		// Swap myList[i] with myList[j]
		char temp = list[i];
		list[i] = list[j];
			list[j] = temp;
	}
}



	
	


 int list[LIMIT], i, j, val, count, flag, test[LIMIT], c = 0;
    //enter the values
    for (i = 0; i < LIMIT; i++)
    {
        cout << "Enter The Elements : ";
        cin >> list[i];
        if (list[i] == 0)
            break;
    }
    //count the occurence of each value
    for (j = 0; j < LIMIT; j++)
    {
        count = 0;
        flag = 1;
        val = list[j];
        //counts each value's occurence and if the value is 0 break
        for (i = 0; i < LIMIT; i++)
        {
            if (val == list[i])
                count++;
            else if (list[i] == 0)
                break;
        }
        //checks whether the value has been already counted (flag = 0) or not (flag stays 1)
        for (i = 0; i < c; i++)
        {
            if (test[i] == val)
                flag = 0;
        }
        //if the value has not been counted print 
        if (flag == 1)
        {

            cout << "The Occurence Of The Number " << val << " is " << count << endl;
            test[c] = val;
            c++;
        }

    }
#include<iostream>
#include <fstream>
#include <cctype>
#include<ctffunc.h>
using namespace std;

void enterLetters(char list[], int limit);
void countVandCLetters(char list[], int limit);



const int LIMIT = 100;


int main()
{
	char letters[LIMIT];

	enterLetters(letters, LIMIT);
	countVandCLetters(letters, LIMIT);
    
}
void enterLetters(char list[], int limit)
{
	
	for (int i = 0; i < limit; i++)
	{
		cin >> list[i];
		if (list[i] == '0')
			break;
	}
}
void countVandCLetters(char list[], int limit)
{
	int vowel = 0;
	int Consonant = 0;
	char vowels[] = { 'a','e','o','u','i' };
	char Consonants[] = { 'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z' };
	
	for (int i = 0; i < limit; i++)
	{
		if (IsCharUpperA(list[i]))
			list[i] = list[i] + 32;
		
		for (int j = 0; j < 5; j++)
		{
			if (list[i] == vowels[j])
				vowel++;
		}
		for (int j = 0; j < 21; j++)
		{
			
			if (list[i] == Consonants[j])
				Consonant++;
		}
		
		
	}
	
		cout << "Number Of vowels Letters is " << vowel << endl;
		cout << "Number Of Consonants Letters is " << Consonant << endl;
	
}
 
#include<iostream>
#include <fstream>
using namespace std;
void selectionSort(double list[], int listSize);
int main()
{
    double list[] = { 3.4, 5, 3, 3.5, 2.2, 1.9, 2 };

    selectionSort(list, 7);
    for (int i = 0; i < 7; i++)
    {
        cout << list[i]<<" ";
    }
}
//decreasing order
void selectionSort(double list[], int listSize)
{
    for (int i = listSize-1; i >= 0 ; i--)
    {
        double currentMax = list[i];
        int currentMaxIndex = i;
        for (int j = i - 1; j >= 0; j--)
        {
            if (currentMax < list[j])
            {
                currentMax = list[j];
                currentMaxIndex = j;
            }
        }
            if (currentMaxIndex != i)
            {
                list[currentMaxIndex] = list[i];
                list[i] = currentMax;
            }
   
    }
}
//increasing order
void selectionSort(double list[], int listSize)
{
    for (int i = 0; i < listSize - 1; i++)
    {
        double currentMin = list[i];
        int currentMinIndex = i;
        for (int j = i + 1; j < listSize; j++)
        {
            if (currentMin > list[j])
            {
                currentMin = list[j];
                currentMinIndex = j;
            }
        }
            if (currentMinIndex != i)
            {
                list[currentMinIndex] = list[i];
                list[i] = currentMin;
            }
        
    }
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll cs=0;
ll tab[500000][20];
void spar(ll a[],ll n)
{
    ll i,j;
    for(i=0;i<n;i++)
        tab[i][0]=a[i];
    for(j=1;(1<<j)<=n;j++)
    {
        for(i=0;i+(1<<(j-1))-1<n;i++)
            tab[i][j]=__gcd(tab[i][j-1],tab[i+(1<<(j-1))][j-1]);
    }
}
ll qry(ll a,ll b)
{
    ll j=log2(b-a+1);
    return __gcd(tab[a][j],tab[b-(1<<j)+1][j]);
}
void sol()
{
    ll n,m,i,sum=0;
    cin>>n>>m;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    spar(a,n);
    for(i=0;i+m-1<n;i++)
        sum+=qry(i,i+m-1);
    cout<<sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll t;
    //cin>>t;
    //while(t--)
    sol();
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
ll cs=0;
struct duo
{
    ld x,F,S;
};
bool sim(duo a,duo b)
{
    if(a.F==b.F||a.F==b.S||a.S==b.F||a.S==b.S)
        return 1;
    return 0;
}
void sol()
{
    cout.precision(11);
    cout<<fixed;
    ll n,i,k;
    cin>>n;
    ld a[n],vl,ans=0;
    duo low[3],h[3];
    for(i=0; i<3; i++)
        low[i].x=INT_MAX;
    for(i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0; i<3; i++)
    {
        h[i].F=a[n-1-i];
        h[i].S=a[n-2-i];
    }
    for(i=0; i<n-1; i++)
    {
        vl=abs(a[i]-a[i+1]);
        for(k=0; k<3; k++)
        {
            if(vl<low[k].x)
            {
                ll j=k;
                for(j=2; j>=k+1; j--)
                {
                    low[j].x=low[j-1].x;
                    low[j].F=low[j-1].F;
                    low[j].S=low[j-1].S;
                }
                low[k].x=vl;
                low[k].F=a[i];
                low[k].S=a[i+1];
                break;
            }
        }
    }
    for(i=0;i<3;i++)
    {
        for(k=0;k<3;k++)
        {
            if(!sim(h[i],low[k]))
                ans=fmax(ans,(h[i].F+h[i].S)/low[k].x);
        }
    }
    cout<<ans;

}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //ll t;
    //cin>>t;
    //while(t--)
    sol();
    return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
// CPP program to check if a string is 
// substring of other. 

using namespace std;

// Returns true if s1 is substring of s2 
int isSubstring(string s1, string s2)
{
	int M = s1.length();
	int N = s2.length();

	/* A loop to slide pat[] one by one */
	for (int i = 0; i <= N - M; i++) {
		int j;

		/* For current index i, check for
pattern match */
		for (j = 0; j < M; j++)
			if (s2[i + j] != s1[j])
				break;

		if (j == M)
			return i;
	}

	return -1;
}

/* Driver program to test above function */
int main()
{
	string s1 ,s2 ;
	getline(cin, s1);
	getline(cin, s2);
	int res = isSubstring(s1, s2);
	if (res == -1)
		cout << "Not present";
	else
		cout << "Present at index " << res;
	return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);
int bin2Dec(int binNumber);
int dec2octal(const string& number);




int main()
{
	string binNumber;
	getline(cin, binNumber);
	cout << dec2octal(binNumber);
	return 0;
}
int dec2octal(const string& number)
{
	int binNumber = stringToNum(number);
	int decimalNumber = bin2Dec(binNumber);
	int octal = 0, placeValue = 1;
	while (decimalNumber != 0)
	{
		octal += (decimalNumber % 8) * placeValue;
		decimalNumber /= 8;
		placeValue *= 10;
	}
	return octal;
}

int bin2Dec(int binNumber)
{
	int digits, decimal = 0, count = 0, bin = binNumber;
	while (bin != 0)
	{
		digits = bin % 10;
		  decimal += digits* pow(2,count);

		  bin /= 10;
		count++;
		
	}
	return decimal;
}
int stringToNum(string binNumber)
{
	int convertedNumber = 0;
	for (int i = 0; i < binNumber.length(); i++)
	{
		
		convertedNumber = (convertedNumber * 10) + static_cast<int>(binNumber[i] - '0');
	}
	return convertedNumber;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int octal2Dec(string& octal);
bool validity(int number);
int stringToNum(string number);


int main()
{
	string number;
	getline (cin , number);

	
	cout << octal2Dec(number);
	return 0;
}

int octal2Dec(string& octal)
{
	int digits, decimal = 0, count = 0,oct = stringToNum(octal);
	while (oct != 0)
	{
	
		digits = oct % 10;
		if(validity(digits) == true)
		  decimal += digits* pow(8,count);
		else
		{
			return NAN;
		}
		oct /= 10;
		count++;
		
	}
	return decimal;
}
bool validity(int number)
{
	return number % 8 == 0 || number % 9 == 0? false : true;
		
}
int stringToNum(string number)
{
	int convertedNumber = 0;
	for (int i = 0; i < number.length(); i++)
	{
		convertedNumber = (convertedNumber * 10) + static_cast<int>(number[i] - '0');
	}
	return convertedNumber;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;




string format(int number, int width);
int numberWidthF(int number);

int main()
{

	
	int number,width;
	cin >> number >> width;
	cout << format(number, width);
	
}
string format(int number, int width)
{
	string zeros = " ";
	string num = to_string(number);
	
	int numberWidth = numberWidthF(number);
	
	for (int  i = 1; i <= width-numberWidth; i++)
	{
		zeros += "0";
	}
	return zeros+num;
}
int numberWidthF(int number)
{
	int digits, numberWidth = 0;
	while (number != 0)
	{
		digits = number % 10;
		number /= 10;
		numberWidth++;
	}
	return numberWidth;
}
cout << "Machine ID: ";
	//WHILE LOOP: check whether Machine ID is in numeric
	while(!(cin >> machineID)){
		//display error message
		cout << "ERROR! Invalid Machine ID! Please try again..." << endl;
		cout << "Machine ID: ";
		
		cin.clear(); //clear previous user input
		cin.ignore(INT_MAX, '\n'); //discard previous user input
	}
//	optionMenu = getMenuOption();
//	
//	while(optionMenu > -1){
//		switch(optionMenu){
//			case 1:
//				addJob(h, j);
//				break;
//			
//			case 2:
//				retrieveJob(h, j);
//				break;
//				
//			case 3:
//				cout << "Option 3..." << endl;
//				break;
//				
//			case 4:
//				cout << "Option 4..." << endl;
//				break;
//			
//			case 5:
//				cout << "Bye!";
//				exit(0); //terminate program
//				break;
//				
//			default:
//				cout << "ERROR! Invalid option! Please try again..." << endl;
//				break;
//		}
//		
//		optionMenu = getMenuOption();
//	}


int getMenuOption(){
	int menuOption=0;
		
	cout << "Please enter number to select: ";
	cin >> menuOption;
	
	//error check
	while(!cin.good()){
		//report problem when user input in not numeric
		cout << "ERROR! Faulty input! Please try again..." << endl;
		
		//clear stream
		cin.clear();
		cin.ignore(INT_MAX, '\n');
		
		//get input again
		cout << "Please enter number to select: ";
		cin >> menuOption;
	}
	
	//clear stream
	cin.clear();
	cin.ignore(INT_MAX, '\n');
		
	return menuOption;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;



double avgOfEvenPlaces(int number);
int reversal(int n);


int main()
{
	
	int number;
	cin >> number;
	cout << fixed<<setprecision(3)<<avgOfEvenPlaces(reversal(number));
}
double  avgOfEvenPlaces(int n)
{
	
	int digit, count = 1.0, countOfEven = 0.0;
	double sumOfEven = 0.0;
	while (n != 0)
	{
		digit = n % 10;
		n /= 10;
		
		if (count % 2 == 0)
		{
		  
			sumOfEven += digit; 
			countOfEven++;
		}
			count++;
	}
	
		return  sumOfEven / countOfEven;
	
}
int reversal(int n)
{
	int digits, revers = 0.0;
	while (n != 0)
	{
		digits = n % 10;
		revers = revers * 10 + digits;
		n /= 10;
	}
	return revers;
 }


#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;



double sqrt(int n);


int main()
{
	
	long n;
	cin >> n;
	cout << "the approximated sqrt of the number " << n << " is " << sqrt(n);
}
double sqrt(long n)
{
	double lastGuess = 1;
	double nextGuess = (lastGuess + n / lastGuess) / 2;

	while (nextGuess - lastGuess > 0.0001)
	{
		nextGuess = lastGuess;
		(lastGuess + (n / lastGuess)) / 2;
	}
	lastGuess = nextGuess;
	return nextGuess = (lastGuess + n / lastGuess) / 2;

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


bool primeNumber(int n);
bool additivePrime(int n);
int sumOfDigits(int n);



int main()
{
	
	int count = 0;
	int number = 13;
	cout << setw(3) << "Prime number" << setw(20) << "Sum of its digits" << endl;
	for (int i = 2; i <= 70; i++)
	{
		if (primeNumber(i) && additivePrime(i))
			cout <<setw(1)<< i<<setw(15)<<sumOfDigits(i)<<endl;
	}
		

}
bool primeNumber(int n) {
	
		for (int i = 2; i <= n / 2; i++) {
			
			if (n % i == 0) {

				return false;
			}
		}
		return true;
}

bool additivePrime(int n)
{
	
	if (primeNumber(sumOfDigits(n)))
		return true;
	else
		return false;
}
int sumOfDigits(int n)
{
	int sum = 0, digit = 0;
	while (n != 0)
	{
		digit = n % 10;
		sum += digit;
		n /= 10;
	}
	return sum;
}






	
   




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


bool primeNumber(int n);
bool Emirp(int n);
int reversal(int n);
int recursive(int a, int b);

int main()
{
	
	int count = 0;
	int number = 13;
	while (count <= 100)
	{
		if (Emirp(number))
		{
			count++;
			if (count % 10 == 0)
				cout << setw(7) << number << endl;
			else
				cout << setw(7) << number;
		}
		number++;
	}
		

}
bool primeNumber(int n) {
	
		for (int i = 2; i <= n / 2; i++) {
			
			if (n % i == 0) {

				return false;
			}
		}
		return true;
}

bool Emirp(int n) {
	

	return primeNumber(n) && primeNumber(reversal(n));
	
}

int reversal(int n) {
	
		if (n < 10) {
			
				return n;
			
		}
		return recursive(n % 10, n / 10);
	
}

int recursive(int a, int b) {

	if (b < 1) {

		return a;

	}
	return recursive(a * 10 + b % 10, b / 10);
	
}



	
   




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;
bool isEven(int number);
bool isPalindrom(int number);

int main()
{
	
	int count = 0, number = 1;
	
	while (count <= 50)
	{

		if(isEven(number) == true && isPalindrom(number) == true)
		{
			count++;
			if (count % 5 == 0)
				cout << setw(8) << number << endl;
			else
				cout << setw(8) << number;
		}
		number++;
	}
	
		
	

}

bool isEven(int number)
{
	if (number % 2 == 0)
		return true;
	else
		return false;
	
}
bool isPalindrom(int number)
{
	int reverse = 0, rem = 0;
	int num = number;
	while (number != 0)
	{
		rem = number % 10;
		reverse = reverse * 10 + rem;
		number /= 10;
	}
	if (reverse == num)
		return true;
	else
		return false;
}


	
   




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

bool isArmstrong(int n);
int reversNumber(int n);
void isReversedArmstrong(int n);

int main()
{
	cout << "Enter first integer: ";
	int n1;
	cin >> n1;
	isReversedArmstrong(n1);
	

}

bool isArmstrong(int n)
{
	int temp = 0,armstrong, total = 0;
	armstrong = n;
	while (armstrong != 0)
	{
		temp = armstrong % 10;
		total += pow(temp, 3);
		armstrong /= 10;
	}
	if (total == n)
		return true;
	else
		return false;
 }
int reversNumber(int n)
{
	int reverse = 0, rem = 0;
	while (n != 0)
	{
		rem = n % 10;
		reverse = reverse * 10 + rem;
		n /= 10;
	}
	return reverse;
}
void isReversedArmstrong(int n)
{
	if (isArmstrong(n))
	{
		if(isArmstrong(reversNumber(n)))
			cout << "the Reversed "<< reversNumber(n)<<" number IS an Armstrong number ";
		else
			cout << "the Reversed " << reversNumber(n) << " number is NOT Armstrong number ";
	}
	else
		cout << "the number entered is NOT Armstrong number ";

}


	
   




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int LCM(int n1, int n2);

int main()
{
	cout << "Enter first integer: ";
	 int n1;
	 cin >> n1;
	
		 cout << "Enter second integer: ";
	 int n2;
	 cin >> n2;
	
	
	
		cout << "Least Common Multiple for " << n1 <<
			" and " << n2 << " is " << LCM(n1,n2)<< endl;
}

 int LCM(int n1, int n2)
 {
	 int lcm = 1; 
	 int max = (n1 > n2) ? n1 : n2;
	
		 while (true)
		 {
			 if (max % n1 ==0 && max % n2 == 0)
			 {
				 lcm = max;
				 break;
			 }
			 else
				 max++;

		 }
	
		return lcm; // Return gcd
	 }




	
   




#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;


int compute_profit(int quantity);

int main()
{
	int quantity = 1000;
	cout << "Quantity " << setw(9) << "Profit-per-item (in $)"<<endl;
    for ( ; quantity <= 10000; quantity+=1000)
    {
            cout<<quantity<< setw(9)<<compute_profit(quantity)<<endl;
    }
   
}
int compute_profit(int quantity)
{
    int profit = 0;
   

   
    if (quantity < 1000)
        profit += quantity; // * 1
    else
    {
        profit += 1000;
        quantity -= 1000;
        if (quantity < 4000)
            profit += quantity * 2;
        else
        {
            profit += 8000; // 4000 * 2
            quantity -= 4000;
            profit += quantity * 5;
        }
    }
    
    return profit;
}


// access v1 by copy 
[v1]() { 
	for (auto p = v1.begin(); p != v1.end(); p++) { 
		cout << *p << " "; 
	} 
}; 
/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
vi<ll>coins;
struct tim
{
    ll s,f;
};
bool cmp(tim a,tim b)
{
    if(a.s!=b.s)return a.s<b.s;
    return a.f<b.f;
}
/**
THINK TWICE,
      CODE ONCE
**/

void sol(ll cs)
{
   ll n,i,sum=1,j;
   cin>>n;
   tim t;
   vector<tim>v;
   for(i=0;i<n;i++)
    cin>>t.f>>t.s,v.pb(t);
   sort(v.B,v.E,cmp);//if time ain't sorted
   j=0;
   for(ll i=1;i<n;i++)
   {
       if(v[i].f>=v[j].s)sum++,j=i;
   }
   cout<<sum<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
struct pt
{
    ll x,y,t;
};
/**
THINK TWICE,
      CODE ONCE
**/
void show(vi<ll>&v)
{
    for(auto it:v)cout<<it<<' ';
    cout<<"\n";
}
vi<ll> filsub(vi<ll>v)
{
    vi<ll>temp;
    ll i,j,n=v.size(),sum;
    for(i=0;i<(1<<n);i++)
    {
        sum=0;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
                sum+=v[j];
        }
        temp.pb(sum);
    }
    return temp;
}
void sol(ll cs)
{
    vi<ll>v,va,vb;
    ll n,i,a,k;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>a,v.pb(a);
    va.assign(v.B,v.E-n/2);
    vb.assign(v.B+(n+1)/2,v.E);
    sort(va.B,va.E);
    sort(vb.B,vb.E);
    va=filsub(va);
    vb=filsub(vb);
    bool bl=false;
    for(i=0;i<va.size();i++)
    {
        if(binary_search(vb.B,vb.E,k-va[i]))
        {
            bl=true;
            break;
        }
    }
    cout<<csee<<((bl)?"Yes":"No")<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
struct pt
{
    ll x,y,t;
};
/**
THINK TWICE,
      CODE ONCE
**/
void show(vi<ll>&v)
{
    for(auto it:v)cout<<it<<' ';
    cout<<"\n";
}
set<ll> filsub(vi<ll>v)
{
    set<ll>temp;
    ll i,j,n=v.size(),sum;
    for(i=0;i<(1<<n);i++)
    {
        sum=0;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
                sum+=v[j];
        }
        temp.ins(sum);
    }
    return temp;
}
void sol(ll cs)
{
    set<ll>sa,sb;
    vi<ll>v,va,vb;
    ll n,i,a,k;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>a,v.pb(a);
    va.assign(v.B,v.E-n/2);
    vb.assign(v.B+(n+1)/2,v.E);
    sort(va.B,va.E);
    sort(vb.B,vb.E);
    sa=filsub(va);
    sb=filsub(vb);
    bool bl=false;
    for(auto it=sa.B;it!=sa.E;it++)
    {
        if(sb.count(k-*it))
        {
            bl=true;
            break;
        }
    }
    cout<<csee<<((bl)?"Yes":"No")<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
const ld pi=2*acos(0.0);
ll T,N;
ll cs=1;
ll soln=0;
/**
THINK TWICE,
      CODE ONCE
**/
bool ok(vi<vi<ll>>&v,ll row,ll col)
{
    if(row>=0&&row<N&&col>=0&&col<N&&!v[row][col])
        return true;
    return false;
}
void go(vi<vi<ll>>&v,ll row,ll col,ll tp)
{
    if(row==N-1&&col==N-1)
    {
        if(N*N==tp)
            soln++;
        return;
    }
    v[row][col]=1;
    if(row==0&&col==0)
        go(v,row+1,col,tp+1);
    else
    {
        v[row][col]=0;
        bool l=false,r=false,u=false,d=false;
        if(ok(v,row,col+1))
            r=true;
        if(ok(v,row,col-1))
            l=true;
        if(ok(v,row+1,col))
            d=true;
        if(ok(v,row-1,col))
            u=true;
        if(!u&&!d&&r&&l)
            return;
        if(u&&d&&!r&&!l)
            return;
        v[row][col]=1;
        if(r)
            go(v,row,col+1,tp+1);
        if(l)
            go(v,row,col-1,tp+1);
        if(d)
            go(v,row+1,col,tp+1);
        if(u)
            go(v,row-1,col,tp+1);
    }
    v[row][col]=0;
}
void sol(ll cs)
{
    soln=0;
    cin>>N;
    vi<ll>temp(N,0);
    vi<vi<ll>>v(N,temp);
    go(v,0,0,1);
    cout<<csee<<2*soln<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

void printMonth(int year, int month);
void printMonthTitle(int year, int month);
void ptintMonthName(int month);
void printMonthBody(int year, int month);
int getStartDay(int year, int month);
int getTotalNumberOfDays(int year, int month);
int getNumberOfDaysInMonth(int year, int month);
bool isLeapYear(int year);

int main()
{
	cout << "Enter full year ";
	int year;
	cin >> year;
	cout << " Enter month in number between 1 and 12: ";
	int month;
	cin >> month;
	printMonth(year, month);

}
void printMonth(int year, int month)
{
	printMonthTitle(year, month);

	printMonthBody(year, month);
}


void printMonthTitle(int year, int month)

{
	ptintMonthName(month);
	cout << " " << year << endl;
	cout << "-----------------------------" << endl;
	cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
	

}



void ptintMonthName(int month)

{
	switch (month)
	{
	case 1:
		cout << "January";
		break;
	case 2:
		cout << "February";
		break;
	case 3:
		cout << "March";
		break;
	case 4:
		cout << "April";
		break;
	case 5:
		cout << "May";
		break;
	case 6:
		cout << "June";
		break;
	case 7:
		cout << "July";
		break;
	case 8:
		cout << "August";
		break;
	case 9:
		cout << "September";
		break;
	case 10:
		cout << "October";
		break;
	case 11:
		cout << "November";
		break;
	case 12:
		cout << "December";
	}
}
void printMonthBody(int year, int month)
{
	int startDay = getStartDay(year, month);
	int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);

	for (int i = 0; i < startDay; i++)
		cout << "    ";
	for (int i = 1; i <=  numberOfDaysInMonth; i++)
	{
		cout << setw(4) << i;
		if ((i + startDay) % 7 == 0)
			cout << endl;
	}
}
int getStartDay(int year, int month)
{
	int startDay1800 = 3;
	int totalNumberOfDays = getTotalNumberOfDays(year, month);


	return (totalNumberOfDays + startDay1800) % 7;

}
int getTotalNumberOfDays(int year, int month)
{
	int total = 0;
	for (int i = 1800; i < year; i++)
	{
		if (isLeapYear(i))
			total += 366;
		else
			total += 365;
	}
	for (int i = 1; i < month; i++)
	{
		total += getNumberOfDaysInMonth(year, i);
	}
	return total;
}
int getNumberOfDaysInMonth(int year, int month)
{
	if (month == 1 || month == 3 || month == 5 || month == 7 ||
		month == 8 || month == 10 || month == 12)
		return 31;
	if (month == 4 || month == 6 || month == 9 || month == 11)
		return 30;
	
		if (month == 2) return isLeapYear(year) ? 29 : 28;
	
		 return 0;
}
bool  isLeapYear(int year)
{
	return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int hexDec(const string& hex);
int hexCharToDecimal(char ch);
int main()
{
	cout << "enter a hex Number ";
	string hex;
	cin >> hex;

	cout << "The Decimal Number For Hex Is  " << hex
		<< " is " << hexDec(hex) << endl;
}
int hexDec(const string&  hex)
{
	int decimalValue = 0;
	for (unsigned i = 0; i < hex.length(); i++)
	{
		decimalValue = decimalValue * 16 + hexCharToDecimal(hex[i]);
	}
	return decimalValue;
	
}
int hexCharToDecimal(char ch)
{
	ch = toupper(ch);
	if (ch >= 'A' && ch <= 'F')
		return 10 + ch - 'A';
	else
		return ch - '0';
}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
    int counter = 1;
    int number = 0;
    int largest = 0;
    int n;
    cin >> n;
    int occurrence = 0;

    cout << "Please enter up to 10 numbers and I will print the largest one on the screen.\n\n";

    while (counter <= n)
    {
        cout << "Number: ";
        cin >> number;
        
        if (largest < number)
        {
            largest = number;
            occurrence = 1;
            
        }
        else if (number == largest)
        {
            occurrence++;
        }
        if (number == 0)
        {
            break;

        }
            counter++;
    }

    cout << "the largest number is "<<largest << endl;
    cout << "  the occurrence count " << largest << " is " << occurrence << " time";


	

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

	int firstprofit = 0;
	int quantity = 0;
	int q3 = 1;

	//the targeted profit >> 50000
	cout << "Enter the profit ";
	int endProfit;
	cin >> endProfit;

	//first five quantity 1 * 1000+2 * 4000
	firstprofit += 9000;
	do
	{
		//the remaining quantity(q3) which is 50000(endProfit) - 9000(firstProfit) / 5
		if (q3 == (endProfit - 9000) / 5)

			firstprofit += q3 * 5;
		else
			q3++;

	} while (firstprofit <= endProfit);

	//the whole quantity
	quantity += 1000 + 4000 + q3;

	cout << quantity;






}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	int num, reversedInteger = 0, remainder, originalInteger;
	cin >> num;
	originalInteger = num;
	for (; num != 0; num /= 10)
	{
		remainder = num % 10;
		reversedInteger = reversedInteger * 10 + remainder;
	}


	if (originalInteger == reversedInteger)
		cout << originalInteger << " is a palindrome.";
	else
		cout << originalInteger << " is not a palindrome.";


	
	

	
	
}

	
	

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

	int f1 = 0, f2 = 1;
	int nextTerm = 0;
	for (int i = 1; i < 10; i++)
	{
		//print first 2 numbers
		if (i == 1)
		{
			cout <<  f1<<" ";
			continue;
		}
		if (i == 2)
		{
			cout << f2 << " ";
			continue;
		}
		
		nextTerm = f1 + f2;
		f1 = f2;
		//make f2 = the next term
		f2 = nextTerm;
		cout << nextTerm<<" ";

	}

	
	

	
	
}

	
	

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	cout << "enter the year ";
	int year;
	cin >> year;
	
	cout << "Enter The First Day Of The year ";
	int FirstDay;
	cin >> FirstDay;
	int count = 1;
	int days = 1;
	for (int month = 1; month <= 12; month++)
	{
		cout << "             ";
		switch (month)
		{
		case 1: cout << "January " << year<<endl;
			break;
		case 2: cout << "February " << year << endl;
			break;
		case 3: cout << "March  " << year << endl;
			break;
		case 4: cout << "April  " << year << endl;
			break;
		case 5: cout << "May " << year << endl;
			break;
		case 6: cout << "June  " << year << endl;
			break;
		case 7: cout << "July  " << year << endl;
			break;
		case 8: cout << "August " << year << endl;
			break;
		case 9: cout << "September " << year << endl;
			break;
		case 10: cout << "October " << year << endl;
			break;
		case 11: cout << "November " << year << endl;
			break;
		case 12: cout << "December " << year << endl;
			break;
		}
		cout << " --------------------------------------------------------- "<<endl;
		cout << "  Sun Mon Tue Wed Thu Fri Sat"<<endl;
		for (int i = 0; i < FirstDay; i++)
		{
			cout << "    ";
		}
		for (int i = 1; i < 31; i++)
		{
			if (i < 10) {
				cout<<"   " <<i;
			}
			else {
				cout<<"  " << i;
			}
			if ((i + FirstDay) % 7 == 0) {
				cout << endl;
			}
		}
		cout << endl;

		FirstDay = (FirstDay + 31) % 7;
		
	}
	
	
}

	
	

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	cout << "enter the month ";
	int month;
	cin >> month;
	cout << "Enter The First Day Of The Month ";
	int firstDay;
	cin >> firstDay;
	int nextSunday = 1;
	
		switch (firstDay)
		{
			
		case 1: nextSunday += 7;
			cout << "The first day of this month is sunday "<<endl;
			while (nextSunday < 30)
			{
					cout << "Next Sunday of this month is on " << nextSunday << endl;
									nextSunday += 7 ;
			}
			break;

		case 2: nextSunday += 6;
			cout << "The first day of this month is monday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;
		case 3: nextSunday += 5;
			cout << "The first day of this month is tuesday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;
		case 4: nextSunday += 4;
			cout << "The first day of this month is wednesday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;
		case 5: nextSunday += 3;
			cout << "The first dayof this month is thursday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;
		case 6: nextSunday += 2;
			cout << "The first day of this month is friday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;
		case 7: nextSunday += 1;
			cout << "The first day of this month is saturday " << endl;
			while (nextSunday < 30)
			{
				cout << "Next Sunday of this month is on " << nextSunday << endl;
				nextSunday += 7;
			}
			break;

		}
		
}

	
	

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	int number;
	cin >> number;
	for (int i = 0; i <=number; i++)
	{
		for (int j = 0; j <= number; j++)
		{
			if
				(
					i == 0 || i == number ||
					i == number/2|| j == number/2||
					j == 0 || j == number ||
					i == j || j == (number - i + 0)
					)
				cout <<" "<< "*";
			else
				cout << "  ";
			int h = (number - i + 1);
		}
	
			cout << "\n";
	}
		


		
	


}

	
	

	
	

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
	for (int i = 0; i < 8; i++)
	{
		for (int k = 0; k <= i; k++)
		{
			cout << "  ";
		}
		for (int j = i; j < 8; j++)
		{
			cout <<" "<< static_cast<char>(j+97-i);

		}
		for (int j = 7; j >= i; j--)
		{
			cout << " " << static_cast<char>(j + 97 - i);
		}
			cout << "\n";
	}
		

}