Let's denote a function $$$f(x)$$$ in such a way: we add $$$1$$$ to $$$x$$$, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example,   $$$f(599) = 6$$$: $$$599 + 1 = 600 \rightarrow 60 \rightarrow 6$$$;  $$$f(7) = 8$$$: $$$7 + 1 = 8$$$;  $$$f(9) = 1$$$: $$$9 + 1 = 10 \rightarrow 1$$$;  $$$f(10099) = 101$$$: $$$10099 + 1 = 10100 \rightarrow 1010 \rightarrow 101$$$. We say that some number $$$y$$$ is reachable from $$$x$$$ if we can apply function $$$f$$$ to $$$x$$$ some (possibly zero) times so that we get $$$y$$$ as a result. For example, $$$102$$$ is reachable from $$$10098$$$ because $$$f(f(f(10098))) = f(f(10099)) = f(101) = 102$$$; and any number is reachable from itself.You are given a number $$$n$$$; your task is to count how many different numbers are reachable from $$$n$$$.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

Print one integer: the number of different numbers that are reachable from $$$n$$$.

#include "stdio.h"

int main() {
    unsigned int num;
    int count;
    while(~scanf("%d", &num)) {
        count = 0;
        while(num >= 10) {
            num++;
//            printf("%d %d ", num, num%10);
            while(num%10 == 0) {
                num /= 10;
            }
//            printf("%d\n", num);
            count++;
        }
        printf("%d\n", count + 9);
    }

    return 0;
}

#include<stdio.h>
int cnt,flag=0,flag2=0;
long long fun(long long x);
int main(void)
{
    long long x,temp=10;
    scanf("%lld",&x);
//    cnt++;
    while(x>9&&flag==0)
    {
        x=fun(x);
//        if(x==1&&flag==0)
//            flag=1;
//        if(flag2==1)
//            break;
    }
    printf("%d\n",cnt+9);
    return 0;
}
long long fun(long long x)
{
    x++;
    while(x%10==0)
        x/=10;
    cnt++;
    return x;
}

#include <stdio.h>
#include <math.h>
int main()
{
    int a,count;
    scanf("%d",&a);
    if(a>0 && a<=9)
    {
        count=0;
    }
    else
    {
        count=1;
    }
    while(1)
    {
        a++;
        while(1)
        {
            if(a%10!=0)
            {
                break;
            }
            else
            {
                a=a/10;
            }
        }
        count++;
        if(a>=1 && a<=9)
        {
            break;
        }
    }
    printf("%d",count+8);

    return 0;
}

#include <stdio.h>
#include <stdbool.h>

int f(int n)
{
	n++;
	while (n % 10 == 0)
	{
		n = n / 10;
	}
	return n;
}

int main()
{
	int n;
	scanf("%d" , &n);

	int c;

	for (c = 0 ; n > 1 ; c++)
	{
		if (n > 1 && n < 10)
		{
			c--;
		}
		n = f(n);
	}

	printf("%d\n", c + 9);
}

#include <stdio.h>

int main(void)
{
    long long int num , count = 0;
    scanf("%lli" ,&num);

    while (1)
    {
        if(num < 10) break;
        count++;
        num++;

        while (1)
        {
            if(!(num % 10)) num /= 10;
            else break;
        }
    }

    count += 9;
    printf("%lli",count);
    return 0;
}

#include<stdio.h>
int main()
{
    char ch=getchar();int i=1,total=0,n;
    total=0;i=1;while(ch>='0'&&ch<='9')
    {
        ch=ch-'0';
        if(i==1)
        {
            total+=9;
        }
        else
            total=total+10-ch-1;
        ch=getchar();
        i++;
    }
    if(i==2)
        printf("9");
    else printf("%d\n",total+1);
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);

    int i=0,j=0;

    while(1)
    {
        if(n>=1&&n<10)
        {
            printf("%d",9+j);
            return 0;
        }
        i=10-n%10;
        j=j+i;
        n=n+i;
        while(n%10==0)
            n=n/10;
    }
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
long int count=0;
void recur(long int n){
    if(n<10){
        count+=9;
        return;
    }
    else{
        n = n+1;
        while(n%10==0){
            n=n/10;
        }
        count++;
        recur(n);
    }
}
int main(){
    long int num;
    scanf("%ld",&num);
    recur(num);
    printf("%ld",count);
}

#include <stdio.h>

int main(void)
{
	int N, i;
	int flag = 0;
	int A[1000000] = { 0 };
	int count = 1;
	int index = 0;
	scanf("%d", &N);
	while(1)
	{
		A[index] = N;
		index++; count++;
		N += 1;
		if(N % 10 == 0)
		{
			while(N % 10 == 0)
				N /= 10;
		}
		A[index] = N;
		if(flag)
		{
			for(i = 0; i < index; i++)
			{
				if(A[i] == N)
				{
					printf("%d", count - 1);
					return 0;
				}
			}
		}
		flag = 1;
	}
}

#include <stdio.h>
int main () {
    int n, ans = 0;
    scanf ("%d", &n);

    while (n >= 10) {
        n ++;
        while (!(n % 10)) {
            n /= 10;
        }
        ans ++;
    }
    printf ("%d\n", ans + 9);
    return 0;
}

#include<stdio.h>
int recur(int n)
{
static int psf=0;
if(n<10) psf++;
        n++;
        if(n%10==0)
        {
            while(n%10==0)
            {
                n/=10;
            }
        }

    if(n==1)
    {
        return 10-psf;

    }
    return 1+recur(n);

}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",recur(n));
    return 0;
}

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

typedef int64_t I64;

int main() {
	I64 n, count = 0;
	scanf("%"SCNi64, &n);

	while (n >= 10) {
		n++;
		while (n % 10 == 0) {
			n /= 10;
		}
		count++;
	}

	printf("%"PRIi64"\n", count + 9);
	return 0;
}

#include<stdio.h>

int main()
{
    long long int n;
    long long int cou=1;
    scanf("%I64d", &n);

    if(n/10 == 0){
        cou = 9;
        goto print;
    }
    n++;
    while(1){
        if(n/10 == 0){
            cou += 9;
            break;
        }
        if(n%10 == 0){
            n /= 10;
        }
        else{
            n++;
            cou++;
        }
    }
    print:
    printf("%I64d", cou);

    return 0;
}

#include<stdio.h>
int main(){
    int i=0,j=2,k,l;
    long long int n;

scanf("%I64d",&n);
if(n==1)k=1;if(n<10){
            puts("9");
            return 0;
         }
n++;
while(n!=1){

        if(n%10==0){i++;
    n=n/10;}
else n++;
    j++;
    if(n<=9){break;}

}

    printf("%d\n",j-i+8);
return 0;
}

#include<stdio.h>

int main()
{
    int i;
    scanf("%d", &i);
    int count = 0;
    while(i > 9)
    {

        i++;
        while(i % 10 == 0)
        {
            i /= 10;
        }

        if(i % 10 != 0)
        {
            count++;
        }

        if(i == 1)
        {
            break;
        }

    }

    printf("%d\n", count + 9);

    return 0;

}

/*  AUTHOR:AKASH JAIN
*   USERNAME:akash19jain
*   DATE:05/06/2019
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
long long solve(long long x)
{
    x++;
    while(x%10==0)
    {
        x=x/10;
    }
    return x;
}
int main()
{
    long long t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        long long n,ans=0;
        scanf("%lld",&n);
        long long arr[1000],a=0;
        long long c=n,x=1;
        arr[a++]=n;
        while(x)
        {
            n=solve(n);
            for(long long i=0;i<a;i++)
            {
                if(arr[i]==n)
                {
                    x=0;
                    break;
                }
            }

            arr[a++]=n;
        }
        printf("%lld\n",a-1);
    }
    return 0;
}

#include <stdio.h>

int main() {
	int n, c, cnt;

	scanf("%d", &n);
	cnt = 0;
	while (n >= 10) {
		n++;
		cnt++;
		while (n % 10 == 0)
			n /= 10;
	}
	printf("%d\n", cnt + 9);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

typedef int PrimaryType_t;
typedef struct {
    PrimaryType_t mPrimaryVal;
} RBData_t;

typedef enum {
    RB_RED,
    RB_BLACK
} RBColor_t;

struct RBNode_t {
    struct RBNode_t *mLeft, *mRight, *mParent;
    RBColor_t mColor;
    RBData_t mKey;
};

typedef struct {
    struct RBNode_t mSentinelLeaf;
    struct RBNode_t *mTreeRoot;
} RBTree_t;

void Show(struct RBNode_t *node)
{
    printf("%p %p %p %p %d %d\n", node, node->mParent, node->mLeft, node->mRight, node->mKey.mPrimaryVal, node->mColor);
}

void RBTreeInitialize(RBTree_t *tree)
{
    tree->mTreeRoot = &tree->mSentinelLeaf;
    tree->mSentinelLeaf.mColor = RB_BLACK;
}

void RBTreeInorder(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node != stop) {
        RBTreeInorder(node->mLeft, stop);
        Show(node);
        RBTreeInorder(node->mRight, stop);
    }
}

void RBTreePostorderFree(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node != stop) {
        RBTreePostorderFree(node->mLeft, stop);
        RBTreePostorderFree(node->mRight, stop);
        free(node);
    }
}

void RBTreeDestroy(RBTree_t *tree)
{
    RBTreePostorderFree(tree->mTreeRoot, &tree->mSentinelLeaf);
    RBTreeInitialize(tree);
}

struct RBNode_t *RBTreeSearch(struct RBNode_t *node, RBData_t *key, struct RBNode_t *stop)
{
    while(node != stop && key->mPrimaryVal != node->mKey.mPrimaryVal) {
        if(key->mPrimaryVal < node->mKey.mPrimaryVal) {
            node = node->mLeft;
        } else {
            node = node->mRight;
        }
    }
    return node;
}

struct RBNode_t *RBTreeMinimum(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node == stop) {
        return node;
    }
    while(node->mLeft != stop) {
        node = node->mLeft;
    }
    return node;
}

struct RBNode_t *RBTreeMaximum(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node == stop) {
        return node;
    }
    while(node->mRight != stop) {
        node = node->mRight;
    }
    return node;
}

struct RBNode_t *RBTreeSuccessor(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node->mRight != stop) {
        return RBTreeMinimum(node->mRight, stop);
    }
    struct RBNode_t *p = node->mParent;
    while(p != stop && node == p->mRight) {
        node = p;
        p = node->mParent;
    }
    return p;
}

struct RBNode_t *RBTreePredecessor(struct RBNode_t *node, struct RBNode_t *stop)
{
    if(node->mLeft != stop) {
        return RBTreeMaximum(node->mLeft, stop);
    }
    struct RBNode_t *p = node->mParent;
    while(p != stop && node == p->mLeft) {
        node = p;
        p = node->mParent;
    }
    return p;
}

void RBTreeLeftRotate(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *y = node->mRight;
    node->mRight = y->mLeft;
    if(y->mLeft != &tree->mSentinelLeaf) {
        y->mLeft->mParent = node;
    }
    y->mParent = node->mParent;
    if(node->mParent == &tree->mSentinelLeaf) {
        tree->mTreeRoot = y;
    } else if(node == node->mParent->mLeft) {
        node->mParent->mLeft = y;
    } else {
        node->mParent->mRight = y;
    }
    y->mLeft = node;
    node->mParent = y;
}

void RBTreeRightRotate(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *y = node->mLeft;
    node->mLeft = y->mRight;
    if(y->mRight != &tree->mSentinelLeaf) {
        y->mRight->mParent = node;
    }
    y->mParent = node->mParent;
    if(node->mParent == &tree->mSentinelLeaf) {
        tree->mTreeRoot = y;
    } else if(node == node->mParent->mLeft) {
        node->mParent->mLeft = y;
    } else {
        node->mParent->mRight = y;
    }
    y->mRight = node;
    node->mParent = y;
}

void RBTreeInsertFixup(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *s;
    while(node->mParent->mColor == RB_RED) {
        if(node->mParent == node->mParent->mParent->mLeft) {
            s = node->mParent->mParent->mRight;
        } else {
            s = node->mParent->mParent->mLeft;
        }
        if(s->mColor == RB_RED) {
            node->mParent->mColor = RB_BLACK;
            s->mColor = RB_BLACK;
            node->mParent->mParent->mColor = RB_RED;
            node = node->mParent->mParent;
        } else {
            if(node == node->mParent->mRight && node->mParent == node->mParent->mParent->mLeft) {
                node = node->mParent;
                RBTreeLeftRotate(tree, node);
            } else if(node == node->mParent->mLeft && node->mParent == node->mParent->mParent->mRight) {
                node = node->mParent;
                RBTreeRightRotate(tree, node);
            }
            node->mParent->mColor = RB_BLACK;
            node->mParent->mParent->mColor = RB_RED;
            if(node == node->mParent->mLeft) {
                RBTreeRightRotate(tree, node->mParent->mParent);
            } else {
                RBTreeLeftRotate(tree, node->mParent->mParent);
            }
        }
    }
    tree->mTreeRoot->mColor = RB_BLACK;
}

void RBTreeInsert(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *y = &tree->mSentinelLeaf;
    struct RBNode_t *x = tree->mTreeRoot;
    while(x != &tree->mSentinelLeaf) {
        y = x;
        if(node->mKey.mPrimaryVal < x->mKey.mPrimaryVal) {
            x = x->mLeft;
        } else {
            x = x->mRight;
        }
    }
    node->mParent = y;
    if(y == &tree->mSentinelLeaf) {
        tree->mTreeRoot = node;
    } else if(node->mKey.mPrimaryVal < y->mKey.mPrimaryVal) {
        y->mLeft = node;
    } else {
        y->mRight = node;
    }
    node->mLeft = &tree->mSentinelLeaf;
    node->mRight = &tree->mSentinelLeaf;
    node->mColor = RB_RED;
    RBTreeInsertFixup(tree, node);
}

void RBTreeTransplant(RBTree_t *tree, struct RBNode_t *u, struct RBNode_t *v)
{
    if(u->mParent == &tree->mSentinelLeaf) {
        tree->mTreeRoot = v;
    } else if(u == u->mParent->mLeft) {
        u->mParent->mLeft = v;
    } else {
        u->mParent->mRight = v;
    }
    v->mParent = u->mParent;
}

void RBTreeDeleteFixup(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *s;
    while(node != tree->mTreeRoot && node->mColor == RB_BLACK) {
        if(node == node->mParent->mLeft) {
            s = node->mParent->mRight;
            if(s->mColor == RB_RED) {
                s->mColor = RB_BLACK;
                node->mParent->mColor = RB_RED;
                RBTreeLeftRotate(tree, node->mParent);
                s = node->mParent->mRight;
            }
            if(s->mLeft->mColor == RB_BLACK && s->mRight->mColor == RB_BLACK) {
                s->mColor = RB_RED;
                node = node->mParent;
            } else {
                if(s->mRight->mColor == RB_BLACK) {
                    s->mLeft->mColor = RB_BLACK;
                    s->mColor = RB_RED;
                    RBTreeRightRotate(tree, s);
                    s = node->mParent->mRight;
                }
                s->mColor = node->mParent->mColor;
                node->mParent->mColor = RB_BLACK;
                s->mRight->mColor = RB_BLACK;
                RBTreeLeftRotate(tree, node->mParent);
                node = tree->mTreeRoot;
            }
        } else {
            s = node->mParent->mLeft;
            if(s->mColor == RB_RED) {
                s->mColor = RB_BLACK;
                node->mParent->mColor = RB_RED;
                RBTreeRightRotate(tree, node->mParent);
                s = node->mParent->mLeft;
            }
            if(s->mLeft->mColor == RB_BLACK && s->mRight->mColor == RB_BLACK) {
                s->mColor = RB_RED;
                node = node->mParent;
            } else {
                if(s->mLeft->mColor == RB_BLACK) {
                    s->mRight->mColor = RB_BLACK;
                    s->mColor = RB_RED;
                    RBTreeLeftRotate(tree, s);
                    s = node->mParent->mLeft;
                }
                s->mColor = node->mParent->mColor;
                node->mParent->mColor = RB_BLACK;
                s->mLeft->mColor = RB_BLACK;
                RBTreeRightRotate(tree, node->mParent);
                node = tree->mTreeRoot;
            }
        }
    }
    node->mColor = RB_BLACK;
}

void RBTreeDelete(RBTree_t *tree, struct RBNode_t *node)
{
    struct RBNode_t *y = node;
    struct RBNode_t *x;
    RBColor_t origincolor = y->mColor;
    if(node->mLeft == &tree->mSentinelLeaf) {
        x = node->mRight;
        RBTreeTransplant(tree, node, node->mRight);
    } else if(node->mRight == &tree->mSentinelLeaf) {
        x = node->mLeft;
        RBTreeTransplant(tree, node, node->mLeft);
    } else {
        y = RBTreeMinimum(node->mRight, &tree->mSentinelLeaf);
        origincolor = y->mColor;
        x = y->mRight;
        if(y->mParent == node) {
            x->mParent = y;
        } else {
            RBTreeTransplant(tree, y, y->mRight);
            y->mRight = node->mRight;
            y->mRight->mParent = y;
        }
        RBTreeTransplant(tree, node, y);
        y->mLeft = node->mLeft;
        y->mLeft->mParent = y;
        y->mColor = node->mColor;
    }
    if(origincolor == RB_BLACK) {
        RBTreeDeleteFixup(tree, x);
    }
}

void RBTreeAdd(RBTree_t *tree, PrimaryType_t num)
{
    struct RBNode_t *node = (struct RBNode_t *)malloc(sizeof(struct RBNode_t));
    node->mKey.mPrimaryVal = num;
    RBTreeInsert(tree, node);
}

void RBTreeDel(RBTree_t *tree, PrimaryType_t num)
{
    RBData_t check;
    check.mPrimaryVal = num;
    struct RBNode_t *node = RBTreeSearch(tree->mTreeRoot, &check, &tree->mSentinelLeaf);
    if(node == &tree->mSentinelLeaf) {
        puts("ERROR");
        return;
    }
    RBTreeDelete(tree, node);
    free(node);
}

int f(int x)
{
    ++x;
    while(x % 10 == 0) {
        x /= 10;
    }
    return x;
}

int main()
{
    int n, ans = 1;
    scanf("%d", &n);
    RBTree_t Tree;
    RBTreeInitialize(&Tree);
    RBTreeAdd(&Tree, n);
    while(1) {
        n = f(n);
        RBData_t check;
        check.mPrimaryVal = n;
        struct RBNode_t *node = RBTreeSearch(Tree.mTreeRoot, &check, &Tree.mSentinelLeaf);
        if(node == &Tree.mSentinelLeaf) {
            RBTreeAdd(&Tree, n);
            ++ans;
        } else {
            break;
        }
    }
    printf("%d\n", ans);
    RBTreeDestroy(&Tree);
    return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k=1;
    scanf("%lld",&n);
    if(n<=9)
        printf("9\n");
    else{
        while(1)
        {
            n=n+1;
            while(n%10==0){
                n=n/10;
                }

            k++;
            if(n<10)
            {
                k=k+8;
                break;}
        }
        if(k<10)
        printf("%lld\n",k+8);
        else printf("%lld\n",k);
    }
    return 0;
}

#include <stdio.h>

int main()
{
    int n, cnt=9;
    scanf("%d", &n);
    while(n > 9)
    {
        n++;
        cnt++;
        while(n%10==0)
        {
            n /= 10;
        }
    }
    printf("%d\n", cnt);
	return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int f(long);

int main()
{
	long n;
	scanf("%ld", &n);
	printf("%d", f(n));
	return 0;
}

int f(long n)
{
	int count = 0;
	if(n % 10 == 0)
	{
		count++;
		n++;
	}
	while(n > 10)
	{
		while(n % 10 != 0)
		{
			count++;
			n++;
		}
		n = n/10;
	}
	count += 9;
	return count;
}

#include <stdio.h>

int main()
{
    int a, count=1, b, d, e, f;
    scanf("%d", &a);
    int c[100], flag=0;
    c[0] = a;
    a++;
    while(1)
    {
        b = a%10;
        flag =0;
        if(b != 0)
        {
            for (d=0; d<count; d++)
            {
                if(a == c[d])
                    flag=1;
            }
            if (flag)
                break;
            c[count] = a;
            count++;
            a += 1;
     //   printf("%d %d %d\n", a, count, c[count-1]);
        }
        else
            a /= 10;

    }
    printf("%d", count);
    return 0;

}

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);

    int num = n;

    int i, j, temp=num, count=1;

    if (n<10)
    {
        printf("%d\n", 9);
    }

    else
    {
        for (i=1; ;i++)
        {
            if (num<10)
            {
                count+=9;
                break;
            }

            if ((num+i)%10==0)
            {
                i=0;
                ///printf("%d\n", i);
                num = num/10;
                continue;
            }
            ///printf(":: %d\n", num+i);
            count++;
        }

        printf("%d\n", count);
    }
    return 0;
}

#include<stdio.h>
int main(void)
{
	long long int num = 0;
	scanf("%I64d",&num);
	long long int ans = 0;
	while(num/10!=0)
	{
		ans+=(10-num%10);
		num/=10;
		num+=1;
		while(num%10==0)
		{
			num/=10;
		}
	}
	ans+=9;
	printf("%I64d",ans);
}

#include <stdio.h>
int main(){
  int n,ans=0;
    scanf("%d",&n);
    if(n%10==0){
        ans++;
        n++;
    }
    while(1){
        if(n<10)break;
        int x=n%10;
        if(x==0){
            n/=10;
            continue;
        }
        ans+=10-x;
        n=n/10+1;
    }
 printf("%d",ans+9);
}

#include <stdio.h>

int main(){
	int n, result = 1, s = 0;
	scanf("%d",&n);
	while (n >= 10){
		s = 10 - n%10;
		result += s;
		n+=s;
		while(!(n%10)) n/=10;
	}
	printf("%d", result+8);
}

#include<stdio.h>
int main()
{
    long n;
    scanf("%ld",&n);
    int counter=0;
    int flag=1;
    int a[10000];
    a[counter++]=n;
    while(flag==1)
    {
        n=n+1;
        while(n%10==0)
        n=n/10;
        for(int i=0;i<counter;i++)
        if(a[i]==n)
        {flag=0;break;}
        if(flag==0)
        break;
        a[counter]=n;
        //printf("%d\n",a[counter]);
        counter++;
    }
    //for(int i=0;i<counter;i++)
    //printf("%d ",a[i]);
    printf("\n%d",counter);
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int lt(int i){
    int k,s=1;
    for (k=1;k<=i;k++)
        s=s*10;
    return s;
}
int f(int x){
	int f,i=0,y=x+1;
	while (y%lt(i)==0){
		i++;
	}
	f=y/lt(i-1);
	return f;
}
int main() {
	int a[1000],count=1,kq,x,i=0,j,kt=1;
	scanf("%d",&x);
	kq=x;
	if (x==10) count=19;
	else if (x<10) count=9;
	else{
	while (kq>10){
		kq=f(kq);
		a[i]=kq;
		for (j=0;j<i;j++){
			if (a[i]==a[j]){
				kt=0;
				break;
			}
		}
		if (kt==1) count++;
		i++;
	}
	count+=8;
	}
	printf("%d",count);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x,y,z;
    y=0;
    z=-1;
    scanf("%d",&x);
    while (1)
    {
        if(z==x)
            break;
        if(z==-1&&x<10)
            z=x;
        y++;
        x+=1;
        while(x%10==0)
            x/=10;

    }
    printf("%d\n",y);
    return 0;
}

#include <stdio.h>

long long ans = 0;

void f(long long n){
    if (n < 10){
        ans += 9;
        return;
    }
    ans++;
    n++;
    while (n % 10 == 0){
        n = n / 10;
    }
    //printf("%lld %lld\n", n, ans);
    f(n);
}

int main(){
    long long n;
    fscanf(stdin, "%lld", &n);

    f(n);

    printf("%lld", ans);
    return 0;
}

#include <stdio.h>

int main()
{
    int n,c=1;
    scanf("%d",&n);

    while(1)
    {
        if(n>=10)
        {
            n=n+1;
            c=c+1;
            while(n%10==0)
            {
                n=n/10;
            }

        }
       else
        {
            printf("%d",c+8);
            break;
        }

    }

}

#include <stdio.h>
int main()
{
    long long int  n, count = 1;
    while(scanf("%lld", &n) != EOF)
    {
        if(n >= 10)
        {
            n = n + 1;
        count++;
        while(n >= 10)
        {
            while(n % 10 != 0)
            {
                n = n + 1;
                if(n < 10)
                {
                    count--;
                    break;
                }
                count++;
            }
            while(n % 10 == 0)
            {
                n = n / 10;
                if(n < 10)
                {
                    count--;
                    break;
                }
            }
        }
        count = count + 9;
        printf("%lld\n", count);
        }
        else
        {
            count = 9;
            printf("%lld\n", count);
        }

        count = 1;
    }
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
  int n,c=1,i,j=1,flag=0;
  scanf("%d",&n);
  int k=n;

  int a[100]={0};
  a[0]=n;
  while(1)
  {
   n=n+1;
   while(n%10==0)
   {
       n=n/10;
   }
  for(i=0;i<100;i++)
   {
       if(a[i]==n)
       {
           flag=1;
           break;
       }
   }
   if(flag==1)
    break;
    else
    {
        a[j]=n;
        j++;
        c++;
    }

  }

  printf("%d",j);

}

#include <stdio.h>

long int n;
int c;
long int parada;

int count(){
  if(n<10){
    c = 9;
    return 0;
  }
  c = 1;
  n++;
  parada = 10000000000;
  while(1){
    while(n%10 == 0){
      n= n/10;
      if(parada/10 < 1){break;}
      parada = n-1;
      if(!parada){
        parada = 9;
      }
    }

    //printf("%li\n",n);
    c++;
    //printf("%li %d\n",n,c);
    if(n == parada){
      return 0;
    }
    n++;
  }
  return 0;
}

int main(void) {

  scanf("%li", &n);

  count();
  printf("%d\n", c);

  return 0;
}

#include<stdio.h>
int main()
{
	int num;
	scanf("%d",&num);
	int count=0;
	if(num<10)printf("9\n");
	else{
		while(num>9){
				count+=10-(num%10);
				num=num/10+1;
			while(num%10==0)
				num=num/10;
		}
		printf("%d",count+9);
	}
	return 0;
}

#include<stdio.h>
int main()
{
	long aa,aaa;
	int i,a[15],n,k;
	scanf("%ld",&aa);
	aaa=aa;
	for(i=1;aa!=0;i++)
	{
		a[i]=aa%10;
		aa/=10;
	}
	k=i-1;
	n=0;
	for(i=1;i<k;i++)
	{
		n+=9-a[i];
	}
	n+=10;
	if(aaa<10)
		printf("9");
	else
	printf("%d",n);
	return 0;
}

#include <stdio.h>

int main() {
    int n, dem = 0;
    scanf("%d", &n);
    while (n >= 10) {
        int k = n % 10;
        dem += (10 - k);
        n += (10 - k);
        while(n % 10 == 0)
        n /= 10;
    }
    dem += 9;
    printf("%d", dem);
    return 0;
}

#include <stdio.h>
int main(void) {
	int n,a=1;
	scanf("%d",&n);
	while(1)
    {
        if(n>0 && n<10)
            break;
        n=n+1;
        a=a+1;
        while(n%10==0)
            n=n/10;
    }
    printf("%d",a+8);
	return 0;
}

#include<stdio.h>
int vis[15];
int main()
{
    int n;
    scanf("%d", &n);
    if(n < 10 && n > 0)
    {
        printf("9\n");
        return 0;
    }
    int count = 0;
    while(1)
    {
            n++;
        while(n % 10 == 0)
        {
            n /= 10;
        }
        if(n <= 10 && n > 0)
        {
            if(vis[n] == 1)
                break;
            else
                vis[n] = 1;
        }
        count++;
    }
    printf("%d\n", count+1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, cn, nr;
    scanf("%d", &n);
    nr=0;
    while(n>=10){
        nr++;
        n++;
        while(n%10==0)
            n/=10;
    }
    printf("%d", nr+9);
    return 0;
}

#include <stdio.h>

int v[10], sum;
int check(int n)
{
    if(n / 10) return n / 10;
    if(sum < 45)
        for(int i = 1; i <= 9; i++)
            if(v[i] == 0)
            {
                v[i] = 1;
                sum += i;
                return 1;
            }
    return 0;
}

int main()
{
    int n, cnt = 0;

    scanf("%d", &n);
    do
    {
        if(n / 10 == 0) sum += n;
        // printf("n = %d\n", n);
        // printf("sum = %d\n", sum);
        n++; cnt++;
        if(n % 10 == 0)
            while(n % 10 == 0)
                n /= 10;
    }while(sum < 45);
    printf("%d\n", cnt);

    return 0;
}

#include<stdio.h>

int main()
{
    int i;
    scanf("%d", &i);
    int count = 0;
    while(i > 9)
    {

        i++;
        while(i % 10 == 0)
        {
            i /= 10;
        }

        if(i % 10 != 0)
        {
            count++;
        }

        if(i == 1)
        {
            break;
        }

    }

    printf("%d\n", count + 9);

    return 0;

}

#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	int ans=0;
	if(n<10)
	{
		ans=9;
	}
	else
	{
		ans=10;
		while(n>9)
		{
		ans+=9-n%10;
		n/=10;
		}
	}
	printf("%d",ans);
 }

#include<stdio.h>
long long int n,k,count=0,flag=0;
long long int f(long long int n)
{	n+=1;
	while(1)
	{	if(n%10==0)	n/=10;
		else break;
	}
	return n;
}
void ff(long long int n)
{	if(n>=10)
	{
		n=f(n);
		count++;
	//	printf("%d %d\n",n,count);

		ff(n);
	}
	else if(n<10)
	{	count+=9;
		return ;
	}
	else return ;
}

int main()
{
	scanf("%d",&n);

	if(n==1)
	printf("%d\n",9);
	else
	{
	ff(n);
	printf("%d\n",count);
	}

 }

#include <stdio.h>
int main () {
    int n, ans = 0;
    scanf ("%d", &n);

    while (n >= 10) {
        n ++;
        while (!(n % 10)) {
            n /= 10;
        }
        ans ++;
    }
    printf ("%d\n", ans + 9);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

typedef long long int LL;

int main(){

	int n; scanf("%d", &n);
	if( n < 10 ){
		printf("9\n");
		return 0;
	}

	int count = 1;
	int num = n;

	while( 1 ){
		num++;
		while(num % 10 == 0){
			num /= 10;
		}
		if(num < 10){
			break;
		}
		count++;
	}
	printf("%d\n", count+9);

	return 0;
}

#include<stdio.h>
int main(void)
{
	long long int num = 0;
	scanf("%I64d",&num);
	long long int ans = 0;
	while(num/10!=0)
	{
		ans+=(10-num%10);
		num/=10;
		num+=1;
		while(num%10==0)
		{
			num/=10;
		}
	}
	ans+=9;
	printf("%I64d",ans);
}

#include<stdio.h>
int main()
{
    long long int n,c=0;
    scanf("%I64d",&n);
    if((n/10)<0)
        printf("9");
    else
    {
    while(n>9)
    {
        n=n+1;
        c++;
        while(n%10==0)
        {
            n=n/10;

        }
    }

        printf("%I64d",c+9);
    }
}

#include <stdio.h>

int f(int a);

int main(void)
{
    int a, ans=0;

    scanf("%d", &a);

    for(;a>9;)
    {
        a=f(a);
        ans++;
    }
    printf("%d", ans+9);

    return 0;
}

int f(int a)
{
    a+=1;
    for(;a%10==0;)
    {
        a/=10;
    }
    return a;
}

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

typedef int64_t I64;

int main() {
	I64 n, count = 0;
	scanf("%"SCNi64, &n);

	while (n >= 10) {
		n++;
		while (n % 10 == 0) {
			n /= 10;
		}
		count++;
	}

	printf("%d\n", count + 9);
	return 0;
}

#include<stdio.h>

int check(int* a){

	int flag=0, j;
	for(j=1;j<10;j++){
		if(a[j]==0){
			flag=0;
			break;
		}
		else{
			flag=1;
		}
	}
	return flag;
}
int main(){
	long long n,temp;
	scanf("%lld",&n);
	int flag=0,count=0,i,j;
	int a[10]={0,0,0,0,0,0,0,0,0,0};
	temp=n;
	int iter=0,it=0;
	while(1){
		iter++;
		for(i=0;;i++){
			it++;
			if(check(a))
				break;
			if(it!=1 && temp%10==0){
				temp=temp/10;
				break;
			}
			count++;
			if(temp<10){
				a[temp]=1;
			}
			temp++;
		}
		//condition for flag
		flag=check(a);
		if(flag==1) break;
	}
	printf("%d\n", count);
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x,y,z;
    y=0;
    z=-1;
    scanf("%d",&x);
    while (1)
    {
        if(z==x)
            break;
        if(z==-1&&x<10)
            z=x;
        y++;
        x+=1;
        while(x%10==0)
            x/=10;

    }
    printf("%d\n",y);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);

    int i=0,j=0;

    while(1)
    {
        if(n>=1&&n<10)
        {
            printf("%d",9+j);
            return 0;
        }
        i=10-n%10;
        j=j+i;
        n=n+i;
        while(n%10==0)
            n=n/10;
    }
}

#include<stdio.h>
int main()
{
   long long int n;
    scanf("%lld",&n);
    long long int i=0;
    while(n>=10)
    {
        n++;
        i++;
        while(n%10==0)
        {
            n=n/10;
        }

    }
    printf("%lld",i+9);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

unsigned long long d( unsigned long long e){
	e += 1;
	while( e % 10 == 0){
		e /= 10;
	}
	return e;
}

typedef struct list list;
struct list{
	unsigned long long d;
	list *next;
};

void add( list **l, unsigned long long z){
	list *sl = *l;
	list *nl = NULL;
	nl = malloc(sizeof(list));
	nl -> next = sl;
	nl -> d = z;
	*l = nl;
}
int coll( unsigned long long z, list **l){
	list *sl = *l;
	while( sl != NULL){
		if( z == sl -> d){
			return 1;
		}
		// printf("<%d> ", sl->d);
		sl = sl -> next;
	}
	return 0;
}
int len( list **l){
	int c = 0;
	list *sl = *l;
	while( sl -> next != NULL){
		++c;
		sl = sl -> next;
		// printf("<%d> ", sl->d);
	}
	return c;
}
int main(int argc, char const *argv[])
{
	unsigned long long a = 0;

	scanf("%d", &a);
	list *l = NULL;
	l = malloc( sizeof(list));
	while( coll(a, &l) != 1){
		add(&l, a);
		a = d(a);
	}
	printf("%d", len(&l));

	return 0;
}

#include<stdio.h>

long remove_zeros(long num) {
    return num % 10 == 0 ? remove_zeros(num / 10) : num;
}

int solve(long num) {
    if(num < 10)
        return 9;

    return 10 - (num % 10) + solve(remove_zeros(num / 10 + 1));
}

int main() {
    long num;

    scanf("%ld", &num);
    printf("%d\n", solve(num));

    return 0;
}

#include<stdio.h>

int main(void)
{
    long long int n, a, b, c=1, e;
    scanf("%lld", &n);

    if(n>9) {
        n++;
        c++;
    }

    for( ; ; ) {

        if(!(n%10))
            n /= 10;

        else if(n>9) {
            a = n%10;
            c += 10-a;
            n += 10-a;
            n /= 10;
        }
        else if(n<10) {
            c += 8;
            break;
        }

    }

    printf("%lld", c);

    return 0;
}

#include <stdio.h>

int f(int a);

int ans=1;

int main(void)
{
    int a;
    int b=0;

    scanf("%d", &a);

    for(;a!=1 || b!=1;)
    {
        if(a==1)
        {
            b=1;
        }
        a=f(a);
    }
    printf("%d", ans);

    return 0;
}

int f(int a)
{
    a+=1;
    for(;a%10==0;)
    {
        a/=10;
    }
    ans++;
    return a;
}

#include <stdio.h>

int main() {
	int n, result = 2, s = 0;
	scanf("%d", &n);
	n += 1;
	while (n != 1) {
		s = 10 - n % 10;
		result += s;
		n += s;
		while (!(n % 10))
			n /= 10;
	}
	printf("%d", result);
}

#include <stdio.h>

int main() {
    int n, dem = 0;
    scanf("%d", &n);
    while (n > 10) {
        int k = n % 10;
        if (k != 0) {
            dem += (10 - k);
            n += (10 - k);
        }
        else n /= 10;
    }
    if (n == 10) dem += 19;
    else
    dem += (11-n);
    printf("%d", dem);
    return 0;
}

#include<stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int count = 0;
    int i;
    for(i = n; i >= 1; )
    {

        if(i == n)
        {
            count++;
        }
        i++;
        while(i % 10 == 0)
        {
            i /= 10;
        }

        if(i % 10 != 0)
        {
            count++;
        }

        if(i == 1)
        {
            break;
        }

    }

    printf("%d\n", count);

    return 0;

}

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int count=1;
    if(n<=9)
        count=9;
    else
    {
        while(n!=1)
        {
            n++;
            while(n%10==0)
            {
                n=n/10;
            }
            count++;
        }
    }

    if(count<9)
        printf("%d",count+8);
    else
        printf("%d",count);
    return 0;
}

#include<stdio.h>
int main()
{
    char ch=getchar();int i=1,total=05;
    while(ch!='\n')
    {
        ch=ch-'0';
        if(i==1)
        {
            total+=9;
        }
        else
            total=total+10-ch-1;
        ch=getchar();
        i++;
    }
    printf("%d",total+1);
}

#include<stdio.h>
int main()
{
    char ch=getchar();int i=1,total=0;
    while(ch!='\n')
    {
        ch=ch-'0';
        if(i==1)
        {
            total+=9;
        }
        else
            total=total+10-ch-1;
        ch=getchar();
        i++;
    }
    printf("%d",total+1);
}

#include<stdio.h>
int main()
{
int n,t,dig,count=0;
scanf("%d",&n);
while(n!=0)
{
dig=n%10;
count+=9-dig;
t=n;
n/=10;
}
count+=t+1;
printf("%d",count);
}

#include <stdio.h>

int main() {
    int n, count;
    count = 1;
    scanf("%d", &n);

    while (n != 1) {
        n++;
        while (n % 10 == 0) n /= 10;
        count++;
    }

    printf("%d\n", count);
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x,y;
    y=1;
    scanf("%d",&x);
    while (x!=1)
    {
        y++;
        x+=1;
        while(x%10==0)
            x/=10;
    }
    printf("%d\n",y);
    return 0;
}

#include <stdio.h>
int main()
{
    int n;
    int count=1;
    scanf("%d", &n);
    if(n==1)
    {
        printf("9");
        return 0;
    }
    else
    {
        while(n!=1)
        {
            n+=1;
            count+=1;
            //printf("%d\n",n);
            if(n%10==0)
            {
                while (n%10==0)
                {
                    n/=10;
                }
            }
        }
    }
    printf("%d", count);
    return 0;
}

#include <stdio.h>

int main()
{
    int n;int c=1;
    scanf("%d", &n);
    if(n==1){printf("9");}

    else{while(1){
        if(n==1){break;}
        n=n+1;
        if(n%10==0){
                while(1){
                    if(n%10==0){n=n/10;}
                    else{break;}
                        }
                    }
        c++;
    }
    printf("%d", c);
    }
    return 0;
}

#include <stdio.h>
int fnc(int n)
{
    int ans;
     ans=n+1;
    while(ans%10==0)
    {
        ans=ans/10;
    }
    return ans;

}

int main()
{
    int a[100],p,i,cn=1;
    scanf("%d",&p);
    i=fnc(p);
    while(i!=1)
    {
        i=fnc(i);
        cn++;
    }
    printf("%d",cn+1);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int j,rem,n,count=0,div;
    scanf("%d",&n);
    j=n;
    div=n/10;
    if(n>=0&&n<=9){
        printf("9\n");
        return 0;
    }
    while(div!=0){
        rem=j%10;
        if(rem!=1&&rem!=0){
            count=count+(9-rem);
        }
        else{
            count=count+9;
        }
        div=j/10;
        j=div;
    }
    printf("%d\n",count+1);
    return 0;
}

#include<stdio.h>
int main()
{
	long long int n,i,k,j,s;
	scanf("%I64d",&n);
	s=n;
	n=n+1;
	for(i=1;  ;i++){

	if(n%10==0)
	n=n/10;
	else
	break;}
	for(i=1;n!=1;i++)
	{
		n=n+1;
		for(k=1;  ;k++)
		{
		if(n%10==0)
		n=n/10;
		else
		break;
	}
	if(n==s)
		j=i+1;
		else
		j=i+2;
	}
	printf("%I64d",j);
	return 0;
}

#include<stdio.h>
int main()
{
    char ch=getchar();int i=1,total=0,n;
    while(ch>='0'&&ch<='9')
    {
        ch=ch-'0';
        if(i==1)
        {
            total+=9;
        }
        else
            total=total+10-ch-1;
        ch=getchar();
        i++;
    }
    printf("%d",total+1);
}

#include <stdio.h>

int main() {
	int n, result = 1, s = 0;
	scanf("%d", &n);
	while (n != 1) {
		s = 10 - n % 10;
		result += s;
		n += s;
		while (!(n % 10))
			n /= 10;
	}
	printf("%d", result);
}

#include<stdio.h>
int main()
{
    int n,c=0;
    scanf("%d",&n);
    while(n!=1)
    {
        n++;
        while(n%10==0)
            n/=10;
        c++;
    }
    printf("%d\n",c+1);
    return 0;
}

#include <stdio.h>

int main() {
	int n, c, cnt;

	scanf("%d", &n);
	c = n;
	cnt = 0;
	while (c != 1) {
		cnt++;
		c++;
		while (c % 10 == 0)
			c /= 10;
	}
	printf("%d\n", cnt + 1);
	return 0;
}

#include<stdio.h>
int main(){
    int i=0,j=2,k,l,n;

scanf("%d",&n);
n++;
while(n!=1){

        if(n%10==0){i++;
    n=n/10;}
else n++;
    j++;
    //if(n==1)break;
}
printf("%d",j-i);
return 0;
}

#include<stdio.h>

int main()
{
    int n,f=0,count=0,rem;
    scanf("%d",&n);
    while(f==0)
    {
    rem=n%10;
    count+=(10-rem);
    n+=(10-rem);
    while(n%10==0)
    {
    n/=10;
    if(n<10)
    {
    count+=9;
    f=1;
    }
    }
    }
    printf("%d",count);
    return 0;
}

#include<stdio.h>
int main()
{
     long long int n;
    long long int i=1;
    scanf("%lld",&n);
    while(n>1)
    {
        n=n+1;
        while(n%10==0)
        {
            n=n/10;
        }
        i++;
    }
    printf("%lld",i);
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int count=0;
void recur(int n){
    if(n==0||n==1) return;
    else{
        n = n+1;
        while(n%10==0){
            n=n/10;
        }
        count++;
        recur(n);
    }
}
int main(){
    int num;
    scanf("%d",&num);
    recur(num);
    printf("%d",count+1);
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i=0,j=0;
    int n;
    scanf("%d",&n);

    while(1)
    {
        if(n%10==0)
        {
            n=n/10;
            continue;
        }
        else
        {
            i=10-n%10;
            j=i+j;
            n=n+i;
            if(n>=1&&n<=10)
            {
                printf("%d",j-1+n);
                break;
            }
        }
    }
    return 0;
}

#include<stdio.h>

int check(int* a){

	int flag=0, j;
	for(j=1;j<10;j++){
		if(a[j]==0){
			flag=0;
			break;
		}
		else{
			flag=1;
		}
	}
	return flag;
}
int main(){
	long long n,temp;
	scanf("%lld",&n);
	int flag=0,count=0,i,j;
	int a[10]={0,0,0,0,0,0,0,0,0,0};
	temp=n;
	int iter=0,it=0;
	while(1){
		iter++;
		for(i=0;;i++){
			it++;
			if(check(a))
				break;
			if(it!=1 && temp%10==0){
				temp=temp/10;
				break;
			}
			count++;
			if(temp<10){
				a[temp]=1;
			}
			temp++;
		}
		//condition for flag
		flag=check(a);
		if(flag==1) break;
		if(iter==5)
			break;
	}
	printf("%lld\n", count);
}

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>

int main(){

    long long int num;
    int cnt=0,end=-1,on=0;
    scanf("%lld",&num);

   while(1){
    if(num<10){
        cnt++;
        end = num;
        cnt += 8;
        break;
    }

    while((num%10)!=0){
        cnt++;
        num++;
    }

    num = num/10;
   }
   printf("%d",cnt);
   return 0;
}

#include <stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int num=0;
	while(n!=1){
		n+=1;
		if(n%10==0){
		while(n%10==0){
		n/=10;
		}

	  }
	  num++;
	}
	num+=1;
	printf("%d",num);
}

#include<stdio.h>

int main()
{
    long int n;
    int cou=1;
    scanf("%d", &n);

    n++;
    while(1){
        if(n/10 == 0){
            cou += 9;
            break;
        }
        if(n%10 == 0){
            n /= 10;
        }
        else{
            n++;
            cou++;
        }
    }
    printf("%d", cou);

    return 0;
}

#include <stdio.h>
int main(void) {
	int n,a=1;
	scanf("%d",&n);
	if(n==1)
        a=0;
	do
    {
        n=n+1;
        a=a+1;
        while(n%10==0)
            n=n/10;
    }while(n!=1);
    printf("%d",a);
	return 0;
}

#include<stdio.h>
int main()
{
    int n,c=0;
    scanf("%d",&n);
    if(n==1)
    {
        printf("9\n");
        return 0;
    }
    while(n!=1)
    {
        n++;
        while(n%10==0)
            n/=10;
        c++;
    }
    printf("%d\n",c+10);
    return 0;
}

#include <stdio.h>

int main()
{
    int count=1,x,num;
    scanf("%d",&x);
    num=x+1;
    do
    {
        if(num%10==0)
        {
            num=num/10;
        }
        else
        {
            num=num+1;
            count++;
        }
    }while(num !=1);
    printf("%d",++count);

    return 0;
}

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int c=1;
    while(1){
        if(n==1){break;}
        n=n+1;
        if(n%10==0){
                while(1){
                    if(n%10==0){n=n/10;}
                    else{break;}
                        }
                    }
        c++;
    }
    printf("%d", c);
    return 0;
}

#include<stdio.h>
int main()
{
	long long int n,i,j=2,k;
	scanf("%I64d",&n);
	n=n+1;
	for(i=1;n!=1;i++)
	{
		if(n%10==0)
		n=n/10;
		else {
		n=n+1;
		j=j+1;}
	}
	printf("%I64d",j);
	return 0;
}

#include <stdio.h>
#include <math.h>
int main() {
	int n, result = 1, s = 0;
	scanf("%d", &n);
	n++;
	if (n % 10 && n > 10)result++;
	else while (!(n % 10))
		n /= 10;
	while(n>100)
	{
		s = 10 - n % 10;
		result += s;
		n += s;
		while (!(n % 10))
			n /= 10;
	}
	printf("%d", 8 + 9*(n/10)+result);
}

#include<stdio.h>
int main()
{
	long long int n,i,k,j;
	scanf("%I64d",&n);

	for(i=1;n!=1;i++)
	{
		n=n+1;
		for(k=1;  ;k++)
		{
		if(n%10==0)
		n=n/10;
		else
		break;
	}

		j=i+1;
	}
	printf("%I64d",j);
	return 0;
}

#include<stdio.h>
#include<conio.h>
int main(){

     int i,j,k,l,m,n;
     int length,number,tests,ans,anslist[10000],flag;
     flag=0;
     scanf("%d",&number);
     ans=1;
     j=0;
     while(1){
            number=number+1;
        while(number%10==0){
            number=number/10;

        }

        for (m=0;m<=j ;m++ )
        {
          if(anslist[m]==number){
            flag=1;
          }
        }
        if(flag==1){
            break;
        }
        anslist[j]=number;
        j++;
        ans++;
        //printf("\n%d",number);

     }
      printf("%d",ans);

      return 0;
}

#include<stdio.h>

int main()
{
    long int n;
    int cou=1;
    scanf("%d", &n);

    n++;
    while(n != 1){
        if(n%10 == 0){
            n /= 10;
        }
        else{
            n++;
            cou++;
        }
    }
    cou++;
    printf("%d", cou);

    return 0;
}

#include<stdio.h>

int main(void)
{
    long long int n, a, b, c=1, e;
    scanf("%lld", &n);

    for( ; ; ) {

        if(!(n%10))
            n /= 10;

        else if(n>9) {
            a = n%10;
            c += 10-a;
            n += 10-a;
            n /= 10;
        }
        else if(n<10) {
            c += 8;
            break;
        }

    }

    printf("%lld", c);

    return 0;
}

#include <stdio.h>
int main()
{
    long long int n, i, j, sum, count = 1;
    while(scanf("%lld", &n) != EOF)
    {
        while(n != 1)
        {
            if(n % 10 == 0)
            {
                n = n + 1;
                count++;
            }
            while(n % 10 != 0)
            {
                n = n + 1;
                count++;
            }

            while(n % 10 == 0)
            {
                n = n / 10;
            }
        }
        printf("%d\n", count);
        count = 1;
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int i=0,j=0;
    int n;
    scanf("%d",&n);

    while(1)
    {
        if(n%10==0)
        {
            n=n/10;
            continue;
        }
        else
        {
            i=10-n%10;
            j=i+1+j;
            n=n+i;
            if(n>=1||n<=10)
            {
                printf("%d",j);
                break;
            }
        }
    }
    return 0;
}

#include<stdio.h>
long long int t = 1;

void find( long long int last )
{
    //printf("tt%lld %lld ", last, t);
    if( last == 1  && t != 1 )
    {
        return;
    }

    if( last % 10 == 0 && t != 1 )
    {

        return find(last / 10);
    }

    else
    {
        t++;
        return find(last+1);
    }

}

int main()
{
    long long int n;
    scanf("%lld", &n);

    find(n);
    if( n == 1 )
    {
        t = t - 1;
    }
    printf("%lld", t);

    return 0;
}

#include<stdio.h>

int main()
{
    long long a,count;

    scanf("%lld",&a);
    count=0;
        if(a==1)
    {
        count+=9;
    }
while(a>1)
{

    count+=10-(a%10);
    a+=10-(a%10);
     while(a%10==0)
    {
        a=a/10;
    }
 if(a==1){count++;break;}
}
printf("%lld\n",count);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,c=0;
    scanf("%d",&n);
    if(n==1)
    {
        printf("9\n");
        return 0;
    }
    while(n!=1)
    {
        n++;
        while(n%10==0)
            n/=10;
        c++;
    }
    printf("%d\n",c+1);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,c = 2,input,count = 0;
    scanf("%d",&n);
    input = n+1;
    if(n<10)
    {
    while(count != 2)
    {

        if(input %10 != 0)
        {
            input++;
            c++;
           // printf("%d ",c);
           // printf("i%d \n",input);
        }
       else
       {
           while(input % 10 == 0)
           {
               input = input /10;
               // printf("i%d \n",input);
           }
           if(input == 1)
           {
               count++;
           }

          // c++;
          // printf("%d ",c);
       }
    }

    }
    else
    {
        while(input != 1)
        {
          if(input %10 != 0)
        {
            input++;
            c++;
           // printf("%d ",c);
           // printf("i%d \n",input);
        }
       else
       {
           while(input % 10 == 0)
           {
               input = input /10;
               // printf("i%d \n",input);
           }

          // c++;
          // printf("%d ",c);
       }
        }
    }
    printf("%d",c);
    return 0;

}

#include <stdio.h>

long int n;
int c;

int count(){
  if(n!=1){c = 1;}
  n++;
  while(n != 1){
    while(n%10 == 0){
      n= n/10;
    }
    //printf("%li\n",n);
    c++;
    if(n == 1){
      break;
    }
    n++;
  }
  return 0;
}

int main(void) {

  scanf("%li", &n);

  count();
  printf("%d\n", c);

  return 0;
}

#include<stdio.h>
int main()
{
    long long int n,k=1;
    scanf("%lld",&n);

    while(1)
    {
        n=n+1;
        if(n%10==0){
            while(n%10==0)
                n=n/10;}
        ++k;
        if(n==1)
            break;
    }
    printf("%lld\n",k);
    return 0;
}

#include <stdio.h>

int main()
{
    long long int n, i, j, c=1, a;
    scanf("%lld",&n);
    a=n;
    if(n==9){printf("9");return 0;}
    for(i=0; ;i++)
    {
        n++;
        for(;n%10==0;)
        {
            n=n/10;
        }
        if(n==a)
        {
            break;
        }
        c++;
        if(n==1)
        {
            break;
        }
    }
    printf("%lld\n",c);
}

#include <stdio.h>
int main () {
    int n, ans = 0;
    scanf ("%d", &n);

    while (n != 1) {
        n ++;
        while (!(n % 10)) {
            n /= 10;
        }
        ans ++;
    }
    printf ("%d\n", ans + 1);
    return 0;
}

#include <stdio.h>

int main()
{
    int count=1,x,num;
    scanf("%d",&x);

    num=x+1;
    do
    {
        if(num%10==0)
        {
            num=num/10;
        }
        else
        {

            num=num+1;
            count++;
        }
    }while(num !=1);
    if(x<10)
    {
      count=8;
    }
    printf("%d",++count);

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
main()
{
	long int n,sum=0;
	scanf("%ld",&n);
	int r=n%10;
	sum+=(10-r);
	n/=10;
	if(n==0 && r==1)
	{
		printf("%ld",sum);
		exit(0);
	}
	while(n)
	{
		int r=n%10;
		r++;
		sum+=(10-r);
		n/=10;
	}
printf("%ld",sum+1);
}

#include <stdio.h>
int main()
{
    int count=1,x,num;
    scanf("%d",&x);
    if(x==1)
        count=0;
    num=x+1;
    do
    {
        if(num%10==0)
        {
            num=num/10;
        }
        else
        {
            num=num+1;
            count++;
        }
    }while(num !=1);
    printf("%d",++count);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int f(int x){
	int f,i=0,y=x+1;
	while (y%(long)pow(10,i)==0){
		i++;
	}
	f=y/(long)pow(10,i-1);
	return f;
}
int main() {
	int a[1000],count=1,kq,x,i=0,j,kt=1;
	scanf("%d",&x);
	kq=x;
	if (x==10) count=19;
	else if (x<10) count=9;
	else{
	while (kq>10){
		kq=f(kq);
		a[i]=kq;
		for (j=0;j<i;j++){
			if (a[i]==a[j]){
				kt=0;
				break;
			}
		}
		if (kt==1) count++;
		i++;
	}
	count+=8;
	}
	printf("%d",count);
	return 0;
}

#include<stdio.h>
int main()
{
    long long int n,c=1;
    scanf("%I64d",&n);
    while(n>1)
    {
        n=n+1;
        c++;
        while(n%10==0)
        {
            n=n/10;
        }
    }
    printf("%I64d",c);
}

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int count=1;
    if(n==1)
        printf("9\n");
    else
    {
        while(n!=1)
        {
            n++;
            while(n%10==0)
            {
                n=n/10;
            }
            count++;
        }
        printf("%d",count);
    }

    return 0;
}


In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted.  If there is no valid common subsequence, output 0.

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define MAX(A,B) (((A) > (B)) ? (A) : (B))

char s1[105];
char s2[105];
char virus[105];
int fail[105];

int dp[105][105][105];
int seq[105][105][105][3];
int print[105][105][105];
int n, m, p;

int solve(int pos1, int pos2, int pos3) {
    if (pos3 >= p) {
        return -INF;
    }

    if (pos1 >= n || pos2 >= m) {
        return 0;
    }

    if (seq[pos1][pos2][pos3][0] != -1) {
        return dp[pos1][pos2][pos3];
    }

    int aux, aux2, aux3;
    int way1, way2, way3;

    aux = aux2 = aux3 = -INF;
    way1 = way2 = way3 = 0;
    if (s1[pos1] == s2[pos2]) {
        if (s1[pos1] == virus[pos3]) {
            print[pos1][pos2][pos3] = 1;
            aux = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
            way1 = pos1 + 1;
            way2 = pos2 + 1;
            way3 = pos3 + 1;
        } else {
            way1 = pos1;
            way2 = pos2;
            if (pos3 != 0) {
                if (virus[fail[pos3 - 1]] == s1[pos1]) {
                    aux = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1] + 1);
                    print[pos1][pos2][pos3] = 1;
                    way1++;
                    way2++;
                    way3 = fail[pos3 - 1] + 1;
                } else {
                    aux = solve(pos1, pos2, fail[pos3 - 1]);
                    way3 = fail[pos3 - 1];
                }
            } else {
                aux = 1 + solve(pos1 + 1, pos2 + 1, 0);
                print[pos1][pos2][0] = 1;
                way1++;
                way2++;
                way3 = 0;
            }
        }
    }

    dp[pos1][pos2][pos3] = aux;
    seq[pos1][pos2][pos3][0] = way1;
    seq[pos1][pos2][pos3][1] = way2;
    seq[pos1][pos2][pos3][2] = way3;

    aux2 = solve(pos1 + 1, pos2, pos3);
    aux3 = solve(pos1, pos2 + 1, pos3);

    if (aux2 > dp[pos1][pos2][pos3]) {
        dp[pos1][pos2][pos3] = aux2;
        print[pos1][pos2][pos3] = 0;
        seq[pos1][pos2][pos3][0] = pos1 + 1;
        seq[pos1][pos2][pos3][1] = pos2;
        seq[pos1][pos2][pos3][2] = pos3;
    }
    if (aux3 > dp[pos1][pos2][pos3]) {
        dp[pos1][pos2][pos3] = aux3;
        print[pos1][pos2][pos3] = 0;
        seq[pos1][pos2][pos3][0] = pos1;
        seq[pos1][pos2][pos3][1] = pos2 + 1;
        seq[pos1][pos2][pos3][2] = pos3;
    }

    return dp[pos1][pos2][pos3];
}

void build_fail(void) {
    int len;
    int i;

    fail[0] = 0;
    i = 1;
    len = 0;

    while(i < p) {
        if (virus[i] == virus[len]) {
            len++;
            fail[i++] = len;
        } else {
            if (len != 0) {
                len = fail[len - 1];
            } else {
                fail[i++] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int i, j, k;
    int res;

    int w1, w2, w3;

    scanf(" %s %s %s", s1, s2, virus);

    n = strlen(s1);
    m = strlen(s2);
    p = strlen(virus);

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            for (k = 0; k < p; k++) {
                seq[i][j][k][0] = -1;
                print[i][j][k] = 0;
            }
        }
    }

    build_fail();
    res = solve(0, 0, 0);

    if (res) {
        i = 0;
        j = 0;
        k = 0;
        while(i != n && j != m) {
            if (print[i][j][k]) {
                printf("%c", s1[i]);
            }
            w1 = seq[i][j][k][0];
            w2 = seq[i][j][k][1];
            w3 = seq[i][j][k][2];
            i = w1;
            j = w2;
            k = w3;
        }
        printf("\n");
    } else {
        printf("0\n");
    }

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>

#define MAX_N (100)
#define TAKE (1)
#define UP   (2)
#define DOWN (3)

char s1[MAX_N+1];
char s2[MAX_N+1];
char v[MAX_N+1];
int vlen;
int s1len;
int s2len;

int f[MAX_N+1];
int dp[MAX_N+1][MAX_N+1][MAX_N+1];
int sn[MAX_N+1][MAX_N+1][MAX_N+1];

int max(int x, int y) { return x > y ? x : y; }

int trans(int k, char c) {
  while ( k != -1 && v[k] != c )
    k = f[k];
  return k+1;
}

void build_fail() {
  int i;

  f[0] = -1;
  for ( i=1; i <= vlen; ++i )
    f[i] = trans(f[i-1], v[i-1]);
}

void build_dp() {
  int i,j,k,kn,x,y,z;

  for ( i=0; i <= s1len; ++i )
    for ( j=0; j <= s2len; ++j )
      dp[i][j][vlen] = INT_MIN;
  for ( i=s1len-1; i >= 0; --i ) {
    for ( j=s2len-1; j >= 0; --j ) {
      for ( k=0; k <= vlen; ++k ) {
	kn = k == vlen ? k : trans(k, s1[i]);
	x = s1[i] == s2[j] ? 1 + dp[i+1][j+1][kn] : INT_MIN;
	y = dp[i+1][j][k];
	z = dp[i][j+1][k];
	dp[i][j][k] = max(max(x, y), z);
	if ( x >= y && x >= z ) sn[i][j][k] = TAKE;
	else if ( y >= x && y >= z ) sn[i][j][k] = UP;
	else sn[i][j][k] = DOWN;
      }
    }
  }
}

char * get_soln(char * buf) {
  int i,j,k,ix;

  for ( i=j=k=ix=0; sn[i][j][k]; ) {
    switch ( sn[i][j][k] ) {
      case TAKE:
        buf[ix++] = s1[i];
	k = k == vlen ? k : trans(k, s1[i]);
	i += 1, j += 1;
	break;
      case UP:
        i += 1;
	break;
      case DOWN:
        j += 1;
	break;
    }
  }
  buf[ix] = '\0';
  return buf;
}

int main() {
  char buf[MAX_N+1];

  gets(s1);
  gets(s2);
  gets(v);
  vlen = strlen(v);
  s1len = strlen(s1);
  s2len = strlen(s2);
  build_fail();
  build_dp();
  if ( dp[0][0][0] )
    printf("%s\n", get_soln(buf));
  else
    printf("0\n");
  return EXIT_SUCCESS;
}

#include <stdio.h>
#include <string.h>
char s1[101] = {0},s2[101] = {0},vir[101] = {0},ans[101][101][101] = {0},ansans[101] = {0},maxans = 0;
int f[101][101] = {0},len1,len2,lenv;
int cmp(char *sa,char *sb)
{
    int i,j,cnt = 0,maxcnt = 0;
    for(i=0;sa[i];i++)
    {
        if(sa[i] == sb[0])
        {
            cnt = 0;
            for(j=0;sb[j];j++)
            {
                if(sa[i+j] == sb[j]) cnt++;
                else break;
            }
            maxcnt = maxcnt>cnt?maxcnt:cnt;
        }
    }
    return maxcnt;
}
int work(char c)
{
    short swi = 0;
    int i,j;
    for(i=1;i<=len1;i++)
    {
        for(j=1;j<=len2;j++)
        {
            if(s1[i-1] == s2[j-1]&&s1[i-1] != c&&s2[j-1] != c)
            {
                f[i][j] = f[i-1][j-1] + 1;
                memcpy(ans[i][j],ans[i-1][j-1],sizeof(ans[i][j]));
                ans[i][j][f[i][j]-1] = s1[i-1];
                if(cmp(ans[i][j],vir) != lenv) continue;
            }
            if(f[i-1][j]>f[i][j-1])
            {
                memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                f[i][j] = f[i-1][j];
            }
            else if(f[i-1][j]<f[i][j-1])
            {
                memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                f[i][j] = f[i][j-1];
            }
            else
            {
                if(cmp(ans[i-1][j],vir)>cmp(ans[i][j-1],vir))
                {
                    memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                    f[i][j] = f[i][j-1];
                }
                else
                {
                    memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                    f[i][j] = f[i-1][j];
                }
            }
        }
    }
    if(f[len1][len2]>maxans)
    {
        memcpy(ansans,ans[len1][len2],sizeof(ansans));
        maxans = f[len1][len2];
    }
}
int main()
{
    int i;
    scanf("%s%s%s",s1,s2,vir);
    len1 = strlen(s1);
    len2 = strlen(s2);
    lenv = strlen(vir);
    work('a');
    for(i=0;i<lenv;i++) work(vir[i]);
    if(maxans) printf("%s",ansans);
    else printf("0");
    return 0;
}

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int const MOD = 1000000007;

typedef long long int lli;

#define fo3(i,a,b) for(i=(int)(a);i<=(int)(b);i++)
#define abso(x)    (((x)>=0)?(x):(-(x)))
#define in32(x)    scanf("%d",&(x))
#define out32(x)   printf("%d\n",(x))
#define in64(x)    scanf("%I64d",&(x))
#define out64(x)   printf("%I64d\n",(x))
#define instr(x)   scanf("%s",(x));
#define outstr(x)  printf("%s\n", (x));

#define MAX 105
#define oo 987654321
#define SENT -1
#define UP   0
#define LEFT 1
#define DIAG 2

int len1, len2, len3;
int memo[MAX][MAX][MAX];
int move[MAX][MAX][MAX];
char word1[MAX];
char word2[MAX];
char word3[MAX];
int ** dfa;

void kmp() {
    int R=26,X=0,c,j;
    dfa = calloc(len3,sizeof(int*));
    fo3(j,0,len3-1)
        dfa[j] = calloc(R,sizeof(int));
    dfa[0][word3[0]-'A'] = 1;
    for (j=1; j<len3; j++) {
        for (c=0; c<R; c++)
            dfa[j][c] = dfa[X][c];
        dfa[j][word3[j]-'A']=j+1;
        X = dfa[X][word3[j]-'A'];
    }
}

int rec(int p1, int p2, int p3) {
    if (p3 == len3)
        return -oo;
    if (word1[p1] == '\0' || word2[p2] == '\0')
        return 0;
    if (memo[p1][p2][p3] != SENT)
        return memo[p1][p2][p3];
    memo[p1][p2][p3] = rec(p1+1, p2, p3);
    move[p1][p2][p3] = UP;
    int tmp = rec(p1, p2+1, p3);
    if (tmp > memo[p1][p2][p3]) {
        memo[p1][p2][p3] = tmp;
        move[p1][p2][p3] = LEFT;
    }
    if (word1[p1] == word2[p2]) {
        int np3 = dfa[p3][word1[p1]-'A'];
        int tmp = rec(p1 + 1, p2 + 1, np3) + 1;
        if (tmp > memo[p1][p2][p3]) {
            memo[p1][p2][p3] = tmp;
            move[p1][p2][p3] = DIAG;
        }
    }
    return memo[p1][p2][p3];
}

int main(void) {
    int i,j,k,ans;
    instr(word1);
    instr(word2);
    instr(word3);
    len1=strlen(word1);
    len2=strlen(word2);
    len3=strlen(word3);
    kmp();
    fo3(i,0,len1)
        fo3(j,0,len2)
            fo3(k,0,len3)
                memo[i][j][k] = SENT;
    ans=rec(0,0,0);
    if (ans) {
        char buff[MAX];
        int cur = 0;
        int p1 = 0;
        int p2 = 0;
        int p3 = 0;
        while (p1 != len1 && p2 != len2) {
            if (move[p1][p2][p3] == DIAG) {
                buff[cur++] = word1[p1];
                p3=dfa[p3][word1[p1]-'A'];
                p1++;
                p2++;
            } else if (move[p1][p2][p3] == LEFT) {
                p2++;
            } else {
                p1++;
            }
        }
        buff[cur] = '\0';
        outstr(buff);
    } else out32(ans);
    return 0;
}

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define MAX(A,B) (((A) > (B)) ? (A) : (B))

char s1[105];
char s2[105];
char virus[105];
int fail[105];

int dp[105][105][105];
int seq[105][105][105];
int n, m, p;

int solve(int pos1, int pos2, int pos3) {
    int aux1, aux2, aux3, aux4;

    if (pos3 >= p) {
        return -INF;
    }

    if (pos1 >= n || pos2 >= m) {
        return 0;
    }

    if (dp[pos1][pos2][pos3] != -1) {
        return dp[pos1][pos2][pos3];
    }

    aux1 = aux2 = -INF;
    if (s1[pos1] == s2[pos2]) {
        if (virus[pos3] == s1[pos1]) {
            aux1 = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
        } else {
            if (pos3 != 0) {
                aux2 = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1]);
            } else {
                aux2 = 1 + solve(pos1 + 1, pos2 + 1, 0);
            }
        }
    }
    aux3 = solve(pos1 + 1, pos2, pos3);
    aux4 = solve(pos1, pos2 + 1, pos3);

    dp[pos1][pos2][pos3] = -INF;
    if (dp[pos1][pos2][pos3] < aux1) {
        seq[pos1][pos2][pos3] = 1;
        dp[pos1][pos2][pos3] = aux1;
    }
    if (dp[pos1][pos2][pos3] < aux2) {
        seq[pos1][pos2][pos3] = 2;
        dp[pos1][pos2][pos3] = aux2;
    }
    if (dp[pos1][pos2][pos3] < aux3) {
        seq[pos1][pos2][pos3] = 3;
        dp[pos1][pos2][pos3] = aux3;
    }
    if (dp[pos1][pos2][pos3] < aux4) {
        seq[pos1][pos2][pos3] = 4;
        dp[pos1][pos2][pos3] = aux4;
    }

    return dp[pos1][pos2][pos3];
}

void build_fail(int m) {
    int len;
    int i;

    fail[0] = 0;
    len = 0;
    i = 1;

    while(i < m) {
        if (virus[i] == virus[len]) {
            len++;
            fail[i++] = len;
        } else {
            if (len != 0) {
                len = fail[len - 1];
            } else {
                fail[i++] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int i, j, k;
    int res;

    scanf(" %s %s %s", s1, s2, virus);

    n = strlen(s1);
    m = strlen(s2);
    p = strlen(virus);

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            for (k = 0; k < p; k++) {
                dp[i][j][k] = -1;
            }
        }
    }

    build_fail(p);
    res = solve(0, 0, 0);

    /*for (i = 0; i < p; i++) {
        printf("i = %d, fail[i] = %d\n", i, fail[i]);
    } */

    i = 0;
    j = 0;
    k = 0;
    while(i != n && j != m) {
        switch(seq[i][j][k]) {
            case 1:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                i++;
                j++;
                k++;
                break;
            case 2:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                if (s1[i] == virus[k]) {
                    k++;
                } else {
                    if (k != 0) {
                        k = fail[k - 1];
                    }
                }
                i++;
                j++;
                break;
            case 3:
                i++;
                break;
            case 4:
                j++;
                break;
        }
    }
    printf("\n");

    if (res == 0) {
        printf("0\n");
    }

    /*printf("%d\n", res); */

    return 0;
}

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define MAX(A,B) (((A) > (B)) ? (A) : (B))

char s1[105];
char s2[105];
char virus[105];
int fail[105];

int dp[105][105][105];
int seq[105][105][105];
int n, m, p;

int solve(int pos1, int pos2, int pos3) {
    int aux1, aux2, aux3, aux4;

    if (pos3 >= p) {
        return -INF;
    }

    if (pos1 >= n || pos2 >= m) {
        return 0;
    }

    if (dp[pos1][pos2][pos3] != -1) {
        return dp[pos1][pos2][pos3];
    }

    aux1 = aux2 = -INF;
    if (s1[pos1] == s2[pos2]) {
        if (virus[pos3] == s1[pos1]) {
            aux1 = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
        } else {
            if (pos3 != 0) {
                aux2 = 1 + solve(pos1 + 1, pos2 + 1, fail[pos3 - 1]);
            } else {
                aux2 = 1 + solve(pos1 + 1, pos2 + 1, 0);
            }
        }
    }
    aux3 = solve(pos1 + 1, pos2, pos3);
    aux4 = solve(pos1, pos2 + 1, pos3);

    dp[pos1][pos2][pos3] = -INF;
    if (dp[pos1][pos2][pos3] < aux1) {
        seq[pos1][pos2][pos3] = 1;
        dp[pos1][pos2][pos3] = aux1;
    }
    if (dp[pos1][pos2][pos3] < aux2) {
        seq[pos1][pos2][pos3] = 2;
        dp[pos1][pos2][pos3] = aux2;
    }
    if (dp[pos1][pos2][pos3] < aux3) {
        seq[pos1][pos2][pos3] = 3;
        dp[pos1][pos2][pos3] = aux3;
    }
    if (dp[pos1][pos2][pos3] < aux4) {
        seq[pos1][pos2][pos3] = 4;
        dp[pos1][pos2][pos3] = aux4;
    }

    return dp[pos1][pos2][pos3];
}

void build_fail(int m) {
    int len;
    int i;

    fail[0] = 0;
    len = 0;
    i = 1;

    while(i < m) {
        if (virus[i] == virus[len]) {
            len++;
            fail[i++] = len;
        } else {
            if (len != 0) {
                len = fail[len - 1];
            } else {
                fail[i++] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int i, j, k;
    int res;

    scanf(" %s %s %s", s1, s2, virus);

    n = strlen(s1);
    m = strlen(s2);
    p = strlen(virus);

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            for (k = 0; k < p; k++) {
                dp[i][j][k] = -1;
            }
        }
    }

    build_fail(p);
    res = solve(0, 0, 0);

    /*for (i = 0; i < p; i++) {
        printf("i = %d, fail[i] = %d\n", i, fail[i]);
    } */

    i = 0;
    j = 0;
    k = 0;
    while(i != n && j != m) {
        switch(seq[i][j][k]) {
            case 1:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                i++;
                j++;
                k++;
                break;
            case 2:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                if (s1[i] == virus[k]) {
                    k++;
                } else {
                    if (k != 0) {
                        k = fail[k - 1];
                    }
                }
                i++;
                j++;
                break;
            case 3:
                i++;
                break;
            case 4:
                j++;
                break;
        }
    }

    if (res == 0) {
        printf("0\n");
    } else {
        printf("\n");
    }

    /*printf("%d\n", res); */

    return 0;
}

#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
#define MAX(A,B) (((A) > (B)) ? (A) : (B))

char s1[105];
char s2[105];
char virus[105];
int fail[105];

int dp[105][105][105];
int seq[105][105][105];
int n, m, p;

int solve(int pos1, int pos2, int pos3) {
    int aux1, aux2, aux3, aux4, aux5;

    if (pos3 >= p) {
        return -INF;
    }

    if (pos1 >= n || pos2 >= m) {
        return 0;
    }

    if (dp[pos1][pos2][pos3] != -1) {
        return dp[pos1][pos2][pos3];
    }

    aux1 = aux2 = -INF;
    aux5 = -INF;
    if (s1[pos1] == s2[pos2]) {
        if (virus[pos3] == s1[pos1]) {
            aux1 = 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1);
        } else {
            if (pos3 != 0) {
                aux5 = solve(pos1, pos2, fail[pos3 - 1]);
            } else {
                aux2 = 1 + solve(pos1 + 1, pos2 + 1, 0);
            }
        }
    }
    aux3 = solve(pos1 + 1, pos2, pos3);
    aux4 = solve(pos1, pos2 + 1, pos3);

    dp[pos1][pos2][pos3] = -INF;
    if (dp[pos1][pos2][pos3] < aux1) {
        seq[pos1][pos2][pos3] = 1;
        dp[pos1][pos2][pos3] = aux1;
    }
    if (dp[pos1][pos2][pos3] < aux2) {
        seq[pos1][pos2][pos3] = 2;
        dp[pos1][pos2][pos3] = aux2;
    }
    if (dp[pos1][pos2][pos3] < aux3) {
        seq[pos1][pos2][pos3] = 3;
        dp[pos1][pos2][pos3] = aux3;
    }
    if (dp[pos1][pos2][pos3] < aux4) {
        seq[pos1][pos2][pos3] = 4;
        dp[pos1][pos2][pos3] = aux4;
    }
    if (dp[pos1][pos2][pos3] < aux5) {
        seq[pos1][pos2][pos3] = 5;
        dp[pos1][pos2][pos3] = aux5;
    }

    return dp[pos1][pos2][pos3];
}

void build_fail(int m) {
    int len;
    int i;

    fail[0] = 0;
    len = 0;
    i = 1;

    while(i < m) {
        if (virus[i] == virus[len]) {
            len++;
            fail[i++] = len;
        } else {
            if (len != 0) {
                len = fail[len - 1];
            } else {
                fail[i++] = 0;
            }
        }
    }
    return;
}

int main(void) {
    int i, j, k;
    int res;

    scanf(" %s %s %s", s1, s2, virus);

    n = strlen(s1);
    m = strlen(s2);
    p = strlen(virus);

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            for (k = 0; k < p; k++) {
                dp[i][j][k] = -1;
            }
        }
    }

    build_fail(p);
    res = solve(0, 0, 0);

    /*for (i = 0; i < p; i++) {
        printf("i = %d, fail[i] = %d\n", i, fail[i]);
    } */

    i = 0;
    j = 0;
    k = 0;
    while(i != n && j != m && k < p) {
        switch(seq[i][j][k]) {
            case 1:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                i++;
                j++;
                k++;
                break;
            case 2:
                /*printf("printing i = %d\n", i); */
                printf("%c", s1[i]);
                i++;
                j++;
                break;
            case 3:
                i++;
                break;
            case 4:
                j++;
                break;
            case 5:
                if (k != 0) {
                    k = fail[k - 1];
                }
                break;
        }
    }

    if (res == 0) {
        printf("0\n");
    } else {
        printf("\n");
    }

    /*printf("%d\n", res); */

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>

#define MAX_N (100)
#define TAKE (1)
#define UP   (2)
#define DOWN (3)

char s1[MAX_N+1];
char s2[MAX_N+1];
char v[MAX_N+1];
int vlen;
int s1len;
int s2len;

int f[MAX_N+1];
int dp[MAX_N+1][MAX_N+1][MAX_N+1];
int sn[MAX_N+1][MAX_N+1][MAX_N+1];

int max(int x, int y) { return x > y ? x : y; }

void build_fail() {
  int i,j;

  f[0] = 0;
  for ( i=1; v[i-1]; ++i ) {
    for ( j=i-1; j && v[f[j]] != v[i-1]; j=f[j] );
    f[i] = j ? f[j]+1 : 0;
  }
}

int fail(int k, char c) {
  int i;

  for ( i=k; i && v[f[i]] != c; i=f[i] );
  return i + (v[f[i]] == c);
}

void build_dp() {
  int i,j,k,kn,x,y,z;

  for ( i=0; i <= s1len; ++i )
    for ( j=0; j <= s2len; ++j )
      dp[i][j][vlen] = INT_MIN;
  for ( i=s1len-1; i >= 0; --i ) {
    for ( j=s2len-1; j >= 0; --j ) {
      for ( k=0; k <= vlen; ++k ) {
	kn = k == vlen ? k : (s1[i] == v[k] ? k+1 : fail(k, s1[i]));
	x = s1[i] == s2[j] ? 1 + dp[i+1][j+1][kn] : INT_MIN;
	y = dp[i+1][j][k];
	z = dp[i][j+1][k];
	dp[i][j][k] = max(max(x, y), z);
	if ( x >= y && x >= z ) sn[i][j][k] = TAKE;
	else if ( y >= x && y >= z ) sn[i][j][k] = UP;
	else sn[i][j][k] = DOWN;
      }
    }
  }
}

char * get_soln(char * buf) {
  int i,j,k,ix;

  for ( i=j=k=ix=0; sn[i][j][k]; ) {
    switch ( sn[i][j][k] ) {
      case TAKE:
        buf[ix++] = s1[i];
	k = k == vlen ? k : (s1[i] == v[k] ? k+1 : fail(k, s1[i]));
	i += 1, j += 1;
	break;
      case UP:
        i += 1;
	break;
      case DOWN:
        j += 1;
	break;
    }
  }
  buf[ix] = '\0';
  return buf;
}

int main() {
  char buf[MAX_N+1];

  gets(s1);
  gets(s2);
  gets(v);
  vlen = strlen(v);
  s1len = strlen(s1);
  s2len = strlen(s2);
  build_fail();
  build_dp();
  if ( dp[0][0][0] )
    printf("%s\n", get_soln(buf));
  else
    printf("0\n");
  return EXIT_SUCCESS;
}

#include <stdio.h>
#include <string.h>
char s1[101] = {0},s2[101] = {0},vir[101] = {0},ans[101][101][101] = {0},ansans[101] = {0},maxans = 0;
int f[101][101] = {0},len1,len2,lenv;
int cmp(char *sa,char *sb)
{
    int i,cnt = 0;
    for(i=0;sa[i]&&sb[i];i++) if(sa[i] == sb[i]) cnt++;
    return cnt;
}
int work(char c)
{
    short swi = 0;
    int i,j;
    for(i=1;i<=len1;i++)
    {
        for(j=1;j<=len2;j++)
        {
            if(s1[i-1] == s2[j-1])
            {
                if(s1[i-1]!=c&&s2[j-1]!=c) if(!swi)
                {
                    swi = 1;
                    continue;
                }
                f[i][j] = f[i-1][j-1] + 1;
                memcpy(ans[i][j],ans[i-1][j-1],sizeof(ans[i][j]));
                ans[i][j][f[i][j]-1] = s1[i-1];
                if(cmp(ans[i][j],vir) != lenv) continue;
            }
            if(f[i-1][j]>f[i][j-1])
            {
                memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                f[i][j] = f[i-1][j];
            }
            else if(f[i-1][j]<f[i][j-1])
            {
                memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                f[i][j] = f[i][j-1];
            }
            else
            {
                if(cmp(ans[i-1][j],vir)>cmp(ans[i][j-1],vir))
                {
                    memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                    f[i][j] = f[i][j-1];
                }
                else
                {
                    memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                    f[i][j] = f[i-1][j];
                }
            }
        }
    }
    if(f[len1][len2]>maxans)
    {
        memcpy(ansans,ans[len1][len2],sizeof(ansans));
        maxans = f[len1][len2];
    }
}
int main()
{
    int i;
    scanf("%s%s%s",s1,s2,vir);
    len1 = strlen(s1);
    len2 = strlen(s2);
    lenv = strlen(vir);
    work('a');
    for(i=0;i<lenv;i++) work(vir[i]);
    if(maxans) printf("%s",ansans);
    else printf("0");
    return 0;
}

#include <stdio.h>
#include <string.h>
char s1[101] = {0},s2[101] = {0},vir[101] = {0},ans[101][101][101] = {0},ansans[101] = {0},maxans = 0;
int f[101][101] = {0},len1,len2,lenv;
int cmp(char *sa,char *sb)
{
    int i,cnt = 0;
    for(i=0;sa[i]&&sb[i];i++) if(sa[i] == sb[i]) cnt++;
    return cnt;
}
int work(char c)
{
    int i,j;
    for(i=1;i<=len1;i++)
    {
        for(j=1;j<=len2;j++)
        {
            if(s1[i-1] == s2[j-1]&&s1[i-1]!=c&&s2[j-1]!=c)
            {
                f[i][j] = f[i-1][j-1] + 1;
                memcpy(ans[i][j],ans[i-1][j-1],sizeof(ans[i][j]));
                ans[i][j][f[i][j]-1] = s1[i-1];
                if(cmp(ans[i][j],vir) != lenv) continue;
            }
            if(f[i-1][j]>f[i][j-1])
            {
                memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                f[i][j] = f[i-1][j];
            }
            else if(f[i-1][j]<f[i][j-1])
            {
                memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                f[i][j] = f[i][j-1];
            }
            else
            {
                if(cmp(ans[i-1][j],vir)>cmp(ans[i][j-1],vir))
                {
                    memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                    f[i][j] = f[i][j-1];
                }
                else
                {
                    memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                    f[i][j] = f[i-1][j];
                }
            }
        }
    }
    if(f[len1][len2]>maxans)
    {
        memcpy(ansans,ans[len1][len2],sizeof(ansans));
        maxans = f[len1][len2];
    }
}
int main()
{
    int i;
    scanf("%s%s%s",s1,s2,vir);
    len1 = strlen(s1);
    len2 = strlen(s2);
    lenv = strlen(vir);
    work('a');
    for(i=0;i<lenv;i++) work(vir[i]);
    if(maxans) printf("%s",ansans);
    else printf("0");
    return 0;
}

#include <stdio.h>
#include <string.h>
char s1[101] = {0},s2[101] = {0},vir[101] = {0},ans[101][101][101] = {0},ansans[101] = {0},maxans = 0;
int f[101][101] = {0},len1,len2,lenv;
int cmp(char *sa,char *sb)
{
    int i,j,cnt = 0;
    for(i=0;sa[i];i++)
    {
        if(sa[i] == sb[0])
        {
            for(j=0;sb[j];j++)
            {
                if(sa[i+j] == sb[j]) cnt++;
            }
        }
    }
    return cnt;
}
int work(char c)
{
    short swi = 0;
    int i,j;
    for(i=1;i<=len1;i++)
    {
        for(j=1;j<=len2;j++)
        {
            if(s1[i-1] == s2[j-1]&&s1[i-1] != c&&s2[j-1] != c)
            {
                f[i][j] = f[i-1][j-1] + 1;
                memcpy(ans[i][j],ans[i-1][j-1],sizeof(ans[i][j]));
                ans[i][j][f[i][j]-1] = s1[i-1];
                if(cmp(ans[i][j],vir) != lenv) continue;
            }
            if(f[i-1][j]>f[i][j-1])
            {
                memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                f[i][j] = f[i-1][j];
            }
            else if(f[i-1][j]<f[i][j-1])
            {
                memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                f[i][j] = f[i][j-1];
            }
            else
            {
                if(cmp(ans[i-1][j],vir)>cmp(ans[i][j-1],vir))
                {
                    memcpy(ans[i][j],ans[i][j-1],sizeof(ans[i][j]));
                    f[i][j] = f[i][j-1];
                }
                else
                {
                    memcpy(ans[i][j],ans[i-1][j],sizeof(ans[i][j]));
                    f[i][j] = f[i-1][j];
                }
            }
        }
    }
    if(f[len1][len2]>maxans)
    {
        memcpy(ansans,ans[len1][len2],sizeof(ansans));
        maxans = f[len1][len2];
    }
}
int main()
{
    int i;
    scanf("%s%s%s",s1,s2,vir);
    len1 = strlen(s1);
    len2 = strlen(s2);
    lenv = strlen(vir);
    work('a');
    for(i=0;i<lenv;i++) work(vir[i]);
    if(maxans) printf("%s",ansans);
    else printf("0");
    return 0;
}


All bus tickets in Berland have their numbers. A number consists of $$$n$$$ digits ($$$n$$$ is even). Only $$$k$$$ decimal digits $$$d_1, d_2, \dots, d_k$$$ can be used to form ticket numbers. If $$$0$$$ is among these digits, then numbers may have leading zeroes. For example, if $$$n = 4$$$ and only digits $$$0$$$ and $$$4$$$ can be used, then $$$0000$$$, $$$4004$$$, $$$4440$$$ are valid ticket numbers, and $$$0002$$$, $$$00$$$, $$$44443$$$ are not.A ticket is lucky if the sum of first $$$n / 2$$$ digits is equal to the sum of remaining $$$n / 2$$$ digits. Calculate the number of different lucky tickets in Berland. Since the answer may be big, print it modulo $$$998244353$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5, 1 \le k \le 10)$$$ — the number of digits in each ticket number, and the number of different decimal digits that may be used. $$$n$$$ is even. The second line contains a sequence of pairwise distinct integers $$$d_1, d_2, \dots, d_k$$$ $$$(0 \le d_i \le 9)$$$ — the digits that may be used in ticket numbers. The digits are given in arbitrary order.

Print the number of lucky ticket numbers, taken modulo $$$998244353$$$.

NoteIn the first example there are $$$6$$$ lucky ticket numbers: $$$1111$$$, $$$1818$$$, $$$1881$$$, $$$8118$$$, $$$8181$$$ and $$$8888$$$.There is only one ticket number in the second example, it consists of $$$20$$$ digits $$$6$$$. This ticket number is lucky, so the answer is $$$1$$$.

/* practice with Dukkha */
#include <stdio.h>

#define MD	998244353
#define N_	(1 << 20)	/* N_ = pow2(ceil(log2(N * 9 + 1))) */

long long ww[21], ww_[21];

long long power(int a, int k) {
	long long p;

	if (k == 0)
		return 1;
	p = power(a, k / 2);
	p = p * p % MD;
	if (k % 2)
		p = p * a % MD;
	return p;
}

void init() {
	int h;

	for (h = 0; h <= 20; h++) {
		ww[h] = power(3, (MD - 1) >> h);
		ww_[h] = power(3, MD - 1 - ((MD - 1) >> h));
	}
}

void ntt(int *aa, int n, int inverse) {
	int h, i, j, b, l, r, u, v, tmp;
	long long w, w_;

	for (i = 1, j = 0; i < n; i++) {
		b = n;
		do
			j ^= b >>= 1;
		while ((j & b) == 0);
		if (i < j)
			tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	for (h = 0; (b = 1 << h) < n; h++) {
		w_ = inverse ? ww_[h + 1] : ww[h + 1];
		for (i = 0; i < n; i += b * 2) {
			w = 1;
			for (j = 0; j < b; j++) {
				l = i + j, r = l + b;
				u = aa[l], v = aa[r] * w % MD;
				if ((aa[l] = u + v) >= MD)
					aa[l] -= MD;
				if ((aa[r] = u - v) < 0)
					aa[r] += MD;
				w = w * w_ % MD;
			}
		}
	}
}

int main() {
	static int aa[N_];
	int n, n_, k, i;
	long long v, a, ans;

	init();
	scanf("%d%d", &n, &k), n /= 2;
	n_ = 1;
	while (n_ < n * 9 + 1)
		n_ *= 2;
	while (k--) {
		int d;

		scanf("%d", &d);
		aa[d] = 1;
	}
	ntt(aa, n_, 0);
	for (i = 0; i < n_; i++)
		aa[i] = power(aa[i], n);
	ntt(aa, n_, 1);
	v = power(n_, MD - 2);
	for (i = 0; i < n_; i++)
		aa[i] = aa[i] * v % MD;
	ans = 0;
	for (i = 0; i <= n * 9; i++) {
		a = aa[i];
		ans = (ans + a * a) % MD;
	}
	printf("%lld\n", ans);
	return 0;
}

#include <string.h>
#include <stdio.h>
#include <ctype.h>
//#include <DEBUG.h>
#define LL long long
#define uLL long long
#define uL unsigned int
#define iL unsigned int
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

LL CP=(LL)998244353;
LL inv[0x100000];
LL num1[0x100000],num2[0x100000];
uL exgcd(uL a,uL c)
{
    static uL gcd;
    uL k;
    uLL x;
    if (a==0)
    {
        gcd=c;
        return 1;
    }
    else
    {
        k=c%a;
        if (k==0)
        {
            gcd=a;
            return 1;
        }
        else
        {
            x=exgcd(a%k,k);
        }
    }
    return (x*c-c/a*gcd)/k;
}
void ini1(long n,LL P)
{
    long i;
    inv[1]=1;
    for (i=2;i<=n;i++)
    {
        inv[i]=(uLL)inv[P%i]*(P-P/i)%P;
    }
}
static inline LL madd(LL a,LL b)
{
    a+=b;
    a-=(a>CP)?CP:0;
    return a;
}
static inline LL msub(LL a,LL b)
{
    a-=b;
    a+=(a<0)?CP:0;
    return a;
}
static inline LL MR(LL a,LL b)
{
    return (a*b)%CP;
}
uLL mexp(uLL a,uLL b)
{
    register uLL t;
    for (t=1;b;b=b>>1)
    {
        if (b&1) {t=MR(a,t);}
        a=MR(a,a);
    }
    return t;
}
static inline uLL PolynomialPower(uLL *pol,uLL psize,uLL ex,uLL N,uLL *ans)
{
    uLL i,j,a,b,c,d;
    psize=(psize>N)?N:psize;
    uLL temp[psize],ans2[N+1];
    ans[1]=mexp(pol[1],ex);
    for (i=1;i<psize;i++) {temp[i-1]=pol[i+1]*i%CP;}
    c=ex%CP;d=exgcd(pol[1],CP);
    for (i=2;i<=N;i++)
    {
        a=0;b=min(psize-1,i-1);
        for (j=0;j<b;j++)
        {
            a=madd(a,MR(ans[i-j-1],temp[j]));
        }
        a=MR(a,c);
        b=min(psize,i-1);
        for (j=2;j<=b;j++)
        {
            a=msub(a,MR(ans2[i-j],pol[j]));
        }
        ans[i]=MR(a,MR(d,inv[i-1]));
        ans2[i-1]=MR(i-1,ans[i]);
    }
}
int main()
{
    //freopen("in.in","r",stdin);
    LL i,j,k,a,b,c,n,ans;
    ini1(1000013,CP);
    scanf("%lld%lld",&n,&k);
    *num1=10;
    memset(num1+1,0,sizeof(*num1)*(*num1+1));
    for (i=1;i<=k;i++)
    {
        scanf("%lld",&a);
        num1[a+1]=1;
    }
    //printf("%lld\n",n/2);
    //print(num1,20);
    for (i=1;i<=10;i++) {if (num1[i]>0) {break;}}
    PolynomialPower(num1+i-1,10-i+1,n/2,1000001,num2);
    //print(num2,20);
    ans=0;
    for (i=1;i<=1000000;i++)
    {
        a=num2[i]*num2[i]%CP;
        ans=madd(a,ans);
    }
    printf("%lld\n",ans);
    return 0;
}


A chainword is a special type of crossword. As most of the crosswords do, it has cells that you put the letters in and some sort of hints to what these letters should be.The letter cells in a chainword are put in a single row. We will consider chainwords of length $$$m$$$ in this task.A hint to a chainword is a sequence of segments such that the segments don't intersect with each other and cover all $$$m$$$ letter cells. Each segment contains a description of the word in the corresponding cells.The twist is that there are actually two hints: one sequence is the row above the letter cells and the other sequence is the row below the letter cells. When the sequences are different, they provide a way to resolve the ambiguity in the answers.You are provided with a dictionary of $$$n$$$ words, each word consists of lowercase Latin letters. All words are pairwise distinct.An instance of a chainword is the following triple:   a string of $$$m$$$ lowercase Latin letters;  the first hint: a sequence of segments such that the letters that correspond to each segment spell a word from the dictionary;  the second hint: another sequence of segments such that the letters that correspond to each segment spell a word from the dictionary. Note that the sequences of segments don't necessarily have to be distinct.Two instances of chainwords are considered different if they have different strings, different first hints or different second hints.Count the number of different instances of chainwords. Since the number might be pretty large, output it modulo $$$998\,244\,353$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 8$$$, $$$1 \le m \le 10^9$$$) — the number of words in the dictionary and the number of letter cells. Each of the next $$$n$$$ lines contains a word — a non-empty string of no more than $$$5$$$ lowercase Latin letters. All words are pairwise distinct.

Print a single integer — the number of different instances of chainwords of length $$$m$$$ for the given dictionary modulo $$$998\,244\,353$$$.

NoteHere are all the instances of the valid chainwords for the first example:   The red lines above the letters denote the segments of the first hint, the blue lines below the letters denote the segments of the second hint.In the second example the possible strings are: "abab", "abcd", "cdab" and "cdcd". All the hints are segments that cover the first two letters and the last two letters.

/* https://csacademy.com/contest/archive/task/superstition/ (rainboy) */
#include <stdio.h>
#include <string.h>

#define N	8
#define L	5
#define N_	(1 + N * L)
#define N1	(N_ * 2)
#define A	26
#define MD	998244353

int tt[1 + N_][A]; char word[1 + N_];

void dfs(int coef[][L + 1], int s1, int s2, int l) {
	int a;

	if (s1 == 0 || s2 == 0)
		return;
	if (l > 0) {
		if (word[s1])
			coef[s2 - 1 << 1 | 0][l]++;
		if (word[s2])
			coef[s1 - 1 << 1 | 1][l]++;
		if (word[s1] && word[s2])
			coef[0][l]++;
	}
	for (a = 0; a < A; a++)
		dfs(coef, tt[s1][a], tt[s2][a], l + 1);
}

int coef[N1][N1][L + 1];

void apply(int aa[][N1][L], int n) {
	static int bb[N1][N1];
	int i, j, k, l;

	for (i = 0; i < n; i++)
		memset(bb[i], 0, n * sizeof *bb[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				for (l = 1; l <= L; l++)
					bb[i][k] = (bb[i][k] + (long long) aa[i][j][l - 1] * coef[j][k][l]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (l = L - 1; l >= 0; l--)
				aa[i][j][l] = l == 0 ? bb[i][j] : aa[i][j][l - 1];
}

void mult(int aa[][N1][L], int bb[][N1][L], int cc[][N1][L], int n) {
	static int aa_[N1][N1][L], bb_[N1][N1][L + L];
	int i, j, k, l, l1, l2;

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			memcpy(aa_[i][j], aa[i][j], L * sizeof *aa[i][j]);
	for (l = 0; l < L; l++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (k = 0; k < n; k++)
					for (l1 = 1; l + l1 < L; l1++)
						aa_[i][k][l] = (aa_[i][k][l] - (long long) aa_[i][j][l + l1] * coef[j][k][l1]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++) {
			memset(bb_[i][j], 0, L * sizeof *bb_[i][j]);
			memcpy(bb_[i][j] + L, bb[i][j], L * sizeof *bb[i][j]);
		}
	for (l = L - 1; l >= 0; l--)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (k = 0; k < n; k++)
					for (l1 = 1; l1 <= L; l1++)
						bb_[i][k][l] = (bb_[i][k][l] + (long long) coef[i][j][l1] * bb_[j][k][l + l1]) % MD;
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			memset(cc[i][j], 0, L * sizeof *cc[i][j]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			for (k = 0; k < n; k++)
				for (l1 = 0; l1 < L; l1++)
					for (l2 = L - l1; l1 + l2 - L < L; l2++)
						cc[i][k][l1 + l2 - L] = (cc[i][k][l1 + l2 - L] + (long long) aa_[i][j][l1] * bb_[j][k][l2]) % MD;
}

void power(int pp[][N1][L], int tt[][N1][L], int n, int k) {
	int i, j, l;

	if (k == 0) {
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				for (l = 0; l < L; l++)
					pp[i][j][l] = i == j && l == 0;
		return;
	}
	power(tt, pp, n, k / 2);
	mult(tt, tt, pp, n);
	if (k & 1)
		apply(pp, n);
}

int main() {
	static int pp[N1][N1][L], tt_[N1][N1][L];
	int n, n_, k, i, s;

	scanf("%d%d", &n, &k);
	n_ = 1;
	for (i = 0; i < n; i++) {
		static char cc[L + 1];
		int l, h;

		scanf("%s", cc), l = strlen(cc);
		for (h = 0, s = 1; h < l; h++) {
			int a = cc[h] - 'a';

			if (!tt[s][a])
				tt[s][a] = ++n_;
			s = tt[s][a];
		}
		word[s] = 1;
	}
	for (s = 0; s < n_; s++) {
		dfs(coef[s << 1 | 0], 1, s + 1, 0);
		if (s != 0)
			dfs(coef[s << 1 | 1], s + 1, 1, 0);
	}
	power(pp, tt_, n_ * 2, k);
	if (pp[0][0][0] < 0)
		pp[0][0][0] += MD;
	printf("%d\n", pp[0][0][0]);
	return 0;
}