#include <stdio.h>
#define rep(i,a,b) for (int i=a; i<b; i++)
void read(int *arr, int length) {
    rep (i,0,length) scanf("%d",(arr+i));
    scanf("\n");
}
int clockwise(int *arr, int length) {
    rep (i,0,length) {
        if (arr[i]!=(i+1)) return 0;
    }
    return 1;
}
int counterclockwise(int *arr, int length) {
    rep (i,0,length) {
        if (arr[i]!=(length-i)) return 0;
    }
    return 1;
}
void invert(int *arr, int s, int e) {
    int mid=(e-1-s)/2+1,temp;
    rep (i,0,mid) {
        temp=arr[s+i];
        arr[s+i]=arr[e-1-i];
        arr[e-1-i]=temp;
    }
}
int round_dance(int *arr, int length) {
    if (clockwise(arr,length)) {
        return 1;
    } else if (counterclockwise(arr,length)) {
        return 1;
    } else {
        int j=0;
        while (arr[j]!=length) j++;
        invert(arr,0,j);
        invert(arr,j,length);
        if (clockwise(arr,length)) return 1;
        invert(arr,0,j);
        invert(arr,j,length);
        invert(arr,0,j+1);
        invert(arr,j+1,length);
        if (counterclockwise(arr,length)) return 1;
        return 0;
    }
}
int main() {
    int queries,len;
    scanf("%d\n",&queries);
    for (int i=0; i<queries; i++) {
        scanf("%d\n",&len);
        int st[len];
        read(st,len);
        if (round_dance(st,len)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}


#include<stdio.h>

int main(){
	int t;
	scanf(" %d",&t);
	while(t--){
		int n;
		scanf(" %d",&n);
		int nums[n];
		for(int i = 0; i < n;++i)
			scanf(" %d",&nums[i]);
		int first = nums[0];
		int po = 1;
		for(int i = 1; i < n && po;++i){
			if(nums[i] -1 != first && (nums[i] != 1 || first != n))
				po = 0;
			first = nums[i];
		}
		if(po){
			puts("YES");
			continue;
		}
		first = nums[0];
		po = 1;
		for(int i = 1; i < n && po;++i){
			if(nums[i] + 1 != first && (first != 1 || nums[i] != n))
				po = 0;
			first = nums[i];
		}
		if(po)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<stdio.h>

int main(){
	int t;
	scanf(" %d",&t);
	while(t--){
		int n;
		scanf(" %d",&n);
		int nums[n];
		for(int i = 0; i < n;++i)
			scanf(" %d",&nums[i]);
		int first = nums[0];
		int po = 1;
		for(int i = 1; i < n && po;++i){
			if(nums[i] -1 != first && nums[i] != 1 && first != n)
				po = 0;
			first = nums[i];
		}
		if(po){
			puts("YES");
			continue;
		}
		first = nums[0];
		po = 1;
		for(int i = 1; i < n && po;++i){
			if(nums[i] + 1 != first && first != 1 && nums[i] != n)
				po = 0;
			first = nums[i];
		}
		if(po)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}


#include<stdio.h>
int main()
{
    int q,n;
    scanf(" %d", &q);
    while(q--)
    {
        scanf("%d", &n);
        int ara[n];
        int num[n-1];
        int one,da;
        one=da=0;
        scanf("%d", &ara[0]);
        for(int i=1;i<n;i++)
        {
            scanf("%d", &ara[i]);
            num[i-1]=ara[i-1]-ara[i];
        }
        for(int i=0;i<n-1;i++)
        {
            if(num[i]==-1) one+=num[i];
            else if(num[i]==(n-1)) da+=num[i];
        }
        if((one+da==1 && da==(n-1)) || one==1-n)
        {
            printf("YES\n");
            continue;
        }
        one=0,da=0;
        for(int i=0;i<n-1;i++)
        {
            if(num[i]==1) one++;
            else if(num[i]==(1-n)) da+=num[i];
        }
        if((one+da==-1 && da==(1-n)) || one==n-1 )
        {
            printf("YES\n");
            continue;
        }
        printf("NO\n");
    }
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int q,i,j;
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int n,one = 0,last = 0,clo=0,revclo=0;
        scanf("%d",&n);
        int a[n];
        scanf("%d",&a[0]);
        for(j=1;j<n;j++){
            scanf("%d",&a[j]);
            if(a[j-1]>a[j]){
                clo++;
            }
            else if(a[j-1]<a[j]){
                revclo++;
            }
        }
        if(a[0]<a[n-1]){
            clo++;
        }
        else if(a[0]>a[n-1]){
            revclo++;
        }
        if(clo==n-1||revclo==n-1){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }

    }
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int q,i,j;
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int n,one = 0,last = 0;
        scanf("%d",&n);
        int a[n];
        for(j=0;j<n;j++){
            scanf("%d",&a[j]);
            if(a[j]==1){
                one = j;
            }
            else if(a[j] == n){
                last = j;
            }
        }
        //printf("one = %d last = %d\n",one,last);
        if(n==1){
            printf("Yes\n");
        }
        else if(abs(last-one)==n-1){
            if(one>last) {
                //printf("IN One>Last\n ");
                for (j = one; j != last; j--) {
                    //printf("j = %d\n",j);
                    //printf("%d!=%d-1 && abs(%d - %d)!=1\n",j,n,a[j],a[j-1]);
                    if(j!=n-1 && abs(a[j]-a[j-1])!=1){
                        printf("No\n");
                        goto bye;
                    }
                }
            }
            else{
                //printf("IN One<Last\n");
                for (j = one; j != last; j++) {
                    //printf("j = %d\n",j);
                    //printf("%d>0 && abs(%d - %d)!=1\n",j,a[j],a[j-1]);
                    if(j>0 && abs(a[j]-a[j-1])!=1){
                        printf("No\n");
                        goto bye;
                    }
                }
            }
            printf("Yes\n");
        }
        else{
            if(one<last) {
                int temp = a[one]+1;
                //printf("IN One<Last\n");
                for (j = one; j != last; j--) {
                    //printf("temp= %d\n",temp);
                    //printf("j = %d\n",j);
                    //printf("(a[%d]=%d)!=%d && %d != %d\n",j,a[j],temp,j,one);
                    if(a[j]!=temp&&j!=one){
                        printf("No\n");
                        goto bye;
                    }
                    else{
                        temp = a[j]+1;
                    }
                    if(j==0){
                        j=n;
                    }
                }
                printf("Yes\n");
            }
            else{
                //printf("IN One>Last\n");
                int temp = a[one]+1;
                for (j = one; j != last; j++) {
                    //printf("temp= %d\n",temp);
                    //printf("j = %d\n",j);
                    //printf("(a[%d]=%d)!=%d && %d != %d\n",j,a[j],temp,j,one);
                    if(a[j]!=temp&&j!=one){
                        printf("No\n");
                        goto bye;
                    }
                    else{
                        temp = a[j]+1;
                    }
                    if(j==n-1){
                        j=-1;
                    }
                }
                printf("Yes\n");
            }
        }
        bye:printf("");
    }
}


#include<stdio.h>
int main(){
    int t,j,clo=0,revclo=0;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        int n;
        scanf("%d",&n);
        int a[n];
        scanf("%d",&a[0]);
        for(j=1;j<n;j++){
            scanf("%d",&a[i]);
            if(a[i]>a[i-1]){
                clo++;
            }
            else{
                revclo++;
            }
        }
        if(a[0]>a[n-1]){
            revclo++;
        }
        else{
            clo++;
        }
        if(revclo==n-1||clo==n-1){
            printf("YES");
        }
        else{
            printf("NO");
        }
    }
}


#include<stdio.h>
int main(){
    int t,j;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        int n,clo = 0,revclo = 0;
        scanf("%d",&n);
        int a[n];
        scanf("%d",&a[0]);
        for(j=1;j<n;j++) {
            scanf("%d", &a[j]);
            if (a[j] > a[j - 1]) {
                clo++;
            } else {
                revclo++;
            }
        }
        if(a[0]>a[n-1]){
            clo++;
        }
        else{
            revclo++;
        }
        //printf("clo = %d  revclo = %d\n",clo,revclo);
        if(revclo == n-1||clo == n-1){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}


#include <stdio.h>

int main(void)
{
    int times, flag;
    scanf("%i", &times);
    char *answer[times];
    for (int t = 0; t < times; t++)
    {
        int p;
        scanf("%i", &p);
        int indice[p];
        for (int q = 0; q < p; q++)
        {
            scanf("%i", &indice[q]);
        }

        if (p == 1)
            flag = 1;
        else
            flag = 0;

        int tmp;
        if (flag == 0)
        {
            for (int i = 0; i < p - 1; i++)
            {
                tmp = (indice[i] - indice[i + 1]);
                if (tmp == -1 || tmp == (p - 1))
                    flag = 1;
                else
                {
                    flag = 0;
                    break;
                }
            }
        }

        if (flag == 0)
        {
            for (int i = 0; i < p - 1; i++)
            {
                tmp = (indice[i] - indice[i + 1]);
                if (tmp == 1 || tmp == (1 - p))
                    flag = -1;
                else
                {
                    flag = 0;
                    break;
                }
            }
        }

        if (flag == 1 || flag == -1)
            answer[t] = "YES";
        else
            answer[t] =  "NO";
    }

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


#include<stdio.h>
#include<stdlib.h>
#define size 201
main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
	int i,n,pos,flag=0;
	scanf("%d",&n);
	int a[size];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		  pos=i;
	}
if(pos==0)
{
	for(i=0;i<n-1;++i)
	{
		if(a[i+1]<a[i])
		{
			flag=1;
			break;
		}
	}
if(flag==1)
{
	printf("NO\n");
}
else
{
	printf("YES\n");
}
}
else if(pos==n-1)
{
	for(i=0;i<n-1;++i)
	{
		if(a[i+1]>a[i])
		{
			flag=1;
			break;
		}
	}
if(flag==1)
{
	printf("NO\n");
}
else
{
	printf("YES\n");
}
}
else
{
	if(a[pos-1]==2)
	{
		for(i=pos-1;i>0;--i)
		{
			if(a[i-1]<a[i])
			{
				flag=1;
				break;
			}
		}
		for(i=pos+1;i<n-1;++i)
		{
			if(a[i+1]>a[i])
			{
				flag=1;
				break;
			}
		}
if(flag==1)
{
	printf("NO\n");
}
else
{
	printf("YES\n");
}
	}
	else
	{
		for(i=pos+1;i<n-1;++i)
		{
			if(a[i+1]<a[i])
			{
				flag=1;
				break;
			}
		}
		for(i=pos-1;i>0;--i)
		{
			if(a[i-1]>a[i])
			{
				flag=1;
				break;
			}
		}
if(flag==0)
{
	printf("YES\n");

}
else
{
	printf("NO\n");
}
	}

}
}
}


#include<stdio.h>
#include<stdlib.h>
#define size 201
main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
	int i,n,pos,flag=0;
	scanf("%d",&n);
	int a[size];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		  pos=i;
    }
i=(pos+1)%n;
if(a[i]==n)
{
	int v=n;
	while(i!=pos)
	{
		if(a[i]!=v)
		{
			flag=1;
			break;
		}
		i=(i+1)%n;
		v--;
	}
}
else
{
	int v=2;
	while(i!=pos)
	{
		if(a[i]!=v)
		{
			flag=1;
			break;
		}
		i=(i+1)%n;
		v++;
	}
}
if(flag==0)
{
	printf("YES\n");
}
else
{
	printf("NO\n");
}
   }
}


#include<stdio.h>
#include<stdlib.h>
#define size 201
main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
	int i,n,pos,flag=0;
	scanf("%d",&n);
	int a[size];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		  pos=i;
    }
i=(pos+1)%n;
if(a[i]==n)
{
while(i!=pos)
{
	if(a[i]<a[(i+1)%n])
	{
		flag=1;
		break;
	}
	i=(i+1)%n;
}
}
else
{
	while(i!=pos)
	{
	if(a[i]>a[(i+1)%n])
	{
		flag=1;
		break;
	}
	i=(i+1)%n;
    }
}
if(flag==0)
{
	printf("YES\n");
}
else
{
	printf("NO\n");
}
}
}


#include<stdio.h>
#include<stdlib.h>
#define size 201
main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
	int i,n,pos,flag=0;
	scanf("%d",&n);
	int a[size];
	for(i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		  pos=i;
    }
for(i=0;i<n-1;++i)
{
	if(a[i]>a[i+1])
	{
		flag=1;
		break;
	}
}
if(flag==0)
{
	printf("YES\n");
	continue;
}
flag=0;
i=(pos+1)%n;
if(a[i]==n)
{
while(i!=pos)
{
	if(a[i]<a[(i+1)%n])
	{
		flag=1;
		break;
	}
	i=(i+1)%n;
}
}
else
{
	while(i!=pos)
	{
	if(a[i]>a[(i+1)%n])
	{
		flag=1;
		break;
	}
	i=(i+1)%n;
    }
}
if(flag==0)
{
	printf("YES\n");
}
else
{
	printf("NO\n");
}
}
}


#include <stdio.h>

//for reading/writing the input/output files

#include <iostream>
using namespace std;

int main (void){
	unsigned int q=4; // <------------ Number of queries
	unsigned int n=5; // <----------- Number of students (maximun size of arrays)
	unsigned int student[n];  // <---------- Array of students
	unsigned char flag=0;
	int counter=0;

	cin >> q; //READ NUMBER OF QUERIES
	for (int j=0; j<q;j++){
		cin >> n; //READ NUMBER OF STUDENTS
		// ------------------- LLENAR ARRAY
		for (int i=0; i<n; i++){
			cin >> student[i]; // READ ARRAY
		}

		// ------------------ clockwise
		counter= student[0];
		for (int i=1; i<n; i++){
			if (counter+1 != student[i]){
				flag++;
				counter= student[i];
			}
			else{
				counter++;
			}
			if (flag>2){
				i=n;
			}
		}
		//-------------------- counterclockwise
		if (flag>=2){
			flag=0;
			counter= student[n-1];
			for (int i=n-2; i>=0; i--){
				if (counter-1 != student[i]){
					flag++;
					counter= student[i];
				}
				else{
					counter--;
				}
				if (flag>2){
					i=-1;
				}
			}
		}
		//-------------------- WRITE "NO" OR "YES"
		if (flag>=2){
			cout <<"NO"<<"\n" << endl;
		}
		else {
			cout <<"YES"<<"\n" << endl;
		}

	}

	return 0;
}


#include <stdio.h>

int main (void){
	unsigned int q=0; // <------------ Number of queries
	unsigned int n=1000; // <----------- Number of students (maximun size of arrays)
	unsigned int student[n];  // <---------- Array of students
	unsigned char flag=0;
	int counter=0,j,i;

	scanf("%d",&q); //READ NUMBER OF QUERIES
	for (j=0; j<q;j++){
		scanf("%d",&n); //READ NUMBER OF STUDENTS
		// ------------------- LLENAR ARRAY
		for (i=0; i<n; i++){
			scanf("%d",&student[i]); // READ ARRAY
		}

		// ------------------ clockwise
		//printf("\nASCENDENTE: \n");
		counter= student[0];
		for (i=1; i<n; i++){
			if (counter+1 != student[i]){
				//printf ("%d != %d\n",counter-1,student[i]);
				flag++;
				counter= student[i];
			}
			else{
				//printf ("%d = %d\n",counter-1,student[i]);
				counter++;
			}
			if (flag>2){
				i=n;
			}
		}
		//-------------------- counterclockwise
		//printf("\nDESCENDENTE: \n");
		if (flag>=2){
			flag=0;
			counter= student[0];
			for (i=1; i<n; i++){
				if (counter-1 != student[i]){
					//printf ("%d != %d\n",counter-1,student[i]);
					flag++;
					counter= student[i];
				}
				else{
					//printf ("%d = %d\n",counter-1,student[i]);
					counter--;
				}
				if (flag>2){
					i=n;
				}
			}
		}
		//-------------------- WRITE "NO" OR "YES"
		if (flag>=2){
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
		flag=0;
	}

	return 0;
}


#include <stdio.h>
//using namespace std;

int main (void){
	unsigned int q=0; // <------------ Number of queries
	unsigned int n=1000; // <----------- Number of students (maximun size of arrays)
	unsigned int student[n];  // <---------- Array of students
	unsigned char flag=0;
	int counter=0,j,i;

	scanf("%d",&q); //READ NUMBER OF QUERIES
	for (j=0; j<q;j++){
		scanf("%d",&n); //READ NUMBER OF STUDENTS
		// ------------------- LLENAR ARRAY
		for (i=0; i<n; i++){
			scanf("%d",&student[i]); // READ ARRAY
		}

		// ------------------ clockwise
		//printf("\nASCENDENTE: \n");
		counter= student[0];
		for (i=1; i<n; i++){
			if (counter+1 != student[i]){
				//printf ("%d != %d\n",counter-1,student[i]);
				flag++;
				counter= student[i];
			}
			else{
				//printf ("%d = %d\n",counter-1,student[i]);
				counter++;
			}
			if (flag>2){
				i=n;
			}
		}
		//-------------------- counterclockwise
		//printf("\nDESCENDENTE: \n");
		if (flag>=2){
			flag=0;
			counter= student[0];
			for (i=1; i<n; i++){
				if (counter-1 != student[i]){
					//printf ("%d != %d\n",counter-1,student[i]);
					flag++;
					counter= student[i];
				}
				else{
					//printf ("%d = %d\n",counter-1,student[i]);
					counter--;
				}
				if (flag>2){
					i=n;
				}
			}
		}
		//-------------------- WRITE "NO" OR "YES"
		if (flag>=2){
			printf("NO\n");
		}
		else {
			printf("YES\n");
		}
		flag=0;
	}

	return 0;
}


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

        if(n==1 || n==2 ||n==3)
            flag=1;

        else
        {
            for(i=2; i<=n; i++)
            {
                if(ara[i]-ara[i-1]==1)
                    flag=1;

                else if(ara[i]-ara[i-1]==-1)
                    flag=1;

                else if((ara[i]==1 && ara[i+1]==n) || (ara[i]==n && ara[i-1]==1))
                    flag=1;

                else
                    {
                        flag=0;
                        break;
                    }
            }
        }

        if(flag==0)
            printf("N0\n");

        else
            printf("YES\n");
    }
}


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

        if(n==1 || n==2 ||n==3)
            flag=1;

        else
        {
            for(i=2; i<=n; i++)
            {
                if(ara[i]-ara[i-1]==1)
                    flag=1;

                else if(ara[i]-ara[i-1]==-1)
                    flag=1;

                else if((ara[i]==1 && ara[i-1]==n) || (ara[i]==n && ara[i-1]==1))
                    flag=1;

                else
                    {
                        flag=0;
                        break;
                    }
            }
        }

        if(flag==0)
            printf("NO\n");

        else
            printf("YES\n");
    }
    return 0;
}


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

        if(n==1 || n==2 ||n==3)
            flag=1;

        else
        {
            for(i=2; i<=n; i++)
            {
                if(ara[i]-ara[i-1]==1)
                    flag=1;

                else if(ara[i]-ara[i-1]==-1)
                    flag=1;

                else if((ara[i]==1 && ara[i+1]==n) || (ara[i]==n && ara[i-1]==1))
                    flag=1;

                else
                    {
                        flag=0;
                        break;
                    }
            }
        }

        if(flag==0)
            printf("NO\n");

        else
            printf("YES\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define TAM 300
int main()
{
    int n=0, m=0, vetor[TAM]={0}, auxH[TAM]={0}, auxA[TAM]={0}, k=0;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
    int x = 0, y=0, flag1 = 0, flag2 = 0;
        scanf("%d", &m);
        for(int j=0; j<m; j++){
            scanf("%d", &vetor[j]);
        }
        for(k=0; k<m; k++){
            if(vetor[k]==1){
                    //horario
                for(int l=k; l<m; l++){
                    auxH[x] = vetor[l];
                    x++;
                }
                for(int j=0; j<k; j++){
                    auxH[x] = vetor[j];
                    x++;
                }
                //anti horario
                /*if(k==0){
                    auxA[0] = 1;
                }
                else{*/
                    for(int l=k; l>=0; l--){
                        auxA[y] = vetor[l];
                        y++;
                    }
                //}
                for(int j=(m-1); j>k; j--){
                    auxA[y] = vetor[j];
                    y++;
                }
            }
        }

        for(int a=0; a<m; a++){
            if(auxH[a]-1!=a){
                //printf("%d %d,", a, auxH[a]);
                flag1 = 1;
            }
        }
//printf("\n");
        for(int a=0; a<m; a++){
            if(auxA[a]-1!=a){
                flag2 = 1;
            }
        }
        if(flag1==0 || flag2==0){
            printf("SIM\n");
        }
        else{
            printf("NÃO\n");
        }
        /*for(int i=0; i<m; i++){
            printf("%d ", auxA[i]);
        }*/

        x = 0;
        y=0;
        flag1 = 0;
        flag2 = 0;
        k=0;
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define TAM 300
int main()
{
    int n=0, m=0, vetor[TAM]={0}, auxH[TAM]={0}, auxA[TAM]={0}, k=0;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
    int x = 0, y=0, flag1 = 0, flag2 = 0;
        scanf("%d", &m);
        for(int j=0; j<m; j++){
            scanf("%d", &vetor[j]);
        }
        for(k=0; k<m; k++){
            if(vetor[k]==1){
                    //horario
                for(int l=k; l<m; l++){
                    auxH[x] = vetor[l];
                    x++;
                }
                for(int j=0; j<k; j++){
                    auxH[x] = vetor[j];
                    x++;
                }
                //anti horario
                /*if(k==0){
                    auxA[0] = 1;
                }
                else{*/
                    for(int l=k; l>=0; l--){
                        auxA[y] = vetor[l];
                        y++;
                    }
                //}
                for(int j=(m-1); j>k; j--){
                    auxA[y] = vetor[j];
                    y++;
                }
            }
        }

        for(int a=0; a<m; a++){
            if(auxH[a]-1!=a){
                //printf("%d %d,", a, auxH[a]);
                flag1 = 1;
            }
        }
//printf("\n");
        for(int a=0; a<m; a++){
            if(auxA[a]-1!=a){
                flag2 = 1;
            }
        }
        if(flag1==0 || flag2==0){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
        /*for(int i=0; i<m; i++){
            printf("%d ", auxA[i]);
        }*/

        x = 0;
        y=0;
        flag1 = 0;
        flag2 = 0;
        k=0;
    }
    return 0;
}


#include<stdio.h>

int main()
{
  long long a[300],n,j,i,t,count=0;
  scanf("%lld",&t);
  for(i=0;i<t;i++)
  {   count=0;
      scanf("%lld",&n);
      for(j=0;j<n;j++)
      {
          scanf("%lld",&a[j]);
      }
      if(a[n-1]<a[0])
      {
          count++;
      }

       for(j=1;j<n;j++)
        {
          if(a[j]>a[j-1])
          count++;
      }
      if(count==1||count==n-1){printf("YES\n");}
      else{printf("NO\n");}
  }
    return 0;
}


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

typedef struct node{
	int num;
	struct node *next;
} node;

typedef struct{
	node* head;
	node* tail;
} queue;

void freeallq(queue *q){
	for(node *tmp; q->head; q->head = tmp){
		tmp = q->head->next;
		free(q->head);
	}
	q->tail = NULL;
}

void enq(queue *q, int num){
	node* n = malloc(sizeof(node));
	if(!n) {freeallq(q); exit(1);}
	n->num = num;
	n->next = NULL;
	if(q->tail) q->tail->next = n;
	q->tail = n;
	if(q->head == NULL) q->head = n;
}

int deq(queue *q){
	if(q->head == NULL) exit(1);
	node *n = q->head->next;
	int num = q->head->num;
	free(q->head);
	q->head = n;
	if(n == NULL) q->tail = NULL;
	return num;
}

int main(void){
	queue q;
	q.head = NULL;
	q.tail = NULL;
	node *tmp = NULL;
	int t, num, n;
	scanf("%i",&t);
	for(; t > 0; --t){
		scanf("%i",&n);
		for(; n > 0; --n){
			scanf("%i",&num);
			enq(&q,num);
		}
		while(q.head->num != 1)
			enq(&q,deq(&q));
		for(tmp = q.head; tmp->next; ){
			if(tmp->num > tmp->next->num)
				break;
			tmp = tmp->next;
		}
		if(tmp->next == NULL){
			puts("YES");
			freeallq(&q);
			continue;
		}
		enq(&q,deq(&q));
		for(tmp = q.head; tmp->next; ){
			if(tmp->num < tmp->next->num)
				break;
			tmp = tmp->next;
		}
		if(tmp->next == NULL)
			puts("YES");
		else
			puts("NO");
		freeallq(&q);
	}
	return 0;
}


#include<stdio.h>
#include<stdbool.h>
int main(void)
{
	int q,n;
	int position[200];
	scanf("%d",&q);
	while(q--)
	{
		int pos_1;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%d",&position[i]);
			if(position[i]==1)
			{
				pos_1=i;
			}
		}
		bool left=true,right=true;
		for(int i=1;i<n;i++)
		{
			left&=(position[(pos_1-i+n)%n]==(i+1));
			right&=(position[(pos_1+i+n)%n]==(i+1));
		}
		if(left || right)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
}


#include<stdio.h>
void func(int m)
{
    int cond=1,i,num[m],order=0;
    for(i=0; i<m; i++)
    {
        scanf("%d",&num[i]);

    }
    for(i=0;i<m;i++)
    {
        if(i==1)
        {
            if(num[i-1]==1||num[i-1]==m)
            {
                if(num[i-1]==1)
                {
                    if(num[i]==m)
                        order=-1;
                    else if(num[i]==2)
                        order=1;
                    else cond=0;
                }
                else
                {
                    if(num[i]==1)
                        order=1;
                    else if(num[i]==m-1)
                        order=-1;
                    else cond=0;
                }
            }
            else
            {
                if(num[i]-num[i-1]==1||num[i]-num[i-1]==-1)
                    order=num[i]-num[i-1];
                else cond=0;
            }
        }
        if(i>=2)
        {
            if(num[i]==1||num[i]==m)
            {
                if(num[i]==1)
                {
                    if(order==1)
                    {
                        if(num[i-1]!=m)
                            cond=0;
                    }
                    else if(num[i]-num[i-1]!=order)
                        cond=0;
                }
                else
                {
                    if(order==-1)
                    {
                        if(num[i-1]!=1)
                            cond=0;
                    }
                    else if(num[i]-num[i-1]!=order)
                        cond=0;

                }
            }
            else
            {
                if(num[i]-num[i-1]!=order)
                    cond=0;
            }
        }
    }
    if(cond)
    {
        printf("YES\n");
    }
    else printf("NO\n");
}
int main()
{
    int i,n,m,j;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&m);
        func(m);
    }
    return 0;
}


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

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d ", n);
	for (int i = 0; i < n - 1;i++)
		printf("%d ", i + 1);
}


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

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n;i++)
		printf("%d ", i + 1);
	printf("1");
}


#include <stdio.h>

void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

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

    for(i=0; i<n; i++)
        arr[i] = i + 1;

    for(i=n-1; i>=1; i--)
        swap(&arr[i], &arr[i-1]);

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

    return 0;
}


#include<stdio.h>
int per(int n);
int main()
{
    int n,x;
    scanf("%d",&n);
    printf("%d ",n);
    per(n);
    return 0;
}
int per(int x)
{
    if(x!=1)
    {
    per(x-1);
    printf("%d ",x-1);
    }
}


#include<stdio.h>

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


#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	while(n>0)
	{
		printf("%d ",n);
		n--;
	}
}


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


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

int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}
int main()
{
long long   int n,m,i,x=1,y=1,j,count1,count=0,sum=0,o=0,k[100000]={0};

scanf("%lld",&n);
for(i=n;i>=1;i--){
    printf("%lld ",i);
}
   return 0;
}


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

int cmpfunc (const void * a, const void * b) {
   return ( *(int*)a - *(int*)b );
}
int main()
{
long long   int n,m,i,x=1,y=1,j,count1,count=0,sum=0,o=0,k[100000]={0};

scanf("%lld",&n);
printf("%lld ",n);
for(i=1;i<n;i++){
    printf("%lld ",i);
}
   return 0;
}


#include <stdio.h>

int main (){
    int i,a;
    scanf("%d",&a);
    printf("%d ",a);
    for(i=1;i<a;i++)
        printf("%d ",i);

return 0;
}


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


#include<stdio.h>
int main(){
int n,i;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++){
printf("%d ",i);}
return 0;}


#include <stdio.h>

void swap(int *x, int *y){
    int temp = *x;
    *x = *y;
    *y = temp;
}

int arr[1001];

void precompute(){
    for(int i=1;i<=1000;i++)
        arr[i] = i;
}

void f(int x){
    if(x == 1)
        return;
    else
        swap(&arr[x-1],&arr[x]);
    f(x-1);
}

int main(){
    int n;
    scanf("%d", &n);
    precompute();
    f(n);
    for(int i=1;i<=n;i++)
        printf("%d ", arr[i]);

}


#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	for(int i = 2; i < n; i++) printf("%d ", n);
	printf("1");
	return 0;
}


#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	printf("%d", n);
	for(int i = 1; i < n; i++) printf(" %d", i);
	return 0;
}


#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	printf("%d", n);
	for(int i = 1; i < n; i++) printf(" %d", n);
	return 0;
}


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


#include <stdio.h>

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

		printf("%d ", n);
		for (int i = 1; i < n; i++)
				printf("%d ", i);
		printf("\n");

		return 0;
}


#include<stdio.h>
int main()
{
int a,i;
scanf("%d",&a);
for(i=a;i>=1;i--)
{
printf("%d ",i);
if(i==1)break;
}
}


#include<stdio.h>
int main()
{
int a,i;
scanf("%d",&a);
printf("%d ",a);
for(i=1;i<a;i++)
{
printf("%d ",i);
}
}


#include <stdio.h>
int main()
{
	int n,i;
	scanf("%d",&n);
	for (i=2;i<=n;i++)
		printf("%d ",i);
	printf("%d",1);
	return 0;
}


#include <stdio.h>
int main()
{
	int n,i;
	scanf("%d",&n);
	printf("%d ",n);
	for (i=1;i<n;i++)
		printf("%d ",i);
	return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    printf("%d ",n);
    for(i=1;i<n;i++)
    {
        printf("%d ",i);
    }

    return 0;
}


#include<stdio.h>

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


#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  printf("%d", n);
  int i = 1;
  while (i < n) {
    printf(" %d", i);
    ++i;
  }
  printf("\n");
  return 0;
}


#include <stdio.h>

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


#include <stdio.h>

int main()
{
    int n, i=1;
    scanf("%d", &n);
    printf("%d ",n);
    while(i<n)
    {
        printf("%d ",i);
        i++;
    }
    printf("\n");
    return 0;
}


#include <stdio.h>

int main()
{
    int n, i;
    scanf("%d", &n);
    int a[n + 1];
    for(i = 1; i <= n ; i++){
        a[i] = i;
    }
    int k = n, temp;
    while(k>1){
        temp = a[k];
        a[k] = a[k - 1];
        a[k - 1] = temp;
        k--;
    }
    for(i = 1; i <= n; i++)
        printf("%d ", a[i]);
    return 0;
}


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

int main()
{
    int n, i;
    scanf("%d", &n);
    for(i = n; i >0 ; i--){
        printf("%d ", i);
    }
    return 0;
}


#include <stdio.h>

int main(int argc, char** argv){
    int n, i;
    scanf("%d", &n);
    printf("%d ", n);
    for(i = 1; i < n; ++i){
	printf("%d ", i);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
int main() {
    int n;
    scanf("%d",&n);
    for (int i=2; i<=n; i++) printf("%d ",i);
    printf("1");
    return 0;
}


#include <stdio.h>
int main() {
    int n;
    scanf("%d",&n);
    printf("%d ",n);
    for (int i=1; i<n; i++) printf("%d ",i);
    return 0;
}


/* Little Elephant and Function */
#include<stdio.h>
#include<string.h>
int main()
{
   int n,t;
   scanf("%d",&n);
   printf("%d ",n);
   for(t=1;t<n;t++)
    printf("%d ",t);
}


/* Little Elephant and Function */
#include<stdio.h>
#include<string.h>
int main()
{
   int n,t;
   scanf("%d",&n);
   int arr[n],i;
   if(n==1)
    printf("1");
   else{
    for(i=0;i<n;i++)
    {
        arr[i]=i+1;
    }
    for(i=1;i<n;i++)
    {
        t=arr[i];
        arr[i]=arr[i-1];
        arr[i-1]=t;
    }
    for(i=0;i<n;i++)
        printf("%d ",arr[i]);
   }

}


#include <stdio.h>

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

    for(int i = n; i > 0; i--)
    {
        printf("%d ", i);
    }

    printf("\n");
}


#include <stdio.h>

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

    printf("%d ", n);

    for(int i = 1; i <= n-2; i++)
    {
        printf("%d ", i);
    }

    if(n > 1)
        printf("%d\n", n-1);
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=n;i>=1;i--)
        printf("%d ",i);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=n;i>=1;i--)
        printf("%d",i);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=n;i>1;i--)
    {
        printf("%d ",i);
        if(i==n)
        printf("1 ");
    }
    if(n==1)
    printf("1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    printf("%d ",n);
    for(i=1;i<n;i++)
    {
        printf("%d ",i);
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=n;i>1;i--)
    {
        printf("%d ",i);
        if(i==n)
        printf("1 ");
    }

    return 0;
}


#include<stdio.h>
int main()
{
   int n;
   scanf("%d",&n);
   printf("%d ",n);
   for(int i=1;i<n;i++)
   {
       printf("%d ",i);
   }
   return 0;
}


#include<stdio.h>
int rec_sort(int *arr,int x)
{
	if(x==0)
		return 0;
	rec_sort(arr,x-1);
	int temp=arr[x];
	arr[x]=arr[x-1];
	arr[x-1]=temp;
}

int main()
{
	int n;
	scanf("%d",&n);
	printf("%d ",n);
	for(int i=1;i<n;i++)
		printf("%d ",i);
	printf("\n");
}


#include<stdio.h>
int main()
{
    int d1,d2,n,j,f=-1 ,k,d=0 ,sum1,sum2=0,i,sum=0;
 scanf("%d",&n);
 printf("%d ",n);
for(i=1;i<n;i++)
{
    printf("%d ",i);
}

}


#include<stdio.h>

int main()
{
    int n,i;

    scanf("%d",&n);

    printf("%d ",n);

    for(i=1;i<n;i++)
    {
        printf(" %d ",i);
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d ",n);
    for(int i=1;i<n;i++)
    printf("%d ",i);
    return 0;
}


#include<stdio.h>

int main(void){
    int n,i;
    scanf("%d", &n);printf("%d",n);
    for(i=1;i<n;i++){
        printf(" %d",i);
    }
}


#include<stdio.h>

// Time O(n)
// Memory O(1)
int main(void){
	int n;
	scanf("%d", &n);

	if(n == 1){
		printf("%d\n", n);
		return 0;
	}

	printf("%d ", n);
	for(int i = 1; i < n - 1; i++){
		printf("%d ", i);
	}

	printf("%d\n", n - 1);

	return 0;
}


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

}
void fun(int n,int a[]){
     if(n==1)
    {
        return;

    }
    else
    {
        swap(n,n-1,a);
        fun(n-1,a);
    }

}
int swap(int n,int m,int a[])
{
    int t;
    t=a[n];
    a[n]=a[m];
    a[m]=t;
}


 #include<stdio.h>

 int main()
{
    int n;
    scanf("%d",&n);
    for(int i=n;i>=1;i--)
    {
        printf("%d ",i);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define spc printf(" ");
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}*/
play
{
    I n,i;
    sf(n);
    rep(i,2,n+1)
    pf(i),spc;
    pf(1);
    nl;
    out 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define spc printf(" ");
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
    return (*(int*)a-*(int*)b);
}*/
play
{
    I n,i;
    sf(n);
    pf(n);
    spc;
    rep(i,1,n)
    pf(i),spc;
    nl;
    out 0;
}


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


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


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int tab[1000];
int permutation(int n){
  if(n==1)return 0;
  int temp;
  temp=tab[n-2];
  tab[n-2]=tab[n-1];
  tab[n-1]=temp;
  permutation(n-1);
}
int main() {
  int n;
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    tab[i]=i+1;
  }
  permutation(n);
  for (int i = 0; i < n; i++) {
    printf("%d ",tab[i]);
  }
  return 0;
}


#include<stdio.h>

int main()
{
	int i, n;
	scanf("%d", &n);
	printf("%d ", n);
	for(i=1; i<=n-1; i++)
	printf("%d ", i);
	return 0;
}


#include<stdio.h>

int swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
/*
void xxx(int x,int ar[])
{
if(x==1) return;
else
{
xxx(x-1,ar);
swap(&ar[x],&ar[x-1]);
}
}*/
int main()
{
    int n;
scanf("%d",&n);
int ar[n];
for(int i=0;i<n;i++)
ar[i]=i+1;
for(int i=0;i<n-1;i++)
swap(&ar[i],&ar[i+1]);
    //xxx(n,ar);
    for(int i=0;i<n;i++)
    printf("%d ",ar[i]);
    return 0;
}


#include<stdio.h>

int swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
/*
void xxx(int x,int ar[])
{
if(x==1) return;
else
{
xxx(x-1,ar);
swap(&ar[x],&ar[x-1]);
}
}*/
int main()
{
    int n;
scanf("%d",&n);
int ar[n];
for(int i=0;i<n;i++)
ar[i]=i+1;
for(int i=n-1;i>0;i--)
swap(&ar[i],&ar[i-1]);
    //xxx(n,ar);
    for(int i=0;i<n;i++)
    printf("%d ",ar[i]);
    return 0;
}


#include<stdio.h>

void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}

void xxx(int x,int ar[])
{
if(x==0) return;
else
{
swap(&ar[x],&ar[x-1]);
xxx(x-1,ar);

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

    xxx(n-1,ar);
    for(int i=0;i<n;i++)
    printf("%d ",ar[i]);
    return 0;
}


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

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


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


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


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


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

    for(i=1;i<=n;i++)
    {
        s=i;
    }
    for(i=s;s>=1;s--)
    {
        printf("%d ",s);
    }

}


#include<stdio.h>
int main()
{
	int n,i;
	scanf("%d",&n);
	printf("%d ",n);
	for(i=1;i<n;i++)
	printf("%d ",i);

	return 0;
}


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


#include<stdio.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    if(n==1){printf("1\n");}
    else{
        for(i=n; i>0; i--)
        {
            printf("%d ",i);
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    if(n==1){printf("1\n");}
    else{
            printf("%d ",n);
        for(i=1; i<n; i++)
        {
            printf("%d ",i);
        }
        printf("\n");
    }
    return 0;
}


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const len = +readLine();
  const result = [];

  result.push(len);
  for (let i = 1; i < len; i++) {
    result.push(i);
  }

  console.log(result.join(" "));
}


function read_input(){
    var n ;
 const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
  })

  readline.question("", (n) => {
    //console.log(`Hi ${name}!`)
    console.log(n);
    for(i=1 ; i <= n-1 ;i++){
        console.log(i);}
        readline.close()
  })
}

read_input()


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let n = readLine() >> 0;
	let a = [];
	for (let i = n; i >= 1; --i) {
		a.push(i);
	}
	console.log(a.join(' '));
}


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let n = readLine() >> 0;
	let a = [n];
	for (let i = 1; i < n; ++i) {
		a.push(i);
	}
	console.log(a.join(' '));
}


process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let n = parseInt(readLine());
    let numbers = [];
    for (let i = n; i >= 1; i--) {
        numbers.push(i);
    }
    console.log(...numbers);
}


process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let n = parseInt(readLine());
    let numbers = [];
    for (let i = 1; i < n; i++) {
        numbers.push(i);
    }
    console.log(n, ...numbers);
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
                Console.WriteLine(count+" "+string.Join(" ",Enumerable.Range(1,count-1)));
        }
    }
}


using System;
class Test {
    static int [] a;
    static void per(int n){
        if(n!=1){
            int tmp = a[n-1];
            a[n-1] = a[n];
            a[n] = tmp;
            per(n-1);
        }
    }
    static void Main() {
        int n = int.Parse(Console.ReadLine());
        a = new int[n+1];
        string ans = "";
        for(int i = 1 ; i <= n ; i++){
            a[i] = i;
        }
        per(n);
        for(int j = 1 ; j<a.Length ; j++){
            ans += a[j] + " ";
        }
        Console.WriteLine(ans.Trim());
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A31_08_12
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Console.Write("{0}", n);
            for (int i = 1; i <= n-1; i++)
                Console.Write("{0} ", i);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A31_08_12
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Console.Write("1");
            for (int i = 1; i <= n-1; i++)
                Console.Write("{0} ", i);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A31_08_12
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Console.Write("{0} ", n);
            for (int i = 1; i <= n-1; i++)
                Console.Write("{0} ", i);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A31_08_12
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 2; i <= n; i++)
                Console.Write("{0} ", i);
            Console.Write("1");
            //Console.ReadLine();
        }
    }
}


namespace Ap1
{
    class Program
    {
        static void Main()
        {
            string in1, in2;
            in1 = System.Console.ReadLine();
            int n, i;
            n = int.Parse(in1);
            System.Console.WriteLine(n);
            for (i = n-1; i >= 1; i--)
                System.Console.WriteLine(i);
        }
    }
}


namespace Ap1
{
    class Program
    {
        static void Main()
        {
            string in1, in2;
            in1 = System.Console.ReadLine();
            int n, i;
            n = int.Parse(in1);
            for (i = n; i >= 1; i--)
                System.Console.WriteLine(i);
        }
    }
}


namespace Ap1
{
    class Program
    {
        static void Main()
        {
            string in1, in2;
            in1 = System.Console.ReadLine();
            int n, i;
            n = int.Parse(in1);
            System.Console.WriteLine(n);
            for (i = 1; i < n; i++)
                System.Console.WriteLine(i);
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    class _221A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(string.Join(" ", new int[] { n }.Concat(Enumerable.Range(1, n - 1))));
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    class _221A
    {
        public static void Main() => Console.WriteLine(string.Join(" ", Enumerable.Range(1, int.Parse(Console.ReadLine())).Reverse()));
    }
}


/*
 * Created by SharpDevelop.
 * User: Jeremy
 * Date: 9/5/2012
 * Time: 9:23 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

	/// <summary>
	/// Description of Class1.
	/// </summary>
	public class Function
	{
		public static void Main(String[] args)
		{
			print(Int32.Parse(Console.ReadLine()));
		}
		public static void print(int n)
		{
			String str="";
			str+=n;
			for(int i=1;i<n;i++)
				str+=" "+i;
			Console.WriteLine(str);
		}
	}


/*
 * Created by SharpDevelop.
 * User: Jeremy
 * Date: 9/5/2012
 * Time: 9:23 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

	/// <summary>
	/// Description of Class1.
	/// </summary>
	public class Function
	{
		public static void Main(String[] args)
		{
			print(Int32.Parse(Console.ReadLine()));
		}
		public static void print(int n)
		{
			if(n==1)
				Console.WriteLine(n);
			else
			{
				Console.Write(n+" ");
				print(n-1);
			}
		}
	}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        public static int x;
        static void Main(string[] args)
        {
            x = Convert.ToInt32(Console.ReadLine());
            Console.Write(x + " ");
            recursive(1);
            Console.Read();
        }

        public static int recursive(int y)
        {
            Console.Write(y + " ");
            if (x-1 == y || x==y)
                return x-1;
            else
                return recursive(y + 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        public static int x;
        static void Main(string[] args)
        {
            x = Convert.ToInt32(Console.ReadLine());
            Console.Write(x + " ");
            if(x!=1)
                recursive(1);
            Console.Read();
        }

        public static int recursive(int y)
        {
            Console.Write(y + " ");
            if (x-1 == y || x==y)
                return x-1;
            else
                return recursive(y + 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        public static int x;
        static void Main(string[] args)
        {
            x = Convert.ToInt32(Console.ReadLine());
            Console.Write(x + " ");
            recursive(1);
            Console.Read();
        }

        public static int recursive(int y)
        {
            Console.Write(y + " ");
            if (x-1 == y)
                return x-1;
            else
                return recursive(y + 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputNumber = Convert.ToInt32(Console.ReadLine());
            Console.Write(inputNumber.ToString());
            fun1(inputNumber);
            Console.WriteLine();
        }
        public static void fun1(int value)
        {
            if (value > 1)
            {

                value--;
                fun1(value);
                Console.Write(" " + value.ToString());

            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            int nu = Convert.ToInt32(Console.ReadLine());

            Console.Write(nu);
            for (int i = 1; i < nu; i++)
            {
                Console.Write(" "+i);
            }

            //Console.ReadKey();

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            int nu = Convert.ToInt32(Console.ReadLine());

            Console.Write(nu);
            for (int i = 1; i < nu; i++)
            {
                Console.Write(i);
            }

            //Console.ReadKey();

        }
    }
}


using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace temp
{
    class MainClass
    {
        private static Int32[] read_ints(int n) {
            string[] str = Console.ReadLine().Split(new char[]{' '});
            Int32[] ret = new Int32[n];
            for (Int32 i = 0; i < n; i++)
                ret[i] = Convert.ToInt32(str[i]);
            return ret;
        }

        private static Int32 read_int() {
            return Convert.ToInt32(Console.ReadLine());
        }

        private static Int64[] read_longs(int n) {
            string[] str = Console.ReadLine().Split(new char[]{' '});
            Int64[] ret = new Int64[n];
            for (Int64 i = 0; i < n; i++)
                ret[i] = Convert.ToInt64(str[i]);
            return ret;
        }

        private static Int64 read_long() {
            return Convert.ToInt64(Console.ReadLine());
        }

        private static string read_line() {
            return Console.ReadLine();
        }

        public static void Main (string[] args)
        {
            int n = read_int();
            Console.Write("{0} ", n);
            for (int i = 1; i < n; i++)
                Console.Write("{0} ", i);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Reflection;

class Program
{
    static void solve()
    {
        int n = RI();

        Console.Write(n + " ");
        for (int i = 1; i < n; i++)
        {
            Console.Write(i + " ");
        }
    }

    #region
    struct quat<T1, T2, T3, T4> { public T1 fst; public T2 snd; public T3 thr; public T4 frt;}
    struct trip<T1, T2, T3> { public T1 fst; public T2 snd; public T3 thr;}
    struct pair<T1, T2> { public T1 fst; public T2 snd;}
    static long LCM(long a, long b) { return a / GCD(a, b) * b; }
    static long GCD(long a, long b) { if (b == 0) return a; else return GCD(b, a % b); }
    static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
    static double Dist(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)); }
    static long Factorial(int n) { long ans = 1; for (int i = 2; i <= n; i++)ans *= i; return ans; }
    static void Fill<T>(T[] d, T v) { for (int i = 0; i < d.Length; i++)d[i] = v; }
    static void Fill<T>(T[,] d, T v) { for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { d[i, j] = v; } } }
    static T[] RA<T>() { return RLine().Split().Select(v => (T)Convert.ChangeType(v, typeof(T))).ToArray(); }

    static void Main()
    {
#if DEBUG
        StreamWriter fout;
        Console.SetIn(new StreamReader("input.txt"));
        Console.SetOut(fout = new StreamWriter("output.txt"));
#endif
        solve();
#if DEBUG
        fout.Close();
#endif
    }

    static string RLine()
    {
        return Console.ReadLine();
    }

    static int RC()
    {
        return Console.Read();
    }

    static double RD()
    {
        bool m = false;
        double val = 0;
        int c = 0, r = 1;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-')
        {
        }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m = true : m = false) ? 0 : 0;
        while ((c = Console.Read()) >= '0' && c <= '9')
            val = val * 10 + (m ? -(c - 48) : (c - 48));
        if (c == '.')
            while ((c = Console.Read()) >= '0' && c <= '9')
            {
                val += ((double)(c - 48)) / (r *= 10);
            }

        return val;
    }

    static long RL()
    {
        long val = 0;
        bool m = false;
        int c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-')
        {
        }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m = true : m = false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9)
            val = val * 10 + (m ? -c : c);
        return val;
    }

    static int RI()
    {
        bool m = false;
        int val = 0, c;
        while (((c = Console.Read()) < '0' || c > '9') && c != '-')
        {
        }
        val = (c >= '0' && c <= '9') ? c - 48 : (c == '-' ? m = true : m = false) ? 0 : 0;
        while ((c = Console.Read() - 48) >= 0 && c <= 9)
            val = val * 10 + (m ? -c : c);
        return val;
    }
}
    #endregion


using System;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Console.Write(n + " ");
            if (n - 1 > 0) Console.Write(1 + " ");
            for (int i = 2; i < n; i++)
                Console.Write(i + " ");
        }
    }
}


using System;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 2; i <= n; i++)
                Console.Write(i + " ");
            Console.WriteLine(1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
          int e = 0, o = 0;

            for (int i = 0; i <x; i++)
            {
                if (i==0)
                {
                    Console.Write(x + " ");

                }
                else
                {
                    Console.Write(i + " ");
                }
            }
            Console.WriteLine();
        }
    }
}


#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
const int N = 1e5 + 7, M = 2 * N;

vector<pair<int, ll>> adj[N];

struct edge {
    int u, v;
    ll c;
};

edge edgeList[M];
edge trains[M];

int ecnt = 0;

ll dis[N];
int n, m, k;

void dijkstra(int src) {
    memset(dis, '?', n * sizeof dis[0]);
    priority_queue<pair<ll, int>> q;
    dis[src] = 0;
    q.emplace(0, src);
    while (!q.empty()) {
        int u = q.top().second;
        ll d = -q.top().first;
        q.pop();
        if (d != dis[u]) continue;
        for (auto &e : adj[u]) {
            int v = e.first;
            ll nd = dis[u] + e.second;
            if (nd < dis[v]) {
                dis[v] = nd;
                q.emplace(-nd, v);
            }
        }
    }
}

int reach[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
    freopen("in", "rt", stdin);
#endif

    cin >> n >> m >> k;
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        --u, --v;
        adj[u].emplace_back(v, c);
        adj[v].emplace_back(u, c);
        edgeList[ecnt++] = {u, v, c};
        edgeList[ecnt++] = {v, u, c};
    }
    for (int i = 0; i < k; ++i) {
        int v, c;
        cin >> v >> c;
        --v;
        trains[i] = {0, v, c};
        adj[0].emplace_back(v, c);
    }
    dijkstra(0);

    for (int i = 0; i < ecnt; ++i) {
        edge &e = edgeList[i];
        if (dis[e.u] + e.c == dis[e.v])
            reach[e.v] = 1;
    }

    int remove = 0;
    for (int i = 0; i < k; ++i) {
        edge &e = trains[i];

        if (reach[e.v] || dis[e.u] + e.c != dis[e.v])
            remove++;
        else
            reach[e.v] = 1;
    }

    cout << remove << endl;
}


#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
const int N = 1e5 + 7, M = 6e5 + 7, TR = 1e5 + 7;

vector<pair<int, ll>> adj[N];

struct edge {
    int u, v;
    ll c;
};

edge edgeList[M];
edge trains[TR];

int ecnt = 0;

ll dis[N];
int n, m, k;

void dijkstra(int src) {
    memset(dis, '?', n * sizeof dis[0]);
    priority_queue<pair<ll, int>> q;
    dis[src] = 0;
    q.emplace(0, src);
    while (!q.empty()) {
        int u = q.top().second;
        ll d = -q.top().first;
        q.pop();
        if (d != dis[u]) continue;
        for (auto &e : adj[u]) {
            int v = e.first;
            ll nd = dis[u] + e.second;
            if (nd < dis[v]) {
                dis[v] = nd;
                q.emplace(-nd, v);
            }
        }
    }
}

int reach[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
    freopen("in", "rt", stdin);
#endif

    cin >> n >> m >> k;
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        cin >> u >> v >> c;
        --u, --v;
        adj[u].emplace_back(v, c);
        adj[v].emplace_back(u, c);
        edgeList[ecnt++] = {u, v, c};
        edgeList[ecnt++] = {v, u, c};
    }
    for (int i = 0; i < k; ++i) {
        int v, c;
        cin >> v >> c;
        --v;
        trains[i] = {0, v, c};
        adj[0].emplace_back(v, c);
    }
    dijkstra(0);

    for (int i = 0; i < ecnt; ++i) {
        edge &e = edgeList[i];
        if (dis[e.u] + e.c == dis[e.v])
            reach[e.v] = 1;
    }

    int remove = 0;
    for (int i = 0; i < k; ++i) {
        edge &e = trains[i];

        if (reach[e.v] || dis[e.u] + e.c != dis[e.v])
            remove++;
        else
            reach[e.v] = 1;
    }

    cout << remove << endl;
}


#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
typedef long long ll;
const int N = 1e5 + 7, M = 6e5 + 7;

//first: cst, second: v
vector<vector<pair<int, int>>> adj;

int n, m, k;

ll dis[N];

void dijkstra(int src) {
    //create a priority queue where the smallest element is at top
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;

    //initialize dis array with a very big number
    memset(dis, '?', n * sizeof dis[0]);

    pq.push({0, src});
    dis[src] = 0;

    while (!pq.empty()) {
        auto cur = pq.top();
        pq.pop();
        int u = cur.second;
        ll d = cur.first;

        if (d != dis[u]) continue;

        for (auto e : adj[u]) {
            int cst = e.first, v = e.second;
            ll nd = dis[u] + cst;
            if (nd < dis[v]) {
                pq.push({nd, v});
                dis[v] = nd;
            }
        }
    }
}

int fromB[M], toB[M], cstB[M];
int toT[N], cstT[N];

int reach[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
    freopen("in", "rt", stdin);
#endif
    scanf("%d%d%d", &n, &m, &k);
    adj.clear();
    adj.resize(n);
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        scanf("%d%d%d", &u, &v, &c);
        fromB[i] = --u, toB[i] = --v, cstB[i] = c;
        adj[u].push_back({c, v});
        adj[v].push_back({c, u});
    }
    for (int i = 0; i < k; ++i) {
        int c, v;
        scanf("%d%d", &v, &c);
        toT[i] = v, cstT[i] = c;
        adj[0].push_back({c, v});
    }
    dijkstra(0);
    for (int i = 0; i < m; ++i) {
        int u = fromB[i], v = toB[i], c = cstB[i];
        if (dis[u] + c == dis[v])
            reach[v] = 1;
    }
    int remove = 0;
    for (int i = 0; i < k; ++i) {
        int v = toT[i], c = cstT[i];
        //if e is not relaxed or reach[e.v]
        if (c != dis[v] || reach[v])
            ++remove;
        else
            reach[v] = 1;
    }
    printf("%d\n", remove);
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            if (train[a] != w)
                rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);

    return 0;
}
/*
3 2 2
1 2 7
2 3 6
2 5
3 11
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int train[1000010];
int remv[1000010];

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    vector<ll> dist(n + 1, 1e15), prev(n + 1, -1);
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prev[e1.to] = e1.from;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = ne.cost + dist[ne.from];
                q.push(ne);
            }
        }
    }
    ll cnt = 0;
    for (ll i = 1; i <= n; ++i) {
        cnt += remv[i];
        if (train[i] != -1 && dist[i] <= train[i])
            cnt++;
    }
    cout << cnt;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            if (train[a] <= w)
                remv[a]++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);
vector<ll> prv(1e5 + 10, -1);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prv[e1.to] = e1.from;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = dist[ne.from] + ne.cost;
                q.push(ne);
            }
            if (dist[ne.to] == dist[ne.from] + ne.cost && train[ne.to] > -1 && train[ne.from] > -1)
                rm++;
        }
    }
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (dist[i] <= train[i]) {
            train[i] = -1;
            rm++;
        } else if (train[i] != -1) {
            graph[1].push_back(e(1, i, train[i]));
            graph[i].push_back(e(i, 1, train[i]));
        }
    }
    fill(prv.begin(), prv.end(), -1);
    fill(dist.begin(), dist.end(), 1e15);
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (train[i] != -1 && prv[i] != 1) rm++;
    }
    cout << rm;
    return 0;
}
/*
7 6 5
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
3 5
4 5
5 5
6 4
7 7

8 7 6
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
6 8 2
3 5
4 5
5 5
6 4
7 7
8 6
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    vector<ll> dist(n + 1, 1e15), prev(n + 1, -1);
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prev[e1.to] = e1.from;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = ne.cost + dist[ne.from];
                q.push(ne);
            }
        }
    }
    ll cnt = 0;
    for (ll i = 1; i <= n; ++i) {
        cnt += remv[i];
        if (train[i] != -1 && dist[i] <= train[i])
            cnt++;
    }
    cout << cnt;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            if (train[a] <= w)
                remv[a]++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);
vector<ll> prv(1e5 + 10, -1);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prv[e1.to] = e1.from;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = dist[ne.from] + ne.cost;
                q.push(ne);
            }
        }
    }
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (dist[i] <= train[i]) {
            train[i] = -1;
            rm++;
        }
        else if(train[i] != -1){
            graph[1].push_back(e(1, i, train[i]));
            graph[i].push_back(e(i, 1, train[i]));
        }
    }
    fill(prv.begin(), prv.end(), -1);
    fill(dist.begin(), dist.end(), 1e15);
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (train[i] != -1 && prv[i] != 1) rm++;
    }
    cout << rm;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
bool c[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        int s = graph[e1.to].size();
        for (ll i = 0; i < s; ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

ll dup[100010][100010];

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        if (dup[a][b] != 0 && dup[a][b] < w) continue;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
        dup[a][b] = w;
        dup[b][a] = w;
        if (a == 1 || b == 1) {
            int y = max(a, b);
            c[y] = 1;
        }
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
        if (!c[a]) {
            c[a] = 1;
            graph[1].push_back(e(1, a, 1e15));
        }
    }
    Dijkstra(graph, 1);

    return 0;
}
/*
5 3 4
1 2 7
2 3 6
5 4 3
2 5
3 11
4 6
5 3
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
bool c[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
        if (a == 1 || b == 1) {
            int y = max(a, b);
            c[y] = 1;
        }
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    for (int i = 2; i < n + 1; ++i) {
        if (!c[i] && train[i] > -1) {
            graph[1].push_back(e(1, i, train[i] + 1));
            graph[i].push_back(e(i, 1, train[i] + 1));
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll rmv[1000010];
ll rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);
vector<ll> prv(1e5 + 10, -1);

void Dijkstra(vector<vector<e>> &graph, ll s, bool b = false) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prv[e1.to] = e1.from;

        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = dist[ne.from] + ne.cost;
                q.push(ne);
            }
            if (b && dist[ne.to] == dist[ne.from] + ne.cost && train[ne.to] > -1 && ne.from != 1) {
                rmv[ne.to]++;
            }
        }
    }
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (dist[i] <= train[i]) {
            train[i] = -1;
            rm++;
        } else if (train[i] != -1) {
            graph[1].push_back(e(1, i, train[i]));
            graph[i].push_back(e(i, 1, train[i]));
        }
    }
    fill(prv.begin(), prv.end(), -1);
    fill(dist.begin(), dist.end(), 1e15);
    Dijkstra(graph, 1, 1);
    for (int i = 1; i <= n; ++i) {
        if ((train[i] != -1 && prv[i] != 1) || rmv[i]) {
            rm++;
        }
    }
    cout << rm;
    return 0;
}
/*
7 6 5
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
3 5
4 5
5 5
6 4
7 6

8 7 6
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
6 8 2
3 5
4 5
5 5
6 4
7 6
8 6

8 8 6
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
6 8 2
1 8 2
3 5
4 5
5 5
6 4
7 1
8 3
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int train[1000010];
int remv[1000010];

struct e {
    int from, to, cost;

    e(int from, int to, int cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

void Dijkstra(vector<vector<e>> &graph, int s, int d) {
    int n = graph.size();
    vector<ll> dist(n + 1, 1e15), prev(n + 1, -1);
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prev[e1.to] = e1.from;
        for (int i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = ne.cost + dist[ne.from];
                q.push(ne);
            }
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        cnt += remv[i];
        if (train[i] != -1 && dist[i] <= train[i])
            cnt++;
    }
    cout << cnt;
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (int i = 0; i < m; ++i) {
        int a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (int i = 0; i < k; ++i) {
        int a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            if (train[a] <= w)
                remv[a]++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1, n);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);
vector<ll> prv(1e5 + 10, -1);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prv[e1.to] = e1.from;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = dist[ne.from] + ne.cost;
                q.push(ne);
            }
        }
    }
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (dist[i] <= train[i]) {
            train[i] = -1;
            rm++;
        }
        else if(train[i] != -1){
            graph[1].push_back(e(1, i, train[i]));
            graph[i].push_back(e(i, 1, train[i]));
        }
    }
    fill(prv.begin(), prv.end(), -1);
    fill(dist.begin(), dist.end(), 1e15);
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (train[i] != -1 && prv[i] != 1) rm++;
    }
    cout << rm;
    return 0;
}
/*
7 6 5
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
3 5
4 5
5 5
6 4
7 7

8 7 6
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
6 8 2
3 5
4 5
5 5
6 4
7 7
8 6
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
bool c[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
        graph[1].push_back(e(1, a, train[a] + 1));
        graph[a].push_back(e(a, 1, train[a] + 1));
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
bool c[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
        if (a == 1 || b == 1) {
            int y = max(a, b);
            c[y] = 1;
        }
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
        if (!c[a]) {
            c[a] = 1;
            graph[1].push_back(e(1, a, 1e15));
        }
    }
    Dijkstra(graph, 1);

    return 0;
}
/*
5 3 4
1 2 7
2 3 6
5 4 3
2 5
3 11
4 6
5 3
*/


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
ll nk = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    for (ll i = 1; i <= n; ++i) {
        nk += remv[i];
    }
    cout << nk;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            if (train[a] <= w)
                remv[a]++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll remv[1000010];
bool c[1000010];
ll nk = 0, rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);

void Dijkstra(vector<vector<e>> &graph, ll s) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] >= dist[ne.from] + ne.cost) {
                if (dist[ne.from] + ne.cost <= train[ne.to]) {
                    nk++;
                    train[ne.to] = -1;
                } else if (train[ne.to] != -1) {
                    ne.cost = dist[ne.to] = train[ne.to];
                }
                q.push(ne);
            }
        }
    }
    cout << nk + rm;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
        if (a == 1 || b == 1) {
            int y = max(a, b);
            c[y] = 1;
        }
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    for (int i = 2; i < n + 1; ++i) {
        if (!c[i] && train[i] > -1) {
            graph[1].push_back(e(1, i, train[i] + 1));
        }
    }
    Dijkstra(graph, 1);

    return 0;
}


#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

ll train[1000010];
ll rmv[1000010];
ll rm = 0;

struct e {
    ll from, to, cost;

    e(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {}

    bool operator<(const e &e1) const {
        return cost > e1.cost;
    }
};

vector<ll> dist(1e5 + 10, 1e15);
vector<ll> prv(1e5 + 10, -1);

void Dijkstra(vector<vector<e>> &graph, ll s, bool b = false) {
    ll n = graph.size();
    dist[s] = 0;
    priority_queue<e> q;
    q.push(e(-1, s, 0));
    while (!q.empty()) {
        e e1 = q.top();
        q.pop();
        if (e1.cost > dist[e1.to]) continue;
        prv[e1.to] = e1.from;

        for (ll i = 0; i < graph[e1.to].size(); ++i) {
            e ne = graph[e1.to][i];
            if (dist[ne.to] > dist[ne.from] + ne.cost) {
                ne.cost = dist[ne.to] = dist[ne.from] + ne.cost;
                q.push(ne);
            }
            if (b && dist[ne.to] == dist[ne.from] + ne.cost && train[ne.to] > -1 && train[ne.from] > -1) {
                rmv[ne.to]++;
            }
        }
    }
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<e>> graph(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll a, b, w;
        cin >> a >> b >> w;
        graph[a].push_back(e(a, b, w));
        graph[b].push_back(e(b, a, w));
    }
    memset(train, -1, sizeof(train));
    for (ll i = 0; i < k; ++i) {
        ll a, w;
        cin >> a >> w;
        if (train[a] == -1)
            train[a] = w;
        else {
            rm++;
            train[a] = min(w, train[a]);
        }
    }
    Dijkstra(graph, 1);
    for (int i = 1; i <= n; ++i) {
        if (dist[i] <= train[i]) {
            train[i] = -1;
            rm++;
        } else if (train[i] != -1) {
            graph[1].push_back(e(1, i, train[i]));
            graph[i].push_back(e(i, 1, train[i]));
        }
    }
    fill(prv.begin(), prv.end(), -1);
    fill(dist.begin(), dist.end(), 1e15);
    Dijkstra(graph, 1, 1);
    for (int i = 1; i <= n; ++i) {
        if ((train[i] != -1 && prv[i] != 1) || rmv[i]) {
            rm++;
        }
    }
    cout << rm;
    return 0;
}
/*
7 6 5
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
3 5
4 5
5 5
6 4
7 6

8 7 6
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
6 7 2
6 8 2
3 5
4 5
5 5
6 4
7 6
8 6
*/