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<bits/stdc++.h>
#define rep(a,b) for(int a=0;a<b;a++)
#define int long long int

using namespace std;

const int INF = 1000000009;

int day,al;
int almost[200];
int ans=1;
int used[200];

int pasu(int p){
    if(p==3)return 1;
    else if(p==2)return 3;
    else if(p==1)return 2;
}

int pasu2(int p){
    if(p==3)return 2;
    else if(p==2)return 1;
    else if(p==1)return 3;
}

int kaburi1(int date){
    if(almost[date+1]!=0){
        return almost[date+1];
    }else return 0;
}

int kaburi2(int date){
    if(almost[date+2]!=0){
        return almost[date+2];
    }else return 0;
}

int memo[200][200][200];

int pasuta(int d2, int d1, int date){
    if(date>day)return 1;
    else if(memo[d2][d1][date]>0)return memo[d2][d1][date];
    else if(almost[date]>0){
            ///?±??????£?????????
            if(d2==d1&&d1==almost[date])return 0;
        else return pasuta(d1,almost[date],date+1)%10000;
    }/*else if(d2==d1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),date+1)+pasuta(d1,pasu2(d1),date+1))%10000;
    }else if(d1==dd1&&d1!=0){
        ///?????\??¨?????????????????¨???
       return memo[d2][d1][date]=(pasuta(d1,pasu(d1),date+1)+pasuta(d1,pasu2(d1),date+1))%10000;
    }else if(dd1==dd2&&dd1!=0){
        ///?????¨?????¨?????????
       return memo[d2][d1][date]=(pasuta(dd1,dd2,date+3)+pasuta(dd1,dd2,date+3))%10000;
    }*/else{
    int an=0;
    for(int i=1;i<=3;i++){
        if(d1==d2&&d1==i)continue;
        an+=pasuta(d1,i,date+1);
    }
    return memo[d2][d1][date]=an%10000;
    }
}

signed main(){
    fill(almost,almost+200,0);
    fill(used,used+200,0);
    cin >> day >> al;
    rep(a,al){
        int da,pa;
        cin >> da >> pa;
        almost[da]=pa;
    }
    ans = pasuta(0,0,1);
    cout << ans%10000 << endl;
return 0;
}

C++: #include <cstdio>
#include <cstring>

#define MOD (10000)

using namespace std;

int sum(int *p)
{
	return (p[0] + p[1]);
}

int main(void)
{
	int n, k;
	static int dp[100][3][2];
	int done[100];
	
	scanf("%d %d", &n, &k);
	
	memset(done, -1, sizeof(done));
	for (int i = 0; i < k; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		done[--a] = --b;
	}
	
	for (int i = 0; i < 3; i++){
		if (~done[0]) dp[0][done[0]][0] = 1;
		else dp[0][i][0] = 1;
	}
	
	for (int i = 1; i < n; i++){
		for (int j = 0; j < 3; j++){
			if (~done[i]){
				j = done[i];
				dp[i][j][0] = (sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
				dp[i][j][1] = dp[i - 1][j][0] % MOD;
				break;
			}
			else {
				dp[i][j][0] = (sum(dp[i - 1][(j + 1) % 3]) + sum(dp[i - 1][(j + 2) % 3])) % MOD;
				dp[i][j][1] = dp[i - 1][j][0] % MOD;
			}
		}
	}
	
	int s = 0;
	for (int i = 0; i < 3; i++){
		s += sum(dp[n - 1][i]);
	}
	
	printf("%d\n", s % MOD);
	
	return (0);
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[100][6];
	int n=0;
	int k=0;
	int c[100];
	int d[100];
	int i=0;
	int j=0;
	int s=0;
	int r=0;
	int h=0;
	
	for(i=0;i<100;i++){
		c[i]=0;
		d[i]=0;
	}
	cin>>n;
	cin>>k;
	for(i=0;i<k;i++){
		cin>>c[i];
		cin>>d[i];
	}
	for(i=0;i<k;i++){
		if(c[i]==1){
			r=1;
			for(j=0;j<6;j++){
				if(j==d[i]*2-2){
					a[0][j]=1;
				}else{
					a[0][j]=0;
				}
			}
		}
	}
	if(r==0){
		a[0][0]=1;
		a[0][1]=0;
		a[0][2]=1;
		a[0][3]=0;
		a[0][4]=1;
		a[0][5]=0;
	}                                                        //ok!
	r=0;
	for(i=1;i<n;i++){
		a[i][0]=a[i-1][2]+a[i-1][3]+a[i-1][4]+a[i-1][5];
		a[i][1]=a[i-1][0];
		a[i][2]=a[i-1][0]+a[i-1][1]+a[i-1][4]+a[i-1][5];
		a[i][3]=a[i-1][2];
		a[i][4]=a[i-1][2]+a[i-1][3]+a[i-1][0]+a[i-1][1];
		a[i][5]=a[i-1][4];
		for(j=0;j<k;j++){
			if(c[j]==i+1){
				for(h=0;h<6;h++){
					if(d[j]-1!=h/2){
						a[i][h]=0;
					}
				}
			}
		}
		for(j=0;j<6;j++){
			if(a[i][j]>10000){
				a[i][j]=a[i][j]%10000;
			}
		}
	}
	for(i=0;i<6;i++){
		s=s+a[n-1][i];
	}
	if(s>=10000){
		s=s%10000;
	}
	cout<<s<<endl;
}

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

struct day
{
  int kind[4];
  int order;
  int sum;
};

int n, k;
int a[100], b[100];
day dp[101];

int main()
{
  cin >> n >> k;
  for(int i = 0; i < k; i++)
    cin >> a[i] >> b[i];

  for(int i = 0; i < k; i++)
    dp[a[i]].order = b[i];

  //day 1
  if(dp[1].order)
    dp[1].sum = dp[1].kind[dp[1].order] = 1;
  else
    for(int i = 1; i <= 3; i++)
      dp[1].sum += dp[1].kind[i] = 1;

  //day 2
  if(dp[2].order)
    dp[2].sum = dp[2].kind[dp[2].order] = dp[1].sum;
  else
    for(int i = 1; i <= 3; i++)
      dp[2].sum += dp[2].kind[i] = dp[1].sum;

  //day 3
  for(int i = 3; i <= n; i++){
    if(dp[i].order){
      if(!dp[i - 1].kind[dp[i].order])
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum;
      else
	dp[i].sum = dp[i].kind[dp[i].order] = dp[i - 1].sum - dp[i - 1].kind[dp[i].order] + dp[i - 2].sum - dp[i - 2].kind[dp[i].order];
    }
    else{
      for(int j = 1; j <= 3; j++){
	
	if(!dp[i - 1].kind[j])
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum;
	else
	  dp[i].sum += dp[i].kind[j] = dp[i - 1].sum - dp[i - 1].kind[j] + dp[i - 2].sum - dp[i - 2].kind[j];
      }

      dp[i].sum = dp[i].sum % 100000;
    }
  }

  cout << dp[n].sum % 10000 << endl;
  return 0;
}