#include using namespace std; using ll=long long; // TLE int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin>>N>>K; vector A(N,0),C(N,0); for(int &i:A)cin>>i; for(int &i:C)cin>>i,--i; vector dp(N,vector(N,vector(50,-(int)1e9))); for(int i=0;i0&&dp[(i+j)%N][w-j][k]>0){ dp[i][w][c]=dp[i][j][c]+dp[(i+j)%N][w-j][k]; dp[i][w][k]=dp[i][j][c]+dp[(i+j)%N][w-j][k]; } } } } } } int ans=0; for(int i=0;i