Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

C++: #include<iostream>
using namespace std;

int n,k,a,b,p[100];

int fanc(int i,int x,int y,int z)
{
  int c[3][3][3];
  if(i==0){
    for(int j1=0;j1<3;j1++){
      for(int j2=0;j2<3;j2++){
	for(int j3=0;j3<3;j3++){
	  c[j1][j2][j3]=1;
	}
      }
    }
  }
  
  else{
    for(int j1=0;j1<3;j1++){
      c[x][y][j1]+=fanc(i--,j1,x,y);
    }
  }
  
  for(int j1=0;j1<3;j1++){
    c[j1][j1][j1]=0;
  }
  
  if(p[i]){
    for(int j1=0;j1<3;j1++){
      for(int j2=0;j2<3;j2++){
	for(int j3=0;j3<3;j3++){
	  if(j1!=p[i]){c[j1][j2][j3]=0;}
	}
      }
    }
  }
  
  if(p[i+1]){
    for(int j1=0;j1<3;j1++){
      for(int j2=0;j2<3;j2++){
	for(int j3=0;j3<3;j3++){
	  if(j2!=p[i]){c[j1][j2][j3]=0;}
	}
      }
    }
  }
  
  if(p[i+2]){
    for(int j1=0;j1<3;j1++){
      for(int j2=0;j2<3;j2++){
	for(int j3=0;j3<3;j3++){
	  if(j3!=p[i]){c[j1][j2][j3]=0;}
	}
      }
    }
  }
  
  
  for(int j1=0;j1<3;j1++){
    for(int j2=0;j2<3;j2++){
      for(int j3=0;j3<3;j3++){
	if(c[j1][j2][j3]>10000){c[j1][j2][j3]%=10000;}
      }
    }
  }

  return c[x][y][z];
  
}

int total()
{
  int sum;
  for(int j1=0;j1<3;j1++){
    for(int j2=0;j2<3;j2++){
      for(int j3=0;j3<3;j3++){
	sum+=fanc(n-3,j1,j2,j3);
      }
    }
  }
  return sum;
}
   
      
int main()
{
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>a>>b;
    p[a-1]=b;
  }

  cout<<total()%10000<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int INF = 1e9;
int MOD=10000;
int dp[110][3][2];
int main(){
	int N,K,a,b;
	int d[110];
	memset(d,-1,sizeof(d));
	cin>>N>>K;
	REP(i,K){
		cin>>a>>b;a--;b--;
		d[a]=b;
	}
	if(d[0]==-1){
		dp[0][0][0]=dp[0][1][0]=dp[0][2][0]=1;
	}else{
		dp[0][d[0]][0]=1;
	}
	for(int i=1;i<N;i++){
		if(d[i]!=-1){
			REP(j,3)if(j!=d[i])dp[i][d[i]][0]+=dp[i-1][j][0]+dp[i-1][j][1];
			dp[i][d[i]][1]+=dp[i-1][d[i]][0];
		}else{
			REP(j,3)REP(k,3)if(j!=k)dp[i][j][0]+=dp[i-1][k][0]+dp[i-1][k][1];
			REP(j,3)dp[i][j][1]+=dp[i-1][j][0];
		}
		REP(j,3)REP(k,2)dp[i][j][k]%=MOD;
	}
	int ans=0;
	REP(i,3)REP(k,2)ans+=dp[N-1][i][k];
	cout<<ans%MOD<<endl;
}

C++: #include <stdio.h>
int N,k;
int day[101]={0};
long long int tem[101][4][3]={0};

long long int cal(int n,int p,int d ){
		if(tem[n][p][d]>0)
			return tem[n][p][d];
		else if(d>=3)
			return 0;
		else if(n>=N)
			return 1;
		else if(day[n+1]>0){
			tem[n][p][d] =cal(n+1,day[n+1],(p==day[n+1])?d+1:1);
			return tem[n][p][d];
		}else{
			tem[n][p][d]= cal(n+1,1,(p==1)?d+1:1)+cal(n+1,2,(p==2)?d+1:1)+cal(n+1,3,(p==3)?d+1:1);
			return tem[n][p][d];
		}
}

int main(void){
	int a,b;
	int total;
	scanf("%d %d",&N,&k);
	for(int i=0;i<k;i++){
		scanf("%d %d",&a,&b);
		day[a]=b;
	}
	total=cal(0,0,0);
	total %=10000;
	printf("%lld\n",total);
	return 0;
}

C++: #include <cstdio>
using namespace std;

int n, k;
int a[100];
int dp[100][3][3];

int main(){
	scanf("%d %d", &n, &k);
	for(int i=0; i<k; i++){
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		a[t1-1] = t2;
	}

	if(a[0] == 0){
		for(int i=0; i<3; i++){
			dp[0][i][0] = 1;
		}
	}else{
		dp[0][a[0]-1][0] = 1;
	}

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

	for(int i=2; i<n; i++){
		if(a[i] == 0){
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					for(int r=0; r<3; r++){
						if(p == q && q == r) continue;
						else{
							dp[i][p][q] += dp[i-1][q][r];
							dp[i][p][q] %= 10000;
						}
					}
				}
			}
		}else{
			for(int p=0; p<3; p++){
				for(int q=0; q<3; q++){
					if(a[i] - 1 == p && p == q) continue;
					else{
						dp[i][a[i] - 1][p] += dp[i-1][p][q];
						dp[i][a[i] - 1][p] %= 10000;
					}
				}
			}
		}
	}
/*
	for(int i=0; i<n; i++)
		printf("%d\t", a[i]);
*/

	for(int i=0; i<n; i++){
		for(int j=0; j<3; j++){
			printf("%d\t", dp[i][j][0] + dp[i][j][1] + dp[i][j][2]);
		}
		printf("\n");
	}

	int ans=0;
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			ans += dp[n-1][i][j];
			ans %= 10000;
		}
	}
	printf("%d\n", ans);
	return 0;
}