Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.

The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x1, x2, ..., xn (1 ≤ xi ≤ 100).

Output a single integer — the required minimal sum.

NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1.

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

int GCD(int x, int y){
    int tmp;
    while(x%y != 0){
        x = x%y;
        tmp = y;
        y = x;
        x = tmp;
    }
    return y;
}

int main(){
    int n[200];
    int T;
    int i,j;
    int nowGCD;
    scanf("%d", &T);
    for(i = 0; i < T; i++){
        scanf("%d", &n[i]);
    }
    nowGCD = GCD(n[0], n[1]);
    for(i = 2; i < T; i++){
        nowGCD = GCD(nowGCD, n[i]);
    }
    printf("%d", T*nowGCD);
    return 0;
}

#include<stdio.h>

int GCD(int a, int b)
    {
    int c;
    while(a)
        {
        c=b%a;
        b=a;
        a=c;
        }
    return b;
    }
int main()
    {
    int n, x, y, i;
    scanf("%d%d", &n, &x);
    for(i=1;i<n;i++)
        {
        scanf("%d", &y);
        x=GCD(x,y);
        }
    printf("%d", x*n);
    return 0;
    }

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
typedef long long ll;
int main()
{
  int n;
   scanf("%d",&n);
  int ar[10000],i=0,j=0,min=101;
  for(i=0;i<n;i++)
  {
    scanf("%d",&ar[i]);
    if(ar[i]<min)
    min = ar[i];
  }
  int count = 0;
  for(i=min;i>=2;i--)
  {
    count = 0;
   for(j=0;j<n;j++)
   {
      if(ar[j]%i==0)
      count++;
   }
   if(count==n)
   break;
  }
  printf("%d\n",i*n);
  return 0;
}

#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
    return(*(int *)a)<(*(int *)b)?1:-1;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,i,j;
    int p[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&p[i]);
    qsort(p,n,sizeof(int),cmp);
    while(p[0]!=p[n-1])
    {
        for(i=0,j=0;j<n;)
        {
           if(p[i]>p[j])
           {
              p[i]=p[i]-p[j];
              i++;
           }
           else
              j++;
        }
        qsort(p,n,sizeof(int),cmp);
    }
    printf("%d\n",n*p[0]);
    return 0;
}

#include<stdio.h>
int gcd(int , int);
int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n,x,i,y;
	scanf("%d",&n);
	scanf("%d",&x);
	for(i=1;i<n;i++)
	{
		scanf("%d",&y);
		x=gcd(x,y);
	}
	printf("%d",x*n);
	return 0;
}

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

int gcd(int a, int b)
{
    if(b == 0)
           return a;
    else
        return gcd(b,a%b);
}

int main()
{
    int n,i,min=100,max=0;
    scanf("%d",&n);
    int x[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        max = max>x[i]?max:x[i];
        min = min<x[i]?min:x[i];
    }
    int mingc = min;
    int j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(j != i)
                mingc = mingc<gcd(x[i],x[j]) ? mingc:gcd(x[i],x[j]);
        }
    }
    for(i=0;i<n;i++)
    {
        if(x[i]%mingc != 0)
        {
            printf("%d\n",n);
            return 0;
        }
    }
    printf("%d",n*mingc);
    printf("\n");
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    int n,i,x[102],sum,m;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
            m=x[i];
        else
            m=gcd(m,x[i]);
    }
    printf("%d",m*n);
    return 0;
}

#include <stdio.h>

int hcf(int a,int b)
         {
              if(a%b==0)
               {
                      return b;
               }
              else
              {
                      return(hcf(b,a%b));
              }
         }

int main()
{

    int n,i,h,t=10;

    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
     for(i=0;i<n-1;i++)
                {
                     h=hcf(arr[i],arr[i+1]);
                     arr[i+1]=h;
                }
        printf("%d\n",n*h);

return 0;

}

#include<stdio.h>

#define MAX_NUMBERS 110

int gcd (int x, int y){
    if (x == 0)
        return y;
    else
        return gcd(y%x, x);
}

int main (){

    int n, i, g, numbers[MAX_NUMBERS];

    scanf("%d", &n);

    for (i=0; i<n; i++)
        scanf("%d", &numbers[i]);

    g = gcd(numbers[0], numbers[1]);
    for (i=2; i<n; i++){
        //Calculate gcd, running for the rest of the items in the array
        g = gcd(g, numbers[i]);
    }

    printf("%d\n", g*n);

    return 0;
}

int main()
{
    int number,array[200],i,min=1000,z,counter=0,sum=0,y=0;
    scanf("%d",&number);
    for(i=0;i<number;i++)
    {
        scanf("%d",&array[i]);
    }
    for(;;)
    {
        for(i=0;i<number;i++)
        {

           if(array[i]<min)
           {
               min=array[i];
           }
        }
           while(y<number)
           {
               if(array[y]!=min)
               {
                   array[y]=array[y]-min;
               }
               y++;
           }

        for(z=0;z<number;z++)
           {
               if(array[z]==array[z+1])
               {
                   counter++;
               }
               else
               {
                   break;
               }
           }
           if(counter==number-1)
           {
               break;
           }
           counter=0;
           y=0;
    }
    i=0;
    while(i<number)
    {
        sum=sum+array[i];
        i++;
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,i,j,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(a[i]>a[j]){
                a[i]=a[i]-a[j];
                i=-1;
                break;
            }
        }
    }
    for(i=0;i<n;i++) sum=sum+a[i];
    printf("%d",sum);
    return 0;
}

/*
#include<stdio.h>
int* sortandsub(int *a, int n){
    int i, j;
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            if(a[i] > a[j]){
                a[i] = a[i] - a[j];
            }
            else if(a[j] > a[i]){
                a[j] -= a[i];
            }
        }
    }
    return a;
}
int main(){
    int n;
    scanf("%d", &n);
    int a[n], i, j;
    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(a[i] != a[j]){
                sortandsub(a, n);
            }
        }
    }
    printf("%d", n * a[0]);
    return 0;
}
*/
#include <stdio.h>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n, n_, g = 0;

	scanf("%d", &n);
	n_ = n;
	while (n--) {
		int x;

		scanf("%d", &x);
		g = gcd(x, g);
	}
	printf("%d\n", g * n_);
	return 0;
}

#include<stdio.h>
int hcf(int a,int b)
 {
   if((b%a)==0)
    return a;
   else
    return hcf(b%a,a);

 }
int main()
{
   int a,cnt=0,j,c,d,dum,arr[109]={0},n,i,k,b,ans1,ans2;
   scanf("%d",&n);
    for(i=0;i<n;i++)
       {
           scanf("%d",&arr[i]);
       }
    for(i=0,j=n-1;i<=n-2,j>=1;i++,j--)
       {
            a=arr[i];b=arr[i+1];
              if(a>b)
                {
                   k=b;b=a;a=k;
                }
               ans1=hcf(a,b);

               arr[i]=ans1;arr[i+1]=ans1;
               c=arr[j];d=arr[j-1];

              if(c>d)
                {
                  dum=d;d=c;c=dum;
                }
               ans2=hcf(c,d);
             arr[j]=ans2;arr[j-1]=ans2;
       }
     for(i=0;i<n;i++)
       {
          cnt+=arr[i];
       }
      printf("%d\n",cnt);
 return 0;
}

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

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
   int i, j;
   for (i = 0; i < n-1; i++)

       // Last i elements are already in place
       for (j = 0; j < n-i-1; j++)
           if (arr[j] > arr[j+1])
              swap(&arr[j], &arr[j+1]);
}

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

	int a[n];
	for(int i=0;i<n;i++)
	{
 		scanf("%d",&a[i]);

	}
	bubbleSort(a,n);

	while(1)
	{
		if(a[0]==a[n-1])
		{
			break;
		}
		else
			for(int i=1;i<n;i++)
			{
				if(a[i]==a[0])
				continue;
				else
				a[i]-=a[0];
			}
		bubbleSort(a,n);
	}
	printf("%d",a[n-1]*n);
}

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

int compareInt(const void *pa, const void *pb)
{
    const int *p1 = pa;
    const int *p2 = pb;
    return *p1 - *p2;
}

int main()
{
    int n, sum, i, j;
    scanf("%d", &n);
    int arr[n];

    for(i=0; i<n; i++)
    {
        scanf("%d", &arr[i]);
    }

    qsort(arr, n, sizeof(int), compareInt);
    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(arr[j]>arr[i])
            {
                arr[j] = arr[j] - arr[i];
                i--;
                break;
            }
        }
        qsort(arr, n, sizeof(int), compareInt);

        if(arr[0]==arr[n-1])break;
    }

    printf("%d", arr[0]*n);
}

#include <stdio.h>

int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}

int main(void) {
    int n, x[101], i, hcf;

    scanf("%d",&n);

    for(i=0; i<n; i++)
    {
        scanf("%d",&x[i]);
    }

    hcf=gcd(x[0],x[1]);
    for(i=2; i<n; i++)
        hcf=gcd(hcf,x[i]);

    printf("%d",hcf*n);

    return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
int cmp(const void*a,const void*b)
{
    return *(int*)a - *(int*)b;
}
int GCD(int a,int b)
{
	int x,y,r;
	x=MAX(a,b);
	y=MIN(a,b);
	while(y)
	{
		r=x%y;
		x=y;
		y=r;
	}
	return x;
}
int main(void)
{
    int n,i,j,a;
    int t[101];
    while(scanf("%d",&n)!=EOF)
	{
        for(i=0;i<n;i++)
        scanf("%d",&t[i]);
        qsort(t,n,sizeof(int),cmp);
        a=GCD(t[0],t[1]);
        for(i=1;i<n;i++)
        {
        	a=GCD(a,t[i]);
        }
        printf("%d\n",a*n);
    }
    return 0;
}

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

int gcd(int a,int b)
{
   if(a%b==0)
   return b;

   return gcd(b,a%b);
}

int main()
{
    int n;
    scanf("%d",&n);
    int hcf;
    scanf("%d",&hcf);
    for(int i=1;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        if(hcf>a)
            hcf = gcd(hcf,a);
        else
            hcf = gcd(a,hcf);

    }
    printf("%d\n",n*hcf);

}

#include<stdio.h>
int gcd(int a,int b)
{
	//printf("here3");

	if(a>b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
	else
	{
		if(b%a==0)
			return a;
		return gcd(a,b%a);
	}
}
int main()
{
	//printf("%d",gcd(1,2));
	int n,m,a,b,g;
	scanf("%d",&n);
	m=n-1;
	scanf("%d",&a);
	g=a;
	//printf("here1");
	while(m--)
	{
		//printf("here2");
		scanf("%d",&b);
		g=gcd(g,b);
	}
	printf("%d",n*g);
	return 0;
}

#include<stdio.h>
int main()
{
    int n,x[105];
    scanf("%d",&n);
    int i;
    for(i=0;i<n;++i)
        scanf("%d",&x[i]);
    int ans,j;
    for(i=1;i<=100;++i)
    {
        int ct=0;
        for(j=0;j<n;++j)
        {
            if(x[j]%i!=0)
                ct=1;
        }
        if(ct==0)
        ans=i;
    }
    printf("%d",ans*n);
    return 0;
}

#include<stdio.h>
int comp(const void * a,const void *b);
int main(){
    int n;
    scanf("%d",&n);
    int i,j,ans=0;
    int num[n];
    for(i=0;i<n;i++)
        scanf("%d",&num[i]);
    qsort((void*)num,n,sizeof(int),comp);
    int flag=0;
    while(1){
        flag=0;
        for(j=n-2;j>=0;j--){
            if(num[n-1]>num[j]){
                num[n-1]=num[n-1]-num[j];
                flag=1;
            }
        }
        if(flag==0)
            break;
        qsort((void*)num,n,sizeof(int),comp);
    }
    printf("%d\n",num[n-1]*n);
    return 0;
}

int comp(const void * a,const void *b){
    return *(int*)a>*(int*)b?1:-1;
}

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

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
int findGCD(int arr[], int n)
{
    int result = arr[0];
    int i;
        for (i=1; i<n; i++)
        result = gcd(arr[i], result);

    return result;
}
int main(){

    int n,i,j=0;
    scanf("%d",&n);
    int a[100];
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    int sum = n * findGCD(a,n);
    printf("%d",sum);
    return 0;
}

#include<stdio.h>

int g(int i,int j)
{
    int k;
    while(1)
    {
        if(i==0)
            break;
        k=j%i;
        j=i;
        i=k;

    }
    return (j);
}
int main()
{
    int n,i,a[105];
    int c=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        c++;
    }
    int x=g(a[0],a[1]);
    for(i=2; i<n; i++)
    {
        x=g(x,a[i]);
    }
    c=c*x;
    printf("%d",c);
    return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int i,j,arr[200],k;
	int sum=0;
	int maxm=0;
	for(i=0;i<n;i++)
		{
			scanf("%d", &arr[i]);
			if(arr[i]>maxm)
				maxm=arr[i];
		}
	for(k=0;k<maxm;k++)
	{
	for(i=0;i<n;i++)
	{
		int max=0;
		for(j=0;j<n;j++)
		{

			if(arr[i]>arr[j] && arr[j]>max)
		{
			//printf("%d ", j);
			max=arr[j];
			//("%d\n",max);
		}
		}
	arr[i]-=max;
	//printf("%d\n", arr[i]);

}
}
for(i=0;i<n;i++)
sum+=arr[i];
printf("%d", sum);
return 0;
}

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

int gongyue(int nn,int m)
{
    if(m==0){return nn;}
    return gongyue(m,nn%m);
}
int main(){
    int a[105], n, i;
    scanf("%d",&n);
    for(i = 0; i < n; i++){scanf("%d",&a[i]);}
    for(i = 0; i < n; i++){
        a[i + 1]=gongyue(a[i], a[i+1]);
    }
    printf("%d\n", a[n-1] * n);
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	int a[103],n,i,ans;
	scanf("%d",&n);
	scanf("%d",&a[0]);
	ans=a[0];
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
		ans=gcd(ans,a[i]);
	}
	printf("%d\n",ans*n);
	return 0;
}

#include <stdio.h>
int gcd(int a,int b){
	if (a==0){
		return b;
	}
	else{
		return gcd(b%a,a);
	}
}
int main()
{
	int n,i,j,f,t,r;

	scanf("%d",&n);
	int ara[100];
	for (i=0;i<n;i++){
		scanf("%d",&ara[i]);
	}
	for (i=n-1;i>=0;i--){
		for (j=0;j<i;j++){
			if (ara[j]>ara[j+1]){
				t=ara[j];
				ara[j]=ara[j+1];
				ara[j+1]=t;
			}
		}
	}
	r=ara[0];
	for (i=1;i<n;i++){
		if (ara[i]%r!=0){
			r=gcd(ara[i],r);
		}
	}
	printf("%d",r*n);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int comp(const void*a,const void*b){
    return *(int*)a - *(int*)b;
}

int gcd(int a,int b){
    int t;
    while(t=a%b){
        a = b;
        b = t;
    }
    return b;
}

int main(){
    int n,i,j,a;
    int t[105];
    while(scanf("%d",&n)!=EOF){
        for(i=0;i<n;i++){
            scanf("%d",&t[i]);
        }
        for(i=1,a=t[0];i<n;i++){
            a = gcd(a,t[i]);
        }
        printf("%d\n",a*n);
    }
    return 0;
}

#include <stdio.h>

int an[101];

int solve(int n)
{
    int min = 101;
    for (int i = 0; i < n; i++) {
        if (an[i] < min) {
            min = an[i];
        }
    }

    while (1) {
        int m = min;
        for (int i = 0; i < n; i++) {
            while (an[i] > min) {
                an[i] -= min;
                if (an[i] < m) {
                    m = an[i];
                }
            }
        }
        if (m == min) {
            break;
        }
        min = m;
    }

    return n*an[0];
}

int main()
{
    int n = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &an[i]);
    }
    printf("%d\n", solve(n));
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
void sort(int *arr,int k)
{
    int i,j,temp;
    for(i=0;i<k;i++)
    {
        for(j=i+1;j<k;j++)
        {
            if(*(arr+i)<*(arr+j))
            {
                temp=*(arr+i);
                *(arr+i)=*(arr+j);
                *(arr+j)=temp;
            }
        }
    }
}
void res(int *arr,int k)
{
    int i,j,sum;
    for(i=sum=0,j=i+1;j<k;i++,j++) if(*(arr+i)>*(arr+j)) *(arr+i)=*(arr+i)-*(arr+j);
}
int main(void)
{
    int n,*x,i,sum;
    scanf("%d",&n);
    x=(int*)malloc(n*sizeof(int));
    for(i=0;i<n;i++) scanf("%d",(x+i));
    sort(x,n);
    for(i=0;i<n;)
    {
        if(*(x+i)==*(x+i+1))
        {
            i++;
            if(i==n-1) break;
        }
        else
        {
            res(x,n);
            sort(x,n);
            i=0;
        }
    }
    for (i=sum=0;i<n;i++) sum+=*(x+i);
    printf("%d",sum);
    free(x);
    x=NULL;
    return 0;
}

#include <stdio.h>
int main()
{
    int n,i,j,k,sum=0,ind;
    scanf("%d", &n);
    int li[n];
    for (i=0; i<n; i++){
        scanf("%d", &li[i]);
    }
    while(1){
        for (i=0; i<n; i++){
            for (j=0; j<n; j++){
                if (li[i]>li[j]) li[i] = li[i] - li[j];
            }
        }
        ind = 1;
        for (j=1; j<n; j++){
            if (li[0]!=li[j]) {ind = 0; break;}
        }
        if (ind) break;
    }
    sum = n*li[0];
    printf("%d", sum);
    return 0;
}

#include<stdio.h>
int min (int ar[],int n)
{
    int i,p=19000;
    for (i=0;i<n;i++)
    {
        if (ar[i]<=p)
        {
            p=ar[i];
        }
    }
    return p;
}
int gcd(int ar[],int p,int n)
{
    int i=0,f=1;
    while (i<n)
    {
        if (ar[i]%p==0)
        {
            f=1;
            i++;
        }
        else if (ar[i]%p!=0)
        {
            f=0;
            p-=1;
            i=0;
        }
    }
    return p;

}
int main()
{
    int n,ar[1000],i,s,w,x;
    scanf ("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf ("%d",&ar[i]);
    }
    w=min(ar,n);
    x=gcd(ar,w,n);
    s=x*n;

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

#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
    return (*(int *)a) - (*(int *)b);
}
int main(void)
{
    int x[10000];
    int n;
    int i,sum = 0;
    scanf("%d",&n);
    for(i = 0 ; i < n ; i ++)
        scanf("%d",&x[i]);
    qsort(x,n,sizeof(int),cmp);
    while(x[0] != x[n-1])
    {
        for(i = n - 1 ; i > 0 ; i --)
        {
            if(x[i] % x[i-1] == 0)
                x[i] = x[i-1];
            else
                x[i] %= x[i-1];
        }
        qsort(x,n,sizeof(int),cmp);
    }
    for(i = 0 ; i < n ; i ++)
        sum += x[i];
    printf("%d\n",sum);
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    int i;
    if(a>b)
    {
        for(i=b;i>=1;i--)
            if(a%i==0&&b%i==0)
            return i;
    }
    else
        for(i=a;i>=1;i--)
            if(a%i==0&&b%i==0)
            return i;
}
int main()
{
    int a,b,n,g,s=101,i;
    scanf("%d%d",&n,&a);

    for(i=1;i<n;i++)
    {
        scanf("%d",&b);
        g=gcd(a,b);
        if(g<s)
        s=g;
        a=g;
    }
    printf("%d",s*n);

}

#include<stdio.h>
int gcd(int , int);
int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n,x,i,y;
	scanf("%d",&n);
	scanf("%d",&x);
	for(i=1;i<n;i++)
	{
		scanf("%d",&y);
		x=gcd(x,y);
	}
	printf("%d",x*n);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int hcf(int,int);
int main()
{ int i,j,k,n;
  scanf("%d",&n);
  int *a =(int*)malloc(n*sizeof(int));
  for(i=0;i<n;i++)
   {scanf("%d",&a[i]);
   }
  for(i=0;i<n-1;i++)
  { k=hcf(a[i],a[i+1]);
    a[i+1]=k;
  }
  printf("%d",k*n);
  free(a);
  return 0;
  }
  int hcf(int p,int q)
  { if(p>q)
     { if(p%q==0)
        return q;
       else
        return(hcf(q,p%q));
      }
     else
     {if(q%p==0)
       return p;
       else
       return(hcf(p,q%p));
      }
      }

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

int gcd(int a, int b)
{
	if(b == 0)
	       return a;
	else
		return gcd(b,a%b);
}

int main()
{
	int n,i,min=100,max=0;
	scanf("%d",&n);
	int x[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
		max = max>x[i]?max:x[i];
		min = min<x[i]?min:x[i];
	}
	int mingc = min;
	int j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(j != i)
				mingc = mingc<gcd(x[i],x[j]) ? mingc:gcd(x[i],x[j]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(x[i]%mingc != 0)
		{
			printf("%d\n",n);
			return 0;
		}
	}
	printf("%d\n",n*mingc);
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
int min(int a, int b)
{
if(a>b) return b;
else if(b>a) return a;
else if(b==a) return a;

}
int main()
{
     int a[110] , c;
     int i, k, j;
     scanf("%d",&k);
     for(i=0;i<k;i++)
        scanf("%d",&a[i]);
     c=100;
     int d=0;
     while(d==0)
     {
     for(i=0;i<k;i++)
     {
     for(j=0;j<k;j++)
     {
         if(a[i]>a[j]) a[i]=a[i]-a[j];
         else if(a[j]>a[i]) a[j]=a[j]-a[i];
         c=min(a[i],a[j]);
     }
     }
      for(i=0;i<k;i++)
      {
          if(a[i]%c!=0) break;
      }
      if(i==k) d=1;
      else d=0;
     }

     printf("%d\n",c*k);
     return 0;

}

#include<stdio.h>
int GCD(int x,int y);
int IsArrayEqual(int array[],int n);
int main(){
	int m,n,i=0,j;
	int array[100];
	scanf("%d",&n);
	m=n;
    do{
       scanf("%d",&array[i++]);
       }while(getchar()!='\n');
    while(!IsArrayEqual(array,m)){
    	int temp=array[0];
    	for(j=0;j<m-1;j++){
	    	array[j]=GCD(temp,array[j+1]);
	    }
	    m--;

    }
    printf("%d",n*array[0]);
    return 0;
}
int GCD(int x,int y){
	int temp;
	if(x>y){
		x=x%y;
		if(x==0) return y;
		if(x==1) return (1);
		else return (GCD(x,y));
	}
	else if(x<y){
		y=y%x;
		if(y==0) return (x);
		else if(y==1) return (1);
		else return (GCD(x,y));
	}
	else return x;
}
int IsArrayEqual(int array[],int n){
	if(n==0){
		return (1);
	}
	else if(array[0]==array[n-1]){
		IsArrayEqual(array,n-1);
	}
	else return (0);
}

#include <stdio.h>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n, n_, g;

	scanf("%d", &n);
	n_ = n;
	while (n--) {
		int x;

		scanf("%d", &x);
		g = gcd(x, g);
	}
	printf("%d\n", g * n_);
	return 0;
}

#include <stdio.h>
#include <string.h>
int main()
{
    int n,min;
    scanf("%d",&n);
    int a[n];
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }

    for(int i=0; i<n-1; i++)
    {
        for(int j=i+1; j<n; j++)
        {int diff=a[i]-a[j];
            if(diff>0)
            {
                a[i]=diff;j--;
            }
            else if(diff<0)
                {a[j]=-diff;j--;}

        }
    }int s=0;
    for(int i=0; i<n; i++)
    {
        s+=a[i];
    }
    printf("%d",s);
}

#include<stdio.h>

int hcf(int a,int b)

         {

              if(a%b==0)

               {

                      return b;

               }

              else

              {

                      return(hcf(b,a%b));

              }

         }

int main()

{

    int i,j,h,n,a[100];

    scanf("%d",& n);

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

        {

            scanf("%d",& a[i]);

        }

            for(i=0;i<n-1;i++)

                {

                     h=hcf(a[i],a[i+1]);

                     a[i+1]=h;

                }

                     printf("%d\n",h * n);

	return 0;
  }

#include<stdio.h>
int gcd(int a,int b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
int main()
{
	int arr[100],sum,i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&arr[i]);
    sum=gcd(arr[0],arr[1]);
    for(i=2;i<n;i++)
    {
    	sum=gcd(arr[i],sum);
    }
    printf("%d",sum*n);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int n;
scanf("%d",&n);
int a[n],i,j;
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
int min=a[0];
for(i=0;i<n;i++){
    if(min>a[i]){
        min=a[i];
    }
}
int hcf=1,z;
for(i=2;i<=min;i++){
    z=0;
    for(j=0;j<n;j++){
        if(a[j]%i==0){z++;}
    }
    if(z==n){hcf=i;}
}
printf("%d",hcf*n);
return 0;
}

#include <stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}
int main(void) {
    int n,i,sum,x;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sum=arr[0];
    if(n!=1)
    {
        sum=0;
    qsort(arr,n,sizeof(int),cmp);
    while(1)
    {
        x=n-2;
        while(x>=0)
        {
            if(arr[x]<arr[n-1])
            break;
            x--;
        }
    if(x<0||arr[x]==0)
    break;
    arr[n-1]=arr[n-1]-arr[x];
    qsort(arr,n,sizeof(int),cmp);
    }
    for(i=0;i<n;i++)
    sum=sum+arr[i];
    }
    printf("%d\n",sum);
    return 0;
}

#include<stdio.h>

int max(int x[],int n){
    int max,i,maxi;
    int max1;
int max2;
    max2=-1;
    max=0;
    for(i=0;i<n;i++){
        if(x[i]>max){
            max=x[i];
            max1=i;
        }
    }
    maxi=max;
    max=0;
    for(i=0;i<n;i++){
        if(x[i]>max&&x[i]<maxi){
            max=x[i];
            max2=i;
        }
    }
    x[max1]-=x[max2];
   return max2;
}
int main()
{
	int n;
	int max2;
    int i;
    int x[100];
   scanf("%d",&n);
   for(i=0;i<n;i++){
       scanf("%d",&x[i]);
   }
   i=1;

   while(i==1){
   max2=max(x,n);
   if(max2==-1){
       printf("%d",(x[1]*n));
    return 0;
   }
   }

}

#include <stdio.h>
int main(){
  int n,m,a[100],i,tr=1,min;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&a[i]);
while(tr){
tr=0;
min=a[0];
for(i=1;i<n;i++)if(min>a[i])min=a[i];
for(i=0;i<n;i++)if(a[i]>min){
tr=1;
a[i]-=min;
}
}
m=0;

for(i=0;i<n;i++)m+=a[i];
printf("%d",m);
return 0;
}

#include<stdio.h>
#include<math.h>
main()
{
    int n,i,r,min;
    scanf("%d",&n);
    int arr[n];

    for(i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    min = arr[0];
    for(i=1; i<n; i++)
    {
        if(min>arr[i])
        {
            min = arr[i];
        }
    }
    int max=1,k=1,count;
    for(k=2; k<=min; k++)
    {
        for(i=0; i<n; i++)
        {
            count=1;

            if(arr[i]%k!=0)
            {
                count = 0;
                break;
            }
        }
        if(count==1)
        {

           max = k;

        }
    }

    printf("%d\n",max*n);
}

#include<stdio.h>
int gcd(int a,int b)
{
    if(a%b!=0) return gcd(b,a%b);
    else return b;
}
int main()
{
   int a,b,c,d,n,k,i,ss[110],sum;
   while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
           {
              scanf("%d",&k);
              ss[i]=k;
           }
        if(n==1)  {printf("%d\n",ss[0]);continue;}
        else
            {
                for(i=0,sum=ss[0];i<n-1;i++)
                    {
                        sum=gcd(sum,ss[i+1]);
                    }
                printf("%d\n",sum*n);
            }
    }
}

#include <stdio.h>
int n, arr[1100], m;
int gcd(int a, int b);

int main()

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

    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &arr[i]);
    }
    if (n == 1)
    {
        printf("%d", arr[1]);
        return 0;
    }

    int m = arr[1];

    for (int i = 2; i <= n; i++)
    {
        m = gcd(m, arr[i]);
    }

    printf("%d\n", m * n);

    return 0;

}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

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

int gongyue(int nn,int m)
{
    if(m==0){return nn;}
    return gongyue(m,nn%m);
}
int main(){
    int a[105], n, i;
    scanf("%d",&n);
    for(i = 0; i < n; i++){scanf("%d",&a[i]);}
    for(i = 0; i < n; i++){
        a[i + 1]=gongyue(a[i], a[i+1]);
    }
    printf("%d\n", a[n-1] * n);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,min=100,i,j,A[100],temp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
        if(A[i]<min)
            min=A[i];
    }
    for(i=min;i>0;i--)
    {
        for(j=0;j<n;j++)
        {
            if(A[j]%i)
                break;
        }
        if(j==n)
            break;
    }
    printf("%d",i*n);
    return 0;
}

#include<stdio.h>

int g(int i,int j)
{
    int k;
    while(1)
    {
        if(i==0)
            break;
        k=j%i;
        j=i;
        i=k;

    }
    return (j);
}
int main()
{
    int n,i,a[105];
    int c=0;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        c++;
    }
    int x=g(a[0],a[1]);
    for(i=2; i<n; i++)
    {
        x=g(x,a[i]);
    }
    c=c*x;
    printf("%d",c);
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    int i;
    if(a>b)
    {
        for(i=b;i>=1;i--)
            if(a%i==0&&b%i==0)
            return i;
    }
    else
        for(i=a;i>=1;i--)
            if(a%i==0&&b%i==0)
            return i;
}
int main()
{
    int a,b,n,g,s=101,i;
    scanf("%d%d",&n,&a);

    for(i=1;i<n;i++)
    {
        scanf("%d",&b);
        g=gcd(a,b);
        if(g<s)
        s=g;
        a=g;
    }
    printf("%d",s*n);

}

#include<stdio.h>
int gcd(int a,int b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	int a[103],n,i,ans;
	scanf("%d",&n);
	scanf("%d",&a[0]);
	ans=a[0];
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
		ans=gcd(ans,a[i]);
	}
	printf("%d\n",ans*n);
	return 0;
}

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

int Cmp(const void* a,const void* b)
{
    return *(int*)a-*(int*)b;
}

int GCD(int a,int b){
    if(a==0||b==0) return 0;
    while(a&&b){
        if(a>b){
            a=a%b;
        }
        else{
            b=b%a;
        }
    }
    if(a==0) return b;
    else return a;
}

int main()
{
    int n;
    int arr[200];
    scanf("%d",&n);
    int  i;
    for(i=0;i<n;i++)scanf("%d",&arr[i]);
    qsort(arr,n,sizeof(int),Cmp);
    int min=GCD(arr[n-1],arr[n-2]),tmp;
        for(i=n-2;i>=1;i--){
            tmp=GCD(arr[i],arr[i-1]);
            min=GCD(tmp,min);
        }

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

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

int gcd(int a, int b){
    if(b==0)
        return a;
    else
    return gcd(b,a%b);
}

int main(){

int n=0;

while(scanf("%d",&n)!=EOF){

    int* x = (int*) malloc(sizeof(int)*n);
    int cgcd =1;

    int i=0, tmp=0;
    for (i;i<n;i++)
        scanf("%d",x+i);

    for (i=0;i<n-1;i++){
        tmp= gcd(x[i],x[i+1]);

        if(i!=0 && gcd(tmp,cgcd)==1){
            cgcd=1;
            break;
        }

        if(i==0 || tmp<cgcd)
            cgcd=tmp;
    }

    printf("%d\n",n==1?x[0]:cgcd*n);
}

return 0;
}

#include <stdio.h>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int i, n, g;
	static int x[100];

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &x[i]);
	g = x[0];
	for (i = 1; i < n; i++)
		g = gcd(g, x[i]);
	printf("%d\n", n * g);
	return 0;
}

#include <stdio.h>

int A(int a, int b)
{
	int c;

	if (a < b) {
		c = a;
		a = b;
		b = c;
	}
	while (b != 0)
		if (a - b > b)
			a = a - b;
		else {
			c = a - b;
			a = b;
			b = c;
		}

	return a;
}

int main()
{
	int a, b, c, d;

	scanf("%d%d", &a, &b);
	for (c = 1; c < a; ++c) {
		scanf("%d", &d);
		b = A(b, d);
	}
	printf("%d\n", b * a);

	return 0;
}

#include<stdio.h>
int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main()
{
    int i, n, sum = 0, arr[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    sum = gcd(arr[0], arr[1]);
    for(i = 1; i < n - 1; i++)
    {
        sum = gcd(sum, arr[i + 1]);
    }
    printf("%d", n * sum);
    return 0;
}

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
    int i,n,k,j,c=0,min=222222222,min2=222222222,flag=1,save;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(min>a[i])min=a[i];
    }
    save=min;
    while(flag){
        flag=0;
        for(i=0;i<n;i++){
            if(a[i]%min<min2&&a[i]%min!=0){min2=a[i]%min;}
            if(a[i]%min!=0)flag=1;
        }
    min=min2;
   }
   if(min==222222222)min=save;
   printf("%d",min*n);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,j,i,k,l=0,t,d,max,min,m;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
    max=arr[0];
    min=arr[0];
    for(j=1;j<n;j++)
    {
        if(arr[j]<min)
        min=arr[j];
        if(arr[j]>max)
        max=arr[j];
    }
    d=max;
    m=min;
    while(m!=0)
    {
        t=d%m;
        d=m;
        m=t;

    }
    for(j=0;j<n;j++)
    {
        if(arr[j]%d==1||d%arr[j]==1)
        {
            l=1;
            break;
        }
    }
    if(l==1)
    printf("%d",n);
    else
    printf("%d",n*d);

}

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

int gcd(int a,int b)
{
   if(a%b==0)
   return b;

   return gcd(b,a%b);
}

int main()
{
    int n;
    scanf("%d",&n);
    int hcf;
    scanf("%d",&hcf);
    for(int i=1;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        if(hcf>a)
            hcf = gcd(hcf,a);
        else
            hcf = gcd(a,hcf);

    }
    printf("%d\n",n*hcf);

}

#include<stdio.h>
int gcd(int a,int b)
{
	//printf("here3");

	if(a>b)
	{
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
	else
	{
		if(b%a==0)
			return a;
		return gcd(a,b%a);
	}
}
int main()
{
	//printf("%d",gcd(1,2));
	int n,m,a,b,g;
	scanf("%d",&n);
	m=n-1;
	scanf("%d",&a);
	g=a;
	//printf("here1");
	while(m--)
	{
		//printf("here2");
		scanf("%d",&b);
		g=gcd(g,b);
	}
	printf("%d",n*g);
	return 0;
}

#include<stdio.h>
int gcd(int , int);
int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n,x,i,y;
	scanf("%d",&n);
	scanf("%d",&x);
	for(i=1;i<n;i++)
	{
		scanf("%d",&y);
		x=gcd(x,y);
	}
	printf("%d",x*n);
	return 0;
}

#include<stdio.h>

unsigned gcd(unsigned x, unsigned y){
    unsigned wk;
    if(x<y){ wk=x;x=y;y=wk; }
    while(y){
        wk = x%y;
        x=y;
        y=wk;
    }
    return x;
}

int gcd_a(int n, int a[n]){
    if(n==1) return a[0];
    if(n==2) return gcd(a[0], a[1]);
    int h = n / 2;
    return gcd(gcd_a(h, &a[h-1]), gcd_a(n - h, &a[h]));
}

int main(){
int n,j;
int i=0;
scanf("%d",&n);
int A[n];
for(i=0;i<n;i++){
    scanf("%d",&A[i]);
}

    int size_A = sizeof(A)/sizeof(*A);
    int gcd = gcd_a(size_A, A);
    printf("%d\n", gcd*n);
    return 0;

}

#include<stdio.h>
int main()
{
    int n,i,x,d,t,z,c,j,k,s;
    z=0;
    scanf("%d",&n);
    int array[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&array[i]);

    }

  for (c = 1 ; c <= n - 1; c++)
   {
    d = c;

    while ( d > 0 && array[d] < array[d-1]) {
      t          = array[d];
      array[d]   = array[d-1];
      array[d-1] = t;

      d--;
    }
  }

      while(array[n-1]>array[0])

 {

    array[n-1]=array[n-1]-array[0];
       for (c = 1 ; c <= n - 1; c++) {
    d = c;

    while ( d > 0 && array[d] < array[d-1]) {
      t          = array[d];
      array[d]   = array[d-1];
      array[d-1] = t;

      d--;

  }
}

}

  for(i=0;i<n;i++)
  z=z+array[i];

  printf("%d",z);
  return 0;

}

#include <stdio.h>

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main()
{
    int n;
    scanf("%d", &n);
    int input[1000];
    for(int i = 0; i < n; i++)
        scanf("%d", &input[i]);
    int min = input[0];
    for(int i = 1; i < n; i++) {
        min = gcd(min,input[i]);
    }
    printf("%d\n", min * n);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a, const void *b)
{
	return *(int *)b-*(int *)a;
}
int main(void)
{
	int n,i,sum,min,t;
	int a[101];
	while(scanf("%d",&n)!=EOF)
	{
		min=100;
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		qsort(a,n,sizeof(int),cmp);
		for(i=0;i<n-1;i++)
		{
			t=a[i]-a[i+1];
			min=min<t?min:t;
		}
		printf("%d\n",min*n);
	}
	return 0;
}

#include<stdio.h>
int gcd(int , int);
int gcd(int a,int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}
int main()
{
	int n,x,i,y;
	scanf("%d",&n);
	scanf("%d",&x);
	for(i=1;i<n;i++)
	{
		scanf("%d",&y);
		x=gcd(x,y);
		printf("%d\n",x);
	}
	printf("%d",x*n);
	return 0;
}

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

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
   int i, j;
   for (i = 0; i < n-1; i++)

       // Last i elements are already in place
       for (j = 0; j < n-i-1; j++)
           if (arr[j] > arr[j+1])
              swap(&arr[j], &arr[j+1]);
}

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

	int a[n];
	for(int i=0;i<n;i++)
	{
 		scanf("%d",&a[i]);

	}

	bubbleSort(a,n);
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n;j++)
		{
			a[j]=a[j]-a[i];
			printf("%d ",a[j]);
		}
		printf("\n");
	}
	printf("%d",a[n-1]);
}

#include<stdio.h>
int main()
{
    int n,j,i,k,l=0,t,d,max,min,m;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    scanf("%d",&arr[i]);
    max=arr[0];
    min=arr[0];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(arr[i]-arr[j]==1)
            {
                l=1;
                break;
            }
        }
    }
    if(l==1)
    printf("%d",n);
    else
    {
    for(j=1;j<n;j++)
    {
        if(arr[j]<min)
        min=arr[j];
        if(arr[j]>max)
        max=arr[j];
    }
    d=max;
    m=min;
    while(m!=0)
    {
        t=d%m;
        d=m;
        m=t;

    }
    printf("%d",n*d);
}
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int i,j,arr[200],k;
	int sum=0;
	for(i=0;i<n;i++)
		scanf("%d", &arr[i]);
	for(k=0;k<n;k++)
	{
	for(i=0;i<n;i++)
	{
		int max=0;
		for(j=0;j<n;j++)
		{

			if(arr[i]>arr[j] && arr[j]>max)
		{
			//printf("%d ", j);
			max=arr[j];
			//("%d\n",max);
		}
		}
	arr[i]-=max;
	//printf("%d\n", arr[i]);

}
}
for(i=0;i<n;i++)
sum+=arr[i];
printf("%d", sum);
return 0;
}

#include<stdio.h>
int FindMax(int array[],int n);
int FindMin(int array[],int n);
int main(){
	int n,i=0;
	int array[100];
	scanf("%d",&n);
    do{
       scanf("%d",&array[i++]);
       }while(getchar()!='\n');
    printf("%d",FindMax(array,n)-FindMin(array,n));
    return 0;
}
int FindMax(int array[],int n){
	int max=array[0];
	int i=1;
	while(i<n){
		if(max<array[i]){
			max=array[i];
		}
		i++;
	}
	return max;
}
int FindMin(int array[],int n){
	int min=array[0];
	int i=1;
	while(i<n){
		if(min>array[i]){
			min=array[i];
		}
		i++;
	}
	return min;
}

#include<stdio.h>
#include<math.h>
main()
{
    int n,i,r;
    scanf("%d",&n);
    int arr[n];

    for(i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    int min = abs(arr[0]-arr[1]);
    for(i=1; i<n; i++)
    {
        r = abs(arr[i]-arr[i+1]);
        if(r<min)
        {
            min = r;
        }
    }
    if(min==0)
    {
        min = arr[0];
    }
    printf("%d\n",min*n);
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);

    printf("%d\n",a[0]*n);
    return 0;
}

 #include<stdio.h>
 #include<stdlib.h>
 int gcd(int a,int b);
 int main()
 {
 int n,*a,cd,i;
 scanf("%d",&n);
 a=(int*)malloc(n*sizeof(int));
 for(i=0;i<n;i++)
 scanf("%d",&a[i]);
 cd=gcd(a[0],a[1]);
 for(i=2;i<n;i++)
 {
 cd=gcd(cd,a[i]);
 }
 printf("%d",(n*cd));

 return 0;
 }
 int gcd(int a,int b)
 {
    if(a==0)
    return b;
    else if(b==0)
    return a;
    else if(a<b)
    gcd(a,b-a);
    else
    gcd(a-b,a);

 }

/* Problem: 389A - Fox and Number Game */
/* Solver: Gusztav Szmolik */

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

int cmp (const void*, const void*);

int main ()
    {
    unsigned short n;
    unsigned short i;
    unsigned short x[100];
    unsigned short gcd;
    unsigned short f;

    if (scanf("%hu",&n) != 1)
        return -1;
    if (n < 2 || n > 100)
        return -1;
    for (i = 0; i < n; i++)
        {
        if (scanf("%hu",&x[i]) != 1)
            return -1;
        if (x[i] < 1 || x[i] > 100)
            return -1;
        }
    qsort (x,n,sizeof(unsigned short),cmp);
    gcd = x[0];
    f = 0;
    while (gcd > 1 && !f)
        {
        f = 1;
        for (i = 1; i < n && f; i++)
            if (x[i]%gcd)
                f = 0;
        if (!f)
            {
            if (!(gcd%2))
                gcd /= 2;
            else if (!(gcd%3))
                gcd /= 3;
            else if (!(gcd%5))
                gcd /= 5;
            else if (!(gcd%7))
                gcd /= 7;
            else
                gcd = 1;
            }
        }
    printf ("%hu\n",gcd*n);
    return 0;
    }

int cmp (p1,p2)
    const void* p1;
    const void* p2;
    {
    unsigned short a;
    unsigned short b;

    a = *(unsigned short*)p1;
    b = *(unsigned short*)p2;
    if (a == b)
        return 0;
    return (a > b ? 1 : -1);
    }

#include<stdio.h>
#include<stdlib.h>
int comp(const void *p,const void *q);
int main(){
    int n,i,min=999,j;
    int x[1200];
    scanf("%d",&n);
    for(i=0;i<n;++i)
        scanf("%d",&x[i]);
    qsort(x,n,sizeof(int),comp);
    for(i=0;i<n;++i){
        for(j=i+1;j<n;++j)
            if(x[j]==x[i])
            min=x[i];
            if(x[j]-x[i]<min&&x[j]-x[i]>0)
                min=x[j]-x[i];
    }
    printf("%d\n",min*n);
return 0;
}
int comp(const void *p,const void *q){
    return (*(int *)p-*(int *)q);
}

 #include<stdio.h>
 #include<stdlib.h>
 int gcd(int a,int b);
 int main()
 {
 int n,*a,cd,i;
 scanf("%d",&n);
 a=(int*)malloc(n*sizeof(int));
 for(i=0;i<n;i++)
 scanf("%d",&a[i]);
 cd=gcd(a[0],a[1]);
 for(i=2;i<n;i++)
 {
 cd=gcd(cd,a[i]);
 }
 printf("%d",(n*cd));

 return 0;
 }
 int gcd(int a,int b)
 {
 	if(a==0)
 	return b;
 	else if(b==0)
 	return a;
 	else if(a<b)
 	gcd(a,b-a);
 	else
 	gcd(a-b,a);

 }

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{int a,b[101],c,d,e,f,n,w,g,j,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&a);
b[i]=a;
}
w=10000;
int ma(int a,int b);
for(i=0;i<n-1;i++)
{for(j=1;j<n;j++)
{

    g=ma(b[i],b[j]);
    if(g<w){w=g;}}
}//if(g<w){w=g;}//printf("%d %d\n",g,w);
printf("%d\n",n*w);
return 0;
}
int ma(int a,int b)
{int c=1,t,d;
if(a<b){d=a;a=b;b=d;}
if(a>b)
while(c!=0)
{c=a%b;//printf("88%d %d %d %d\n",t,a,b,c);
a=b;
t=b;
b=c;
}//printf("88%d %d %d %d\n",t,a,b,c);
return t;
}

#include <stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
    return *(int*)a-*(int*)b;
}
int main(void) {
    int n,i,sum;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    sum=arr[0];
    if(n!=1)
    {
        sum=0;
    qsort(arr,n,sizeof(int),cmp);
    while(1)
    {
    if(arr[n-2]==0||arr[n-1]<=arr[n-2])
    break;
    arr[n-1]=arr[n-1]-arr[n-2];
    qsort(arr,n,sizeof(int),cmp);
    }
    for(i=0;i<n;i++)
    sum=sum+arr[i];
    }
    printf("%d\n",sum);
    return 0;
}

#include<stdio.h>

#define MAX_NUMBERS 110

int gcd (int x, int y){
    if (x == 0)
        return y;
    else
        return gcd(y%x, x);
}

int main (){

    int n, i, g, numbers[MAX_NUMBERS];

    scanf("%d", &n);

    for (i=0; i<n; i++)
        scanf("%d", &numbers[i]);

    g = gcd(numbers[0], numbers[1]);
    for (i=2; i<n-1; i++){
        //Calculate gcd, running for the rest of the items in the array
        g = gcd(g, numbers[i]);
    }

    printf("%d\n", g*n);

    return 0;
}

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

int gcd(int a, int b)
{
	if(b == 0)
	       return a;
	else
		return gcd(b,a%b);
}

int main()
{
	int n,i,min=100,max=0;
	scanf("%d",&n);
	int x[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
		max = max>x[i]?max:x[i];
		min = min<x[i]?min:x[i];
	}
	int mingc = min;
	int j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(j != i)
				mingc = mingc<gcd(x[i],x[j]) ? mingc:gcd(x[i],x[j]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(x[i]%mingc != 0)
		{
			printf("%d\n",n);
			return 0;
		}
	}
	printf("%d\n",mingc);
	return 0;
}

#include<stdio.h>
int gcd(i,j)
{
    int temp;
    if(i==0)return j;
    if(j==0)return i;
    while(j!=0){
        temp=i;
        i=j;
        j=temp%j;
    }
    return i;
}
int main()
{
    int a,i,gd,sum;
    int b[101];
    while(scanf("%d",&a)==1){
        sum=0;

        for(i=0;i<a;i++){
            scanf("%d",&b[i]);
        }
        for(i=0;i<a-1;i++){
            gd=gcd(b[i],b[i+1]);
            b[i]=gd;
            b[i+1]=gd;
        }
        for(i=0;i<a;i++){
            sum=sum+b[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}

/* Problem: 389A - Fox and Number Game */
/* Solver: Gusztav Szmolik */

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

int cmp (const void*, const void*);

int main ()
    {
    unsigned short n;
    unsigned short i;
    unsigned short x[100];
    unsigned short gcd;
    unsigned short f;

    if (scanf("%hu",&n) != 1)
        return -1;
    if (n < 2 || n > 100)
        return -1;
    for (i = 0; i < n; i++)
        {
        if (scanf("%hu",&x[i]) != 1)
            return -1;
        if (x[i] < 1 || x[i] > 100)
            return -1;
        }
    qsort (x,n,sizeof(unsigned short),cmp);
    gcd = x[0];
    f = 0;
    while (gcd > 1 && !f)
        {
        f = 1;
        for (i = 1; i < n && f; i++)
            if (x[i]%gcd)
                f = 0;
        if (!f)
            {
            if (gcd == x[0])
                gcd /= 2;
            else
                gcd--;
            }
        }
    printf ("%hu\n",gcd*n);
    return 0;
    }

int cmp (p1,p2)
    const void* p1;
    const void* p2;
    {
    unsigned short a;
    unsigned short b;

    a = *(unsigned short*)p1;
    b = *(unsigned short*)p2;
    if (a == b)
        return 0;
    return (a > b ? 1 : -1);
    }

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);
    while(a[n-1]!=a[0]){
        qsort(a,n,sizeof(int),f);
        for(i=n;i>=1;i--){
                if(a[i]-a[i-1]>0)
            a[i]=a[i]-a[i-1];
        }
        l++;
    }
    int s=0;
    for(i=0;i<n;i++){
        s=s+a[i];
    }
    printf("%d\n",s);
    return 0;
}

#include<stdio.h>
int solve(int a,int b)
{
    while(a!=b)
    {
        if(a>b)
        a-=b;
        else
        b-=a;
    }
    return a;
}
int main()
{
    int a,b,sum=0,ans,n;
    scanf("%d",&n);
    scanf("%d%d",&a,&b);
    ans=solve(a,b);
    sum+=ans*2;
    n-=2;
    while(n--)
    {
        scanf("%d",&a);
        ans=solve(ans,a);
        sum+=ans;
    }
    printf("%d",sum);
}

#include<stdio.h>
int comp(const void * a,const void *b);
int main(){
    int n;
    scanf("%d",&n);
    int i,j,ans=0;
    int num[n];
    int temp;
    for(i=0;i<n;i++)
        scanf("%d",&num[i]);
    qsort((void*)num,n,sizeof(int),comp);
    temp=num[n-1];
    for(i=n-2;i>=0;i--){
        for(j=n-2;j>=0;j--){
            if(temp>num[j]){
                temp=temp-num[j];
            }
        }
        ans+=num[i];
    }
    printf("%d\n",temp*n);
    return 0;
}

int comp(const void * a,const void *b){
    return *(int*)a>*(int*)b?1:-1;
}

#include<stdio.h>
int hcf(int a,int b)
 {
   if((b%a)==0)
    return a;
   else
    return hcf(b%a,a);

 }
int main()
{
   int a,cnt=0,j,c,d,dum,arr[109]={0},n,i,k,b,ans1,ans2;
   scanf("%d",&n);
    for(i=0;i<n;i++)
       {
           scanf("%d",&arr[i]);
       }
    for(i=0,j=n-1;i<=n-2,j>=1;i++,j--)
       {
            a=arr[i];b=arr[i+1];
            c=arr[j];d=arr[j-1];
              if(a>b)
                {
                   k=b;b=a;a=k;
                }
               ans1=hcf(a,b);
              if(c>d)
                {
                  dum=d;d=c;c=dum;
                }
               ans2=hcf(c,d);
             arr[i]=ans1;arr[i+1]=ans1;
             arr[j]=ans2;arr[j-1]=ans2;
       }
     for(i=0;i<n;i++)
       {
          cnt+=arr[i];
       }
      printf("%d\n",cnt);
 return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    int t;
    while(b!=0)
    {
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int main ()
{
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    int max=a[0];
    for(i=1;i<n;i++)
    {
        int x=gcd(a[i],a[0]);
        if(x<max && x!=1) max=x;
    }
    printf("%d",max*n);
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{if(b%a==0)
return a;
else
return gcd(b%a,a);}

int main()
{
int k,i,j,n,a[100],l=0,t=0,sum=0,min,gc=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
if(i==0)
min=a[i];
else if(min>a[i])
min=a[i];}
l=min;t=min;
for(i=0;i<n;i++)
{
if(min!=a[i])
{t=gcd(min,a[i]);}
if(l>t)
l=t;}
printf("%d",n*l);
return 0;
}

#include<stdio.h>

unsigned gcd(unsigned x, unsigned y){
    unsigned wk;
    if(x<y){ wk=x;x=y;y=wk; }
    while(y){
        wk = x%y;
        x=y;
        y=wk;
    }
    return x;
}

int gcd_a(int n, int a[n]){
    if(n==1) return a[0];
    if(n==2) return gcd(a[0], a[1]);
    int h = n / 2;
    return gcd(gcd_a(h, &a[h-1]), gcd_a(n - h, &a[h]));
}

int main(){
int n,j;
int i=0;
scanf("%d",&n);
int A[n];
for(i=1;i<n;i++){
    scanf("%d",&A[i]);
}

    int size_A = sizeof(A)/sizeof(*A);
    int gcd = gcd_a(size_A, A);
    printf("%d\n", gcd*n);
    return 0;

}

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

int main(){

    int n,i,j=0;
    scanf("%d",&n);
    int a[100];
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
        if(a[i]>a[i-1]){
            a[i]-=a[i-1];
        }
    }
    for(j=0; j<n; j++){
        for(i=0; i<n; i++){
            if(a[i]>a[j]){
                a[i]-=a[j];
                continue;
            }
            if(a[j]>a[i]){
                a[j]-=a[i];
            }
        }
    }
    int sum=0;
    for(i=0; i<n; i++){
        sum+=a[i];
    }
    printf("%d",sum);
    return 0;
}

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

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n&&i+1<n;i++)
    {
        while(arr[i]!=arr[i+1])
        {
            if(arr[i]>arr[i+1])
            {
                arr[i]=arr[i]-arr[i+1];
            }
            else if(arr[i]<arr[i+1])
            {
                arr[i+1]=arr[i+1]-arr[i];
            }
        }
    }
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int cmpfn (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
    int arr[100];
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    int sum,p_sum;
    p_sum = INT_MAX;
    sum = 0;
    qsort(arr,n,sizeof(int),cmpfn);
        for(i=n-1;i>=0;i--)
        {
            if(arr[i]>arr[i-1])
                arr[i] = arr[i]-arr[i-1];
            sum+=arr[i];
        }
    while(sum<p_sum)
    {
        p_sum = sum;
        sum = 0;
        qsort(arr,n,sizeof(int),cmpfn);
        for(i=n-1;i>=0;i--)
        {
            if(arr[i]>arr[i-1])
                arr[i] = arr[i]-arr[i-1];
            sum+=arr[i];
        }
    }
    printf("%d",p_sum);
    return 0;
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);

    printf("%d\n",a[0]*n);
    return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
	int n,f,mini,i,s,j;
	scanf("%d",&n);
	int ara[100000];
	for (i=0;i<n;i++){
		scanf("%d",&ara[i]);
	}
	mini=abs(ara[0]-ara[1]);
	for (i=0;i<n-1;i++){
		for (j=i+1;j<n;j++){
		s=abs(ara[i]-ara[j]);
		if (s<=mini){
			mini=s;

		}
		}

	}
	f=mini*n;
	printf("%d",f);
	return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
int main()
{
	int arr[100],sum,i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&arr[i]);
    sum=gcd(arr[0],arr[1]);
    for(i=2;i<n;i++)
    {
    	sum=gcd(arr[i],sum);
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int main()
{
	int n,j,i,k,l,t,d,max,min,m;
	scanf("%d",&n);
	int arr[n];
	for(i=0;i<n;i++)
	scanf("%d",&arr[i]);
	max=arr[0];
	min=arr[0];
	for(j=1;j<n;j++)
	{
		if(arr[j]<min)
		min=arr[j];
		if(arr[j]>max)
		max=arr[j];
	}
	d=max;
	m=min;
	while(m!=0)
	{
		t=d%m;
		d=m;
		m=t;

	}
	printf("%d",n*d);

}

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

int main(){
    int n[200];
    int T;
    int i,j;
    int firMax = 0;
    int secMax = 0;
    n[0] = 0;
    int sum = 0;
    scanf("%d", &T);
    for(i = 1; i <= T; i++){
        scanf("%d", &n[i]);
        if(n[i] >= n[firMax]){
            secMax = firMax;
            firMax = i;
        }else if(n[i] >= n[secMax]){
            secMax = i;
        }
    }
    //printf("FirstMax[%d]:%d\nSecondMax[%d]:%d\n", firMax, n[firMax], secMax, n[secMax]);
    while(n[firMax] - n[secMax] != 0){
        n[firMax] -= n[secMax];
        firMax = 0;
        secMax = 0;
        for(i = 1; i<= T; i++){
            if(n[i] >= n[firMax]){
                secMax = firMax;
                firMax = i;
            }else if(n[i] >= n[secMax]){
                secMax = i;
            }
        }
    }
    for(i = 1; i <= T; i++){
        sum += n[i];
    }
    printf("%d", sum);
    return 0;
}

#include <stdio.h>
#include <math.h>
int main()
{
	int n,f,mini,i,s,j,r;
	scanf("%d",&n);
	int ara[100000];
	for (i=0;i<n;i++){
		scanf("%d",&ara[i]);
	}
	r=0;
	for (i=0;i<n-1;i++){
		if (ara[i]!=ara[i+1]){
			r=1;
			break;
		}
	}
	if (r==0){
		printf("%d",n*ara[0]);
	}
	else{
	mini=100;
	for (i=0;i<n-1;i++){
		for (j=i+1;j<n;j++){
		s=abs(ara[i]-ara[j]);
		if (s<mini && s>0){
			mini=s;

		}
		}

	}
	f=mini*n;
	printf("%d",f);
	}
	return 0;
}

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

int gcd(int a, int b){
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

int main(){

int n=0;

while(scanf("%d",&n)!=EOF){

    int* x = (int*) malloc(sizeof(int)*n);

    int i=0, tmp=0;
    for (i;i<n;i++)
        scanf("%d",x+i);

    int cgcd =x[0];

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

        if(n==1)
            break;

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

        tmp= gcd(x[i], x[j]);

        if(tmp < cgcd)
            cgcd=tmp;

        }

    }
    printf("%d\n",n==1?x[0]:cgcd*n);
}

return 0;
}

#include <stdio.h>
#include <stdlib.h>
/* Written by Nishant Mittal aka nishantwrp */
int main()
{
   int n;
   scanf("%d",&n);
   int data[n];
   int i=0;
while(i<n) {
scanf("%d",&data[i]);
i++;
}
int mincount=0;
while(mincount!=n) {
        mincount = 0;
int max=0;
int maxl;
int min=0;
int j=0;
while(j<n) {
if (data[j] < min || min ==0){
    min = data[j];
}
if (data[j] > max || max==0) {
    max = data[j];
    maxl=j;
}
if (data[j] == min) {
    mincount++;
}
j++;
}
if (mincount != n) {
if (max %  min == 0) {
    data[maxl] = min;
} else {
int c,d;
c = max/min;
d = max - ((c)*min);
data[maxl] = d;
}
} else {
printf("%d",n*min);
}
}
    return 0;
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);

        for(i=n;i>=1;i--){
            a[i]=a[i]-a[i-1];
        }
qsort(a,n,sizeof(int),f);
    int s=0;

    printf("%d\n",n*a[0]);
    return 0;
}

#include<stdio.h>
int main()
{
    int i, n, j, sum = 0;
    scanf("%d", &n);
    fflush(stdin);
    int arr[n];
    for(i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    for(i = 0; i < n; i++)
    {
        for(j = i; j < n; j++)
        {
            if(arr[i] > arr[j])
                arr[i] = arr[i] - arr[j];
        }
    }
    for(i = 0; i < n; i++)
    {
        for(j = i; j < n; j++)
        {
            if(arr[i] < arr[j])
                arr[j] = arr[j] - arr[i];
        }
    }
    for(i = 0; i < n; i++)
        sum += arr[i];
    printf("%d", sum);
}

#include<stdio.h>
#include<stdlib.h>
int hcf(int *j,int n)
{
    int i,l,k,p,m;
    k=1;
    for(i=2;i<13;i++)
    {
                     m=0;
                     //printf("c");
                     for(l=0;l<n;l++)
                     {
                                     //printf("d");
                                     p=*(j+l);
                                     //printf("%d",p);
                                     if((p%i)==0)
                                     m++;
                                     //printf("e");
                     }
                     if(m==n&&i>k)
                     k=i;
                    // printf("%d\n",m);
    }
    return(k);
}
int main()
{
    int i,j,k,l,m,n,p,a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    //printf("b\n");
    j=hcf(a,n);
    k=j*n;
    printf("%d",k);
    //system("pause");
    return(0);
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);
    while(a[0]>0){
        qsort(a,n,sizeof(int),f);
        for(i=n;i>=1;i--){
            a[i]=a[i]-a[i-1];
        }
        l++;
    }
    int s=0;
    for(i=0;i<n;i++){
        s=s+a[i];
    }
    printf("%d\n",s);
    return 0;
}

#include <stdio.h>
int main()
{
    int n, a[101], i, min, flag;
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }

    flag=1;
    while(flag==1)
    {
        min=101;
        flag=0;
        for(i=0; i<n; i++)
        {
            if(min>a[i])
            {
                min=a[i];
            }
        }

        for(i=0; i<n; i++)
        {
            while(a[i]-min>0)
                a[i]-=min;
        }

        for(i=1; i<n; i++)
        {
            if(a[i]!=a[i-1])
                flag=1;
        }
    }

    int sum=0;
    for(i=0; i<n; i++)
    {
        printf("%d ", a[i]);
        sum+=a[i];
    }

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

#include <stdio.h>
#include<math.h>
#include<string.h>
int main(void) {
int n,freq,i,j,temp,d;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
  scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
  for(j=i+1;j<n;j++){
if(a[i]>a[j]){
  temp=a[i];
  a[i]=a[j];
  a[j]=temp;
}
  }
}
d=a[n-1]-a[0];
for(i=d;i>=1;i--){freq=0;
  for(j=0;j<n;j++){
    if(a[j]%i==0){
      freq++;
    }
  }
  if(freq==n){
    break;
  }
}
printf("%d",i*n);
  return 0;
}

 #include<stdio.h>
 #include<stdlib.h>
 int gcd(int a,int b);
 int main()
 {
 int n,*a,cd,i;
 scanf("%d",&n);
 a=(int*)malloc(n*sizeof(int));
 for(i=0;i<n;i++)
 scanf("%d",&a[i]);
 cd=gcd(a[0],a[1]);
 for(i=2;i<n;i++)
 {
 cd=gcd(cd,a[i]);
 }
 printf("%d",(n*cd));

 return 0;
 }
 int gcd(int a,int b)
 {
    if(a==0)
    return b;
    else if(b==0)
    return a;
    else if(a<b)
    gcd(a,b-a);
    else
    gcd(a-b,a);

 }

#include <stdio.h>

int a[100];

int reduce(int *a, int size){
	int m1 = 0, m2 = -1;
	for(int i =1 ; i < size; i++ ){
		if ( a[m1] < a[i] ){
			m2 = m1;
			m1 = i;
		}
	}
	if ( m2 == -1 ) m2 = 1;
	//printf( "Found max %d %d, %d %d\n", a[m1], a[m2] , m1, m2);
	if ( a[m1] - a[m2] <= 0)
		return 0;
	a[m1] -= a[m2];
	return 1;
}

int sum ( int *a, int size ){
	int res = 0;
	for(int i = 0; i < size ;i++){
		res += a[i];
	}
	return res;
}

int main(){
	int n, i=0;
	scanf("%d", &n);
	for(int i = 0 ; i < n ; i++ )
		scanf("%d", &a[i]);
	while ( reduce(a, n));
	printf("%d\n", sum(a, n));
}

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

int main()
{
    int n , A[200]={0},  Result=0,i,j,temp;
    scanf("%d",&n);
for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
        }
        for (i=1;i<n;i++)
    {
        for(j=0;j<(n-i);j++)
        {
            if (A[j]<A[j+1])
            {
                temp=A[j];
            A[j]=A[j+1];
            A[j+1]=temp;
            }
        }
    }

    while(A[0]>A[1])
    {
        if(A[0]==A[n-1])
        {
            break;}
           for(i=0;i<n;i++)
    {

       A[i]=A[i]-A[i+1];
        }
        for (i=1;i<n;i++)
    {
        for(j=0;j<(n-i);j++)
        {
            if (A[j]>A[j+1])
            {
                temp=A[j];
            A[j]=A[j+1];
            A[j+1]=temp;
            }
        }
    }

    }

       Result=A[0]*n;    printf("%d",Result);

    return 0;
}

#include<stdio.h>
#include<math.h>
main()
{
    int n,i,r;
    scanf("%d",&n);
    int arr[n];

    for(i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    int min = abs(arr[0]-arr[1]);
    for(i=1; i<n; i++)
    {
        r = abs(arr[i]-arr[i+1]);
        if(r<min)
        {
            min = r;
        }
    }
    printf("%d\n",min*n);
}

#include<stdio.h>
int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main()
{
    int i, n, sum = 0, arr[100];
    for(i = 0; i < 100; i++)
            arr[i] = 0;
    scanf("%d", &n);
    fflush(stdin);
    for(i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    sum = arr[0];
    for(i = 0; i < n - 1; i++)
    {
        sum = gcd(sum, arr[i + 1]);
    }
    printf("%d", n * sum);
    return 0;
}

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

int gcd(int a, int b){
    if(b==0)
        return a;
    else
    return gcd(b,a%b);
}

int main(){

int n=0;

while(scanf("%d",&n)!=EOF){

    int* x = (int*) malloc(sizeof(int)*n);
    int cgcd =1;

    int i=0, tmp=0;
    for (i;i<n;i++)
        scanf("%d",x+i);

    for (i=0;i<n-1;i++){
        tmp= gcd(x[i],x[i+1]);

        if( n==1 || gcd(tmp,cgcd)==1){
            cgcd=1;
            break;
        }

        if(i==0 || tmp<cgcd)
            cgcd=tmp;
    }

    printf("%d\n",n==1?x[0]:cgcd*n);
}

return 0;
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);
while(a[n-1]-a[0]>0){
        for(i=n;i>=1;i--){
                if(a[i]-a[i-1]>0)
            a[i]=a[i]-a[i-1];
        }
}
qsort(a,n,sizeof(int),f);
    int s=0;

    printf("%d\n",n*a[0]);
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int comp(const void*a,const void*b){
    return *(int*)a - *(int*)b;
}

int main(){
    long long n,i,j,min;
    int t[105];
    while(scanf("%I64d",&n)!=EOF){
        for(i=0;i<n;i++){
            scanf("%d",&t[i]);
        }
        qsort(t,n,sizeof(int),comp);
        for(i=0,min=2147483647;i<n;i++){
            for(j=i+1;j<n;j++){
                min = MIN(min,t[j]-t[i]);
            }
        }
        printf("%I64d\n",min*n);
    }
    return 0;
}

#include<stdio.h>
int gcd(i,j)
{
    int temp;
    if(i==0)return j;
    if(j==0)return i;
    while(j!=0){
        temp=i;
        i=j;
        j=temp%j;
    }
    return i;
}
int main()
{
    int a,i,gd,sum;
    int b[101];
    while(scanf("%d",&a)==1){
        sum=0;

        for(i=0;i<a;i++){
            scanf("%d",&b[i]);
        }
        for(i=0;i<a-1;i++){
            gd=gcd(b[i],b[i+1]);
            b[i]=gd;
            b[i+1]=gd;
        }
        for(i=0;i<a;i++){
            sum=sum+b[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}

#include <stdio.h>

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main()
{
    int n;
    scanf("%d", &n);
    int input[101];
    for(int i = 0; i < n; i++)
        scanf("%d", &input[i]);
    int min = 1e9;
    for(int i = 0; i < n - 1; i++) {
        if(gcd(input[i], input[i + 1]) < min)
            min = gcd(input[i], input[i + 1]);
    }
    printf("%d\n", min * n);
    return 0;
}

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

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n-1;i++)
    {
        while(arr[i]!=arr[i+1])
        {
            if(arr[i]>arr[i+1])
            {
                arr[i]=arr[i]-arr[i+1];
            }
            else if(arr[i]<arr[i+1])
            {
                arr[i+1]=arr[i+1]-arr[i];
            }
        }
    }
    for(i=0;i<n;i++)
    {
        sum=sum+arr[i];
    }
    printf("%d",sum);
    return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    int t;
    while(b!=0)
    {
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int main ()
{
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    int max=a[0];
    for(i=1;i<n;i++)
    {
        int x=gcd(a[i],a[0]);
        if(x<max && x!=1) max=x;
        if(x==1) {max=1;break;}
    }
    printf("%d",max*n);
    return 0;
}

#include<stdio.h>
int main()
{
	int a[101],i,n,j,sum=0,min=100000,flag,cnt,rem;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(min>a[i])
		{
			min=a[i];
		}
	}
	rem=min;
	while(flag==0)
	{
		min=rem;
		for(i=0;i<n;i++)
		{
			if(a[i]%min==0)
			{
				a[i]=min;
			}
			else
			{
				a[i]=a[i]%min;
			}
			if(rem>a[i])
			{
				rem=a[i];
			}
		}
		if(rem==min)
		{
			flag=1;
		}
	}
	for(i=0;i<n;i++)
	{
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

#include <stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			while(a[i]>a[j]){
				a[i]-=a[j];
			}
			while(a[j]>a[i]){
				a[j]-=a[i];
			}
		}
	}

	int num=0;
	for(int i=0;i<n;i++){
		num+=a[i];
	}
	printf("%d",num);
}

#include <stdio.h>

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main()
{
    int n;
    scanf("%d", &n);
    int input[101];
    for(int i = 0; i < n; i++)
        scanf("%d", &input[i]);
    int min = 1e9;
    for(int i = 0; i < n - 1; i++) {
        if(gcd(input[i], input[i + 1]) < min)
            min = gcd(input[i], input[i + 1]);
    }
    printf("%d", min * n);
    return 0;
}

#include<stdio.h>
int n;
int hcf(int a,int b)
{
	int k,l,o=1,i;
	k=b;
	for(i=1;i<=k;i++)
	{
		if((a%i==0)&&(b%i==0))
		{
			o=i;
		}
	}
	return o;
}
int main()
{
	int i,j,k,l=0,a2;
	int ans,sum=0,min=100000,max=0;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(max<a[i])
			max=a[i];
		if(min>a[i])
			min=a[i];

	}
	ans=hcf(max,min);
	printf("%d",ans*n);
	return 0;
}

#include<stdio.h>
#include<math.h>
main()
{
    int n,i,r;
    scanf("%d",&n);
    int arr[n];

    for(i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    int min = abs(arr[0]-arr[1]);
    for(i=1; i<n; i++)
    {
        r = abs(arr[i]-arr[i+1]);
        if(r<min)
        {
            min = r;
        }
    }
    if(min==0)
    {
        min = arr[0];
    }
    printf("%d\n",min*n);
}

#include<stdio.h>
int f(const void *a,const void *b){
return (*(int*)a-*(int*)b);
}
int main()
{
    int i,j,n,l=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    qsort(a,n,sizeof(int),f);
    while(a[0]>0){
        qsort(a,n,sizeof(int),f);
        for(i=n;i>=1;i--){
            a[i]=a[i]-a[i-1];
        }
        l++;
    }
    int s=0;
    for(i=0;i<n;i++){
        s=s+a[i];
    }
    printf("%d\n",s);
    return 0;
}

#include<stdio.h>
int gcd(i,j)
{
    int temp;
    if(i==0)return j;
    if(j==0)return i;
    while(j!=0){
        temp=i;
        i=j;
        j=temp%j;
    }
    return i;
}
int main()
{
    int a,i,gd,sum;
    while(scanf("%d",&a)==1){
        sum=0;
        int b[a];
        for(i=0;i<a;i++){
            scanf("%d",&b[i]);
        }
        for(i=0;i<a-1;i++){
            gd=gcd(b[i],b[i+1]);
            b[i]=gd;
            b[i+1]=gd;
        }
        for(i=0;i<a;i++){
            sum=sum+b[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}

#include <stdio.h>

int gcd(int a, int b)
{
    if(b == 0)
        return a;
    else
        return gcd(b, a % b);
}

int main()
{
    int n;
    scanf("%d", &n);
    int input[1000];
    for(int i = 0; i < n; i++)
        scanf("%d", &input[i]);
    int min = 1e9;
    for(int i = 0; i < n - 2; i++) {
        if(gcd(input[i], input[i + 1]) < min)
            min = gcd(input[i], input[i + 1]);
    }
    printf("%d\n", min * n);
    return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);
	int i,j,arr[200],k;
	int sum=0;
	for(i=0;i<n;i++)
		scanf("%d", &arr[i]);
	for(k=0;k<n;k++)
	{
	for(i=0;i<n;i++)
	{
		int max=0;
		for(j=0;j<n;j++)
		{

			if(arr[i]>arr[j] && arr[j]>max)
		{
			//printf("%d ", j);
			max=arr[j];
			//("%d\n",max);
		}
		}
	arr[i]-=max;
	//printf("%d\n", arr[i]);

}
}
for(i=0;i<n;i++)
sum+=arr[i];
printf("%d", sum);
return 0;
}

#include<stdio.h>
int gcd(int a,int b)
{
    int t;
    while(b!=0)
    {
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}
int main ()
{
    int n,i;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    int max=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]==1) continue;
        int x=gcd(a[i],a[0]);
        if(x<max && x!=1) max=x;
    }
    printf("%d",max*n);
    return 0;
}

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

#define SWAP(X, Y) { int T = X; X = Y; Y = T; }

int partition (int *arr, int left, int right);
void quickSort (int *arr, int left, int right);
int min (int *arr, int n);
void perasma (int *arr, int n, int s);

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

	int i, nums[n];
	for (i = 0; i < n; i++)
		scanf("%d", &nums[i]);

	quickSort(nums, 0, n - 1);

/*	printf("SORTED\n");
	for (i = 0; i < n; i++)
		printf("\t%d", nums[i]);
	printf("\n");
*/
	for (i = 0; i < n; i++)
		perasma(nums, n, i);
	printf("PRINTF\n");
	for (i = 0; i < n; i++)
		perasma(nums, n, i);

	printf("%d\n", n * min(nums, n));

	return 0;
}

void perasma (int *arr, int n, int s)
{
	int j, quot, rem;
	for (j = s + 1; j < n; j++) {
		quot = arr[s] / arr[j];
		rem = arr[s] % arr[j];
		if (rem != 0)
			arr[s] -= quot * arr[j];
		else
			arr[s] -= (quot - 1) * arr[j];
	}
	for (j = 0; j < s; j++) {
		quot = arr[s] / arr[j];
		rem = arr[s] % arr[j];
		if (rem != 0)
			arr[s] -= quot * arr[j];
		else
			arr[s] -= (quot - 1) * arr[j];
	}
}

int min (int *arr, int n)
{
	int i, ret = arr[0];
	for (i = 1; i < n; i++)
		if (arr[i] < ret)
			ret = arr[i];
	return ret;
}

int partition (int *arr, int left, int right)
{
	int pivot = arr[left],
	    i = left - 1,
	    j = right + 1;
	while (1) {
		while (arr[++i] > pivot);
		while (arr[--j] < pivot);
		if (i < j) {
			SWAP(arr[i], arr[j]);
		}
		else
			return j;
	}
}

void quickSort (int *arr, int left, int right)
{
	if (left >= right)
		return;
	int q = partition(arr, left, right);
	quickSort(arr, left, q);
	quickSort(arr, q + 1, right);
}

#include<stdio.h>
int solve(int a,int b)
{
    while(a!=b)
    {
        if(a>b)
        a-=b;
        else
        b-=a;
    }
    return a;
}
int main()
{
    int a,b,sum=0,ans,n;
    scanf("%d",&n);
    scanf("%d%d",&a,&b);
    ans=solve(a,b);
    sum+=ans*2;
    n-=2;
    while(n--)
    {
        scanf("%d",&a);
        ans=solve(ans,a);
        sum+=ans;
    }
    printf("%d",sum);
}

#include <stdio.h>
#include <stdlib.h>
int factor(int a,int b)
{
    while(a != b)
    {
        if(a>b)
            a-=b;
        else if(a<b)
            b-=a;
    }
        return a;
}
int main()
{
    int n;
    scanf("%d",&n);
    int num[200]= {0},ans=1000000;
    for(int i=0; i<n; i++)
        scanf("%d",&num[i]);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
                 if(factor(num[i],num[j])<ans)
                    ans=factor(num[i],num[j]);
        }
    }
    printf("%d\n",ans*n);
    return 0;
}


During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.Cube is called solved if for each face of cube all squares on it has the same color.https://en.wikipedia.org/wiki/Rubik's_Cube

In first line given a sequence of 24 integers ai (1 ≤ ai ≤ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.

Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.

NoteIn first test case cube looks like this:  In second test case cube looks like this:   It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.

#include<stdio.h>

int check_equal(int arr[],int a,int b,int c,int d){
    if(arr[a]==arr[b] && arr[b]==arr[c] && arr[c]==arr[d])
        return 1;
    return 0;
}

int main(){
    int i,arr[25];
    for(i=1;i<=24;i++){
        scanf("%d",&arr[i]);
    }
    if(check_equal(arr,13,14,15,16) && check_equal(arr,17,18,19,20)){
        if(check_equal(arr,1,3,6,8) && check_equal(arr,2,4,22,24) && check_equal(arr,5,7,10,12) && check_equal(arr,9,11,21,23))
            printf("yes");
        else if(check_equal(arr,2,4,5,7) && check_equal(arr,1,3,21,23) && check_equal(arr,6,8,9,11) && check_equal(arr,10,12,22,24))
            printf("yes");
        else
            printf("no");
    }
    else if(check_equal(arr,1,2,3,4) && check_equal(arr,9,10,11,12)){
        if(check_equal(arr,13,14,7,8) && check_equal(arr,5,6,19,20) && check_equal(arr,17,18,23,24) && check_equal(arr,21,22,15,16))
            printf("yes");
        else if(check_equal(arr,5,6,15,16) && check_equal(arr,17,18,7,8) && check_equal(arr,21,22,19,20) && check_equal(arr,13,14,23,24))
            printf("yes");
        else
            printf("no");
    }
    else if(check_equal(arr,5,6,7,8) && check_equal(arr,21,22,23,24)){
        if(check_equal(arr,1,2,14,16) && check_equal(arr,3,4,18,20) && check_equal(arr,17,19,11,12) && check_equal(arr,9,10,13,15))
            printf("yes");
        else if(check_equal(arr,3,4,13,15) && check_equal(arr,14,16,11,12) && check_equal(arr,9,10,18,20) && check_equal(arr,17,19,1,2))
            printf("yes");
        else
            printf("no");
    }
    else
        printf("no");
    return 0;
}

#include <stdio.h>
#include <string.h>
#define LL long long
#define uLL unsigned long long
#define uL unsigned long
#define uC unsigned char
long temp[100000];
void print(long *a,long size)
{
	long i;
	for (i=1;i<=size;i++)
	{
		printf("%ld,",a[i]);
	}
	printf("\n---\n");
}
void print2(long *a,long size)
{
	long i;
	for (i=1;i<=size;i++)
	{
		printf("%ld[%ld],",a[i],i);
	}
	printf("\n---\n");
}
void copy(long *a,long *b)
{
	long i;for (i=0;i<=b[0];i++) {a[i]=b[i];}
}
///////////////////////////////////////////////////////////////
int PermutationValid(long *pol)
{
	long i,j,k;
	for (i=1;i<=*pol;i++)
	{
		if (pol[i]>*pol) {return 0;}
		if (0-pol[i]>*pol) {return 0;}
		if (pol[i]==0) {return 0;}
		if (pol[pol[i]]<0) {return 0;}
		pol[pol[i]]=0-pol[pol[i]];
	}
	for (i=1;i<=*pol;i++) {pol[i]=0-pol[i];}
	return 1;
}
void ColorTransfer(long *color,long *pol,long *ans)
{
	long i,j,k;
	for (i=1;i<=pol[0];i++)
	{
		ans[pol[i]]=color[i];
	}
}
void PermutationTransfer(long *pol1,long *pol2,long *ans)
{
	static long i,j,k;
	for (i=1;i<=pol1[0];i++)
	{
		ans[i]=pol2[pol1[i]];
	}
	ans[0]=pol1[0];
}
void PermutationInverse(long *pol,long *ans)
{
	static long i,j,k;
	for (i=1;i<=pol[0];i++)
	{
		ans[pol[i]]=i;
	}
	ans[0]=pol[0];
}
void PermutationFactoring(long *pol,long *ans)
{
	long i,j,k,a,b,c;
	long *stack=temp;*stack=0;
	memcpy(ans,pol,sizeof(pol)*(*pol+1));
	for (i=1;i<*pol;i++)
	{
		if (ans[i]>0)
		{
			for (j=i;ans[j]>0;j=stack[*stack]) {stack[++(*stack)]=ans[j];ans[j]=0;}
			stack[++(*stack)]=0;
		}
	}
	*ans=1;j=1;
	for (i=1;i<=*stack;i++)
	{
		if (stack[i]>0)
		{
			ans[++(*ans)]=stack[i];
		}
		else
		{
			ans[j]=i-j;j=i;*ans+=1;
		}
	}
}
void Cycles2Permutation(long *cycles,long *ans,long len)
{
	long i,j,k;
	for (i=1;i<=len;i++) {ans[i]=i;}*ans=len;
	k=1;
	for (i=1;i<=*cycles;i++)
	{
		for (j=k+1;j<k+cycles[k];j++)
		{
			ans[cycles[j]]=cycles[j+1];
		}
		ans[cycles[j]]=cycles[k+1];
		k=j+1;
	}
}
//////////////////////////////////////
#define PPPP 50
long pcr[][PPPP]={{1},{6,
				   4,1,3,4,2,
				   4,9,10,12,11,
				   4,13,5,17,21,
				   4,15,7,19,23,
				   4,16,8,20,24,
				   4,14,6,18,22}};
long pcf[][PPPP]={{1},{6,
				   4,13,14,16,15,
				   4,17,19,20,18,
				   4,1,5,9,24,
				   4,2,6,10,23,
				   4,3,7,11,22,
				   4,4,8,12,21}};
long pco[][PPPP]={{1},{3,
				  4,6,5,7,8,
				  4,3,16,10,17,
				  4,4,14,9,19}};
//////////////////////////////////////

long id[PPPP],flip[10][PPPP],rotate[10][PPPP],opr[10][PPPP],fsize,rsize,osize;
long gg[100][PPPP],gsize;
long pg[100000][PPPP],psize;
void RubikCube(long size,long rt,long dep)
{
	long i,j,k,l1,l2,a,b,c;
	long t1[PPPP],t2[PPPP],t3[PPPP];
	for (i=1;i<=size;i++) {id[i]=i;}*id=size;
	//////////////////////
	//Basic Permutations//
	//////////////////////
	rsize=**pcr<<1;
	for (i=1;i<=**pcr;i++){Cycles2Permutation(pcr[i],rotate[2*i-2],size);PermutationInverse(rotate[2*i-2],rotate[2*i-1]);}
	fsize=**pcf<<1;
	for (i=1;i<=**pcf;i++){Cycles2Permutation(pcf[i],flip[2*i-2],size);PermutationInverse(flip[2*i-2],flip[2*i-1]);}
	osize=**pco<<1;
	for (i=1;i<=**pco;i++){Cycles2Permutation(pco[i],opr[2*i-2],size);PermutationInverse(opr[2*i-2],opr[2*i-1]);}
	//////////////////////
	gsize=0;
	copy(t1,rotate[1]);copy(t3,rotate[0]);
	for (i=1;i<=rt;i++)
	{
		PermutationTransfer(t1,rotate[0],t2);copy(t1,t2);
		PermutationTransfer(t3,rotate[1],t2);copy(t3,t2);
		for (k=0;k<osize;k++)
		{
			PermutationTransfer(t1,opr[k],t2);
			PermutationTransfer(t2,t3,gg[++gsize]);
			for (j=0;j<fsize;j++)
			{
				PermutationTransfer(t1,flip[j],t2);
				PermutationTransfer(t2,opr[k],gg[++gsize]);
				PermutationTransfer(gg[gsize],flip[j^1],t2);
				PermutationTransfer(t2,t3,gg[psize]);
			}
		}
	}
//	for (i=0;i<rsize;i++) {print(rotate[i],size);}
//	for (i=0;i<fsize;i++) {print(flip[i],size);}
//	for (i=0;i<osize;i++) {print(opr[i],size);}
//	for (i=1;i<=gsize;i++) {print(gg[i],size);}
//	for (i=1;i<=gsize;i++) {printf("%ld\n",PermutationValid(gg[i]));}
	//////////////
	copy(pg[1],id);psize=1;
	for (l1=psize,l2=l1;dep>0;dep-=1)
	{
		for (i=l1;i<=l2;i++)
		{
			for (j=1;j<=gsize;j++)
			{
				PermutationTransfer(pg[i],gg[j],pg[++psize]);
			}
		}
		l1=l2+1;l2=psize;
	}
	//////////////////////
}

int check(long *clr)
{
	long i,j,k,c;
	k=1;
	for (i=1;i<=6;i++)
	{
		c=clr[k++];
		for (j=2;j<=4;j++)
		{
			if (clr[k++]!=c) {return 0;}
		}
	}
	return 1;
}
//////////////////////////////////////////////////
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c;
	long t1[PPPP],t2[PPPP],t3[PPPP];
	RubikCube(24,4,1);
	t1[0]=24;
	for (i=1;i<=24;i++)
	{
		scanf("%ld",&t1[i]);
	}
	for (i=2;i<=psize;i++)
	{
		ColorTransfer(t1,pg[i],t2);
//		print(t2,24);
		if (check(t2)==1) {printf("YES\n");return 0;}
	}
	printf("NO\n");
	return 0;
}

#include <stdio.h>
#include <string.h>
#define LL long long
#define uLL unsigned long long
#define uL unsigned long
#define uC unsigned char
long temp[100000];
void print(long *a,long size)
{
	long i;
	for (i=1;i<=size;i++)
	{
		printf("%ld,",a[i]);
	}
	printf("\n---\n");
}
void print2(long *a,long size)
{
	long i;
	for (i=1;i<=size;i++)
	{
		printf("%ld[%ld],",a[i],i);
	}
	printf("\n---\n");
}
void copy(long *a,long *b)
{
	long i;for (i=0;i<=b[0];i++) {a[i]=b[i];}
}
///////////////////////////////////////////////////////////////
void ColorTransfer(long *color,long *pol,long *ans)
{
	long i,j,k;
	for (i=1;i<=pol[0];i++)
	{
		ans[pol[i]]=color[i];
	}
}
void PermutationTransfer(long *pol1,long *pol2,long *ans)
{
	static long i,j,k;
	for (i=1;i<=pol1[0];i++)
	{
		ans[i]=pol2[pol1[i]];
	}
	ans[0]=pol1[0];
}
void PermutationInverse(long *pol,long *ans)
{
	static long i,j,k;
	for (i=1;i<=pol[0];i++)
	{
		ans[pol[i]]=i;
	}
	ans[0]=pol[0];
}
void PermutationFactoring(long *pol,long *ans)
{
	long i,j,k,a,b,c;
	long *stack=temp;*stack=0;
	memcpy(ans,pol,sizeof(pol)*(*pol+1));
	for (i=1;i<*pol;i++)
	{
		if (ans[i]>0)
		{
			for (j=i;ans[j]>0;j=stack[*stack]) {stack[++(*stack)]=ans[j];ans[j]=0;}
			stack[++(*stack)]=0;
		}
	}
	*ans=1;j=1;
	for (i=1;i<=*stack;i++)
	{
		if (stack[i]>0)
		{
			ans[++(*ans)]=stack[i];
		}
		else
		{
			ans[j]=i-j;j=i;*ans+=1;
		}
	}
}
void Cycles2Permutation(long *cycles,long *ans,long len)
{
	long i,j,k;
	for (i=1;i<=len;i++) {ans[i]=i;}*ans=len;
	k=1;
	for (i=1;i<=*cycles;i++)
	{
		for (j=k+1;j<k+cycles[k];j++)
		{
			ans[cycles[j]]=cycles[j+1];
		}
		ans[cycles[j]]=cycles[k+1];
		k=j+1;
	}
}
//////////////////////////////////////
#define PPPP 50
long pcr[][PPPP]={{1},{6,
				   4,1,3,4,2,
				   4,9,10,12,11,
				   4,13,5,17,21,
				   4,15,7,19,23,
				   4,16,8,20,24,
				   4,14,6,18,22}};
long pcf[][PPPP]={{1},{6,
				   4,13,14,16,15,
				   4,17,19,20,18,
				   4,1,5,9,24,
				   4,3,6,10,23,
				   4,3,7,11,22,
				   4,4,8,12,21}};
long pco[][PPPP]={{1},{3,
				  4,6,5,7,8,
				  4,3,16,10,17,
				  4,4,14,9,19}};
//////////////////////////////////////

long id[PPPP],flip[10][PPPP],rotate[10][PPPP],opr[10][PPPP],fsize,rsize,osize;
long gg[100][PPPP],gsize;
long pg[100000][PPPP],psize;
void RubikCube(long size,long rt,long dep)
{
	long i,j,k,l1,l2,a,b,c;
	long t1[PPPP],t2[PPPP],t3[PPPP];
	for (i=1;i<=size;i++) {id[i]=i;}*id=size;
	//////////////////////
	//Basic Permutations//
	//////////////////////
	rsize=**pcr<<1;
	for (i=1;i<=**pcr;i++){Cycles2Permutation(pcr[i],rotate[2*i-2],size);PermutationInverse(rotate[2*i-2],rotate[2*i-1]);}
	fsize=**pcf<<1;
	for (i=1;i<=**pcf;i++){Cycles2Permutation(pcf[i],flip[2*i-2],size);PermutationInverse(flip[2*i-2],flip[2*i-1]);}
	osize=**pco<<1;
	for (i=1;i<=**pco;i++){Cycles2Permutation(pco[i],opr[2*i-2],size);PermutationInverse(opr[2*i-2],opr[2*i-1]);}
	//////////////////////
	gsize=0;
	copy(t1,rotate[1]);copy(t3,rotate[0]);
	for (i=1;i<=rt;i++)
	{
		PermutationTransfer(t1,rotate[0],t2);copy(t1,t2);
		PermutationTransfer(t3,rotate[1],t2);copy(t3,t2);
		for (k=0;k<osize;k++)
		{
			PermutationTransfer(t1,opr[k],t2);
			PermutationTransfer(t2,t3,gg[++gsize]);
			for (j=0;j<fsize;j++)
			{
				PermutationTransfer(t1,flip[j],t2);
				PermutationTransfer(t2,opr[k],gg[++gsize]);
				PermutationTransfer(gg[gsize],flip[j^1],t2);
				PermutationTransfer(t2,t3,gg[psize]);
			}
		}
	}
	//////////////
	copy(pg[1],id);psize=1;
	for (l1=psize,l2=l1;dep>0;dep-=1)
	{
		for (i=l1;i<=l2;i++)
		{
			for (j=1;j<=gsize;j++)
			{
				PermutationTransfer(pg[i],gg[j],pg[++psize]);
			}
		}
		l1=l2+1;l2=psize;
	}
	//////////////////////
}

int check(long *clr)
{
	long i,j,k,c;
	k=1;
	for (i=1;i<=6;i++)
	{
		c=clr[k++];
		for (j=2;j<=4;j++)
		{
			if (clr[k++]!=c) {return 0;}
		}
	}
	return 1;
}
//////////////////////////////////////////////////
int main()
{
//	freopen("in.in","r",stdin);
	long i,j,k,a,b,c;
	long t1[PPPP],t2[PPPP],t3[PPPP];
	RubikCube(24,4,1);
	t1[0]=24;
	for (i=1;i<=24;i++)
	{
		scanf("%ld",&t1[i]);
	}
	for (i=1;i<=psize;i++)
	{
		ColorTransfer(t1,pg[i],t2);
//		print(t2,24);
		if (check(t2)==1) {printf("YES\n");return 0;}
	}
	printf("NO\n");
	return 0;
}