akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	
	using namespace std;
	int main()
	{
      int s;
cin >>s;
int k=s%100;
int p=(s-k)/100;

if(0<p&&p<13){
  if(0<k&&k<13){
    cout <<"AMBIGUOUS";
  }else{
    cout <<"MMYY";
  }
}else{
    if(0<k&&k<13){
    cout <<"YYMM";
  }else{
    cout <<"NA";
  }
}

	}

Measured memory_bytes: 256
N = input()
 
for n in range(N):
    data = map(float,raw_input().split( ))
    slopes = []
    for i in range(2):
        _x1 = data.pop(0)
        _y1 = data.pop(0)
        _x2 = data.pop(0)
        _y2 = data.pop(0)
         
        if _x1 != _x2:
            slopes.append((_y1 - _y2)/(_x1 - _x2))
     
    if len(slopes) == 0:
        print "YES"
    elif len(slopes) == 1:
        print "NO"
    elif abs(slopes[0] - slopes[1]) < 1e-10:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d.at(i);
  int ans = 0;
  for(int i = 0; i<n; i++){
    for(int j=i+1; j<n; j++){
      ans+=d.at(i)*d.at(j);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    ll a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    REP(i, a){
        cin >> s[i];
    }
    REP(i, b){
        cin >> t[i];
    }
    REP(i, q){
        ll x;
        cin >> x;
        ll idx1 = lower_bound(s.begin(), s.end(), x) - s.begin();
        ll idx2 = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll ans = INF;
        if(idx1 > 0 && idx2 > 0){
            ans = min(ans, x - min(s[idx1 - 1], t[idx2 - 1]));
        }
        if(idx1 > 0 && idx2 < b && s[idx1 - 1] < t[idx2]){
            ans = min(ans, x - s[idx1 - 1] + (t[idx2] - s[idx1 - 1]));
            ans = min(ans, t[idx2] - x + (t[idx2] - s[idx1 - 1]));
        }
        if(idx2 > 0 && idx1 < a && t[idx2 - 1] < s[idx1]){
            ans = min(ans, x - t[idx2 - 1] + (s[idx1] - t[idx2 - 1]));
            ans = min(ans, s[idx1] - x + (s[idx1] - t[idx2 - 1]));
        }
        if(idx1 < a && idx2 < b){
            ans = min(ans, max(s[idx1], t[idx2]) - x);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
int n,m;
vector<int> g[N];

bool dfs(int u, int d, int pre){
    if(d>2)return false;
    if(u==n&&d==2)return true;
    for(auto i:g[u]){
        if (i == pre)continue;
        if(dfs(i, d+1, u))return true;
    }
    return false;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    int a,b;
    for (int i = 1; i <= m; i++){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    if (dfs(1, 0, -1)){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 12016
function Main(input) {
  input = input.split(/\n/);
  balance = input[0] - input[1];
  
  console.log(balance % input[2]);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	rep(i, 1, n + 1){
		if(!(i % 3 == 0 || i % 5 == 0)) ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    string ss;
    cin >> ss;

    bool perfect = true;
    rep(i, ss.size() - 1) {
        if (ss[i] != ss[i + 1])
            perfect = false;
    }

    if (perfect) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1e5;
    for (char i = 'a'; i <= 'z'; i++) {
        string s = ss;
        int cnt = 0;
        while (true) {
            bool judge = 0;
            string news = "";
            for (int j = 0; j < s.size() - 1; j++) {
                if (s[j] == i || s[j + 1] == i) {
                    news += i;
                    judge = 1;
                } else {
                    news += s[j];
                }
            }

            s = news;
            if (!judge)
                break;
            cnt++;

            bool flag = true;
            rep(k, s.size()) {
                if (s[k] != i) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                ans = min(ans, cnt);
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
//define mod (ll)(1e9+7)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    REP(i,tx-sx) cout << "R";
    REP(i,ty-sy) cout << "U";
    REP(i,tx-sx) cout << "L";
    REP(i,ty-sy+1) cout << "D";
    REP(i,tx-sx+1) cout << "R";
    REP(i,ty-sy+1) cout << "U";
    cout << "LU";
    REP(i,tx-sx+1) cout << "L";
    REP(i,ty-sy+1) cout << "D";
    cout << "R" << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	int h[n+1], dp[n+1];
	for(int i = 0 ; i < n ; i++)
		cin >> h[i];

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2 ; i < n ; i++)
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    int H, W, K;
    boolean[][] C;

    public Main() {
        Scanner scanner = new Scanner(System.in);
        H = scanner.nextInt();
        W = scanner.nextInt();
        K = scanner.nextInt();

        C = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            String R = scanner.next();

            for (int j = 0; j < W; j++) {
                if(R.charAt(j) == '.'){
                    C[i][j] = false;
                } else {
                    C[i][j] = true;
                }
            }
        }

        System.out.println(search(0, new boolean[H+W]));
    }

    int search(int N, boolean[] T){
        if(N == T.length){
            boolean[][] copy = new boolean[H][W];
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    copy[i][j] = C[i][j];
                }
            }

            for (int i = 0; i < H; i++) {
                if (T[i]){
                    for (int j = 0; j < W; j++) {
                        copy[i][j] = false;
                    }
                }
            }
            for (int i = 0; i < W; i++) {
                if(T[H+i]){
                    for (int j = 0; j < H; j++) {
                        copy[j][i] = false;
                    }
                }
            }

            int num = 0;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (copy[i][j]){
                        num++;
                    }
                }
            }

            if(num == K){
                return 1;
            } else {
                return 0;
            }
        }

        int R;
        T[N] = true;
        R = search(N+1, T);
        T[N] = false;
        R += search(N+1, T);

        return R;
    }


    public static void main(String[] args){
        new Main();
    }
}


Measured memory_bytes: 38996
n = int(input())
a = [int(i) for i in input().split()]

result = a[0]
p = pow(10,18)

if 0 in a:
    result = 0

else:
    for i in range(n-1):
        result *= a[i+1]
        if result > p:
            result = -1
            break

print(result)

Measured memory_bytes: 21468
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
int main(){
 cin.tie(nullptr);
 ios::sync_with_stdio(false);
 int n,k,d,b,ans;
 cin>>n>>k;
 ans=0;
 vector<int> vec(n,0);
 fr(i,k){
     cin>>d;
     fr(l,d){
         cin>>b;
         vec[b-1] = 1;
     }
 }
 fr(i,n){
     if(vec[i]==0){
         ++ans;
     }
 }
 cout<<ans;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<int> vec(N+1);
  vec[0] = 2;
  vec[1] = 1;
  FOR(i, 2, N+1) vec[i] = vec[i-1]+vec[i-2];

  cout << vec[N] << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
X = []
for i in range(n):
  x, l = map(int, input().split())
  X.append([x-l, x+l])
X.sort()
temp = X[0][1]
count = n
for i in range(1,n):
  if temp>X[i][0]:
    count -= 1
    temp = min(temp, X[i][1])
  else:
    temp = X[i][1]
print(count)

Measured memory_bytes: 20108
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(void) {
    int N,M,ans=0;
    cin >> N >> M;

    double A[N];
    double cnt=0;
    for(int i=0; i<N; i++){
      cin >> A[i];
      cnt += A[i];
     }

     double tmp;
     tmp = cnt/(4ll*M);


     sort(A,A+N);
     reverse(A,A+N);
     bool flag = true;
     for(int i=0; i<M; i++){
       if(A[i]<tmp)
        flag = false;
     }

    if(flag)
      cout << "Yes" << endl;
      else
      cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);

	 		String input1 = bf.readLine().trim();
	 		String input2 = bf.readLine().trim();
	 		int count = 0;
	 	for(int i = 0;i<input1.length();i++){
	 		if (input1.charAt(i) != input2.charAt(i))
	 			count++;
	 	}
 		
 		out.println(count);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 30440
#include<iostream>
using namespace std;

int main() {
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    if (a < b) {
        if (b < c) {
            cout << "Yes" << endl;
            return 0;
        } 
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)

void solve()
{
    int n,k;
    cin>>n>>k;
    int res=0;
    while(n>0)
    {
        n/=k;
        res++;
    }
    cout<<res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}


func main() {
	sc.Split(bufio.ScanWords)
	h := scanInt()
	w := scanInt()

	s := make([]string,h)
	for i := 0; i < h; i++ {
		s[i] = scanText()
	}

	lco := make([][]int, h)
	rco := make([][]int, h)
	uco := make([][]int, h)
	dco := make([][]int, h)
	for i := 0; i < h; i++ {
		lco[i] = append(lco[i],make([]int, w)...)
		rco[i] = append(rco[i],make([]int, w)...)
		uco[i] = append(uco[i],make([]int, w)...)
		dco[i] = append(dco[i],make([]int, w)...)
	}

	for i := 0; i < h; i++ {
		co := 0
		for j := 0; j < w; j++ {
			co++
			if string(s[i][j]) == "#" {
				co = 0
			}
			lco[i][j] = co
		}
	}

	for i := 0; i < h; i++ {
		co := 0
		for j := 0; j < w; j++ {
			co++
			if string(s[i][w-j-1]) == "#" {
				co = 0
			}
			rco[i][w-j-1] = co
		}
	}

	for i := 0; i < w; i++ {
		co := 0
		for j := 0; j < h; j++ {
			co++
			if string(s[j][i]) == "#" {
				co = 0
			}
			uco[j][i] = co
		}
	}

	for i := 0; i < w; i++ {
		co := 0
		for j := 0; j < h; j++ {
			co++
			if string(s[h-j-1][i]) == "#" {
				co = 0
			}
			dco[h-j-1][i] = co
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			light := lco[i][j]+rco[i][j]+uco[i][j]+dco[i][j]-3
			if ans < light {
				ans = light
			}
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 159812
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int v[3005][3005];
ll dp[3005][3005][4];

int main(){
  int r, c, n, inp1, inp2, inp3;
  cin >> r >> c >> n;
  rep(i,n){
    cin >> inp1 >> inp2 >> inp3;
    v[inp1-1][inp2-1]=inp3;
  }
  rep(i, r){
    rep(j, c){
      for(int k=2; k>=0; k--){
        dp[i][j][k+1]=max(dp[i][j][k+1], dp[i][j][k]+v[i][j]);
      }
      rep(k, 4){
        dp[i+1][j][0]=max(dp[i+1][j][0], dp[i][j][k]);
        dp[i][j+1][k]=max(dp[i][j+1][k], dp[i][j][k]);
      }
    }
  }
  ll ans=0;
  rep(k, 4){
    ans=max(ans, dp[r-1][c-1][k]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 320012
N=int(input())
W=[]
for i in range(N):
  W.append(input())
for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    print('No')
    exit()
  for j in range(i+1, N):
    if W[i]==W[j]:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 3060
import java.util.*;
import java.util.function.Predicate;

public class Main {

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        Scanner cin = new Scanner(System.in);
        int N = cin.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        Work W[] = new Work[N];
        for (int i = 0; i < N; i++){
            A[i] = cin.nextInt();
            B[i] = cin.nextInt();
            W[i] = new Work(A[i], B[i]);
        }
        if(solve(N, W)) System.out.println("Yes");
        else System.out.println("No");
    }

    class Work implements Comparable<Work>{
        public int A, B;
        public Work(int A, int B){
            this.A = A; this.B = B;
        }
        @Override
        public int compareTo( Work w ){
            return this.B - w.B;
        }
    }

    boolean solve(int N, Work[] W){
        //仕事時間の短い順にソートする
        Arrays.sort(W);
        int time = 0;
        //順番に仕事を消化していく
        for (Work w: W){
            time += w.A;
            // 納期を過ぎていたら失敗
            if(time > w.B) return false;
        }
        //最後まで仕事を終えることが出来たら
        return true;
    }
}



Measured memory_bytes: 109580
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  vvi A(N, vi(N));
  rep(i,N) rep(j,N) std::cin >> A[i][j];

  auto B = A;
  rep(k,N) rep(i,N) rep(j,N) B[i][j] = std::min(B[i][j], B[i][k]+B[k][j]);

  rep(i,N) rep(j,N) {
    if ( A[i][j] != B[i][j] ) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }

  // build
  ll S = 0;
  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) {
    bool flag = false;
    rep(k,N) {
      if ( i == k || k == j ) continue;
      if ( B[i][j] == B[i][k] + B[k][j] ) { flag = true; break; }
    }
    if ( !flag ) S += (ll)(A[i][j]);
  }
  std::cout << S << std::endl;
  return 0;
}


Measured memory_bytes: 1024
H,W=map(int,input().split())
Ch,Cw=map(lambda x:int(x)-1,input().split())
Dh,Dw=map(lambda x:int(x)-1,input().split())
S=[input() for _ in range(H)]

grid = [[0 for _ in range(W)] for _ in range(H)]
grid[Ch][Cw] = 1

stack1=[(Ch,Cw)]
stack2=[]

answer=0

while 1:
    while stack1:
        sh,sw=stack1.pop()
        stack2.append((sh,sw))
        for i,j in [(-1,0),(1,0),(0,1),(0,-1)]:
            nh,nw = sh+i, sw+j
            if 0<=nh<H and 0<=nw<W and S[nh][nw]!="#" and grid[nh][nw]==0:
                if nh==Dh and nw==Dw:
                    print(answer)
                    exit()
                grid[nh][nw]=1
                stack1.append((nh,nw))
    answer+=1

    while stack2:
        sh,sw=stack2.pop()
        for i in range(-2,3):
            for j in range(-2,3):
                nh,nw = sh+i,sw+j
                if 0<=nh<H and 0<=nw<W and S[nh][nw]!="#" and grid[nh][nw]==0:
                    if nh==Dh and nw==Dw:
                        print(answer)
                        exit()
                    grid[nh][nw]=1
                    stack1.append((nh,nw))

    if not stack1:
        print(-1)
        exit()

Measured memory_bytes: 82288
#include <bits/stdc++.h>
using namespace std;
constexpr long long MAX = 1e15;

vector<long long> dijkstra(const vector<vector<pair<int, long long>>> &G, int s){
    struct RadixHeap {
        inline int bsr(long long x){ return (x == 0) ? -1 : 63-__builtin_clz(x); }
        vector<pair<long long, int>> v[65];
        long long last, sz;
        RadixHeap() : last(0), sz(0) { }
        inline bool empty () { return (sz == 0); }
        void push(long long x, int u) { sz++; v[bsr(x^last)+1].emplace_back(x, u); }
        inline pair<long long, int> pop () {
            if (!v[0].size()) {
                int i = 1;
                while (!v[i].size()) { i++; }
                last = min_element(v[i].begin(), v[i].end())->first;
                for (auto x : v[i]) { v[bsr(x.first^last)+1].emplace_back(x); }
                v[i].clear();
            }
            pair<long long, int> res = v[0].back();
            sz--;
            v[0].pop_back();
            return res;
        }
    };
    const long long inf = INT64_MAX;
    vector<long long> ret(G.size(), inf); ret[s] = 0;
    RadixHeap rh; rh.push(ret[s], s);
    while (!rh.empty()) {
        long long dist; int node;
        tie(dist, node) = rh.pop();
        if (ret[node] < dist) continue;
        for (auto &e : G[node]) {
            int next_node; long long next_dist;
            tie(next_node, next_dist) = e;
            if (ret[next_node] > ret[node] + next_dist){
                ret[next_node] = ret[node] + next_dist;
                rh.push(ret[next_node], next_node);
            }
        }
    }
    return ret;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<pair<int, long long>>> g1(n), g2(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        long long c1, c2;
        cin >> a >> b >> c1 >> c2;
        a--; b--;
        g1[a].emplace_back(b, c1);
        g1[b].emplace_back(a, c1);
        g2[a].emplace_back(b, c2);
        g2[b].emplace_back(a, c2);
    }
    
    vector<long long> d1 = dijkstra(g1, s); // yen
    vector<long long> d2 = dijkstra(g2, t); // snuuk
    vector<long long> d(n);
    for (int i = 0; i < n; i++) d[i] = d1[i] + d2[i];
    for (int i = n-1; i > 0; i--) d[i-1] = min(d[i-1], d[i]);
    
    for (auto& ans : d) cout << MAX - ans << '\n';
    return 0;
}

Measured memory_bytes: 19108
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M);

  for (int i = 0; i < M; i++)
  {
    int k;
    cin >> k;
    vec.at(i).resize(k);
    for (int j = 0; j < k; j++)
    {
      cin >> vec.at(i).at(j);
      vec.at(i).at(j)--;
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; i++)
  {
    cin >> p.at(i);
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    bool ok = true;
    for (int j = 0; j < M; j++)
    {
      int c = 0;
      for (int k = 0; k < vec.at(j).size(); k++)
      {
        if ((bit >> vec.at(j).at(k)) & 1)
        {
          c++;
        }
      }
      c %= 2;
      if (c != p[j])
      {
        ok = false;
      }
    }
    if (ok)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  map<string, int> mp;
  vector<string> s(N);
  rep(i, 0, N) {
    cin >> s[i];
    mp[s[i]]++;
  }
  int M;
  cin >> M;
  vector<string> t(M);
  rep(i, 0, M) {
    cin >> t[i];
    mp[t[i]]--;
  }
  int ans = -INF;
  for (auto p : mp) {
    chmax(ans, p.se);
  }
  cout << max(0, ans) << endl;

  return 0;
}


Measured memory_bytes: 256
/*input
1000 1 1000
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;

int const MOD = 1e9+7;	

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int n, x, t;
	cin >> n >> x >> t;
	if(n%x) cout << t*(n/x+1);
	else cout << n/x*t;
	return 0;	
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll nop(ll m, ll n) 
{ 
   
    ll path = 1; 
    for (ll i = n; i < (m + n - 1); i++) { 
        path *= i; 
        path /= (i - n + 1); 
    } 
    return path; 
} 
  
int main()
 {  fast();
	ll t;
    ll n;
    cin>>n;
   
    VI arr(n);
   fore(i,n){
     cin>>arr[i];
   }
  sort(arr.begin(),arr.end());
  int flag=1;
  if(n%2==0){
      fore(i,n){
          if(arr[i]!=arr[i+1])
          {flag=0;
              break;
          }
          else i++;
      }
  }
  else {
      if(arr[0]!=0){
          flag=0;
      }
      else {
          fore1(i,1,n){
              if(arr[i]!=arr[i+1])
          {flag=0;
              break;
          }
          else i++;
          }
      }
  }
  if(flag){
      cout<<fastexp(2ll,n/2,1e9+7)<<endl;
  }
  else cout<<0<<endl;}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a=new int[3];
		for(int i=0;i<3;i++){
			a[i]=sc.nextInt();
		}
		if(a[0]==a[1]){
			System.out.println(a[2]);
		}else if(a[0]==a[2]){
			System.out.println(a[1]);
		}else{
			System.out.println(a[0]);
		}



	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 2000;
const int INF = 1e9+10;
const int inf[2] = {-INF, INF};
int dp[MAX_N+1][2];
int N, Z, W, c[MAX_N+1];

int dfs(int pos, int p) {
  if (dp[pos][p] != inf[p]) return dp[pos][p];
  int res = abs(c[pos] - c[N]);
  for (int i=pos+1; i<N; i++) {
    int tmp = dfs(i, 1-(1&p));
    res = (p == 0) ? min(res, tmp) : max(res, tmp);
  }
  return dp[pos][p] = res;
}

int main() {
  for (int i=0; i<=MAX_N; i++) {
    for (int j=0; j<2; j++) {
      dp[i][j] = inf[j];
    }
  }
  cin >> N >> Z >> W;
  c[0] = W;
  for (int i=0; i<N; i++) {
    cin >> c[i+1];
  }

  cout << dfs(0, 1) << endl;
  return 0;
}


Measured memory_bytes: 384
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
alp = [chr(ord('a') + i) for i in range(26)]
#A
def A():
    x, a, b = LI()
    if abs(x - a) > abs(x - b):
        print("B")
    else:
        print("A")
    return

#B
def B():
    s = S()
    s = set(s)
    for i in s:
        alp.remove(i)
    if len(alp) == 0:
        print("None")
    else:
        print(alp[0])
    return

#C
def C():
    n = II()
    a = LI()
    i = 1
    a.sort(reverse=True)
    ans = []
    while i < n:
        if a[i] == a[i - 1]:
            ans.append(a[i])
            if len(ans) == 2:
                print(ans[0] * ans[1])
                return
            i += 2
        else:
            i += 1
    print(0)

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 61808
/* ex5_4
   moka223711 */

#include <stdio.h>
#define SIZE 11

int main(void){
    char input;
    int count = 0, ans = 0;
    while((input = getchar()) != EOF){ // EOF = End Of File ファイルの終端に入っている文字、stdio.h内で定義されている
        if(input=='A'||input=='C'||input=='G'||input=='T')count++; // 受け取った入力が'A'、'C'、'G'、'T'のいずれかであればcountをインクリメント
        else{ // そうでなければcountとansの大小関係を比較して、大きければansにcountを代入し、その後countを0にする
            if(count > ans)ans = count;
            count = 0;
        }
    }
    printf("%d\n", ans); // ansを出力
    return 0;
}


Measured memory_bytes: 1580
while True:
    n = int(input())
    if n == 0:
        break
    l = [0]*(3600*24 + 1)
    for i in range(n):
        s, t = input().split()
        stime = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8])
        etime = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8])
        # print(stime, etime)
        l[stime]+=1
        l[etime]-=1
    for i in range(len(l)-1):
        l[i+1] = l[i] + l[i+1]
    # print(l[0:3700])
    ans = max(l[1:])
    print(ans)    

    


Measured memory_bytes: 9516
#include<stdio.h>

#define FUCK 1000000007

long fack(long n){
  long k = n;
  long result = 1;
  if(n == 0){
    result = 1;
  }else{
    for(;k > 0;){
      result = (result * k)%FUCK;
      //printf("%ld#",result);
      k--;
    }
  }
  return result;
}

int main(){
  long n=0;
  long m=0;
  long i=0;
  long combcnt = -1;
  scanf("%ld %ld",&n,&m);
  if(n == m+1 || n+1 == m){
    combcnt = (fack(n)*fack(m))%FUCK;
  }else if(n == m){
    combcnt = (2*fack(n)*fack(n))%FUCK;
  }else{
    combcnt  =0;
  }
  
  //printf("%ld#",fack(6));
  printf("%ld",combcnt);
  return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> sz(n, 1);
  vector<uint8_t> c(n);
  c[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    c[y] |= c[x];
    sz[x]--;
    sz[y]++;
    if (sz[x] == 0) {
      c[x] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int n = 2, m;
vector<int> a[1 << 20], dy[1 << 20];
int cnt[1 << 20], pr[1 << 20];
bool lgl[1 << 20];

int main() {
	scanf("%d", &m);
	loop(i, n) a[i].resize(m);
	loop(i, n) loop(j, m) scanf("%d", &a[i][j]);
	cont(i, n - 1) {
		loop(j, m) cnt[a[i - 1][j]]++, cnt[a[i][j]]++, pr[a[i - 1][j]]++;
		loop(j, m) if(cnt[a[i][j]] > m) goto invalid;
		priority_queue<pair<int, int> > pq;
		deque<int> as; loop(j, m) as.pub(a[i][j]);
		sort(all(as));
		loop(j, m) if(!lgl[a[i - 1][j]]) {
			lgl[a[i - 1][j]] = 1;
			pq.push(mak(cnt[a[i - 1][j]], a[i - 1][j]));
		}
		loop(j, m) lgl[a[i - 1][j]] = 0;
		while(SZ(pq)) {
			pair<int, int> X = pq.top(); pq.pop();
			int ts = X.first, x = X.second;
			if(cnt[x] != ts) continue;
			if(!pr[x]) continue;
			int sel;
			if(as.front() != x) sel = as.front(), as.pop_front();
			else if(as.back() != x) sel = as.back(), as.pob();
			cnt[x]--; cnt[sel]--; pr[x]--; dy[x].pub(sel);
			if(cnt[x]) pq.push(mak(cnt[x], x));
			if(cnt[sel]) pq.push(mak(cnt[sel], sel));
		}
		loop(j, m) a[i][j] = dy[a[i - 1][j]].back(), dy[a[i - 1][j]].pob();
	}
	puts("Yes");
	loop(j, m) printf("%d%c", a[1][j], " \n"[j == m - 1]);
	return 0;

	invalid:
	return 0 & puts("No");
}


Measured memory_bytes: 64272
#include <iostream>
using namespace std;

int main(){
    int num;
    cin >> num;

    int ans = 0;
    int numbers[num];
    for(int i=0; i<num; i++)  cin >> numbers[i];

    while(true){

        bool clear = true;
        for(int i=0; i<num; i++){
            if(numbers[i] % 2 != 0){
                clear = false;
                break;
            }
        }

        if(clear == true){
            for(int i=0; i<num; i++){
                numbers[i] /= 2;
            }
            ans++;
        }else{
            break;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <string>
#define rep(i, cc, n) for (int i = cc; i < n; ++i)
using namespace std;
using ll = long long;

int main()
{
    int D;
    cin >> D;

    vector<int> C(26);
    vector<int> conts(26, 0);
    rep(i, 0, 26)
    {
        int c;
        cin >> c;

        C[i] = c;
    }

    vector<vector<int>> S(D, vector<int>(26));
    rep(i, 0, D)
    {
        rep(j, 0, 26)
        {
            int s;
            cin >> s;
            S.at(i).at(j) = s;
        }
    }

    rep(d, 1, D + 1)
    {
        int max = 0;
        int memo = 0;
        rep(j, 0, 26)
        {
            rep(k, 0, 26)
            {

                int satit = 0;
                if (k == j)
                {
                    satit += S.at(d - 1).at(j);
                }
                else
                {
                    satit -= C[j] * (d - conts[j]);
                }

                if (satit > max)
                {
                    max = satit;
                    memo = k;
                }
            }
        }
        cout << memo + 1 << endl;
        conts[memo] = d;
    }
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
vector<ll>v[100004];
ll ans[100004];
ll dfs(ll i){
    //cout<<i<<"   I\n";
    if(ans[i] != -1){
        return ans[i];
    }
    ll d = 0;
    //cout<<v[i].size()<<" sizee\n";
    for(ll j = 0; j < v[i].size(); j++){
        //cout<<v[i][j]<<"  v\n";
        d = max(d,1+dfs(v[i][j]));
    }
    return ans[i] = d;
}
int main(){

    ll n,m;
    cin>>n>>m;
    memset(ans,-1,sizeof ans);
    for(ll i = 0; i < m; i++){
        ll a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    ll maxi = 0;
    for(ll i = 1; i <= n; i++){
        maxi = max(dfs(i),maxi);
    }
    cout<<maxi;
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


Measured memory_bytes: 8576
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		sc.close();
		long n = Math.max(a * (long)c , Math.max(b * (long)d , Math.max(a * (long)d , b * (long)c)));
		ou.println(n);
		ou.flush();
	}
}

Measured memory_bytes: 35680
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x);

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int N;
  	cin >> N;
    vector<ll> A(N), B(N);
    
    REP(i,N){
        cin >> A[i] >> B[i];
    }
    
    ll ans = 0;
    for (int i=N-1; i>=0; i--){
        if((A[i]+ans)%B[i]!=0){
            ans += B[i] - (A[i]+ans)%B[i];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        int[] br = new int[N-1];
        for (int i = 0; i < N-1; i++) {
            br[i] = Integer.parseInt(sc.next());
        }
        
        int ans = br[0];
        ans += br[N-2];
        for (int i = 1; i < N-1; i++) {
            ans += Math.min(br[i], br[i-1]);
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(10000) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int a;
    string s;
    cin >> a >> s;
    if(a < 3200){
        cout << "red" << endl;
    }
    else{
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 6003;

int n[3];
char a[3][N];
int u[3] = {0, 1, 2};

bool c[3][3][N];

int s[3];
int yans = N;

void rec(int i)
{
    int m = 0;
    for (int j = 0; j < i; ++j)
    {
        int jj = u[j];
        m = max(m, s[jj] + n[jj]);
    }
    if (i == 3)
    {
        yans = min(yans, m);
        return;
    }
    int ii = u[i];
    for (s[ii] = 0; s[ii] <= m; ++s[ii])
    {
        bool z = true;
        for (int j = 0; j < i; ++j)
        {
            int jj = u[j];
            if (s[ii] < s[jj])
            {
                z = false;
                break;
            }
        }
        if (!z)
            continue;
        for (int j = 0; j < i; ++j)
        {
            int jj = u[j];
            if (s[ii] < s[jj] + n[jj])
            {
                if (!c[ii][jj][s[ii] - s[jj]])
                {
                    z = false;
                    break;
                }
            }
        }
        if (z)
            rec(i + 1);
    }
}

int solv()
{
    rec(0);
}

int main()
{
    for (int i = 0; i < 3; ++i)
    {
        scanf(" %s", a[i]);
        n[i] = strlen(a[i]);
        //n[i] = 1000;
        //for (int j = 0; j < n[i]; ++j)
        //    a[i][j] = 'a';
    }
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            if (i == j)
                continue;
            for (int s = 0; s <= n[j]; ++s)
            {
                c[i][j][s] = true;
                for (int k = s; k < min(n[j], s + n[i]); ++k)
                {
                    if (a[i][k - s] == '?' || a[j][k] == '?')
                        continue;
                    if (a[i][k - s] != a[j][k])
                    {
                        c[i][j][s] = false;
                        break;
                    }
                }
            }
        }
    }
    do
    {
        solv();
    } while (next_permutation(u, u + 3));
    printf("%d\n", yans);
    return 0;
}
/*
baa
aab
?baab?
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int r;
    std::cin >> r;
    if(r < 1200) std::cout << "ABC" << std::endl;
    else if(r < 2800) std::cout << "ARC" << std::endl;
    else std::cout << "AGC" << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 


 int main(){
 ll n,m,v,p ; cin>>n>>m>>v>>p ;
 vector<ll> A(n) ;
 rep(i,n)  cin>>A[i] ;
 sort(A.rbegin(),A.rend()) ;
 ll ans=0 ;
 ll x= 0 ;
 ll y= 0 ;
 rep(i,n-p){
 x+= (A[p+i-1]-A[p+i])*(i+1) ;
 y+= (A[p+i-1]-A[p+i]) ;
 if(x<=((n-v)*m)&&y<=m) ans++ ;
 }
 cout<<ans+(p)<<endl ;
   return 0 ;
 }



Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v% MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {

	int n; cin >> n;
	mint tmp10 = 1;
	mint tmp9 = 1;
	mint tmp8 = 1;
	while (n--) {
		tmp10 *= 10;
		tmp9 *= 9;
		tmp8 *= 8;
	}
	mint ans = tmp10 + tmp8 - tmp9 - tmp9;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552