akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX_H 505
#define MAX_N 105
int H,N,P,M,K;

int t[MAX_H];
int u[MAX_H];
int tmp[MAX_N];

double dp[2][MAX_H][MAX_N];

int total=0;

int main(){
  cin>>H>>N>>P>>M>>K;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    t[a]=b;
  }
  int last;
  dp[H&1][0][P]=1;
  for(int i=H;i>=1;i--){
    int ai=i&1,bi=1-ai;
    last=bi;
    for(int j=0;j<=K;j++)
      for(int k=1;k<=N;k++)
        dp[bi][j][k]=0;
    
    if(t[i]>0){
      for(int j=0;j<=K;j++){
        for(int k=1;k<=N;k++){
          if( k==t[i] ){
            dp[bi][j][k+1]+=dp[ai][j][k]; 
          }else if(k==t[i]+1){
            dp[bi][j][k-1]+=dp[ai][j][k];
          }else{
            dp[bi][j][k]+=dp[ai][j][k];
          }
        }
      }
      continue;
    }
    
    for(int j=0;j<=K;j++){
      for(int k=1;k<=N;k++){
        
        dp[bi][j][k]+=dp[ai][j][k];
        double C=N-1;
        if(k<N){
          dp[bi][j+1][k+1]+=dp[ai][j][k];
          C-=1;
        }
        if(1<k){
          dp[bi][j+1][k-1]+=dp[ai][j][k];
          C-=1;
        }

        dp[bi][j+1][k]+=dp[ai][j][k]*C;

      }
    }
    
  }
  
  double maxm=0,total=0;
  for(int i=1;i<=N;i++){
    total+=dp[last][K][i];
    maxm=max(maxm,dp[last][K][i]);
  }
  //  printf("%.10f\n",maxm);
  //  printf("%.10f\n",total);
  printf("%.10f\n",maxm/total);
  return 0;
}

Measured memory_bytes: 1364
#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	if (N % 2 == 1) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	
	long long ans = 0;
	for (N /= 10; N > 0; N /= 5) ans += N;
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(all(v),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l=0,r=0,a,N;
  cin >> N;
  rep(i,N){
    bool f = false;
    vary(int,v,10,0);
    rep(i,10){
      cin >> v[i];
    }
    queue<pair<pii,int>> q;
    q.push(make_pair(make_pair(0,0),0));
    while(!q.empty()){
      auto top = q.front();q.pop();
      if(top.se == 10){
        f = true;
        break;
      }
      l = top.fi.fi,r=top.fi.se;
      a = v[top.se];
      if(r < a){
        r = a;
        q.push(make_pair(make_pair(l,r),top.se+1));
      }
      else if(l < a){
        l = a;
        q.push(make_pair(make_pair(l,r),top.se+1));
      }
    }
    Ans(f);
  }
  return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int kaizyo(int K)
{
	int i, A = 1;
	for (i = K; i > 1; i--)
	{
		A = A * i;
	}
	return A;
}
int main(void)
{
	char S[55];
	int N, P[10], Q[10], p = 1, q = 1, i, j;
	scanf("%d", &N);

	for (i = 0; i < N; i++)
	{
		scanf("%d", &P[i]);
	}
	for (i = 0; i < N - 1; i++)
	{
		p = p + kaizyo(N - i - 1) * (P[i] - 1);
		for (j = i + 1; j < N; j++)
		{
			if (P[j] > P[i])
				P[j]--;
		}
	}

	for (i = 0; i < N; i++)
	{
		scanf("%d", &Q[i]);
	}
	for (i = 0; i < N - 1; i++)
	{
		q = q + kaizyo(N - i - 1) * (Q[i] - 1);
		for (j = i + 1; j < N; j++)
		{
			if (Q[j] > Q[i])
				Q[j]--;
		}
	}
	printf("%d\n", abs(p - q));

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
int v = 100005; //頂点の数
vector<vector<int>> tree(v,vector<int>()); //木
vector<vector<int>> parents; //parents[i][j] := i の　2^j　上の祖先
vector<int> dist(v,0); //rootからの距離

void init_dfs(int i,int before=-1,int d=0){
    parents[i][0] = before;
    dist[i] = d;
    for(int next:tree[i]){
        if(next == before) continue;
        init_dfs(next,i,d+1);
    }
}

void LCAinit(int root = 0){
    int k = 1;
    while((1<<k)<v) k ++;
    parents.assign(v,vector<int>(k,-1));
    init_dfs(root);
    for(int j = 0;j < k-1;j++){
        for(int i = 0;i < v;i++){
            if(parents[i][j] < 0){
                parents[i][j+1] = -1;
            }else{
                parents[i][j+1] = parents[parents[i][j]][j];
            }
        }
    }
}

int LCA(int x,int y){
    if(dist[x] < dist[y]) swap(x,y);
    int k = parents[0].size();
    for(int i = 0;i < k;i++){
        if((dist[x]-dist[y]) >> i & 1){
            x = parents[x][i];
        }
    }

    if(x == y) return x;
    for(int i = k-1;i >= 0 ;i--){
        if(parents[x][i] != parents[y][i]){
            x = parents[x][i];
            y = parents[y][i];
        }
    }
    return parents[x][0];
}

int main(){
    cin >> v;
    rep(i,v){
        int p;
        cin >> p;
        rep(j,p){
            int c;
            cin >> c;
            tree[i].push_back(c);
            tree[c].push_back(i);
        }
    }
    LCAinit();

    int q;
    cin >> q;
    while(q--){
        int a,b;
        cin >> a >> b;
        cout << LCA(a,b) << endl;
    }

    return 0;
}


Measured memory_bytes: 23428
#include <iostream>
#include <stdio.h>
using namespace std;
const int size=1e5+10;
int pre[size];
int main(int argc, char** argv) {
	int n,temp;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&temp);
		pre[temp]=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(i==1)printf("%d",pre[i]);
		else printf(" %d",pre[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1152
import sys
input=sys.stdin.readline

m,n=map(int,input().split())
dt=[]
for i in range(n):
    p,y = map(int, input().split())
    dt+=[[i,p,y,0]]
dt.sort(key=lambda x:(x[1],x[2]))
pi=1
prep=0
for x in dt:
    if prep==x[1]:
        pi+=1
    else:
        pi=1
    x[3]=pi
    prep=x[1]
dt.sort()
for x in dt:
    print(str(x[1]).zfill(6)+str(x[3]).zfill(6))

Measured memory_bytes: 33700
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <set>
#include <algorithm> 
#include <iostream>
#include <bits/stdc++.h>
 
//------------------------------------------------------------------------------
 
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb emplace_back
#define mp make_pair
#define sf scanf
#define pf printf
#define F first
#define S second
 
//------------------------------------------------------------------------------
using namespace std;
 
 
ll int n,dp[100010];

ll int find(ll int a[],ll int i)
{
    if(dp[i]!=-1) return dp[i];
   // if(i==n-1) return a[n-1];
    if(i+1>=n && i+2>=n) return 0;
    
    ll int one=999999999999, two=999999999999;
    
    if(i+1<n)
      one=abs(a[i]-a[i+1])+find(a,i+1);
    if(i+2<n)
      two=abs(a[i]-a[i+2])+find(a,i+2);
   // cout<<one<<" "<<two<<endl;
return dp[i]=min(one,two);
}
 
 
int main() 
{ 
	fio;
	memset(dp,-1,sizeof(dp));
	ll int x,a[100010]={0};
	cin>>n;
	
	for(ll int i=0;i<n;i++)
	  cin>>a[i];
	
	x=find(a,0);
	
	cout<<x<<endl;
    
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc082/tasks/abc082_b

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << ((s<t)?"Yes":"No") << "\n";


    return 0;
}


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

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

int main() {
  long long a, b, nb;
  long long ans;
  cin >> a >> b;
  if (a < b) {
    nb = b;
    b = a;
    a = nb;
  }
  ans = a / gcd(a, b) * b;
  cout << ans << endl;
}


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

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

    int four_cnt = 0,two_cnt = 0;

    for(int i=0; i<N; i++){
        if(A[i] % 4 == 0) four_cnt++;
        if(A[i] % 2 == 0 && A[i] % 4 != 0){
            two_cnt++;
            if(two_cnt == 2){
                two_cnt = 0;
                four_cnt++;
            }
        }
    }

    cout<<((four_cnt >= N/2) ? "Yes" : "No")<<endl;

    return 0;
}

Measured memory_bytes: 640
#![allow(unused)]

use std::{cell, cmp, collections, convert, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let d = parse_word::<i32>();
    let n = parse_word::<i32>();

    let ans = pow100(d) * if n == 100 { 101 } else { n };
    println!("{}", ans);
}

fn pow100(d: i32) -> i32 {
    if d == 0 {
        1
    } else {
        100 * pow100(d - 1)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn next_prime(x: i32) -> i32 {
    for i in (x + 1).. {
        if is_prime(i) {
            return i;
        }
    }

    panic!("attempt to add with overflow");
}

fn is_prime(x: i32) -> bool {
    let ceil = f64::from(x).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}


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

union buff {
    int i[2];
    long l;
};

int main(void)
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    unordered_map<long, int> mp;
    vector<long> keys;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            int p = x[i] - x[j];
            int q = y[i] - y[j];
            union buff key;
            key.i[0] = p;
            key.i[1] = q;
            mp[key.l]++;
            keys.push_back(key.l);
        }
    }
    sort(keys.begin(), keys.end());
    keys.erase(unique(keys.begin(), keys.end()), keys.end());
    int mincost = 50;
    for (size_t i = 0; i < keys.size(); i++) {
        mincost = min(mincost, n - mp[keys[i]]);
    }
    if (n == 1) cout << 1 << endl;
    else cout << mincost << endl;
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>



int main(void){
    char s[100],ss[100];
    int dif=0;
    scanf("%s",s);
    scanf("%s",ss);
    for(int i=0;i<strlen(s)||i<strlen(ss)-1;i++){
        if(s[i]!=ss[i]){dif++;}
    }
    if(dif==0){printf("Yes");}
    else{printf("No");}
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()

int main() {
    int n;
    scanf("%d", &n);
    vector<double> vec(n+1);
    rep(i,n) cin >> vec.at(i);
    sort(all(vec));
    vec.at(0) = vec.at(1);
    rep (i,n) {
        vec.at(i+1) = (vec.at(i)+vec.at(i+1))/2;
    }
    printf("%.5f\n", vec.at(n));
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
	string n;
	cin >> n;
	ll ans = 0;
	int N = n.size();
	for (int i = 0; i < N; i++) {
		ans+=int(n[i]-'0');
	}
	if (ans % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3724
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]

N,C = lmi()

x = { i for i in range(1,N+1)}
for _ in range(C):
    input()
    x = x - set(lmi())
print(len(x))

Measured memory_bytes: 9472
#include<iostream>
using namespace std;
int n,m;
char c[50][50],s[50][50];
int main()
{
    cin>>n>>m;
    bool ok=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cin>>c[i][j];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++)cin>>s[i][j];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i+m-1>=n or j+-1>=n)continue;
            bool can=1;
            for(int k=0;k<m;k++)
            {
                for(int l=0;l<m;l++)
                {
                    if(c[i+k][j+l]!=s[k][l])can=0;
                }
            }
            if(can)ok=1;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[3][101],ans[101]={},ansn=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[1][i];
	for(int i=1;i<=n;i++)
		cin>>a[2][i];
	for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=i;j++)
				ans[i]+=a[1][j];
			for(int k=i;k<=n;k++)
				ans[i]+=a[2][k];
		}
	ansn=ans[1];
	for(int i=2;i<=n;i++)
		ansn=max(ansn,ans[i]);
	cout<<ansn;
	return 0;
} 

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		int n=sc.nextInt();
		int c4=0,c1=0;
		for(int i=0;i<n;i++){
			int x=sc.nextInt()%4;
			if(x==0)
				c4++;
			else
				if(x!=2)
					c1++;
		}
		if(c1+c4==n)
			pw.println(c4>=c1-1? "Yes" : "No");
		else
			pw.println(c4>=c1? "Yes" : "No");
		
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

Measured memory_bytes: 35852
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2010;
int n,head[N],to[N*2],nex[N*2],x,y,tot,k,ans;
void link(int x,int y)
{
	nex[++tot]=head[x];
	to[head[x]=tot]=y;
}
int dfs(int now, int lim, int f)
{
	if(lim<0)
		return 0;
	int ans=1;
	for(int i=head[now]; i; i=nex[i])
		if(to[i]!=f)
			ans+=dfs(to[i],lim-1,now);
	return ans;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1; i<n; i++)
	{
		scanf("%d%d",&x,&y);
		link(x,y);
		link(y,x);
	}
	for(int i=1; i<=n; i++)
	{
		if(k&1)
			for(int j=head[i];j;j=nex[j])
				ans=max(ans,dfs(i,k/2,to[j])+dfs(to[j],k/2,i));
		else
			ans=max(ans,dfs(i,k/2,0));
	}
	printf("%d",n - ans);
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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 (a>b) { a=b; return 1; } return 0; }

bool pos[81][81][12810];

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

    int val[81][81];
    memset(val,0, sizeof(val));
    memset(pos,0, sizeof(pos));

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin>>val[i][j];
        }
    }
    int tmp=0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin>>tmp;
            val[i][j]-=tmp;
        }
    }

    pos[0][0][abs(val[0][0])]=true;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            for (int k = 0; k < 12809; ++k) {
                if(i>0){
                    if(pos[i-1][j][k]) {
                        pos[i][j][abs(k + val[i][j])] = true;
                        pos[i][j][abs(k - val[i][j])] = true;
                    }
                }
                if(j>0){
                    if(pos[i][j-1][k]) {
                        pos[i][j][abs(k + val[i][j])] = true;
                        pos[i][j][abs(k - val[i][j])] = true;
                    }
                }
            }
        }
    }

    for (int k = 0; k < 12809; ++k) {
        if(pos[H-1][W-1][k]){
            cout<<k<<endl;
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 82432
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n, x, y;
	cin >> n >> x >> y;
    --x, --y;
    vector<int> ans(n);
    rep(i,n-1) for (int j = i + 1; j < n; j++) {
        int d = min(j-i, min(abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1));
        ans[d]++;
    }
    rep(i,n-1) cout << ans[i+1] << "\n";
	return 0;
}


Measured memory_bytes: 3656
D = int(input())
c = list(map(int, input().split()))
sdi = [list(map(int, input().split())) for i in range(D)]

#import numpy as np

lastdi = [0 for i in range(26)]
ans_c = []

d = 0
while True:
  if d == D:
    break
  if d > D - 2:
    day_s = sdi[d]
    
    sloss = [day_s[i] + c[i]*(d - lastdi[i]) for i in range(26) ]
    ans = sloss.index(max(sloss))
    ans_c.append( ans+1 )
    
    lastdi[ans] = d
    d += 1
    
  else:
    
    a = [sdi[d][i] + sdi[d+1][i2] - sum([c[k]*( 2*d-lastdi[k]+1) for k in range(26) if (k!=i) & (k!=i2) ] ) -c[i] -c[i2]*(d-lastdi[i2]) for i in range(26) for i2 in range(26) ]
    idx = a.index(max(a))
    best_i2 = idx % 26 + 1
    best_i1 = (idx // 26) % 26 + 1
    
    ans_c.append(best_i1)
    ans_c.append(best_i2)
    lastdi[best_i1-1] = d
    lastdi[best_i2-1] = d+1
    
    d += 2

for i in range(D):
  print(ans_c[i])


Measured memory_bytes: 9528
#include <iostream>
#include <map>
#include <utility>
#include <vector>

class Node {
  public:
    Node* parent;
    Node() { parent = nullptr; }
    Node(Node* p) { parent = p; }
    Node* find_root() {
      Node* p = this;
      while (p->parent != nullptr) {
        p = p->parent;
      }
      return p;
    }
    Node* update_and_find_root() {
      Node* p = this;
      while (p->parent != nullptr) {
        p = p->parent;
      }
      if (p != this) {
        this->parent = p;
      }
      return p;
    }
};

int main()
{
  int ncities, nroads, nlines;
  std::cin >> ncities >> nroads >> nlines;
  std::vector<Node> road(ncities+1);
  std::vector<Node> line(ncities+1);
  for (int i = 0; i < nroads; i++) {
    int dst, src;
    std::cin >> dst >> src;
    Node* dst_root = road.at(dst).update_and_find_root();
    Node* src_root = road.at(src).update_and_find_root();
    if (dst_root != src_root) {
      src_root->parent = dst_root;
    }
  }
  for (int i = 0; i < nlines; i++) {
    int dst, src;
    std::cin >> dst >> src;
    Node* dst_root = line.at(dst).update_and_find_root();
    Node* src_root = line.at(src).update_and_find_root();
    if (dst_root != src_root) {
      src_root->parent = dst_root;
    }
  }
  std::map<std::pair<Node*, Node*>, int> cnt;
  for (int i = 1; i <= ncities; i++) {
    Node* road_root = road.at(i).find_root();
    Node* line_root = line.at(i).find_root();
    cnt[std::pair<Node*, Node*>(road_root, line_root)]++;
  }
  for (int i = 1; i <= ncities; i++) {
    Node* road_root = road.at(i).find_root();
    Node* line_root = line.at(i).find_root();
    if (i != 1) {
      std::cout << ' ';
    }
    std::cout << cnt[std::pair<Node*, Node*>(road_root, line_root)];
  }
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
map<string,ll> mp;
int main(void){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    
    ll ans = 0;
    for(auto i : mp){
        if(i.second >= 2){
            ans += i.second*(i.second-1)/2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
#define rep(i,a,b) for (int i=a;i<=b;i++)
using namespace std;
int n,a,b,x;
int ans=0;
int sum1[1005],sum2[1005];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read(); ans=-233333;
	rep(i,1,n)
	  x=read(),sum1[i]=sum1[i-1]+x;
	rep(i,1,n)
	  x=read(),sum2[i]=sum2[i-1]+x;
	for (int i=1;i<=n;i++)
	  if (sum1[i]+sum2[n]-sum2[i-1]>ans) ans=sum1[i]+sum2[n]-sum2[i-1];
	out(ans);
	return 0;
 }

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int a, b;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> a >> b;

    vector<int> vec(1000, 0);
    for(int i = 1; i < 1000; i++){
        vec[i] = vec[i-1] + i;
    }
    
    cout << vec[b-a] - b << endl;

}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char (isSpace)
import Data.List (unfoldr, maximumBy)

data Position =
  Position
    { idx :: Int
    , pos :: Int
    }
    deriving (Show, Eq)
data DistInfo =
  DistInfo 
    { start :: Position
    , end :: Position
    , distance :: Int
    }
    deriving (Show)

main = do
  [k, n] <- map read . words <$> getLine :: IO [Int]
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print =<< solve k n as

test0 = solve 14 11 [0,1,2,3,4,8,9,10,11,12,13]

solve :: Int -> Int -> [Int] -> IO Int
solve k n as = do
  let positions = indexedMap Position as
  let distInfo = maxDistInfo $ spacings k positions
  let i = idx $ start $ distInfo
  let shifted = (drop i positions) ++ (take i positions)
  let xs = take (length shifted - 1) $ spacings k shifted
  return $ foldr (\e acc -> (distance e) + acc) 0 xs

indexedMap :: (Int -> a -> b) -> [a] -> [b]
indexedMap f xs = zipWith f [0..(length xs)-1] xs

dist :: Int -> Position -> Position -> Int
dist k (Position _ x) (Position _ y) =
  min (abs $ x - y) (k - (abs $ x - y))

pairsLooped :: [a] -> [(a, a)]
pairsLooped [] = []
pairsLooped (h:xs) = help (h:xs)
  where
    help [] = []
    help (x0:[]) = [(x0,h)]
    help (x0:x1:xs) = (x0,x1):(help (x1:xs))
  

spacings :: Int -> [Position] -> [DistInfo]
spacings k positions =
  map help $ pairsLooped positions
  where
    help (x, y) =
      DistInfo
        { start = y
        , end = x
        , distance = dist k x y
        }

maxDistInfo :: [DistInfo] -> DistInfo
maxDistInfo xs = maximumBy (\a b -> compare (distance a) (distance b)) xs

Measured memory_bytes: 48508
import java.util.Scanner;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int sum;
        while(true) {
            String s = sc.next();
            if(s.equals("-")) break;
            n = sc.nextInt();
            sum = 0;
            for (int i = 0; i < n; i++) {
                sum += sc.nextInt();
            }
            int p = sum % s.length();
            for (int i = 0; i < s.length(); i++) {
                System.out.print(s.charAt((p + i) % s.length()));
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 26204
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    int a[2][100];
    for(int i=0;i<n;i++)
        cin>>a[0][i];
    for(int i=0;i<n;i++)
        cin>>a[1][i];
    int ans=0;
    for(int i=0;i<n;i++){
        int cc1=0;
        for(int j=0;j<=i;j++)
            cc1+=a[0][j];
        for(int j=i;j<n;j++)
            cc1+=a[1][j];
        chmax(ans,cc1);
    }
    cout<<ans<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<cmath>
#include<bitset>
#include<cassert>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;

typedef long long ll;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    int n;
    cin >> n;

    if (n >= 30)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  long double r=0;
  vector<int> a;
  cin>>n;
  a.resize(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    r+=1.0/a[i];
  }
  r=1/r;
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define FOR(i,a,n) for(i=a;i<n;i++)
typedef struct LIST{
    int to;
    struct LIST *next;
}Edge;
Edge *edge[100001];
int used[100001];
int ans[100000];
int size1=0,size2=0;
void add(int v,int t){
    Edge *temp = (Edge*)malloc(sizeof(Edge));
    temp->to=t;
    temp->next=edge[v];
    edge[v]=temp;
    return;
}
void end(int v){
    for(int i=1;i<=v;i++){
        for(Edge *e=edge[i]->next;e!=NULL;e=e->next){
            free(e);
        }
    }
    return;
}
int check(int v){
    for(Edge *e=edge[v];e!=NULL;e=e->next){
        if(!used[e->to]) return e->to;
    }
    return -1;
}
int main(void){
    int n,m,i,a,b;
    scanf("%d %d",&n,&m);
    FOR(i,0,m){
        scanf("%d %d",&a,&b);
        add(a,b);
        add(b,a);
    }
    int s=1,g=edge[1]->to;
    used[s]=used[g]=1;
    ans[size1++]=s;
    while(1){
        int t=check(s);
        if(t==-1) break;
        else{
            s=t;
            used[s]=1;
            ans[size1++]=s;
        }
    }
    size2 = size1;
    ans[size2++]=g;
    while(1){
        int t=check(g);
        if(t==-1) break;
        else{
            g=t;
            used[g]=1;
            ans[size2++]=g;
        }
    }
    printf("%d\n",size2);
    for(int i=size1-1;i>=0;i--) printf("%d\n",ans[i]);
    for(int i=size1;i<size2;i++) printf("%d\n",ans[i]);
    
    end(n);
    return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

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

int main(){
	int n,r;
	while(1){
		cin >> n >> r;
		if(n==0 && r==0) break;
		
		int i,j;
		int p[100],c[100];
		for(i=0;i<r;i++){
			cin >> p[i] >> c[i];
		}
		
		int top=0;
		for(i=r-1;i>=0;i--){
			if(0<=top && top<c[i]) top+=(p[i]-1);
			else if(c[i]<=top && top<p[i]+c[i]-1) top-=c[i];
		}
		cout << n-top << endl;
	}
}

Measured memory_bytes: 0
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

array<int, 123> asciiBet = {};

int main()
{
	fastIOS();
	
	vector<int> sen;
	int ta, tb, tc;
	cin >> ta;
	cin >> tb;
	cin >> tc;
	sen.push_back(ta);
	sen.push_back(tb);
	sen.push_back(tc);

	int senSize = sen.size();

	int cnt7 = 0;
	int cnt5 = 0;

	REP(i, senSize)
	{
		if (sen[i] % 5 == 0)
			cnt5++;
		else if (sen[i] % 7 == 0)
			cnt7++;
	}

	if (cnt5 == 2 && cnt7 == 1)
		cout << "YES" << "\n";
	else
		cout << "NO" << "\n";
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        String n = sc.next();
        switch (n.charAt(n.length()-1)) {
            case '2':
            case '4':
            case '5':
            case '7':
            case '9':
                System.out.println("hon");
                break;
            case '0':
            case '1':
            case '6':
            case '8':
                System.out.println("pon");
                break;
            case '3':
                System.out.println("bon");
                break;
        }
    }
}



Measured memory_bytes: 35716
//↓見なくていいよ！ここから--------------------------------------------------
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] - 1;
	var s = nextCharArray();
	s[K] = s[K].toLowerCase();
	myout(myconv(s,0));
}


Measured memory_bytes: 30072
#include <stdio.h>
#include <stdlib.h>

int a[10291], b[10102];

int main() {
    int grupo, soma=0;
    scanf("%d", &grupo);
    for (int i = 0; i < grupo; i++) {
        scanf("%d %d", &a[i], &b[i]);
        if (a[i]!=b[i]) {
            soma+=b[i]-a[i]+1;
        } else {
            soma+=1;
        }
    }
    printf("%d\n", soma);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
typedef long long int ll;
typedef vector<ll> v;


int main() {
	int h, w, l;
	cin >> h >> w >> l;
	ll dp[110][10];
	rep(i, 110) {
		rep(j, 10) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, pow(2,w-1)) {
			bool iku = true;
			rep(k, w-2) {
				if (j >>(k+1) & 1 && j >> (k + 2) & 1&&iku) {
					iku = 0;
				}
			}
			if (j % 2 == 1 && j >> 1 & 1 &&iku) {
				iku = 0;
			}
			if (iku) {
				rep(k, w) {
					if (k == 0){
						if (j % 2 == 1) {
							dp[i + 1][k+1] = (dp[i+1][k+1]+ dp[i][k])%mod;
						}
						else {
							dp[i + 1][k] =(dp[i+1][k]+ dp[i][k])%mod;
						}
					}
					else if (k == w - 1) {
						if ((j >> (w - 2)) & 1) {
							dp[i + 1][k - 1] =(dp[i+1][k-1]+ dp[i][k])%mod;
						}
						else {
							dp[i + 1][k] =(dp[i+1][k]+ dp[i][k])%mod;
						}
					}
					else if (k == 1){
						if (!((j >> k) & 1) && j%2 == 0) {
							dp[i + 1][k] = (dp[i + 1][k] + dp[i][k]) % mod;
						}
						else if ((j >>k) & 1) {
							dp[i + 1][k + 1] = (dp[i + 1][k + 1] + dp[i][k]) % mod;
						}
						else {
							dp[i + 1][k - 1] = (dp[i + 1][k - 1] + dp[i][k]) % mod;
						}
					}
					else {
						if (!((j >> k) & 1) && !((j >> (k - 1))&1)) {
							dp[i + 1][k] =(dp[i+1][k]+ dp[i][k])%mod;
						}
						else if (j >> k & 1) {
							dp[i + 1][k + 1] =(dp[i+1][k+1]+ dp[i][k])%mod;
						}
						else {
							dp[i + 1][k - 1] =(dp[i+1][k-1]+ dp[i][k])%mod;
						}
					}
				}
			}
		}
	}
	cout << dp[h][l-1]%mod << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

/*
template<class T> void disp_pos (const T& a, int start )
{
//	int size = sizeof(a)/sizeof(a[0]);
	int size = 8;
	int i,j;

//	cout << "size: " << size << endl;

	for (i = 0, j = start; i < size; ++i, j = (j + 1) % size ){
		cout << a[j];
		if (i != size - 1){
			cout << ' ';
		} // end if
	} // end for
	cout << endl;
}
*/
  
template<class T> string itos (const T& a, int start )
{
	int size = sizeof(a)/sizeof(a[0]);
	string res = "";
	int i,j;

//	cout << "size: " << size << endl;

	for (i = 0, j = start; i < size; ++i, j = (j + 1) % size ){
		res += a[j] + '0';
	} // end for	
	
	return res;
}

string disp_res (string str )
{
	int len = str.length();
	string res = "";
	int i;

	for (i = 0; i < len; ++i){
		res += str[i];
		if (i != len - 1){
			res += ' ';
		} // end if
	} // end for
	
	return res;	
}
	
int main()
{
//	cut here before submit 
//	freopen("testcase.fj", "r", stdin);

	const int flying_pos[] = { 4, 1, 4, 1, 2, 1, 2, 1 }; // order by clockwise

	string str = "";

	while (getline (cin, str ) ){
		vector <int> c (8, 0 );
		stringstream ss(str);
		int i,j;

		for (i = 0; i < 8; ++i){
			ss >> c[i];
		} // end for

		vector <int> not_ride (8, 0 );
		vector <map <int, string> > rank;

		for (i = 0; i < 8; ++i){
//			cout << "custamer:" << endl;
//			disp_pos (c, 0 );
//			cout << "vehicle: " << endl;
//			disp_pos (flying_pos, i % 8 );
			for (j = 0; j < 8; ++j){
				int remain = c[j] - flying_pos[(i+j) % 8];
				not_ride[i] += remain <= 0 ? 0 : remain;
			} // end for
//			cout << "sum_not_ride: " << not_ride[i] << endl;
			map<int, string> r;
			string curr_pos = itos (flying_pos, i % 8 );
			r.insert (make_pair (not_ride[i], curr_pos ) );
			rank.push_back (r );
		} // end for

		sort (rank.begin(), rank.end() );

		vector <map <int, string > >::iterator it = rank.begin();
//		for (i = 0; it != rank.end(); ++i, ++it ){
		map<int, string >::iterator itr = rank[0].begin();
		string res = disp_res ((*itr).second );
		cout << res << endl;
//			cout << (*itr).first << ':' << (*itr).second << endl;
//		} // end for

/*			
		// for debug
		cout << string (20, '-') << endl;
		for (i = 0; i < 8; ++i){
			cout << not_ride[i];
			if (i != 7 ){
				cout << ' ';
			} // end if
		} // end for
		cout << endl;
*/
	} // end loop
		
	return 0;
}

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

#define MAX_N 109

using namespace std;

typedef long long lint;

string s;
int k;

int cif;

lint rez;
lint getComb(int n, int k)
{
    if(k == 0 || k == n)
        return 1;

    if(k > n)
        return 0;

    //cout << " INTREU COMB " << n << " " << k << "\n";

    lint rez = 1;
    for(lint i = n; i >= n - k + 1; i --)
    {
        rez = rez * i;
    }

    for(int i = 1; i <= k; i ++)
        rez /= i;

    //cout << " IES COMB " << rez << "\n";

    return rez;
}

lint p[5];

int main()
{
    cin >> s;
    cin >> k;
//cout << "GATA CITIRea\n";

    cif = s.size();

    p[0] = 1;
    for(int i = 1; i <= 3; i ++)
        p[i] = p[i - 1] * 9;

    for(int i = k; i < cif; i ++)
    {
        rez += getComb(i - 1, k - 1) * p[k];
    }

   // cout << rez << " + " << getComb(cif - 1, k) * p[k] << " < N\n";


/*
    if(s[0] - '0' > 1)
    {
        rez += (s[0] - '0' - 1) * getComb(cif - 1, k - 1) * p[k - 1];
    }*/

    //cout << " DUPA 1 cif\n" << rez << "\n";

    int cate = 0;
    rez = 0;
    for(int i = 0; i < cif; i ++)
    {


        if(s[i] - '0' != 0)
            cate ++;

        if(cate <= k && s[i] != '0' )
        {
            rez += (s[i] - '0' - 1) * getComb(cif - (i + 1), k - cate) * p[k - cate];
            rez += getComb(cif - (i + 1), k - cate + 1) * p[k - cate + 1];
          //  cout << " DUPA " << i << " EGALE " << rez << "\n";
        }
    }

    if(cate >= k)
        rez ++;

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	int N; cin >> N;
	vector<P>v(N);
	int mx = 0, mn = 1e9;
	REP(i, N) {
		cin >> v[i].first >> v[i].second;
		if (v[i].first > v[i].second)swap(v[i].first, v[i].second);
		chmax(mx, v[i].second);
		chmin(mn, v[i].first);
	}
	VSORT(v);
	//max=Rmax,min=Bmin
	ll ans = 1e18;
	{
		int Bmin = mn, Rmax = mx;
		int Bmax = 0, Rmin = 1e9;
		REP(i, N) {
			chmax(Bmax, v[i].first);
			chmin(Rmin, v[i].second);
		}
		chmin(ans, (Bmax - Bmin)*(Rmax - Rmin));
	}
	//max=Rmax,min=Rmin
	{
		if (v[0].second != mx) {
			int Mmin = v[0].second;
			int Rmax = mx, Rmin = mn;
			int Bmax = v[0].second, Bmin = v[0].second;
			FOR(i, 1, N) {
				chmax(Bmax, v[i].first);
				chmin(Bmin, v[i].first);
			}
			ll res = (Rmax - Rmin)*(Bmax - Bmin);
			//pe(Bmin); print(Bmax);
			FOR(i, 1, N) {
				chmin(Mmin, v[i].second);
				if (i == N - 1)Bmin = Mmin;
				else Bmin = min({ v[i+1].first,Mmin });
				chmax(Bmax, v[i].second);
				res = min(res, (Rmax - Rmin)*(Bmax - Bmin));
				//pe(Bmin); print(Bmax);
			}
			chmin(ans, res);
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 3968