Snippets Collections
/**
 * 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";
	}
		

}

	
	

	
	

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

using namespace std;

int main()
{
	
	cout << " ##############";
	cout << endl;
	for (int  i = 0; i <=5; i++)
	{
		
		for (int j = 0;  j < 1;  j++)
		{
			cout << " " << "#";
		}
		for (int j = 1;  j <= i;  j++)
		{
                cout << " ";
		}
		for (int j = 0; j <1; j++)
		{
			cout << "#";
		}
		for (int j = i; j < 5; j++)
		{
			cout << " ";
		}
		for (int j = i; j < 5; j++)
		{
			cout << " ";

		}
		for (int j = 0; j <1 ; j++)
		{
			cout << "#";
		}
		for (int j = 0; j < i; j++)
		{
			cout << " ";
		}
		for (int i = 0; i < 1; i++)
		{
			cout << "#";
		}
		cout << endl;
	}

	for (int i = 0; i <=5; i++)
	{
		for (int j = 0; j < 1; j++)
		{
			cout << " " << "#";
		}
		for (int j = 5; j >i; j--)
		{
			cout << " ";
		}
		for (int j = 0;  j< 1; j++)
		{
			cout << "#";
		}
		for (int j = 0; j < i; j++)
		{
			cout << " ";
		}
		for (int j = 0; j < i; j++)
		{
			cout << " ";
		}
		for (int j = 0; j < 1; j++)
		{
			cout << "#";
		}
		for (int j = 5; j > i ; j--)
		{
			cout << " ";
		}
		for (int i = 0; i < 1; i++)
		{
			cout << "#";
		}
		cout << endl;
		
	}
	cout << " ##############";
	cout << endl;


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

using namespace std;

int main()
{



    int rows;
    cin >> rows;

    for (int i = 1; i <= rows; i++)
    {
        for (int k = 1; k <= (rows -i); k++)
        {
            cout << "   ";
           
        }
        for (int d = i; d > 1; d--)
            {
            cout << d << "  ";
                
            }
        for (int  v = 1; v <= i; v++)
        {
            cout << v<<"  ";
        }
        cout << endl;

        
    }


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

using namespace std;

int main()
{
	int firstLetter = 65;
	int count = 0;

	for (int i = 65; i <= 90; i++)
	{
		count++;
		if (count%5 == 0)
			cout << setw(3) << static_cast<char>(i) << endl;
		else
			cout << setw(3) << static_cast<char>(i);

		
		
	}

	
	
		

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

using namespace std;

int main()
{

	cout << "Enter two positive numbers ";
	int n1,n2;
	cin >> n1>>n2;
	int d = 1;
	int gcd = 1;
	
	if (n1 < n2)
		d = n1;
	else
		d = n2;
	while (true)
	{
		if (n1 % d == 0 && n2 % d == 0) {
				gcd = d;
				break;
		}
			
		d--;
	}
	
	cout << "the CGD of " << n1 << " and " << n2 << " is " << gcd;

	
	
		

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

using namespace std;

int main()
{
	
	int n = 1;
	int largest = 0;
	while (n*n<30000)
	{
		if (n > largest)
		{
			largest = n;
		}
		n++;
	}
	cout << "the largest number is " << largest;
	
	
		

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

using namespace std;

int main()
{
	
	int count = 0;
	
	// iterate from 0 to N 
	for (int num = 300,count = 0; num <=400; num++)
	{
		// Short-circuit operator is used  
		if (num % 3 == 0 || num % 6 == 0)
		{
			cout << setw(5) << num;
			count++;
			if (count % 5 == 0)
				cout << setw(5) << num << endl;
		
		}
		
		
			
	}
		

	
	
}
#include <iostream>  
using namespace std;  
int main() 
{  
  int n1=0,n2=1,n3,i,number;    
 cout<<"Enter the number of elements: ";    
 cin>>number;    
 cout<<n1<<" "<<n2<<" "; //printing 0 and 1    
 for(i=2;i<number;++i) //loop starts from 2 because 0 and 1 are already printed    
 {    
  n3=n1+n2;    
  cout<<n3<<" ";    
  n1=n2;    
  n2=n3;    
 }    
   return 0;  
}  
#include<iostream>
using namespace std;

int main()
{
  cout<<"Enter the integers: "<
}
include <FirebaseArduino.h>

#define FIREBASE_HOST "example.firebaseio.com"
#define FIREBASE_AUTH "token_or_secret"


void setup() {
  Serial.begin(9600);
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

int n = 0;

void loop() {

  // set value
  Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // update value
  Firebase.setFloat("number", 43.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // get value 
  Serial.print("number: ");
  Serial.println(Firebase.getFloat("number"));
  delay(1000);

  // remove value
  Firebase.remove("number");
  delay(1000);

  // set string value
  Firebase.setString("message", "hello world");
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /message failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);
  
  // set bool value
  Firebase.setBool("truth", false);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /truth failed:");
      Serial.println(Firebase.error());  
      return;
  }
  delay(1000);

  // append a new value to /logs
  String name = Firebase.pushInt("logs", n++);
  // handle error
  if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;
  }
  Serial.print("pushed: /logs/");
  Serial.println(name);
  delay(1000);
}
  
#include <ESP8266WiFi.h>


// Set these to run example.
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASSWORD"

  // connect to wifi.
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
#include <stdio.h>
 
class Node
{
public:
    Node( int v )
    {
        data = v;
        left = 0;
        right = 0;
    }
 
    int data;
    Node* left;
    Node* right;
};
 
void Add( Node** root, Node* n )
{
    if ( !*root  )
    {
        *root = n;
        return;
    }
 
    if ( (*root)->data < n->data )
    {
        Add( &(*root)->right, n );
    }
    else
    {
        Add( &(*root)->left, n );
    }
}
 
void Print( Node* node )
{
    if ( !node )  return;   
    Print( node->left );
    printf( "value = %i\n", node->data );
    Print( node->right );
}
 
int main()
{
    Node* root = 0;
 
    Add( &root, new Node( 1 ) );
    Add( &root, new Node( 2 ) );
    Add( &root, new Node( -1 ) );
    Add( &root, new Node( 12 ) );
 
    Print( root );
    return 0;
}
int maxSubArraySum(int a[], int size) 
{ 
int max_so_far = 0, max_ending_here = 0; 
for (int i = 0; i < size; i++) 
{ 
	max_ending_here = max_ending_here + a[i]; 
	if (max_ending_here < 0) 
		max_ending_here = 0; 

	/* Do not compare for all elements. Compare only 
		when max_ending_here > 0 */
	else if (max_so_far < max_ending_here) 
		max_so_far = max_ending_here; 
} 
return max_so_far; 
} 
// Define macros for inlining x86 assembly in a compiler-independent way
#ifdef _MSC_VER
	#define ASM1(asm_literal) \
		__asm asm_literal
	#define ASM2(asm_literal1, asm_literal2) \
		__asm asm_literal1, asm_literal2
	#define ASM3(asm_literal1, asm_literal2, asm_literal3) \
		__asm asm_literal1, asm_literal2, asm_literal3

	#define ASM_MOV_REG_VAR(register, variable) \
		ASM(mov register, variable)

	#define ASM_MOV_VAR_REG(variable, register) \
		ASM(mov variable, register)

#elif __GNUC__ || __clang__
	#define ASM1(asm_literal) \
		ASM_GCC(#asm_literal)
	#define ASM2(asm_literal1, asm_literal2) \
		ASM_GCC(#asm_literal1 ", " #asm_literal2)
	#define ASM3(asm_literal1, asm_literal2, asm_literal3) \
		ASM_GCC(#asm_literal1 ", " #asm_literal2 ", " #asm_literal3)
	
	#ifdef __x86_64__
		#define ASM_MOV_REG_VAR(register, variable) \
			__asm__ __volatile__("movq %0, %%" EXPAND_AND_QUOTE(register)  : /* no outputs */ : "m"(variable) : )

		#define ASM_MOV_VAR_REG(variable, register) \
			__asm__ __volatile__("movq %%" EXPAND_AND_QUOTE(register) ", %0"  : "=m"(variable) : /* no inputs */ : )
	#else
		#define ASM_MOV_REG_VAR(register, variable) \
			__asm__ __volatile__("mov %0, %%" EXPAND_AND_QUOTE(register)  : /* no outputs */ : "m"(variable) : )

		#define ASM_MOV_VAR_REG(variable, register) \
			__asm__ __volatile__("mov %%" EXPAND_AND_QUOTE(register) ", %0"  : "=m"(variable) : /* no inputs */ : )
	#endif

	#define ASM_GCC(asm_string) \
		__asm__ __volatile__(".intel_syntax noprefix;" asm_string ";.att_syntax prefix"); \
	
#endif
#include<iostream>                //including input/output libarary
using namespace std;
int main(){                               //starting main function
int array_name[5];                   //defining a variable array of type integer with name "array_name" and size 5.
array_name[0]=2;                   //assigning value of 2 to  first element of array "array_name"
array_name[1]=3;                   
array_name[2]=4                      // assinging values to other elements of array using their index number
array_name[3]=12;
array_name[4]=33;

return 0;
}
> More steps
star

Thu Jul 08 2021 07:53:58 GMT+0000 (UTC) https://pastebin.com/YfYcJ5f1

#c++
star

Fri Jul 02 2021 18:33:06 GMT+0000 (UTC)

#c++
star

Fri Jul 02 2021 17:34:27 GMT+0000 (UTC)

#c++
star

Fri Jul 02 2021 08:16:57 GMT+0000 (UTC) https://leetcode.com/explore/challenge/card/july-leetcoding-challenge-2021/608/week-1-july-1st-july-7th/3800/

#c++
star

Wed Jun 23 2021 05:09:08 GMT+0000 (UTC) https://www.codechef.com/submit/VOTERS

#c++
star

Tue Jun 22 2021 02:54:54 GMT+0000 (UTC) https://github.com/imneonizer/How-to-find-if-an-image-is-bright-or-dark/

#python #c++
star

Fri Jun 18 2021 14:33:24 GMT+0000 (UTC) https://www.geeksforgeeks.org/reverse-a-string-in-c-cpp-different-methods/

#c++
star

Wed Jun 02 2021 16:09:47 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 11:56:03 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 10:39:55 GMT+0000 (UTC)

#c++
star

Wed Jun 02 2021 10:37:42 GMT+0000 (UTC)

#c++
star

Wed May 26 2021 22:05:48 GMT+0000 (UTC) https://stackoverflow.com/questions/5307169/what-is-the-meaning-of-a-c-wrapper-class

#c #c++ #wrapper
star

Wed May 26 2021 20:58:04 GMT+0000 (UTC) https://www.c-plusplus.net/forum/topic/270976/was-ist-ein-wrapper

#c #c++ #wrapper
star

Sat May 08 2021 17:17:06 GMT+0000 (UTC)

#c++
star

Mon May 03 2021 16:22:37 GMT+0000 (UTC)

#c++ #output #xcode #redirection
star

Mon May 03 2021 16:14:21 GMT+0000 (UTC)

#c++
star

Wed Apr 28 2021 00:56:03 GMT+0000 (UTC) https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work#:~:text=The%20compilation%20of%20a%20C%2B%2B%20program%20involves%20three%20steps%3A&text=Compilation%3A%20the%20compiler%20takes%20the,library%20or%20an%20executable%20file.

#c++
star

Tue Apr 20 2021 01:06:11 GMT+0000 (UTC) https://gitlab.eecs.umich.edu/eecs281/wiki/-/wikis/xcode-file-redirection

#c++ #output #xcode #redirection
star

Sat Apr 17 2021 00:49:25 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688332?%24web_only=true&~channel=email&~stage=published&utm_medium=email&utm_campaign=email&utm_source=sendgrid.com&_branch_match_id=890253272865013170#questions/14628310/

#c++
star

Thu Apr 15 2021 19:48:48 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688274#questions/10258738

#c++
star

Thu Apr 15 2021 17:02:27 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688272#questions/14617278

#c++
star

Thu Apr 15 2021 16:53:13 GMT+0000 (UTC)

#c++
star

Wed Apr 14 2021 17:38:00 GMT+0000 (UTC) https://www.udemy.com/course/learn-advanced-c-programming/learn/lecture/3688272#questions/14612872/

#c++
star

Thu Apr 08 2021 21:39:39 GMT+0000 (UTC) https://stackoverflow.com/questions/10359702/c-filehandling-difference-between-iosapp-and-iosate#:~:text=ios%3A%3Aapp%20%22set%20the,file%20when%20you%20open%20it.&text=The%20ios%3A%3Aate%20option,to%20the%20end%20of%20file.

#c++
star

Fri Apr 02 2021 11:14:20 GMT+0000 (UTC)

#c++
star

Tue Mar 30 2021 13:35:34 GMT+0000 (UTC)

#c++
star

Mon Mar 29 2021 15:48:43 GMT+0000 (UTC) https://stackoverflow.com/questions/11938979/what-exception-classes-are-in-the-standard-c-library

#c++
star

Wed Mar 17 2021 04:14:46 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 02:53:18 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 01:58:37 GMT+0000 (UTC)

#c++
star

Wed Mar 17 2021 01:57:12 GMT+0000 (UTC)

#c++
star

Wed Mar 10 2021 03:42:55 GMT+0000 (UTC)

#c++
star

Tue Jan 26 2021 22:43:21 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Jan 21 2021 20:17:57 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Jan 20 2021 22:02:30 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Jan 09 2021 02:24:44 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Jan 08 2021 09:33:32 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Jan 07 2021 06:42:04 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Jan 06 2021 21:53:09 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Jan 02 2021 17:54:04 GMT+0000 (UTC)

#c++
star

Tue Dec 29 2020 11:21:13 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Dec 28 2020 03:44:59 GMT+0000 (UTC)

#c++
star

Sun Dec 20 2020 11:27:54 GMT+0000 (UTC) https://stackoverflow.com/questions/29995863/how-to-add-custom-code-snippets-in-vscode

#c++
star

Fri Dec 18 2020 02:16:44 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Dec 11 2020 20:09:09 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Dec 09 2020 03:00:16 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Thu Nov 26 2020 14:13:55 GMT+0000 (UTC)

#c++
star

Wed Nov 25 2020 01:54:07 GMT+0000 (UTC)

#c++
star

Sun Nov 15 2020 04:08:15 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 15 2020 02:54:42 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Fri Nov 13 2020 03:52:42 GMT+0000 (UTC)

#c++
star

Thu Nov 12 2020 14:28:30 GMT+0000 (UTC)

#c++
star

Tue Nov 10 2020 22:42:18 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Nov 10 2020 16:12:46 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Nov 09 2020 07:53:26 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Mon Nov 09 2020 01:01:29 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sun Nov 08 2020 23:35:48 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Nov 07 2020 03:20:33 GMT+0000 (UTC) https://www.geeksforgeeks.org/lambda-expression-in-c/

#c++
star

Fri Nov 06 2020 17:32:33 GMT+0000 (UTC)

#c++
star

Fri Nov 06 2020 15:00:33 GMT+0000 (UTC)

#c++
star

Fri Nov 06 2020 14:49:48 GMT+0000 (UTC)

#c++
star

Thu Nov 05 2020 20:47:39 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Tue Oct 27 2020 02:55:57 GMT+0000 (UTC) https://zerojudge.tw/ShowProblem?problemid

#c++
star

Sun Oct 25 2020 03:45:41 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Sat Oct 24 2020 11:35:47 GMT+0000 (UTC) http://cpp.sh/

#c++
star

Wed Oct 21 2020 08:25:33 GMT+0000 (UTC) https://www.javatpoint.com/fibonacci-series-in-cpp

#c++ #fibonacci
star

Wed Oct 21 2020 07:59:21 GMT+0000 (UTC)

#c++
star

Wed Oct 14 2020 22:19:09 GMT+0000 (UTC)

#c++
star

Wed Oct 14 2020 18:44:50 GMT+0000 (UTC)

#c++
star

Fri Sep 11 2020 14:28:11 GMT+0000 (UTC) https://www.technical-recipes.com/2011/simple-binary-tree-implementation/

#c++
star

Wed Dec 25 2019 10:57:06 GMT+0000 (UTC) https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/

#c++ #algorithms #interviewquestions #arrays

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension