#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e6+10;
const int mod=1e9+7;
int dp[maxn][3];
int quick(int a,int n)
{
    int ans=1;
    int x=a;
    while(n!=0)
    {
        if(n%2==1) {ans=ans%mod*x%mod; n--; }
        else       { x=x%mod*x%mod;n=n/2;  }
    }
    return ans%mod;
}
int32_t main()
{
    int T; cin>>T;
    while(T--)
    {
        memset(dp,0,sizeof(dp));
        int n,k; cin>>n>>k;
        k=quick(2,k);
        dp[1][0]=k%mod;//  1
        dp[1][1]=0;// qi ta
        dp[1][2]=0;// bu neng de
        for(int i=2;i<=n;i++)
        {
            dp[i][0]=dp[i-1][0]%mod+dp[i-1][1]%mod;
            dp[i][1]=dp[i-1][0]*(k-2)+dp[i-1][1]*(k-3)%mod+dp[i-1][2]*(k-2)%mod;
            dp[i][2]=dp[i-1][2]%mod+dp[i-1][1]%mod;
            dp[i][0]=dp[i][0]%mod;
            dp[i][1]=dp[i][1]%mod;
            dp[i][2]=dp[i][2]%mod;
           // cout<<dp[i][0]<<"  "<<dp[i][1]<<"  "<<dp[i][2]<<endl;
        }
        cout<<(dp[n][0]+dp[n][1])%mod<<endl;
    }
}
A.cpp

 

 

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T; scanf("%d",&T);
    while(T--)
    {
        map<pair<int,int>,int> mp;
        map<pair<int,int>,int> tf;
        int num; scanf("%d",&num);
        int ans=0;
        for(int i=1;i<=num;i++)
        {
            int k;  scanf("%d",&k);
            for(int j=1;j<=k;j++)
            {
                int a,b; scanf("%d %d",&a,&b);
                if(tf[{a,b}]==i) continue;
                if(tf[{a,b}]==i-1)
                {
                      tf[{a,b}]=i;
                      mp[{a,b}]++;
                      if(mp[{a,b}]>ans) ans=mp[{a,b}];
                }
                else
                {
                      tf[{a,b}]=i;
                      mp[{a,b}]=1;
                      if(mp[{a,b}]>ans) ans=mp[{a,b}];
                }
            }
        }printf("%d\n",ans);
    }
}
F.cpp

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int T; cin>>T;
    while(T--)
    {
        int n; char z;
        cin>>n>>z;
        string ss; cin>>ss;
        int ans=0;
        int t=0;
        for(int i=0;i<n;i++)
        {
            int k=abs(z-ss[i]);
            if(t==0)
            {
                if(k==0) continue;
                else
                {
                    if(k<10) ans+=1;
                    else if(k<100) ans+=2;
                    else if(k<1000) ans+=3;

                }
                t=1;
            }
            else if(t==1) ans+=2;
        }
        if(ans==0) ans=1;
        cout<<ans<<endl;
    }
}
I.cpp