akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int A,B,C,D;
inline void solve(){
  IN4(A,B,C,D);
  OUT(min(A,B)+min(C,D));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define md 1000000000
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=((res)*(x))%mod;
        }
        x=((x)*(x))%mod;
        y=y/2;
    }
    return res;
}
    
    ll dp[2000][2000],n;
    pair<ll,ll> a[2000];
ll rec(ll l,ll r){

        if(l>r)return 0;

            if(dp[l][r]!=-1)return dp[l][r];

            int id=(n-1-(r-l));

            dp[l][r]=max(a[id].fs*(abs(a[id].se-l))+rec(l+1,r),a[id].fs*(abs(a[id].se-r))+rec(l,r-1));

            return dp[l][r];

}



 
  
int main(){
 
  /*#ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif
 */
    ll i,c[2001]={0},j;

    sfl(n);

    

    f(i,0,n){
        sfl(j);
        a[i]={j,i};
    }
    sort(a,a+n,greater<pair<ll,ll>>());
    mst(dp,-1);
    cout<<rec(0,n-1);

   
    

   return 0;
 
  
 
    
 }

Measured memory_bytes: 35136
#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}

struct TT{
	LL a,b;
}tt,ss;
LL t,n,m,ans;
LL MOD=1e9+7;
char a[100005];

int main()
{
	LL i,j,k,l,res;
	cin>>a;
	l=strlen(a); 
	for(i=1;i<l;i++){
		if(a[i]==a[i-1]){
			m=1;
			j=i;k=i+1;
			break;
		}
	}
	if(l>2){
		if(!m)
		for(i=2;i<l;i++){
			if(a[i]==a[i-2]){
				m=1;
				j=i-1;k=i+1;
				break;
			}
		}
	}
	if(!m)j=k=-1;
	cout<<j<<" "<<k<<endl;
	return 0;
}

Measured memory_bytes: 384
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, pre = -1 ; 
    cin >> n ; 
    vector <int>  dp(200005,0), c(200005,-1) ; 
    dp[0] = 1 ; 
    for (int i=1,x ;i<=n; i++) { 
        cin >> x ; 
        dp[i] = dp[i-1];
        if ( c[x] != -1 and pre != x ) dp[i] += dp[c[x]] ; 
        c[x] = i ; 
        pre = x ; 
        dp[i] %= 1000000007;
    } 
    cout << dp[n] << endl ; 
}

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


Measured memory_bytes: 6408
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int n;
int h[100010];

int dp[100010];

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


    cout << dp[n-1] << endl;
}


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

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int nrlin = H / h;
    int nrcol = W / w;

    if (H % h == 0 && W % w == 0) {
        cout << "No\n";
        return 0;
    }
    else
        cout << "Yes\n";

    for (int i(1); i <= H; i++)
        for (int j(1); j <= W; j++)
            cout << (i % h == 0 && j % w == 0 ? -(h * w - 1) * 1000 - 1 : 1000) << " \n"[j == W];
    return 0;
}


Measured memory_bytes: 1536
import sys
f = sys.stdin

def calc_limit(a,l,order):
    INF = 1000000
    limit = 0
    for i in range(len(a))[::order]:
        if a[i] == 0:
            limit = INF
        else:
            if a[i] < 0:
                limit = min(-a[i], limit)
            else:
                l[i] = max(l[i], limit)
            limit -= 1

_ = int(f.readline())
a = list(map(int, f.readline().split()))
l = [0] * len(a)
calc_limit(a,l,1)
calc_limit(a,l,-1)

print(sum(min(ai, li) for ai, li in zip(a,l) if ai > 0 ))

Measured memory_bytes: 21584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		boolean possible = true;
		Scanner input = new Scanner(System.in);
		int h = input.nextInt();
		int w = input.nextInt();
		input.nextLine();
		char[][] mat = new char[h][w];
		String[][] sol = new String[h][w];
		for (int r = 0; r < h; r++) {
			String s = input.nextLine();
			for (int c = 0; c < w; c++) {
				mat[r][c] = s.charAt(c);
			}
		}

		

		for (int r = 0; r < h; r++) {
			for (int c = 0; c < w; c++) {
				if (mat[r][c] == '#')
					sol[r][c] = "#";
				else {
					int cnt = 0;
					if (r - 1 >= 0) {
						if (c - 1 >= 0 && mat[r - 1][c - 1] == '#')
							cnt++;
						if (c + 1 < w && mat[r - 1][c + 1] == '#')
							cnt++;
						if(mat[r-1][c] == '#')
							cnt++;
					}
					if (r + 1 < h) {
						if (c - 1 >= 0 && mat[r + 1][c - 1] == '#')
							cnt++;
						if (c + 1 < w && mat[r + 1][c + 1] == '#')
							cnt++;
						if (mat[r + 1][c] == '#')
							cnt++;
					}

					if (c - 1 >= 0 && mat[r][c - 1] == '#')
						cnt++;
					if (c + 1 < w && mat[r][c + 1] == '#')
						cnt++;

					sol[r][c] = "" + cnt;
				}
			}

		}

		for (int r = 0; r < h; r++) {
			for (int c = 0; c < w; c++) {
				System.out.print(sol[r][c]);
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 22356
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var list = next();
	var plist = [0];
	var nlist = [0];
	for(var i = 0; i < N; i++){
		if(list[i] == "1"){
			plist[plist.length - 1]++;
			if(list[i + 1] == "0"){
				plist.push(0);
			}
		}else{
			nlist[nlist.length - 1]++;
			if(list[i + 1] == "1"){
				nlist.push(0);
			}
		}
	}
	if(nlist[nlist.length - 1] == 0){
		nlist.pop();
	}
	if(nlist.length == plist.length){
		plist.unshift(0);
	}
	if(nlist.length <= K){
		myout(N);
		return;
	}
	var max = plist[0];
	var sum = plist[0];
	for(var i = 0; i < nlist.length; i++){
		sum += plist[i + 1] + nlist[i];
		if(i >= K){
			sum -= plist[i - K] + nlist[i - K];
		}
		max = Math.max(max, sum);
	}
	myout(max);

}


Measured memory_bytes: 35600
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,c;
    cin>>n>>m>>c;
    
    int B[m];
    for(int i=0;i<m;++i)cin>>B[i];
    vector<vector<int>> A(n, vector<int>(m));
    
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>A[i][j];
        }
    }
    
    
    int cnt = 0;
    for(int i=0;i<n;++i){
        int tmp = 0;
        for(int j=0;j<m;++j){
            tmp += B[j] * A[i][j];
        }
        tmp += c;
        if(tmp > 0) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = 0
for ai in a:
    if ai < 0:
        q += 1
    else:
        break
if q == 0:
    q = 1
elif q == n:
    q = n - 1
ans = []
x = a[0]
for ai in a[q:-1]:
    ans.append([x, ai])
    x -= ai

ans.append([a[-1], x])
y = a[-1] - x

for ai in a[1:q]:
    ans.append([y, ai])
    y -= ai

print(y)
for i in ans:
    print(*i)


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

// s[i]とs[i+1]を入れ替えた文字列を出力
string trans(string s, int i) {
    swap(s[i], s[i + 1]);
    return s;
}

//長さ3の文字列が"AGC"か判定
bool notAGC(string s) {
    string a = "agc";
    if (s == a || trans(s, 0) == a || trans(s, 1) == a) return false;
    return true;
}

int main() {
    int n;
    cin >> n;
    long long int p = 1e+9 + 7;
    // dp[i][s]:長さiのnotAGCで右3つがsなるものの数
    vector<unordered_map<string, long long int>> dp(n + 1);
    vector<string> c = {"a", "c", "g", "t"};
    // a[3]を完成させる
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                string temp = c[i] + c[j] + c[k];
                if (notAGC(temp)) {
                    dp[3][temp]++;
                }
            }
        }
    }
    // dp[i(>3)]を完成させる
    for (int i = 3; i < n; i++) {
        for (auto itr = dp[i].begin(); itr != dp[i].end(); itr++) {
            for (int j = 0; j < 4; j++) {
                string temp1 = (*itr).first.substr(1) + c[j];
                string temp2 = (*itr).first.substr(0, 2) + c[j];
                string temp3 = trans((*itr).first, 0).substr(1) + c[j];
                if (notAGC(temp1) && temp2 != "agc" && temp3 != "agc") {
                    dp[i + 1][temp1] += (*itr).second;
                    dp[i + 1][temp1] %= p;
                }
            }
        }
    }
    long long int ans = 0;
    for (auto itr = dp[n].begin(); itr != dp[n].end(); itr++) {
        ans += (*itr).second;
        ans %= p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> sum(n, 0);
	
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			sum[i]++;
			i++;
		}
	}
	for (int i = 1; i < n; i++) {
		sum[i] += sum[i - 1];
	}

	int l, r;
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		cout << sum[r - 1] - (l == 0 ? 0 : sum[l - 1]) << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		//String t= sc.next();
		String buff= "";
		String[] buff1=new String[s.length()];
		String[] buff2=new String[s.length()];
		//double n = sc.nextInt()/1000.0;
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0,flag=0;
		long count1=0,count2=0;
		int count3=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		for(int i=0;i<s.length()/2;i++) {
			buff1[i]=s.substring(i,i+1);
		}
		for(int i=s.length();i>s.length()/2;i--) {
			buff2[count3]=s.substring(i-1,i);
			count3++;
		}
		for(int i=0;i<s.length()/2;i++) {
			if(!buff1[i].equals(buff2[i])) {
				count++;
			}
			//System.out.println(buff1[i]);
			//System.out.println(buff2[i]);
		}
		/*if(s.length()%2==0) {
			for(int i=0;i<s.length()/2;i++) {
				for(int j=s.length();j>s.length()/2;j--) {
					if(!s.substring(i,i+1).equals(s.substring(j-1,j)))count++;
				}
			}
			System.out.println(count);
		}else{
			for(int i=0;i<s.length()/2;i++) {
				for(int j=s.length();j>s.length()/2;j--) {
					if(!s.substring(i,i+1).equals(s.substring(j-1,j)))count++;
				}
			}
			System.out.println(count);
		}*/

		System.out.println(count);
	}
}




Measured memory_bytes: 23124
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int num,mid,last,i,j,k;
        num=scan.nextInt();
        mid=scan.nextInt();
        last=scan.nextInt();
        long A[][]=new long[num][mid];
        long B[][]=new long[mid][last];
        long C[][]=new long[num][last];
        for (i=0;i<num;i++) { 
            for (j=0;j<mid;j++) { 
                A[i][j]=scan.nextInt();
            } 
        } 
        for (i=0;i<mid;i++) { 
            for (j=0;j<last;j++) { 
                B[i][j]=scan.nextInt();
            } 
        }
        
        for (i=0;i<num;i++) { 
            for (j=0;j<last;j++) { 
                for (k=0;k<mid;k++) 
                    C[i][j] += A[i][k]*B[k][j]; 
            } 
        } 
        for (i=0;i<num;i++) { 
            for (j=0;j<last-1;j++) {
                System.out.print(C[i][j]+" ");
            }
            System.out.println(C[i][last-1]);
        } 
    }
}


Measured memory_bytes: 53192
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] hist = new long[26];
		for (int i = 0; i < N; ++i) {
			hist[sc.next().charAt(0) - 'A']++;
		}
		for (int i = 1;; ++i) {
			int sum = 0;
			for (int j = 0; j < hist.length; ++j) {
				sum += Math.min(i, hist[j]);
			}
			if (sum < K * i) {
				System.out.println(i - 1);
				return;
			}
		}

	}
}


Measured memory_bytes: 18692
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}


int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll odd = (A & 1) + (B & 1) + (C & 1);
    cout << (2 <= odd ? "Hom" : "Tem") << endl;
    return 0;
}



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

using namespace std;

int main()
{
    int n, m;

    cin >> n >> m;
    

    vector<int> a(n);

    int tmp, total = 0;
    for(int i = 0; i < n; ++i) {
        cin >> tmp;
        total += tmp;
        a[i] = tmp;
    }

    int s = 0;
    for(int i = 0; i < n; ++i) {
        if(a[i] * 4 * m >= total)
            s++;
    }

    if(s >= m)
        cout << "Yes\n";
    else
        cout << "No\n";

}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000
int main()
{
  int data[N];
  int i,n,m;
  while (scanf("%d %d",&n,&m)){
    int cnt=0,nuke=0;
    if ((n==0) && (m==0))
      break;
    for (i=0;i<n;i++)
      data[i]=1;
    i=0;
    while (nuke<n-1){
      if (data[i%n]==1)
        cnt++;
      if (cnt==m){
        data[i%n]=0;
        cnt=0;
        nuke++;
      }
      i++;
    }
    for (i=0;i<n;i++)
      if (data[i]==1)
        printf("%d\n",i+1);
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>

using namespace std;

#define ll long long

ll n, ans;

void DFS(ll a, ll b, ll c, ll x)
{
	if (x > n) return;
	if (a && b && c) ans++;

	DFS(1, b, c, x * 10 + 3);
	DFS(a, 1, c, x * 10 + 5);
	DFS(a, b, 1, x * 10 + 7);
}

int main()
{
	cin >> n;

	DFS(0, 0, 0, 0);

	cout << ans << endl;
}

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

int main()
{
	int A[10];

	for (int i = 0; i < 10; i++) {
		cin >> A[i];
	}
	sort(A, A + 10);
	cout << A[9]<<endl;
	cout << A[8]<<endl;
	cout << A[7]<<endl;
    return 0;
}

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

int main() {
  int a,b,c,d,e;
  int t1=0,t2=0,t3=0,t4=0,t5=0;
  cin>>a>>b>>c>>d>>e;
  vector<int>dishes;
  vector<int>dishes2;
  int last_dish;
  int value=0;
  int index = 0;
  dishes.push_back(a);dishes2.push_back(a);
  dishes.push_back(b);dishes2.push_back(b);
  dishes.push_back(c);dishes2.push_back(c);
  dishes.push_back(d);dishes2.push_back(d);
  dishes.push_back(e);dishes2.push_back(e);
  for(int i=0;i<5;i++){
    int counter = 0;
    while(dishes2[i]%10!=0){
            if(dishes2[i%10]==0){
                break;
            }
        counter++;
        dishes2[i]++;
    }
    if(max(value,counter)==counter){
        last_dish=dishes[i];
        value=counter;
        index=i;
    }
  }
  int ans = 0;
  for(int i=0;i<5;i++){
    if(i!=index){
        ans+=dishes2[i];
    }
  }
  ans+=last_dish;
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	vector<int> a(26);
	rep(i,s.size()) a[s[i]-'a']++;
	rep(i,26){
		if(a[i]==0){
			char c='a'+i;
			cout << c << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=1;i<=n;++i)
#define debug(i) cout<<#i<<":"<<i<<endl;

int main()
{
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        switch (input) {
            case "A":
                Console.WriteLine("T");
                break;
            case "T":
                Console.WriteLine("A");
                break;
            case "C":
                Console.WriteLine("G");
                break;
            case "G":
                Console.WriteLine("C");
                break;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> v(5);
  for (int i = 0; i < 5; i++) cin >> v[i];
  int ans = INT_MAX;
  sort(v.begin(), v.end());
  for (int cnt = 5 * 4 * 3 * 2 * 1; cnt--;) {
    int tmp = 0;
    for (int i = 0; i < 5; i++) {
      tmp = (tmp + 9) / 10 * 10;
      tmp += v[i];
    }
    ans = min(ans, tmp);
    next_permutation(v.begin(), v.end());
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    string s;
    cin >> s;
    int pos = -1;
    ll tmp = 0;
    ll ans = mod;
    REP(i, s.size()-2){
        tmp = 0;
        tmp += (s[i] - '0') * 100;
        tmp += (s[i+1] - '0') * 10;
        tmp += (s[i+2] - '0') * 1;
        ans = min(ans, abs(tmp - 753));
    }
    print(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <queue>

#define lp(n) for(int i=0;i<n;i++)
#define LP(n,i) for(int i=0;i<n;i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
typedef long long ll;

using namespace std;

/*ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	ll g=gcd(x,y);
	return x/g*y;
}*/

int n,a[300000];
priority_queue<int,vector<int>,greater<int>>l;
priority_queue<int>r;
ll rs[100001],ls[100001],ans;
int main(){
	cin>>n;
	lp(3*n)
		cin>>a[i];
	ls[0]=0;
	lp(n){
		ls[0]+=a[i];
		l.push(a[i]);
	}
	lp(n){
		l.push(a[i+n]);
		ls[i+1]=ls[i]+a[i+n]-l.top();
		l.pop();
	}
	rs[n]=0;
	lp(n){
		rs[n]+=a[3*n-i-1];
		r.push(a[3*n-i-1]);
	}
	lp(n){
		r.push(a[2*n-i-1]);
		rs[n-i-1]=rs[n-i]+a[2*n-i-1]-r.top();
		r.pop();
	}
	ans=-llmax;
	lp(n+1)
		ans=max(ans,ls[i]-rs[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3832
#include <iostream>
#include <queue>

using namespace std;

void solve()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	priority_queue<int> PQue;
	PQue.push(a);
	PQue.push(b);
	PQue.push(c);
	PQue.push(d);
	PQue.push(e);
	for(int i = 0; i < 4; ++i)
	{
		cout << PQue.top() << " ";
		PQue.pop();
	}
	cout << PQue.top() << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
INF = 10**18

res = 0
dp = [INF]*(10*N)
dp[0] = 0
for i in range(0, N):
    dp[i+1] = min(dp[i+1], dp[i]+1)

    j = 1
    while i+6**j <= N:
        dp[i+6**j] = min(dp[i+6**j], dp[i]+1)
        j += 1

    l = 1
    while i+9**l <= N:
        dp[i+9**l] = min(dp[i+9**l], dp[i]+1)
        l += 1

print(dp[N])




Measured memory_bytes: 50156
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-11 22:00:56
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

int factorial(int n) {
    int ret = 1;
    for (int i = 2; i <= n; i++)
        ret *= i;

    return ret;
}

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i];

    vector<int> v(n);
    iota(all(v), 0);

    double sum = 0.0;
    do {
        for (int k = 1; k < n; k++) {
            int i, j;
            i = v[k];
            j = v[k-1];

            double dist = sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
            sum += dist;
        }
    } while (next_permutation(all(v)));

    double ans = sum/factorial(n);
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
let harmony a b =
  if (a + b) mod 2 = 0 then string_of_int ((a + b) / 2) else "IMPOSSIBLE"

let a, b = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))
let () = Printf.printf "%s\n" (harmony a b)

Measured memory_bytes: 3768
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String result = "Yes";
		String[] split = s.split("");
		if (split[0].equals(split[1]) && split[2].equals(split[3]) && !split[0].equals(split[2])) {

		} else if (split[0].equals(split[2]) && split[1].equals(split[3]) && !split[1].equals(split[2])) {

		} else if (split[0].equals(split[3]) && split[1].equals(split[2]) && !split[0].equals(split[1])) {

		} else {
			result = "No";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21844
class_ = {i: c for i, c in enumerate(["light fly", "fly", "bantam", "feather", "light", "light welter",
                                      "welter", "light middle", "middle", "light heavy", "heavy"])}
while True:
    try:
        w = float(input())
    except:
        break
    for i, c in enumerate([48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0, 150.0]):
        if w <= c:
            print(class_[i])
            break

Measured memory_bytes: 7412
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <stack>
#include <string>
#include <iomanip>
#include <queue>
#include <deque>
#include<cstring>
#include<limits>
#include <sstream>
#include <stdio.h>
#include<unordered_map>
using namespace std;
#define sz(x) (x).size()
#define all(v) (v).begin(),(v).end()
#define m_p make_pair
void run()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{    
	fast();
	long long x, y;
	cin >> x >> y;
	x *= y;
	if (x % 2)
	{
		cout << "Odd" << endl;
	}
	else
		cout << "Even" << endl;
	return 0;

}

Measured memory_bytes: 256
n,t = map(int,input().split())
li = [int(x) for x in input().split()]
ans = 0
pre_time = 10**10

for i in range(n):
    if abs(li[i] - pre_time) < t:
        ans += (li[i] - pre_time)
    else:
        ans += t
    pre_time = li[i]

print(ans)


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

long long int a,b;
long long int gcd(long long int a,long long int b){
    while(a!=b){
        if(a>b){
            if(a%b!=0) a=a%b;
            else return b;
        }
        else{
            if(b%a!=0) b=b%a;
            else return a;
        }
    }
    return a;
}

long long int lcm(long long int a,long long int b){
    return a/gcd(a,b)*b;
}

int main(){
   
    int N;cin>>N;
    long long int ans=1;
    for(int i=0;i<N;i++){
        long long int k;
        cin>>k;
        ans=lcm(ans,k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035
　　　https://atcoder.jp/contests/dp/submissions/3970847
・メモ化再帰
・累積和
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
aN = LIST()

# 累積和
sm = [0] * (N+1)
for i in range(N):
    sm[i+1] = sm[i] + aN[i]

memo = list2d(N+1, N+1, INF)
def rec(l, r):

    if memo[l][r] != INF: 
        return memo[l][r]
    if l == r:
        return 0
    mn = INF
    # 開区間にした
    for m in range(l, r):
        mn = min(mn, rec(l, m) + rec(m+1, r))
    # この先切った分の最小値に、今回のlとrを合体させる分を足す
    memo[l][r] = mn + (sm[r] - sm[l-1])
    return memo[l][r]

print(rec(1, N))


Measured memory_bytes: 75224
import sys
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        uf.union(a, b)
    ans = max(-uf.parents[uf.find(x)] for x in uf.roots())
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 82392
n = int(input())
edges = [[] for _ in range(n + 1)]
for a, b, c in (map(int, input().split()) for _ in range(n - 1)):
    edges[a].append((c, b))
    edges[b].append((c, a))
q, k = map(int, input().split())
stack = [(0, k, None)]
costs = [0] * (n + 1)
while stack:
    c, p, a = stack.pop()
    costs[p] = c
    stack.extend((c + c2, p2, p) for c2, p2 in edges[p] if p2 != a)
print('\n'.join(map(str, (costs[x] + costs[y] for x, y in (map(int, input().split()) for _ in range(q))))))


Measured memory_bytes: 50588
n, k, l = [int(i) for i in input().split()]
P = [[int(i) for i in input().split()] for j in range(k)]
R = [[int(i) for i in input().split()] for j in range(l)]

class UnionFind():
  def __init__(self, elements):
    self.elements = elements
    self._root = {}
    for e in self.elements:
      self._root[e] = e
    
  def unite(self, x, y):
    x = self.root(x)
    y = self.root(y)
    if x != y:
      self._root[x] = y
    
  def root(self, x):
    if self._root[x] != x:
      self._root[x] = self.root(self._root[x])
    return self._root[x]
  
  def count(self):
    cnt = {}
    for e in self.elements:
      cnt[self.root(e)] += cnt.get(self.root(e), 0)
      
    for e in self.elements:
      yield cnt.get(e, 0)
      
  def get_union(self):
    union = {}
    for e in self.elements:
      if self.root(e) in union:
        union[self.root(e)].add(e)
      else:
        union[self.root(e)] = {e}
    return union
      
  
road = UnionFind(range(1, n+1))
rail = UnionFind(range(1, n+1))

for i in range(k):
  road.unite(P[i][0], P[i][1])
  
for i in range(l):
  rail.unite(R[i][0], R[i][1])

ans = {}
key = []
for e in range(1, n+1):
  key.append((road.root(e), rail.root(e)))
  ans[key[-1]] = ans.get(key[-1], 0) +1
  
for k in key:
  print(ans[k], end=' ')


Measured memory_bytes: 110056
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Control.Monad
import Data.Array.IO
import Data.List

infinite = maxBound :: Int

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  edge <- (\[x, y, z] -> zip3 x y $ map negate z) . transpose . map (map read . words) . lines <$> getContents :: IO [Edge]
  weight <- newArray (0, n) infinite :: IO Memo
  let index = [1..n*2]
  writeArray weight 0 0
  writeArray weight 1 0
  foldM (bellmanFord edge n n) weight index
  inf <- readArray weight 0
  ans <- readArray weight n
  if inf == 1 then putStrLn "inf"
              else print $ negate ans

type Memo = IOUArray Int Int
type Edge = (Int, Int, Int)

bellmanFord :: [Edge] -> Int -> Int -> Memo -> Int -> IO Memo
bellmanFord edge n dst weight i = do
  b <- readArray weight 0
  case b of
    0 -> do
      foldM (bf' n dst i) weight edge
      return weight
    _ -> do
      return weight

--始点からdstの間にある負閉路を検出(weight[0] = 1)
bf' :: Int -> Int -> Int -> Memo -> Edge -> IO Memo
bf' n dst i weight (from, to, w) = do
  updatable <- readArray weight 0
  case updatable of
    0 -> do
      distFrom <- readArray weight from
      distTo <- readArray weight to
      let isUpdate = distFrom /= infinite && distTo > distFrom + w
          newDist = if isUpdate then distFrom + w
                                else distTo
          isClosed = if isUpdate && i == n && to == dst
                       then 1 else 0
      writeArray weight to newDist
      writeArray weight 0 isClosed
      return weight
    _ -> do
      return weight


Measured memory_bytes: 3708
#![allow(non_snake_case)]

use std::io;
use std::char;

fn main() {
    // 0:a, 1:b, ... 25:z
    let mut cnt_vec: Vec<u32> = vec![0; 26];

    let sin = io::stdin();

    loop {
        let mut buf = String::new();
        match sin.read_line(&mut buf) {
            Ok(n) => if n == 0 { break } else { () },
            Err(_) => panic!(),
        };

        for c in buf.chars() {
            let idx = match c {
                'a'...'z' => Some(c as u8 - 'a' as u8),
                'A'...'Z' => Some(c as u8 - 'A' as u8),
                _ => None,
            };

            match idx {
                Some(i) => cnt_vec[i as usize] += 1,
                None => (),
            };
        }
    }

    for (i, v) in cnt_vec.iter().enumerate() {
        let c = char::from_u32(i as u32 + 'a' as u32).unwrap();
        println!("{} : {}", c, v);
    }
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll ans = 0;
    ll n = s.size();
    for (int z=0;z<n;z++){
        ans++;
        if (z < n-1 && s[z] == s[z+1]){
            if (z != n-2) {
                //cout << s[z] << " ";
                ans++;
            } else {
                //cout << s[z] << s[z+1] << " ";
                z+=2; continue;
            }
            z+=2;
            // cout << s[z-1] << s[z] << " ";
        }
        else {
            //cout << s[z] << " ";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>

using namespace std;

int main()
{
    int x, y;

    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        if (x < y) {
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3016
#include <algorithm>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long> A(N), a(N), b(N);
	for (long& i : A) cin >> i;
	sort(A.begin(), A.end());
	vector<long> c(A.begin(), next(A.begin(), (N + 1) / 2));
	vector<long> d(next(A.begin(), (N + 1) / 2), A.end());
	a.front() = c.back();
	c.pop_back();
	if (N % 2) {
		if (!c.empty()) {
			a.back() = c.back();
			c.pop_back();
		}
	}
	else {
		a.back() = d.front();
		d.erase(d.begin());
	}
	for (int i = 1; i < N - 1; i++) {
		if (i % 2) {
			a[i] = d.back();
			d.pop_back();
		}
		else {
			a[i] = c.back();
			c.pop_back();
		}
	}

	vector<long> e(A.begin(), next(A.begin(), N / 2));
	vector<long> f(next(A.begin(), N / 2), A.end());
	b.front() = f.front();
	f.erase(f.begin());
	if (N % 2) {
		if (!f.empty()) {
			b.back() = f.front();
			f.erase(f.begin());
		}
	}
	else {
		b.back() = e.back();
		e.pop_back();
	}
	for (int i = 1; i < N - 1; i++) {
		if (i % 2) {
			b[i] = e.back();
			e.pop_back();
		}
		else {
			b[i] = f.back();
			f.pop_back();
		}
	}
	pair<long, long> g;
	for (int i = 1; i < N; i++) {
		g.first += abs(a[i - 1] - a[i]);
		g.second += abs(b[i - 1] - b[i]);
	}
	cout << max(g.first, g.second);
}

Measured memory_bytes: 4224
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<time.h>
#include<vector>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define R register
#define LL long long
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int n,a[N],p[N],f[N];

namespace FastIO {
	template<typename tp> inline void read(tp &x) {
		x=0; register char c=getchar(); register bool f=0;
		for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
		for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
		if(f) x=-x;
	}
	template<typename tp> inline void write(tp x) {
	  if (x==0) return (void) (putchar('0'));
     if (x<0) putchar('-'),x=-x;
     int pr[20]; register int cnt=0;
     while (cnt) putchar(pr[cnt--]+'0');
	}
	template<typename tp> inline void writeln(tp x) {
		write(x);
		putchar('\n');
	}
}
using namespace FastIO;

int main() {
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),p[a[i]]=i;
	int ans=1;
	f[n]=1;
	for (int i=n-1;i>=1;i--) {
		if (p[i+1]>p[i]) f[i]=f[i+1]+1;
		else f[i]=1;
		ans=max(ans,f[i]);
	}
	cout<<n-ans; 	
	return 0;
}
/*
5
2 3 1 5 4
*/

Measured memory_bytes: 2560
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int in = sc.nextInt();
    for(int i = 1; i <= in; i++){
      if (i % 3 == 0 || i % 10 == 3){
        System.out.print(" "+i);
        continue;
      }else{
        int x = i;
        while(x / 10 != 0){
          x /= 10;
          if(x % 10 == 3){
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println();
  }
}

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

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  if(B-A+1<=2*K){
    for(int i=A;i<=B;i++){
      cout<<i<<endl;
    }
  }else{
    for(int i=0;i<K;i++){
      cout<<A+i<<endl;
    }
    for(int i=0;i<K;i++){
      cout<<B-K+1+i<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(abs(a-c)<=d)
	{
		printf("Yes");
	}
	else if(abs(a-b)<=d&&abs(b-c)<=d)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll dp[5001][5001];
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			(dp[i + 1][j + 1] += dp[i][j] * 2) %= MOD;
			(dp[i + 1][max(j - 1, 0)] += dp[i][j]) %= MOD;
		}
	}
	ll ans = dp[N][s.size()];
	ll x = mod_pow(2, MOD - 2);
	(ans *= mod_pow(x, s.size())) %= MOD;
	cout << ans << endl;
}


Measured memory_bytes: 193792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  string s;cin>>s;
  
  int ans = 0;
  for(int i = s.size()-1;i >= 0;--i){
    if(s[i] == '9')ans += 9;
    else if(i){
      s[i-1]--;
      ans += 9;
    }else ans += ctoi(s[i]);
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a, b, c, cont = 0, i;
  scanf("%d %d %d", &a, &b, &c);
  for(i = a;i <= b;i++){
    if(c % i == 0)cont++;
  }
  printf("%d\n", cont);
  scanf("%d", &a);
  return 0;
}


Measured memory_bytes: 2104