#include #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; template bool chkmax(T &x,T y){return x bool chkmin(T &x,T y){return x>y?x=y,true:false;} int readint(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,ans; int t[3],a[3],b[3][3],rem[3]; char s[100005][3]; void work1(int x){ for(int i=0;i<3;i++){ if(i!=x){ ans+=min(b[i][x],rem[i])*2; if(b[i][x]a[i]) knd=i; else rem[i]=a[i]-t[i]; } work1(knd); } else{ int knd=-1; for(int i=0;i<3;i++){ if(t[i]<=a[i]) knd=i; else rem[i]=t[i]-a[i]; } for(int i=0;i<3;i++){ if(i!=knd){ ans+=min(b[knd][i],rem[i])*2; if(rem[i]>b[knd][i]) ans+=rem[i]-b[knd][i]; } } } printf("%d\n",ans); } return 0; }