akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

bool is[maxn];
ll pri[maxn],cnt,a[505][505],n;

inline void pre()
{
	for(int i=2;i<=maxn-5;i++)
	{
		if(!is[i]) pri[++cnt]=i;
		for(int j=1;j<=cnt&&pri[j]*i<=(maxn-5);j++)
		{
			is[i*pri[j]]=1;
			if(i%pri[j]==0) break;
		}
	}
}

inline ll X(int x){return pri[x];}
inline ll Y(int x){return pri[750+x];}
inline ll lcm(ll a,ll b){return a/__gcd(a,b)*b;}

int main()
{
	n=read(); pre();
	if(n==2)
	{
		printf("4 7\n23 10\n");
		return 0;
	}
	rep(i,0,n+1) rep(j,0,n+1) a[i][j]=1;
	rep(i,1,n) rep(j,1,n) if((i+j)%2==0)
	{
		a[i][j]=X((i+j)/2)*Y((i-j)/2);
	}
	rep(i,1,n) rep(j,1,n) if((i+j)%2==1)
	{
		ll p1=lcm(a[i-1][j],a[i][j-1]);
		ll p2=lcm(a[i+1][j],a[i][j+1]); a[i][j]=lcm(p1,p2)+1;
	}
	rep(i,1,n)
	{
		rep(j,1,n) printf("%lld ",a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 8820
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<vector>
using namespace std;
const int MAXN=8000;
char s[MAXN+10];int n;
int x,y,d,cnt,fl;
vector<int> rec[2];
bool check(int p,const vector<int>& rec)
{
	set<int> A,B;A.insert(0);
	for(int i=0;i<(int)rec.size();++i)
	{
		B.clear();
		for(set<int>::iterator it=A.begin();it!=A.end();++it)
		{
			B.insert((*it)+rec[i]);
			B.insert((*it)-rec[i]);
		}
		swap(A,B);
	}
	return A.count(p);
}
int main()
{
	scanf("%s%d%d",s+1,&x,&y);n=strlen(s+1);s[++n]='S';
	for(int i=1;i<=n;++i)
	{
		if(s[i]=='F')++cnt;
		else
		{
			if(fl){rec[d].push_back(cnt);d^=1;}
			else{fl=true;d=1;x-=cnt;}
			cnt=0;
		}
	}
	puts((check(x,rec[0])&&check(y,rec[1]))?"Yes":"No");
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    REP(i, 10) REP(j, 10) {
        if (N == i * j) {
            print("Yes");
            return 0;
        }
    }

    print("No");
    
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(long long N, std::string S){
    int count = 0;
    for (int i = 0; i < S.size() - 2; i++) {
        if (S.substr(i, 3) == "ABC") count++;
    }
    print(count);
}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

const int N = (int)1e5;

int dat[N+5];
long long pre[N+5];

long long get_number_of_handshake(int n, int pts) {
    long long res = 0;
    for (int i=1; i<=n; i++) {
        int num = dat + 1 + n - lower_bound(dat+1, dat+1+n, pts - dat[i]);
        res += (long long)num;
    }

    return res;
}

long long get_points(int n, int pts) {
    long long res = 0;
    for (int i=1; i<=n; i++) {
        int num = dat + 1 + n - lower_bound(dat+1, dat+1+n, pts - dat[i]);
        res += pre[n] - pre[n-num];
        res += (long long)num * (long long)dat[i];
    }

    return res;
}

int main() {
    int n; scanf("%d", &n);
    long long m; scanf("%lld", &m);
    pre[0] = 0;
    for (int i=1; i<=n; i++) scanf("%d", dat+i);
    sort(dat+1, dat+1+n);
    for (int i=1; i<=n; i++) pre[i] = pre[i-1] + (long long)dat[i];

    long long temp = 0;
    long long res = 0;
    for (int lo=0,hi=2*N; lo<=hi; ) {
        int mid = (lo + hi) / 2;
        long long ret = get_number_of_handshake(n, mid);

        if (ret < m) {
            hi = mid - 1;
        } else {
            lo = mid + 1;
            temp = max(temp, (long long)mid);
            res = get_points(n, mid);
        }
    }

    long long ret = get_number_of_handshake(n, temp);
    res -= (ret - m) * temp;

    printf("%lld\n", res);
    return 0;
}


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

int main() {
  ll n, m;
  cin >> n >> m;

  ll ret = 0;
  ret += min(n, m / 2);
  m -= ret * 2;
  ret += m / 4;

  cout << ret << endl;
}


Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let n : u64 = get_one();
    let mut i = 1;
    let mut ans = 100;
    while i*i <= n {
        if n % i == 0 {
            let mut tmp = std::cmp::max(i, n/i);
            let mut tmp2 = 0;
            while tmp > 0 {
                tmp = tmp / 10;
                tmp2 += 1;
            }
            ans = std::cmp::min(ans, tmp2);
        }
        i+=1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
 
int main(){
	
    char string[20];
    int i;
    
    scanf("%[^\n]", string);
    
    for(i = 0; i < 19; i++){
    	
      if(string[i] == ','){
      	
        printf(" ");
        
      }else{
      	
        printf("%c", string[i]);
        
      }
    }

}

Measured memory_bytes: 2028
N = int(input())
H = list(map(int, input().split()))
 
for i in range(1, N):
    if H[i] < H[i - 1]:
        H[i] += 1
for i in range(1, N):
    if H[i] < H[i - 1]:
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int N,M;
	int X[100010]={};
	
	cin >> N >> M;
	for(int i=0;i<M;i++)
		cin >> X[i];
	
	sort(X,X+M);
	
	if(N>=M)
	{
		cout << 0 << endl;
		return 0;
	}
	
	int sub[100010]={};
	for(int i=0;i<M-1;i++)
		sub[i]=X[i+1]-X[i];
	sort(sub,sub+M-1);
	
	int ans=0;
	for(int i=0;i<M-N;i++)
		ans+=sub[i];
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
N,M = (int(i) for i in input().split())

cards = [0 for i in range(N+1)]
for i in range(M):
    L,R = (int(k) for k in input().split())
    cards[L-1] += 1
    cards[R] -= 1

anscards = [0 for i in range(N)]
total = cards[0]
for i in range(N):
    anscards[i] = total
    total += cards[i+1]      
    
print(anscards.count(M))

Measured memory_bytes: 8096
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,y,s;
    cin >> n >> y;
    for(int f=0;f<=n;f++)
        for(int h=0;h<=n;h++){
            s = (y-f*10000-h*5000)/1000;
            if(s>=0&&s<=n-f-h&&n==s+f+h){
                cout << f << " " << h << " " << s << endl;
                goto OUT;
            }
        }
    cout << "-1 -1 -1" << endl;
    OUT:;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    double START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n;
    string s;
    cin >> n >> s;

    i32 cnt = 0;
    for(i32 pass = 0; pass < 1000; ++pass) {
        string t = to_string(pass);
        while(t.size() < 3) t = "0" + t;
        bool can = 0;
        i32 idx_t = 0;
        for(i32 i = 0; i < s.size(); ++i) {
            if(idx_t == 3) break;
            if(s[i] == t[idx_t]) {
                ++idx_t;
            }
        }
        if(idx_t == 3) can = 1;
        if(can) ++cnt;
    }

    cout << cnt << '\n';

//     printf("ElapsedTime: %5.3f ms\n",1000*((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) ( ((a) + ((b) - 1) ) / b)

typedef long long int lli;

using namespace std;

template<class Abel> struct UnionFind{
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n);
		rank.resize(n);
		diff_weight.resize(n);
		for (int i = 0; i < n; ++i) {
			par[i] = i;
			rank[i] = 0;
		}
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		} else { 
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	} 

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	} 

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, int w) {
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x,y);
			w = -w;
		}
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
};

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	UnionFind<int> uf(N);
	for (int i = 0; i < M; ++i) {
		int l, r, d;
		scanf("%d%d%d", &l, &r, &d);
		if (uf.issame(--l, --r)) {
			int diff = uf.diff(l, r);
			if (diff != d) {
				printf("No\n");
				return 0;
			}
		} else {
			uf.merge(l, r, d);
		}
	}
	printf("Yes\n");
	return 0;
}


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

int main() {
  string s;
  cin >>s;
  int a0=0,a1=0;
  rep(i,s.size()){
    if(i%2==0){
      if(s.at(i)=='0') a1++;
      else a0++;
    }else{
      if(s.at(i)=='0') ++a0;
      else a1++;
    }
  }
  int k=min(a0,a1);
  cout << k <<endl;
}



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

int main()
{
	int a, b;
	cin>>a>>b;
	if (a+b>=a-b && a+b>=a*b)
		cout<<a+b<<"\n";
	else if (a-b>=a+b && a-b>=a*b)
		cout<<a-b<<"\n";
	else if (a*b>=a-b && a*b>=a+b)
		cout<<a*b<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  int R;
  cin >> R;
  cout << (R < 1200 ? "ABC" : (R < 2800 ? "ARC" : "AGC")) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 924844033
#define N 2009
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int n,m,a[N],bin[N],fac[N],f[N][2],dp[N][N],g[N][N];
int main(){
	scanf("%d%d",&n,&m);
	int i,j,k,x,y;
	for (i=bin[0]=1; i<=n; i++) bin[i]=(bin[i-1]<<1)%mod;
	for (i=fac[0]=1; i<=n; i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=1; i<=n && i<=(m<<1); i++){
		a[i]=(n-i)/(m<<1)+1;
		memset(f,0,sizeof(f));
		f[0][i-m<=0]=1;
		for (j=1; j<=a[i]; j++)
			for (k=a[i]+1; k>=0; k--){
				ad(f[k][0],f[k][1]); f[k][1]=0;
				if (k) for (x=0; x<2; x++)
					for (y=0; y<=x; y++) ad(f[k][x],f[k-1][y]);
			}
		x=i+(a[i]-1)*(m<<1);
		for (j=0; j<=a[i]+1; j++){
			dp[i][j]=f[j][0];
			if (x+m<=n) ad(dp[i][j],f[j][1]);
		}
	}
	g[0][0]=1;
	for (i=1; i<=n && i<=(m<<1); i++)
		for (j=0; j<=n; j++)
			for (k=0; k<=j && k<=a[i]+1; k++)
				ad(g[i][j],(ll)g[i-1][j-k]*dp[i][k]);
	int ans=0; x=min(n,m<<1);
	for (i=0; i<=n; i++)
		if (i&1) ans=(ans-(ll)g[x][i]*fac[n-i]%mod+mod)%mod;
		else ad(ans,(ll)g[x][i]*fac[n-i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 31360
var data = require('fs').readFileSync('/dev/stdin', 'utf8');
var input = data.trim().split('\n');

// var input = [
// 	1819,
// 	2003,
// 	876,
// 	2840,
// 	1723,
// 	1673,
// 	3776,
// 	2848,
// 	1592,
// 	922
// ];

function findHighestHills(arr) {
	if (arr.length <= 1) {
		return arr;
	}

	var pivot = parseInt(arr.pop());
	var left = [];
	var right = [];

	while (arr.length) {
		var elem = parseInt(arr.pop());
		if (elem > pivot) {
			left.push(elem);
		} else {
			right.push(elem);
		}
	}

	var sorted = [].concat(findHighestHills(left), pivot, findHighestHills(right));
	return sorted.splice(0, 3);
}

var output = findHighestHills(input);

for (var i = 0; i < output.length; i ++) {
	console.log(output[i]);
}

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

signed main(){
  int N;
  cin >> N;
  
  vector<int> A(N);
  vector<int> B(N);
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }
  
  int ans = 0;
  //奇数番目が負の場合
  int now = 0;
  for( int i = 0; i < N; i++ ){
    now += A.at(i);
    if( i%2 == 0 && now >= 0 ){
        ans += now+1;
        A.at(i) -= now+1;
        now = -1;
    }else if( i%2 == 1 && now <= 0 ){
      ans += abs(now)+1;
      A.at(i) += abs(now)+1;
      now = 1;
    }
  }
  
  int ans2 = 0;
  //偶数番目が負の場合
  now = 0;
  for( int i = 0; i < N; i++ ){
    now += B.at(i);
    if( i%2 == 0 && now <= 0 ){
      ans2 += abs(now)+1;
      B.at(i) += abs(now)+1;
      now = 1;
    }else if( i%2 == 1 && now >= 0 ){
      ans2 += now+1;
      B.at(i) -= now+1;
      now = -1;
    }
  }
 
  cout << min(ans, ans2) << endl;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int inf = 1<<30;

struct max_flow {
    struct edge { int to, cap, rev; };
    int V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(int from, int to, int cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int run(int s, int t) {
        int ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main() {
  int N;
  cin>>N;
  vector<vector<int>> red(N,vector<int>(2)),blu(N,vector<int>(2));
  for(int i = 0; i < N; i++) cin>>red[i][0]>>red[i][1];
  for(int i = 0; i < N; i++) cin>>blu[i][0]>>blu[i][1];
  vector<vector<int>> gr;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(red[i][0]<blu[j][0]&&red[i][1]<blu[j][1]) gr.push_back({i+1,j+1});
    }
  }
  max_flow m(2*N+2);
  for(auto x:gr){
    m.add_edge(x[0],x[1]+N,1);
  }
  for(int i = 0; i < N; i ++){
    m.add_edge(0,i+1,1);
    m.add_edge(N+i+1,2*N+1,1);
  }
  cout<<m.run(0,2*N+1)<<endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int x ,y,z;
        cin >> x;
        cin >> y;
        cin >> z;
        if(x > y){
            int temp =x;
            x = y;
            y = temp;
        }
        if(y > z){
           int a =y;
           y = z;
           z = a;
        }
        if(x > y){
            int b = x;
            x = y;
            y = b;
        }
        cout << x << " " << y << " " << z << endl;
}



Measured memory_bytes: 3056
def main():
    B_MAX = (80 + 80 - 1) * 80 // 2
    H, W = list(map(int, input().split(' ')))
    A = [list(map(int, input().split(' '))) for _ in range(H)]
    B = [list(map(int, input().split(' '))) for _ in range(H)]
    dp = [[[0 for _ in range(B_MAX + 1)] for _ in range(W)] for _ in range(H)]
    dp[0][0][abs(A[0][0] - B[0][0])] = 1
    max_b = abs(A[0][0] - B[0][0])
    for h in range(H):
        for w in range(W):
            if h == 0 and w == 0:
                continue
            d = abs(A[h][w] - B[h][w])
            max_b += d
            for b in range(min(B_MAX, max_b) + 1):
                v = 0
                if h > 0:
                    v = max(v, dp[h - 1][w][abs(b - d)])
                    if b + d <= B_MAX:
                        v = max(v, dp[h - 1][w][b + d])
                if w > 0:
                    v = max(v, dp[h][w - 1][abs(b - d)])
                    if b + d <= B_MAX:
                        v = max(v, dp[h][w - 1][b + d])
                dp[h][w][b] = v
    ans = 0
    while dp[H - 1][W - 1][ans] == 0:
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 418104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main(){
	int x, y, z;
	int s, ans;
	scanf("%d %d", &x, &y);
	if(y%x==0)ans = x + y;
	else ans = y - x;

	printf("%d\n", ans);


	return 0;
}


Measured memory_bytes: 128
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	int n, i;
	cin>>n;
	
	LL a[n+1], suml = 0;
	for(i=0;i<=n;i++) {
		cin>>a[i];
		suml += a[i];
	}
	
	LL nodes = 1, ans = 0;
	for(i=0;i<=n;i++) {
		ans += nodes;
		if(nodes < a[i]) {
			cout<<-1<<endl;
			return 0;
		}
		
		LL non_leaf = nodes - a[i];
		suml -= a[i];
		
		nodes = min(2*non_leaf, suml);
	}

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



Measured memory_bytes: 4412
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int main(){
  int n;
  cin >> n;
  string s;
  int alpha[26] = {0};
  cin >> s;
  rep(i, s.size()){
    alpha[s[i] - 'a']++;
  }
  rep(x, n - 1){
    int alphaTmp[26] = {0};
    cin >> s;
    rep(i, s.size()){
      alphaTmp[s[i] - 'a']++;
    }
    rep(i, 26){
      alpha[i] = min(alpha[i], alphaTmp[i]);
    }
  }
  rep(i, 26){
    rep(j, alpha[i]) printf("%c", i + 'a');
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,eps=1e-6,pi=acos(-1.0),maxn=1000010;
const int inf=0x7f7f7f7f7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],c[maxn];
string s; 
il int qpow(int base,int m)
{
	int res = 1; 
	while(m)
	{
		if(m&1)
			(res*=base);
		(base*=base);
		m >>= 1;
		if(res*base > 1e9&&m)
			return 1e9;
	}
	return res%mod;
}
signed main()
{
	int t=1;
///	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		int flag = 0;
		int ans= 1,sum = 0;
		rep(i,0,n)
			cin >> a[i],sum+=a[i];
		if(a[0])
		{
			if(n==0&&(a[0]==1))
			{
				cout << 1;
				return 0;
			}
			cout << -1;
			return 0;
		}
		int p = 1;
		b[0] = 1;
		rep(i,1,n)
		{
			p = (b[i-1]-a[i-1])*2;
			if(a[i] > p)
			{
				cout << -1;
				return 0;
			}
			b[i] = min(sum,p);
			ans+=b[i]; 
			sum-=a[i];
		}
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 5212
#include <iostream>
#include <math.h>
using namespace std;

// max(Bの桁数)
int calc_keta(long B) {
  int keta = 0;
  while (B > 0) { // n が 0 になるまで
    ++keta;
    B /= 10;
  }
  return keta;
}

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
 
    double max = 0;
    int mt_all = 0;
    int mt_sug = 0;
    for (int a = 0; a*A*100 <= F; ++a) { // 100Agの水
       for (int b = 0; b*B*100 + 100*A*a <= F; ++b){
           	   if (a==0 & b==0) continue;
       	   int max_suger = (A*a + B*b) * E;
       	   if (max_suger > F-100*A*a-100*B*b) max_suger =F-100*A*a-100*B*b;
       	   //cout << " max_suger " << max_suger;
           for (int c = 0; c*C <= max_suger; ++c){
               int d = (max_suger - C*c) / D;
               double noudo = (double)(c*C + d*D) / (100*A*a + 100*B*b + C*c + D*d);
               if (noudo>max){
                   max = noudo;
                   mt_all = 100*A*a + 100*B*b + C*c + D*d;
                   mt_sug = C*c + D*d;
                   //cout << " A " << a << " B " << b << " C " << c << " D " << d;
           	       //cout << " noudo " << noudo << endl;
               } 
           	   //cout << " A " << a << " B " << b << " C " << c << " D " << d;
           	   //cout << " noudo " << noudo << endl;
               
           }	
       }

    }
    if (max==0) mt_all = A*100;
    cout << mt_all << endl;
    cout << mt_sug << endl;
}

Measured memory_bytes: 256
import itertools
N=int(input())
s=set(["M","A","R","C","H"])
d=dict(zip(list(s),[0]*5))
for _ in range(N):
    try:
        d[input()[0]]+=1
    except KeyError:
        pass
ans=0
for v in itertools.combinations(d.keys(), 3):
    ans+=d[v[0]]*d[v[1]]*d[v[2]]

print(ans)
#S=[input() for _ in range(N) if input()[0] in s]


Measured memory_bytes: 74892
n = int(input())
t, a = map(float, input().split())
h = list(map(float, input().split()))
mind = abs(t - h[0] * 0.006 - a)
j = 0
for i in range(1, n):
    u = abs(t - h[i] * 0.006 - a)
    if mind > u:
        j = i
        mind = u
print(j + 1)

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef pair<LL,LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}

bool ComPaiSec(PII a, PII b){
  if(a.SE != b.SE){
    return a.SE < b.SE;
  }else{
    return a.FI < b.FI;
  }
}

int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  vector<PII> xl(N);
  
  REP(i,N){
    int X,L;
    cin >> X >> L;
    xl.at(i) = (MP(X-L,X+L));
  }
  
  sort(ALL(xl),ComPaiSec);
  
  LL t=0, lf= -1*INF;
  
  REP(i,N){
    if(lf > xl.at(i).FI) {
      continue;
    }
    t++;
    lf = xl.at(i).SE;
  }
  
  cout << t << endl;
  
  return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;

int freq[26];
bool vis[26];
int main()
{
ll n;
cin>>n;
ll arr[n];
ll sum=0;
for(int i=0;i<n;i++)
   {
        cin>>arr[i];
       // if(i!=0)
        sum+=arr[i];
   }
   ll sum2=0;
   ll ans=INT_MAX;
   for(int i=0;i<n-1;i++)
   {
sum2+=arr[i];
       ans=min(ans,abs((sum-sum2)-sum2));

   }
   cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll n, a, b;
	cin >> n >> a >> b;
	cout << n/(a+b)*a + min(n%(a+b), a) << endl;
}


Measured memory_bytes: 256
while 1:
    a, b, c = map(int, raw_input().split())
    if not a:
        break
    I = []
    res = [2]*(a+b+c)
    for p in xrange(int(raw_input())):
        i, j, k, r = map(int, raw_input().split())
        i -= 1; j -= 1; k -= 1
        if r:
            res[i] = res[j] = res[k] = 1
        else:
            I.append((i, j, k))
    for e in I:
        i, j, k = e
        if res[i]+res[j]+res[k]!=4:
            continue
        if res[i]==2:
            res[i] = -1
        elif res[j]==2:
            res[j] = -1
        else:
            res[k] = -1
    for i in xrange(a+b+c):
        print res[i] if res[i]>=0 else 0

Measured memory_bytes: 4284
#include<stdio.h>
int sum1(int);
int main(void){
  int n, a, b,total=0,d;
  scanf("%d %d %d",&n,&a,&b);



  for(int i=0;i<=n;i++){
    d=sum1(i);
    if(a<=d && b>=d){
      total+=i;
    }
  }

  printf("%d\n",total);
  return 0;
}


int sum1(int c){
 int  sum=0;
  while(c>0){
    sum+= c%10;
    c/=10;
  }
  return sum;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sc1(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sc3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pb push_back
#define MX 400005
using namespace std;

typedef long long int ll;

int main()
{
    map<ll,ll>mp;
    for(ll i=1;i<=3;i++)
    {
        ll x;
        cin>>x;
        mp[x]++;
    }
    if(mp.size()==2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        int[] s=new int[N];
        for(int i=0;i<N;i++){
            s[i]=sc.nextInt();
        }
        
        
        int count=0;
        boolean end=false;
        for(;!end;){
            for(int i=0;i<N;i++){
                if(s[i]%2==1){
                    end=true;
                }
            }
            if(!end){
                for(int i=0;i<N;i++){
                    s[i]=s[i]/2;
                }
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();

		if (x % 11 == 0 || x % 11 == 6) {
			System.out.println(2 * x / 11);
		} else {
			System.out.println(2 * x / 11 + 1);
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}
}


Measured memory_bytes: 9808
s = int(input())
l = [s]
ans = True
while ans:
    m = len(l)
    if l[m - 1] % 2 == 0:
        l.append(l[m - 1] // 2)
    else:
        l.append(3 * l[m - 1] + 1)
    for i in range(m):
        if l[i] == l[m]:
            print(m + 1)
            ans = False

Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
m = nl()
res = 1
if 0 in m:
    print(0)
else:
    for i in m:
        res *= i
        if res > 10**18 :
            print(-1)
            break
    else:
        print(res)

Measured memory_bytes: 87844
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void) {
	int i,j;
	int count;
	char p[1001];
	while (1) {
		j = 0;
		count = 0;
		fgets(p, sizeof(p), stdin);
		while (p[j++] != '\0') {
			count++;	//何故かカウントが一回多くされる。なんも入力しなくても(=p[0]='\0')でもcountが１される
		}
			
		for (i = 0; i<count-1; i++) {
			if (!isalpha(p[i])) {
				printf("アルファベットの大文字で入力してください\n");
				fflush(stdin);
				break;
			}
		}
		if (i == count - 1) break;
	}
	for(i=0;i<count-1;i++){
		switch(p[i]){
			case 'A':p[i]='X'; break;
			case 'B':p[i]='Y'; break;
			case 'C':p[i]='Z'; break;
			default:p[i]=p[i]-3; break;
		}
	}
	printf("%s",p);
	return 0;
}


Measured memory_bytes: 2096
#include <iostream>
using namespace std;
int main() {
int A,B;
cin>>A>>B;
if(A==B){
  cout<<"Draw";
}
else if (A>B&&B!=1){
  cout<<"Alice";
}
else if (A==1){
  cout<<"Alice";
}
else if (B>A||B==1){
  cout<<"Bob";
}

return 0 ;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
      	if (n%1000==0) {
          System.out.println(0);
        } else {
          System.out.println(1000-n%1000);
        }
	}
}

Measured memory_bytes: 35860
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

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

int main(void){
    int n;
    ll x;
    cin>>n>>x;
    vector<ll> v(n+1);
    rep(i, n) cin>>v[i];
    if(n==1) {
        cout<<abs(x-v[0])<<endl;
        return 0;
    }
    v[n]=x;
    sort(v.begin(), v.end());
    vector<ll> diff(n);
    rep(i, n) diff[i]=v[i+1]-v[i];
    sort(diff.begin(), diff.end());
    //vecout(diff);
    ll k=diff[0];
    ll ans=k;
    rep(j, n){
        ll GCD=gcd(k, diff[j]);
        ans=min(ans, GCD);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
using namespace std;

signed main() {
	int a, b; cin >> a >> b;
	if (a == 1)a = 14;
	if (b == 1)b = 14;
	if (a > b) {
		puts("Alice");
	}
	else if (a < b) {
		puts("Bob");
	}
	else {
		puts("Draw");
	}
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;


fn main() {
    let a:usize=read!();
    let mut set = HashSet::new();

    for i in 0..a{
        let m :usize= read!();
        set.insert(m);
    }
    println!("{}",set.len())
}

Measured memory_bytes: 2196
#include <iostream>

using namespace std;

int T[100][100];

void init(){
	for (int i = 0; i < 100; ++i)
	{
		for (int j = 0; j < 100; ++j)
		{
			T[i][j] = 0;
		}
	}
}

void DispTable(int n){
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cout << T[i][j];
			if(j!=n-1) cout << " ";
		}
		cout << endl;
	}
}

int main(){
	int n;
	cin >> n;
	init();
	for (int i = 0; i < n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			int v;
			cin >> v;
			T[u-1][v-1] = 1;	
		}
	}
	DispTable(n);
	return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

int main(void){
    string s;
    cin>>s;
    int num=0;
    for(int i=0;i<s.length()/2;i++){
        if(s[i]!=s[s.length()-1-i])num++;
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
// D - Islands War
#include <bits/stdc++.h>
using namespace std;
int V[100000+1];

int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in(), M=in();
	while(M--){
		int l=in(), r=in();
		V[r] = max(V[r], l);
	}
	int ans = 0, R = 0;
	for(int r=1; r<=N; ++r) if(V[r]>0 && V[r]>=R) R=r, ans++;
	cout<< ans <<endl;
}

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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n * 2);
  for (int i = 0; i < n * 2; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r + 1) >> 1;
    bool red = true;
    for (int i = 0; i < mid; ++i) {
      if (a[n * 2 - mid + i] + a[n * 2 - mid - i - 1] < m) {
        red = false;
        break;
      }
    }
    if (red) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < l; ++i) {
    ans = max(ans, a[n * 2 - l + i] + a[n * 2 - l - i - 1] - m);
  }
  for (int i = 0; i < n - l; ++i) {
    ans = max(ans, a[i] + a[n * 2 - l * 2 - i - 1]);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
card = [int(x) for x in input().split()]

a_sum=0
b_sum=0

for i in range((N+1)//2):
    max_value=max(card)
    max_index=card.index(max_value)
    a_sum+=max_value
    card[max_index]=0

    max_value=max(card)
    max_index=card.index(max_value)
    b_sum+=max_value
    card[max_index]=0

print(a_sum-b_sum)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<ctime>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<bitset>
#define ll long long 
#define ull unsigned long long 
#define mem(a) memset(a,0,sizeof(a))
#define rint register int 
#define rll register long long 
#define rull register unsigned long long 
#define rchar register char
#define rstring register string 
#define rfloat register float
#define rdouble register double 
#define fio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,a,b) for(int i=a;i<b;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define cFor(i,a,b) for(int i=a;i>b;i--)
#define cFOR(i,a,b) for(int i=a;i>=b;i--)
#define lFor(i,a,b) for(ll i=a;i<b;i++)
#define lFOR(i,a,b) for(ll i=a;i<=b;i++)
#define lcFor(i,a,b) for(ll i=a;i>b;i--)
#define lcFOR(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
int main(){
	fio;
	int a,b;
	cin>>a>>b;
	char A[15],B[15];
	mem(A),mem(B);
	For(i,0,b)
		A[i]=a+'0';
	For(i,0,a)
		B[i]=b+'0';
	if(strcmp(A,B)>0)
		cout<<B<<endl;
	else if(strcmp(A,B)<0)
		cout<<A<<endl;	
	else
		cout<<A<<endl;					
}

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

namespace _163_c
{
    internal class Management
    {
        private static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException());
            
            var sb = new StringBuilder();
            while (true)
            {
                var ch = Convert.ToChar(Console.Read());
                sb.Append(ch);
                if (ch == '\n') break;
            }
            var a = sb.ToString().Split(' ').Select(int.Parse).ToArray();

            var dict = new Dictionary<int, int>();
            for (var i = 0; i < n; i++)
            {
                dict[i] = 0;
            }

            for (var i = 0; i < a.Length; i++)
            {
                dict[a[i] - 1] += 1;
            }

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(dict[i]);
            }
        }
    }
}


Measured memory_bytes: 52992
A,B,C,D,E,F=map(int,input().split(' '))
water = set()
for a in range(0,F,100*A):
  for b in range(0,F,100*B):
    if a+b <= F:
      water.add(a+b)
    else:
      break
sugars = set()
for c in range(0,F,C):
  for d in range(0,F,D):
    if c+d <= F:
      sugars.add(c+d)
    else:
      break
density = 0
sugar = 0
content = 100*A
for x in water:
  for y in sugars:
    if x+y != 0 and x+y <= F and E*x >= 100*y and density < y/(x+y):
      density = y/(x+y)
      sugar = y
      content = x+y
print(content,sugar)

Measured memory_bytes: 9224
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;
#define INF 100000000
#define MOD 1000000007

int main()
{
	int h, w;
	vector<string> a(101);
	
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#" << a[i] << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;

	return (0);
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_H

#include <bits/stdc++.h>

using namespace std;

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    int ans = (n > k) ? 0 : 1;
    cout << ans << endl;
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3120
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
  int max,min;
  int n;

  cin >> n;
  scanf("%d", &max);
  min = max;
  --n;
  while(n--) {
    int tmp;
    scanf("%d", &tmp);
    if ( tmp < min ) min = tmp;
    if ( tmp > max ) max = tmp;
  }

  cout << abs(min-max) << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc088/tasks/abc088_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
PII mv[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    PII start = {1, 1}, goal = {h, w}, now;
    vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
    queue<PII> q;
    REP(i, h) REP(j, w) {
        cin >> s[i + 1][j + 1];
        if (s[i + 1][j + 1] == '#') {
            q.push({i + 1, j + 1});
        }
    }

    vector<vector<int>> dist(h + 2, vector<int>(w + 2, 0));
    dist[start.first][start.second] = 0;
    int ans = 0;
    while (!q.empty()) {
        now = q.front();
        q.pop();
        int dist_n = dist[now.first][now.second];
        ans = max(ans, dist_n);
        for (auto x : mv) {
            if (s[now.first + x.first][now.second + x.second] == '.' &&
                dist[now.first + x.first][now.second + x.second] == 0) {
                q.push({now.first + x.first, now.second + x.second});
                dist[now.first + x.first][now.second + x.second] = dist_n + 1;
            }
        }
    }

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


Measured memory_bytes: 13456
#include <iostream>
using namespace std;
int main()
{
	double A,B,C,D;
	cin>>A>>B>>C>>D;
	while(1)
	{
		C-=B;
		if(C<=0)
		{
			cout<<"Yes";
			return 0;
		}
		A-=D;
		if(A<=0)
		{
			cout<<"No";
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3724
K, N = map(int, input().split())
house = list(map(int,input().split()))
house = house + house
min = house[N - 1] - house[0]
 
for i in range(N - 1):
  if K - (house[N + 1 + i] - house[i]) < min:
    min = K - (house[N + 1 + i] - house[i])
 
print(int(min))

Measured memory_bytes: 26444
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    Q = NI()
    
    que = deque(list(S))
    
    reverse = False
    
    for q in range(Q):
        query = input()

        if query == "1":
            if reverse == False:
                reverse = True
            else:
                reverse = False
        else:
            x,y,z = map(str,query.split())
            if reverse == False:
                if y == "1":
                    que.appendleft(z)
                else:
                    que.append(z)
            else:
                if y == "1":
                    que.append(z)
                else:
                    que.appendleft(z)

    if reverse==True:
        print("".join(reversed(list(que))))
    else:
        print("".join(list(que)))#print(x,y,z)



if __name__ == '__main__':
    main()

Measured memory_bytes: 15984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C;
    cin >>A>>B>>C;
    long long K;
    cin>>K;

    if(K%2==0)
    { cout<<(A-B)<<endl;}
    else {
        cout <<(B-A)<<endl;
    }
    
}

Measured memory_bytes: 3588
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq 
'''
#------------------PYPY FAst I/o--------------------------------#

def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#

#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))

def find_gt(a, x):
    #'Find leftmost value greater than x'
    i = bi.bisect_right(a, x)
    if i != len(a):
        return i
    else:
        return -1


def main():
    try:
        n=I()
        print(math.pi*n*2)

            
    except:
        pass
M = 998244353
P = 1000000007

if __name__ == '__main__':
    main()

Measured memory_bytes: 9484