Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 2):
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

int t,number=1,total,num2,num3;

char num[1005][100005];

int main(){

    scanf("%d",&t);

    while (t--)

    {

        total = 0;

        num2 = 0;

        num3 = 0;

        scanf("%s",num[number]);

        for (int i = 0; i < strlen(num[number]); i++)

        {

            total += (num[number][i] - '0');

            if (num[number][i] == '2')

            {

                num2 ++;

            }

            if (num[number][i] == '3')

            {

                num3 ++;

            }

            

        }

        if (total%9 == 0)

        {

            printf("YES\n");

            continue;

        }

        

        if ((total%9)%2 == 0)

        {

            total = 18-(total%9);

        }else{

            total = 9-(total%9);

        }



        int temp = num2+num3;

       for (int i = 1; i <= temp+1; i++)

       {

        if (total == 0)

        {

            printf("YES\n");

            break;

        }

        

         if (total>=6 && num3>0)

         {

            total -= 6;

            num3--;

         }

         else if (total>=2 && num2>0)

         {

            total -= 2;

            num2--;

         

         

         

       }

       

        

    }

    if (total == 0)

    {

        continue;

    }

    

    printf("NO\n");

        

        number++;

}

    

    return 0;

}

Submission (verdict: Memory limit exceeded on test 1):
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

int t,number=1,total,num2,num3;

char num[10005][100005];

int main(){

    scanf("%d",&t);

    while (t--)

    {

        total = 0;

        num2 = 0;

        num3 = 0;

        scanf("%s",num[number]);

        for (int i = 0; i < strlen(num[number]); i++)

        {

            total += (num[number][i] - '0');

            if (num[number][i] == '2')

            {

                num2 ++;

            }

            if (num[number][i] == '3')

            {

                num3 ++;

            }

            

        }

        if (total%9 == 0)

        {

            printf("YES\n");

            continue;

        }

        

        if ((total%9)%2 == 0)

        {

            total = 18-(total%9);

        }else{

            total = 9-(total%9);

        }



        int temp = num2+num3;

       for (int i = 1; i <= temp+1; i++)

       {

        if (total == 0)

        {

            printf("YES\n");

            break;

        }

        

         if (total>=6 && num3>0)

         {

            total -= 6;

            num3--;

         }

         else if (total>=2 && num2>0)

         {

            total -= 2;

            num2--;

         

         

         

       }

       

        

    }

    if (total == 0)

    {

        continue;

    }

    

    printf("NO\n");

        

        number++;

}

    

    return 0;

}