akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int n; ll c;
ll solve(VL& x, VL& v) {
    VL a = v, b = v, m(n);
    FOR(i, 1, n)a[i] += a[i - 1];
    rFOR(i, 0, n - 1)b[i] += b[i + 1];
    FOR(i, 0, n) {
        if (0 < i)m[i] = m[i - 1];
        chmax(m[i], a[i] - x[i]);
    }

    ll ret = 0;
    rFOR(i, 0, n) {
        ll sum = b[i] - (c - x[i]);
        chmax(ret, sum);
        if (0 < i)chmax(ret, sum + m[i - 1] - (c - x[i]));
    }
    return ret;
}

int main() {
    init();

    cin >> n >> c;
    VL x(n), v(n);
    FOR(i, 0, n)cin >> x[i] >> v[i];

    ll ans = 0;
    chmax(ans, solve(x, v));
    FOR(i, 0, n)x[i] = c - x[i];
    reverse(all(x));
    reverse(all(v));
    chmax(ans, solve(x, v));

    cout << ans << "\n";
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second


void solve()
{
    ll n,i,j,k,x,y,z;
    cin >> n;
    ll a[n];
    for(i=0;i<n;i++)
        cin >> a[i];

    ll dp[n];
    dp[0] = 0;
    for(i=1;i<n;i++)
    {
        if(i-2 >= 0)
        {
            x = dp[i-1] + abs(a[i] - a[i-1]);
            y = dp[i-2] + abs(a[i] - a[i-2]);
            dp[i] = min(x,y);
        }
        else
        {
            dp[i] = dp[i-1] + abs(a[i] - a[i-1]);
        }
    }
    cout << dp[n-1];


}
int main()
{

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin >> t;
	while(t-- > 0)
	{
		solve();
	}

}


Measured memory_bytes: 5140
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let c, m, s = Array.fold_left (fun (c, m, s) a -> (c + if a < 0 then 1 else 0), min m @@ abs a, s + abs a) (0, max_int, 0) a_s
let _ = Printf.printf "%d\n" @@ s - if c mod 2 = 1 then 2 * m else 0

Measured memory_bytes: 5120
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a + b == c || a + c == b || b + c == a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll perm(ll num) {
    if (num == 1) return 1;
    else {
        return (num * (perm(num - 1) % ((ll)1e9+7))) % (ll)(1e9+7);
    }
}

int main()
{
    ll n, m; cin >> n >> m;
    if (abs(n - m) > 1) {cout << 0 << endl; return 0;}


    if (n == m) {
        ll num = perm(n);
        cout << ((2 * ((num * num) % (ll)(1e9+7))) % ((ll)1e9+7)) << endl;
    } else {
        ll num = perm(min(n, m));
        cout << ((((num * num) % (ll)(1e9+7)) * max(n, m)) % ((ll)1e9+7)) << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;


bool solve(vector<int> v, int g, char mode){
    // dp配列は、"必ず"余分に取る
    const int lim = 8010;
    vector<vector<bool>> dp(2, vector<bool>(2*lim+100));

    // スタート時は、右方向にしか進めないことに気をつける。(Tの司令が来たら反対方向も選べるようになる)
    if(mode == 'x') dp[1][lim + v[0]] = true;
    if(mode == 'y') dp[0][lim] = true;

    rep(i, v.size()){
        rep(j, 2*lim){
            if(!dp[i%2][j]) continue;
            dp[i%2][j] = false;
            int m = v[i];
            dp[(i+1)%2][j + m] = true;
            dp[(i+1)%2][j - m] = true;
        }
    }

    return dp[v.size()%2][g + lim];
}

int main(){
    string s;
    int x, y;
    cin >> s >> x >> y;

    int f = 0;
    vector<int> v;
    rep(i, s.size()){
        if(s[i] == 'T'){
            v.push_back(f);
            f = 0;
        }
        else f++;
    }
    if(s[s.size()-1] != 'T') v.push_back(f);

    vector<int> vx, vy;
    rep(i, v.size()){
        if(i%2 == 0) vx.push_back(v[i]);
        else vy.push_back(v[i]);
    }

    if(solve(vx, x, 'x') && solve(vy, y, 'y')) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

bool solve() {
	int m; cin >> m;
	map<string, pair<int, int>> range;
	while(m--) {
		string name; cin >> name;
		int lb, ub; cin >> lb >> ub;
		range[name] = {lb, ub};
	}
	int n; cin >> n;
	stack<set<int>> num;
	while(n--) {
		string e; cin >> e;
		set<int> st;
		if(range.count(e)) {
			for(int i = range[e].first; i <= range[e].second; ++i) {
				st.insert(i);
			}
		} else if(e == "+" or e == "-" or e == "*" or e == "/") {
			auto st2 = num.top();
			num.pop();
			auto st1 = num.top();
			num.pop();
			for(auto lhs : st1) {
				for(auto rhs : st2) {
					if(e == "+") st.insert((lhs + rhs) % 256);
					if(e == "-") st.insert((lhs - rhs + 256) % 256);
					if(e == "*") st.insert((lhs * rhs) % 256);
					if(e == "/") {
						if(rhs == 0) return false;
						st.insert((lhs / rhs) % 256);
					}
				}
			}
		} else {
			int tmp = 0;
			for(char c : e) {
				tmp *= 10;
				tmp += c - '0';
			}
			st.insert(tmp);
		}
		num.push(st);
	}
	return true;
}

int main() {
	cout << (solve() ? "correct" : "error") << "\n";
	return 0;
}




Measured memory_bytes: 3240
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		Arrays.sort(s);
		String ans = "";
		for(int i = 0; i < n; i++) {
			ans += s[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26068
from itertools import product

X = [int(x) for x in input()]

for ptn in product([-1, 1], repeat=3):
    if X[0] + ptn[0] * X[1] + ptn[1] * X[2] + ptn[2] * X[3] == 7:
        ptn = ['+' if s == 1 else '-' for s in ptn]
        print('{}{}{}{}{}{}{}=7'.format(X[0], ptn[0], X[1], ptn[1], X[2],
                                        ptn[2], X[3]))
        break

Measured memory_bytes: 3064
w, h, n = list(map(int, input().split()))
rw = w
rh = h

points = []
for x in range(w):
  rows = []
  for y in range(h):
    rows.append(0)
  points.append(rows)

for i in range(n):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if row_index < x:
          points[row_index][col_index] = 1
  if a == 2:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if row_index >= x:
          points[row_index][col_index] = 1
  if a == 3:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if col_index < y:
          points[row_index][col_index] = 1
  if a == 4:
    for row_index, row in enumerate(points):
      for col_index, col in enumerate(row):
        if col_index >= y:
          points[row_index][col_index] = 1

count = 0
for row_index, row in enumerate(points):
  for col_index, col in enumerate(row):
    if points[row_index][col_index] == 0:
      count += 1
print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, P);
  VEC(int, A, N);
  bool f = false;
  each(x, A) {
    if (x % 2) {
      f = true;
    }
  }
  if (f) {
    print((ll)pow(2, N - 1));
  } else {
    print(P == 0 ? (ll)pow(2, N) : 0);
  }
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_LIMIT 1100
#define MAX 110

using namespace std;

int pre[MAX_LIMIT][3],pre2[MAX_LIMIT][MAX],LIMIT,N,M,X,SEC_E[MAX],SEC_S[MAX],E[MAX],S[MAX];
string tmp;


int main(){
  while(cin >> LIMIT >> N >> M >> X, LIMIT|N|M|X){
    rep(i,N)cin >> tmp >> SEC_E[i] >> SEC_S[i];
    rep(i,M)cin >> tmp >> E[i] >> S[i];
    rep(i,MAX_LIMIT)rep(j,3)pre[i][j] = -1;
    rep(i,MAX_LIMIT)rep(j,MAX)pre2[i][j] = -1;
    pre[0][0] = pre2[0][0] = 0;

    rep(i,N)for(int j=1;j>=0;j--)rep(k,LIMIT+1){
	if( pre[k][j] == -1 ) continue;
	int total_money = k + SEC_E[i];
	if( total_money > LIMIT ) continue;
	pre[total_money][j+1] = max(pre[total_money][j+1],pre[k][j]+SEC_S[i]);
      }

    rep(i,3)rep(j,LIMIT+1)if( j ) pre[j][i] = max(pre[j][i],pre[j-1][i]);

    rep(i,M)for(int j=M-1;j>=0;j--)rep(k,LIMIT+1){
	if( pre2[k][j] == -1 ) continue;
	int total_money = k + E[i];
	if( total_money > LIMIT ) continue;
	pre2[total_money][j+1] = max(pre2[total_money][j+1],pre2[k][j]+S[i]);
      }

    rep(i,M+1)rep(j,LIMIT+1)if( j ) pre2[j][i] = max(pre2[j][i],pre2[j-1][i]);

    int ans = 0;

    REP(i,X,M+1)REP(j,1,3)rep(k,LIMIT+1){
      if( pre2[k][i] == -1 || pre[LIMIT-k][j] == -1 ) continue;
      int points = pre2[k][i] + pre[LIMIT-k][j];
      ans = max(ans,points);
    }

    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 1688
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int w=sc.nextInt();
			int h=sc.nextInt();
			String gomi = sc.nextLine();
			if(w==0&&h==0) break;
			int[][] map = new int[h+2][w+2];
			int start_w=0,start_h=0;
			for(int i=1;i<=h;++i){
				String line = sc.nextLine();
				String[] line2=line.split("");
				for(int j=0;j<w;++j){
					if(line2[j].equals(".")){
						map[i][j+1]=1;
					} else if(line2[j].equals("@")){
						map[i][j+1]=2;
						start_w=j+1; start_h=i;
					}
				}
			}
			int count=1;
			Queue<Node> queue = new LinkedList<Node>();
			queue.add(new Node(start_h, start_w));
			while(!queue.isEmpty()){
				Node cur = queue.remove();
				if(map[cur.h-1][cur.w]==1){
					count++; map[cur.h-1][cur.w]=0;
					queue.add(new Node(cur.h-1,cur.w));
				}
				if(map[cur.h+1][cur.w]==1){
					count++; map[cur.h+1][cur.w]=0;
					queue.add(new Node(cur.h+1,cur.w));
				}
				if(map[cur.h][cur.w-1]==1){
					count++; map[cur.h][cur.w-1]=0;
					queue.add(new Node(cur.h,cur.w-1));
				}
				if(map[cur.h][cur.w+1]==1){
					count++; map[cur.h][cur.w+1]=0;
					queue.add(new Node(cur.h,cur.w+1));
				}
			}
			System.out.println(count);
		}
	}
}

class Node{
	int h,w;
	Node(int w,int h){
		this.h=w;
		this.w=h;
	}
}


Measured memory_bytes: 59056
#include<stdio.h>

int main(void)
{
int N,M;
scanf("%d%d",&N,&M);
int ai[M];
if(M==0)printf("%d\n",N-1);
else scanf("%d\n",&ai[M]);
if(M==0)return 0;
else printf("%d\n",N-M-1);
return 0;
}

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

using namespace std;

int main() 
{
    int n, m, i;
    scanf("%d", &n);
    
    vector<int> v;
    
    for(i = 0; i < n; i++)
    {
        scanf("%d", &m);
        v.emplace_back(m);
    }
    
    scanf("%d", &m);
    
    for(i = 0; i < m; i++)
    {
        scanf("%d", &n);
        printf("%d %d\n", lower_bound(v.begin(), v.end(), n) - v.begin(), upper_bound(v.begin(), v.end(), n) - v.begin());
    }
    
    return 0;
}


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

void insertionSort(vector<int>& A, int N, int G, int& cnt) {
  for (int i = G; i < N; i++) {
    int v = A[i];
    int j = i - G;
    while (j >= 0 && A[j] > v) {
      A[j+G] = A[j];
      j -= G;
      cnt++;
    }
    A[j+G] = v;
  }
}

void shellSort(vector<int>& A, int N) {
  int cnt = 0;
  vector<int> G;
  int h = 1;

  while (h <= N) {
    G.push_back(h);
    h = h * 3 + 1;
  }

  cout << G.size() << endl;

  for (int i = G.size() - 1; i >= 0; i--) {
    insertionSort(A, N, G[i], cnt);
    cout << G[i];
    if (i) cout << ' ';
  }

  cout << endl << cnt << endl;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  shellSort(A, N);
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
}


Measured memory_bytes: 6752
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    ll N;
    cin >> N;
    ll A[N], B[N];
    ll asum = 0, bsum = 0;
    REP(i, 0, N) {
        cin >> A[i];
        asum += A[i];
    }
    ll lessnum = 0;
    ll less = 0;
    vector<ll> over;
    REP(i, 0, N) {
        cin >> B[i];
        bsum += B[i];
        if (B[i] > A[i]) {
            lessnum++;
            less += B[i] - A[i];
        } else {
            over.push_back(A[i] - B[i]);
        }
    }
    sort(over.begin(), over.end());
    reverse(over.begin(), over.end());
    if (asum < bsum) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    if (lessnum != 0) {
        REP(i, 0, N - lessnum) {
            if (less <= over[i]) {
                ans++;
                break;
            } else {
                ans++;
                less -= over[i];
            }
        }
    }
    cout << lessnum + ans << endl;
}


Measured memory_bytes: 2680
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;

  vvl ab(N, vl(2));
  rep(i, N) cin >> ab[i][0] >> ab[i][1];

  vvl cd(M, vl(2));
  rep(i, M) cin >> cd[i][0] >> cd[i][1];

  rep(i, N){
    ll dist = (ll)pow(10, 10);
    ll pts = 1;

    rep(j, M){
      if(dist > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])){
        dist = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]);
        pts = j + 1;
      }
    }

    cout << pts << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

lli sum[200005] = {};
lli rec(lli l, lli r)
// [l, r)
{
  return sum[r] - sum[l];
}
bool pivot(lli l, lli r, lli piv)
{
  //  assert(l <= piv + 1 && piv < r - 1);
  return rec(piv, r) - rec(l, piv) >= 0;
}
lli calc(int l, int r, int piv)
{
  return rec(piv, r) - rec(l, piv);
}
int good(int l, int r, int piv1, int piv2)
{
  if (abs(calc(l, r, piv1)) < abs(calc(l, r, piv2)))
    return piv1;
  return piv2;
}
pair<lli, lli> calc(lli l, lli r)
{
  lli low = l + 1, up = r;
  while (up - low > 1)
  {
    lli mid = (up + low) / 2;
    if (pivot(l, r, mid))
    {
      low = mid;
    }
    else
    {
      up = mid;
    }
  }
  int go = good(l, r, low, up);
  return make_pair(rec(l, go), rec(go, r));
}
void solve(long long N, std::vector<long long> A)
{
  rep(i, N) sum[i + 1] = sum[i] + A[i];
  lli ans = 1e18;
  for (int i = 2; i <= N - 2; i++)
  {
    // [0, i) , [i, N) に分割
    int ll = 0, lr = i;
    int rl = i, rr = N;
    auto ls = calc(ll, lr);
    auto rs = calc(rl, rr);
    chmin(ans, max({ls.first, ls.second, rs.first, rs.second}) - min({ls.first, ls.second, rs.first, rs.second}));
  }
  cout << ans << endl;
}

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  cout << (1 + n) * n / 2 << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string.h>
using namespace std;

const int COL_SIZE = 9;
const int ROW_SIZE = 9;

void inputBoard( int board[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		for( int j = 0; j < COL_SIZE; ++j ){
			cin >> board[ i ][ j ];
		}
	}
}

void outputBoard( int board[][ COL_SIZE ], bool check[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		for( int j = 0; j < COL_SIZE; ++j ){
			cout << ( check[ i ][ j ] ? '*' : ' ' ) << board[ i ][ j ];
		}
		cout << endl;
	}
}

enum{
	COL = 0,
	ROW,
	BLOCK
};

bool investigate( int board[][ COL_SIZE ], bool check[][ COL_SIZE ] )
{
	for( int i = 0; i < ROW_SIZE; ++i ){
		int usedNumber[ 3 ][ 10 ];
		memset( usedNumber, 0, sizeof(usedNumber) );
		for( int j = 0; j < COL_SIZE; ++j ){
			usedNumber[ COL ][ board[ i ][ j ] ]++;
			usedNumber[ ROW ][ board[ j ][ i ] ]++;
			usedNumber[ BLOCK ][ board[ ( i / 3 ) * 3 + j / 3 ][ ( i % 3 ) * 3 + j % 3 ] ]++;
		}
		for( int j = 0; j < COL_SIZE; ++j ){
			if( usedNumber[ COL ][ board[ i ][ j ] ] > 1 ){
				check[ i ][ j ] = true;
			}
			if( usedNumber[ ROW ][ board[ j ][ i ] ] > 1 ){
				check[ j ][ i ] = true;
			}
			int y = ( i / 3 ) * 3 + j / 3;
			int x = ( i % 3 ) * 3 + j % 3;
			if( usedNumber[ BLOCK][ board[ y ][ x ] ] > 1 ){
				check[ y ][ x ] = true;
			}
		}
	}
	return false;
}

int main()
{
	int n;
	cin >> n;
	for( int i = 0; i < n; ++i ){
		int board[ ROW_SIZE ][ COL_SIZE ];
		bool check[ ROW_SIZE ][ COL_SIZE ];
		memset( check, 0, sizeof(check) );
		inputBoard( board );
		investigate( board, check );
		if( i != 0 ){
			cout << endl;
		}
		outputBoard( board, check );
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int W, H, N, w, h; cin >> W >> H >> N;
	int x, y, a;

	while (N--) {
		cin >> x >> y >> a;
		if (a == 1) {
			w = max(w, x);
		}
		else if (a == 2) {
			W = min(W, x);
		}
		else if (a == 3) {
			h = max(h, y);
		}
		else if (a == 4) {
			H = min(H, y);
		}
	}
	if (w < W && h < H) {
		cout << (W - w)*(H - h) << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);  
//*s.find_by_order(p)   returns the value of pth largest starting from 0 
//s.order_of_key(p)   returns no. of items that are strictly < p 
//string bin = bitset<64>(m).to_string();     convert decimal m to binary 
ll fac[2002];

ll power(ll a, ll b) 
{
    ll res = 1;
    while (b > 0) {
        if (b & 1){res = res * a;res=res%MOD;}
        a = a * a;a=a%MOD;
        b >>= 1;
    }
    return res;
}
ll inverse(ll a)
{
    return power(a, MOD-2);
}
ll ncr(ll n, ll r) 
{ 
   if (r==0) 
      return 1; 
  
    return (fac[n]* inverse(fac[r]) % MOD * inverse(fac[n-r]) % MOD) % MOD; 
}
int main()
{
      fast;ll t;t=1;
      while(t--)
      { 
            fac[0]=1;
            fac[1]=1;
            fac[2]=2;
            for(ll i=3;i<=2002;i++){
                  fac[i]=fac[i-1]*i;
                  fac[i]%=MOD;
            }
            ll n,i,j,ans;
            cin>>n;
            ans=0;
            for(i=1;i<=n;i++)
            {
                  if(n-3*i<0){break;}
                  if(n-2*i-1<0){continue;}
                  ans=ans+(ncr(n-2*i-1,i-1));
                  ans%=MOD;
            }
            cout<<ans<<"\n";
      }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<queue>
using namespace std;
typedef vector<int>Vec;
int flag=0;
map<int,vector<int> > arr;
bool f(vector<int> s,int n){
	for(int i=0;i<s.size();i++)
		if(s[i]==n){
			return 1;
		}
	return 0;
}
int main()
{
	int a,b,n,m;
	vector<int> temp;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		if(arr.count(a)==0){
			arr[a]=temp;
		}
		if(arr.count(b)==0){
			arr[b]=temp;
		}
		arr[a].push_back(b);
	}
	for(int i=0;i<arr[1].size();i++){
		if(f(arr[arr[1][i]],n)){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 19448
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var s = r[0].ToLong();
            var w = r[1].ToLong();
            var ans = string.Empty;
            if (w >= s) ans = "unsafe";
            else ans = "safe";
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int ToInt32(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long ToLong(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))


        {
            return value;
        }
        return new T2();
    }
}



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

int main() {
	int R;
  	cin >> R;
	if (R < 1200) cout << "ABC";
	else if (R < 2800) cout << "ARC";
	else cout << "AGC";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

touristかな？
*/

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = 998244353;
ll inf=1e17;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll n,m,ans=0;
  cin>>n>>m;
  vector<vector<ll>>adj(n+10);
  vector<bool>vis(n+10,false);
  vector<ll>dist(n+10,inf);
  queue<pair<int,int>>cave;
  vector<ll>signs(n+10);
  //node - parent
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dist[1]=0;
  cave.push(make_pair(1,1));
  while(!cave.empty()){
    pair<int,int>next=cave.front();
    ll node=next.first,parent=next.second;
    signs[node]=parent,vis[node]=true;
    cave.pop(),ans++;
    for(auto nextNode:adj[node]){
      if(!vis[nextNode]){
        if(dist[nextNode]>dist[node]+1){
          cave.push(make_pair(nextNode,node));
          dist[nextNode]=dist[node]+1;
        }
      }
    }
  }
  if(ans==n){
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++){
      cout<<signs[i]<<endl;
    }
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 13676
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 2505

struct Edge{
	void set(int arg_from,int arg_to,ll arg_value){
		from = arg_from;
		to = arg_to;
		value = arg_value;
	}
	int from,to;
	ll value;
};


ll N,M,P;
bool visited[SIZE];
ll min_dist[SIZE];
Edge edge[2*SIZE];
vector<int> rev_G[SIZE];


void dfs(int node_id){

	for(int i = 0; i < rev_G[node_id].size(); i++){

		int next = rev_G[node_id][i];
		if(visited[next])continue;

		visited[next] = true;

		dfs(next);
	}
}


int main(){

	scanf("%lld %lld %lld",&N,&M,&P);

	int from,to;
	ll value;

	for(int i = 0; i < M; i++){

		scanf("%d %d %lld",&from,&to,&value);
		from--;
		to--;

		edge[i].set(from,to,P-value);
		rev_G[to].push_back(from);
	}

	for(int i = 0; i < N; i++){

		visited[i] = false;
	}

	visited[N-1] = true;
	dfs(N-1);

	min_dist[0] = 0;
	for(int i = 1; i < N; i++){

		min_dist[i] = HUGE_NUM;
	}

	bool FLG = true,updated;

	for(int i = 0; i < N; i++){
		updated = false;
		for(int k = 0; k < M; k++){
			Edge tmp = edge[k];
			if(!visited[tmp.from]||!visited[tmp.to])continue;

			if(min_dist[tmp.from] != HUGE_NUM && min_dist[tmp.to] > min_dist[tmp.from] + tmp.value){
				min_dist[tmp.to] = min_dist[tmp.from] + tmp.value;

				updated = true;
				if(i == N-1){
					FLG = false;
					break;
				}
			}
		}
		if(!updated)break;
		if(!FLG)break;
	}

	if(!FLG){
		printf("-1\n");
		return 0;
	}

	printf("%lld\n",max(0LL,min_dist[N-1]*(-1)));

	return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    int a=min(k,x/d);
    x-=a*d;
    k-=a;
    cout<<(k%2?d-x:x)<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int N;
string S;


int main()
{

	cin >> S;
	N = S.size()+1;
	vector<int>A(N, -1);

	
	long long ans = 0;
	int center = -1;


	for (int i = 0; i < N - 1; i++) {
		if (S[i] == '<'){
			if (center == -1) {
				center = i;
			}

			A[i] = i - center;
		}
		else{
			if (center >= 0) {
				A[i] = i - center;
			}
			center = -1;
		}
	}
	if (S[N - 2] == '>') {
		A[N - 1] = 0;
	}
	else {
		A[N - 1] = A[N - 2] + 1;
	}

	center = -1;
	for (int i = N-1; i >= 0; i--) {
		if (A[i] == 0) {
			center = i;
		}
		else if(center >= 0){
			if (A[i] < 0) {
				A[i] = center - i;
			}
			else {
				A[i] = max(A[i], center - i);
				center = -1;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans += A[i];
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+9,U=1e7+5;
int n,nn,XX[N],X[N],i,j,ls,flw;
struct edge{int to,next,f;}e[1<<21|1];
int h[N],cur[N],xb=1,S,T,d[N];
inline void addedge(int x,int y,int f){
	e[++xb]=(edge){y,h[x],f};h[x]=xb;
	e[++xb]=(edge){x,h[y],0};h[y]=xb;
}
inline bool bfs(){
	static int q[N],t,w;int u,i;
	q[t=0,w=1]=S;memset(d+1,0,T<<2);d[S]=1;
	for(;t<w;)for(i=h[u=q[++t]];i;i=e[i].next)if(e[i].f && !d[e[i].to])d[q[++w]=e[i].to]=d[u]+1;
	return d[T];
}
inline int dfs(int x,int f){
	if(x==T)return f;
	int ans=0,&i=cur[x],t;
	for(;i;i=e[i].next)if(d[e[i].to]==d[x]+1 && e[i].f && (t=dfs(e[i].to,min(f,e[i].f)))){
		e[i].f-=t;e[i^1].f+=t;ans+=t;f-=t;
		if(!f)break;
	}
	return ans;
}
bool b[U];
int main(){
	scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",XX+i);
	for(i=2;i<U;++i)if(!b[i])for(j=i*2;j<U;j+=i)b[j]=1;b[2]=b[1]=b[0]=1;
	sort(XX+1,XX+n+1);X[nn=1]=XX[1];if(n==1 || XX[1]+1<XX[2])X[++nn]=XX[1]+1;
	for(i=2;i<=n;++i){
		if(XX[i]>XX[i-1]+1)X[++nn]=XX[i];
		if(i==n || XX[i]+1<XX[i+1])X[++nn]=XX[i]+1;
	}
	S=nn+1;T=S+1;
	for(i=1;i<=nn;++i)if(X[i]&1){
		addedge(S,i,1);++ls;
		for(j=1;j<=nn;++j)if(!b[abs(X[i]-X[j])])addedge(i,j,1);
	}else addedge(i,T,1);
	for(;bfs();)memcpy(cur+1,h+1,T<<2),flw+=dfs(S,1<<25);
	printf("%d\n",nn-flw+(ls-flw)%2);
	return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  for (int i = 0; i < q; i++) {
    cin >> a[i];
  }
  map<int, int> m;
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    m[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (k - (q - m[i]) > 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5760
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    ll m = 0, s = 0;
    rep(i, n) {
        m = max(m, a[i]);
        s += m - a[i];
    }
    cout << s << endl;
    return 0;
}


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

using namespace std;
#define ull unsigned long long
#define ll long long

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}

inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}

inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }

/*-----------------------------------------------------MATH------------------------------------------------*/

const int inf = 1e6;
const int MAXN = 2e5 + 10;
ll mod = 998244353;
vector<int> arr;
void solve() {
    int n;
    cin>>n;
    arr.resize(n);

    for(int i=0;i<n;i++) cin>>arr[i];
    int last=0;
    for(int i=0;i<n;i++){
        if(arr[i]==last+1){
            last++;
        }
    }
    if(last==0){
        cout<<-1<<endl;
        return;
    }
    cout<<n-last;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = 1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h> 

int A[100001];

int Partition(int p,int r){
  int i,x,j,sw;
  x = A[r];
 
  i = p-1;
  for(j = p;j <= r-1;j++){
    if(A[j] <= x){
      i = i + 1;
      sw=A[i];
      A[i]=A[j];
      A[j]=sw;
    }
  }
  sw=A[i+1];
  A[i+1]=A[r];
  A[r]=sw;
  return i+1;
}

int main(void){
  int q;
  int n,i,p;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  p=Partition(0,n-1);
  printf("%d",A[0]);
  
  for(i=1;i<n;i++){
    
    if(i==p)
      printf(" [%d]",A[i]);
    
    else printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#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 FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 1e9
using namespace std;
typedef long long ll;

signed main() {
  // std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;

  vector<int> ps(n);
  REP(i, n){
    cin >> ps.at(i);
  }

  vector<int> ps_new = ps;
  sort(ps_new.begin(), ps_new.end());

  int cnt = 0;
  REP(i, n){
    if (ps_new.at(i) != ps.at(i)){
      cnt++;
    }
  }

  cout << ((cnt <= 2) ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    int mario[n];
    for(int i=0;i<n;i++){
        cin>>mario[i];
    }
    unsigned long long int cnt=0;
    for(int i=1;i<n;i++){
        //cout<<mario[i]<<mario[i-1];
        if(mario[i]<mario[i-1]){
            //cout<<mario[i-1]<<mario[i];
            cnt+=(mario[i-1]-mario[i]);
            mario[i]=mario[i-1];
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 4364
import java.util.*;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] vectorA = new int[n][m];
		int[] vectorB = new int[m];
		int[] vectorC = new int[n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				int elm = scan.nextInt();
				vectorA[i][j] = elm;
				//if(j == m -1){
					//String ent = scan.next();
				//}
			}
		}
		for(int i = 0; i < m; i++){
			int elm = scan.nextInt();
			vectorB[i] = elm;
		}

		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				vectorC[i] += vectorA[i][j] * vectorB[j];
			}
		}

		for(int i = 0; i < n; i++){
			System.out.println(vectorC[i]);
		}
	}
}

Measured memory_bytes: 40364
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
  int h,w;
  cin>>h>>w;
  int c[10][10];
  rep(i,10)rep(j,10) cin>>c[i][j];
  vector<vector<int>> a(h,vector<int>(w));
  rep(i,h)rep(j,w) cin>>a[i][j];
  
  vector<int> dp(10,100002);
  rep(i,10) dp[i]=c[i][1];
  rep(k,10)rep(i,10)rep(j,10){
    dp[i]=min(dp[i],c[i][j]+dp[j]); 
  }
  
  vector<int> seen(10);
  rep(i,h)rep(j,w){
    if(a[i][j]!=-1) seen[a[i][j]]++;
  }
  int ans=0;
  rep(i,10) ans+=seen[i]*dp[i];
  cout << ans << endl;
}

Measured memory_bytes: 384
"use strict"

function Main(input) {
  input = input.split('\n');
  let N = parseInt(input.shift());
  let array = input.shift().split(/\s/).map(value => value - 0);
  let result = 0;
  let min = Math.abs(array[0]);
  let count = 0;
  for(let i=0;i<N;i++){
    let tmp = array[i];
    if(tmp > 0){
      result += tmp;
      min = Math.min(tmp, min);
    } else {
      result -= tmp;
      min = Math.min(-tmp, min);
      count++;
    }
  }
  if(count % 2 == 1) {
    result -= 2*min;
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 26780
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [None]*n
    dp[0], dp[1] = 0, abs(h[0]-h[1])
    for i, hi in enumerate(h[2:], 2):
        di = 10**9
        m = max(0, i-k)
        for dj, hj in zip(dp[m:i], h[m:i]):
            d = dj + abs(hj-hi)
            if di > d:
                di = d
        dp[i] = di
    print(dp[-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define maxn 55

using namespace std;
typedef long long ll;
ll dis[maxn][maxn],n,a[maxn],b[maxn],ans,r;
bool f[maxn][maxn],g;

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    for (int i=0;i<n;i++) scanf("%d",&b[i]);
    memset(f,false,sizeof(f));
    for (int i=0;i<n;i++) f[i][a[i]]=true;
    for (int i=0;i<=50;i++)
        for (int j=0;j<=50;j++)
            dis[i][j]=51;
    for (int i=0;i<=50;i++) dis[i][i]=0;
    for (int i=0;i<=50;i++)
        for (int j=1;j<=i;j++)
            dis[i][i%j]=min(dis[i][i%j],1ll*j);
    for (int k=0;k<=50;k++)
        for (int i=0;i<=50;i++)
            for (int j=0;j<=50;j++)
                dis[i][j]=min(dis[i][j],max(dis[i][k],dis[k][j]));
    for (int i=0;i<n;i++) if (dis[a[i]][b[i]]>50) {printf("-1\n");return 0;}
    for (int i=50;i>=1;i--)
    {
        g=false;
        for (int j=0;j<n;j++)
        {
            r=51;
            for (int k=0;k<=50;k++) if (f[j][k]) r=min(r,dis[k][b[j]]);
            if (r==i) g=true;
        }
        if (g) {
            ans+=((1ll)<<i);
            for (int j=0;j<n;j++)
                for (int k=0;k<=50;k++)
                    f[j][k%i]|=f[j][k];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
 
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
 
#define repn(i, a, b) for (int i=a; i<(b); i++)
#define rep(i, a) for (int i=0; i<(a); i++)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;

 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n ; cin>>n;
	map <string, int> ans;
	rep(i,n)
	{
		string s; cin>>s;
		ans[s]++;
	}
	int maxv=0;
	for( const auto &x : ans)
	{
		if(x.s>maxv) maxv=x.s;
	}
	
	for(auto it = ans.begin(); it != ans.end() ; it++)
	{
		if(it->s==maxv)
		{
			cout<<it->f<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 23808
N,M=map(int,input().split())
parent=[-1 for _ in range(N)]
A=[0]*M
B=[0]*M
ans=[0]*M
ans[M-1]=(N*(N-1))//2

def root(a):
    if parent[a]<0:
        return a
    else:
        parent[a]=root(parent[a])
        return parent[a]


def size(a):
    return -parent[root(a)]

def connect(a,b):
    ra=root(a)
    rb=root(b)

    if ra==rb:
        return False

    if size(ra)<size(rb):
        ra,rb = rb,ra

    parent[ra]+=parent[rb]
    parent[rb]=ra

    return True

for i in range(M):
    A[i],B[i]=map(int,input().split())
    A[i]-=1
    B[i]-=1

for i in range(M-1,0,-1):
    ans[i-1]=ans[i]
    if root(A[i])!=root(B[i]):
        ans[i-1]-=size(A[i])*size(B[i])
        connect(A[i],B[i])

for a in ans:
    print(a)

Measured memory_bytes: 16864
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == 'R') {
      cnt++;
    } else {
      cnt = 0;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>


int N;
int a[100];
int left[100], right[100], flag;
int main()
{
    scanf("%d", &N);

   while(N--){

        for(int j = 0; j < 10; j++) scanf("%d", &a[j]);

        for(int j = 0; j < 1<<10; j++)
        {
            int l = 0, r = 0;
            flag = 1;
            for(int k = 1, x = 0; k < 1<<10; k<<=1, x++)
            {
                if(j & k)  left[l++] = a[x];
                else   right[r++] = a[x];

                if((l >= 2 && left[l-1] <= left[l-2]) ||(r >= 2 && right[r-1] <= right[r-2]))
                {
                    flag = 0;
                    break;
                }
            }

            if(flag) break;

        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 3112
l,r  = map(int,input().split())
ans = 2019
if r - l >= 2019:
    print(0)
else: 
    for i in range(l % 2019,r % 2019):
        for j in range(i + 1,r % 2019 + 1):
            ans = min((i * j) % 2019,ans)
    print(ans)


Measured memory_bytes: 2940
#include<stdio.h>
#include<algorithm>
using namespace std;
char A[10][100];
char B[10][100];
bool ans[10][800001];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s",A[i]);
		for(int i=0;i<b;i++)scanf("%s",B[i]);
		for(int i=0;i<b;i++)
			for(int j=0;j<800001;j++)ans[i][j]=false;
		for(int i=1;i<=20;i++){
			for(int j=1;j<=20;j++){
				for(int k=1;k<=20;k++){
					bool ok=true;
					int c=0,d=0,e=0;
					for(int l=0;l<a;l++){
						int in=0;
						for(int m=0;A[l][m];m++){
							if(A[l][m]!='.')break;
							in++;
						}
						if(c*i+d*j+e*k!=in)ok=false;
						for(int m=0;A[l][m];m++){
							if(A[l][m]=='(')c++;
							if(A[l][m]==')')c--;
							if(A[l][m]=='{')d++;
							if(A[l][m]=='}')d--;
							if(A[l][m]=='[')e++;
							if(A[l][m]==']')e--;
						}
					}
					if(!ok)continue;
					c=0;
					d=0;
					e=0;
					for(int l=0;l<b;l++){
						ans[l][c*i+d*j+e*k]=true;
						for(int m=0;B[l][m];m++){
							if(B[l][m]=='(')c++;
							if(B[l][m]==')')c--;
							if(B[l][m]=='{')d++;
							if(B[l][m]=='}')d--;
							if(B[l][m]=='[')e++;
							if(B[l][m]==']')e--;
						}
					}
				}
			}
		}
		for(int i=0;i<b;i++){
			if(i)printf(" ");
			int at=0;
			int count=0;
			for(int j=0;j<800001;j++){
				if(ans[i][j]){
					at=j;
					count++;
				}
			}
			if(count>1)printf("-1");
			else printf("%d",at);
		}
		printf("\n");
	}
}

Measured memory_bytes: 8844