#include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define mod 1000003 #define INF 1000000000 #define LLINF 2000000000000000000LL #define SIZE 10000 int n,m,s[50],a,b,c; bool kaku[50][51][51]; vector > way[50]; priority_queue,pair > > pq; int main(){ int now,cost,fir,sec; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&s[i]); scanf("%d",&m); for(int j=0;j,pair > p = pq.top(); pq.pop(); cost = p.first.first; now = p.first.second; fir = p.second.first; sec = p.second.second; if(kaku[now][fir][sec]) continue; kaku[now][fir][sec] = true; if(now==n && fir>0 && sec>0){ printf("%d\n",-cost); return 0; } //nowに滞在しない for(int i=0;i0 || now==1 || now==n) continue; if(fir==0) fir = now; else sec = now; for(int i=0;i