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>
#include <string.h>
using namespace std;

int dp[101][4][4];//何日目から、どのぱすたを、何日連続で食べているか
int plan[101];//先に決められている予定　要素：日付

#define MOD 10000;

int main(void)
{
		int day;
		int k;
		cin >> day >> k;
		memset(plan,0,sizeof(plan));
		for(int i=0;i<k;++i){
			int d,p;
			cin >> d >> p;
			plan[d] = p;
		}
		memset(dp,0,sizeof(dp));

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

		for(int d=2;d<=day;++d){//どの日から？
			for(int p=1;p<=3;++p){//どのパスタを？
				if(plan[d]){
					dp[d][plan[d]][1] = (dp[d-1][(plan[d]+1)%3+1][1] + dp[d-1][(plan[d]+1)%3+1][2] + dp[d-1][plan[d]%3+1][1] + dp[d-1][plan[d]%3+1][2])%MOD;
					dp[d][plan[d]][2] = dp[d-1][plan[d]][1] % MOD;
				}
				else{
					dp[d][p][1] = (dp[d-1][(p+1)%3+1][1] + dp[d-1][(p+1)%3+1][2] + dp[d-1][p%3+1][1] + dp[d-1][p%3+1][2])%MOD;
					dp[d][p][2] = dp[d-1][p][1] % MOD;
				}
			}
		}
		int ans = dp[day][1][1] + dp[day][2][1] + dp[day][3][1] + dp[day][1][2] + dp[day][2][2] + dp[day][3][2];
		cout << ans << endl;
	return 0;
}

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 % 10000) + 10000) % 10000;
    }
  }

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

C++: #include <iostream>
using namespace std;
int N,K;
int sum;
int main() {
	int DP[100][3][3]={0},EN[101]={0};
	cin >> N >> K;
	int x,y,can;
	
	for(int i=0;i<K;i++){
	cin >> x >> y;
		EN[x]=y;
		
	}

	for(int i=0;i<3;i++){
		if(EN[1]==0 || EN[1]==i+1)
			DP[0][i][(i+1)%3]=1;
	}
	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				for(int l=0;l<3;l++){
					if((!(j==k && k==l)) && ((EN[i+1]==j+1) || EN[i+1]==0)){
				DP[i][j][k]=(DP[i][j][k]+DP[i-1][k][l])%10000;

					}
					
				}
				//cout << i << j << k << " " << DP[i][j][k] << endl;
			}
		}
	}
	
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				sum+=DP[N-1][j][k];
			}
		}
		cout << sum%10000 << endl;
	// your code goes here
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N, K, c[105]{}, dp[105][3][4]{};  // dp[i][j][k] = i日目にパスタjをk回連続で食べるときの通り
    cin >> N >> K;
    for(int i=0;i<K;i++){
        int a, b;
        cin >> a >> b;
        c[a] = b;
    }

    dp[0][0][0] = 1;
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(c[i+1]>0 && c[i+1]!=k+1)continue;  // 予定と異なる場合は弾く
                for(int l=0;l<3;l++){
                    if(j==k){  // 前日と同じパスタを食べる遷移
                        dp[i+1][k][l+1] += dp[i][j][l];
                        dp[i+1][k][l+1] %= 10000;
                    }
                    else{  // 前日と異なるパスタを食べる遷移
                        dp[i+1][k][1] += dp[i][j][l];
                        dp[i+1][k][1] %= 10000;
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ans += dp[N][i][j];
            ans %= 10000;
        }
    }
    cout << ans << endl;
    return 0;
}