#include<stdio.h>

#include<vector>

#include<iostream>

using namespace std;

vector<pair<int,int>> vec;

int dp[1001][16][16];

int main(){

    int solve=0;

    while(!cin.eof()){

        int a,b;

        cin>>a>>b;

        vec.push_back(make_pair(a,b));

    }

    dp[0][0][1]=vec[0].second;

    dp[0][1][0]=vec[0].first;

    for(int x=1;x<vec.size();x++){

        int white=vec[x].first;

        int black=vec[x].second;

        for(int w=0;w<16;w++){

            for(int b=0;b<16;b++){

                if(w<15){

                    if(dp[x][w+1][b]<dp[x-1][w][b]+white){

                      dp[x][w+1][b]=dp[x-1][w][b]+white;

                    }

                }

                if(b<15){

                    if(dp[x][w][b+1]<dp[x-1][w][b]+black){

                    dp[x][w][b+1]=dp[x-1][w][b]+black;

                    }

                }

                if(dp[x][w][b]<dp[x-1][w][b]) dp[x][w][b]=dp[x-1][w][b];

            }

        }

        if(solve<dp[x][15][15]){

            solve=dp[x][15][15];

        }

    }

    cout<<solve;

}

3시간째 끙끙대는중인데

점화식에서 틀린건가 코너케이스를 못잡는건가 도저히 모르겠음

백준 게시판에 올려도 대답없길래 여기다가 올려봄