akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Stack;

//Strange Mathematical Expression
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String[] s = sc.nextLine().split(" ");
			Stack<Double> u = new Stack<Double>();
			for(String v:s){
				if(v.equals("+")){
					double b = u.pop();
					double a = u.pop();
					u.push(a+b);
				}
				else if(v.equals("-")){
					double b = u.pop();
					double a = u.pop();
					u.push(a-b);
				}
				else if(v.equals("*")){
					double b = u.pop();
					double a = u.pop();
					u.push(a*b);
				}
				else if(v.equals("/")){
					double b = u.pop();
					double a = u.pop();
					u.push(a/b);
				}
				else u.push(Double.parseDouble(v));
			}
			System.out.println(u.pop());
		}
	}
}

Measured memory_bytes: 26060
from numpy import*
t,*h=open(0)
_,a,b=int32(t.split())
h=int32(h)
i,j=0,2**30
while~i+j:
  k=(j+i)//2
  t=(b*k-h)//(a-b)
  if-k>sum(t[t<0]):i=k
  else:j=k
print(j)

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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(c - Math.min(c, a - b));

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23124
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 2e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 1e-9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w" stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long a, b;
    cin >> a >> b;
    
    cout << a * b;
	return 0;
}


Measured memory_bytes: 3600
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    ll n; cin >> n;
    ll ans = 0;
    rip(i,n+1,1) {
        ans += (ll) (n/i)*(n/i+1)/2*i;
    }
    cout << ans << endl;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

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

int32_t main(){
  DESYNC;
  int n;
  cin >> n;
  int v[n];
  for(int i=0; i<n; i++)
    cin >> v[i];
  
  int ans = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      ans += v[i]*v[j];
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
H, W=map(int, input().split())
h, w=map(int, input().split())

t=[[0]*W for i in [0]*H]

for i in range(h):
    for j in range(W):
        t[i][j]=1

for i in range(w):
    for j in range(H):
        t[j][i]=1

ans=0

for i in range(H):
    for j in range(W):
        if t[i][j]==0:
            ans+=1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std ;
int main()
{
    int a,b,c,add,sub,mult ;
    cin>>a>>b;
    add=a+b;
    sub=a-b;
    mult=a*b;
    if((add>sub ||add==sub) && add>mult){
        cout<<add;
    }else if ((sub>add||sub==add) && sub>mult){
        cout <<sub;
    }else {
        cout<<mult;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
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, diff_weight[i] = SUM_UNITY;
    }

    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];
    }

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

    bool merge(int x, int y, Abel 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;
    }

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


int main(){
    int n,q;
    int x,y,z;
    int count=0;
    cin>>n>>q;
    UnionFind<int> U(n);
    int info;
    int diff[q];
    for(int i=0;i<q;i++){
        cin>>info;
        if(info==0){
        cin>>x>>y>>z;
        U.merge(x,y,z);
        }

        if(info==1){
        cin>>x>>y;
        if(U.issame(x,y)){
        cout<<U.diff(x, y)<<endl;
        }
        else{
            cout<<"?"<<endl;
        }
        }
    }

    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,a[100003],b[100002],ans=0;
    cin >> n;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    
    rep(i,n){
        if(a[i] >= b[i]) ans += b[i];
        else if(a[i] < b[i]){
            b[i] -= a[i];
            ans += a[i];
            if(b[i] >= a[i+1]){
                ans += a[i+1];
                a[i+1] = 0;
            }else if(b[i] < a[i+1]){
                a[i+1] -= b[i];
                ans += b[i];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
const inputs = require('fs').readFileSync('/dev/stdin', 'UTF-8').split('\n');
let str = '';
for (let i = 0; i < inputs.length; i++) {
  const input = inputs[i].split(' ').map(Number);
  const h = input[0];
  const w = input[1];
  if (w === 0 && h === 0) break;
  if (i !== 0) {
    str += '\n';
  }
  let W = Array(w + 1).join('#') + '\n';
  str += W;
  for (let j = 1; j < h - 1; j++) {
    str += '#' + Array(w - 1).join('.') + '#' + '\n';
  }
  str += W;
}
console.log(str);



Measured memory_bytes: 17076
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)

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


  if(a==1&& b==1)cout<<"Draw"<<endl;
  else if(a==1)cout<<"Alice"<<endl;
  else if(b==1)cout<<"Bob"<<endl;
  else if(a==b)cout<<"Draw"<<endl;
  else if(a>b)cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;




  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

class Main{
	static int[] dp;
	static int[] Match= {6,2,5,5,4,5,6,3,7,6};
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		StringBuilder sb=new StringBuilder();
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[] useable=new int[M];
		for(int i=0; i<M; i++) {
			useable[i]=sc.nextInt();
		}
		dp=new int[N+1];
		Arrays.fill(dp, -200);
		dp[0]=0;
		for(int i=0; i<=N; i++) {
			for(int j=0; j<M; j++) {
				if(i-Match[useable[j]]>=0) {
					dp[i]=Math.max(dp[i], dp[i-Match[useable[j]]]+1);
				}
			}
		}
		int keta = dp[N];		//桁
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0; i<keta; i++) {
			int suji=0;	//今から決める数字
			for (int j = 0; j < M; j++) {
				if (N >= Match[useable[j]] && dp[N] - dp[N - Match[useable[j]]] == 1) {
					suji = Math.max(suji, useable[j]);
				}
			}
			list.add(suji);
			N-=Match[suji];
		}
		Collections.sort(list);
		sb = new StringBuilder();
		for (int i = list.size() - 1; i >= 0; i--) sb.append(list.get(i));
		System.out.println(sb.toString());
	}
	public static boolean Bigger(String a,String b) {//前者のほうが大きいとTrue、そうでなければFalse
		if(a.length()>b.length()) {
			return true;
		}
		else if(a.length()<b.length()) {
			return false;
		}
		else {
			for(int j=0; j<a.length(); j++) {
				if(a.charAt(j)>b.charAt(j)) {
					return true;
				}
				else if(a.charAt(j)<b.charAt(j)) {
					return false;
				}
			}
		}
		return true;
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define inf (long long)1e18
using namespace std;

struct data{
    long long from,to,c;
};

long long n,m,ans = 0;
vector<data> v;
vector<long long> dist;


void solve();
bool bell_calc();
bool bell_ch();

int main(){
    cin >> n >> m;
    v.resize(m);
    for(int i = 0;i < m;++i){
        cin >> v[i].from >> v[i].to >> v[i].c;
        --v[i].from,--v[i].to;
        v[i].c *= -1;
    }
    solve();
    if(ans == inf)cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}

void solve(){
    dist.assign(n,inf);
    dist[0] = 0;
    for(int i = 0;i < n - 1;++i)bell_calc();
    ans = dist[n-1];
    for(int i = 0;i < n;++i)
        if(bell_ch())ans = inf;
}

bool bell_calc(){
    bool ch = 0;
    for(int i = 0;i < m;++i)
        if(dist[v[i].from] != inf && dist[v[i].to] > dist[v[i].from] + v[i].c){
            dist[v[i].to] = dist[v[i].from] + v[i].c;
            ch = 1;
        }
    return ch;
}
bool bell_ch(){
    bool ch = 0;
    for(int i = 0;i < m;++i)
        if(dist[v[i].from] != inf && dist[v[i].to] > dist[v[i].from] + v[i].c){
            dist[v[i].to] = -inf;
            if(v[i].to == n-1)ch = 1;
        }
    return ch;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string a,b;
    cin>>a>>b;
    for (int i=0;i<n;i++)
    cout<<a.at(i)<<b.at(i);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%s",s);
  n = strlen(s);
  rep(i,floorl(n/2)){
    if(s[i]!=s[n-1-i]) result++;
  }
  printf("%lld",result);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
char ai[10005];
int main()
{
    scanf("%s",ai);int a=0,b=0;
    for(int i=0;ai[i]!='\0';i++)
    {

        if(ai[i]=='+')
            a++;
        else
            b++;
    }
    printf("%d\n",a-b);
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, C = input().split()

print((A[0] + B[0] + C[0]).upper())

Measured memory_bytes: 3572
N = int(input())
S = input()

oder = N
l = [0 for _ in range(N)]
r = [0 for i in range(N)]

for i in range(1, N):
  l[i] = l[i-1] + (S[i-1] == 'W')
  r[-i-1] = r[-i] + (S[-i] == 'E')

for i in range(N):
  oder = min(oder, l[i]+r[i])

print(oder)


Measured memory_bytes: 27384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

ll judge(vector<vector<char>> &v,ll x){
    ll n=siz(v);

    for(int i=0;i < siz(v);i++)
    {
        for(int j=0;j < siz(v);j++)
        {
            if(v[(i-x+n)%n][(j)%n]!=v[(j-x+n)%n][(i)%n]){
                return 0;
            }
        }
    }

    return n;
}

signed main(){
    int n;cin>>n;
    ll ans=0;
    vector<vector<char>> v(n,vector<char>(n));
    rep(i,n)rep(j,n){
        cin>>v[i][j];
    }

    
    rep(i,n){
        ans+=judge(v,i);
    }

    cout<<ans<<endl;

}	

Measured memory_bytes: 384
#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>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct BIT {
    int n;
    vi bit;
    BIT(int num) : bit(num + 1, 0) {n = num; }
    void add(int i, int w){
        for(int x = i; x <= n; x += x & -x) bit[x] += w;
    }
    int sum(int i){ // sum of [1, i]
        int ret = 0;
        for(int x = i; x > 0; x -= x &- x) ret += bit[x];
        return ret;
    }
    int sum(int l, int r){  // sum of (l, r]
        return sum(r) - sum(l);
    }
};

typedef tuple<ll, ll, ll> tup;

void solve() {
    ll n, q;
    cin >> n >> q;
    vll c(n + 1);
    rep(i, n) cin >> c[i + 1];
    vector<tup> vtup;
    rep(i, q) {
        ll l, r;
        cin >> l >> r;
        vtup.emplace_back(r, l, i);
    }
    sort(vtup.begin(), vtup.end());

    vll last(n + 1, -1);
    vll ans(q);
    ll ic = 1;
    BIT bit(n);
    for(ll i = 0; i < q; i++) {
        ll r, l, idx;
        tie(r, l, idx) = vtup[i];
        while(ic <= n && ic <= r) {
            ll last_tmp = last[c[ic]];
            if(last_tmp != -1) bit.add(last_tmp, -1);
            last[c[ic]] = ic;
            bit.add(ic, 1);
            ++ic;
        }
        ans[idx] = bit.sum(l - 1, r);
    }
    for(ll& i : ans) cout << i << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 29144
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ull i=0;i<(ull)n;++i)
const ull INF = 999999999999999;



int main(){
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> array(n);
  rep(i,m){
    ll a,b;
    scanf("%lld %lld",&a,&b);
    --a;
    --b;
    array.at(a).push_back(b);
  }
  rep(i,array.at(0).size()){
    ll num = array.at(0).at(i);
   rep(j,array.at(num).size()){
     if( array.at(num).at(j) == n-1 ){
       cout << "POSSIBLE" << endl;
       return 0;
     }
   }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,temp;
	cin>>a>>b;
	temp=a;
	for(int i=1;i<=b;i++){
		temp++;
		if(temp==24)
			temp=0;
	}
	cout<<temp<<"\n";
	return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())
words = [input() for i in range(N)]
after = [words[0]]

for i in range(1, N):
    word = words[i]
    if word in after or after[-1][-1] != word[0]:
        print('No')
        sys.exit()  
    after.append(word)
    
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    rep(i,10001){
        int x;
        cin >> x;
        if(x == 0)break;
        cout << "Case " << i+1 << ": " << x << endl;
        
    }
}


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

void solve(){
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t = 1;
	while(t--) solve();
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll vet[n+2];
    ll xoract=0;
    rep(i,0,n){
        cin>>vet[i];
        xoract^=vet[i];
    }
    rep(i,0,n){
        cout<<(xoract^vet[i])<<" ";
    }
    cout<<"\n";
    return 0;  
}   

Measured memory_bytes: 5184
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

ll ce(ll x,ll y){
    return (y+(x-1))/x;
}

int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;

    ll tmp[5];
    tmp[0]=ce(a,n);
    tmp[1]=ce(b,n);
    tmp[2]=ce(c,n);
    tmp[3]=ce(d,n);
    tmp[4]=ce(e,n);

    ll ans=tmp[0];
    ll mx=tmp[0];
    for(int i=1;i<5;i++){
        if(mx>=tmp[i]) {
            ans++;
        }else{
            ans=tmp[i]+i;
            mx=tmp[i];
        }
    }

    cout << ans << endl;    
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>

int keta(int a){
  
  int count = 0;
  int temp = a;
  while(temp != 0){
    count ++;
    temp /= 10;
  }
  return count;
}

int main(void){
  long n;
  scanf("%ld",&n);
  
  int k = (int)sqrt(n);
  int ans;
  
  
for(int i = k + 1;i > 0;i --){
   if(n%i == 0){
     long temp = n/i;
     ans = keta(temp);
     i = -1;
   }
}
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
#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 = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

void debug_out() {
    cerr << endl;
}

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

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main() {
    FAST

    string a,b;
    cin>>a>>b;
    if(a==b.substr(0,b.size()-1))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  int F = 0, K = 0;
  rep(i, N) {
    int a; cin >> a;
    if (a % 4 == 0) {
      F++;
    }
    if (a % 4 != 0 && a % 2 != 0) {
      K++;
    }
  }

  if (N % 2 == 0) {
    cout << (K <= F ? "Yes" : "No") << "\n";
  } else {
    cout << (K - 1 <= F ? "Yes" : "No") << "\n";
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main{
	Scanner sc=new Scanner(System.in);
	int INF=1<<28;
	double EPS=1e-9;

	int n, m, l;
	int[][] w;
	int[] p, t;

	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			l=sc.nextInt();
			if((n|m|l)==0){
				break;
			}
			w=new int[n][n];
			p=new int[l];
			t=new int[l];
			for(int i=0; i<n; i++){
				Arrays.fill(w[i], INF);
				w[i][i]=0;
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt();
				int v=sc.nextInt();
				int d=sc.nextInt();
				w[u][v]=w[v][u]=d;
			}
			for(int i=0; i<l; i++){
				p[i]=sc.nextInt();
				t[i]=sc.nextInt();
			}
			solve();
		}
	}

	void solve(){
		for(int k=0; k<n; k++){
			for(int j=0; j<n; j++){
				for(int i=0; i<n; i++){
					w[i][j]=Math.min(w[i][j], w[i][k]+w[k][j]);
				}
			}
		}
		V[] vs=new V[l*2];
		for(int i=0; i<l*2; i++){
			vs[i]=new V(i%l);
		}
		for(int j=0; j<l; j++){
			for(int i=0; i<l; i++){
				if(i==j){
					continue;
				}
				int u=p[i];
				int v=p[j];
				if(t[i]+w[u][v]<=t[j]){
					vs[i].connect(vs[j+l]);
				}
			}
		}
		/*
		 * for(int i=0; i<l*2; i++){ debug("i:", i); for(V v : vs[i]){
		 * debug(v.i); } }
		 */
		int match=hopcroftKarp(vs);
		int ans=l-match;
		//debug("match", match);
		//debug("ans",ans);
		for(int i=0; i<l*2; i++){
			// debug(i, ":", vs[i].pair!=null?vs[i].pair.i:-1);
		}

		println(ans+"");
	}

	int hopcroftKarp(V[] vs){
		for(int match=0;;){
			Queue<V> que=new LinkedList<V>();
			for(V v : vs){
				v.level=-1;
			}
			for(V v : vs){
				if(v.pair==null){
					v.level=0;
					que.offer(v);
				}
			}
			for(; !que.isEmpty();){
				V v=que.poll();
				for(V u : v){
					V w=u.pair;
					if(w!=null&&w.level<0){
						w.level=v.level+1;
						que.offer(w);
					}
				}
			}
			for(V v : vs){
				v.used=false;
			}
			int d=0;
			for(V v : vs){
				if(v.pair==null&&dfs(v)){
					d++;
				}
			}
			if(d==0){
				return match;
			}
			match+=d;
		}
	}

	boolean dfs(V v){
		v.used=true;
		for(V u : v){
			V w=u.pair;
			if(w==null||!w.used&&v.level<w.level&&dfs(w)){
				v.pair=u;
				u.pair=v;
				return true;
			}
		}
		return false;
	}

	class V extends LinkedList<V>{
		V pair;
		boolean used;
		int i, level;

		V(int i){
			this.i=i;
		}

		void connect(V v){
			add(v);
			v.add(this);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		try{
			// System.setIn(new FileInputStream("in.txt"));
		}catch(Throwable e){
			e.printStackTrace();
		}
		new Main().run();
	}
}

Measured memory_bytes: 55000
import java.util.Scanner;

public class Main {
	private int number[] = new int[3];
	private int product[][] = new int[3][];
	private int test[][];
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run(){
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 3; i++) {
			number[i] = scan.nextInt();
		}

		while ((number[0]|number[1]|number[2]) != 0) {
			
			for (int i = 0; i < 3; i++) {
				product[i] = new int[number[i]];
			}
			
			
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < number[i]; j++) {
					product[i][j] = 2;
				}
			}

			int n = scan.nextInt();
			
			test = new int[n][4];
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < 4; j++) {
					test[i][j] = scan.nextInt();
				}
			}
			
			for (int i = 0; i < n; i++) {
				if (test[i][3] == 1) {
					product[0][test[i][0] - 1] = 1;
					product[1][test[i][1] - number[0] - 1] = 1;
					product[2][test[i][2] - (number[0] + number[1]) - 1] = 1;
				}
			}
			
			//confirm(n);
			boolean flag = false;
			
			while (!flag) {
				flag = true;
				
				for (int i = 0; i < number[0]; i++) {
					if (product[0][i] == 2) {
						for (int p = 0; p < n; p++) {
							if (test[p][0] == i + 1) {
								if (product[1][test[p][1] -number[0] - 1] == 1 && product[2][test[p][2] - (number[0] + number[1]) - 1] == 1) {
									product[0][i] = 0;
									flag = false;
								}
							}
						}
					}
				}
				
				for (int j = 0; j < number[1]; j++) {
					if (product[1][j] == 2) {
						for (int p = 0; p < n; p++) {
							if (test[p][1] == j + number[0] + 1) {
								if (product[0][test[p][0] - 1] == 1 && product[2][test[p][2] - (number[0] + number[1]) - 1] == 1) {
									product[1][j] = 0;
									flag = false;
								}
							}
						}
					}
				}
				
				for (int k = 0; k < number[2]; k++) {
					if (product[2][k] == 2) {
						for (int p = 0; p < n; p++) {
							if (test[p][2] == k + (number[0] + number[1]) + 1) {
								if (product[0][test[p][0] - 1] == 1 && product[1][test[p][1] - number[0] - 1] == 1) {
									product[2][k] = 0;
									flag = false;
								}
							}
						}
					}
				}
			}
			
			
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < number[i]; j++) {
					System.out.println(product[i][j]);
				}
			}
			
			for (int i = 0; i < 3; i++) {
				number[i] = scan.nextInt();
			}
		}
		
	}
	
	private void confirm(int n){
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < number[i]; j++) {
				System.out.print(product[i][j]+" ");
			}
			System.out.println();
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 4; j++) {
				System.out.print(test[i][j] + " ");
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 35336
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        PrintWriter pw = new PrintWriter(System.out);
        for (char c : S.toCharArray()) {
            int i = c+N;
            pw.print((char) (i > 90 ? i-26 : i));
        }
        pw.println();
        pw.flush();
    }
}


Measured memory_bytes: 23892
#include <stdio.h>

 int main(void){
 int a[3][10][4] = {0};
 int i, j, k;
 int n, p;
 int b, f, r, v; /* b棟f階r番目の部屋にv人 [階][部屋][棟] */

scanf("%d", &n);
 for(i=0; i<n; i++){
 scanf("%d%d%d%d", &b, &f, &r, &v);

 a[f-1][r-1][b-1] += v;
 }

 for(k=0; k<4; k++){
 for(i=0; i<3; i++){
 for(j=0; j<10; j++){
 if(a[i][j][k] == 0){
 printf(" 0");
 }else{
 printf(" %d", a[i][j][k]);
 }
 }
 printf("\n");
 }
 if(k != 3){
 printf("####################\n");
 }
 }

 return 0;
 }


Measured memory_bytes: 2036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		String[] x = line.split(" ");
		int[] n = new int[x.length];
		for (int i = 0; i < x.length; i++) {
			n[i] = Integer.parseInt(x[i]);
		}

		for (int i = 0; i < n.length; i++) {
			int keep = n[i];
			int j = i - 1;
			while (j >= 0 && n[j] > keep) {
				n[j + 1] = n[j];
				j--;
			}
			n[j + 1] = keep;

		}

		System.out.println(n[0] + " " + n[1] + " " + n[2]);

	}

}

Measured memory_bytes: 26136
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;

int main(){
    string S;cin >> S;
    int count0odd = 0, count1odd = 0, count0even = 0, count1even = 0;
    for(int i = 0;i < S.size();++i){
        if(i%2){
            count0odd +=((S[i] == '0') ? 1 : 0);
            count1odd +=((S[i] == '1') ? 1 : 0);
        }else{
            count0even +=((S[i] == '0') ? 1 : 0);
            count1even +=((S[i] == '1') ? 1 : 0);
        }
    }
    cout << min(count0odd + count1even, count1odd + count0even);
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int x, a, b;
  cin >> x;
  a = x/500;
  b = (x - a * 500)/ 5;
  cout << a * 1000 + b * 5 << endl;
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

min_val = 99999999
for i in range(-100, 101):
  sum_val = 0
  for j in range(n):
    sum_val += (i - a[j])**2
  if min_val > sum_val:
    min_val = sum_val
print(min_val)

Measured memory_bytes: 3064
# coding: utf-8

from itertools import accumulate as accum
import sys
input = sys.stdin.readline

def f2(n, a):
    acsum = list(accum(a)) + [0]
    dp = [[float('inf')] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = 0
        if i + 1 != n:
            dp[i][i + 1] = a[i] + a[i + 1]
    for i in range(n - 3, -1, -1):
        for j in range(i + 2, n):
            c = float('inf')
            dpi = dp[i]
            for x in range(i, j):
                c_ = dpi[x] + dp[x + 1][j]
                if c_ < c:
                    c = c_
            dpi[j] = c + acsum[j] - acsum[i - 1]
    return(dp[0][n - 1])

n = int(input()) # 2 <= n <= 400
a = list(map(int, input().split()))
print(f2(n, a))


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

int n;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(true){
		cin >> n;
		if(n == 0) return 0;
		vector<int> v;
		for(int i=0; i<n; ++i){
			int t;
			cin >> t;
			v.push_back(t);
		}
		int sum = 0;
		sort(v.begin(), v.end());
		for(int i=1; i<n-1; ++i)
			sum += v[i];
		sum /= n-2;
		cout << sum << "\n";
	}
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <bitset>

const int MOD = 1e9 + 7;

using namespace std;

long long si = 0;

long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}

const int K = 4000;
vector<long long> dp(K);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            si = (si + j * inq(k + 1, n - 1)) % MOD;
        }
    }
    dp[0] = 1;
    for (int i = n; i >= 1; i--)
    {
        vector<long long> dp2(K);
        for (int a = 0; a <= k; a++)
        {
            for (int hv = 0; hv < K; hv++)
            {
                if (dp[hv] != 0)
                {
                    if (a <= i) dp2[hv + (hv + a) / i] = (dp2[hv + (hv + a) / i] + dp[hv]) % MOD;
                    else dp2[hv] = (dp2[hv] + dp[hv]) % MOD;
                }
            }
        }
        dp = dp2;
    }
    long long si2 = 0;
    for (int i = 0; i < K; i++) si2 = (si2 + dp[i] * i) % MOD;
    cout << (si + MOD - si2) % MOD;
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)

template<typename T>
constexpr T int_pow(T b, uint64_t e)
{
	if (e == 0) return 1;
	if ((e & 0x1) == 0) return int_pow(b * b, e >> 1);
	else return b * int_pow(b * b, e >> 1);
}

int main()
{
	int N, K;
	cin >> N >> K;
	
	assert(N >= 1);
	cout << K * int_pow(K-1, static_cast<uint64_t>(N-1)) << endl;

	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();
    HashMap<String,HashMap<Integer,Integer>> res = new HashMap<>();
    List<String> list = new ArrayList<>();
    
    for(int i = 1;i <= n; ++i){
      //市
      String s = sc.next();
      //同じのあるかな
      if(res.containsKey(s)){
        //点とレストラン番号
        HashMap<Integer,Integer> po_num = res.get(s);
        po_num.put(sc.nextInt(), i);
        res.remove(s);
        res.put(s,po_num);	        
      }else{
        //ないから追加
        list.add(s);
        //点とレストラン番号
        HashMap<Integer,Integer> po_num = new HashMap<>();
        po_num.put(sc.nextInt(), i);
		res.put(s,po_num);        
      }
    }
    //ソート
    Collections.sort(list);
    //まちの数
    int s_num = list.size();
    
    for (int i = 0; i < s_num; ++i){
      String s = list.get(i);
      HashMap<Integer,Integer> po_num = res.get(s);
      Object[] result = po_num.keySet().toArray();
      Arrays.sort(result);
      int count = result.length;
      
      for (int j = 1; j <= count; ++j){
        int ans = (Integer)result[count-j];
        System.out.println(po_num.get(ans));
      }
    }

  }
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	vector<ll> a(n, 0);
	REP(i, n) cin >> a[i];

	ll sum = accumulate(a.begin(), a.end(), 0LL);
	ll sumO = 0;
	REP(i, n)
		if (i % 2)
			sumO += a[i];

	vector<ll> res(n, 0);
	res[0] = sum - 2 * sumO;
	REP(i, n - 1) {
		res[i + 1] = 2 * a[i] - res[i];
	}
	REP(i, n) {
		cout << res[i];
		if (i != n - 1)
			cout << " ";
	}
	cout << '\n';
    return 0;
}


Measured memory_bytes: 4776
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  int y,m,d;
  cin>>s;
   y = atoi(s.substr(0, 4).c_str());
   m = atoi(s.substr(5, 6).c_str());
   d = atoi(s.substr(8, 9).c_str());
  if (y<2019) cout<<"Heisei"<<endl;
  else if (y == 2019 && m<5) cout<< "Heisei"<<endl;
  else cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void number_split_2adic(int num, int a[])
{
	int i=0;

	while(num>0){
		//ビットシフトは1回左シフト(<<)で2倍，1回右シフト(>>)で0.5倍
		a[i++]=num%2;
		num=num>>1;
	}
}
int main(void)
{
	int n, k, ans, min=99999999, a[10], max;

	cin>>n>>k;

	for(int i=0; i<1<<n; i++){
		ans=1;
		for(int j=0; j<10; j++){
			a[j]=0;
		}
		number_split_2adic(i, a);
		for(int j=0; j<n; j++){
			if(a[j]){
				ans=ans<<1;
			}else{
				ans+=k;
			}
		}
		if(ans<min) min=ans;
	}
	cout<<min<<endl;
}


Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

list_mass =  list(sys.stdin.readline().rstrip())

#print(list_math)

cnt = 0

#for i in (len(list_mass)):
for i in list_mass:
    #if(list_math[i] == '1'):
    if(i == '1'):
        cnt += 1

print(cnt)


Measured memory_bytes: 5076
n = int(input())
h = list(map(int , input().split()))
for i in range(1,n):
    if h[i-1] < h[i]:
        h[i] -= 1
    elif h[i-1] > h[i]:
        print("No")
        break
    if i == n-1:
        print("Yes")
if n == 1:
    print("Yes")

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a=0;
	string s;
	map<string,int> m;
	cin>>n;
	while(n--){cin>>s; sort(s.begin(),s.end()); a+=m[s]++;}
	cout<<a;
}

Measured memory_bytes: 11136
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<cctype>
#include<cassert>
#include<cmath>
#include<climits>

#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define D(x) cout << #x " is " << (x) << endl
#define rep(i,n) for(int i = 0; i < n; i++)
#define x first
#define y second

using namespace std;

typedef pair<int,int>pii;
typedef long long ll;

int dp[1001][1001];

int main(void){

  int n;
  cin >> n;

  vector<pii>v(n);
  rep(i,n)cin >> v[i].x >> v[i].y;


  fill(dp[0],dp[1001],INT_MAX);
  rep(i,1001)dp[i][i]=0;

  for(int w=0;w<n;w++){
    for(int i=0;i+w<n;i++){
      for(int s=i;s<i+w;s++){
        int cost=abs(v[i].x-v[s+1].x)+abs(v[s].y-v[i+w].y);
        dp[i][i+w]=min(dp[i][i+w],dp[i][s]+dp[s+1][i+w]+cost);
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 5112
import sys
import itertools

cin = sys.stdin
# cin = open("in.txt", "r")


def line2N():
    return map(int, cin.readline().split())


N, M = line2N()
if M==0:
    print(0)
    exit(0)
x = [0] * N
y = [0] * N
z = [0] * N
for i in range(N):
    x[i], y[i], z[i] = line2N()

rMax = 0
for sx, sy, sz in itertools.product((-1,1), repeat=3):
    s = [sx * xi + sy * yi + sz * zi for xi, yi, zi in zip(x, y, z)]
    s.sort()
    rMax = max(rMax, sum(s[-M:]))

print(rMax)


Measured memory_bytes: 3188
from collections import defaultdict as ddic
from collections import deque
from itertools import combinations, permutations, product
import bisect
import heapq
import math
import sys

stdout = sys.stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))

a = rri()
b = rri()
c = rri()
d = rri()
e = rri()

lst = [[a,-1],[b,-1],[c,-1],[d,-1],[e,-1]]

lst2 = []

for i, num in enumerate(lst):
    lst[i][1] = num[0] % 10

lst.sort(key=lambda arr: arr[1])

for i, l in enumerate(lst):
    if l[1] != 0:
        if i == 4:
            d1 = [item[0] for item in lst]
            print(sum(d1))
            quit()
        else:
            for j, k in enumerate(lst[i+1:]):
                lst[i+j+1][0] += (10 - lst[i+j+1][1])

            d2 = [item[0] for item in lst]
            print(sum(d2))
            quit()

print(sum([a,b,c,d,e]))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 100003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v , ll a = 0)
{
    //ll a ;
    for(ll i=a ; i<v.size() ; i=i+1)
    {
        v[i] = max((ll)0,v[i]);
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
/*vbool isprime(N,true);
vll spf(N,0);
vll prime;
void sieve()
{
    isprime[0] = isprime[1] = false;
    for(ll i = 2 ; i<N ; i++)
    {
        if(isprime[i])
        {
            for(ll j=2*i ; j<N ; j+=i)
            {
                isprime[j] = false;
                if(spf[j]==0)
                {
                    spf[j] = i;
                }
            }
            prime.pb(i);
        }
    }
}*//*
ll nck(ll n , ll k ,ll m=1e18+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}*//*
long long power(long long k , long long n , long long m=mod)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}*/
ll n,m,k,l,r;
bool ok = false;
ll dp[N][6];
int main()
{
    FastIO ;
    PRECISION ;
    ll a,b,c,d,i,j,t,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    cin>>str;
    if(str[0]=='7' || str[1]=='7' || str[2]=='7')
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No";
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int n, r[20005];

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		int x;
		cin >> x;
		r[x] = i;
	}
	for(int i=1; i<=n; i++){
		printf("%d ", 30000 * i);
	}
	puts("");
	for(int i=1; i<=n; i++){
		printf("%d ", 30000 * (n + 1 - i) + r[i]);
	}
puts("");
}


Measured memory_bytes: 640
N = int(input())
items = []

for i in range(N):
    s, p = [v for v in input().split()]
    dic = {'city':str(s), 'score':-int(p), 'index':i+1}
    items.append(dic)

sorted_items = sorted(items, key = lambda x: (x['city'], x['score']))
for s in sorted_items: print(s['index'])



Measured memory_bytes: 3060
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}
fn main() {
    let n: usize = read()[0];
    let v: Vec<Vec<Vec<usize>>> = (0..n)
        .map(|_| {
            let m: usize = read()[0];
            (0..m).map(|_| read()).collect()
        })
        .collect();

    let mut ans: usize = 0;
    for i in 0..2_usize.pow(n as u32) {
        let b: Vec<usize> = format!("{:0>1$b}", i, n)
            .chars()
            .map(|x| x.to_digit(10).unwrap() as usize)
            .collect();
        let mut res = true;
        let cnt = b.iter().filter(|&&x| x == 1).count();
        if cnt <= ans {
            continue;
        }

        for j in 0..n {
            if b[j] == 0 {
                continue;
            }
            if v[j].iter().all(|q| b[q[0] - 1] == q[1]) {
                continue;
            }

            res = false;
            break;
        }

        if res {
            ans = std::cmp::max(ans, cnt);
        }
    }
    println!("{}", ans);
}


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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(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())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << endl;

    return 0;
}


Measured memory_bytes: 256