Codeforces 565
失踪人口回归
cf 565 A
题意 你可以把一个偶数变成 n/2 , 可以把一个3的倍数变成 n2/3, 可以把一个5的倍数变成 n4/5
问你最少通过多少步可以变成1
解法 我们发现 2/3是最小的 而且生成2这个因子 ,然后 4/5也能生成 2 所以顺序就是 先 3 后 5 再 2
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
long long n;
scanf("%lld",&n);
if(n==1)
{
printf("0\n");
continue;
}
int tmp = 0;
while(n%3==0&&n!=1)
{
tmp++;
n = n/3*2;
}
while(n%5==0&&n!=1)
{
n = n/5*4;
tmp++;
}
while(n%2==0&&n!=1)
{
n = n / 2;
tmp++;
}
if(n!=1)
{
printf("-1\n");
}
else printf("%d\n",tmp);
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
B
题意 就是给你 n 个数 你能执行若干次两两相交 问你 3 的倍数有多少个 包括 0
那么一拿到数字我们就%=3 然后只需要本身能除尽 然后 1 和 2 ,然后 3个 1 ,3 个 2 统计一下答案即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 1025;
int arr[MAX_N],num[15];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
int n,ans = 0;
scanf("%d",&n);
num[0] = num[1] = num[2] = 0;
for(int i = 1;i<=n;++i) scanf("%d",&arr[i]),arr[i]%=3,num[arr[i]]++;
ans = num[0];
num[0] = 0;
int minn = min(num[1],num[2]);
ans += minn;
num[1]-=minn;
num[2]-=minn;
ans+=num[1]/3;
num[1]%=3;
ans+=num[2]/3;
num[2]%=3;
printf("%d\n",ans);
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
C
一开始读错题意了 没有看见它这6个必须按顺序 于是就写WA了
其实只要关心最后一个数字是否在即可 我这里有个繁琐的做法是用set存进去下标 然后依次比较
如果你只关心能不能凑成 就可以值统计最后一个是否生成
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
int arr[500025],num[50];
set<int > st[100];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
int ans = 0;
for(int i = 1;i<=n;++i) scanf("%d",&arr[i]),st[arr[i]].insert(i);
while(st[4].size())
{
int it = *st[4].begin();
st[4].erase(it);
if(st[8].empty()) break;
else
{
set<int> :: iterator tmp = st[8].upper_bound(it);
if(tmp==st[8].end()) break;
it = *tmp;
st[8].erase(*tmp);
}
if(st[15].empty()) break;
else
{
set<int> :: iterator tmp = st[15].upper_bound(it);
if(tmp==st[15].end()) break;
it = *tmp;
st[15].erase(*tmp);
}
if(st[16].empty()) break;
else
{
set<int> :: iterator tmp = st[16].upper_bound(it);
if(tmp==st[16].end()) break;
it = *tmp;
st[16].erase(*tmp);
}
if(st[23].empty()) break;
else
{
set<int> :: iterator tmp = st[23].upper_bound(it);
if(tmp==st[23].end()) break;
it = *tmp;
st[23].erase(*tmp);
}
if(st[42].empty()) break;
else
{
set<int> :: iterator tmp = st[42].upper_bound(it);
if(tmp==st[42].end()) break;
it = *tmp;
st[42].erase(*tmp);
}
ans++;
}
printf("%d\n",n-ans*6);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
D
题意 如果一个数是质数 他只能生成质数序列的第他本身个质数 否则会生成他的最大因子
首先我们要知道 肯定是把两个质数分开 然后我们发现 只有大的质数会被小的质数生成 比如 3 是 2 生成的 5 是 3 生成的 那么我们从大到小 找到一个质数就把生成他的质数放在答案序列里面 如果不是质数 那么我们就需要把他放进答案序列里面 消除他最大因子的贡献
一开始忘记 n是 2n re了一发
ans[0]和ans[2]是想要的答案
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
int arr[400025];
const int MAX_N = 2751150;
int prime[MAX_N];
int flag[MAX_N+5];
int tot,num[MAX_N];
map<int,int > mp;
void make_prime()
{
for(int i = 2;i<=MAX_N;++i)
{
if(!flag[i])
{
prime[++tot] = i;
mp[i] = tot;
for(int j = i + i;j<=MAX_N;j+=i)
flag[j] = 1;
}
}
}
vector<int > ans[4];
bool cmp(int a,int b)
{
return a > b;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
make_prime();
scanf("%d",&n);
for(int i = 1;i<=2*n;++i)
{
scanf("%d",&arr[i]);
num[arr[i]]++;
}
int cnt = 0;
sort(arr+1,arr+1+2*n,cmp);
for(int i = 1;i<=2*n;++i)
{
if(num[arr[i]])
{
if(!flag[arr[i]])
{
if(num[mp[arr[i]]])
{
num[arr[i]]-- ;
num[mp[arr[i]]]--;
ans[0].push_back(arr[i]);
ans[1].push_back(mp[arr[i]]);
}
else
{
cnt++;
num[arr[i]]--;
ans[2].push_back(arr[i]);
}
}
else
{
cnt++;
num[arr[i]]--;
ans[2].push_back(arr[i]);
for(int j = 2;j*j<=arr[i];++j)
{
if(arr[i]%j==0)
{
num[arr[i]/j]--;
ans[3].push_back(arr[i]/j);
break;
}
}
}
}
}
if(ans[1].size())
{
for(int i = 0;i<ans[1].size();++i)
printf("%d ",ans[1][i]);
}
// for(int i = 0;i<cnt;++i)
// dbg2(i,ans[2][i]);
// dbg(cnt);
if(cnt)
{
for(int i = 0;i<cnt;++i)
printf("%d ",ans[2][i]);
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
E
很简单的染色问题 给点染色即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
vector<int > vt[15],V[200025];
int col[200025];
void dfs(int u,int fa,int COL)
{
col[u] = COL;
int sz = V[u].size();
for(int i = 0;i<sz;++i)
{
int v = V[u][i];
if(v==fa) continue;
if(col[v]==0)
{
dfs(v,u,3-COL);
}
}
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
vector<int > tmp;
swap(vt[1],tmp);
vector<int > tmp_;
swap(vt[2],tmp_);
// dbg2(vt[1].size(),vt[2].size());
int n,m,a,b;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;++i)
{
vector<int> now;
swap(V[i],now);
col[i] = 0;
}
for(int i = 1;i<=m;++i)
{
scanf("%d%d",&a,&b);
V[a].push_back(b);
V[b].push_back(a);
}
dfs(1,0,2);
for(int i = 1;i<=n;++i)
if(col[i]==1) vt[1].push_back(i);
else if(col[i]==2) vt[2].push_back(i);
int sz = vt[1].size(),sz_ = vt[2].size();
// dbg2(sz,sz_);
if(sz>=sz_)
{
printf("%d\n",sz_);
for(int i = 0;i<sz_;++i)
i==sz_-1?printf("%d\n",vt[2][i]):printf("%d ",vt[2][i]);
}
else
{
printf("%d\n",sz);
for(int i = 0;i<sz;++i)
i==sz-1?printf("%d\n",vt[1][i]):printf("%d ",vt[1][i]);
}
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
F
题意 就是一个人有 n 回合 每回合不能超过 3 代价的花费 问你能造成多少点伤害
第十个回合是双倍攻击
那么我们就意识到了这个很像dp 而且跟卡牌轮次有关系
所以我们定义dp[n][10] 代表第 n 轮 当前是第几张牌次
我们发现代价为 3 总共只有 6 种花费
1 花费打一张 tmp[1]
2 花费打一张 tmp[2]
3 花费打一张 tmp[3]
1 + 1 2花费打 2 张 tmp[4]
1 + 2 3花费打 2 张 tmp[5]
1 + 1 + 1 3花费打三张 tmp[6]
然后注意dp转移过来的时候合法性 也就是初始化问题
然后这题会爆万恶的int
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
long long dp[MAX_N][10];
priority_queue<long long> q[15];
long long k[200025],tmp[15],maxx[15];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
memset(dp,-1,sizeof(dp));
dp[0][0] = 0;
for(int i = 1;i<=n;++i)
{
int c ,d;
while(!q[1].empty()) q[1].pop();
while(!q[2].empty()) q[2].pop();
while(!q[3].empty()) q[3].pop();
scanf("%d",&k[i]);
for(int j = 1;j<=k[i];++j)
{
scanf("%d%d",&c,&d);
q[c].push(d);
}
for(int j = 0;j<10;++j) dp[i][j] = dp[i-1][j];
for(int j = 1;j<=6;++j) tmp[j] = -inf;
if(!q[1].empty()) tmp[1] = q[1].top();
if(!q[2].empty()) tmp[2] = q[2].top();
if(!q[3].empty()) tmp[3] = q[3].top();
// cout << "ok" <<endl;
if(q[1].size()>=2)
{
long long now = q[1].top();
q[1].pop();
tmp[4] = q[1].top() + now;
maxx[4] = max(q[1].top(),now);
q[1].push(now);
}
// cout << "OK"<<endl;
if(!q[1].empty()&&!q[2].empty())
{
maxx[5] = max(q[1].top(),q[2].top());
tmp[5] = q[1].top()+q[2].top();
}
// cout << "ok" << endl;
if(q[1].size()>=3)
{
maxx[6] = 0;
tmp[6] = q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
tmp[6] += q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
tmp[6] += q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
}
// cout << "ok" <<endl;
if(tmp[1]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[1]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[1]*2);
}
if(tmp[2]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[2]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[2]*2);
}
if(tmp[3]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[3]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[3]*2);
}
if(tmp[4]!=-inf)
{
for(int j = 2;j<=9;++j)
if(dp[i-1][j-2]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-2]+tmp[4]);
if(dp[i-1][9]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][9]+tmp[4]+maxx[4]);
if(dp[i-1][8]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][8]+tmp[4]+maxx[4]);
}
if(tmp[5]!=-inf)
{
for(int j = 2;j<=9;++j)
if(dp[i-1][j-2]!=-1)dp[i][j] = max(dp[i][j],dp[i-1][j-2]+tmp[5]);
if(dp[i-1][9]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][9]+tmp[5]+maxx[5]);
if(dp[i-1][8]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][8]+tmp[5]+maxx[5]);
}
if(tmp[6]!=-inf)
{
for(int j = 3;j<=9;++j)
if(dp[i-1][j-3]!=-1)dp[i][j] = max(dp[i][j],dp[i-1][j-3]+tmp[6]);
if(dp[i-1][9]!=-1)dp[i][2] = max(dp[i][2],dp[i-1][9]+tmp[6]+maxx[6]);
if(dp[i-1][8]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][8]+tmp[6]+maxx[6]);
if(dp[i-1][7]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][7]+tmp[6]+maxx[6]);
}
}
long long ans = 0;
for(int i = 0;i<10;++i)
ans = max(ans,dp[n][i]);
printf("%lld\n",ans);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}