correct this code : 
#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Function to evaluate expression
int evaluateExpression(const string& expr) {
    int result = 0;
    char op = '+';
    int num = 0;
    
    for(size_t i = 0; i < expr.length(); i++) {
        if(isdigit(expr[i])) {
            num = num * 10 + (expr[i] - '0');
        } else {
            if(op == '+') result += num;
            else if(op == '-') result -= num;
            else if(op == '*') result *= num;
            op = expr[i];
            num = 0;
        }
    }
    
    // Process last number
    if(op == '+') result += num;
    else if(op == '-') result -= num;
    else if(op == '*') result *= num;
    
    return result;
}

// Function to get digit from 3x3 display
char getDigit(const vector<string>& display, int pos) {
    vector<string> segment;
    // Check bounds
    if(pos * 3 + 2 >= display[0].length()) return 'X';
    
    for(int i = 0; i < 3; i++) {
        segment.push_back(display[i].substr(pos*3, 3));
    }
    
    // Match patterns for digits and operators
    if(segment == vector<string>{" _ ", "| |", "|_|"}) return '0';
    if(segment == vector<string>{"   ", "  |", "  |"}) return '1';
    if(segment == vector<string>{" _ ", " _|", "|_ "}) return '2';
    if(segment == vector<string>{" _ ", " _|", " _|"}) return '3';
    if(segment == vector<string>{"   ", "|_|", "  |"}) return '4';
    if(segment == vector<string>{" _ ", "|_ ", " _|"}) return '5';
    if(segment == vector<string>{" _ ", "|_ ", "|_|"}) return '6';
    if(segment == vector<string>{" _ ", "  |", "  |"}) return '7';
    if(segment == vector<string>{" _ ", "|_|", "|_|"}) return '8';
    if(segment == vector<string>{" _ ", "|_|", " _|"}) return '9';
    if(segment == vector<string>{"   ", "|_ ", "|  "}) return '+';
    if(segment == vector<string>{"   ", " _ ", "   "}) return '-';
    if(segment == vector<string>{"   ", "|_|", "| |"}) return '*';
    if(segment == vector<string>{"   ", " _ ", " _ "}) return '=';
    
    return 'X';
}

// Function to parse RHS value safely
int parseRHS(const string& rhs) {
    int result = 0;
    for(char c : rhs) {
        if(!isdigit(c)) return -1;
        result = result * 10 + (c - '0');
    }
    return result;
}

int main() {
    int N;
    cin >> N;
    
    vector<string> display(3);
    for(int i = 0; i < 3; i++) {
        cin.ignore();
        getline(cin, display[i]);
    }
    
    string equation;
    for(int i = 0; i < N; i++) {
        char digit = getDigit(display, i);
        if(digit != 'X') equation += digit;
    }
    
    // Find position of '='
    size_t equalPos = equation.find('=');
    if(equalPos == string::npos || equalPos == 0 || equalPos == equation.length()-1) {
        return 1;
    }
    
    string expr = equation.substr(0, equalPos);
    string rhsStr = equation.substr(equalPos + 1);
    int rhs = parseRHS(rhsStr);
    
    if(rhs == -1) return 1;
    
    // Try toggling each digit
    for(int i = 0; i < (int)equalPos; i++) {
        if(!isdigit(expr[i])) continue;
        
        string origExpr = expr;
        char origChar = expr[i];
        
        for(char newDigit = '0'; newDigit <= '9'; newDigit++) {
            if(origChar == newDigit) continue;
            
            expr[i] = newDigit;
            if(evaluateExpression(expr) == rhs) {
                cout << i + 1 << endl;
                return 0;
            }
        }
        expr = origExpr;
    }
    
    return 0;
}