akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;

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

rep(i,m){ 
    int a,b;
    cin >> a >> b;
    --a;--b;
    
    G[a].push_back(b);
    G[b].push_back(a);
    }

    vector<int> dist(n, INF); 
    queue <int> que;
    vector<int> pre(n,-1);

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;

    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        //cout << v << endl;
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            //cout << v << ':';
            //cout << nv << "  ";
            if (dist[nv] != INF) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            //cout << dist[v] << " " << dist[nv] << endl; 
            //cout << v << endl;
            pre[nv]=v;
            //cout << pre[nv] << endl;
            que.push(nv);
            //cout << endl;
        }
    }
    bool ok=true;
    for (int d:dist) if (d == -1) ok = false;
    
    if(ok){
    cout << "Yes" << endl;
    for (int v = 1; v < n; ++v) {
        // int ans = pre[v];
        // ++ans;
        cout << pre[v]+1 << endl;
    }
    }else cout << "No" << endl;
}



Measured memory_bytes: 10728
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int l=0;int r=1000000000;
  while(r-l>1){
    int m=(r+l)/2;
    auto f=[&](int x){
      int64_t cnt=0;
      for(int i=0;i<N;i++){
        cnt+=(A[i]-1)/x;
      }
      if(cnt<=K){return true;}
      else {return false;}
    };
    if(f(m)==true){r=m;}
    else{l=m;}
  }
  cout<<r<<endl;
  return 0;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,M;
	cin>>N>>M;
    string ans = "";
    if(N==1){
        ans +="n";
    }
    else{
        rep(i,N){
            if(i==0){
                ans+="n";
            }else{
                ans+="n";
            }
        }
    }
    
    // cout<<ans<<"\n";
    char c;
    ll s;
    rep(i,M){
        cin>>s>>c;
        if(ans[s-1]!='n'&& ans[s-1]!=c){
            cout<<-1<<"\n";
            return 0;
        }else{
            ans[s-1] = c;
        }
    }
	rep(i,ans.length()){
        if(ans[i]=='n'){
            if(i==0&&N!=1){
                ans[i] = '1';
            }else{
                ans[i] = '0';
            }
        }
    }
    if(ans[0]=='0'&&N!=1){
        cout<<-1<<"\n";
        return 0;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,K; cin >> N >> K;
    char D[K]; rep(i,K) cin >> D[i];
    for(int i=N;i<100000;i++){
        string s=to_string(i);
        bool can = true;
        rep(j,s.size()){
            rep(k,K){
                if(s[j]==D[k]){
                    can=false; break;
                }
            }
            if(!can) break;
        }
        if(can) {cout << i << endl; break;}
    }

    return 0;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	char a;
	string s;
	cin >> s;
	a = s[0];
	for(int i = 1; i < 4; i++){
		if(a == s[i]){
			cout << "Bad";
			return 0;
		}
		a = s[i];
	}
	cout << "Good";
}

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

using namespace std;
using ll = long long;


int main()
{
    ll l, r; cin >> l >> r;
    ll nin = 1e9;
    if(r - l <= 3000) {
        for(ll i = l; i <= r; i++) {
            for(ll j = i + 1; j <= r; j++) nin = min(nin, i * j % 2019);
        }
        cout << nin << endl;
    }else {cout << 0 << endl;}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;


int main(){
	string S;cin >> S;
	bool ok = true;
	if(S[0] == 'A') S[0] = 'a';
	else ok = false;
	int tmp = 0;
	for(int i = 2; i < S.size() - 1; i++){
		if(S[i]=='C'){
			S[i] = 'c';
			tmp++;
		}
	}
	if(tmp!=1) ok = false;
	rep(i,S.size()){
		if(S[i] >= 'A' && S[i] <= 'Z') ok = false;
	}
	if(ok) cout << "AC" << endl;
	else cout << "WA" << endl;
	return 0;



}










Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
	
ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}
int main()
{
	string s;
	cin>>s;
	rep(i,4){
		cout<<s[i];
	}
	cout<<" ";
	rep(i,8){
		cout<<s[i+4];
	}
	cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        int[] a = new int[n], b = new int[n];
        for(int i = 0; i < n; i++) a[i] = scanner.nextInt();
        for(int i = 0; i < n; i++) b[i] = scanner.nextInt();
        PriorityQueue<Pair> queue = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
            queue.offer(new Pair(b[i], i));
        }
        long ans = 0;
        while(!queue.isEmpty()) {
            Pair curr = queue.poll();
            int cur = curr.b;
            if (b[cur] < a[cur]) {
                out.println(-1);
                out.flush();
                return;
            }
            else if (b[cur] == a[cur]) continue;
            int ne = (cur + 1) % n;
            int p = (cur -1 + n) % n;
            int val = b[ne] + b[p];
            if (b[cur] <= val) {
                out.println(-1);
                out.flush();
                return;
            }
            if ((b[cur] - a[cur]) % val == 0) {
                ans += (b[cur] - a[cur]) / val;
                b[cur] = a[cur];
            }
            else {
                ans += b[cur]/(val);
                b[cur] %= val;
                queue.offer(new Pair(b[cur], cur));
            }
        }
        out.println(ans);
        out.flush();
    }
    static class Pair implements Comparable<Pair>{
        int a, b;
        public Pair(int aa, int bb) { a = aa; b = bb;}
        public int compareTo(Pair o) {
            if (a == o.a) return o.b-b;
            return o.a - a;
        }
    }

    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 71372
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int x;
  cin>>x;

  lint result=0;
  for(int i=0;i*500<=x;i++){
    int five=(x-i*500)/5;
    assert(five>=0);
    lint tmp_result=i*1000+5*five;
    UpdateMax(result,tmp_result);
  }
  cout<<result<<endl;

  return 0;
}




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

int main(){
  int A , B , X ; 
  cin >> A >> B >> X ;
  
  if(A + B >= X && X >= A ){
    cout << "YES" << endl ; 
  }
  else{
    cout << "NO" << endl ; 
  }
  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream&o,const pair<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
template<typename T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

void RE(){cout<<1/0;}
void TLE(){sleep(100);}
void WA(){cout<<char(0);exit(0);}

const int N = 1e5;
int n, k;
V<int> e[N];
ll ans = 1;
void dfs(int a, int p){
  int g = k-2;
  for(int b:e[a]) if(p != b){
    ans = ans * g % MOD;
    dfs(b, a);
    g--;
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if(n==1){
    cout << k << endl;
    return 0;
  }
  FOR(_, 1, n){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  FOR(i, 0, n) if(sz(e[i])==1){
    dfs(e[i][0], i);
    cout << ans * k % MOD * (k-1) % MOD << endl;
    return 0;
  }
}

Measured memory_bytes: 12032
n,m = map(int,input().split())
mod = 10**9+7

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

"""
A(x+2y)+B(2x+y) = nx + my
答えは(A+B)CA

xについて
A+2B = n
yについて
2A + B = m

Aは
A = (2m-n)/3
Bは
B = (2n-m)/3
AとBが正の整数で存在しなければ0

"""
A = (2*m-n)/3
B = (2*n-m)/3

if A%1!=0 or B%1!=0 or A<0 or B<0:
    print(0)
    exit()
ans = 1
A,B = int(A),int(B)
for i in range(1,A+B+1):
    ans = ans*i%mod
for i in range(1,A+1):
    ans = ans*mod_inv(i,mod)%mod
for i in range(1,B+1):
    ans = ans*mod_inv(i,mod)%mod
print(ans)

Measured memory_bytes: 41820
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
   
    int n;
    cin >> n;

    vector<int>a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
        if (!i)continue;
        a[i] += max(b[i - 1], c[i - 1]);
        b[i] += max(a[i - 1], c[i - 1]);
        c[i] += max(a[i - 1], b[i - 1]);
    }

    cout << max(a[n - 1], max(b[n - 1], c[n - 1])) << endl;

    return 0;

}

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

using namespace std;
#ifndef localfile
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #pragma GCC optimize("unroll-loops")
#endif
#define int long long
#define x first
#define y second
typedef pair<int, int> pii;
vector<int> g[1009];

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

    int  k, a, b;
    cin >> k >> a >> b;

    if (b - a <= 1) {
        cout << 1 + k;
    }

    else {
        if (k < a - 1) {
            cout << 1 + k;
            return 0;
        }

        k -= (a - 1);
        int curr = a;
        cout << curr + (b - a) * (k / 2) + k%2;
    }

    return 0;
}




Measured memory_bytes: 256
#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 = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  rep(i,n) cin >> v[i];
  rep(i,n) cin >> c[i];

  int ans = 0;
  rep(i,n){
    if(v[i] - c[i] >= 0) ans += v[i] - c[i];
  }
  cout<<ans<<endl;
  return 0;
}

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

diffs = list()
max_diff = 0
for i in range(n):
    diff = 0
    if i == n-1:
        diff = k + a[0] - a[i]
    else:
        diff = a[i+1] - a[i]

    if max_diff < diff:
        max_diff = diff
    diffs.append(diff)

print(sum(diffs) - max_diff)

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

struct node {
	int id = 0;
	int k = 0;
	vector<int> c;
	int parent = -1;
	int child = 0;
	int depth = 0;
	int name = 0;
	vector<int> hukasa;
};

node a[100000];

int parent(node c) {
	return c.parent;
}

int soya(node b,int n) {
	int y = 0;
    if (a[b.parent].child != 0) y++;
	int t = a[b.parent].parent;
	while (t != -1) {
		y++;
		t = parent(a[t]);
	}
	return y;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		a[num].id = num;
		cin >> a[num].k;
		if (a[num].k == 0) a[num].name = 1;
		else {
			for (int j = 0; j < a[num].k; j++) {
				int x;
				cin >> x;
				a[num].c.push_back(x);
				a[x].parent = num;
			}
			a[num].child = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i].parent == -1) a[i].depth = 0;
		else a[i].depth = soya(a[i], n);
	}

	for (int i = 0; i < n; i++) {
		cout << "node" << " " << i << ": " << "parent = " << a[i].parent << ", " << "depth = " << a[i].depth << ", ";
		if (a[i].parent == -1) cout << "root";
		else if (a[i].name == 1) cout << "leaf";
		else cout << "internal node";
		cout << ", [";
		for (int j = 0; j < a[i].k; j++) {
			if (j > 0) cout << ", ";
			cout << a[i].c[j];
		}
		cout << "]" << endl;
	}

	return 0;
}

/*4
1 3 3 2 0
0 0
3 0
2 0*/


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define Si size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define Em empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define Fi first
#define Se second
#define Pi acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>

void FAST();
LL big_mod(LL val,LL pow,LL mod);
LL mod_inverse(LL val,LL mod);







V<int>v;
int a[22];

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int b,i,n;
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for(i=1;i<=n;i++)
    {
        cin >> b;
        v.PSB(a[i]-b);
    }
    sort(v.B,v.E);
    int ans=0;
    for(i=(v.Si)-1;i>=0;i--)
    {
        if(v[i] > 0)
        {
            ans+=v[i];
        }
        else
        {
            break;
        }
    }
    cout << ans;
    return 0;
}







void FAST()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL mod_inverse(LL val,LL mod)
{
    LL mod1 = mod;
    if(mod == 1)
    {
        return 0;
    }
    LL y = 0;
    LL x = 1;
    LL quotient,temp;
    while(val > 1)
    {
        quotient = val / mod;
        temp = mod;
        mod = val % mod;
        val = temp;
        temp = y;
        y = x - quotient * y;
        x = temp;
    }
    if(x < 0)
    {
        x += mod1;
    }
    return x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, x, l, curl, ans;
pair<long long, long long> r[100005];
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=0; i<n; i++){
	cin >> x >> l;
	r[i]=make_pair(x+l, x-l);
} sort(r, r+n); curl=-1234567890LL;
for (int i=0; i<n; i++){
	if (r[i].second>=curl){
		ans++;
		curl=r[i].first;
	}
} cout << ans;
return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()

{
    
    int ara[3] , sum = 0 ;
    
    for(int a=0; a<3;a++)  {
        
        scanf("%d",&ara[a]) ;
        
        sum += ara[a] ;
        
    }
    
    int low = ara[0] , high = 0 , mid ;
    
    for( int b = 0 ; b < 3 ; b++ )  {
        
        if( ara[b] > high )  {
            
            high = ara[b] ;
            
        }
        
        if( ara[b] < low )  {
            
            low = ara[b] ;
            
        }
        
    }
    
    //printf("%d %d %d",low,high,sum-low-high) ;
    
    mid = sum - low - high ;
    
    int answer = high - mid + mid - low ;
    
    printf("%d\n",answer) ;
    
    return 0 ;
    
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans = 0;
    if(a>b){
      ans=0;
    }else if(n==1){
        if(a!=b)ans=0;
        else{ans=1;}
    }else {
        ll nn = n-2;
        ll ma = nn*b+a+b;
        ll mi = nn*a+a+b;
        ans = ma-mi+1;


    }
    cout<<ans<<endl;



    return 0;
}


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

int main()
{
    int  n = 0,a=0,b=0,c=0,d=0,i=0,j=0,k=0;
    cin >> n;
    int x[10][3][4]={};
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                x[k][j][i]={};
            }
        }
    }

        for(i=0;i<n;i++){
            cin >> a >> b >> c >> d;
            x[c-1][b-1][a-1]+=d;
            }


        for(i=0;i<4;i++){
            for(j=0;j<3;j++){
                for(k=0;k<10;k++){
                    cout << ' ' << x[k][j][i];
                }
                cout << endl;
            }
            if(i<3){
            cout << "####################" << endl;
            }
        }




    //cout << endl;

return 0;

}

Measured memory_bytes: 1164
import numpy as np
D, N = map(int, input().split())

def cnt(n):
    tmp = 0
    n = n*1.0
    while n.is_integer():
        if (n/100.0).is_integer():
            tmp += 1
            n = n / 100.0
        else:
            break
            
    return tmp

coef = 100**D
whole = np.array([i*coef for i in range(1, 150)])
result = np.array(list(map(cnt, whole)))

print(whole[np.where(result==D)][N-1])

Measured memory_bytes: 20524
n = int(input())
a = list(map(int, input().split()))
b = [0]*n
ans = 0

for i in range(n):
    b[a[i] - 1] += 1

for i in range(n):
    ans += b[i]*(b[i] - 1)//2

for i in range(n):
    print(ans - b[a[i] -1] + 1)

Measured memory_bytes: 26012
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N;
ll A[100100],B[100100];
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i];
	}
	ll acc = 0ll;
	for(int i=N-1;i>=0;i--){
		ll rem = (A[i]+acc)%B[i];
		if(rem>0ll)rem = B[i]-rem;
		acc += rem;
	}
	cout << acc << endl;	
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
bool check(vector< vector< int > > &A, int k) {
	vector< int > idx(N, 0);
	vector< int > num(M, 0);
	vector< bool > used(M, false);
	while (1) {
		num.assign(M, 0);
		rep(i, N) {
			int j = A[i][idx[i]];
			while (used[j]) {
				j = A[i][++idx[i]];
				if (j >= M)
					return false;
			}
			num[j]++;
		}
		int maxn = 0, maxnj = -1;
		rep(j, M) if (chmax(maxn, num[j])) maxnj = j;
		used[maxnj] = true;
		if (maxn <= k)
			return true;
		rep(i, N) {
			if (A[i][idx[i]] == maxnj) {
				idx[i]++;
				if (idx[i] >= M)
					return false;
			}
		}
	}
}
signed main() {
	cin >> N >> M;
	vector< vector< int > > A(N, vector< int >(M));
	rep(i, N) rep(j, M) {
		cin >> A[i][j];
		--A[i][j];
	}
	int l = -1,
		r = 310;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(A, m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    int n;cin>>n;
    int ma=0;
    int mi=1001;
    int a;
    rep(i,0,n){
        cin>>a;
        mi=min(a,mi);
        ma=max(a,ma);
    }
    cout<<ma-mi;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000;

ll dp[100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	ll A, B;
	cin >> N >> A >> B;
	vector<int> X(N);
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 1; i < N; i++) dp[i] = INF;
	for (int i = 1; i < N; i++) {
		dp[i] = dp[i - 1] + min(A * (X[i] - X[i - 1]), B);
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <stdint.h>
#include <cstring>
using namespace std;
int main(void) {
	string str;
	cin >> str;
	bool N = false, W = false, S = false, E = false;
	N = str.find("N") != string::npos;
	W = str.find("W") != string::npos;
	S = str.find("S") != string::npos;
	E = str.find("E") != string::npos;
	if (N == S && W == E)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    int k;
    cin >> k;
    queue<ll> q;
    rep(i,9){
        q.push(i+1);
    }
    
    while(1){
        if(k<=q.size()){
            rep(i,k-1) q.pop();
            cout << q.front() <<endl;
            return 0;
        }
        ll hd=q.front(); q.pop();
        ll x=hd%10;
        ll cnt;
        if(x==0){
            q.push(hd*10);
            q.push(hd*10+1);
            cnt=2;
        }
        else if(x==9){
            q.push(hd*10+8);
            q.push(hd*10+9);
            cnt=2;
        }
        else{
            q.push(hd*10+x-1);
            q.push(hd*10+x);
            q.push(hd*10+x+1);
            cnt=3;
        }
        k--;


    }

    return 0;
}

Measured memory_bytes: 3848
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

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

    vector<ll> Height(n);
    rep(i, n) {
        cin >> Height[i];
    }

    vector<ll> losers;

    rep(i, m) {
        ll a, b;
        cin >> a >> b;

        if (Height[a - 1] < Height[b - 1]) {
            losers.push_back(a);
        } else if (Height[a - 1] > Height[b - 1]) {
            losers.push_back(b);
        } else {
            losers.push_back(a);
            losers.push_back(b);
        }
    }
    sort(losers.begin(), losers.end());
    losers.erase(unique(losers.begin(), losers.end()), losers.end());


    // for (auto l : losers) {
    //     cout << l << endl;
    // }
    // cout << endl;


    cout << n - losers.size();
    return 0;
}


Measured memory_bytes: 4696
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 110;

char str[MAXN];

int main(){
	scanf("%s", str + 1);
	if(str[1] == 'S' && str[2] == 'U' && str[3] == 'N'){
		printf("7\n");
		return 0;
	}else if(str[1] == 'M' && str[2] == 'O' && str[3] == 'N'){
		printf("6\n");
		return 0;
	}else if(str[1] == 'T' && str[2] == 'U' && str[3] == 'E'){
		printf("5\n");
		return 0;
	}else if(str[1] == 'W' && str[2] == 'E' && str[3] == 'D'){
		printf("4\n");
		return 0;
	}else if(str[1] == 'T' && str[2] == 'H' && str[3] == 'U'){
		printf("3\n");
		return 0;
	}else if(str[1] == 'F' && str[2] == 'R' && str[3] == 'I'){
		printf("2\n");
		return 0;
	}else if(str[1] == 'S' && str[2] == 'A' && str[3] == 'T'){
		printf("1\n");
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            lstInp.Sort();                                          // 昇順
            int iCnt = lstInp.Count / 2;
            if (lstInp[iCnt - 1] != lstInp[iCnt])                   // 真ん中の２つが同じ値の時は分けられない
            {
                iOut = lstInp[iCnt] - (lstInp[iCnt - 1] + 1) + 1;   // 真ん中の２つの小さい方+1以上、大きい方以下の間の数が求める値
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 19168
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    string s;
    cin >> s;
    string ans;
    for (const char ch : s)
    {
        if (ch == ',')
        {
            ans.push_back(' ');
        }
        else
        {
            ans.push_back(ch);
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {

    int n; cin >> n;
    const int p = 8;
    vector<bool> num(p, false);
    int freeCnt = 0;
    for (int i = 0; i < n; i++) {
        int rate; cin >> rate;
        for (int j = 0; j <= p; j++) {
            if (400 * j <= rate && rate <= 400 * (j + 1) - 1 && j < p ) {
                num[j] = true;
            }
            else if (400 * j <= rate && j == p) {
                freeCnt++;
            }
        }
    }


    int cnt = 0;
    for (int i = 0; i < p; i++) {
        if (num[i]) cnt++;
    }
    
    int minCnt;
    if (cnt == 0) minCnt = 1;
    else minCnt = cnt;

    int maxCnt = cnt + freeCnt;

    cout << minCnt << " " << maxCnt << 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 d=sc.nextInt();
		int a,sum=0;
		for(int i=0;i<d;i++)
		{
			a=sc.nextInt();
		
			int count = 0;
			while(a%2==0)
			{
				a=a/2;
				count++;
			}
			sum+=count;
		}
		System.out.println(sum);
		
	}
}

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

using ll = long long;
static const ll MOD = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  vector<vector<ll>> dp(c + 1, vector<ll>(d + 1, 0));
  dp[a][b] = 1;
  
  for (ll i = a + 1; i <= c; i++) {
    dp[i][b] = (dp[i - 1][b] * b) % MOD;
  }
  
  for (ll j = b + 1; j <= d; j++) {
    dp[a][j] = (dp[a][j - 1] * a) % MOD;
  }
  
  for (ll i = a + 1; i <= c; i++) {
    for (ll j = b + 1; j <= d; j++) {
      dp[i][j] = ((dp[i][j - 1] * i + dp[i - 1][j] * j) % MOD - dp[i - 1][j - 1] * (i - 1) * (j - 1) + MOD * MOD) % MOD;
    }
  }
  
  cout << dp[c][d] << '\n';
}

Measured memory_bytes: 73616
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        String a1 = sc.next();
        String b1 = sc.next();
        
        BigInteger a2 = new BigInteger(a1);
        BigInteger b2 = new BigInteger(b1);
        
        BigInteger c  = a2.subtract(b2);

        if(  a2.compareTo(b2) > 0) { System.out.print("GREATER");}
        else if( a2.compareTo(b2) == 0) {      System.out.print("EQUAL");}
        else    {                          System.out.print("LESS");}
        

        System.out.println();
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
n,k,q  = gets.split.map(&:to_i)


threshold = q - k
scores = Array.new(n, 0)

q.times { scores[gets.to_i - 1] += 1 }

scores.each do |i|
    if i > threshold
        puts "Yes"
    else
        puts "No"
    end
end



Measured memory_bytes: 3196
#include<iostream>
using namespace std;
int main()
{
  long long t;
  cin>>t;
  long long fivehundred=0;
  long long five=0;
  while( t>=500 )
  {
    t-=500;
    fivehundred+=1000;
  }
   while( t>=5 )
  {
    t-=5;
    five+=5;
  }
  cout<<fivehundred+five;
return 0;
}

Measured memory_bytes: 256
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
 const int N=2e5+ 5;
 const ll N1=1e15 + 5;

using namespace std;

//check for corner cases(for n==1)
// check for int overflow
// run on some sample cases before submitting



int main()
{
  fast;
   ll a[5];
   for(int i=0;i<5;i++)cin>>a[i];

   ll in=-1;
   for(int i=0;i<5;i++)
   {
       if(a[i]==0)
       {
           in=i;
           break;
       }
   }
   cout<<in+1<<endl;




}





Measured memory_bytes: 3608
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
#define M 1000000007
#define boost
#define push_back push
#define pop_back pop
#define fo(i,n)   for (size_t i = 0; i < n; i++)
#define fo1(i,n)   for (size_t i = 1; i <= n; i++)
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}
int price[100001];
int dp[100001];

int cost(int x){
    
    if(x==1)
    return dp[x]=0;

    if(x==2)
   return dp[x]= abs(price[2]-price[1]);

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

 else
return dp[x]= std ::min(cost(x-1)+ abs(price[x]-price[x-1]),cost(x-2)+abs(price[x]-price[x-2])) ;
   
   
}
//ll T;

int main()
{  
   /* ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
      for(read(T);T;--T)*/
   {
    memset(dp,-1,sizeof(dp));
    int n ; read(n);

    fo1(i,n)
    read(price[i]);

    cout<<cost(n);
   }

return 0;
}

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

using namespace std;
 
const int MAX = 1000001;
int factor[MAX] = {0};

void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    for (int i = 3; i * i < MAX; i++) { 
         
        if (factor[i] == i) { 
            for (int j = i * i; j < MAX; j += i) { 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 

int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
   
    int dup = factor[n]; 
   
    int c = 1; 
  
    int j = n / factor[n]; 
  
     
    while (j != 1) { 
        
        if (factor[j] == dup) 
            c += 1; 
  
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
   
        j = j / factor[j]; 
    } 
  
    ans = ans * (c + 1); 
  
    return ans; 
} 

int main() {

	int n;
	cin>>n;

	long long int count = 0;

	generatePrimeFactors();

	for(int i=n-1; i>=1; i--) {

		count += calculateNoOFactors(i);
	}

	cout<<count<<endl;

	return 0;
}

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

int main(){
    string SS, T;
    cin >> SS >> T;
    reverse(SS.begin(), SS.end());
    reverse(T.begin(), T.end());
    bool can = false;
    if (SS.size() < T.size()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for (int i = 0; i <= SS.size() - T.size(); i ++){
        int j = 0;
        while (SS.at(i + j) == '?' || SS.at(i + j) == T.at(j)){
            //cout << "i " << i << " j " << j << endl;
            if (j == T.size() - 1){
                //cout << "OK" << endl;
                SS.replace(i, j + 1, T);
                can = true;
                break;
            }
            else{
                j++;
                if (i + j == SS.size()) break;
            }
            
            
        }
        if(can) break;
    }
    
    if(can){
        for (int i = 0; i < SS.size(); i++){
            if (SS.at(i) == '?'){
                SS.replace(i, 1, "a");
            }
        }
        reverse(SS.begin(), SS.end());
    }
    else{
        SS = "UNRESTORABLE";
    }
    
    cout << SS << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)

using namespace std;
using namespace __gnu_pbds; 

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    if(a.ss==b.ss)return a.ff<b.ff;
    return a.ss < b.ss;
}

typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 

int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k,V=0,W=0;
    cin>>n>>k;
    vpll v(n);
    from(i,n){
        ll a,b;
        cin>>a>>b;
        v[i]=mb(a,b);
        V+=b;
        W+=a;
    }
    if(k>=W)cout<<V;
    else {
    	ll ar[n+1][V+1];
        ll ans=0;
        from(i,n+1)ar[i][0]=0;    
        for(int i=1;i<V+1;i++)ar[0][i]=INT_MAX;
        for(ll i=1;i<n+1;i++){
            for(ll j=1;j<V+1;j++){
                if(v[i-1].ss<=j)ar[i][j]=min(ar[i-1][j],v[i-1].ff+ar[i-1][j-v[i-1].ss]);
                else ar[i][j]= ar[i-1][j];
            }
        }
        for(ll i=0;i<n+1;i++){
            for(ll j=0;j<V+1;j++)
                if(ar[i][j]<=k)ans=max(ans,j);
        }
        cout<<ans;
    }
}    


Measured memory_bytes: 81788
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, K;

int main(void){
    
    scanf("%d %d", &N, &K);
    printf("%d\n", (N % K == 0) ? 0 : 1);
    
    return 0;
}


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

const int mod = 1e9+7;

vector<string> split(string s){
  vector<string> res;
  string tmp;
  rep(i,s.size()){
    if(isalpha(s[i]))tmp += s[i];
    else if(s[i] == ' '){
      res.push_back(tmp);
      tmp = "";
    }
  }
  res.push_back(tmp);
  return res;
}

int n;
int a,t,g,c,m;
map<string,int> id;
vector<string> rule[55];

void parse(int cur, vector<int> &seq){
  for(string s : rule[cur]){
    if((int)seq.size()>n)return;
    if(isupper(s[0])){
      int k = 0;
      rep(i,s.size()){
	if(s[i] == 'A')k |= 1<<0;
	if(s[i] == 'T')k |= 1<<1;
	if(s[i] == 'G')k |= 1<<2;
	if(s[i] == 'C')k |= 1<<3;
      }
      seq.push_back(k);
    }else parse(id[s],seq);
  }
}

int dp[2][55][55][55];

int main(){
  cin >> a >> t >> g >> c >> m; cin.ignore();
  n = a+t+g+c;

  rep(i,m){
    string s;
    getline(cin,s);

    vector<string> vs = split(s);
    id[vs[0]] = i;
    rep(j,vs.size()-1)rule[i].push_back(vs[j+1]);
  }

  vector<int> seq;
  parse(0,seq);
  if((int)seq.size()!=n){
    cout << 0 << endl;
    return 0;
  }

  dp[0][0][0][0] = 1;
  rep(i,n){
    int cur = i&1, nxt = 1-cur;
    rep(A,a+1)rep(T,t+1)rep(G,g+1)dp[nxt][A][T][G] = 0;

    rep(A,a+1)rep(T,t+1)rep(G,g+1){
      if(seq[i]&1 && A+1<=a){
	(dp[nxt][A+1][T][G] += dp[cur][A][T][G]) %= mod;
      }
      if((seq[i]>>1)&1 && T+1<=t){
	(dp[nxt][A][T+1][G] += dp[cur][A][T][G]) %= mod;
      }
      if((seq[i]>>2)&1 && G+1<=g){
	(dp[nxt][A][T][G+1] += dp[cur][A][T][G]) %= mod;
      }
      if((seq[i]>>3)&1 && i-A-T-G<=c){
	(dp[nxt][A][T][G] += dp[cur][A][T][G]) %= mod;
      }
    }
  }
  cout << dp[n&1][a][t][g] << endl; 
}

Measured memory_bytes: 2472