Snippets Collections
from collections import deque

visited_states = []
total_moves = 70
expanded = 0
count = 0

class Node:
    def __init__(self, state, parent, operator, depth, cost):
        self.state = state
        self.parent = parent
        self.operator = operator
        self.depth = depth
        self.cost = cost

def create_node(state, parent, operator, depth, cost):
    return Node(state, parent, operator, depth, cost)

def expand_node(node):
    expanded_nodes = []
    
    temp_state = move_down(node.state)
    temp_node = create_node(temp_state, node, "down", node.depth + 1, node.cost + 1)
    expanded_nodes.append(temp_node)

    temp_state1 = move_up(node.state)
    temp_node1 = create_node(temp_state1, node, "up", node.depth + 1, node.cost + 1)
    expanded_nodes.append(temp_node1)

    temp_state2 = move_left(node.state)
    temp_node2 = create_node(temp_state2, node, "left", node.depth + 1, node.cost + 1)
    expanded_nodes.append(temp_node2)

    temp_state3 = move_right(node.state)
    temp_node3 = create_node(temp_state3, node, "right", node.depth + 1, node.cost + 1)
    expanded_nodes.append(temp_node3)

    return expanded_nodes

def move_left(state):
    swap = state.copy()
    idx = swap.index(0)
    if (idx == 0 or idx == 3 or idx == 6):
        return swap
    else:
        swap[idx - 1], swap[idx] = swap[idx], swap[idx - 1]
        return swap

def move_right(state):
    swap = state.copy()
    idx = swap.index(0)
    if (idx == 2 or idx == 5 or idx == 8):
        return swap
    else:
        swap[idx + 1], swap[idx] = swap[idx], swap[idx + 1]
        return swap

def move_up(state):
    swap = state.copy()
    idx = swap.index(0)
    if (idx == 0 or idx == 1 or idx == 2):
        return swap
    else:
        swap[idx - 3], swap[idx] = swap[idx], swap[idx - 3]
        return swap

def move_down(state):
    swap = state.copy()
    idx = swap.index(0)
    if (idx == 6 or idx == 7 or idx == 8):
        return swap
    else:
        swap[idx + 3], swap[idx] = swap[idx], swap[idx + 3]
        return swap

def bfs(start, goal):
    if (start == goal):
        return [None]
    else:
        to_be_expanded = []
        current_node = create_node(start, None, None, 0, 0)
        to_be_expanded.append(current_node)

        for i in range(total_moves):
            temp_expanded = []
            size = len(to_be_expanded)

            for j in range(size):
                if (to_be_expanded[j] in visited_states):
                    continue

                node_array = expand_node(to_be_expanded[j])

                for x in range(4):
                    if (node_array[x].state == goal):
                        count = i + 1
                        return node_array[x]
                    else:
                        temp_expanded.append(node_array[x])
                        visited_states.append(node_array[x].state)

            to_be_expanded.clear()
            to_be_expanded = temp_expanded.copy()
            temp_expanded.clear()

    return None

def main():
    method = 'bfs'
    length = 0
    x = 0
    x = x + 1

    board_input = input("Enter the initial state values (comma-separated): ")
    board_split = board_input.split(',')
    starting_state = [int(i) for i in board_split]

    goal_input = input("Enter the goal state values (comma-separated): ")
    goal_split = goal_input.split(',')
    goal_state = [int(i) for i in goal_split]

    if (len(starting_state) == 9 and len(goal_state) == 9):
        result = bfs(starting_state, goal_state)
        if result == None:
            print("No solution found")
        elif result == [None]:
            print("Start node was the goal!")
        else:
            print("Total number of moves needed =", result.cost)
            path = []
            path.append(result.state)
            current = result
            flag = True

            while flag:
                parent = current.parent
                prev_state = parent.state
                path.append(prev_state)
                current = parent

                if (prev_state == starting_state):
                    flag = False

            path.reverse()
            print("Step-wise Sequence of states from start to goal is ")
            for state in path:
                print(state[0], "|", state[1], "|", state[2])
                print(state[3], "|", state[4], "|", state[5])
                print(state[6], "|", state[7], "|", state[8])
                print()
    else:
        print("Invalid input")

if __name__ == "__main__":
    main()


The introduction of computerized technology in the healthcare sector - the promised to bring a qualitative change to patient one. While in various ways there was a bump in the service they received, patients should have experienced higher value all over the board. 

Let’s see some of the examples of integration of Healthcare and blockchain technology. 

Remote Patient Monitoring (RPM)

RMP should to have allowed the shift from episodic to preventative healthcare delivery. This should have been feasible with proactive patient monitoring with "Internet of Things" (IoT) approved devices. The RMP market is predicted to reach $535 Million in united states. RMP devices collect PHI, which needs protection, therefore, a private blockchain is the right choice in this case.
Smart contracts on this private blockchain analyze patient health data.

Electronic Medical Records (EMRs)

EMRs record patient data in the format of electronical, that should have reduced the requirement of paper-based processes. This should have permitted multiple healthcare providers to seamlessly access patient data. This was supposed to significantly enhance the provision of healthcare services. To secure EMRs, Medicalchain uses Hyperledger Fabric, an enterprise blockchain.

There are many healthcare blockchain business ideas that have significant potential. However, integrating any of these ideas is a complex process. Blockchain development requires a lot of expertise and planning, so you might want to get proficient help.
#include <iostream>
using namespace std;

string ending(int sum, int cash) {
  const string s = "купюр";
  const string end1 = "a";
  const string end2 = "ы";
  string banknote;

  sum /= cash;

  if (sum > 4 && sum < 21 || sum > 24 && sum % 10 > 4 
    && sum % 10 <= 9 && sum % 10 == 0 || sum == 0) banknote = s;
  if (sum == 1 || sum % 10 == 1) banknote = s + end1;
  if (sum > 1 && sum < 5 || sum % 10 > 1 
    && sum % 10 < 5)  banknote = s + end2;
  
  return banknote;
}

int remainder(int sum, int cash) {
  sum -= 1;

  if (sum >= 100 && sum != 0 && sum / cash != 0) {
    cout << sum / cash << " - " << ending(sum, cash) << " " << cash << " руб.\n";
  }
  return sum;
}

int main() {
  system("clear");
  
  int sum;
  cout << "Введите сумму, которую хотите обналичить : ";
  cin >> sum;
  sum += 1;
  
  if (sum > 100 && sum < 150000 && sum % 100 == 1) {

    int cash = 5000;
    remainder(sum, cash);
      cash = 2000; sum = sum % 5000;
    remainder(sum, cash);
      cash = 1000; sum = sum % 2000;
    remainder(sum, cash);
      cash = 500; sum = sum % 1000;
    remainder(sum, cash);
      cash = 200; sum = sum % 500;
    remainder(sum, cash);
      cash = 100; sum = sum % 200;
    remainder(sum, cash);

  } else {
    cout << "Не корректная сумма для вывода денег.";
  }
}
#include <iostream>
using namespace std;

int main() 
{
  int mansCount;
  int barbersCount;
  int mansPerBarber = 8; // один человек в час, смена 8 часов
  int mansPerBarberPerMonth = mansPerBarber * 30;
/*
mansCount;               - КолМужчин
barbersCount;            - КолБарберов
mansPerBarber            - КолПодстриженныхЗаСмену
mansPerBarberPerMonth    - КолПодстриженныхЗаМесяц
NecessaryNumberBarbers   - НеобходимоеКолБарберов
BarbersRequired          - ТребуемыеБарберы
*/
  cout << "\n************ Барбершоп-калькулятор ************\n\n";
back:
  cout << "Введите число мужчин в городе: ";
  cin >> mansCount;
  if (mansCount <= 0) {
    cout << "\nВы не можете ввести нулевое или отрицательное значение...\n";
    cout << "Попробуйте ещё раз.\n\n";
    goto back;
  }
back1:
  cout << "Сколько уже барберов удалось нанять? ";
  cin >> barbersCount;
  if (barbersCount <= 0) {
    cout << "\nВы не можете ввести нулевое или отрицательное значение...\n";
    cout << "Попробуйте ещё раз.\n\n";
    goto back1;
  }
  
  cout << "\nОдин барбер стрижёт " << mansPerBarberPerMonth << " клиентов в месяц.\n";

  // Сколько нужно барберов, чтобы постричь mansCount человек?
  int NecessaryNumberBarbers = mansCount / mansPerBarberPerMonth;
  
  if (NecessaryNumberBarbers * mansPerBarberPerMonth % mansCount) {
    NecessaryNumberBarbers += 1;
  }
  
  cout << "Необходимое число барберов: " << NecessaryNumberBarbers << "\n\n";

    const string b = "барбер";
    const string end1 = "a";
    const string end2 = "ов";
  
    string endin;
    int n = NecessaryNumberBarbers;
    if (n == 1 || (n > 20 && n % 10 == 1)) endin = b;
    else if (n > 1 && n < 5 || n > 20 && n % 10 > 1 && n % 10 < 5) endin = b + end1;
    else endin = b + end2;

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

    string ending;
    int nb = NecessaryNumberBarbers - barbersCount;
    if (nb == 1 || (nb > 20 && nb % 10 == 1)) ending = b;
    else if (nb > 1 && nb < 5 || nb > 20 && nb % 10 > 1 && nb % 10 < 5) ending = b + end1;
    else ending = b + end2;

  int BarbersRequired = NecessaryNumberBarbers - barbersCount;

  if (NecessaryNumberBarbers > barbersCount) {
    cout << "Требуется ещё " << BarbersRequired << " " << ending << ".\n";
  } else if (NecessaryNumberBarbers == barbersCount) {
    cout << "Барберов ровно столько, сколько нужно!!!\n";
  } else if (barbersCount % NecessaryNumberBarbers == 0) {
    cout << "У вас работает в " << barbersCount / NecessaryNumberBarbers << " раза больше барберов, чем это нужно!!!\n";
  } else cout << "Барберов хватает!!!\n";
}
#include <iostream>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
// #include<bits/stdc++.h>
using namespace std;
#define forn(i, a, n) for (int i = a; i < n; i++)
#define MAXN 1000000
#define MOD 1000000007
#define int long long
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define TC size(arr) / size(arr[0])
#define mp make_pair
#define Radhe ios::sync_with_stdio(false);
#define Krishna cin.tie(NULL);

int Time = 0;
vector<pair<int, int>> br;
set<pair<int, int>> res;

vector<int> low, disc;
vector<vector<int>> adj;

void dfsBR(int u, int p)
{
    low[u] = disc[u] = ++Time;
    for (int &v : adj[u])
    {
        if (v == p)
            continue; // we don't want to go back through the same path.
                      // if we go back is because we found another way back
        if (!disc[v])
        {
            res.insert({u, v});
            // if V has not been discovered before
            dfsBR(v, u);          // recursive DFS call
            if (disc[u] < low[v]) // condition to find a bridge
                br.push_back({u, v});

            low[u] = min(low[u], low[v]); // low[v] might be an ancestor of u
        }
        else // if v was already discovered means that we found an ancestor
        {
            if (low[u] >= disc[v])
            {
                low[u] = min(low[u], disc[v]); // finds the ancestor with the least discovery time
                res.insert({u, v});

            }else{
                if(res.find({v,u})==res.end()){
                    res.insert({u,v});
                }
            }

        }
    }
}

void BR()
{
    low = disc = vector<int>(adj.size(), 0);
    Time = 0;
    for (int u = 0; u < adj.size(); u++)
    {
        if (!disc[u])
        {
            dfsBR(u, u);
        }
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;
    adj.resize(n);
    forn(i, 0, m)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    BR();

    if (br.size())
    {
        cout << 0 << endl;
        return;
    }

    // cout<<br.size()<<endl;
    for (auto &x : res)
    {
        cout << x.first + 1 << " " << x.second + 1 << endl;
    }
}
int32_t main()
{
    Radhe Krishna
    {
        solve();
    }

    return 0;
}
// adj[u] = adjacent nodes of u
// ap = AP = articulation points
// p = parent
// disc[u] = discovery time of u
// low[u] = 'low' node of u

int dfsAP(int u, int p) {
  int children = 0;
  low[u] = disc[u] = ++Time;
  for (int& v : adj[u]) {
    if (v == p) continue; // we don't want to go back through the same path.
                          // if we go back is because we found another way back
    if (!disc[v]) { // if V has not been discovered before
      children++;
      dfsAP(v, u); // recursive DFS call
      if (disc[u] <= low[v]) // condition #1
        ap[u] = 1;
      low[u] = min(low[u], low[v]); // low[v] might be an ancestor of u
    } else // if v was already discovered means that we found an ancestor
      low[u] = min(low[u], disc[v]); // finds the ancestor with the least discovery time
  }
  return children;
}

void AP() {
  ap = low = disc = vector<int>(adj.size());
  Time = 0;
  for (int u = 0; u < adj.size(); u++)
    if (!disc[u])
      ap[u] = dfsAP(u, u) > 1; // condition #2
}
   for(int k=0;k<26;k++){
        for(int j=0;j<26;j++){
            for(int i=0;i<26;i++){
                if(W[i][k]!=3000 && W[k][j]!=3000)
                W[i][j]=min(W[i][j],W[i][k]+W[k][j]);
            }
        }
    }
#include <iostream>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
// #include<bits/stdc++.h>
using namespace std;
#define forn(i, a, n) for (int i = a; i < n; i++)
#define MAXN 1000000
#define MOD 1000000007
#define INT_MAX 1e12
#define int long long
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define TC size(arr) / size(arr[0])
#define Radhe ios::sync_with_stdio(false);
#define Krishna cin.tie(NULL);
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int>>> adj(n);
    map<pair<int, int>, int> mp;
    vector<int> par(n, -1);
    for (int i = 0; i < m; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        if (u == v)
        {
            continue;
        }
        if (v < u)
        {
            swap(u, v);
        }
        u--, v--;
        
        
        if (mp.count({u, v}))
        {
            mp[{u, v}] = min(mp[{u, v}], w);
        }
        else
        {
            mp[{u, v}] = w;
        }
    }
    
for  (auto i = mp.begin(); i != mp.end(); i++) 
    { auto x=*i;
        adj[x.first.first].push_back({x.first.second,x.second});
        adj[x.first.second].push_back({x.first.first,x.second});
    }

    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
    vector<int> dist(n, INT_MAX);
    dist[0] = 0;
    pq.push({0, {0, -1}});
    while (!pq.empty())
    {
        int u = pq.top().second.first;
        if(pq.top().first>dist[u])
        {
            pq.pop();
            continue;
        }
        par[u] = pq.top().second.second;
        pq.pop();
        for (auto it : adj[u])
        {
            int v = it.first;
            int weight = it.second;
            if (dist[u] == INT_MAX)
            {
                continue;
            }
            if (dist[v] > dist[u] + weight)
            {
                dist[v] = dist[u] + weight;
                pq.push({dist[v], {v, u}});
            }
        }
    }
   
    if(dist[n-1]==INT_MAX)
    {
        cout<<-1<<endl;
        return;
    }
    vector<int> ans;
    int i = n - 1;
    while (i != -1)
    {
        ans.push_back(i + 1);
        i = par[i];
    }
    for(int i=ans.size()-1;i>0;i--)
    {
        cout<<ans[i]<<" ";
    }
    cout<<ans[0]<<endl;
}
int32_t main()
{
    Radhe Krishna
    {
        solve();
    }

    return 0;
}
#include <iostream>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
// #include<bits/stdc++.h>
using namespace std;
#define forn(i, a, n) for (int i = a; i < n; i++)
#define MAXN 1000000
#define MOD 1000000007
#define int long long
#define tc    \
    int t;    \
    cin >> t; \
    while (t--)
#define TC size(arr) / size(arr[0])
#define mp make_pair
#define Radhe ios::sync_with_stdio(false);
#define Krishna cin.tie(NULL);

vector<vector<int>> graph;
int tot = 0;

void findComponent(int u, vector<int> &disc, vector<int> &lowLink, stack<int> &stk, vector<bool> &stkItem)
{
    static int time = 0;
    disc[u] = lowLink[u] = ++time;
    stk.push(u);
    stkItem[u] = true;

    for (auto x : graph[u])
    {
        {
            if (disc[x] == -1)
            {
                findComponent(x, disc, lowLink, stk, stkItem);
                lowLink[u] = min(lowLink[u], lowLink[x]);
            }
            else if (stkItem[x])
                lowLink[u] = min(lowLink[u], disc[x]);
        }
    }
    int poppedItem = 0;

    if (lowLink[u] == disc[u])
    {
        int co = 0;

        while (stk.top() != u)
        {
            poppedItem = stk.top();
            co++;
            stkItem[poppedItem] = false;
            stk.pop();
        }
        poppedItem = stk.top();
        co++;
        stkItem[poppedItem] = false;
        stk.pop();

        if (co > 1)
        {
            tot += co;
        }
    }
}

void strongConComponent(vector<vector<int>> &graph)
{
    int v = graph.size();
    vector<int> disc(v, -1), lowLink(v, -1);
    vector<bool> stkItem(v, false);
    stack<int> stk;

    for (int i = 0; i < v; i++)
        if (disc[i] == -1)
            findComponent(i, disc, lowLink, stk, stkItem);
}

void solve()
{

    tot = 0;
    int n;
    cin >> n;
    graph = vector<vector<int>>(n);
    forn(i, 0, n)
    {
        char x;
        cin >> x;
        if (x == '<')
        {
            graph[(i + 1) % n].push_back(i);
        }
        else if (x == '>')
        {
            graph[i].push_back((i + 1) % n);
        }
        else
        {
            graph[i].push_back((i + 1) % n);
            graph[(i + 1) % n].push_back(i);
        }
    }

    strongConComponent(graph);
    cout << tot << endl;
}
int32_t main()
{
    Radhe Krishna
        tc
    {
        solve();
    }

    return 0;
}
// br = bridges, p = parent

vector<pair<int, int>> br;

int dfsBR(int u, int p) {
  low[u] = disc[u] = ++Time;
  for (int& v : adj[u]) {
    if (v == p) continue; // we don't want to go back through the same path.
                          // if we go back is because we found another way back
    if (!disc[v]) { // if V has not been discovered before
      dfsBR(v, u);  // recursive DFS call
      if (disc[u] < low[v]) // condition to find a bridge
        br.push_back({u, v});
      low[u] = min(low[u], low[v]); // low[v] might be an ancestor of u
    } else // if v was already discovered means that we found an ancestor
      low[u] = min(low[u], disc[v]); // finds the ancestor with the least discovery time
  }
}

void BR() {
  low = disc = vector<int>(adj.size());
  Time = 0;
  for (int u = 0; u < adj.size(); u++)
    if (!disc[u])
      dfsBR(u, u)
}
Bitcoin Miner Script holding a hash algorithm that executes the mining activity in a simple and effective way. Whenever a user tries to access the data for transactions, the script verifies the ledger system automatically that matches the private key to proceed with the transactions. The Bitcoin miner script is developed with the ability to support other features that includes:

Payment gateways
Ticket system
Plan management
Genealogy
Multiple currencies
Promotional banners
E-pin generation facility
Multiple languages

It was a Good approach to move ahead based on the up-gradation of technology. The usage of cryptocurrencies are really high, so that the opportunities to create a business website are in good state to yield benefits as well. Visit Best bitcoin miner script to know more about the ideal features of the script. 

> https://maticz.com/bitcoin-mining-script
#include <bits/stdc++.h>
using namespace std;

// Main function to run the program
int main() 
{ 
    int arr[] = {10, 30, 10, 20, 10, 20, 30, 10}; 
    int n = sizeof(arr)/sizeof(arr[0]); 

    int visited[n];

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

        if(visited[i]!=1){
           int count = 1;
           for(int j=i+1; j<n; j++){
              if(arr[i]==arr[j]){
                 count++;
                 visited[j]=1;
              }
            }

            cout<<arr[i]<<" occurs at "<<count<<" times "<<endl;
         }
     }

    return 0; 
}
#include <stdio.h>
#include <string.h>

#define MAX_ATTEMPTS 3
#define MAX_USERS 5
#define MAX_USERNAME_LENGTH 20
#define MAX_PASSWORD_LENGTH 20

typedef struct {
    char username[MAX_USERNAME_LENGTH];
    char password[MAX_PASSWORD_LENGTH];
} User;

int main() {
    User users[MAX_USERS] = {
        {"user1", "pass1"},
        {"user2", "pass2"},
        {"user3", "pass3"},
        {"user4", "pass4"},
        {"user5", "pass5"}
    };

    int attempts = 0;
    int authenticated = 0;

    while (attempts < MAX_ATTEMPTS && !authenticated) {
        char inputUsername[MAX_USERNAME_LENGTH];
        char inputPassword[MAX_PASSWORD_LENGTH];

        printf("Enter username: ");
        scanf("%s", inputUsername);
        printf("Enter password: ");
        scanf("%s", inputPassword);

        for (int i = 0; i < MAX_USERS; i++) {
            if (strcmp(inputUsername, users[i].username) == 0 && strcmp(inputPassword, users[i].password) == 0) {
                authenticated = 1;
                break;
            }
        }

        if (!authenticated) {
            attempts++;
            printf("Authentication failed, try again.\n");
        }
    }

    if (authenticated) {
        printf("Authentication successful.\n");
    } else {
        printf("Limit exceeded. Exiting.\n");
    }

    return 0;
}
class Solution {
public:
    vector<int> countBits(int n) {
        vector<int> v(n+1, 0);
        for(int i=1;i<=n;i++)
        {
            int p=i;
            int t=32;
            int ans=0;
            
            while(p!=0)
            {
                int rsbm = p&-p;
                p-=rsbm;
                ans++;
            }
            v[i]=ans;
        }
        return v;
    }
};
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
        char *cat="/bin/cat";
    if(argc<2)
        {
                printf("Please type a file name.\n");
                return 1;
        }
     char *command =malloc(strlen(cat) + strlen(argv[1]) + 2);
        sprintf(command,"%s %s", cat,argv[1]);
        system((command));
        return 0;
}
Developing a Rummy Game can be a lucrative endeavor, But it is important to consider its various factors such as the game’s design, complexity, platform compatibility, and back-end infrastructure all crucially determine the overall expenditure. Hiring freelance rummy game developers or partnering with a proficient rummy game development company can also impact the final price tag.

A simple Rummy game with important features and minimalistic graphics could set you back anywhere from $10000 to $40000. On the other hand, if your vision includes an intricate, cross-platform game with attractive visuals, the cost will be up to $35000 to $200000 or more., Thus, before you initiate looking for rummy game developers for hire, you must first determine what you are planning to build.

https://maticz.com/rummy-game-development
#include <bits/stdc++.h>

using namespace std;

struct node {
  int data;
  struct node * left, * right;
};

vector < int > postOrderTrav(node * cur) {

  vector < int > postOrder;
  if (cur == NULL) return postOrder;

  stack < node * > st;
  while (cur != NULL || !st.empty()) {

    if (cur != NULL) {
      st.push(cur);
      cur = cur -> left;
    } else {
      node * temp = st.top() -> right;
      if (temp == NULL) {
        temp = st.top();
        st.pop();
        postOrder.push_back(temp -> data);
        while (!st.empty() && temp == st.top() -> right) {
          temp = st.top();
          st.pop();
          postOrder.push_back(temp -> data);
        }
      } else cur = temp;
    }
  }
  return postOrder;

}

struct node * newNode(int data) {
  struct node * node = (struct node * ) malloc(sizeof(struct node));
  node -> data = data;
  node -> left = NULL;
  node -> right = NULL;

  return (node);
}

int main() {

  struct node * root = newNode(1);
  root -> left = newNode(2);
  root -> right = newNode(3);
  root -> left -> left = newNode(4);
  root -> left -> right = newNode(5);
  root -> left -> right -> left = newNode(8);
  root -> right -> left = newNode(6);
  root -> right -> right = newNode(7);
  root -> right -> right -> left = newNode(9);
  root -> right -> right -> right = newNode(10);

  vector < int > postOrder;
  postOrder = postOrderTrav(root);

  cout << "The postOrder Traversal is : ";
  for (int i = 0; i < postOrder.size(); i++) {
    cout << postOrder[i] << " ";
  }
  return 0;
}
#include <vector>
#include <stack>

using namespace std;

// Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    vector<int> inorderTraversal(TreeNode* root) {
        stack<TreeNode*> st;
        vector<int> inorder;

        TreeNode* node = root;

        while (true) {
            if (node != nullptr) {
                st.push(node);
                node = node->left;
            } else {
                if (st.empty())
                    break;

                node = st.top();
                st.pop();
                inorder.push_back(node->val);

                node = node->right;
            }
        }

        return inorder;
    }
};
#include <vector>
#include <stack>

using namespace std;

// Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    vector<int> preorderTraversal(TreeNode* root) {
        vector<int> preorder;

        if (root == nullptr)
            return preorder;

        stack<TreeNode*> st;
        st.push(root);

        while (!st.empty()) {
            root = st.top();
            st.pop();
            preorder.push_back(root->val);

            if (root->right != nullptr) {
                st.push(root->right);
            }

            if (root->left != nullptr) {
                st.push(root->left);
            }
        }

        return preorder;
    }
};
//level order traversal ---->  lecture 8 striver 

#include <vector>
#include <queue>

using namespace std;

// Definition for a binary tree node.
struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> ans;

        if (root == nullptr)
            return ans;

        queue<TreeNode*> q;
        q.push(root);

        while (!q.empty()) {
            int size = q.size();
            vector<int> level;

            for (int i = 0; i < size; i++) {
                TreeNode* node = q.front();
                q.pop();

                if (node->left != nullptr)
                    q.push(node->left);
                if (node->right != nullptr)
                    q.push(node->right);

                level.push_back(node->val);
            }

            ans.push_back(level);
        }

        return ans;
    }
};

//iterative preorder traversal
Blockchain businesses have gained tremendous popularity in the upcoming years. Many companies are showing keen interest in the field of blockchain, so it is the perfect time for blockchain to rise. Because blockchain is a distributed and p2p technology, its major benefits, and application can be found in almost every sector. You can turn this blockchain use into your Blockchain business idea if you solely understand the technology.


​#include <iostream>

using namespace std;

int main()
{
    int a,b,s;
    cin >>a>>b;
    s=a+b;
    cout <<s;

    return 0;
}
Are you interested in the crypto world and want to explore new ways of trading? Do you have a knack for coding and want to develop your own crypto trading bot? If yes, you have come to the right place! Creating a crypto trading bot from scratch can sound threatening, but it is quite easier and can potentially yield great results. 

However, for the ultimate security and reliability, it is best to know how to create a trading bot for crypto if you want to make Bitcoin trading a significant portion of your revenue. Want to create your own crypto trading bot? Then Maticz can assist you to build your own trading bot in a hassle-free manner. Check out the website and get more information via >> https://maticz.com/how-to-create-a-crypto-trading-bot
Video games are a massive industry with over 59 billion USD in sales in 2015. The process of creating a video game is much more complicated than you might think, that involves a number of various disciplines and cross-generational teamwork. We have broken down the process into its component pieces so that you can see what roles each team member plays to make something like Overwatch possible.

Early Pre production:

Art Direction
Gameplay Design
Planning
Documents
Designing
Testing
Implementation
Product release

Post Production:

Marketing
Distribution
Support
Post Maintainance
End of Life

This is when the next generation of video games may be created, and when a game is retired, it is no longer eligible for future development. However, the developers may continue to work on it, but without official support.

#include <iostream>
using namespace std;

bool prompt_yes_or_no(const string& question) {
    cout << question << " (Y/N): ";
    char response;
    cin >> response;
    return (response == 'Y' || response == 'y');
}

void join_farm_out_project_teams() {
    cout << "Welcome to our Farm-out project teams!" << endl;
}

int main() {
    if (prompt_yes_or_no("Are you inspired to make the world a better place?")
        && prompt_yes_or_no("Do you want to be part of projects that cover the entire process, "
                            "from edge to cloud and from driver to (front-end) application?")
        && prompt_yes_or_no("Do you want to work on (big scaled) high-tech systems?")
        && prompt_yes_or_no("Do you enjoy responsibility and leadership roles?")
        && prompt_yes_or_no("Do you love challenges in complex architecture for distributed systems?")) {
        join_farm_out_project_teams();
    } else {
        cout << "Thank you for considering us! Keep exploring new opportunities!" << endl;
    }

    return 0;
}
for i=1 to n
   for j=1 to n    
     c[i][j]=0
     for k=1 to n
         c[i][j] = c[i][j]+a[i][k]*b[k][j]
Peer to Peer (P2) Cryptocurrency exchanges have emerged as a popularized and innovative solution for trading digitalized assets. Startups seeking to enter the crypto market can greatly benefit from investing in P2P Crypto exchange development. Let’s see the process included in P2P Exchange development:

Decentralized Trading Experience

Startups can leverage this decentralized trading experience to attract users who value privacy, security, and control over their assets. By offering a platform that facilitates direct peer-to-peer transactions, startups can differentiate themselves from traditional centralized exchanges and tap into a growing demand for decentralized trading solutions.

Enhanced Trust and Security

P2P Crypto Exchanges prioritize security by integrating features such as Multi-factor Authentication, Bitcoin escrow script services, and smart contracts, These security measures instill trust among users.

Market Access Globally

Developing a P2P Crypto exchange has a globalized reach, allowing startups to target users from various regions and countries. By supporting multi languages and local payment methods, startups can assure accessibility and inclusivity for a diverse user base. 

Revenue Generation

P2P crypto exchanges provide various avenues for revenue generation. Startups can implement transaction fees, listing fees, premium memberships, or even integrate advertisement opportunities. 

Benefits of P2P Exchange Development

Investing in P2P exchange development can provide startups with a competitive edge in the cryptocurrency industry. By offering a decentralized trading experience, enhanced security and trust, global market access, and revenue generation opportunities, startups can position themselves as innovative players in the market. However, to ensure a successful development process, it is crucial for startups to hire a reliable and experienced P2P exchange development company.

Partnering with a professional P2P exchange development company is essential for startups aiming to create a robust and feature-rich platform. These companies possess expertise in blockchain technology, security protocols, and user experience design. They can guide startups through the entire development process, from conceptualization to deployment, ensuring a seamless and efficient launch.

In conclusion, startups should seize the opportunity presented by P2P crypto exchange development. By investing in this innovative solution, startups can establish themselves as key players in the evolving cryptocurrency landscape and unlock significant growth potential in the digital asset trading industry.
vector<vector<int>> dp;
Solution(): dp(1000, vector<int>(1000,-1));
int knapSack(int W, int wt[], int val[], int n) {
  if(W==0 || n==0) return 0;
  if(dp[W][n]!=-1) return dp[W][n];
  if(wt[n-1]<=W){
    return dp[W][n]=max(
      val[n-1]+knapSack(W-wt[n-1], wt, val, n-1),
      knapSack(W, wt, val, n-1)
    );
  } else {
    return dp[W][n]=knapSack(W, wt, val, n-1);
  }
}
int knapSack(int W, int wt[], int val[], int n) 
{ 
   if(W==0 || n==0) return 0;
   if(wt[n-1]<=W){
       return max(
         val[n-1] + knapSack(W-wt[n-1], wt, val, n-1), 
         knapSack(W, wt, val, n-1)
       );
   }
   else {
       return knapSack(W, wt, val, n-1);
   }
}
The future of Binance Clone Script in the crypto industry looks promising. With the increasing popularity of cryptocurrencies, many businesses and individuals are looking to enter the market. Binance Clone script provides an effortless and cost-effective way for entrepreneurs to launch their own crypto exchange platforms. Initiating a thriving binance clone business requires careful planning and execution. Here are some of the tips that can assist entrepreneurs to launch a successful Binance clone business:

Market Research

Conduct detailed market research to identify the target audience and competition. This will assist entrepreneurs to understand the market trends and customer needs.

Choose the proper script

Prefer a highly reliable and trustworthy Binance clone script provider that renders cutting-edge security features and customizable options. 

Licensing & Jurisdictions

Make sure that the crypto exchange platform complies with the legal and regulatory needs of the country where the business operates. 

User Experience

The success of a Binance-like platform relies heavily on its user experience. It is crucial to prioritize user-friendliness and ease of navigation to assure that the platform is intuitive and easy to use.

Marketing

Develop a comprehensive marketing strategy to reach out to potential customers. Use various marketing channels, such as social media, email marketing, and advertising, to promote the platform.
class Solution {
public:
    using ll = long long;
    int countBits(ll x){
        int cnt = 0;
        while(x > 0){
            cnt += (x&1);
            x>>=1;
        }
        return cnt;
    }
    int makeTheIntegerZero(int num1, int num2) {
        if(num1 < num2)
            return -1;
        ll x = num1;
        for(int i = 0; i <= 100; i++){
            ll val = x - (ll)i*num2;
            int cnt_ones = countBits(val);
            if(cnt_ones <= i && i <= val)
                return i;
        }
        return -1;
    }
};
void print(TrieNode* root, string t,vector<string>& s ){
        int cnt_nulls = 0;
        for(int i = 0; i < 26; i++){
            if(root->v[i] != NULL){
                char c = (i + 'a');
                // cout << c << endl;
                t.push_back(c);
                print(root->v[i] , t, s);
                t.pop_back();
            }
            else cnt_nulls++;
        }
        if(cnt_nulls == 26)
            s.push_back(t);
    }
class Solution {
  public:
    map<int,int> deno{
        {5,0},
        {10,0},
        {20,0}
    };
    bool canCreateDeno(int x){
       for(auto i = deno.rbegin(); i != deno.rend();i++){
           if(i->second > 0 ){
               int times = (x / i->first);
               times = min(times, i->second);
               x -= times * i->first;
               i->second -= times;
           }
       } 
       return x == 0;
    }
    bool lemonadeChange(int N, vector<int> &bills) {
        // code here
        for(int i = 0 ; i < N; i++){
            int x = bills[i] - 5;
            if(x == 0){
                deno[bills[i]]++;
            }
            else{
                bool f = canCreateDeno(x);
                if(!f)
                    return false;
                deno[bills[i]]++;
            }
        }
        return true;
    }
};
class Solution{
    public:
    // arr: input array
    // n: size of array
    //Function to rearrange an array so that arr[i] becomes arr[arr[i]]
    //with O(1) extra space.
    void arrange(long long v[], int n) {
        // Your code here
        for(int i= 0; i < n; i++){
            if(v[i] >= 0){
                int val = -v[i], ini = i, p = i;
                while( v[p] != ini){
                    int t = v[p];
                    v[p] = v[t];
        		    if(v[p] == 0)
        			    v[p] = INT_MIN;
        		    else
        			    v[p] *= -1;
            		p = t;
                }
                v[p] = val;
            }
        }
        for(int i= 0; i <n ;i++)
            if(v[i] != INT_MIN)
                v[i] *= -1;
            else
                v[i] = 0;
    }
};
class Solution {
public:
    const int mod = 1e9 + 7;
    int m, n;
    vector<int> dx{1,0,0,-1},dy{0,1,-1,0};
    bool isValid(int x, int y){
        return x >= 0 and x < m and y >= 0 and y < n;
    }
    int dfs(int x, int y, vector<vector<int>>& grid, vector<vector<int>>& dp){
        if(dp[x][y] != -1)
            return dp[x][y];
        int ans = 1;
        for(int i = 0; i < 4; i++){
            int x_ = x + dx[i], y_ = y + dy[i];
            if(isValid(x_, y_) and grid[x_][y_] >grid[x][y])
                ans = (ans%mod + dfs(x_,y_,grid, dp)%mod)%mod;
        }
        return dp[x][y] = ans;
    }
    int countPaths(vector<vector<int>>& grid) {
        m = grid.size(), n = grid[0].size();
        vector<vector<int>> dp(m + 1, vector<int> ( n + 1, -1));
        int ans = 0;
        for(int i = 0; i < m; i++)
            for(int j = 0;j <n ;j++)
                ans = (ans%mod + dfs(i, j,grid, dp));
        return ans;
    }
};
class Solution {
public:
    int numOfWays(vector<int>& nums) {
        int m = nums.size();
        
        table.resize( m + 1);
        for(int i = 0; i < m + 1; ++i){
            table[i] = vector<long long> (i+1, 1);
            for(int j = 1; j < i ; ++j)
                table[i][j] = (table[i-1][j-1] + table[i-1][j])%mod;
        }
        return (dfs(nums) - 1) % mod;
    }
private:
    vector<vector<long long>> table;
    long long mod = 1e9+7;
    
    long long dfs(vector<int>& nums){
        int m = nums.size();
        if( m  < 3)
            return 1;
        vector<int> leftNodes, rightNodes;
        for(int i = 1; i < m ; i++){
            if( nums[i] < nums[0])
                leftNodes.push_back(nums[i]);
            else
                rightNodes.push_back(nums[i]);
        }
        long long leftWays = dfs(leftNodes) % mod;
        long long rightWays = dfs(rightNodes) % mod;
        return (((leftWays * rightWays) % mod) * table[m-1][leftNodes.size()])%mod;
    }
};
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int ARRAY_SIZE = 100;

int *R; 

void generateRandomNumbers() {
    int i;
    R = (int *)malloc(ARRAY_SIZE * sizeof(int));
    if (R == NULL) {
        printf("Memory allocation failed.\n");
        exit(1);
    }

    srand(time(NULL));
    for (i = 0; i < ARRAY_SIZE; i++) {
        R[i] = i + 1;
    }

    for (i = ARRAY_SIZE - 1; i > 0; i--) {
        int j = rand() % (i + 1);
        int temp = R[i];
        R[i] = R[j];
        R[j] = temp;
    }
}

int encrypt(int p) {
    int i, c = 0;
    for (i = 0; i < p; i++) {
        c += R[i];
    }
    return c;
}

int decrypt(int c) {
    int i, sum = 0;
    for (i = 0; i < ARRAY_SIZE; i++) {
        sum += R[i];
        if (sum >= c) {
            return i + 1;
        }
    }
    return -1;
}

int main() {
    int plainValues[] = {92, 95, 22};
    int cipher[] = {0,0,0};

    generateRandomNumbers();

    printf("Encryption:\n");
    for (int i = 0; i < 3; i++) {
        cipher[i] = encrypt(plainValues[i]);
        printf("Plain: %d\tCipher: %d\n", plainValues[i], cipher[i]);
    }

    printf("\nDecryption:\n");
    for (int i = 0; i < 3; i++) {
        int plain = decrypt(plainValues[i]);
        printf("Cipher: %d\tPlain: %d\n",cipher[i] , plainValues[i]);
    }

    free(R); // Free the allocated memory

    return 0;
}
class Solution {
public:
    typedef long long ll;
    
    int maxLevelSum(TreeNode* root) {
        vector<int> levels(1e5, 0);
        queue<pair<int,TreeNode*>> q;
        if(!root)
            return 0;
        q.push({0, root});
        int lvls_reached = 0;
        while(!q.empty()){
            auto node(q.front().second);auto lvl(q.front().first);
            q.pop();
            levels[lvl] += node->val;
            lvls_reached = max(lvls_reached, lvl);
            if(node->left)
                q.push({lvl + 1, node->left});
            if(node->right)
                q.push({lvl + 1, node->right});
        }
        ll maxi = LLONG_MIN;
        int ans = -1;
        for(int i = 0; i <=lvls_reached; i++)
            if(levels[i] > maxi)
                ans = i, maxi = levels[i];
        return ans + 1;
    }
};
class Solution {
  public:
    string longestPalin (string S) {
        // code here
        if(S.length() == 0)
            return "";
        string ans;
        pair<int,int> r{0,0};
        int len = 1, n = S.length();
        for(int i = 0 ; i < n; i++){
            int j = i, k =i;
            while(j-1 >= 0 && k+1 < n){
                if(!(S[j-1] == S[k+1]))
                    break;
                j--,k++;
            }
            int l1 = k - j + 1;
            pair<int,int> p1{j,k},p2{i,i};
            int l2 = 1;
            if( i +1 < n){
                bool f = (S[i] == S[i+1]);
                if(f){
                    j = i, k = i+1;
                    while( j-1 >=0 && k+1 < n){
                        if(!(S[j-1] == S[k+1]))
                            break;
                        j--,k++;
                    }
                    l2 = k - j + 1;
                    p2 = {j,k};
                }
            }
            if(len < max(l1,l2)){
                len = max(l1,l2);
                r = (l1 > l2)?p1:p2;
            }
        }
        for(int i = r.first; i<=r.second;i++)
            ans += S[i];
        return ans;
    }
};
class Solution{
    public:
int randomPartition(int arr[], int l, int r)
    {
        int n = r-l+1;
        int pivot = rand() % n;
        swap(arr[l + pivot], arr[r]);
        return partition(arr, l, r);
    }
    int kthSmallest(int arr[], int l, int r, int k)
    {
        // If k is smaller than number of elements in array
        if (k > 0 && k <= r - l + 1)
        {
            // find a position for random partition
            int pos = randomPartition(arr, l, r);
            
            // if this pos gives the kth smallest element, then return
            if (pos-l == k-1)
                return arr[pos];
                
            // else recurse for the left and right half accordingly
            if (pos-l > k-1)  
                return kthSmallest(arr, l, pos-1, k);
            return kthSmallest(arr, pos+1, r, k-pos+l-1);
        }
    
        return INT_MAX;
    }
     
    // partitioning the array along the pivot
    int partition(int arr[], int l, int r)
    {
        int x = arr[r], i = l;
        for (int j = l; j <= r - 1; j++)
        {
            if (arr[j] <= x)
            {
                swap(arr[i], arr[j]);
                i++;
            }
        }
        swap(arr[i], arr[r]);
        return i;
    }
};
​#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long rez;
    rez = 1LL * n * (n + 1) / 2;
    cout << rez;
    return 0;
}
class Solution
{
    public:
    //Function to find the maximum number of meetings that can
    //be performed in a meeting room.
    int maxMeetings(int start[], int end[], int n)
    {
        // Your code here
        using pi = pair<int,int> ;
        vector<pi> vp;
        for(int i = 0; i < n; i++)
            vp.push_back({start[i] , end[i]});
        sort(vp.begin(), vp.end(),[](auto a, auto b){
           return a.second < b.second; 
        });
        int ans = 0, r = INT_MIN;
        for(int  i =0 ; i < n ; i++){
            if(vp[i].first > r){
                ans++;
                r = vp[i].second;
            }
        }
        return ans;
    }
};
    void print(vector<int>& v){
        for(auto ele : v)
            cout << ele << " ";
        cout<< endl;
    }
    void backtrack(int index, vector<int> ans){
        if(index == (ans.size() - 1)){
            print(ans);
            return;
        }
        for(int i = index; i < ans.size(); i++){
            swap(ans[index], ans[i]);
            backtrack(index+1, ans);
            swap(ans[index], ans[i]);
        }
    }
class Solution {
  public:
    //Function to return a list of indexes denoting the required 
    //combinations whose sum is equal to given number.
    void solve(int indx, int target, vector<int> &A, vector<vector<int>> &ans, vector<int> ds){
        if(target==0){ 
    		ans.push_back(ds);
    		return;
    	}
    	//returning if conditions are out of bound.
    	if(target<0 || indx>=A.size()) 
    		return;
        
        ds.push_back(A[indx]);
        solve(indx, target-A[indx], A, ans, ds);
        ds.pop_back();
        solve(indx+1, target, A, ans, ds);
    }
    
    vector<vector<int> > combinationSum(vector<int> &A, int B) {
        // Your code here
        vector<int> ds;
        vector<vector<int>> ans;
        sort(A.begin(), A.end());
        solve(0, B, A, ans, ds);
    }
};
#include <iostream>
#include <vector>

class Person {
public:
    Person(int id) : id(id) {}

    int getId() const {
        return id;
    }

private:
    int id;
};

class Building {
public:
    Building(int levels) : levels(levels) {
        constructBuilding();
    }

    void constructBuilding() {
        int totalPeople = (1 << levels) - 1; // Calculate the total number of people in the building
        people.resize(totalPeople);

        // Create people with their respective IDs
        for (int i = 0; i < totalPeople; ++i) {
            people[i] = Person(i + 1);
        }
    }

    void exitOrder() {
        for (int i = levels - 1; i >= 0; --i) {
            int levelOffset = (1 << i) - 1; // Offset for each level
            int levelSize = (1 << i); // Number of people on each level

            for (int j = 0; j < levelSize; ++j) {
                int personIndex = levelOffset + j;
                std::cout << people[personIndex].getId() << " ";
            }
        }
        std::cout << std::endl;
    }

    void entryOrder() {
        for (int i = 0; i < levels; ++i) {
            int levelOffset = (1 << i) - 1; // Offset for each level
            int levelSize = (1 << i); // Number of people on each level

            for (int j = 0; j < levelSize; ++j) {
                int personIndex = levelOffset + j;
                std::cout << people[personIndex].getId() << " ";
            }
        }
        std::cout << std::endl;
    }

private:
    int levels;
    std::vector<Person> people;
};

int main() {
    int levels;
    std::cout << "Enter the number of levels in the building: ";
    std::cin >> levels;

    Building building(levels);

    std::cout << "Exit Order: ";
    building.exitOrder();

    std::cout << "Entry Order: ";
    building.entryOrder();

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


struct Client{
    string name;
    int phoneNumber;
};

class HashTable {
public:
    static const int size=10;
    Client table[size];
    int collisions[size];
    
    int hash(int key) { return key%size; }
    
    HashTable() { for(int i=0;i<size;i++) collisions[i]=0; }
    
    //function for linear probing
    void linearprobing(Client client){
     
    int index=hash(client.phoneNumber);
    int count=0;
    
    while(collisions[index]==1){
        index=(index+1)%size;
        count++;
    }
    
    table[index]=client;
    collisions[index]=1;
    cout<<"Inserted "<<client.name<<"'s phone number after "<<count<<" collisions using linear probing."<<endl;
 }
  
//function for quadratic probing  
 void quadraticprobing(Client client){
     
    int index=hash(client.phoneNumber);
    int count=0;
    while(collisions[index]!=0 && collisions[index]!=client.phoneNumber){
        count++;
        index=(hash(client.phoneNumber)+count*count)%size;
    }
    table[index]=client;
    collisions[index]=1;
    cout<<"Inserted "<<client.name<<"'s phone number after "<<count<<" collisions using quadratic probing."<<endl;
 }
 
 bool search(int phoneNumber){
    int index=hash(phoneNumber);
    int count=0;
    while(collisions[index]!=0) {
        if(table[index].phoneNumber==phoneNumber){
            cout<<"Found "<<table[index].name<<"'s phone number after "<<count <<" comparisons using linear probing."<< endl;
            return true;
        }
        index=(index+1)%size;
        count++;
    }
    cout<<"Phone number not found."<<endl;
    return false;
}
    
};


int main()
{
    HashTable ht;
    int number;
    string name;
    int x=11, y;
    
    while(x!=0){
        cout<<"\n1.INSERT NUMBER\n2.SEARCH NUMBER\n0.EXIT\nEnter your choice:";
        cin>>x;
 
        switch(x){
            
                case 1:
                  cout<<"\nEnter name:";
                  cin>>name;
                  cout<<"Enter number:";
                  cin>>number;
                  cout<<"\n\n1.Linear probing\n2.Quadratic probing\nEnter your option:";
                  cin>>y;
            
                  if(y==1) ht.linearprobing({name, number});
                  else if(y==2) ht.quadraticprobing({name, number});
                  else cout<<"Error! invalid option\n\n";
                break;
                
                case 2:
                  cout<<"\nEnter number to search:";
                  cin>>number;
                  ht.search(number);
                break;
                
                case 0:
                  cout<<"\nExiting\n\n";
                break;
                
                default:
                  cout<<"\nInvalid choice!!\nEnter again\n\n";
                break;
                }
    }
 return 0;
}
//code heapsort

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

class Heap{
    int n;
    int *minheap, *maxheap;
    
    public:
    void get();
    void displaymin(){
        cout <<"minimum number is: "<<maxheap[0]<<endl;
    }
    void displaymax(){
        cout<<"maximun number is: "<<minheap[0]<<endl;
    }
    void upadjust(bool,int);
};

void Heap::get(){
    cout<<"enter the number of entries you want: ";
    cin >> n;
    minheap= new int[n];
    maxheap= new int[n];
    
    cout <<"enter numbers :"<<endl;
    for(int i=0; i<n; i++){
        int k;
        cin >>k;
        minheap[i]=k;
        upadjust(0,i);
        maxheap[i]=k;
        upadjust(1,i);
    }
}

void Heap::upadjust(bool m, int l){
    int s;
    if(!m){
        while(minheap[(l-1)/2]<minheap[l]){
            swap(minheap[l], minheap[(l-1)/2]);
            l=(l-1)/2;
            
            if(l== -1) break;
        }
      
    }else{
        while(maxheap[(l-1)/2]>maxheap[l]){
            swap(maxheap[l], maxheap[(l-1)/2]);
            l=(l-1)/2;
            
            if(l== -1) break;
        }
    }
}



int main(){
    int choice;
    cout<<"1. min heap"<<endl;
    cout<<"2. max heap"<<endl;
    cout<<"enter your choice: "<<endl;
    cin >>choice;
    
    Heap h;
    
    switch(choice){
        case 1:
            h.get();
            h.displaymax();
            break;
        case 2:
            h.get();
            h.displaymax();
            break;
        return(0);
    }
    
    return 0;
}
#include <iostream>
#include<queue>
#include <string>
using namespace std;

struct patient{
    string name;
    int priority;
};

bool operator<(const patient &a, const patient &b){return a.priority<b.priority;}

int main(){
    priority_queue<patient> q;
    
    int choice;
    do{
        cout<<"1. add patient"<<endl;
        cout<<"2. treat patient"<<endl;
        cout<<"3. exit"<<endl;
        cout<<"enter your choice: "<<endl;
        cin>>choice;
        
        switch(choice){
            case 1:
            {
                patient p;
                cout<<"enter patient name: "<<endl;
                cin>>p.name;
                cout<<"priority-> 1. serious 2. non serious 3. general checkup\n enter priority"<<endl;
                cin >>p.priority;
                q.push(p);
                cout<<"patient added successfully"<<endl;
            }
            break;
            
            case 2:
            {
                if(q.empty()){cout<<"no patient in the queue"<<endl;}
                else{cout<<"serving patient "<<q.top().name<<endl;}
                q.pop();
            }
            break;
            
            case 3:cout<<"thank you! visit again!"<<endl;
            break;
            
            default:cout<<"Enter a valid choice"<<endl;
        }
    }while(choice!=3);
    
    return 0;
}
class UnionFind 
{
    public: 
    vector<int> parent,count;
    UnionFind(int n){
        parent.resize(n, -1);
        count.resize(n, 1);
    }
    int find(int x){
        return (this->parent[x] == -1)? x : find(this->parent[x]);
    }
    void Union(int a, int b){
        int pA = find(a) , pB = find(b);
        if(pA != pB){
            this->parent[pB] = pA;
            this->count[pA] += this->count[pB];
        }
        
    }
};
#include <bits/stdc++.h>
using namespace std;

int solve(vector<vector<int>>& dp, int idx, int cw, int w, vector<int>& v)
{
   if(cw==w) return ++dp[idx][cw];
   if(cw>w||idx==v.size()) return 0;
   if(dp[idx][cw]!=0) return dp[idx][cw];
   
   return dp[idx][cw]=solve(dp, idx+1, cw+v[idx], w, v)+solve(dp, idx+1, cw, w, v);
}

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        int n, w;
	        cin>>n>>w;
	        vector<int>a(n);
	        for(int i=0;i<n;i++)
	        {
	           cin>>a[i];
	        }
	        vector<vector<int>> dp(n+1, vector<int>(w+1, 0));
	        int ans = solve(dp, 0, 0, w, a);
	        cout<<ans;
	}
	return 0;
}
class Solution {
    using Index = pair<int, int>;
    vector<Index> directions =
    {
        {-1, -1},
        {-1, 0},
        {-1, 1},
        {0, -1},
        {0, 1},
        {1, -1},
        {1, 0},
        {1, 1}
    };

public:
    int shortestPathBinaryMatrix(vector<vector<int>>& grid)
    {
        const int n = grid.size();
        if (grid[0][0] == 1 || grid[n - 1][n - 1] == 1)
            return -1;

        if (n == 1)
            return 1;
        
        int distance = 1;
        Index target = {n - 1, n - 1};
        queue<Index> q;
        q.push({0, 0});
        grid[0][0] = 1;
        while (!q.empty())
        {
            const int levelSize = q.size();
            for (int i = 0; i < levelSize; i++)
            {
                Index curr = q.front();
                q.pop();
                for (const Index& diff : directions)
                {
                    Index next = {curr.first + diff.first, curr.second + diff.second};
                    if (next.first >= 0 && next.first < n && next.second >= 0 && next.second < n 
                        && grid[next.first][next.second] == 0)
                    {
                        if (next == target)
                            return distance + 1;
                        grid[next.first][next.second] = 1;
                        q.push(next);
                    }
                }
            }
            distance++;
        }
        return -1;
    }
};
	vector<int> topoSort(int V, vector<int> adj[]) 
	{
	    // code here
	    vector<int> res;
	    vector<int> indegree( V , 0);
	    
	    for(int i = 0 ; i < V ; i++)
	        for(int nbr : adj[i])
	            indegree[nbr]++;
        queue<int> q;
        for(int i = 0; i < V; i++)
            if(indegree[i] == 0)
                q.push(i);
        
        while(!q.empty()){
            int curr = q.front(); q.pop();
            res.push_back(curr);
            for(int nbr : adj[curr])
                if(--indegree[nbr] == 0)
                    q.push(nbr);
        }
        return res;
	}
 template <typename T> std::string type_name();
        const char f = 'C';
    int maxLen(vector<int>&A, int n)
    {   
        // Your code here
        unordered_map<long long ,int> uMap;
        uMap.insert({0, 1});
        int ans = 0 ;
        long long currSum = 0;
        for(int i = 0 ; i < n ; i++){
            currSum += A[i];
            if(uMap[currSum] > 0)
                ans = max(ans, i - uMap[currSum]  + 2);
            else
                uMap[currSum] = i + 2;
        }
        return ans;
    }
    int LargButMinFreq(int arr[], int n) {
        // code here
        priority_queue<int> pq;
        for(int i = 0; i < n ; i++){
            pq.push(arr[i]);
        }
        int ans = 0,minFreq = INT_MAX;
        while(!pq.empty()){
            int val = pq.top(),freq = 1;
            pq.pop();
            while(!pq.empty() && pq.top() == val){
                pq.pop() , freq++;
            }
            if(freq < minFreq)
                minFreq = freq, ans = val;
        }
        return ans;
    }
void print(vector<int>& arr){
		for(auto ele : arr)
			cout<<ele<<" ";
		cout<<endl;
		}
	void maxHeapify(int i, vector<int>& arr, int n){
		vector<int> arr = this->arr;
		int left = 2*i + 1 , right = 2*i+2;
		int largest = i;
		if( left < n && arr[left] > arr[largest])
			largest = left;
		if(right < n && arr[right] > arr[largest])
			largest = right;
		if(largest != i){
			swap(arr[largest] , arr[i]);
			maxHeapify(largest, arr , n);
		}
	}

	void formMaxHeap(vector<int>& arr){
		int n = arr.size();
		int r = (n/2) -1;
		for(int i = r; i>=0; i--){
			maxHeapify(i, arr, n);
		}
	}
	int extract_max(vector<int>& arr){
		int val = arr.front();
		swap(arr.front(), arr.back());
		arr.pop_back();
		int size= arr.size();
		maxHeapify(0, arr, size);
		return val;
	}
	void heapSort(vector<int>& arr){
		int n = arr.size() ;
		formMaxHeap(arr);
		for(int r  = n-1 ; r > 0 ; r--){
			swap(arr[0], arr[r]);
			maxHeapify(0, arr, r );
		}

	}
    int uniquePaths(int m, int n) {
        int N = m + n - 2, r = min(m, n)-1;
        long long p = 1;
        for(int i = 1 ; i <= r; i++){
            p = (p *(N - i + 1))/i;
        }
        return p;
    }
class Solution {
public:

    bool solve(vector<int>& nums, int sum, int curr, int idx, vector<vector<int>>& dp)
    {
        if(curr==sum) return true;
        if(curr>sum||idx==nums.size()) return false;
        if(dp[curr][idx]!=-1) return dp[curr][idx];
        bool ck=false;

        ck=ck|solve(nums, sum, curr+nums[idx], idx+1, dp);
        ck=ck|solve(nums, sum, curr, idx+1, dp);
        return dp[curr][idx]=ck;
    }

    bool canPartition(vector<int>& nums) {
        int s=0;
        int n=nums.size();
        
        for(int i=0;i<n;i++)
        {
            s+=nums[i];
        }
        vector<vector<int>> dp(s+1, vector<int>(nums.size(), -1));
        if(s%2==1) return false;
        
        else return solve(nums, s/2, 0, 0, dp);

    }
};
class Solution {
  public:
  class TrieNode{
    public:
        vector<TrieNode*> v;
        int indices ;
        
        TrieNode(){
            v.resize(26,NULL);
            indices = -1;
        }
        ~TrieNode(){
            v.clear();
        }
    };
    void dfs(TrieNode* curr, vector<string>& ans,vector<string>& Dictionary){
        if(curr->indices != -1)
            ans.push_back(Dictionary[curr->indices]);
        for(int i = 0 ; i < 26; i++){
            if(curr->v[i] != NULL)
                dfs(curr->v[i], ans, Dictionary);
        }
    }
    void push(string word,TrieNode* root ){
        static int i =0;
        TrieNode* currRoot = root;
        for(char letter:word){
            if(letter >='a' && letter <='z')
                continue;
            letter = tolower(letter);
            if(currRoot->v[letter - 'a'] == NULL)
                currRoot->v[letter - 'a'] = new TrieNode();
            currRoot = currRoot->v[letter-'a'];
        }
        currRoot->indices = i++;
    }

    vector<string> CamelCase(int N, vector<string> Dictionary, string Pattern) {
        // code here
        TrieNode* root = NULL;
        root = new TrieNode();
        for(auto word : Dictionary){
            push(word, root);
        }
        TrieNode* curr = root;
        for(auto chr : Pattern){
            chr = tolower(chr);
            if(curr->v[chr-'a'] == NULL)
                return {"-1"};
            curr = curr->v[chr- 'a']; 
        }
        vector<string> ans;
        dfs(curr, ans,Dictionary);
        return ans;
    }
};
class Solution{   
public:

    bool solve(vector<int>&arr, int sum, int curr, int idx, vector<vector<int>>& dp)
    {
        if(curr==sum) return true;
        if(curr>sum||idx==arr.size()) return false;
        if(dp[curr][idx]!=-1) return dp[curr][idx];
        bool ck=false;
        ck=ck|solve(arr, sum, curr+arr[idx], idx+1, dp);
        ck=ck|solve(arr, sum, curr, idx+1, dp);
        return dp[curr][idx]=ck;
        
    }
    
    bool isSubsetSum(vector<int>arr, int sum){
        // code here 
        vector<vector<int>> dp(100000, vector<int> (arr.size(), -1));
       return solve(arr, sum, 0, 0, dp);
    }
};
    int maxIncreasingCells(vector<vector<int>>& mat) {
        int n = mat.size(), m = mat[0].size();
        unordered_map<int,vector<pair<int,int>>> mp;
        set<int> st;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                mp[mat[i][j]].push_back({i,j});
                st.insert(-mat[i][j]);
            }
        }
        vector<vector<int>> val(n, vector<int>(m));
        vector<int> rowPath(n), colPath(m);
        for(auto num : st){
            num = -num;
            for(auto pos : mp[num]){
                int r = pos.first;
                int c = pos.second;
                val[r][c] = max(rowPath[r], colPath[c]) + 1;
            }
            
            for(auto pos : mp[num]){
                int r = pos.first;
                int c = pos.second;
                rowPath[r] = max(rowPath[r], val[r][c]);
                colPath[c] = max(colPath[c], val[r][c]);
            }
        }
        int ans = 0;
        for(auto len : rowPath)
            ans = max(len ,ans);
        for(auto len : colPath)
            ans = max(len , ans);
        return ans;
    }
int getNthFromLast(Node *head, int n)
{
       // Your code here
       Node* front = head; 
       while(front && n--)front = front->next;
       if(n>0)
        return -1;
       Node* rear = head;
       while(front){
           front = front->next;
           rear = rear->next;
       }
       return rear->data;
}
vector<int> sieve(int n){
    int size = sqrt(n);
    bool primes[size+1];
    memset(primes,true,size+1);
    primes[0] = primes[1] = false;
    for(int i = 2; i <= size; i++){
        if(primes[i]){
            int k = 2;
            while(i*k <= size){
                primes[i*k] = false;
                k++;
            }
        }
    }
    vector<int> ans;
    for(int i = 0 ; i<= size; i++)
        if(primes[i])
            ans.push_back(i);
    return ans;

}
    int solve(int ind ,pair<int,int> alphaBeta, vector<int>& stoneValue, bool isAlice ,pair<int,int> points ={0,0}){
        if(ind >= stoneValue.size()){
            if(points.first == points.second)
                return 0;
            return points.first > points.second ? 1 : -1;
        }
        if(isAlice){
            int maxi = INT_MIN;
            int score = points.first;
            for(int i = ind; i < ind+3 && i < stoneValue.size(); i++){
                score += stoneValue[i];
                int eva = solve(i+1,alphaBeta,stoneValue, !isAlice,{score, points.second});
                maxi = max(maxi, eva);
                alphaBeta.first = max(alphaBeta.first, maxi);
                if(alphaBeta.second <= alphaBeta.first)
                    break;
            }
            return maxi;
        }
        else{
            int mini = INT_MAX;
            int score = points.second;
            for(int i = ind; i < ind+3  && i < stoneValue.size(); i++){
                score += stoneValue[i];
                int eva = solve(i+1,alphaBeta,stoneValue, !isAlice,{points.first, score});
                mini = min(mini, eva);
                alphaBeta.second = min(mini, alphaBeta.second);
                if(alphaBeta.second <= alphaBeta.first)
                    break;
            }
            return mini;
        }
    }
        if(!head || head->next  == NULL)
            return head;
        Node* fast = head->next->next,*slow = head;
        while(fast->next && fast->next->next){
            fast = fast->next->next;
            slow = slow->next;
        }
        if(fast != NULL)
            slow = slow->next;
        Node* head2 = reverse(slow->next);
        slow->next =  NULL;
    Node* reverse(Node* head){
        if(!head || !head->next){
            return head;
        }
        Node* newHead = reverse(head->next);
        head->next->next = head;
        head->next = NULL;
        return newHead;
    }
class Solution {
public:
    int nextGreaterElement(int n) {
       string s=to_string(n);
       next_permutation(s.begin(),s.end());
       if(stoll(s)>n&&stoll(s)<=INT_MAX)
       {
          return stoll(s);
       }
       return -1;

    }
};
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int n=s.size();
        int cnt[256]={0};
        int i=0, j=0, ans=0;
        while(j<n)
        {
            cnt[s[j]]++;
            while(cnt[s[j]]>1)
            {
                cnt[s[i]]--;
                i++;
                
            }
            ans=max(ans, j-i+1);
            j++;
        }
        return ans;
    }
};
void printFibonacci(int n) {
    FILE* file = fopen("/var/www/vusers/TIFACyournameone/Fib.txt", "w");
    if (file == NULL) {
        printf("Failed to open file\n");
        return;
    }

    int fib1 = 0;
    int fib2 = 1;
    int fib;
    fprintf(file, "%d\n%d\n", fib1, fib2);

    for (int i = 2; i < n; i++) {
        fib = fib1 + fib2;
        fprintf(file, "%d\n", fib);
        fib1 = fib2;
        fib2 = fib;
    }

    fclose(file);
    printf("Fibonacci series written to Fib.txt\n");
}

int main() {
    int n;
    printf("Enter the number of Fibonacci series terms: ");
    scanf("%d", &n);
    printFibonacci(n);
    return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

int main()
{
    // Vector of integers
    std::vector<int> vecObj {11, 12, 13, 14, 15, 16, 12, 43, 12, 13, 11};

    // Sort the values in vector
    std::sort(vecObj.begin(), vecObj.end());

    // Remove duplicate values from vector
    vecObj.erase(std::unique(vecObj.begin(), vecObj.end()), vecObj.end());

    // print all elements of vector
    for(auto elem : vecObj) {
        std::cout<<elem << ", ";
    }

    return 0;
}
void RemoveDuplicate(struct Node *p){
 
  Node *q= first->next;

  while(q!=NULL){
    if(p->data != q->data){
      p=q;
      q=q->next;
    }else{
      p->next= q->next;
      delete q;
      q= p->next;
    }
  }
}
int isSorted(struct Node *p){
  
  x= INT_MIN;

  while(p!=NULL){
    if(p->data<x)
      return false;
    x=p->data;
    p=p->next;
  }
  return true;
}
#include <iostream>
#include <string>
using namespace std;

int main()

{
     int yearnow;
     int monthnow;
     int yearborn;
     int monthborn;
     int daynow;
     int dayborn;
     

     
     cout << "Enter the current year: ";
     cin >> yearnow;
     cout << "Enter the current month: ";
     cin >> monthnow;
     cout << "Enter the current day: ";
     cin >> daynow;
     cout << "Enter the year when you were born: ";
     cin >> yearborn;
     cout << "Enter the month when you were born: ";
     cin >> monthborn;
     cout << "Enter the day when you were born: ";
     cin >> dayborn;
     
     int yearactual = yearnow - yearborn;
     
     if (monthborn > monthnow){
             
             cout << "You are " << yearactual - 1 << " years old\n";
             cout << "You are " << 12 - (monthborn - monthnow) - 1 << " months old\n";
             cout << "And " << daynow << " days old";
         
     }
     if (monthborn < monthnow){
         if (daynow > dayborn){
             
             cout << "You are " << yearactual << " years old\n";
             cout << "You are " << monthnow - monthborn << " months old\n";
             cout << "And " << daynow - dayborn << " days old";
             
         }
         if (daynow < dayborn){
             
              cout << "You are " << yearactual << " years old\n";
             cout << "You are " << monthnow - monthborn - 1<< " months old\n";
             cout << "And " << daynow << " days old";
             
         }
         if (daynow == dayborn){
             
              cout << "You are " << yearactual << " years old\n";
             cout << "You are " << monthnow - monthborn << " months old\n";
             cout << "And " << "0" << " days old";
             
         }
         
     }
      if (monthborn == monthnow){
         cout << "You are " << yearactual << " years old\n";
         cout << "You are " << "0" << " months old\n";
         cout << "And " << daynow << " days old";
     }
     
     
     
     return 0;
}
int Delete(struct Node *p, int index){
  Node *q;
  int x=-1 , i;
  
  if(index < 1 || index >count(p))
    return -1;
  
  if(index==1){
    x=first->data;
    q=first;
    first=first->next;
    delete q;
    return x;
  } 
  else{
    for(i=0; i<index-1 && p; i++){
      q=p;
      p=p->next;
    }
    q->next=p->next;
    x=p->data;
    delete p;
    return x;
    }
}
void SortedInsert(struct Node *p, int x){
  
  struct Node *t, *q= NULL;
  t= (struct Node *)malloc(sizeof(struct Node));
  t->data= x;
  t->next= NULL;
  
  if (first == NULL)
    first = t;
  else{
    while(p && p->data <x){
      q=p;
      p=p->next;
      }
    if (p==first){
      t->next=first;
      first=t;
    } else {
      t->next = q->next;
      q->next= t;
    }
  }
}
void InsertLast(int x){
  Node *t = x;
  t->data= x;
  t->next= NULL;
  if(first==NULL){
    first= last= t;
  } else {
    last->next= t;
    last=t;
  }
}
void Insert(int pos, int x){
  Node *t, *p;
  if(pos==0){
    t= new Node;
    t->data= x;
    t->next= first;
    first= t;
  }
  else if(pos>0){
    p = first;
    for(i=0; i<pos-1; i++)
      p=p->next;
    if(p){
      t= new Node;
      t->data= x;
      t->next = p->next;
      p->next= t;
    }
  }
}
//inserting a new node at the first; at the head of the linked list

Node *t = new Node;
t->data=x;
t->next = first;
first= t;

//inserting a new node after a given node
Node *t= new Node;
t->data= x;
p=first;
for(i=0; i<pos-1; i++){
  p =p->next;
  t->next= p->next;
  p->next= t;
}
//move to front
//improve searching by moving the searched node to the front so that another time it is searched, it will be found in less time
//function for moving a node to the head (in search operation)

Search(Node *p, int key){
  
  Node *q= NULL;
  
  while(p!= NULL){
    if(key==p->data) {
      q-next= p->next;
      p->next= first;
      first = p;
    }
    q= p;
    p=p->next;
  }
}
//iterative
Search(Node *p, int key){
  while(p!=NULL){
    if(key==p->data)
      return p;
    p= p->next;
  }
  return NULL;
}

//recursive
Node* Search(Node *p, int key){
  if(p==NULL)
    return NULL;
  if(key==p->data)
    return p;
  return Search(p->next, key);
}
//MIN_INT= -32768

//iterative function
max(Node *p){
  int m= INT32_MIN;
  while(p){
    if(p->data > m)
      m=p->data;
    p=p->next;
  }
  return m;
}

//recursive function
max(Node *p){
  int x=0;
  if(p==0)
    return INT32_MIN;
  else
    x= max(p->next);
  
  if(x>p->data)
  	return x;
  else
    return p->data;
}
//using iteration
int Add(struct Node *p){
  int sum=0;
  while(p){
    sum= sum+ p->data;
    p= p->next;
  }
  return(sum);
}

//using recursion
int Add(struct node *p){
  if (p==0)
    return(0);
  else
    return Add(p->next) + p->data;
}

//the data will be added at the time of returning
//code for finding number of nodes in a given linked list: recursive

int count(struct Node *p){
int c=0;
	while(p!= 0) {
	c++;
	p=p->next;
	}
return c;
}
// O(n) time complexity and O(1) space complexity

//recursive function for counting number of nodes in a given linked list

int count(struct Node *p){
  if(p==0)
    return 0;
  else
    return count(p->next)+1;
}

// addition will be done at the time of returning.
// time complexity : O(n)
//space complexity : O(n) for stack as it includes recursion
//print in the given order as first the value is printed and then a call is made to the next node

void Display(struct Node *p){
  if (p!= NULL){
    printf("%d", p->data);  //first print
    Display(p->next);       //call next
  }
}

//print in reverse order as first the call is made and then the values are printed

void Display(struct Node *p){
  if (p!= NULL){
    Display(p->next);          //call next
    printf("%d", p->data);     //then print
  }
}
Cryptocurrency development is the process of creating a digital currency that is secured by cryptography and operates independently of a central authority. It involves designing and building a blockchain-based platform that allows for secure, transparent, and decentralized transactions. The cryptocurrency market is rapidly growing, and businesses are increasingly looking to integrate blockchain technology into their operations. A reputable cryptocurrency development company like Shamla Tech can provide valuable expertise and guidance to ensure a successful implementation. Shamla Tech specializes in providing comprehensive blockchain solutions to clients, including the creation of new cryptocurrencies, blockchain-based software applications, and custom smart contract development. 

Know more: https://shamlatech.com/cryptocurrency-development/
#include <stdio.h>
#include <stdlib.h>

struct Node{
    int data;
    struct Node *next;
}*first=NULL;

void create(int A[10], int n){
    int i;
    struct Node *t, *last;
    first = (struct Node *)malloc(sizeof(struct Node));
    first->data=A[0];
    first->next=NULL;
    last=first;
    
    for(i=1;i<n;i++){
        t=(struct Node*)malloc(sizeof(struct Node));
        t->data=A[i];
        t->next=NULL;
        last->next=t;
        last=t;
    }
}

void Display(struct Node *p){
    while(p!=NULL){
        printf("%d ",p->data);
        p=p->next;
    }
}

int main() {
    int A[]={3,5,7,10,15};
    create(A,5);
    Display(first);
  
    return 0;
}
class Solution{
public:
      string maxSum(string w,char x[], int b[],int n){
          // code here        
          unordered_map<char,int> mp;
          for(int i=0;i<w.size();i++)
          {
              mp[w[i]]=int(w[i]);
          }
          for(int i=0;i<n;i++)
          {
              mp[x[i]]=b[i];
          }
          vector<int> v(w.size());
          for(int i=0;i<w.size();i++)
          {
              v[i]=mp[w[i]];
          }
          
          int edx=0, mxl=0, mxg=INT_MIN;
          for(int i=0;i<w.size();i++)
          {
              mxl=max(v[i], v[i]+mxl);
              
              if(mxl>mxg)
              {
                  mxg=mxl;
                  edx=i;
              }
          }
          int sdx=edx;
          while(sdx>=0)
          {
              mxg-=v[sdx];
              if(mxg==0) break;
              if(sdx==0) break;
              sdx--;
          }
          
          
          string ans="";
          for(int i=sdx;i<=edx;i++)
          {
              ans+=w[i];
          }
          return ans;
      }
};
class Solution {
  public:
    long long countBits(long long N) {
        // code here
        long long ans = 0;
        N += 1;
        int D = log2(N) + 1;
        vector<long long> pow2(D+1,0);
        pow2[0] = 1;
        pow2[1] = 2;
        for(int i = 2; i <=D; i++){
            pow2[i] = 2*pow2[i-1];
        }
        for(int i = 1 ; i <= D ; i++){
            long long t = 0;
            int gN = (N + pow2[i] - 1)/pow2[i];
            t += (gN - 1) * pow2[i-1];
            int v = N%pow2[i];
            long long p = (v == 0) ? pow2[i] : v;
            t += max(0LL , p - pow2[i-1]);
            ans += t;
        }
        return ans;
    }
    
};
var currentTab = 0; // Current tab is set to be the first tab (0)
let inputs = []

let eye2 = 0;
var speed = 15;
var text = "";

const content = document.getElementById("content");

var socket = io.connect();

let responses = []
let questionNumber = 0
let quizID = localStorage.getItem("myID");

window.addEventListener('load', function () {

  showTab(currentTab); // Display the current tab

  let testString = "qustion| answer1| answer2| asnwer3| answer4| correct" //test
  // document.getElementById("testButton").addEventListener('click', function test() {
  //   displayQuestions(testString)
  // }) //test
})


function showTab(n) {
  // This function will display the specified tab of the form ...
  var x = document.getElementsByClassName("tab");
  x[n].style.display = "block"; //?
  // ... and fix the Previous/Next buttons:
  if (n == 0) {
    document.getElementById("prevBtn").style.display = "none";
  } else {
    document.getElementById("prevBtn").style.display = "inline";
  }
  if (n == (x.length - 1)) {
    document.getElementById("nextBtn").innerHTML = "Submit";
  } else {
    document.getElementById("nextBtn").innerHTML = "Next";
  }
  // ... and run a function that displays the correct step indicator:
  fixStepIndicator(n)
}

function nextPrev(n) {
  // This function will figure out which tab to display
  var x = document.getElementsByClassName("tab");
  // Exit the function if any field in the current tab is invalid:
  if (n == 1 && !collectResponses()) return false;
  // Hide the current tab:
  x[currentTab].style.display = "none";
  // Increase or decrease the current tab by 1:
  currentTab = currentTab + n;
  console.log("tab is: " + currentTab)
  // if you have reached the end of the form... :
  if (currentTab >= x.length) {
    //...the form gets submitted:


    // do we need to send an ID here?
    let dataToSend = {'user': quizID, 'responses': responses}

    for (let i = 0; i < responses.length; i++){
      console.log(responses[i]);
    }
    // socket.emit('quiz-response', responses)
    socket.emit('quiz-response', dataToSend)
    console.log("sent quiz response" + dataToSend)

    // location.replace("../video.html")

    document.getElementById("regForm").style.display = "none";
    document.getElementById("content").style.display = "block";

    return false;
  }
  // Otherwise, display the correct tab:
  showTab(currentTab);
  collectResponses(currentTab)
}

function collectResponses() {
  var x, y, i, valid = true;
  x = document.getElementsByClassName("tab");
  // y = x[currentTab].getElementsByTagName("button");

  let currentAnswers = "answers" + String(currentTab)

  y = document.getElementsByClassName(currentAnswers)

  let answers = document.getElementsByClassName("answers")
  console.log(answers)


  for (let i = 0; i < answers.length; i++) {
    answers[i].addEventListener("click", function () {
      responses[currentTab] = answers[i].innerHTML
      console.log('responses: ' + responses)
    });
  }

  if (valid) {
    document.getElementsByClassName("step")[currentTab].className += " finish";
  }
  return valid; // return the valid status
}

function fixStepIndicator(n) {
  // This function removes the "active" class of all steps...
  var i, x = document.getElementsByClassName("step");
  for (i = 0; i < x.length; i++) {
    x[i].className = x[i].className.replace(" active", "");
  }
  //... and adds the "active" class to the current step:
  x[n].className += " active";
}

socket.on('question', (data) => {
  console.log("reciving data: " + data.message);
  displayQuestions(data.message)
  questionNumber++
})

  socket.on('summarize', function (data) {
    if (data.id != quizID){
      console.log("wrong person");
      return;}
    console.log("we're receiving a summary!");
    console.log(data.message.length);

    eye2 = 0;
    text = data.message;

    // delete placeholder text
    document.getElementById("content").innerHTML = "";
    // document.getElementById("content").scrollTop = scrollHeight;
    typeText2();
    // </br>
  });


function displayQuestions(data) {

  console.log("data to display: " + data)
  let incomingSting = data
  quesionArray = incomingSting.split('|')

  console.log(quesionArray)

  x = document.getElementsByClassName("tab");

  x[questionNumber].innerHTML = quesionArray[0]

  for (let i = 0; i < 4; i++) {
    let answers = document.createElement("div");

    answers.setAttribute("class", "answers");
    x[questionNumber].appendChild(answers);
    answersDisplay = document.getElementsByClassName("answers")
    answersDisplay[i + questionNumber * 4].innerHTML = quesionArray[i + 1]

    console.log(answers)
  }
  collectResponses()

  responded = false
}

// worst possible implementation of this hhHAHAAH
function typeText2(){
  if (eye2 < text.length) {
    let newText = document.getElementById("content");
    let i = text.charAt(eye2); 
    if (i == '\n'){
        newText.innerHTML += '<br>'  
        newText.scrollTop = newText.scrollHeight;
    } else {
    newText.innerHTML += i;
    }  
     eye2++;

  setTimeout(typeText2, speed);
//   if (eye == text.length){
  }
  else {
    let textContent = document.getElementById("content").textContent;
    const htmlContent = linkify(textContent);
    document.getElementById("content") = htmlContent;
  }
}

// stolen from stackOverflow:
// https://stackoverflow.com/questions/1500260/detect-urls-in-text-with-javascript
function linkify(text) {
  var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(urlRegex, function(url) {
      return '<a href="' + url + '">' + url + '</a>';
  });
}
.vscode/settings.json

{
  "code-runner.executorMap": {
    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -I/usr/local/include -L/usr/local/lib -lglfw -framework OpenGL -lGLEW && $dir$fileNameWithoutExt",
  },
}
#include <iostream>
using namespace std;

int main() {
  int num=3;
  if(num== 1){
    cout<< "hello world 1"<< endl;
  }else if(num==2){
    cout<< "hello world 2"<< endl;
  }else if(num==3){
    cout<< "hello world 3"<< endl;
  }
    else{
    cout<< "hello world"<< endl;
  }
  return 0;
}
// C++ code
#include<iostream>
using namespace std;

int main(){
        for(int i=0 ; i<10000 ; i=i +1){

                cout<<"hello world"<<endl;

    }
    return 0;
}
#pragma once
#include "Array.h"
#include "Array.cpp"

int main() {
	COLOR_GREEN_TEXT
/*******************************************************/
	Array<double> a(5); 
	a.setSize(7, 2); 
	for (size_t i = 0; i < 7; i++)
	{
		a.addElement(rand() % 10); 
	}
	a.showArray();
/*******************************************************/
	cout << "GetElement = " << a.getAt(5) << endl;
/*******************************************************/
	a.setAt(3, 99);
	a.showArray();
	a.setAt(3, 99);
	a.setAt(1, 89);
	a.setAt(10, 59);
	a.showArray();
/*******************************************************/
	a.addElement(rand() % 10);
	a.showArray();
	a.addElement(rand() % 10);
	a.addElement(rand() % 10);
	a.showArray(); 
/*******************************************************/
	cout << "a[] = " << a[7] << endl;
/*******************************************************/
	cout << *(a.getData() + 1) << endl;
/*******************************************************/
	a.insertAt(2, 22);
	a.showArray();
/*******************************************************/
	a.freeExtra(); 
	a.showArray();
/*******************************************************/
	Array<double> b(1);
	b.setSize(3, 2); 
	b.addElement(5); 
	b.addElement(10);
	b.addElement(25);
	b.showArray(); 
/*******************************************************/
	a.Append(b);
	a.addElement(1256);
	a.addElement(854);
	cout << endl; 
	cout << endl;
	cout << endl;
	a.showArray();
/*******************************************************/
	Array<double> c(10);
	c.setSize(5, 3); 
	c = a; 
	cout << endl;
	cout << endl;
	cout << endl;
	c.showArray(); 
/*******************************************************/
	STOP
	return 0; 
}	
// Array.cpp
#pragma once
#include "Array.h"

template<class T>
Array<T>::Array(int SIZE) // CONSTRUCTOR
{
	this->grow = 1;
	this->SIZE = SIZE + grow;
	this->preSIZE = SIZE; 
	this->count = 0; 
	this->arr = new T[this->SIZE]();
}

template<class T>
Array<T>::Array(const Array & other) // CONSTRUCTOR COPY
{
	this->SIZE = other.SIZE; 
	this->arr = new T[this->SIZE]; 
	for (size_t i = 0; i < this->SIZE; i++)
	{
		this->arr[i] = other.arr[i]; 
	}
}

template<class T>
Array<T>::~Array() // DESTRUCTOR
{
	delete[] arr; 
	arr = NULL; 
}

template<class T>
int Array<T>::getSize() // GET SIZE
{
	return this->SIZE; 
}

template<class T>
void Array<T>::setSize(int SIZE, int grow) //SET SIZE
{
	if(grow > 0)
	this->grow = grow; 
	this->SIZE = SIZE + this->grow; 

	if (this->SIZE > this->preSIZE)
	{
		T * buf = new T[this->SIZE]();
		for (size_t i = 0; i < this->preSIZE; i++)
		{
			buf[i] = arr[i]; 
		}
		delete[] arr; 
		arr = new T[this->SIZE](); 
		for (size_t i = 0; i < this->SIZE; i++)
		{
			arr[i] = buf[i]; 
		}
		delete[] buf; 
		this->preSIZE = this->SIZE; 
	}
	else
	{
		T * buf = new T[this->SIZE]();
		for (size_t i = 0; i < this->SIZE - this->grow; i++)
		{
			buf[i] = arr[i];
		}
		delete[] arr;
		arr = new T[this->SIZE]();
		for (size_t i = 0; i < this->SIZE; i++)
		{
			arr[i] = buf[i];
		}
		delete[] buf;
		this->preSIZE = this->SIZE; 
		this->count = this->SIZE - this->grow;
	}
}

template<class T>
void Array<T>::addElement(T element) // ADD ELEMENT
{
	if (count < this->SIZE)
	{
		this->arr[count] = element;
		count++;
	}
	else
	{
		this->SIZE = this->SIZE + this->grow + 1; 
		T * buf = new T[this->SIZE](); 
		for (size_t i = 0; i < this->SIZE - this->grow; i++)
		{
			buf[i] = arr[i]; 
		}
		delete[] arr;
		arr = new T[this->SIZE]();
		for (size_t i = 0; i < this->SIZE; i++)
		{
			arr[i] = buf[i]; 
		}
		delete[] buf; 
		buf = NULL; 
		arr[count] = element; 
		count++;  
	}
}

template<class T>
int Array<T>::getUpperBound() //GET UPPER BOUND
{
	return count - 1;
}

template<class T>
bool Array<T>::isEmpty() // CHECK EMPTY NO YES?
{
	if (count == 0)
		return false;
	else
		return count; 
}

template<class T>
void Array<T>::freeExtra() // FREE EXTRA
{
	T * buf = new T[this->SIZE - this->grow]();
	for (size_t i = 0; i < this->SIZE - this->grow; i++)
	{
		buf[i] = arr[i];
	}
	delete[] arr;
	arr = new T[this->SIZE - this->grow]();
	for (size_t i = 0; i < this->SIZE - this->grow; i++)
	{
		arr[i] = buf[i];
	}
	this->SIZE = this->SIZE - this->grow;
}

template<class T>
void Array<T>::removeAll() // CLEAR ALL
{
	delete[] arr; 
	arr = NULL; 
	this->SIZE = 0; 
	this->preSIZE = 0; 
	this->grow = 0; 
	this->count = 0; 
}

template<class T>
T Array<T>::getAt(int index) // GET AT
{
	if (index <= count)
		return arr[index - 1];
	else
		return false; 
}

template<class T>
void Array<T>::setAt(int index, T element) // SET AT
{
	if (index <= count)
	{
		int iteration = 0; 
		bool flag = true; 
		T * buf = new T[SIZE + 1]();
		for (size_t i = 0; i < SIZE; i++)
		{
			if (i != index)
			{
				buf[iteration] = arr[i];
				iteration++; 
			}
			if(i == index && flag == true)
			{
				buf[iteration] = element; 
				iteration++; 
				buf[iteration] = arr[i]; 
				iteration++; 
				flag = false; 
			}
		}
		delete[] arr; 
		arr = new T[SIZE + 1](); 
		this->SIZE++; 
		count++; 
		for (size_t i = 0; i < this->SIZE; i++)
		{
			arr[i] = buf[i]; 
		}
		delete[] buf; 
	}
}

template<class T>
T & Array<T>::operator[](int index) // OVERLOAD OPERATOR []
{
	if (index <= count)
		return this->arr[index];
	else
		return this->arr[count];
}

template<class T>
void Array<T>::Append(Array<T> ob) // APPEND 
{
	int temp = this->SIZE + ob.getSize();
	int iteration = 0; 
	T * buf = new T[temp]();
	for (size_t i = 0; i < this->SIZE; i++)
	{
		buf[i] = arr[i];
		iteration++;
	}
	for (size_t i = 0; i < ob.SIZE; i++)
	{
		buf[iteration] = ob.arr[i]; 
		iteration++;
	}
	delete[] this->arr; 
	this->arr = new T[temp](); 
	for (size_t i = 0; i < temp; i++)
	{
		this->arr[i] = buf[i]; 
	}
	this->SIZE = temp;
	this->count = (this->SIZE - this->grow); 
	delete[] buf; 
}

template<class T>
T * Array<T>::getData() // GET POINTER ARR
{
	return arr;
}

template<class T>
void Array<T>::insertAt(int index, T element) // INSERT AT
{
	if (index <= count)
	{
		arr[index] = element; 
	}
}

template<class T>
void Array<T>::showArray()
{
	for (size_t i = 0; i < this->SIZE; i++)
	{
		cout << arr[i] << "\t"; 
	}
	cout << endl; 
}

template<class T>
Array<T> & Array<T>::operator=(const Array & ob1) // OVERLOAD OPERATOR = 
{ 
	this->SIZE = ob1.SIZE; 
	delete[] this->arr; 
	this->arr = new T[this->SIZE]; 
	for (size_t i = 0; i < this->SIZE; i++)
	{
		this->arr[i] = ob1.arr[i]; 
	}
	return *this; 
}
//Array.h	
#pragma once
#include "H.h"
template<class T>
class Array
{
public:
	Array(int SIZE);
	Array(const Array & other); 
	~Array();
	int getSize();
	void setSize(int SIZE, int grow = 1);
	void addElement(T element);
	int getUpperBound();
	bool isEmpty();
	void freeExtra();
	void removeAll();
	T getAt(int index);
	void setAt(int index, T element);
	T & operator[](int index); 
	void Append(Array ob);
	T * getData(); 
	void insertAt(int index, T element); 
	void showArray();
	Array & operator=(const Array & ob1);
private:
	T * arr;
	int SIZE;
	int preSIZE; 
	int count; 
	int grow; 
};
class Solution {
public:
    int mxlcs(string &t1, string &t2, int i, int j,  vector<vector<int>> & dp)
    {
        if(i==t1.size()||j==t2.size()) return 0;
        if(dp[i][j]!=-1) return dp[i][j];
        int p=0;
        if(t1[i]==t2[j]) 
        {
            p = 1+mxlcs(t1, t2, i+1, j+1, dp);
        }
        else p = max(mxlcs(t1, t2, i+1, j, dp), mxlcs(t1, t2, i, j+1, dp));
        return dp[i][j]=p;
    }
    
    int longestCommonSubsequence(string text1, string text2) {
        vector<vector<int>> dp(text1.size(), vector<int>(text2.size(), -1));
        int ans=mxlcs(text1, text2, 0, 0, dp);
        return ans;
    }
};
class Solution {
public:
    int rob(vector<int>& nums) {
        int n=nums.size();
        vector<int> dp(n,-1);
        if(n<1) return 0;
        if(n==1) return nums[0];
        dp[0]=nums[0];
        dp[1]=max(nums[0], nums[1]);
        for(int i=2;i<n;i++)
        {
            dp[i]=max(dp[i-2]+nums[i], dp[i-1]);
        }
        return dp[n-1];
    }
};
std::vector<float> distortion_vec = calib_handler_.getCameraDistortion(calib_handler_.getStereoLeftCameraId());

Eigen::Map<Eigen::VectorXf, Eigen::Unaligned> distortion(distortion_vec.data(), distortion_vec.size() - 2);
class Solution {
public:
    int tribonacci(int n) {
        int dp[n+4];
        for(int i=0;i<n+1;i++)
        {
            dp[i]=-1;
        }
        dp[0]=0;
        dp[1]=1;
        dp[2]=1;
        for(int i=3;i<n+1;i++)
        {
            dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
        }
        return dp[n];
    }
};
#include <iostream>
using namespace std;

struct element
{
  int i;
  int j;
  int x;
 };
 
 struct sparse
 {
     int m;
     int n;
     int num;
     struct element *ele;
 };
 
 void create(sparse *s)
 {
     cout << "Enter dimensions : ";
     cin >> s->m >> s->n;
     cout << "Enter number of non zero elements : \n";
     cin >> s->num;
     
     s->ele = new element[s->num];
     
     cout << "Enter all non zero elements : ";
     for(int i=0; i<s->num; i++)
     {
         cout << "Enter row no: ";
         cin >> s->ele[i].i;
         cout << "Enter column no: ";
         cin >> s->ele[i].j;
         cout << "Enter element: ";
         cin >> s->ele[i].x;
     }
 }
 
 void display(struct sparse s)
{
    int k;
    for (int i=0; i< s.m; i++)
    {
        for(int j=0; j< s.n; j++)
        {
            if(i==s.ele[k].i && j==s.ele[k].j)
                cout << s.ele[k++].x << " ";
            else 
                cout << " ";
        }
        cout << endl;
    }
}

int main() {
    
    struct sparse s;
    create(&s);
    display(s);
    

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

int main()
{
    int *A,n,x, ch;
    int i,j;
    
    cout << "Enter dimension : " ;
    cin >> n;
    
    A = new int[n];
    
    do
    {
        cout << "\n\n---Diagonal matrix---" << endl;
        cout << "1. Create " << endl;
        cout << "2. Get " << endl;
        cout << "3. Set " << endl;
        cout << "4. Display " << endl;
        cout << "5. Exit " << endl;
        cout << "Enter your choice : ";
        cin >> ch;
        
        switch(ch)
        {
            case 1 :
            cout << "Enter the diagonal elements : \n";
            for (int i=1; i<=n; i++)
                cin >> A[i-1];
            break;
            
            case 2 :
            cout << "Enter indices : ";
            cin >> i >> j;
            if (i==j)
                cout << "Element is : " << A[i-1] << endl;
            else 
                cout << "Element is : 0 " << endl;
            break;
            
            case 3 : 
            cout << "Enter the element : ";
            cin >> x;
            cout << "Enter the indices : ";
            cin >> i >> j;
            if (i==j)
            {
                A[i-1] = x;
                cout << "Element is inserted "<< endl;
            }
            else 
            cout << "Element cannot be inserted at those indices!" << endl;
            break;
            
            case 4 :
            for (int i=1; i<=n; i++)
            {
                for(int j=1; j<=n; j++)
                {
                    if (i==j)
                        cout << A[i-1] << " ";
                    else
                        cout << "0 ";
                }
                cout << endl;
            }
            break;
            
        }
        
    }
    while(ch != 5);
    
    return 0;
}
#include <iostream>
using namespace std;

class LowerTri 
{
    private :
        int n; 
        int *A;
 
    public :
    
     LowerTri(int n)
        {
            this->n = n;
            A = new int[(n*(n+1))/2];
        }
 
        void set (int i, int j , int x);
        int get (int i, int j);
        void display();
         LowerTri()
        {
            delete []A;
        }
};
 
void LowerTri :: set(int i, int j, int x)
{
    if(i>=j)
        A[(i*(i-1)/2) + (j-1)] = x;
}
 
int LowerTri :: get(int i ,int j)
{
    if(i>=j)
        return A[(i*(i-1)/2) + (j-1)];
    else 
        return 0;
}
 
void LowerTri :: display()
{
//    cout << "\n\n";
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (i>=j)
                cout << A[(i*(i-1)/2) + (j-1)] << " ";
            else
                cout << "0 ";
        }
        cout << endl;
    }
}

int main() {
    
    int d ;
    cout << "Enter dimensions : " ;
    cin >> d;
    
    LowerTri lm(d);
    
    int x;
    cout << "Enter all elements : " << endl;
    for(int i=1 ; i<=d; i++)
    {
        for (int j=1; j<=d; j++)
        {
            cin >> x;
            lm.set(i,j,x);
        }
    }
    
    cout << "\n\n";
	lm.display();
    return 0;
}
class Solution {
public:
    int maximumProduct(vector<int>& nums) {
        int n=nums.size();
        sort(nums.begin(), nums.end());
        return max(nums[0]*nums[1]*nums[n-1], nums[n-1]*nums[n-2]*nums[n-3]);
    }
};
#include <iostream>
using namespace std;

class Diagonal 
{
    private :
        int n; 
        int *A;
 
    public :
    
        Diagonal(int n)
        {
            this->n = n;
            A = new int[n];
        }
 
        void set (int i, int j , int x);
        int get (int i, int j);
        void display();
        ~Diagonal()
        {
            delete []A;
        }
};
 
void Diagonal :: set(int i, int j, int x)
{
    if(i==j)
        A[i-1] = x;
}
 
int Diagonal :: get(int i ,int j)
{
    if (i==j)
        return A[i-1];
    else 
        return 0;
}
 
void Diagonal :: display()
{
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            if (i==j)
                cout << A[i] << " ";
            else
                cout << "0 ";
        }
        cout << endl;
    }
}

int main() {
    
    Diagonal m(4) ;
    
    m.set(1,1,1);
    m.set(2,2,2);
    m.set(3,3,3);
    m.set(4,4,4);
    
    m.display();

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

class MergeSort {
private:
    int* arr; // pointer to dynamic array
    int size;

public:
    MergeSort(int size) { // constructor to initialize private array and size
        this->size = size;
        arr = new int[size];
    }

    void merge(int* arr, int l, int m, int r) {
        int i, j, k;
        int n1 = m - l + 1;
        int n2 = r - m;

        int L[n1], R[n2];

        for (i = 0; i < n1; i++)
            L[i] = arr[l + i];
        for (j = 0; j < n2; j++)
            R[j] = arr[m + 1 + j];

        i = 0;
        j = 0;
        k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            }
            else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    void mergeSort(int* arr, int l, int r) {
        if (l < r) {
            int m = l + (r - l) / 2;

            mergeSort(arr, l, m);
            mergeSort(arr, m + 1, r);

            merge(arr, l, m, r);
        }
    }

    void sort() { // public function to sort the private array
        mergeSort(arr, 0, size - 1);
    }

    void display() { // public function to display the sorted array
        cout << "Sorted array: ";
        for (int i = 0; i < size; i++) {
            cout << arr[i] << " ";
        }
        cout << endl;
    }

    ~MergeSort() { // destructor to deallocate dynamic array memory
        delete[] arr;
    }
};

int main() {
    int size;
    cout << "Enter the size of the array: ";
    cin >> size;

    int* arr = new int[size];
    cout << "Enter the elements of the array: ";
    for (int i = 0; i < size; i++) {
        cin >> arr[i];
    }

    MergeSort obj(size);
    for (int i = 0; i < size; i++) {
        obj.arr[i] = arr[i]; // copy the array to the private array in the class
    }

    obj.sort(); // sort the private array
    obj.display(); // display the sorted array

    delete[] arr; // deallocate dynamic array memory
    return 0;
}
I am currently working on a project from Willings Corp. , a renowed company in Japan, So I am currently developing an app for the organization in a team, so I have a good knowledge how things works in a real projects. And I have also maintained a good CGPA (8.23/10) in an institute of national importance. So I can assure you that I will give my best to do the required work for this role.
#include <iostream>
#include <vector>
using namespace std;

class insertionsort{
    private:
    int a[100];
    int n;

    public:

    insertionsort(int arr[], int size){
        n = size;
        int j, key;
        for (int i=0; i < n; i++) {
            a[i] = arr[i];
        }
        for(int i = 1; i<size; i++) {
          key = a[i];
          j = i;
          while( j > 0 && a[j-1]>key) {
             a[j] = a[j-1];
             j--;
          }
          a[j] = key;  
       }
    }
    
    void display() {
        cout << "Sorted array: ";
        for (int i = 0; i < n; i++) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int size;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    
    int arr[size];
    
    cout << "Enter all the elemets of the array with spaces:\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    
    insertionsort is(arr, size);
    is.display();

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

class selectionsort{
    private:
    int a[100];
    int n;

    public:

    selectionsort(int arr[], int size){
        n = size;
        int imin, temp;
        
        for (int i=0; i < n; i++) {
            a[i] = arr[i];
        }
       for(int i = 0; i<n-1; i++) {
          imin = i;   
          for(int j = i+1; j<n; j++)
             if(a[j] < a[imin])
                imin = j;
             temp = a[i];
             a[i] = a[imin];
             a[imin] = temp;
       }
    }
    
    void display() {
        cout << "Sorted Array: ";
        for (int i = 0; i < n; i++) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int size;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    
    int arr[size];
    
    cout << "Enter all the elements separated with spaces\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    
    selectionsort ss(arr, size);
    ss.display();

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


class binarysearch {
    private:
        int n;
    public:
    
    void bubblesort(int arr[], int size){
        n = size;
        for (int i=0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        
    }
    
    int search(int arr[], int x, int low, int high) {
        
      if (high >= low) {
        int mid = low + (high - low) / 2;
    
        // If found at mid, then return it
        if (arr[mid] == x)
          return mid;
    
        // Search the left half
        if (arr[mid] > x)
          return search(arr, x, low, mid - 1);
    
        // Search the right half
        return search(arr, x, mid + 1, high);
      }

  return -1;
}
};

int main() {
    int size, x;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    int arr[size];
    
    cout << "Enter all the elements separated with spaces\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    cout <<"Enter the element to do binary search: ";
    cin >>x;

    binarysearch bs;
    bs.bubblesort(arr, size);
    
    cout<<"To do binary search, the array should be sorted\nThe sorted array is:\n";
    for(int i=0; i<size; i++){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    
    int index = bs.search(arr, x, 0, size - 1);

    if (index == -1) {
        cout << "Element not found" << endl;
    } else {
        cout << "Element "<<x<<" found at index " << index << endl;
    }

    return 0;
}
// for LEDS

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#include <Keypad.h>

//
int old_color_piano;
int old_color_guitar;

// for row/col scan
bool initialized = false;
const byte ROWS = 3;
const byte COLS = 8;
char fastPressed;
int lastPressed;
char hexaKeys[ROWS][COLS] = {                
{'0','1','2','3','4','5','6','7'},
{'8','9','A','B','C','D','E','F'},
{'G','H','I','J','K','L','M','N'}
};
byte colPins[COLS] = {37,41,43,45,47,49,51,53};
byte rowPins[ROWS] = {31,33,35};

// this one im adding
int current_button;


Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);


// for the debouncer
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;
int lastButtonState = LOW;


//#define LED_PIN   8
//#define LED_COUNT 60
int LED_PIN_piano = 13;
int LED_PIN_guitar = 29;
int LED_COUNT = 60;

Adafruit_NeoPixel piano_strip(LED_COUNT, LED_PIN_piano, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel guitar_strip(LED_COUNT, LED_PIN_guitar, NEO_GRB + NEO_KHZ800);

int current_step = 0;
int old_color;

// end LEDS


// NEW AS OF 12/10
// C = 2,5 B = 6,3 A = 7,4
int g1[] = {0,0,0};
int g2[] = {0,0,0};
//int g2Pins[] = {5,6,7};
//int g1Pins[] = {2,3,4};

int g1Pins[] = {7,6,5};
int g2Pins[] = {4,3,2};

//int g1Pins[] = {5,6,7};
//int g2Pins[] = {2,3,4};

// C = 16,19 B = 15,18 A = 14,17
int p1[] = {0,0,0};
int p2[] = {0,0,0};
int p1Pins[] = {16,15,14};
int p2Pins[] = {19,18,17};

int potVal;
int potVal_speed;
int potPin_piano = A0;
int potPin_guitar = A1;
int potPin_speed = A2;

int buttonPins[] = {41,43,45,47,49,51,53,52};
int buttonCounts[] = {0,0,0,0,0,0,0,0};

//int piano_steps[] = {1,8,11,0,20,0,23,17};
int piano_steps[] = {1,0,3,0,5,0,0,7};

//int guitar_steps[] = {0,1,2,3,4,5,6};
int guitar_steps[] = {17,17,17,17,17,17,17,0};


int modeButton = 10;
// END NEW


/// FROM 12_9_PUTTINGTOGETHER
int prevStateMode = 0;
int lastDebounceTimeMode = 0;
int buttonStateMode = 0;
int lastButtonStateMode = 0;
// mode_bool must be false on init
// false -> write mode, true -> play mode
int mode_bool = true;

int just_pressed[] = {false,false,false,false,false,false,false,false};
int still_pressed[] = {false,false,false,false,false,false,false,false};
int debounced_times[] = {0,0,0,0,0,0,0,0};

int just_pressed_mode = false;
int still_pressed_mode = false;
int debounced_times_mode = 0;
int wait_time = 1000;
//



// for piano
int myArray[40][6]{
{0,0,0,0,0,0},
{0,0,0,0,0,1},
{0,0,0,0,1,0},
{0,0,0,0,1,1},
{0,0,0,1,0,0},
{0,0,0,1,0,1},
{0,0,0,1,1,0},
{0,0,0,1,1,1},
{0,0,1,0,0,0},
{0,0,1,0,0,1},
{0,0,1,0,1,0},
{0,0,1,0,1,1},
{0,0,1,1,0,0},
{0,0,1,1,0,1},
{0,0,1,1,1,1},
{0,1,0,0,0,0},
{0,1,0,0,0,1},
{0,1,0,0,1,0},
{0,1,0,0,1,1},
{0,1,0,1,0,0},
{0,1,0,1,0,1},
{0,1,0,1,1,1},
{0,1,1,0,0,0},
{0,1,1,0,0,1},
{0,1,1,0,1,0},
{0,1,1,0,1,1},
{0,1,1,1,0,0},
{0,1,1,1,0,1},
{0,1,1,1,1,0},
{0,1,1,1,1,1},
{1,0,0,0,0,0},
{1,0,0,0,0,1},
{1,0,0,0,1,0},
{1,0,0,0,1,1},
{1,0,0,1,0,0},
{1,0,0,1,0,1},
{1,0,0,1,1,0},
{1,0,0,1,1,1},
{1,0,1,0,0,0},
{1,0,1,0,0,1},
// {1,0,1,0,1,0},
//{1,0,1,0,1,1}
};

// for guitar
int myArray_guitar[8][6]{
{0,0,0,0,0,0},
{0,0,0,0,0,1},
{0,0,0,0,1,0},
{0,0,0,0,1,1},
{0,0,1,0,0,0},
{0,0,1,0,0,1},
{0,0,1,0,1,0},
{0,0,1,0,1,1}
};

void setup() {
  // for leds
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
  #endif
  // END of Trinket-specific code.

  piano_strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  piano_strip.show();            // Turn OFF all pixels ASAP
  piano_strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

  guitar_strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  guitar_strip.show();            // Turn OFF all pixels ASAP
  guitar_strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  // end LEDS

 
  Serial.begin(9600);
  pinMode(potPin_piano, INPUT);
  pinMode(potPin_guitar, INPUT);
  pinMode(potPin_speed, INPUT);
 
 
  // init mx/dmx
  for (int i = 0; i < 3; i++){
    pinMode(g1Pins[i],OUTPUT);
    pinMode(g2Pins[i],OUTPUT);
    pinMode(p1Pins[i],OUTPUT);
    pinMode(p2Pins[i],OUTPUT);
  }

  // init buttons
  for (int i = 0; i < 8; i++){
    pinMode(buttonPins[i], INPUT);
   }

  for(int i=0; i<8; i++) {
      piano_strip.setPixelColor(i+3,255,0,0);
      guitar_strip.setPixelColor(i+3,255,0,0);
   }
   piano_strip.show();
   guitar_strip.show();
}


void loop() {

    Serial.print(digitalRead(12));
    //Serial.print(analogRead(A0));
    //Serial.print(analogRead(A1));
    //Serial.println(analogRead(A2));


  // put your main code here, to run repeatedly:
   //Serial.println(digitalRead(modeButton));
   if (!mode_bool) {
     new_write_mode();
   }
//     Serial.print("piano ");
//     Serial.print(piano_steps[0]);
//     Serial.print(piano_steps[1]);
//     Serial.print(piano_steps[2]);
//     Serial.print(piano_steps[3]);
//     Serial.print(piano_steps[4]);
//     Serial.print(piano_steps[5]);
//     Serial.print(piano_steps[6]);
//     Serial.println(piano_steps[7]);

     //Serial.print("guitar ");
//     Serial.print(guitar_steps[0]);
//     Serial.print(guitar_steps[1]);
//     Serial.print(guitar_steps[2]);
//     Serial.print(guitar_steps[3]);
//     Serial.print(guitar_steps[4]);
//     Serial.print(guitar_steps[5]);
//     Serial.print(guitar_steps[6]);
//     Serial.println(guitar_steps[7]);
//   }
   
   if (mode_bool) {
    play_mode();
   }

checkModeButton();

}

void checkButtons(){
Serial.println("write mode");
// iterate thru buttons
for (int i = 0; i < 8; i++){
   
    // for LEDS
    //if (steps[i] == 0) {
      //strip.setPixelColor(i,255,0,0);
  //  }

    //else if (steps[i] != 0) {
      //strip.setPixelColor(i,0,0,255);
  //  }

    // end LEDS
 
  // read button pin
  int buttonState = digitalRead(buttonPins[i]);

  if (buttonState == 1 && just_pressed[i] == false){
       buttonCounts[i]++;
       
    // NEW
    if (buttonCounts[i] % 2 != 0){
        debounced_times[i] = millis();
        potVal = map(analogRead(potPin_piano), 0,920,0,35);
        //steps[i] = potVal;
        //Serial.println(steps[i]);

        if (millis() - debounced_times[i] > wait_time) {
          if (digitalRead(buttonPins[i] == 1)) {
            buttonCounts[i]++;
          }
        }
       
        if (buttonCounts[i] % 2 != 0) {
          // is this the right place to show lights?
          //strip.show();
          break;
        }
      }  
     }
   }
 }




void play_mode() {
  Serial.println("read mode");
  //for play mode test 12/11 3pm


 
  //int piano_steps[] = {10,11,12,0,13,14,0,25};
  //int guitar_steps[] = {0,1,2,3,4,5,6,7};

  //int piano_steps[] = {0,1,2,3,4,5,6,7};
 
  for (int i = 0; i < 8; i++){
    // iterate thru all 8 steps
    //Serial.println("read mode");
    int t_piano = piano_steps[i];
    int t_guitar = guitar_steps[i];
   
    checkModeButton();
   
    // TODO IMPLEMENT FOR MULTIPLE LED STRIPS
    play_mode_leds(i);

  for (int j = 0; j < 3; j++){
    p1[j] = myArray[t_piano][j+3];
    p2[j] = myArray[t_piano][j];

    checkModeButton();

    g2[j] = myArray[t_guitar][j+3];
    g1[j] = myArray[t_guitar][j];
    }
//        for (int i = 0; i < 3; i++){
//    Serial.print(g1[i]);
//  }
//   for (int i = 0; i < 2; i++){
//    Serial.print(g2[i]);
//  }
//  Serial.println(g2[2]);
   
  //atoi()
//    Serial.print(p1[0]);
//    Serial.print(p1[1]);
//    Serial.print(p1[2]);
//    Serial.print(p2[0]);
//    Serial.print(p2[1]);
//    Serial.println(p2[2]);

    checkModeButton();

    for (int j = 0; j < 3; j++){
     digitalWrite(p1Pins[j],p1[j]);
     digitalWrite(p2Pins[j],p2[j]);
     
     digitalWrite(g1Pins[j],g1[j]);
     digitalWrite(g2Pins[j],g2[j]);
    }
   
     wait_time = map(analogRead(potPin_speed),0,1000,100,800);
     checkModeButton();
     delay(wait_time);
   }
}

void checkModeButton(){
//Serial.println("fug");
  int reading = digitalRead(modeButton);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH), and you've waited long enough
  // since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != prevStateMode) {
   
    // reset the debouncing timer
    lastDebounceTimeMode = millis();
  }

  if ((millis() - lastDebounceTimeMode) > 50) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:
    //Serial.println("I am capable of extreme violence");

    // if the button state has changed:
    if (reading != buttonStateMode) {
      buttonStateMode = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonStateMode == HIGH) {
        mode_bool = !mode_bool;
      }
    }
  }
    // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;  
}

void play_mode_leds(int current_step) {
  current_step = current_step+3;
  if (current_step > 0) {
    //old_color = strip.getPixelColor(current_step-1);
    piano_strip.setPixelColor(current_step-1,old_color_piano);
    guitar_strip.setPixelColor(current_step-1,old_color_guitar);
   
    if (piano_steps[current_step-1] == 0) {
      piano_strip.setPixelColor(current_step-1,255,0,0);
    }

    else if (piano_steps[current_step-1] != 0) {
      piano_strip.setPixelColor(current_step-1,0,0,255);
    }

    if (guitar_steps[current_step-1] == 0) {
      guitar_strip.setPixelColor(current_step-1,255,0,0);
    }

    else if (guitar_steps[current_step-1] != 0) {
      guitar_strip.setPixelColor(current_step-1,0,0,255);
    }
   
  }

  else if (current_step == 0) {
    //old_color = strip.getPixelColor(7);
    //strip.setPixelColor(7,old_color);
   
    if (piano_steps[7] == 0) {
      piano_strip.setPixelColor(7+3,255,0,0);
    }
//    else if (piano_steps[7] != 0) {
      else{
      piano_strip.setPixelColor(7+3,0,0,255);
    }

    if (guitar_steps[7] == 0) {
      guitar_strip.setPixelColor(7+3,255,0,0);
    }
    else if (guitar_steps[7] != 0) {
      guitar_strip.setPixelColor(7+3,0,0,255);
    }
   
  }

  old_color_piano = piano_strip.getPixelColor(current_step);
  old_color_guitar = guitar_strip.getPixelColor(current_step);    
  piano_strip.setPixelColor(current_step,0,255,0);
  guitar_strip.setPixelColor(current_step,0,255,0);
  //old_color = strip.getPixelColor(current_step-1)
  //strip.setPixelColor(current_step-1,old_color);
  piano_strip.show();
  guitar_strip.show();
}

void new_write_mode() {
   Serial.println("write mode");
   //Serial.print("potVAL_no press ");
   //Serial.println(potVal);
  checkModeButton();
  char customKey = customKeypad.getKey();
  Serial.println(lastPressed);

  if (customKey != NO_KEY){
    initialized = true;
    decoder(customKey);
  }
 
   
  if (lastPressed < 8 && initialized == true) {
    potVal = map(analogRead(potPin_piano),20,1000,0,35);
    Serial.print("potVAL ");
    Serial.println(potVal);
    piano_steps[lastPressed] = potVal;
  }

  else if (lastPressed > 7 && lastPressed < 16) {
    potVal = map(analogRead(potPin_guitar),0,1013,0,8);
    Serial.print("potVAL ");
    Serial.println(potVal);
    guitar_steps[lastPressed-8] = potVal;
    Serial.println(lastPressed);
  }

  for(int i=0; i<8; i++) {
   
    if (piano_steps[i] == 0) {
      piano_strip.setPixelColor(i+3,255,0,0);
    }

    else if (piano_steps[i] != 0) {
      piano_strip.setPixelColor(i+3,0,0,255);
    }

    if (guitar_steps[i] == 0) {
      guitar_strip.setPixelColor(i+3,255,0,0);
    }

    else if (guitar_steps[i] != 0) {
      guitar_strip.setPixelColor(i+3,0,0,255);
    }
 
  }
 
  piano_strip.show();
  guitar_strip.show();
 
}

void decoder(char myKey){
  if (myKey == '0'){lastPressed = 7;}
  if (myKey == '1'){lastPressed = 6;}
  if (myKey == '2'){lastPressed = 5;}
  if (myKey == '3'){lastPressed = 4;}
  if (myKey == '4'){lastPressed = 3;}
  if (myKey == '5'){lastPressed = 2;}
  if (myKey == '6'){lastPressed = 1;}
  if (myKey == '7'){lastPressed = 0;}

 
  if (myKey == 'G'){lastPressed = 15;}
  if (myKey == 'H'){lastPressed = 14;}
  if (myKey == 'I'){lastPressed = 13;}
  if (myKey == 'J'){lastPressed = 12;}
  if (myKey == 'K'){lastPressed = 11;}
  if (myKey == 'L'){lastPressed = 10;}
  if (myKey == 'M'){lastPressed = 9;}
  if (myKey == 'N'){lastPressed = 8;}

  }
int LinearSearch(struct arr, int key)
{
  int i;
  for(i=0; i<arr.length; i++)
    {
      if (key == arr.A[i])
        return i;
    }
  return -1;
}

int main()
{
  struct Array arr={{2,3,4,5,6},10,5};

  printf("%d\n", LinearSearch(arr,15));
  Display(arr);

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

class bubblesort{
    private:
    int a[100];
    int n;

    public:

    bubblesort(int arr[], int size){
        n = size;
        
        for (int i=0; i < n; i++) {
            a[i] = arr[i];
        }
        for (int i=0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (a[j] > a[j+1]) {
                    int temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
    }
    
    void display() {
        cout << "Sorted Array: ";
        for (int i = 0; i < n; i++) {
            cout << a[i] << " ";
        }
        cout << endl;
    }
};

int main() {
    int size;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    
    int arr[size];
    
    cout << "Enter all the elements separated with spaces\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    bubblesort bs(arr, size);
    bs.display();
    
    return 0;
}
int delete(struct Array *arr, int index)
{
  int x=0;
  int i;
  
  if (index >= 0 && index < arr->length)
    {
      x = arr-> A[index];
      for(i = index; i<arr->length-1; i++)
        arr ->length--;
      return x;
    }
  return 0;
}

int main()
{
  struct Array arr= {{2,3,4,5,6},10,5};

  printf("%d\n", Delete(&arr,4));

  return 0;
}
// Emilio Ordoñez

# include <iostream>
using namespace std;

	//Valores
	float DiasLaborados = 30;
	float UMA = 123.22;
	float Factor1 = .25;
	float Factor2 = .3750;
	float Factor3 = .0110;
	
	float SueldoBruto = 0;
	float SalarioDiarioIntegrado = 0;
	float CuotaObreroPatronal = 0;
	float CuotaPorPrestamo = 0;
	float GastosMedicos = 0;
	float GastosInvalidez = 0;
	float IMSS = 0;

cuotaIMSS(){
	
	//Operaciones
	SalarioDiarioIntegrado = SueldoBruto / DiasLaborados;
	CuotaObreroPatronal = (( SalarioDiarioIntegrado - UMA ) * DiasLaborados ) * Factor3;
	CuotaPorPrestamo = (( SueldoBruto * DiasLaborados ) * Factor1 ) / 100;
	GastosMedicos =  (( SueldoBruto * DiasLaborados ) * Factor2 ) / 100 ;
	GastosInvalidez = SueldoBruto * Factor1;
	
	IMSS = CuotaObreroPatronal + CuotaPorPrestamo + GastosMedicos + GastosInvalidez;
	//Valores de salida
	cout << "Salario diario integrado: " << SalarioDiarioIntegrado << endl;
	cout << "Cuota obrero patronal: " << CuotaObreroPatronal << endl;
	cout << "Cuota por prestamo: " << CuotaPorPrestamo << endl;
	cout << "Gastos medicos: " << GastosMedicos << endl;
	cout << "Gastos invalidez: " << GastosInvalidez << endl;
	cout << "\nCuota del IMSS : " << IMSS << endl;
}

int main(){
	
	cout << "Calculadora de la nomina\n Banco de Mexico\n";
	cout << "\nSueldo bruto: ";
	cin >> SueldoBruto;
	
	cout << "Ingrese una opcion: ";
	int opcion;
	
	cin >> opcion;
		
	switch(opcion) 
	{
    	case 1:
    	cuotaIMSS();
    	break;
    	case 2: 
    	break;
    	default:; 
	}

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

class linearsearch {
    private:
        int a[100], n, x;
        
    public:
        int search(int arr[], int size, int key) {
            n = size;
            x = key;
            
            for (int i=0; i < n; i++) {
            a[i] = arr[i];
            }   
        
            for (int i = 0; i < size; i++) {
                if (arr[i] == key) {
                    return i;
                }
            }
            return -1;
        }
};

int main() {
    int size, x;
    
    cout << "Enter the size of the 1-d array: ";
    cin >> size;
    int arr[size];
    
    cout << "Enter all the elements separated with spaces\n";
    for(int i=0; i<size; i++){
        cin>>arr[i];
    }
    
    cout <<"Enter the element to do linear search: ";
    cin >>x;
    
    linearsearch ls;
    int index = ls.search(arr, size, x);

    if (index == -1) {
        cout << x <<" not found" << endl;
    } else {
        cout << x <<" found at index " << index <<" (starts from 0)." <<endl;
    }

    return 0;
}
class Solution {
public:
    char bsf(vector<char> letters, char target)
    {
        char ans=letters[0];
        int n=letters.size();
        int l=0,h=n-1;
        int mid=l+(h-l)/2;
        while(l<=h)
        {
            if(letters[mid]-'a'>target-'a') 
            {
                ans=letters[mid];
                h=mid-1;
            }
            else l=mid+1;
            mid=l+(h-l)/2;
        }
        return ans;
    }
    
    char nextGreatestLetter(vector<char>& letters, char target) {
        char result=bsf(letters, target);
        return result;
    }
};
class Solution {
public:
    bool isPerfectSquare(int num) {
        int l=1;
        int h=100000;
        long long mid=l+(h-l)/2;
        long long sq;
        while(l<=h)
        {
            sq=mid*mid;
            if(sq==num) return true;
            if(sq<num) l=mid+1;
            else h=mid-1;
            mid=l+(h-l)/2;
        }
        return false;
    }
};
class Solution {
public:
    double my_Pow(double x, long n)
    {
        if(n==0) return 1.0;
        if(n==1) return x;
        if(n<0) return my_Pow(1/x, -n);
        double result=my_Pow(x*x, n/2);
        if(n%2==1) result*=x;
        return result;
    }
    
    double myPow(double x, int n) {
        return my_Pow(x, n);
    }
};
class Solution {
public:
    int pivot(vector<int> nums)
    {
        int n=nums.size();
        int s=0, l=n-1;
        int mid=s+(l-s)/2;
        while(s<=l)
        {
            if(s==l) return s;
            if(nums[mid]>nums[n-1]) s=mid+1;
            else l=mid;
            mid=s+(l-s)/2;
        }
        return s;
    }
    
    int findMin(vector<int>& nums) {
        int ans=nums[pivot(nums)];
        return ans;
    }
};
// The API isBadVersion is defined for you.
// bool isBadVersion(int version);

class Solution {
public:
    int firstBadVersion(int n) {
        int s=0, e=n-1;
        int mid=s+(e-s)/2;
        int ans=-1;
        while(s<=e)
        {
            if(isBadVersion(mid)) 
            {
                ans=mid;
                e=mid-1;
            }
            else s=mid+1;
            mid=s+(e-s)/2;
        }
        return mid;
    }
};
class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int n=nums.size();
        if(n==1) return 0;
        if(n==2) return nums[0]>nums[1]?0:1;
        int s=1, e=n-2;
        int mid=s+(e-s)/2;
        while(s<=e)
        {
            if(nums[mid]>nums[mid-1]&&nums[mid]>nums[mid+1]) return mid;
            else if(nums[mid]<nums[mid+1]) s=mid+1;
            else if(nums[mid]<=nums[mid-1])e=mid-1;
            mid=s+(e-s)/2;
        }
        if(nums[0]>nums[1]) return 0;
        else if(nums[n-1]>nums[n-2]) return n-1;
        
        return -1;
    }
};
/** 
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return 	     -1 if num is higher than the picked number
 *			      1 if num is lower than the picked number
 *               otherwise return 0
 * int guess(int num);
 */

class Solution {
public:
    // int guess(int num)
    // {
    //     if(num>)
    // }
    int guessNumber(int n) {
        int s=1, e=n;
        int mid=s+(e-s)/2;
        
        while(s<=e)
        {
            int num=guess(mid);
            if(num==0) return mid;
            if(num==-1) e=mid-1;
            else s=mid+1;
            mid=s+(e-s)/2;
        }
        return mid;
        
    }
};
class Solution {
public:
    int bs(int x)
    {
        
        int long long n=x/2;
        int long long s=0, e=n;
        int long long mid=s+(e-s)/2;
        int long long ans=0;
        while(s<=e)
        {
            int long long p=mid*mid;
            int long long p2=(mid+1)*(mid+1);
            if(p<=x&&p2>x) return mid;
            if(p<x) 
            {
                ans=
                s=mid+1;
            }
            else e=mid-1;
            mid=s+(e-s)/2;
        }
        return mid;
    }
    
    int mySqrt(int x) {
        if(x==0) return 0;
        if(x==1||x==2||x==3) return 1;
        int ans=bs(x);
        return ans;
    }
 };
        // tennis rackets
        for(int item = 0; item < 2; item++) {
            glm::mat4 world_transform_matrix = glm::mat4(1.0f);
            // global transforms
            world_transform_matrix = glm::translate(world_transform_matrix, starting_locations[item]);
            world_transform_matrix = rotate(world_transform_matrix, r[item]);
            world_transform_matrix = glm::scale(world_transform_matrix, s[item]);

            glm::mat4 arm_transform_matrix = world_transform_matrix;
            glm::mat4 racket_transform_matrix = world_transform_matrix;

            // -- arm -- // tranforms cube to create arm
            // forearm (skin)
            arm_transform_matrix =  tennis_rackets[item][0].cubeRotate(arm_transform_matrix, glm::vec3(45.0f, 0.0f, 0.0f));
            arm_transform_matrix = tennis_rackets[item][0].cubeScale(arm_transform_matrix, glm::vec3(0.5f, 2.0f, 0.5f));
            tennis_rackets[item][0].drawCube(arm_transform_matrix);
            arm_transform_matrix = tennis_rackets[item][0].cubeScale(arm_transform_matrix, glm::vec3(1/0.5f, 1/2.0f, 1/0.5f));

            // arm (skin)
            arm_transform_matrix = tennis_rackets[item][0].cubeTranslate(arm_transform_matrix, glm::vec3(0.0f, 2.0f * 0.1f, 0.0f));
            arm_transform_matrix =  tennis_rackets[item][0].cubeRotate(arm_transform_matrix, glm::vec3(-45.0f, 0.0f, 0.0f));
            arm_transform_matrix = tennis_rackets[item][0].cubeScale(arm_transform_matrix, glm::vec3(0.5f, 2.0f, 0.5f));
            tennis_rackets[item][0].drawCube(arm_transform_matrix);
            arm_transform_matrix = tennis_rackets[item][0].cubeScale(arm_transform_matrix, glm::vec3(1/0.5f, 1/2.0f, 1/0.5f));

            // -- tennis racket shape -- // transforms cube to create racket
            // handle
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f, 3.0f * 0.1f, -0.15f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 2.5f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/2.5f, 1/0.25f));
            // racket
            // racket angled bottom left
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  2.5f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(-70.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 1.5f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/1.5f, 1/0.25f));
            // racket vertical left
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  1.5f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(70.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 2.0f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/2.0f, 1/0.25f));
            // racket angled top left
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  2.0f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(40.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 1.0f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/1.0f, 1/0.25f));
            // racket horizontal top
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  1.0f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(50.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 1.5f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/1.5f, 1/0.25f));
            // racket angled top right
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  1.5f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(50.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 1.0f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/1.0f, 1/0.25f));
            // racket vertical right
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  1.0f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(40.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 2.0f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/2.0f, 1/0.25f));
            // racket horizontal bottom
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f,  2.0f * 0.1f, 0.0f));
            racket_transform_matrix =  tennis_rackets[item][1].cubeRotate(racket_transform_matrix, glm::vec3(90.0f, 0.0f, 0.0f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.25f, 2.75f, 0.25f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.25f, 1/2.75f, 1/0.25f));

            //net
            racket_transform_matrix = tennis_rackets[item][1].cubeTranslate(racket_transform_matrix, glm::vec3(0.0f, 0.0f, -2.25f * 0.1f));
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(0.1f, 2.5f, 0.1f));
            tennis_rackets[item][1].drawCube(racket_transform_matrix);
            racket_transform_matrix = tennis_rackets[item][1].cubeScale(racket_transform_matrix, glm::vec3(1/0.1f, 1/2.5f, 1/0.1f));

            for (float j = 0; j < 6; j++) { ]
class Solution {
public:
    int numRescueBoats(vector<int>& people, int limit) {
        sort(people.begin(), people.end());
        int n=people.size();
        int ptri=0;
        int ptrl=n-1;
        int boats=0;
        
        for(ptrl=n-1;ptrl>=0&&ptrl>=ptri;ptrl--)
        {
            if(people[ptrl]+people[ptri]<=limit) ptri++;
            boats++;
        }
        return boats;
    }
};
class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int n=nums.size();
        int ap[n], aa[n];
        ap[0]=0; aa[n-1]=0;
        int sum=nums[0];
        for(int i=1;i<n;i++)
        {
            ap[i]=sum;
            sum+=nums[i];
        }
        int s=nums[n-1];
        for(int i=n-2;i>=0;i--)
        {
            aa[i]=s;
            s+=nums[i];
        }
        int ans=-1;
        for(int i=0;i<n;i++)
        {
            if(ap[i]==aa[i])
            {
                ans=i;
                break;
            }
        }
        return ans;
    }
};
class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        int st=0, end=arr.size()-1;
        int mid=st+(end-st)/2;
        while(st<=end)
        {
            if(arr[mid]>arr[mid-1]&&arr[mid]>arr[mid+1]) return mid;
            if(arr[mid]<arr[mid+1]) st=mid+1;
            else if(arr[mid]<arr[mid-1]) end=mid;
            mid=st+(end-st)/2;
        }
        return mid;
    }
};
class Solution {
public:
    
    int loweridx(vector<int> nums ,int target)
    {
        int st=0, end=nums.size()-1;
        int ans=-1;
        int mid=st+(end-st)/2;
        while(st<=end)
        {
            if(nums[mid]==target) 
            {
                ans=mid;
                end=mid-1;
            }
            else if(target>nums[mid])
            {
                st=mid+1;
            }
            else if(target<nums[mid])
            {
                end=mid-1;
            }
            mid=st+(end-st)/2;
        }
        return ans;
    }
    
    int largidx(vector<int> nums ,int target)
    {
        int st=0, end=nums.size()-1;
        int ans=-1;
        int mid=st+(end-st)/2;
        while(st<=end)
        {
            if(nums[mid]==target) 
            {
                ans=mid;
                st=mid+1;
            }
            else if(target>nums[mid])
            {
                st=mid+1;
            }
            else if(target<nums[mid])
            {
                end=mid-1;
            }
            mid=st+(end-st)/2;
        }
        return ans;
    }
        
    vector<int> searchRange(vector<int>& nums, int target) {
       
        vector<int> v;
        int lowidx=loweridx(nums, target);
        int laridx=largidx(nums, target);
        v.push_back(lowidx);
        v.push_back(laridx);
        return v;
    }
};
// the following are the resources used for this project :
// https://my.eng.utah.edu/~cs5610/handouts/order_independent_transparency.pdf
// https://learnopengl.com/Getting-started/Hello-Window
// https://learning.oreilly.com/library/view/opengl-build/9781788296724/ch06s02.html

#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

void processInput(GLFWwindow *window);
void initialize_framebuffers();


// settings
const unsigned int SCR_WIDTH = 900;
const unsigned int SCR_HEIGHT = 800;

// framebuffers
GLuint FBO[2], FBOcolourBlender; // frame buffer objects
GLuint colourTextureID[2], depthTextureID[2], colourBlenderTextureID; // textures for attachment to frame buffer

// store vertex data in buffer
// VAO (vertex array object) stores pointers to one or more VBOs (vertex buffer object)
GLuint VAO, VBO, EBO; // EBO (element buffer object)

//total number of depth peeling passes
const int NUM_PASSES = 4;

// basic vertex shader source code
const char* vertexShaderSource = "#version 330 core\n"
    "layout (location = 0) in vec3 aPos;\n"
    "uniform mat4 model;\n"
    "uniform mat4 view;\n"
    "uniform mat4 proj;\n"
    "void main()\n"
    "{\n"
    "   gl_Position = proj * view * model * vec4(aPos, 1.0);\n"
    "}\0";
// basic fragment shader source code
const char* fragmentShaderSource = "#version 330 core\n"
    "out vec4 FragColor;\n"
    "uniform vec4 cubecolour;\n"	//colour uniform
    "void main()\n"
    "{\n"
    "   FragColor = cubecolour;\n"
    "}\n\0";

// peeling vertex shader source code
const char* peeling_vertexShaderSource = "#version 330 core\n"
    "layout (location = 0) in vec3 aPos;\n"
    "uniform mat4 model;\n"
    "uniform mat4 view;\n"
    "uniform mat4 proj;\n"
    "void main()\n"
    "{\n"
    "   gl_Position = proj * view * model * vec4(aPos, 1.0);\n"
    "}\0";
// peeling fragment shader source code
// we compare the depth held in the depth texture of the FBO with the next depth
// if the next depth is less then or equal then we discard it
const char* peeling_fragmentShaderSource = "#version 330 core\n"
    "out vec4 FragColor;\n"
    "uniform vec4 cubecolour;\n"	//colour uniform
    "uniform sampler2DRect depthTexture;\n" // depth
    "void main()\n"
    "{\n" // in order to extract the deoth from the sampler2DRect we need to flip (x , y, z, w) (s, t, p, q)
    "   float frontDepth = texture(depthTexture, gl_FragCoord.xy).s;\n" // gl_FragCoord returns the  (x, y, z, 1/w) for the fragment
    "	if(gl_FragCoord.z <= frontDepth) discard;\n" // we want to see the back depth (equivalent to GL_GREATER)
    "   FragColor = cubecolour;\n"
    "}\n\0";

GLfloat rotation_x = 0.0f;
GLfloat rotation_y = 0.0f;

int main() {

    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    // vertice coordinates
    GLfloat vertices[] = {
        // set of vertices for each face

        -0.25f, 0.25f, 0.25f,
        -0.25f, -0.25f, 0.25f,
        0.25f, 0.25f, 0.25f,
        0.25f, -0.25f, 0.25f,

        0.25f, 0.25f, 0.25f,
        0.25f, -0.25f, 0.25f,
        0.25f, 0.25f, -0.25f,
        0.25f, -0.25f, -0.25f,

        0.25f, 0.25f, -0.25f,
        0.25f, -0.25f, -0.25f,
        -0.25f, 0.25f, -0.25f,
        -0.25f, -0.25f, -0.25f,

        -0.25f, 0.25f, -0.25f,
        -0.25f, -0.25f, -0.25f,
        -0.25f, 0.25f, 0.25f,
        -0.25f, -0.25f, 0.25f,

        0.25f, -0.25f, -0.25f,
        0.25f, -0.25f, 0.25f,
        -0.25f, -0.25f, -0.25f,
        -0.25f, -0.25f, 0.25f,

        0.25f, 0.25f, 0.25f,
        0.25f, 0.25f, -0.25f,
        -0.25f, 0.25f, 0.25f,
        -0.25f, 0.25f, -0.25f 
    };

    // indices for vertices order
    GLuint indices[] = {
        0, 1, 2,
        2, 1, 3,
                             
        4, 5, 6,
        6, 5, 7,

        8, 9, 10,
        10, 9, 11,

        12, 13, 14,
        14, 13, 15,

        16, 17, 18,
        18, 17, 19,

        20, 21, 22,
        22, 21, 23

    };
    const int num_cubes = 6;
    glm::vec3 cube_positions[6] = {
        glm::vec3( 0.0f,  0.0f,  0.0f),
        glm::vec3( 0.5f +0.2f,  0.0f,  0.0f),
        glm::vec3( -0.5f -0.2f,  0.0f,  0.0f),
        glm::vec3( 0.0f,  0.0f,  1.0f),
        glm::vec3( 0.5f +0.2f,  0.0f,  1.0f),
        glm::vec3( -0.5f -0.2f,  0.0f,  1.0f)

    };
    //constants for box colours 
    glm::vec4 box_colors[6]={
        glm::vec4(1,0,0,1), // red
		glm::vec4(0,1,0,1), // green
		glm::vec4(0,0,1,1), // blue
        glm::vec4(1,0,0,1), // red
		glm::vec4(0,1,0,1), // green
		glm::vec4(0,0,1,1) // blue
	};

    // glfw window of size SCR_WIDTH by SCR_HEIGHT 
    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Depth Peeling with OpenGL", NULL, NULL);

    if (window == NULL) {
        
        printf("failed to create GLFW window \n");
        glfwTerminate();
        return -1;
    }
    else { printf("GLFW window creation successful ! \n");}
    glfwMakeContextCurrent(window); // tells glfw we want to use the window created

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
    {
        printf("failed to initialize GLAD \n");
        return -1;
    }  

    // specify the viewport window goes from x = 0  to x = SCR_WIDTH and y = 0 to y = SCR_HEIGHT
    glViewport( 0, 0, SCR_WIDTH, SCR_HEIGHT);

    //-----//
    // basic shader
    // vertex shader reference
    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1 , &vertexShaderSource, NULL);
    // compile shader into machine code
    glCompileShader(vertexShader);

    // fragment shader reference
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1 , &fragmentShaderSource, NULL);
    // compile shader into machine code
    glCompileShader(fragmentShader);

    GLuint shaderProgram = glCreateProgram();
    // attach shader to shader program
    glAttachShader(shaderProgram, vertexShader);
    glAttachShader(shaderProgram, fragmentShader);

    glLinkProgram(shaderProgram);

    // because the shaders are in the program we can delete
    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

    // shders for peeling the front layer off
    // vertex shader reference
    vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1 , &peeling_vertexShaderSource, NULL);
    // compile shader into machine code
    glCompileShader(vertexShader);

    // fragment shader reference
    fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1 , &peeling_fragmentShaderSource, NULL);
    // compile shader into machine code
    glCompileShader(fragmentShader);

    GLuint peeling_shaderProgram = glCreateProgram();
    // attach shader to shader program
    glAttachShader(peeling_shaderProgram, vertexShader);
    glAttachShader(peeling_shaderProgram, fragmentShader);

    glLinkProgram(shaderProgram);

    // because the shaders are in the program we can delete
    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

    //-----//

    initialize_framebuffers();    
    
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO); // because we only have one object
    glGenBuffers(1, &EBO);
    // binding object sets certain object to current object
    glBindVertexArray(VAO);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // draw mean vertices will be modified and used to draw images on the screen

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindVertexArray(0);


    glEnable(GL_DEPTH_TEST);

    //-----//

    while (!glfwWindowShouldClose(window)) {

        // check for keyboard input
        processInput(window);

        // set up for view and proj projections
        // view is for the view from the camera
        // proj is for clip space once the vertices are in the camera space by the view
        // model is for the objects
        glm::mat4 view = glm::mat4(1.0f);
        glm::mat4 proj = glm::mat4(1.0f);

        view = glm::translate(view, glm::vec3(0.0f, 0.0f, -4.0f)); // z is positive towards us and negative away from us

        proj = glm::perspective(glm::radians(45.0f), (float)(SCR_WIDTH/SCR_HEIGHT), 0.1f, 100.0f); // 45.0 rad = fov
                                                                                    // anything 0.1f close to camera is clipped and 100f clipped 
        view = glm::rotate(view, glm::radians(rotation_x), glm::vec3(1.0f, 0.0f, 0.0f));
        view = glm::rotate(view, glm::radians(rotation_y), glm::vec3(0.0f, 1.0f, 0.0f));

        // clear buffers prior to looping 
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        // loop through the number of passes
        for (int i = 0; i < NUM_PASSES; i++){
            int A = i % 2;
            int B = (i+1) % 2;
        }

        // point to matrix object itself  
        GLint viewLoc = glGetUniformLocation(shaderProgram, "view");
        glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
        GLint projLoc = glGetUniformLocation(shaderProgram, "proj");
        glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj));

        glBindVertexArray(VAO);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
        // opengl works by having two buffers, while one is being displayed the other is being made in the backround and they swap
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        // clear back buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        
        // our first dept peeling pass
        glEnable(GL_DEPTH_TEST);

        glUseProgram(shaderProgram);

        // instancing of my cube
        for (unsigned int i = 0; i < num_cubes; i++)
        {
            // calculate the model matrix for each object and pass it to shader before drawing
            glm::mat4 model = glm::mat4(1.0f);
            model = glm::translate(model, cube_positions[i]); // translate the cubes to correct locations
            GLint modelLoc = glGetUniformLocation(shaderProgram, "model");
            glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

            glUniform4fv(glGetUniformLocation(shaderProgram, "cubecolour"),1 , &(box_colors[i].x)); // set the uniform cube colour in the fragment shader to our colour

            glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(int), GL_UNSIGNED_INT, 0);
        }
        /*
        for (int i = 0; i < NUM_PASSES; i++){
            glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            int A = i % 2;
            int B = (i+1) % 2;

            // depth buffer 1 to peel away previous fragment
            glBindFramebuffer(GL_FRAMEBUFFER, FBO[A]);
			//set the first colour attachment as draw buffer
			glDrawBuffer(GL_COLOR_ATTACHMENT0);
            
            glDisable(GL_BLEND);
            glDisable(GL_DEPTH_TEST);
            glDepthFunc(GL_GREATER); 
           
            // depth buffer 2 performs “regular” depth-buffering
            // front - back using the fragment shader
            glBindFramebuffer(GL_FRAMEBUFFER, FBO[B]);

            glEnable(GL_BLEND);
            glDisable(GL_DEPTH_TEST);
            glDepthFunc(GL_LESS);
            glBindVertexArray(VAO);
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);

        }*/
        // swap back buffer with front buffer
        glfwSwapBuffers(window); // image gets updated at each frame
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

void processInput(GLFWwindow *window)
{
    const GLfloat rotation_speed = 5;

    // exit
    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
        glfwSetWindowShouldClose(window, true);
    
    // rotate scene view
    if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_UP) == GLFW_REPEAT)
        rotation_x -= rotation_speed;
    if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_REPEAT)
        rotation_x += rotation_speed;
    if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_REPEAT)
        rotation_y -= rotation_speed;
    if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_REPEAT)
        rotation_y += rotation_speed;
}


void initialize_framebuffers() {
	// set up two frame buffer objects, with a colour texture attachment and a depth textture attachment
	glGenFramebuffers(2, FBO);
	glGenTextures (2, colourTextureID);
	glGenTextures (2, depthTextureID);

	//for each attachment
	for (int i = 0; i < 2; i++) {
        // texture for depth
		glBindTexture(GL_TEXTURE_RECTANGLE, depthTextureID[i]);
		glTexImage2D(GL_TEXTURE_RECTANGLE , 0, GL_DEPTH_COMPONENT32F, SCR_WIDTH, SCR_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
        // texture for colour
		glBindTexture(GL_TEXTURE_RECTANGLE, colourTextureID[i]);
		glTexImage2D(GL_TEXTURE_RECTANGLE , 0,GL_RGBA, SCR_WIDTH, SCR_HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL);

		// bind FBO and attach the depth and colour attachments
		glBindFramebuffer(GL_FRAMEBUFFER, FBO[i]);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_RECTANGLE, depthTextureID[i], 0);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, colourTextureID[i], 0);
	}

        // texture for colour blending at the end
        glGenTextures(1, &colourBlenderTextureID);
        glBindTexture(GL_TEXTURE_RECTANGLE, colourBlenderTextureID);
        glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA, SCR_WIDTH, SCR_HEIGHT, 0, GL_RGBA, GL_FLOAT, 0);

        //frame buffer for holding the colour blending texture and for depth (used at the end)
        glGenFramebuffers(1, &FBOcolourBlender);
        glBindFramebuffer(GL_FRAMEBUFFER, FBOcolourBlender);

        // attach the textures
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_RECTANGLE, depthTextureID[0], 0);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE, colourBlenderTextureID, 0);

        GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if(status == GL_FRAMEBUFFER_COMPLETE )
            printf("FBO setup successful ! \n");
        else
            printf("problem with FBO setup \n");

        glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

// depth peeling is almost like shadow mapping because with shadow mapping we have to get the first z inorder to see what casts the shadow
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int size, int key)
{
   int start=0;
   int end=size-1;
   int mid=start+(start-end)/2;    //for avoiding excess memory
   while(start<=end)
   {
      if(arr[mid]==key) return mid;
      if(key>arr[mid])
      {
         start=mid+1;
      }
      else
      {
         end=mid-1;
      }
      mid=start+(start-end)/2;
   }
   return -1;
}

int main() {
	int even[6]={2,4,6,8,12,18};
	int odd[5]={3,8,11,14,17};
	
	int index=binarySearch(odd, 5, 95);
	cout<<"index of 95 is: "<<index;
	return 0;
}
        bool in_shadow(Surface* surface) {
            // check if ray from surface to light , hits light or is stopped by an object
            Eigen::Vector3f light_direction = (this->light_point - surface->point).normalized();
            Ray shadow_ray = Ray(surface->point, light_direction);
 
            float x = (this->light_point.x() - surface->point.x()) * (this->light_point.x() - surface->point.x());
            float y = (this->light_point.y() - surface->point.y()) * (this->light_point.y() - surface->point.y());
            float z = (this->light_point.z() - surface->point.z()) * (this->light_point.z() - surface->point.z());
            
            float distance_bw_light_point = std::sqrt(x + y + z);
 
            for (const auto& s : get_surfaces()) {
                if (s != surface && s->ray_intersection(shadow_ray) && ((s->point - surface->point).norm() <= distance_bw_light_point)) { return true; }
            }
            return false;
        }
// https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/global-illumination-path-tracing-practical-implementation.html
        // https://alexanderameye.github.io/notes/sampling-the-hemisphere/
        void PointLight::global_illuminate(Ray ray, Output* out, int bounces) { 
            // when using global lighting ignore specural
            if (bounces >= out->maxbounces || static_cast<float>(rand()) / static_cast<float>(RAND_MAX) < out->probterminate) {
                // diffuse calculation = surface->dc * surface->kd * NdotL;
                for (const auto& s : get_surfaces()) {
                    if (s->ray_intersection(ray)) {
                        Eigen::Vector3f light_direction = this->centre - s->point;
                        light_direction.normalize();
                        float cos_pheta = std::max(0.0f, ((s->normal).dot(light_direction)));

                        this->final_colour.x() = s->kd * s->dc.x() * cos_pheta;
                        this->final_colour.y() = s->kd * s->dc.y() * cos_pheta;
                        this->final_colour.z() = s->kd * s->dc.z() * cos_pheta;
                    }
                }
                this->final_colour = this->final_colour / bounces;
                return; // fmax(0.0f, surface->point.normal.dot(L)) * diffuse intensity * diffuse colour
            }
            else {
                for (const auto& s : get_surfaces()) {
                    if (s->ray_intersection(ray)) {
                        // cosine weighted hemisphere sampling
                        float r1 = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); // between 0 and 1
                        float r2 = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); // between 0 and 1

                        float theta = 2 * M_PI * r2;
                        float x = std::sqrt(r1) * cos(theta);
                        float y = std::sqrt(r1) * sin(theta);

                        Eigen::Vector3f new_direction(x, y, std::sqrt(std::max(0.0f, 1-r1)));

                        // create a new ray with out random sampling direction
                        Ray bounce_ray(s->point, new_direction);

                        // here is where we recursive and do the cosine weighted hemisphere sampling to determin direction of random ray

                        Eigen::Vector3f light_direction = this->centre - s->point;
                        light_direction.normalize();
                        float cos_pheta = std::max(0.0f, ((s->normal).dot(light_direction)));

                        this->final_colour = this->final_colour + (s->kd * s->dc * cos_pheta);
                        global_illuminate(bounce_ray,out, bounces + 1);
                    }
                    else {
                        // if we dont hitanything
                        continue;
                    }
                }
                // if our ray doesnt hit anything
                return;
            }
            // check for ray intersection with objects
            // if no we need to remove it from our samples and from our average
            // else return global_illuminate(reflection reflection_ray, bounces-1) * direct illumunation with diffuse * cospheta value (N dot L)

            // at each bounces where we intersect we calculate the light contribution which is only the diffuse value
            // and at the end these product up to the pixel colour value ( add them up and divive by num bounces )
        }
class Solution {
public:
    int fillCups(vector<int>& amount) {
        sort(amount.begin(), amount.end());
        int loww=amount[0], low=amount[1], lar=amount[2];
        int sum=low+loww+lar;
        if(lar<loww+low) return sum/2+sum%2;
        else return lar;
    }
};
#include <bits/stdc++.h> 

bool isSafe(int newx, int newy, vector<vector<bool>> &visited, vector<vector<int>> &arr, int n)
    {
        if((newx>=0&&newx<n)&&(newy>=0&&newy<n)&&visited[newx][newy]!=1&&arr[newx][newy]==1)
        {
            return true;
        }
        else return false;
    }
    
    void solve(int x, int y, int n, vector<vector<int>> &arr, vector<string> &ans, vector<vector<bool>> &visited, string path)
    {
        //base case
        if(x==n-1&&y==n-1)
        {
            ans.push_back(path);
            return;
        }
        
        visited[x][y]=1;
        
        //4 movement
        //DLRU
        //down
        if(isSafe(x+1, y, visited, arr, n))
        {
            solve(x+1, y, n, arr, ans, visited, path+'D');
        }
        
        //left
        if(isSafe(x, y-1, visited, arr, n))
        {
            solve(x, y-1, n, arr, ans, visited, path+'L');
        }
        
        //right
        if(isSafe(x, y+1, visited, arr, n))
        {
            solve(x, y+1, n, arr, ans, visited, path+'R');
        }
        
        //up
        if(isSafe(x-1, y, visited, arr, n))
        {
            solve(x-1, y, n, arr, ans, visited, path+'U');
        }
        visited[x][y]=0;
    }

vector < string > searchMaze(vector < vector < int >> & arr, int n) {
    // Write your code here.
    vector<string> ans;
    vector<vector<bool>> visited(n, vector<bool> (n, 0));
    string path="";
    if(arr[0][0]==0) return ans;
    solve(0, 0, n, arr, ans, visited, path);
    return ans;
}
//////Top-Down approach / recursion-memoization////
class Solution {
public:
    
    int solve(vector<int>& cost, int n, vector<int> &dp)
    {
        if(n==0) return cost[0];
        if(n==1) return cost[1];
        if(dp[n]!=-1) return dp[n];
        dp[n]=min(solve(cost, n-1,dp),solve(cost, n-2, dp))+cost[n];
        return dp[n];
    }
    
    int minCostClimbingStairs(vector<int>& cost) {
        int n=cost.size();
        vector<int> dp(n+1, -1);
        int ans=min(solve(cost, n-1, dp),solve(cost, n-2, dp));
        return ans;
    }
};

/////Tabulation / bottom-up approach/////
class Solution {
public:
    
    int solve(vector<int>& cost, int n)
    {
        vector<int> dp(n+1, -1);
        dp[0]=cost[0];
        dp[1]=cost[1];
        for(int i=2;i<n;i++)
        {
            dp[i]=min(dp[i-1],dp[i-2])+cost[i];
        }
        return min(dp[n-1], dp[n-2]);
    }
    
    int minCostClimbingStairs(vector<int>& cost) {
        int n=cost.size();
        
        
        return solve(cost, n);
    }
};

////////space optimization///////
class Solution {
public:
    
    int solve(vector<int>& cost, int n)
    {
        int pr1=cost[0], pr2=cost[1], curr;
        for(int i=2;i<n;i++)
        {
            curr=min(pr1,pr2)+cost[i];
            pr1=pr2;
            pr2=curr;
        }
        return min(pr1, pr2);
    }
    
    int minCostClimbingStairs(vector<int>& cost) {
        int n=cost.size();
        
        
        return solve(cost, n);
    }
};
/////////////Top-down approach ( recursion+memoization )/////////////
class Solution {
public:
    
    int solve(int n, vector<int> &dp)
    {
       if(n<=1) return n;
       if(dp[n]!=-1) return dp[n];
       dp[n]=solve(n-1, dp)+solve(n-2,dp);
       return dp[n];
    } 
    
    int fib(int n) {
        vector<int> dp(n+1, -1);
        return solve(n, dp);
    }
};

/////////////////Bottom-Top approach//////////////////////
class Solution {
public:
    int fib(int n) {
        if(n<=1) return n;
        int dp[n+1];
        for(int i=0;i<=n;i++)
        {
            dp[i]=-1;
        }
        dp[0]=0;
        dp[1]=1;
        for(int i=2;i<=n;i++)
        {
            dp[i]=dp[i-1]+dp[i-2];
        }
        return dp[n];
    }
};


///////////////////////Space optimization/////////////////
class Solution {
public:
    int fib(int n) {
        if(n<=1) return n;
        int pr1=0, pr2=1, curr;
        for(int i=2;i<=n;i++)
        {
            curr=pr1+pr2;
            pr1=pr2;
            pr2=curr;
        }
        return curr;
    }
};
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long t;
	cin>>t;
	while(t--)
	{
	   long long n, q;
	   cin>>n>>q;
	   long long a[n];
	   long long sum1=0, sum2=0;
	   for(long long i=0;i<n;i++)
	   {
	      cin>>a[i];
	   }
	   long long int prefsum[n+1];
	   prefsum[0]=0;
	   for(int i=0;i<n;i++)
	   {
	       sum1+=a[i];
	       prefsum[i+1]=sum1;
	       
	   }
	   while(q--)
	   {
	      long long l,r,k;
	      cin>>l>>r>>k;
	      long long int p=prefsum[r]-prefsum[l-1];
	      sum2=prefsum[n]+((k*(r-l+1))-p);
	      if(sum2%2==1) cout<<"YES\n";
         else cout<<"NO\n";
	   }
	}
	return 0;
}
class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        unordered_map<int, int> mp;
        for(int i=0;i<nums.size();i++)
        {
            mp[nums[i]]++;
        }
        priority_queue<pair<int,int>, vector<pair<int, int>>, greater<pair<int, int>>>minH;
        for(auto x:mp)
        {
            minH.push({x.second, x.first});
            if(minH.size()>k) minH.pop();
        }
        vector<int> ans;
        while(!minH.empty())
        {
            ans.push_back(minH.top().second);
            minH.pop();
        }
        return ans;
    }
};
class Solution {
public:
    vector<vector<int>> kClosest(vector<vector<int>>& points, int k) {
        int n=points.size();
        priority_queue<pair<int,pair<int, int>>> mxH;
        for(int i=0;i<n;i++)
        {
            int dis=pow(points[i][0],2)+pow(points[i][1],2);
            mxH.push({dis,{points[i][0], points[i][1]}});
            if(mxH.size()>k) mxH.pop();
        }
        vector<vector<int>> ans;
        while(!mxH.empty())
        {
            vector<int> temp;
            temp.push_back(mxH.top().second.first);
            temp.push_back(mxH.top().second.second);
            ans.push_back(temp);
            mxH.pop();
        }
        
        return ans;
    }
};
class Solution {
public:
    int c=0;
    
    void bfs(vector<vector<int>>& isConnected, vector<bool> &v, int i,  unordered_map<int, set<int>> &m)
    {
        queue<int> q;
        q.push(i);
        v[i]=true;
        while(!q.empty())
        {
            int p=q.front();
            q.pop();
            
            for(auto x:m[p])
            {
                if(!v[x])
                {
                    q.push(x);
                    v[x]=true;
                }
            }
        }
    }
    void makeadj(vector<vector<int>> &isConnected, unordered_map<int, set<int>> &m)
    {
        int n=isConnected.size();
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(isConnected[i][j]==1)
                {
                    m[i+1].insert(j+1);
                    m[j+1].insert(i+1);
                }
            }
        }
    }
    
    int findCircleNum(vector<vector<int>>& isConnected) {
        int n=isConnected.size();
        vector<bool> v(n+1,false);
        unordered_map<int, set<int>> m;
        makeadj(isConnected, m);
        for(int i=1;i<=n;i++)
        {
            if(!v[i])
            {
                c++;
                bfs(isConnected, v, i, m);
            }
        }
        return c;
    }
};
class Solution {
public:
    bool canVisitAllRooms(vector<vector<int>>& rooms) {
        int n=rooms.size();
        vector<bool> visited(n, 0);
        queue<int>q;
        q.push(0);
        visited[0]=1;
        while(!q.empty())
        {
            int p=q.front();
            q.pop();
            
            for(auto x:rooms[p])
            {
                if(!visited[x])
                {
                    q.push(x);
                    visited[x]=1;
                }
            }
        }
        bool g=true;
        for(auto x:visited)
        {
            if(!x) g=false;
        }
        return g;
    }
};
class Solution {
public:
    vector<int> findSmallestSetOfVertices(int n, vector<vector<int>>& edges) {
        vector<bool> v(n,false);
        for(int i=0;i<edges.size();i++)
        {
            v[edges[i][1]]=true;
        }
        vector<int> ans;
        for(int i=0;i<n;i++)
        {
            if(!v[i]) ans.push_back(i);
        }
        return ans;
    }
};
class Solution {
public:
    vector<vector<int>> ans;
    
    void dfs(int curr, int dest, vector<vector<int>>& graph, vector<int> &path)
    {
        path.push_back(curr);
        if(curr==dest)
        {
            ans.push_back(path);
        }
        else
        {
            for(auto x:graph[curr])
            {
                dfs(x, dest, graph, path);
            }
        }
        path.pop_back();
    }
    
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        int n=graph.size()-1;
        
        vector<int> path;
        dfs(0, n, graph, path);
        return ans;
    }
};
class Solution {
public:
    int findJudge(int n, vector<vector<int>>& trust) {
        vector<int> v2(n+1,0);
        vector<int> v3(n+1,0);
        for(int i=0;i<trust.size();i++)
        {
            int u=trust[i][0];
            int v=trust[i][1];
            v2[v]++;
            v3[u]++;
        }
        int ans=-1;
       for(int i=1;i<=n;i++)
       {
           if(v2[i]==n-1&&v3[i]==0) ans=i;
       }
        return ans;
    }
};
class Solution {
public:
    bool validPath(int n, vector<vector<int>>& edges, int source, int destination) {
        unordered_map<int, set<int>>m;
        vector<bool> visited(n, false);
        visited[destination]=0;
        for(int i=0;i<edges.size();i++)
        {
            int u=edges[i][0];
            int v=edges[i][1];
            m[u].insert(v);
            m[v].insert(u);
        }
        queue<int>q;
        q.push(source);
        visited[source]=true;
        while(!q.empty())
        {
            int p=q.front();
            q.pop();
            
            
            for(auto x:m[p])
            {
                if(!visited[x])
                {
                    q.push(x);
                    visited[x]=true;
                }
            }
        }
        if(visited[destination]==1) return true;
        return false;
    }
};
class Solution {
public:
    int findCenter(vector<vector<int>>& edges) {
        int n=edges.size();
        unordered_map<int, int>m;
        for(int i=0;i<n;i++)
        {
            m[edges[i][0]]++;
            m[edges[i][1]]++;
        }
        int ans=0;
        for(auto x:m)
        {
            if(x.second==n)
            {
                ans=x.first;
                break;
            }
        }
        return ans;
    }
};
#include<bits/stdc++.h>

void mkadj(unordered_map<int, set<int>> &mp, vector<vector<int>> &edges)
{
    for(int i=0;i<edges.size();i++)
    {
        int u = edges[i][0];
        int v = edges[i][1];

        mp[u].insert(v);
        mp[v].insert(u);
    }
}

void dfs(unordered_map<int, set<int>> &mp, unordered_map<int, bool> &visited, vector<int> &comp, int node)
{
    comp.push_back(node);
    visited[node]=true;
    for(auto x:mp[node])
    {
        if(!visited[x]) dfs(mp, visited, comp, x);
    }
}

vector<vector<int>> depthFirstSearch(int V, int E, vector<vector<int>> &edges)
{
    unordered_map<int, set<int>> mp;
    unordered_map<int, bool> visited;
    mkadj(mp, edges);
   
    vector<vector<int>> ans;
    
    for(int i=0;i<V;i++)
    {
        if(!visited[i])
        {
            vector<int> comp;
            dfs(mp, visited, comp, i);
            ans.push_back(comp);
        }

    }
    return ans;
    // Write your code here
}
#include <bits/stdc++.h> 

void makeAdj(unordered_map<int, set<int>>&mp1, vector<pair<int, int>> &edges)
{
    for(int i=0; i<edges.size(); i++)
    {
        int u = edges[i].first;
        int v = edges[i].second;
        mp1[u].insert(v);
        mp1[v].insert(u);
    }
}

void bfstrav(vector<int> &ans, unordered_map<int, bool> &visited, unordered_map<int, set<int>>&mp1, int node)
{
    queue<int> q;
    q.push(node);
    visited[node]=1;

    while(!q.empty())
    {
        int p=q.front();
        q.pop();

        ans.push_back(p);

        for(auto x: mp1[p])
        {
            if(!visited[x]) 
            {
                q.push(x);
                visited[x]=1;
            }
        }

    }
}


vector<int> BFS(int vertex,vector<pair<int, int>> edges)
{
    vector<int> ans;
    unordered_map<int, bool> visited;
    unordered_map<int, set<int>>mp1;
    makeAdj(mp1, edges);
    for(int i=0;i<vertex;i++)
    {
        if(!visited[i]) bfstrav(ans, visited, mp1, i);
    }
    return ans;
    // Write your code here
}
class Solution {
  public:
    // Function to return the adjacency list for each vertex.
    vector<vector<int>> printGraph(int V, vector<int> adj[]) {
        vector<vector<int>> v2;
        for(int i=0;i<V;i++)
        {
            vector<int> v1;
            v1.push_back(i);
            for(int j=0;j<adj[i].size();j++)
            {
                v1.push_back(adj[i][j]);
            }
            v2.push_back(v1);
        }
        return v2;
    }
};
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int w; // width of the building.
    int h; // height of the building.
    cin >> w >> h; cin.ignore();
    int n; // maximum number of turns before game over.
    cin >> n; cin.ignore();
    int x0;
    int y0;
    cin >> x0 >> y0; cin.ignore();
    int w0 = 0 , h0 = 0;

    // game loop
    while (1) {
        string bomb_dir; // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
        cin >> bomb_dir; cin.ignore();


        if (bomb_dir.find("U") != string::npos){
            h = y0;
            y0 = ((y0+h0)/2) ;
        }
        if (bomb_dir.find("D") != string::npos){
            h0 = y0;
            y0 = floor((y0+h)/2);
        }
        if(bomb_dir.find("R") != string::npos){
            w0 = x0;
            x0 = floor((x0+w) /2);
        }
        if(bomb_dir.find("L") != string::npos){
            w = x0;
            x0 = floor((x0+w0)/2);
        }

        cout << to_string(x0) + " " + to_string(y0) << endl;
    }
}
vector < vector < int >> printAdjacency(int n, int m, vector < vector < int >> & edges) {
    vector<int> ans[n];
    //ans array will store all adjaject nodes corresponding to indexes.
    for(int i=0;i<m;i++)
    {
        int u=edges[i][0];
        int v=edges[i][1];

        ans[u].push_back(v);
        ans[v].push_back(u);
    }

    vector<vector<int>> adj(n);
    for(int i=0;i<n;i++)
    {
        adj[i].push_back(i);

        //entering neighbours
        for(int j=0;j<ans[i].size();j++)
        {
            adj[i].push_back(ans[i][j]);
        }
    }
    return adj;
}
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */

class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if(!root) return NULL;
        if(root==p||root==q) return root;
        
        TreeNode* l=lowestCommonAncestor(root->left, p, q);
        TreeNode* r=lowestCommonAncestor(root->right, p, q);
        
        if(!l) return r;
        else if(!r) return l;
        else return root;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

//BFS Travesal

class Solution {
public:
    int kthSmallest(TreeNode* root, int k) {
        vector<int> v;
        queue<TreeNode*> q;
        TreeNode* p;
        q.push(root);
        
        while(!q.empty())
        {
            p=q.front();
            q.pop();
            ///int p2=p->val;
            v.push_back(p->val);
            if(p->left) q.push(p->left);
            if(p->right) q.push(p->right);
        }
        sort(v.begin(), v.end());
        return v[k-1];
    }
};

//Inorder traversal

class Solution {
public:
    int kthSmallest(TreeNode* root, int k) {
        vector<int> v;
        queue<TreeNode*> q;
        TreeNode* p;
        q.push(root);
        
        while(!q.empty())
        {
            p=q.front();
            q.pop();
            ///int p2=p->val;
            v.push_back(p->val);
            if(p->left) q.push(p->left);
            if(p->right) q.push(p->right);
        }
        sort(v.begin(), v.end());
        return v[k-1];
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    
    bool isValidBST(TreeNode* root) {
       
        return check(root, LONG_MIN, LONG_MAX);
    }
    
   bool check(TreeNode* root, long minval, long maxval)
   {
       if(!root) return true;
       if(root->val>=maxval||root->val<=minval) return false;
       
       return check(root->left, minval, root->val)&&check(root->right, root->val, maxval);
   }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if(!root) return NULL;
        if(root==p||root==q) return root;
        TreeNode* l=lowestCommonAncestor(root->left, p, q);
        TreeNode* r=lowestCommonAncestor(root->right, p, q);
        
        if(!l) return r;
        else if(!r) return l;
        else return root;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    
    int largeheight(TreeNode* root)
    {
        if(!root) return 0;
        return max(largeheight(root->left), largeheight(root->right))+1;
    }

    int diameterOfBinaryTree(TreeNode* root) {
        if(!root) return 0;
        int h1=largeheight(root->left);
        int h2=largeheight(root->right);
        int p1=h1+h2;
        return max(p1, max(diameterOfBinaryTree(root->left), diameterOfBinaryTree(root->right)));
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> v;
    void solve(TreeNode* root, vector<int> &ans, int curr, int targetSum)
    {
        if(!root) return;
        curr+=root->val;
        ans.push_back(root->val);
        if(curr==targetSum && !root->left && !root->right) v.push_back(ans);
        if(root->left) solve(root->left, ans, curr, targetSum);
        if(root->right) solve(root->right, ans, curr, targetSum);
        ans.pop_back();
    }
    
    vector<vector<int>> pathSum(TreeNode* root, int targetSum) {
        vector<int> ans;
        solve(root, ans, 0, targetSum);
        return v;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */


class Solution {
public:
    bool hasPathSum(TreeNode* root, int targetSum) {
        if(!root) return false;
        if(!root->left&&!root->right) 
        {
            return (targetSum==root->val) ;
        }
        bool p=false;
        if(root->left) p = hasPathSum(root->left, targetSum-root->val);
        if(root->right) p=p||hasPathSum(root->right, targetSum-root->val);
        
        return p;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> verticalTraversal(TreeNode* root) {
        vector<vector<int>> v;
        if(!root) return v;
        map<int, map<int, vector<int>>> mp;
        queue<pair<TreeNode*, pair<int,int>>>q;
        q.push({root, {0,0}});
        while(!q.empty())
        {
            auto f=q.front();
            q.pop();
            int p8=f.first->val;
            int hdfo=f.second.first;
            int dfo=f.second.second;
            mp[hdfo][dfo].push_back(p8);
            if(f.first->left) q.push({f.first->left, {hdfo-1, dfo+1}});
            if(f.first->right) q.push({f.first->right, {hdfo+1, dfo+1}});
        }
        
        for(auto i:mp)
        {
            vector<int> v2;
            for(auto j:i.second)
            {
                sort(j.second.begin(), j.second.end());
                for(auto k:j.second)
                {
                    v2.push_back(k);
                }
            }
            v.push_back(v2);
        }
        return v;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root) {
        vector<vector<int>> v;
        queue<TreeNode*> q;
        q.push(root);
        if(!root) return v;
        while(!q.empty())
        {
            vector<int> v2;
            int p1=q.size();
            while(p1--)
            {
                TreeNode* temp=q.front();
                q.pop();
                v2.push_back(temp->val);
                if(temp->left) q.push(temp->left);
                if(temp->right) q.push(temp->right);
            }
            v.push_back(v2);
            
        }
        reverse(v.begin(), v.end());
        return v;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {
        queue<TreeNode*> q;
        q.push(root);
        vector<vector<int>> v;
        if(root==NULL) return v;
        bool p=true;
        while(!q.empty())
        {
            vector<int> v2;
            int p2=q.size();
            while(p2--)
            {
                TreeNode* temp=q.front();
                q.pop();
                v2.push_back(temp->val);
                if(temp->left) q.push(temp->left);
                if(temp->right) q.push(temp->right);
            }
            
            if(!p) 
            {
                reverse(v2.begin(), v2.end());
                p=true;
            }
            else p=false;
            v.push_back(v2);
        }
        return v;
    }
};
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> v;
        if(root==NULL) return v;
        queue<TreeNode*> q;
        q.push(root);
        while(!q.empty())
        {
            vector<int> v2;
            int p=q.size();
            while(p--)
            {
                TreeNode* temp=q.front();
                q.pop();
                
                v2.push_back(temp->val);
                if(temp->left) q.push(temp->left);
                if(temp->right) q.push(temp->right);
                
            }
            v.push_back(v2);
            
        }
        
        return v;
    }
};
#include <iostream>

int main() {
    int b;
    std::cout << "Podaj ilosć liczn: ";
    std::cin >> b;
    int a[b];

    for(int i = 0; i < b; ++i){
        std::cout << "Podaj liczbe " << i +1 << ": ";
        std::cin >> a[i];
        std::cout << "\n";
    }

    int maks = a[0];
    for(int i = 0; i < b; ++i) {
        if(a[i] > maks){
            maks = a[i];
        }
    }

    for(int i = 0; i < maks; i++){
        for(int j = 0; j < b; j++) {
            if(a[j] < maks - i ){
                std::cout << " ";}
            else{
                std::cout << "*";}
        }
        std::cout << "\n";
    }
    return 0;
}
#include <stdlib.h>
#include <stdio.h>
using namespace std;

struct Array
{
    int *A;
    int size;
    int length;
};

void Display(struct Array arr)
{
  int i;
  printf("\n Elements are \n");
  for(i=0; i<arr.length; i++)
    printf("%d ", arr.A[i]);
}

void Append (struct Array *arr, int x)
{
  if(arr->length < arr->size)
    arr->A[arr->length++] = x;
}

void Insert(struct Array *arr, int index, int x)
{
  int i;
  if(index >= 0 && index <= arr->length)
    {
      for(i=arr->length; i>index; i--)
        arr->A[i] = arr->A[i-1];
      arr->A[index]=x;
      arr->length++;
    }
}

int main() 
{
    struct Array arr= {{2,3,4,5,6}, 10, 5};
	Append(&arr, 10);
	insert(&arr, 5, 10);
	Display(arr);
  
    //printf("Enter the size of an array : ") ;
    //scanf("%d", &arr.size);
    //arr.A = (int *)malloc(arr.size*sizeof(int));
    //arr.length=0;

    return 0;
}
#include <iostream>
using namespace std;
 
void TOH(int n, int a, int b, int c)
{
    if(n>0)
    {
        TOH(n-1,a,c,b);
        cout << "from " << a << " to " << c <<endl;
        TOH(n-1,b,a,c);
    }
}
int main() 
{
    TOH(6,1,2,3);
    return 0;
}
#include <iostream>
using namespace std;

int fact(int n)
{
    if (n==0) return 1;
    else return fact(n-1)*n;
}

int ncr(int n, int r)
{
    int num, den;
    num = fact(n);
    den = fact(r)*fact(n-r);
    return num/den;
}

int NCR(int n, int r)  //using recursion
{
    if (n==r || r==0)
        return 1;
    else
        return NCR(n-1, r-1) + NCR(n-1,r);
}

int main() 
{
    cout << ncr(2,0) << endl;
    cout << NCR(5,1);
    return 0;
}
#include <iostream>
using namespace std;

int F[10];     //all array elements are initialized with -1
int fib(int n)
{
    if (n<=1)
    {
        F[n] = n;
        return n;
    }
    else
    {
        if (F[n-2] == -1)
            F[n-2]= fib(n-2);
        if (F[n-1] == -1) 
            F[n-1] = fib (n-1);
        return  F[n-2] + F[n-1];
    }
}

int main() 
{
    for(int i=0; i<10; i++)
        F[i]=-1;
    cout << fib(9);
    return 0;
}
#include <iostream>
using namespace std;

int fib( int n)
{
    if (n<=1)
        return n;
    else 
        return fib(n-1) + fib(n-2);
}


int main() 
{
    cout << fib(9);
    return 0;
}
#include <iostream>
using namespace std;

int fib(int n)
{
    int t0 = 0, t1 = 1, s=0, i;
    if (n<=1)
        return n;
    else
        for(i=2;i<=n;i++)
        {
            s = t0 + t1;
            t0 = t1;
            t1 = s;
        } 
        return s;
}

int main() 
{
    cout << fib(9);
    return 0;
}
#include <iostream>
using namespace std;



double e(int x, int n)
{
    static double s;
    if (n==0)
        return s;
    else
        s = 1 + x*(s/n);
        return e(x, n-1);
}


int main() {
    double sum= e(1,10);
    cout << sum;
    return 0;
}
#include <iostream>
using namespace std;

double e (int x, int n)
{
    static double p=1, f=1;
    double r=0;
    if (n==0)
        return 1;
    else
        r = e(x,n-1);
        p=p*x;
        f=f*n;
        return r+(p/f);
}

int main() {
    double sum= e(1,10);
    cout << sum;
    return 0;
}
#include <iostream>
using namespace std;

int fun(int n)
{
    if(n>100)
        return n-10;
    else
        fun(fun(n+11));    //nested recursive call
}

int main() 
{
    cout << fun(97);
  
    return 0;
}
#include <iostream>
using namespace std;

void funB(int n);

void funA(int n)
{
    if(n>0)
    {
        cout << n << " ";
        funB(n-1);
    }
}
void funB(int n)
{
    if(n>1)
    {
        cout <<n <<" ";
        funA(n/2);
    }
}

int main() 
{
    funA(20);
    return 0;
}
#include <iostream>
using namespace std;

void fun(int n)
{
    if(n>0)
    {
        cout << n << " ";
        fun(n-1);
        fun(n-1);
    }
}

int main() 
{
    fun(3);
    return 0;
}
#include <iostream>
using namespace std;

//int x= 0;      or .....global variable
int fun(int n)
{
    static int x=0;       //local static variable
    if(n>0)
    {
        x++;
       return fun(n-1) +x;
    }
    return 0;
}
int main() 
{
    int r;
    r = fun(5);
    cout<<r;
    return 0;
}
#include <iostream>
using namespace std;

template <class T>
class Arithmetic
{
private :
    T a;
    T b;
public :
    Arithmetic(T a,T b);
    T add();
    T sub();
};

template<class T>
Arithmetic<T>::Arithmetic(T a,T b)
{
    this->a =a;
    this->b =b;
}

template <class T>
T Arithmetic<T>:: add()
{
    T c;
    c = a+b;
    return c;
}

template <class T>
T Arithmetic<T>:: sub()
{
    T c;
    c = a-b;
    return c;
}

int main() 
{
    Arithmetic<int> ar(10,5);
    cout<<ar.add()<<endl;
    cout<<ar.sub()<<endl;
    
    Arithmetic<float> ar1(1.22,1.3);
    cout<<ar1.add()<<endl;
    cout<<ar1.sub()<<endl;
    
    return 0;
}
#include <iostream>;
#include <string>;
#include <random>;
using namespace std;

class Auto
{
public:
    void Start();
    void Accelerate();
    void Break();
    string model;
    string cylinder;

    Auto(string x, string y)
    {
        model = x;
        cylinder = y;
    }
};
void Start()
{
    cout << "Start\n";
}
void Accelerate()
{
    cout << "Accelerate\n";
}
void Break()
{
    cout << "Break\n";
}

int main()
{
    srand(time(NULL));

    int randomAction;
    int randomAuto;
    randomAction = (rand() % 3) + 1;
    randomAuto = (rand() % 3) + 1;

    switch (randomAction)
    {
    case 1:
        Start();
        break;
    case 2:
        Accelerate();
        break;
    case 3:
        Break();
        break;
    }

    Auto auto1("CADILAC", "5");
    Auto auto2("Ferrari", "7");
    Auto auto3("Lamborghini", "9");

    switch (randomAuto)
    {
    case 1:
        cout << "The model is: " << auto1.model << ", and the cylinder is: " << auto1.cylinder << endl;
        break;
    case 2:
        cout << "The model is: " << auto2.model << ", and the cylinder is: " << auto2.cylinder << endl;
        break;
    case 3:
        cout << "The model is: " << auto3.model << ", and the cylinder is: " << auto3.cylinder << endl;
        break;
    }
}
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

class nodes { //objet node
public :
    nodes() {
        next = NULL;
    }
    int element; //element dans la node
    nodes* next; //prochain element
}*front = NULL, *rear=NULL, *n, *temp, *temp1; //initialisation des variables

class circularqueue { //objet de la queue circulaire
public :
    //Fonctions des queues circulaire
    void InsertQueue(); 
    void Delete();
    void SearchQueue();
    void DisplayQueue();
};

//Fonction delete des queues circulaires
void circularqueue::Delete() {
    int x; // element à enlever
    temp = front; // temp devient la position de front
    if (front == NULL) { //Si pas de front (empty)
        cout << "The queue is empty" << endl;
    }
    else {
        if (front == rear) {//si positon de front est la meme que rear (un seul element)
            x = front->element; //x devient la valeur de front
            delete(temp); //enleve l'élément qui est à la position de temp(front)
            front = NULL; //Remet front à null
            rear = NULL;// remet rear à null
        }
        else {
            x = temp->element; //x devient la valeur de front (temp == front)
            front = front->next; //front devient le prochain élément
            rear->next = front; //la position de rear devient la position du prochain de front (rear devient l'ancien front)
            delete(temp); //eneleve l'élement temporaire
        }
        cout << "Element " << x << " has been deleted" << endl;
    }
}
void circularqueue::InsertQueue() {
    n = new nodes[sizeof(nodes)]; //crée un nouvel objet node
    cout << "Enter the element you wish to insert: ";
    cin >> n->element; //entrer l'élément de la nouvelle node
    if (front == NULL) { //si front est null
        front = n; //emplacement de front est maintenant la valeur entrée
    } else
    {
        rear->next = n; //position de rear devient le prochain
    }
    rear = n; //l'emplacement rear devient la valeur entrée
    rear->next = front; //position rear devient le prochain
}

void circularqueue::SearchQueue(){
    int search; // Valeur a chercher dans la queue
    int n = 0; //Compteur

    temp = front; // Valeur temporaire est à front;
    temp1 = NULL; // Autre valeur temp. est nulle

    if (front == NULL) { //Si front na pas d'élément
        cout << "The queue is empty..." << endl;
    }
    else {
        cout << "Enter the element you are searching for: ";
        cin >> search; //Enter l'élément à trouver

        while (temp != temp1) { //Fait pendant que la valeur temp != front
            if (search == temp->element) { //si le search est egal à l'élément de la node
                n++; //ajoute au compteur
                temp = temp->next; //change la valeur du front pour la prochaine valeur
                temp1 = front; //Deuxieme temporaire devient la valeur front
            }
        }
        cout << "The element " << search << " is in the queue " << n << " times." << endl;
    }
    return ;
}

void circularqueue::DisplayQueue() {
    temp = front; //temp devient la position de front
    temp1 = NULL; //deuxieme temp  est NULL
    if (front == NULL) { //si la front est vide
        cout << " The queue is empty..." << endl;
    }
    else { //si c'est pas vide
        cout << "The elements in the queue are: ";
        while (temp != temp1) { //pendant que temp n'est pas temp1 (le tour de la queue n'est pas complétée)
            cout << temp->element << " ";
            temp = temp->next; //temp devient la prochaine position
            temp1 = front; //temp 1 devient le front
        }
    }
 }
void OptionList() {
    cout << "1: Insert in the queue." << endl;
    cout << "2: Delete from the queue." << endl;
    cout << "3: Search the queue." << endl;
    cout << "4: Display the queue." << endl;
}
int main() {
    int opt; //option choisie
    bool whileTrue = true; //bool qui est toujours true pour options

    circularqueue Queue; //crée une nouvel object de circular queue
    
    //choisir un option
    while (whileTrue) {

        OptionList();

        cout << "Enter your desired option: ";
        cin >> opt;

        switch (opt) {
        case 1: Queue.InsertQueue();
            break;
        case 2: Queue.Delete();
            break;
        case 3:Queue.SearchQueue();
            break;
        case 4: Queue.DisplayQueue();
            break;
        }

    }
}
#include <iostream>
using namespace std;

class Rectangle
{
    public :
    int length;
    int breadth;

Rectangle(int l, int b)
{
    length = l;
    breadth = b;
}

int area()
{
    return length*breadth;
}

int perimeter()
{
    int p = 2*(length*breadth);
    return p;
}
};

int main() 
{
    int l,b;
    cout << "Enter length and breadth : ";
    cin >> l >> b;
    Rectangle r(l,b);
    
    int a = r.area();
    cout <<"Area is : "<<a << endl;
    
    int peri = r.perimeter();
    cout <<"perimeter is :"<<peri;

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

struct rectangle
{
    int length;
    int breadth;
};

void initialize(struct rectangle *r, int l, int b)
{
    r->length = l;
    r->breadth = b;
}

int area(rectangle r)
{
    return r.length*r.breadth;
}

int perimeter(rectangle r)
{
    int p = 2*(r.length*r.breadth);
    return p;
}

int main() 
{
    rectangle r={0,0};
    int l,b;
    cout << "Enter length and breadth : ";
    cin >> l >> b;
    initialize(&r,l,b);
    
    int a = area(r);
    cout <<"Area is : "<<a << endl;
    
    int peri = perimeter(r);
    cout <<"perimeter is :"<<peri;

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

int area(int length, int breadth)
{
    return length*breadth;
}

int perimeter(int length, int breadth)
{
    int p = 2*(length*breadth);
    return p;
}

int main() 
{
    int length = 0, breadth =0;
    cout << "Enter length and breadth : ";
    cin >> length >> breadth;
    
    int a = area(length,breadth);
    cout <<"Area is : "<<a << endl;
    
    int peri = perimeter(length,breadth);
    cout <<"perimeter is :"<<peri;

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

int main() 
{
    int length = 0, breadth =0;
    cout << "Enter length and breadth : ";
    cin >> length >> breadth;
    
    int area = length*breadth;
    cout <<"Area is : "<<area << endl;
    
    int peri = 2*(length*breadth);
    cout <<"perimeter is :"<<peri;

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

struct rectangle
{
  int length;
  int breadth;
};

struct rectangle *fun()
{
  struct rectangle *p;
  p = new rectangle;
  //p= (struct rectangle *)malloc(sizeof(struct rectangle));
  
  p->length = 15;
  p->breadth = 7;
  
  return p;
}

int main()
{
  struct rectangle *ptr = fun();
  cout << "length : "<<ptr->length<<endl<<"breadth : "<< ptr->breadth<<endl;
  
  return 0;
}
#include <iostream>
using namespace std;

int fun(int size)
{
  int *p;
  p = new int[size];
  
  for(int i=0; i<size; i++)
    p[i]=i+1;
  return p;
}

int main()
{
  int *ptr, sz = 5;
  ptr = fun(sz);
  
  for(int i=0;i<sz;i++)
    cout << ptr[i]<<endl;
  
  return 0;
}
#include <iostream>
using namespace std;

void swap(int &x, int &y)      //passing the reference
{
  int temp;
  temp = x;
  x=y;
  y = temp;
}

int main()
{
  int a, b;
  a=10;
  b=20;
  swap(a,b);
  
  cout << "a = "<<a <<", b = "<<b << endl;     //a = 10, b = 20
  
  return 0;
}
#include <iostream>
using namespace std;
 
void swap(int *x, int *y)        //getting the pointers 
{
  int temp;
  temp = *x;
  *x=*y;
  *y = temp;
}
int main()
{
  int a, b;
  a=10;
  b=20;
  swap(&a,&b);          //passing the address
  
  cout << "a = "<<a <<", b = "<<b << endl;     //a = 10, b = 20
  
  return 0;
}
#include <iostream>
using namespace std;

void swap(int x, int y)
{
  int temp;
  temp = x;
  x=y;
  y = temp;
}
int main()
{
  int a, b;
  a=10;
  b=20;
  swap(a,b);
  
  cout << "a = "<<a <<", b = "<<b << endl;     //a = 10, b = 20
  
  return 0;
}
#include<iostream>
using namespace std;
int main()
{
 int arr[10] = {0},key,c,d,ch=1;     //k = key, c = collision, d = data
 for(int i=0; i<=9 ; i++)
 {
  cout<<" "<<arr[i];
 }
 while(ch==1)
 {
  cout<<"\nEnter Key";
  cin>>key;
    c = 0;
  d = key % 10;
  for(int i=0;i<=9;i++)
  {
   if(arr[d]>0)
   {
    d++;
    c++;
   }
  }
  arr[d]  = key;
  for(int i=0;i<=9;i++)
  {
  cout<<arr[i]<<endl;;
  }
  cout<<"\nCollisions: "<<c;
  cout<<"Do you want to continue: ";
  cin>>ch;
 }

 return 0;
 }
​#include <iostream>

using namespace std;

int main()
{
    // structura repetitiva
    /// citim un numar oarecare

    for(int i = 1; i <= 5; i = i + 1)
        cout << i << ' ';

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

struct rectangle
{
    int length;
    int breadth;
};

int main() {
    
    rectangle *p;
    // in C, struct rectangle *p;
    
    p = new rectangle;
    //in C, p = (struct rectangle *)malloc(sizeof(struct rectangle));
    
    p->length = 15;
    p->breadth= 7;
    
    cout << "length : "<<p->length<<endl;
    cout << "breadth : "<<p->breadth<<endl;
    
    
 return 0;
}
#include <iostream>
using namespace std;

struct rectangle
{
    int length;
    int breadth;
};

int main() {
   rectangle r={10,5};
   cout <<"length : "<<r.length<<endl;
   cout <<"breadth : "<<r.breadth<<endl<<endl;
   
   cout << "using pointer : " <<endl;
   rectangle *p =&r;  
   cout <<"length : "<< p->length <<endl;
   cout <<"breadth : "<< p->breadth <<endl;

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

int main()
{
    int a= 10;
    int &r = a;
    
    cout <<"a : "<<a<<"  r : "<<r<<endl;
    
    r= 25;
    cout <<"a : "<<a<<"  r : "<<r<<endl;
    
    int b=30;
    r=b;
    cout <<"b : "<<b<<"  a : "<<a<<"  r : "<<r<<endl;
    
  return 0;
}
node* searchBST(node* root, int val)
{
   while(root!=NULL||root->data!=val)
   {
      if(root->data>val) root=root->left;
      else root=root->right;
   }
   return root;
}
int findceil(node* root, int key)
{
   int ceil=-1;
   while(root)
   {
      if(root->data==key)
      {
         ceil=key;
         return ceil;
      }
      
      if(root->data<key)
      {
         root=root->right;
      }
      else 
      {
         ceil=root->data;
         root=root->left;
      }
   }
   return ceil;
}
int mxheight(Node* root)
{
    if(root==NULL) return 0;
    return max(mxheight(root->left), mxheight(root->right))+1;
}
class Solution {
  public:
    // Function to return the diameter of a Binary Tree.
    int diameter(Node* root) {
        // Your code here
        if(root==NULL) return 0;
        int p=mxheight(root->left)+mxheight(root->right)+1;
        return max(p, max(diameter(root->left), diameter(root->right)));
    }
};
int countLeaves(Node* root)
{
    int c=0;
    queue<Node*> q;
    q.push(root);
    
    while(!q.empty())
    {
        Node* temp=q.front();
        q.pop();
        
        if(temp->left==NULL&&temp->right==NULL) c++;
        
        if(temp->left) q.push(temp->left);
        if(temp->right) q.push(temp->right);
    }
    return c;
  // Your code here
}
#include <bits/stdc++.h>
using namespace std;

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

node* buildTree(node* root)
{
   cout<<"Enter the data: "<<"\n";
   int data;
   cin>>data;
   root = new node(data);
   if(data==-1) return NULL;
   
   cout<<"please enter the data for inserting left of "<<data<<endl;
   root->left=buildTree(root->left);
   cout<<"please enter the data for inserting right of "<<data<<endl;
   root->right=buildTree(root->right);
   return root;
}

void levelordertraversal(node* root)
{
   queue<node*> q;
   q.push(root);
   
   while(!q.empty())
   {
      node* temp=new node(q.front());
      q.pop();
      
      if(temp==NULL)
      {
         q.push(NULL);
         cout<<"\n";
      }
      else
      {
         cout<<temp->data<<" ";
         if(temp->left) q.push(temp->left);
         if(temp-right) q.push(temp->right);
      }
   }
}

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

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

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

void buildFromLevelorder(node* root){
   queue<node*> q;
   cout<<"Enter data for root"<<endl;
   int data;
   cin>>data;
   root=new node(data);
   q.push(root);
   
   while(!q.empty())
   {
      node* temp=q.front();
      q.pop();
      
      cout<<"Enter left node for: "<<temp->data<<endl;
      int leftData;
      cin>>leftData;
      
      if(leftData!=-1){
         temp->left=new node(leftData);
         q.push(temp->left);
      }
      
      cout<<"Enter right node for: "<<temp->data<<endl;
      int rightData;
      cin>>rightData;
      
      if(rightData!=-1)
      {
         temp->right=new node(rightData);
         q.push(temp->right);
      }
   }
}


int main() {
   node* root=NULL;
   buildFromLevelorder(root);
   
// 	root=buildTree(root);
// 	cout<<"Levelordertraversal of tree:- \n";
// 	levelOrderTravesal(root);
// 	cout<<"print preorder: "<<preorder(root)<<"\n";
// 	cout<<"print Inorder: "<<Inorder(root)<<"\n";
// 	cout<<"print preorder: "<<postorderorder(root);
	
	return 0;
}
class Solution {
public:
    bool isPowerOfTwo(int n) {
        if(n==1) return true;
        if(n==0||n%2!=0) return false;
        return isPowerOfTwo(n/2);
    }
};
class Solution {
public:
    bool isPowerOfFour(int n) {
        
        if(n==1) return true;
        if(n==0||n%4!=0) return false;
        return isPowerOfFour(n/4);
        
    }
};
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n=nums.size();
        int l=0,r=0;
        int sum=0, ans=INT_MAX;
        while(r < n)
        {
            sum+=nums[r];
            while(sum >= target) 
            {
                //if(sum==target)
                ans = min(ans, r-l+1);
                sum -= nums[l];
                l++;
            }
            r++;
        }
        if (ans == INT_MAX) return 0;
        return ans;
    }
};
#include <iostream>
using namespace std;

class linkedlist
{
	public:
	struct node
	{
		int data;
		node *next;
	}*last, *temp, *head;
//	node *last; node *temp;  node *head;
	
	public:
		void append();
		void display();                                                                                                       
}l1;

void linkedlist :: append()
{
	node *last; node *temp;  node *head;
	int value;
	temp = new node;
	cout << "Enter data : ";
	cin >> value;
	temp->data = value;
	temp->next = NULL;
	if(head == NULL)
	{
		head = temp = last;
	}
	else
	{
		last->next = temp;
		last = temp;
	}
	cout << "New node created!"<< endl;
}

void linkedlist :: display()
{
	temp = head;
	while(temp != NULL)
	{
		cout << temp->data << endl;
		temp = temp->next;
	}
}


int main()
{
	int ch; int choice;
	do{
	cout << "-----Linked List-----\n\n";
	cout << "1. Create first node\n";
	cout << "2. Insert new node at the end\n";
	cout << "3. Display\n";
	cin >> choice;
	
	switch(choice)
	{
		case 1 : l1.append();
		break;
		case 2 : l1.append();
		break;
		case 3 : l1.display();
		break;
		default : cout << "Enter a valid choice!\n";
	}
    }
    while(ch==1);
    cout << "Do you want to continue?\nPress 1 to continue\nPress 0 to exit\n";
    cin >> ch;

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

int main()
{
    int *p;
    p= new int[5];  
    //will allocate memory for 5 integers, so it is an array of integers and it is assigned to p
    
    //initializing the values
    p[0] = 10;
    p[1] = 20;
    p[2] = 30;
    p[3] = 40;
    p[4] = 50;

    
    for(int i=0; i<5; i++)
      cout << p[i] << endl;
   
  	delete [] p;   //to delete an array, first use square brackets and the the name of the variable 		to be deleted
  return 0;
}
#include <iostream>
using namespace std;

int main()
{
  int A[5] = {10,20,30,40,50};
  int *p , *ptr;
  p = A; 
  ptr = &A[0];
/*
no need to give the ampersand(&) when we are giving array name to the pointer, because name of an array A itself is the starting address of this array. So, p is the pointer so, it can store the address.
If we want to use ampersand(&) then we should say A of zero, A[0] means this to 10, A[0] is 2 and its address, then you should write the address.
*/
  
for (int i=0; i<5; i++)
{
    cout << A[i] << endl;
    //To access the values using pointer instead of array name:
    // cout << p[i] << endl;
}
  
  return 0;
}
#include <iostream>
using namespace std;

int main()
{
  int a = 10;
  int *p;
  p = &a;
  
  cout << "value of a : " << a << endl;
  cout << "using pointer : " << *p << endl;
  cout << "address of a : " << &a << endl;
  cout << "address of a using pointer: " << p << endl;
  
  return 0;
}
// words for digits
// in: unsigned long (ul)   
// out: string &

#include <string>
#include <vector>

typedef unsigned long ul;

std::vector<std::string> const ones{"",     "one", "two",   "three", "four", "five", "six", "seven", "eight", "nine"};
std::vector<std::string> const teens{"ten",     "eleven",  "twelve",    "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
    std::vector<std::string> const tens{"",       "",      "twenty", "thirty", "forty",  "fifty", "sixty",  "seventy", "eighty", "ninety"};
   
   std::string wordsForDigits(ul digits) {
    if (digits < 10) {
    return ones[digits];
    } else if (digits < 20) {
    return teens[digits - 10];
    } else if (digits < 100) {
    return tens[digits / 10] +
     ((digits % 10 != 0) ? " " + wordsForDigits(digits % 10) : "");
   } else if (digits < 1'000) {
   return wordsForDigits(digits / 100) + " hundred" +
     ((digits % 100 != 0) ? " " + wordsForDigits(digits % 100) : "");
   } else if (digits < 1'000'000) {
   return wordsForDigits(digits / 1'000) + " thousand" +
   ((digits % 1000 != 0) ? " " + wordsForDigits(digits % 1000) : "");
  } else if (digits < 1'000'000'000) {
  return wordsForDigits(digits / 1'000'000) + " million" +
  ((digits % 1'000'000 != 0) ? " " + wordsForDigits(digits % 1'000'000)
  ▏ : "");
  } else if (digits < 1'000'000'000'000) {
   return wordsForDigits(digits / 1'000'000'000) + " billion" +
   ((digits % 1'000'000'000 != 0)
  ? " " + wordsForDigits(digits % 1'000'000'000)
   : "");
  }
  return "error";
}

void wordsForDigitsHelper(std::string &text, ul digits) {
▏ text = wordsForDigits(digits);
}
class Solution {
public:
    int minSwaps(string s) {
        int n=s.size();
        stack<char> st;
        for(int i=0;i<n;i++)
        {
            if(!st.empty()&&st.top()=='['&&s[i]==']')
            {
                st.pop();
            }
            else st.push(s[i]);
        }
        int n2=st.size()/2;
        if(n2%2==1) return (n2/2)+1;
        else return n2/2;
    }
};
class Solution {
public:
    vector<int> numOfBurgers(int ts, int cs) {
        vector<int> a;
        if(ts%2==1||ts>4*cs||ts<2*cs) 
        {
            return a;
        }
        int p=ts/2;
        int tu=p-cs;
        int du=cs-tu;
        a.push_back(tu);
        a.push_back(du);
        return a;
    }
};
class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        int n1=g.size();
        int n2=s.size();
        int i=0, j=0,res=0;
        sort(g.begin(),g.end());
        sort(s.begin(),s.end());
        while(i<n1 && j<n2)
        {
            if(g[i]<=s[j])
            {
                i++;j++;res++;
            }
            else
            {
                j++;
            }
        }
        return res;
    }
};
bool comp(vector<int>&x, vector<int>&y) //Custom comparator
{
    return x[1]<y[1];
}
class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        int n=points.size();
        if(n==0) return 0;
        if(n==1) return 1;
        
        sort(points.begin(),points.end(), comp);
        int prev=points[0][1];
        int no_ballon=1;
        for(int i=1;i<n;i++)
        {
            if(points[i][0]<=prev) continue;
            prev=points[i][1];
            no_ballon++;
        }
        return no_ballon;
    }
};
class Solution {
public:
    int jump(vector<int>& nums) {
        int n=nums.size();
        int cr=0, cmx=0, j=0;
        for(int i=0;i<n-1;i++)
        {
            if(i+nums[i]>cmx) cmx=i+nums[i];
            
            if(i==cr)
            {
                j++;
                cr=cmx;
            }
        }
        return j;
    }
};
​#include <iostream>

using namespace std;

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if(a <= x && x <=b)
        cout << "DA";
    else
        cout << "NU";


    return 0;
}
class Solution {
public:
    bool canJump(vector<int>& nums) {
        int n=nums.size();
        int mxReach=0;
        for(int i=0;i<n;i++)
        {
            if(i>mxReach) return false;
            mxReach=max(mxReach, i+nums[i]);
            
        }
        return true;
    }
};
class Solution {
public:
    int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {
        int n=gas.size();
        int tg=0, cg=0, s=0;
        for(int i=0;i<n;i++)
        {
            tg+=(gas[i]-cost[i]);
            cg+=(gas[i]-cost[i]);
            if(cg<0)
            {
                s=i+1;
                cg=0;
            }
            
        }
        if(tg>=0) return s;
        else return -1;
    }
};
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(),intervals.end());
        
        int n=intervals.size();
         vector<vector<int>> vns;
        vector<int> v1=intervals[0];
        for(int i=1;i<n;i++)
        {
            if(v1[1]<intervals[i][0])
            {
                vns.push_back(v1);
                v1=intervals[i];
            }
            else 
            {
                v1[1]=max(v1[1],intervals[i][1]);
            }
        }
        vns.push_back(v1);
        return vns;
    }
};
class Solution
{
    public:
    //Function to find the next greater element for each element of the array.
    vector<long long> nextLargerElement(vector<long long> arr, int n){
        
        vector<long long> v;
        
        stack<long long> s;
        for(int i=n-1;i>=0;i--)
        {
            while((!s.empty() && s.top()<=arr[i]))
            {
                s.pop();
            }
            if(s.empty()) v.push_back(-1);
            else 
            {
                v.push_back(s.top());
                
            }
            s.push(arr[i]);
        }
        reverse(v.begin(),v.end());
        return v;
    }
};
class Solution
{
    public:
    //Function to check if brackets are balanced or not.
    bool ispar(string x)
    {
        stack<char> s;
        int n=x.size();
        for(int i=0;i<n;i++)
        {
            if( !s.empty()&&((s.top()=='[' && x[i]==']')||(s.top()=='{' && x[i]=='}')||(s.top() == '(' && x[i]==')' ))) 
            {
                s.pop();
            }
                
            else s.push(x[i]);
        }
        if(s.empty()) return true;
        else return false;
        // Your code here
    }

};
#include<bits/stdc++.h>

using namespace std;
class Stack {
  int size;
  int * arr;
  int top;
  public:
    Stack() {
      top = -1;
      size = 1000;
      arr = new int[size];
    }
  void push(int x) {
    top++;
    arr[top] = x;
  }
  int pop() {
    int x = arr[top];
    top--;
    return x;
  }
  int Top() {
    return arr[top];
  }
  int Size() {
    return top + 1;
  }
};
int main() {

  Stack s;
  s.push(6);
  s.push(3);
  s.push(7);
  cout << "Top of stack is before deleting any element " << s.Top() << endl;
  cout << "Size of stack before deleting any element " << s.Size() << endl;
  cout << "The element deleted is " << s.pop() << endl;
  cout << "Size of stack after deleting an element " << s.Size() << endl;
  cout << "Top of stack after deleting an element " << s.Top() << endl;
  return 0;
}
// C++ program to implement a stack using
// single queue
#include<bits/stdc++.h>
using namespace std;

// User defined stack that uses a queue
class Stack
{
	queue<int>q;
public:
	void push(int val);
	void pop();
	int top();
	bool empty();
};

// Push operation
void Stack::push(int val)
{
	// Get previous size of queue
	int s = q.size();

	// Push current element
	q.push(val);

	// Pop (or Dequeue) all previous
	// elements and put them after current
	// element
	for (int i=0; i<s; i++)
	{
		// this will add front element into
		// rear of queue
		q.push(q.front());

		// this will delete front element
		q.pop();
	}
}

// Removes the top element
void Stack::pop()
{
	if (q.empty())
		cout << "No elements\n";
	else
		q.pop();
}

// Returns top of stack
int Stack::top()
{
	return (q.empty())? -1 : q.front();
}

// Returns true if Stack is empty else false
bool Stack::empty()
{
	return (q.empty());
}

// Driver code
int main()
{
	Stack s;
	s.push(10);
	s.push(20);
	cout << s.top() << endl;
	s.pop();
	s.push(30);
	s.pop();
	cout << s.top() << endl;
	return 0;
}
class StockSpanner {
public:
    stack<pair<int,int>> s;
    StockSpanner() {
        
    }
    
    int next(int price) {
        int span=1;
        while(!s.empty()&&s.top().first<=price)
        {
            span+=s.top().second;
            s.pop();
        }
        s.push({price, span});
        return span;
    }
};

/**
 * Your StockSpanner object will be instantiated and called as such:
 * StockSpanner* obj = new StockSpanner();
 * int param_1 = obj->next(price);
 */
​#include <iostream>
using namespace std;
#include <iomanip>

int main ()
{
    int a, b, c;
    float medie;
    cin >> a >> b >> c;
    medie = (a + b + c) / 3.;
    medie = (int) (medie * 100)/100.;
    cout << fixed << setprecision(2) << medie;


    return 0;
}
class Solution {
public:
    string removeKdigits(string num, int k) {
        int n=num.size();
        if(k>=n) return "0";
        if(k==0) return num;
        string res="";
        stack<char> s;
        
        s.push(num[0]);
        for(int i=1;i<n;i++)
        {
            while(k>0&&!s.empty()&&num[i]<s.top())
            {
                k--;
                s.pop();
            }
            s.push(num[i]);
            
            if(s.size()==1&&num[i]=='0')
            {
                s.pop();
            }
        }
        while(k&&!s.empty())
        {
            k--;
            s.pop();
        }
        while(!s.empty())
        {
            res.push_back(s.top());
            s.pop();
        }
        reverse(res.begin(),res.end());
        if(res.length()==0) return "0";
        return res;
    }
};
class Solution {
public:
    int trap(vector<int>& height) {
        int n=height.size();
        int Pmax[n], Bmax[n];
        int p=0,b=0;
        for(int i=0;i<n;i++)
        {
            Pmax[i]=p;
            if(height[i]>=p) p=height[i];
        }
        for(int i=n-1;i>=0;i--)
        {
            Bmax[i]=b;
            if(height[i]>=b) b=height[i];
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            int Lmin=min(Pmax[i],Bmax[i]);
            if((Lmin==0)||(height[i]>=Lmin)) 
            {
                continue;
            }
            else
            {
                ans+=(Lmin-height[i]);
            }
        }
        return ans;
        
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* rotateRight(ListNode* head, int long long k) {
        if(head==NULL||k==0) return head;
        int long long c=0;
        ListNode* p=head;
        while(p!=NULL)
        {
            c++;
            p=p->next;
        }
        if(c==1||k%c==0) return head;
        int r=k%c;
        int t=(c-r)-1;
        ListNode* i1=head;
        ListNode* i2;
        while(t--)
        {
            i1=i1->next;
        }
        
        if(i1) i2=i1->next;
        
        ListNode* p5=head;
        while(p5->next!=NULL)
        {
            p5=p5->next;
        }
        p5->next=head;
        if(i1) i1->next=NULL;
        
        head=i2;
        return head;
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */


void makell(ListNode* head, int value)
{
    ListNode* p=new ListNode();
    p->val=value;
    p->next=NULL;
    ListNode* l=head;
    while((l->next!=NULL)&&(l!=NULL))
    {
        l=l->next;
    }
    l->next=p;
}
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        
        ListNode* head=new ListNode();
        head->val=0;
        head->next=NULL;
        ListNode* i1 = l1;
        ListNode* i2 = l2;
        int c=0;
        while(i1!=NULL||i2!=NULL)
        {
            int d1,d2;
            if(i1==NULL&&i2==NULL) break;
            if(i1==NULL) d1=0;
            else 
            {
                d1=i1->val;
                i1=i1->next;
            }
            if(i2==NULL) d2=0;
            else
            {
                d2=i2->val;
                i2=i2->next;
            }
            int p=d1+d2+c;
            int r=p%10;
            makell(head,r);
            c=p/10;
        }
        if(c!=0)
        {
            makell(head,c);
        }
        return head->next;
    }
};
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
void makell(ListNode* &head, int value)
{
    ListNode* p=new ListNode();
    p->val=value;
    p->next=NULL;
    ListNode* l=head;
    while(l->next!=NULL)
    {
        l=l->next;
    }
    
    l->next=p;
    
    
}
class Solution {
public:
    ListNode* mergeKLists(vector<ListNode*>& lists) {
        int n1=lists.size();
        multiset<int> s;
        for(int i=0;i<n1;i++)
        {
            ListNode* a=lists[i];
            
            while(a!=NULL)
            {
                s.insert(a->val);
                a=a->next;
            }
        }
        ListNode* head;
        head=new ListNode();
        head->val=0;
        head->next=NULL;
        for(auto it:s)
        {
            makell(head,it);
        }
        return head->next;
    }
};
#include<iostream>
using namespace std;
int main(){
    int n;
    cout<<"Enter the range\n";
    cin>>n;
    int sum=0;
    for(int i=0;i<=n;i++){
        cout<<i<<" ";
        sum+=i;
    }cout<<endl;
    cout<<"The sum between given range is-> "<<sum<<endl;
    return 0;
}
#include<iostream>
using namespace std;
template<class t>
class absolute{
    
    public:
    void check(int a){
        if(a<0){
            a=-(a);
            cout<<"Value is-> "<<a<<endl;
        }
        else{
            cout<<"Value is-> "<<a<<endl;
        }
    }
};
int main(){
    absolute<int>a;
    int n;
    cout<<"Enter the number\n";
    cin>>n;
    a.check(n);
    return 0;
}
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cout<<"Enter the age of three person\n";
    cin>>a>>b>>c;
    if(a>b&&a>c){
        cout<<a<<" is greatest among them"<<endl;
    }
    if(b>c){
        cout<<c<<" is younger among them"<<endl;
    }
    return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
template<class t>
class total{
    public:
    void discount(int quantity){
        int cost=quantity*100;
        int discount=(cost/100)*10;
        int new_cost=0;
        if(cost>1000){
            new_cost=cost-discount;
            cout<<"Your new cost after discount is-> "<<new_cost<<endl;
        }
        else{
            cout<<"Your cost is-> "<<cost<<endl;
        }
    }   
};

int main(){
    int q;
    cout<<"Enter the quantity how much you want"<<endl;
    cin>>q;
    total<int>t;
    t.discount(q);
    return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
template<class t>
class greatest{
private:
int a,b;
public:
void check(int a,int b){
    cout<<"Enter two no.\n";
    cin>>a>>b;
    if(a>b){
        cout<<a<<" is greater than "<<b<<endl;
    }
    else if(a==b){
        cout<<a<<" is equal with "<<b<<endl;
    }
    else{
        cout<<b<<" is greater than "<<a<<endl;
    }
}
};

int main(){
    int a,b;
    greatest<int>g;
    g.check(a,b);
    return 0;
}
#include<iostream>
using namespace std;
template<class t>
    class check{
        public:
        int a,b;
        void sqcheck(int a,int b){
            cout<<"Enter two values\n";
            cin>>a>>b;
            if(a==b){
                cout<<"It is square"<<endl;
            }
            else{
                cout<<"It is a rectangle\n";
            }
        }
    };

    int main(){
        check<int>c;
        int a,b;
        c.sqcheck(a,b);
        return 0;
    }
#include<iostream>
using namespace std;
void prime(int n){
    bool flag=true;
    for(int i=2;i<n;i++){
        if(n%i==0){
            flag=false;
            break;
        }
    }
    if(flag==false){
        cout<<"No it is not a prime no.\n";
    }
    else{
        cout<<"Yes it is a prime no.\n";
    }
}
int main(){
    int a;
    cout<<"Enter the no.\n";
    cin>>a;
    prime(a);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

void solve(string str, string output, int index, vector<string>& ans)
{
   //base case
   if(index >= str.length())
   {
      if(output.length()>0) ans.push_back(output);
      return;
   }
   //exclude
   solve(str, output, index+1, ans);
   
   //include
   char element = str[index];
   output.push_back(element);
   solve(str, output, index+1, ans);
}
vector<string> subsequences(string str)
{
   vector<string> ans;
   string output = "";
   int index = 0;
   solve(str, output, index, ans);
   return ans;
}
int main() {
	string s="abcd";
	vector<string> v=subsequences(s);
	for(int i=0;i<v.size();i++)
	{
	   cout<<v[i]<<" ";
	}
	return 0;
}
class Solution {
public:
    
    void solve(vector<int> nums, vector<int> output, int index, vector<vector<int>> &ans)
    {
        //base case
        if(index>=nums.size())
        {
            ans.push_back(output);
            return;
        }
        
        //eclude
        solve(nums, output, index+1, ans);
        
        //include
        int element = nums[index];
        output.push_back(element);
        solve(nums, output, index+1, ans);
    }
    vector<vector<int>> subsets(vector<int>& nums) {
        
        vector<vector<int>>ans;
        vector<int> output;
        int index=0;
        solve(nums,output,index,ans);
        return ans;
    }
};
#include <bits/stdc++.h>
using namespace std;

int partition(int arr[],int s,int e)
{
   int pivot=arr[s];
   int cnt=0;
   for(int i=s+1;i<=e;i++)
   {
      if(arr[i]<=pivot)
      {
         cnt++;
      }
   }
   
   //place pivot at right position
   int pivotindex = s+cnt;
   swap(arr[pivotindex],arr[s]);
   
   //left and right wala part sambhal lete sambhal
   int i=s, j=e;
   while(i < pivotindex && j > pivotindex)
   {
      while(arr[i]<pivot)
      {
         i++;
      }
      while(arr[j]>pivot)
      {
         j--;
      }
      if(i < pivotindex && j > pivotindex)
      {
         swap(arr[i++],arr[j--]);
      }
   }
   return pivotindex;
}
void quicksort(int arr[], int s,int e)
{
   //base case
   if(s>=e) return;
   
   //partition
   int p=partition(arr,s,e);
   //recursion
   //left part ko sort karo
   quicksort(arr,s,p-1);
   //right part ko sort karo
   quicksort(arr,p+1,e);
}


int main() {
	int a[8]={9,78,6,23,14,2,8,1};
	int n=8;
	quicksort(a,0,n-1);
	for(int i=0;i<n;i++)
	{
	   cout<<a[i]<<" ";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

void merge(int *arr, int s, int e)
{
   int mid = (s+e)/2;
   int len1=mid-s+1;
   int len2=e-mid;
   
   int *first = new int[len1];
   int *second=new int[len2];
   
   //copy value
   int mainArrayIndex = s;
   for(int i=0;i<len1;i++)
   {
      first[i]=arr[mainArrayIndex++];
   }
   mainArrayIndex=mid+1;
   for(int i=0;i<len2;i++)
   {
      second[i]=arr[mainArrayIndex++];
   }
   
   //merge 2 sorted arrays
   int index1=0;
   int index2=0;
   mainArrayIndex=s;
   
   while(index1<len1&&index2<len2)
   {
      if(first[index1]<second[index2])
      {
         arr[mainArrayIndex++]=first[index1++];
      }
      else 
      {
         arr[mainArrayIndex++]=second[index2++];
      }
   }
   while(index1<len1)
   {
      arr[mainArrayIndex++]=first[index1++];
   }
   while(index2<len2)
   {
      arr[mainArrayIndex++]=second[index2++];
   }
   delete []first;
   delete []second;
  
}
void mergesort(int *arr,int s,int e)
{
   //base case
   if(s>=e)
   {
      return;
   }
   
   int mid=(s+e)/2;
   //left part sort karna h
   mergesort(arr, s, mid);
   //right part sort karna right
   mergesort(arr, mid+1, e);
   
   //merge
   merge(arr,s,e);
   
}
int main() {
   
	int a[5]={5,6,1,4,3};
   int n=5;
   mergesort(a,0,n-1);
	for(int i=0;i<5;i++)
	{
	   cout<<a[i]<<" ";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

void bubblesrt(int a[],int n)
{
   if(n==0||n==1) return;
   for(int i=0;i<n-1;i++)
   {
      if(a[i]>a[i+1]) swap(a[i],a[i+1]);
   }
   bubblesrt(a,n-1);
}
int main() {
   
	int a[5]={5,6,1,4,3};
   bubblesrt(a,5);
	for(int i=0;i<5;i++)
	{
	   cout<<a[i]<<" ";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD= 1e9+7;
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	  ll fact=1;
	  ll n;
	  cin>>n;
	   for(ll i=1;i<=n;i++)
	   {    
      fact=(fact*i)%MOD;    
      }
      ll ans=(fact*n)%MOD;
      ll ans2=(ans*(n-1))%MOD;
	 cout<<ans2<<"\n"; 
	 
	}
	return 0;
}
class Solution{
  public:
    //Function to check whether the list is palindrome.
    bool isPalindrome(Node *head)
    {
        //Your code here
        stack<int> s;
        Node *t;
        t=head;
        while(t)
        {
            s.push(t->data);
            t=t->next;
        }
        t=head;
        while(t)
        {
            if(s.top()==t->data)
            {
                s.pop();
            }
            t=t->next;
        }
        if(s.empty()) return true;
        else return false;
        
    }
};
#include <bits/stdc++.h> 
int countDistinctWays(long long nStairs) {
    //  Write your code here.
    //Base case 
    if(nStairs<0) return 0;
    if(nStairs==0) return 1;
    int ans=countDistinctWays(nStairs-1) + countDistinctWays(nStairs-2);
    return ans;
}
//Factorial
#include <bits/stdc++.h>
using namespace std;

int fac(int n)
{
   //Base call and return must be there
   if(n==0) return 1;
   return n*fac(n-1);
}
int main() {
   int t;
   cin>>t;
   while(t--)
   {
      int n;
      cin>>n;
      int ans = fac(n);
      cout<<ans<<"\n";
   }
	return 0;
}

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

long long powerofto(long long n)
{
   if(n==0) return 1;
   return 2*powerofto(n-1);
}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	     long long n;
	     cin>>n;
	     long long ans=powerofto(n);
	     cout<<ans<<"\n";
	}
	return 0;
}

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

void printcnt(int n)
{
   if(n==0) return;
   
   //cout<<n<<" ";
   printcnt(n-1);
   cout<<n<<" ";
}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        int n;
	        cin>>n;
	        printcnt(n);
	        cout<<"\n";
	}
	return 0;
}

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

void reachome(int dest, int src)
{
   if(src==dest)
   {
      cout<<src<<" Pahunchh gya: ";
      return;
      
   }
   cout<<src<<" ";
   src++;
   reachome(dest, src);
}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	      int dest;
	      int src;
	      cin>>dest;
	      cin>>src;
	      reachome(dest,src);
	      cout<<"\n";
	}
	return 0;
}

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

int fab(int n)
{
   if(n==1) return 1;
   if(n==0) return 0;
   return fab(n-1)+fab(n-2);
}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        int n;
	        cin>>n;
	        int ans=fab(n);
	        cout<<ans<<"\n";
	}
	return 0;
}

//Print digits in string
#include <bits/stdc++.h>
using namespace std;

void print(int n, string arr[])
{
   if(n==0) return;
   int digit = n%10;
   n=n/10;
   
   print(n,arr);
   cout<<arr[digit]<<" ";
}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        string arr[10]={"zero", "one","two","three","four","five","six","seven","eight","nine"};
	        int n;
	        cin>>n;
	        print(n,arr);
	        cout<<"\n";
	}
	return 0;
}

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

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	       int n;
	       cin>>n;
	       char a[n][10];
	       for(int i=0;i<n;i++)
	       {
	           for(int j=0;j<10;j++)
	           {
	               cin>>a[i][j];
	           }
	       }
	       int ans=0;
	       for(int i=0;i<10;i++)
	       {
	           int cnt=0;
	           for(int j=0;j<n;j++)
	           {
	               if(a[j][i]=='1') cnt++;
	           }
	           if(cnt%2==1) ans++;
	       }
	       cout<<ans<<"\n";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        long long x;
	        cin>>x;
	        cout<<x<<" "<<0<<"\n";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        int n;
	        cin>>n;
	        int a[n];
	        for(int i=0;i<n;i++)
	        {
	            cin>>a[i];
	        }
	        int ans=0;
	        for(int i=0;i<n-1;i++)
	        {
	            for(int j=i+1;j<n;j++)
	            {
	                if((a[i]==1&&a[j]==1)||(a[i]==0)) ans++;
	            }
	        }
	        cout<<ans<<"\n";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	        int p;
	        cin>>p;
	        int itemprice=2048;
	        int ans=0;
	        while(p>0)
	        {
	            ans+=p/itemprice;
	            p%=itemprice;
	            itemprice/=2;
	        }
	        cout<<ans<<"\n";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	int n,y;
	cin>>t;
	while(t--)
	{
	      cin>>n>>y;
	      long a[n];
	      bool u=false;
	      for(int i=0;i<n;i++)
	      {
	          cin>>a[i];
	      }
	      long p=0;
	      for(int i=0;i<n;i++)
	      {
	          p=p | a[i];
	      }
	      for(int i=0;i<=y;i++)
	      {
	          if((p|i)==y)
	          {
	              cout<<i<<"\n";
	              u=true;
	              break;
	          }
	      }
	      if(u==false) cout<<"-1\n";
	}
	return 0;
}

METHOD 2:-

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

int main() {
	int t,n,y;
	cin>>t;
	while(t--)
	{
	    cin>>n>>y;
	    int a[n];
	    string required, current;
	    int orans=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        orans|=a[i];
	    }
	    current=bitset<32>(orans).to_string();
	    required=bitset<32>(y).to_string();
	    int flag=0, answer=0;
	    for(int i=31; i>=0; i--)
	    {
	        if(current[i]=='1' && required[i]=='0')
	        {
	            flag=1;
	            break;
	        }
	        if(current[i]=='0' && required[i]=='1')
	        {
	            answer+=pow(2,31-i);
	        }
	    }
	    if(flag){cout<<-1<<endl;}
	    else {cout<<answer<<endl;}
	}
	return 0;
}
#include <iostream>
#include <string.h>
using namespace std;

int main() {
    
    double gr1, gr2, gr3, gr4, gr5, gr6, gr7, gr8, gr9, gr10, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, aggregate_grade, gwa;
    int un1, un2, un3, un4, un5, un6, un7, un8, un9, un10, numsub, total_units;
    string sub1, sub2, sub3, sub4, sub5, sub6, sub7, sub8, sub9, sub10;
    
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
    
    cout << "------------------------\n"
        << "IT 202D FINAL OUTPUT\n" 
        << "GWA CALCULATOR\n"
        << "------------------------\n"
        << "Please enter the number of subjects that " << endl
        << "you took this semester (excluding NSTP and subjects \n"
        << "with non-numeric ratings): ";
    cin >> numsub;
    
    if (numsub == 2)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    aggregate_grade = p1 + p2;
    total_units = un1 + un2;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 3)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    aggregate_grade = p1 + p2 + p3;
    total_units = un1 + un2 + un3;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 4)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    aggregate_grade = p1 + p2 + p3 + p4;
    total_units = un1 + un2 + un3 + un4;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 5)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5;
    total_units = un1 + un2 + un3 + un4 + un5;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 6)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub6;
    cout << "Number of Credited Units: ";
    cin >> un6;
    cout << "Grade: ";
    cin >> gr6;
    p6 = un6 * gr6;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5 + p6;
    total_units = un1 + un2 + un3 + un4 + un5 + un6;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 7)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub6;
    cout << "Number of Credited Units: ";
    cin >> un6;
    cout << "Grade: ";
    cin >> gr6;
    p6 = un6 * gr6;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub7;
    cout << "Number of Credited Units: ";
    cin >> un7;
    cout << "Grade: ";
    cin >> gr7;
    p7 = un7 * gr7;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5 + p6 + p7;
    total_units = un1 + un2 + un3 + un4 + un5 + un6 + un7;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 8)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub6;
    cout << "Number of Credited Units: ";
    cin >> un6;
    cout << "Grade: ";
    cin >> gr6;
    p6 = un6 * gr6;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub7;
    cout << "Number of Credited Units: ";
    cin >> un7;
    cout << "Grade: ";
    cin >> gr7;
    p7 = un7 * gr7;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub8;
    cout << "Number of Credited Units: ";
    cin >> un8;
    cout << "Grade: ";
    cin >> gr8;
    p8 = un8 * gr8;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8;
    total_units = un1 + un2 + un3 + un4 + un5 + un6 + un7 + un8;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 9)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub6;
    cout << "Number of Credited Units: ";
    cin >> un6;
    cout << "Grade: ";
    cin >> gr6;
    p6 = un6 * gr6;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub7;
    cout << "Number of Credited Units: ";
    cin >> un7;
    cout << "Grade: ";
    cin >> gr7;
    p7 = un7 * gr7;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub8;
    cout << "Number of Credited Units: ";
    cin >> un8;
    cout << "Grade: ";
    cin >> gr8;
    p8 = un8 * gr8;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub9;
    cout << "Number of Credited Units: ";
    cin >> un9;
    cout << "Grade: ";
    cin >> gr9;
    p8 = un9 * gr9;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
    total_units = un1 + un2 + un3 + un4 + un5 + un6 + un7 + un8 + un9;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n";
    }
    
    else if (numsub == 10)
    {
    cout << "------------------------\n"
        << "Subject Code: ";
    cin >> sub1;
    cout << "Number of Credited Units: ";
    cin >> un1;
    cout << "Grade: ";
    cin >> gr1;
    p1 = un1 * gr1;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub2;
    cout << "Number of Credited Units: ";
    cin >> un2;
    cout << "Grade: ";
    cin >> gr2;
    p2 = un2 * gr2;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub3;
    cout << "Number of Credited Units: ";
    cin >> un3;
    cout << "Grade: ";
    cin >> gr3;
    p3 = un3 * gr3;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub4;
    cout << "Number of Credited Units: ";
    cin >> un4;
    cout << "Grade: ";
    cin >> gr4;
    p4 = un4 * gr4;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub5;
    cout << "Number of Credited Units: ";
    cin >> un5;
    cout << "Grade: ";
    cin >> gr5;
    p5 = un5 * gr5;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub6;
    cout << "Number of Credited Units: ";
    cin >> un6;
    cout << "Grade: ";
    cin >> gr6;
    p6 = un6 * gr6;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub7;
    cout << "Number of Credited Units: ";
    cin >> un7;
    cout << "Grade: ";
    cin >> gr7;
    p7 = un7 * gr7;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub8;
    cout << "Number of Credited Units: ";
    cin >> un8;
    cout << "Grade: ";
    cin >> gr8;
    p8 = un8 * gr8;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub9;
    cout << "Number of Credited Units: ";
    cin >> un9;
    cout << "Grade: ";
    cin >> gr9;
    p8 = un9 * gr9;
    
    cout << "\n------------------------\n"
        << "Subject Code: ";
    cin >> sub10;
    cout << "Number of Credited Units: ";
    cin >> un10;
    cout << "Grade: ";
    cin >> gr10;
    p8 = un10 * gr10;
    
    aggregate_grade = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
    total_units = un1 + un2 + un3 + un4 + un5 + un6 + un7 + un8 + un9 + un10;
    gwa = aggregate_grade / total_units;
    cout << "\n------------------------\n"
        << "GWA = " << gwa 
        << "\n------------------------\n"; 
    }
    
    else
    {
        cout << "\n------------------------\n"
        << "Invalid entry";
    }
    return 0;
    }
#include <fstream>
#include <iostream>
using namespace std;


int main() {

    // Part 1: Write on a file.
    ofstream oFile;
    oFile.open("my-bio.txt");

    string name;
    int age;

    // User input. 
    cout << "Enter name: ";
    getline(cin, name);

    cout << "Enter age: ";
    cin >> age;

    oFile << "My name is " << name << ". \n";
    oFile << "I am " << age << " years old. \n";

    oFile.close();

    // Part 2: Read from a file.
    string str;

    ifstream iFile;
    iFile.open("my-bio.txt");

    cout << "\nReading data from the file: \n\n";

    while(!iFile.eof()) {
        getline(iFile, str);
        cout << str << endl;
    }

    iFile.close();

    return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		File Handling
*/

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


int main() {

	// The string will hold the text present in each line on the file.
	string str;

	// Create ifstream (Input File Stream) object.
	ifstream iFile;

	// Open the file.
	iFile.open("my-note.txt");

	// Use a while loop together with the getline() function to read the file line by line.
	while(!iFile.eof()) {
		getline(iFile, str);		// Reads a line.
		cout << str << endl;		// Prints the line.
	}

	// Close the opened file.
	iFile.close();

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		File Handling
*/

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


int main() {

	// Create an ofstream (Output File Stream) object.
	ofstream oFile;

	// Create a file (if it doesn't exist) and open it.
	oFile.open("my-note.txt");

	// Write on the file.
	oFile << "Hi! \n";
	oFile << "I love to travel. \n";
	oFile << "I am " << 25 << " years old. \n";

	// Close the opened file.
	oFile.close();

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

void findSquareRoot(float n);


int main() {

    // Find the square root of 'n' entered by the user.
    cout << "Program starts -->" << endl << endl;

    float n;

    cout << "Enter n: ";
    cin >> n;

    findSquareRoot(n);

    cout << "<-- Program ends" << endl;

    return 0;
}

void findSquareRoot(float n) {

    try {
        if (n < 0) {
            throw "The value of 'n' must be greater than or equal to 0. Please try again.";
        }

        float result = sqrt(n);
        cout << "Result: " << result << endl << endl;
    } catch (const char *msg) {
        cout << msg << endl << endl;
    }
}
#include <iostream> 
#include <cmath> 
using namespace std; 


int main() {

    // Find the square root of 'n' entered by the user.
    cout << "Program starts -->" << endl << endl;

    float n;

    cout << "Enter n: ";
    cin >> n;

    try {
        if (n < 0) {
            throw "The value of 'n' must be greater than or equal to 0. Please try again.";
        }

        float result = sqrt(n);
        cout << "Result: " << result << endl << endl;
    } catch (const char *msg) {
        cout << msg << endl << endl;
    }

    cout << "<-- Program ends" << endl;

    return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Exception Handling
*/

#include <iostream>
using namespace std;


int main() {

	// Divide two integers: a divided by b.
	cout << "Program starts -->" << endl << endl;

	int a, b;

	cout << "Enter a: ";
	cin >> a;

	cout << "Enter b: ";
	cin >> b;

	try {
		if (b == 0) {
			throw "The value of 'b' must not be 0. Please try again.";
		}

		int result = a / b;
		cout << "Result: " << result << endl << endl;
	} catch (const char *msg) {
		cout << msg << endl << endl;
	}

	cout << "<-- Program ends" << endl;

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Preprocessor Directives
*/

#include <iostream>
using namespace std;

#define UPPER_LIMIT 10		// Macro definition
#define AREA(r) (3.14 * r * r)	// Macro with parameter


int main() {

	// Find even numbers from 1 to 10.
	for (int i = 1; i <= UPPER_LIMIT; i++) {

		if (i % 2 == 0)
			cout << i << endl;
	}

	// Find the area of a circle.
	cout << "Area: " << AREA(5);		// 3.14 * 5 * 5

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Standard Libraries
*/

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

class Employee {
	// Your code 
};

int main() {

	/* C++ <vector> Header
	   Vectors are similar to arrays, but it can change its size. */

	Employee emp1, emp2, emp3, emp4;
	vector<Employee> employeeList;
	employeeList.push_back(emp1);
	employeeList.push_back(emp2);
	employeeList.push_back(emp3);
	employeeList.push_back(emp4);
	
	vector<string> names;
	names.push_back("Rahul");		// Adds element at the end
	names.push_back("Peter");
	names.push_back("Ravi");

	// Check the size.
	cout << "Size: " << names.size() << endl;		// 3

	// Accessing an element.
	cout << "Element at index 0: " << names[0] << endl;		// Rahul

	// Remove element from the end.
	names.pop_back();		// Removes "Ravi"
	cout << "Size: " << names.size() << endl;		// 2

	// Modify element.
	names[0] = "Aditya";
	cout << "Element at index 0: " << names[0] << endl;		// Aditya

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Standard Libraries
*/

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


int main() {

	/* C++ <cmath> Header */

	int x = 4, y = 9;

	cout << "The greater number: " << fmax(x, y) << endl;		// 9
	cout << "The smaller number: " << fmin(x, y) << endl;		// 4
	cout << "The difference: " << fdim(y, x) << endl;			// 5

	cout << "2 to the power 4: " << pow(2, 4) << endl;	// 2 * 2 * 2 * 2 = 16

	cout << sqrt(64) << endl;		// 8
	cout << round(2.5) << endl;		// 3
	cout << round(2.4) << endl;		// 2
	cout << floor(4.9) << endl;		// 4
	cout << log(2) << endl;			// 0.693

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Standard Libraries
*/

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <unistd.h>
using namespace std;


int main() {

	/* WAP to roll a dice.*/

	int randomValue;

	srand(time(NULL));

	randomValue = (rand() % 6) + 1;		// 1, 2, 3, 4, 5, 6

	cout << "Rolling the dice...\n\n";
	usleep(2000000);

	cout << "You got: " << randomValue;

	return 0;
}
/*
 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		Namespaces
*/

#include <iostream>
using namespace std;

namespace jp {

	float dollarValue = 108;	// 1 USD = 108 Japanese Yen

	double toDollars(float currencyUnits) {
		return currencyUnits / dollarValue;
	}
}

namespace cn {

	float dollarValue = 7;		// 1 USD = 7 Chinese Yuan

	double toDollars(float currencyUnits) {
		return currencyUnits / dollarValue;
	}
}


int main() {

	cout << "1 USD = " << jp::dollarValue << " Yen" << endl;
	cout << "1 USD = " << cn::dollarValue << " Yuan" << endl;

	cout << "8960 Yen = " << jp::toDollars(8960) << " USD" << endl;
	cout << "610 Yuan = " << cn::toDollars(610) << " USD" << endl;

	return 0;
}
/*
 Author:	Internshala
 Module:	Fundamentals of Object Oriented Programming Using C++
 Topic:		Friend Class and Friend Function
*/

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

class Employee {

	private:
		string phNo;

	public:
		string name;

		void setPhoneNumber(string phoneNumber) {
			this->phNo = phoneNumber;
		}

		friend void display(Employee);		// Function declaration
};

void display(Employee emp) {	// Function definition
	cout << "Employee name: " << emp.name << ", Phone: " << emp.phNo << endl;
}


int main() {

	Employee employee;
	employee.setPhoneNumber("+91-8093");
	employee.name = "Rishi Raj";

	display(employee);

	return 0;
}
/*
 Author:	Internshala
 Module:	Fundamentals of Object Oriented Programming Using C++
 Topic:		Friend Class and Friend Function
*/

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

class Employee {

	private:
		string phNo;

	public:
		string name;

		void setPhoneNumber(string phoneNumber) {
			this->phNo = phoneNumber;
		}

		friend class Car;
};

class Car {			// Friend class of class Employee

	public:
		string carName;

		void display(Employee emp) {
			cout << "Employee name: " << emp.name << ", Phone: " << emp.phNo << ", Car name: " << carName << endl;
		}
};


int main() {

	Employee employee;
	employee.setPhoneNumber("+91-8093");
	employee.name = "Rishi Raj";

	Car car;
	car.carName = "Ferrari 488";
	car.display(employee);

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

class Shape {

    public:
        virtual double getArea() = 0;
        virtual double getPerimeter() = 0;
};

class Square : public Shape {

    public:
        float side;

        virtual double getArea() {
            return side * side;
        }

        virtual double getPerimeter() {
            return 4 * side;
        }
};

class Rectangle : public Shape {

    public:
        float length;
        float breadth;

        virtual double getArea() {
            return length * breadth;
        }

        virtual double getPerimeter() {
            return 2 * (length + breadth);
        }
};

class Circle : public Shape {

    public:
        float radius;

        virtual double getArea() {
            return 3.14 * radius * radius;
        }

        virtual double getPerimeter() {
            return 2 * 3.14 * radius;
        }
};

class Triangle : public Shape {

    public:
        float base;
        float height;
        float side1;
        float side2;

        virtual double getArea() {
            return (base * height) / 2;
        }

        virtual double getPerimeter() {
            return base + side1 + side2;
        }
};


int main() {

Circle circle;
    circle.radius = 10;
    double area = circle.getArea();
    double perimeter = circle.getPerimeter();

    cout << "The area and the perimeter of the circle is " << area << " square units and " << perimeter << " units respectively." << endl;

    return 0;
}
/*
 Author:	Internshala
 Module:	Fundamentals of Object Oriented Programming Using C++
 Topic:		Abstract Class
*/

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

class Animal {		// Abstract class

	public:
		virtual void sound() = 0;		// Pure virtual function

		virtual void sleep() {
			cout << "Animal class: sleeping" << endl;
		}
};

class Dog : public Animal {		// Concrete class

	public:
		virtual void sound() {
			cout << "Dog class: bow-bow" << endl;
		}

		virtual void sleep() {
			cout << "Dog class: sleeping" << endl;
		}
};


int main() {

//	Animal a;	 // a --> Animal object	 // Error. Cannot create an object of an abstract class. 
	
	Dog dog;		// dog --> Dog object
	dog.sound();
	dog.sleep();

	Animal *animal = new Dog();		// animal --> Dog object
	animal->sound();
	animal->sleep();

	return 0;
}
/*
 Author:	Internshala
 Module:	Fundamentals of Object Oriented Programming Using C++
 Topic:		Polymorphism
*/

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

class Animal {

	public:
		virtual void sound() {
			cout << "Animal class: making sound" << endl;
		}

		virtual void sleep() {
			cout << "Animal class: sleeping" << endl;
		}
};

class Dog : public Animal {

	public:
		virtual void sound() {
			cout << "Dog class: bow-bow" << endl;
		}

		virtual void sleep() {
			cout << "Dog class: sleeping" << endl;
		}
};


int main() {

	Dog dog;		// dog --> Dog object
	dog.sound();
	dog.sleep();

	Animal *animal = new Dog();		// animal --> Dog object
	animal->sound();
	animal->sleep();

	return 0;
}