akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Red and Green Apples
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

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

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int x, y, a, b, c;
vector<pii> vec;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> x >> y >> a >> b >> c;
	REP(i, a) {
		int z;
		cin >> z;
		vec.pb({z, 1});
	}
	REP(i, b) {
		int z;
		cin >> z;
		vec.pb({z, 2});
	}
	REP(i, c) {
		int z;
		cin >> z;
		vec.pb({z, 0});
	}
	sort(vec.begin(), vec.end(), greater<pii>());
	int ileX = x, ileY = y, ileAll = 0;
	ll sum = 0;
	REP(i, a + b + c) {
		pii p = vec[i];
		if (p.nd == 0) {ileAll++; sum += p.st;}
		if (p.nd == 1 && ileX > 0) {
			ileX--;
			sum += p.st;
		}
		if (p.nd == 2 && ileY > 0) {
			ileY--;
			sum += p.st;
		}
		if (ileX + ileY == ileAll) break;
		//cout << p.st << " " << p.nd << endl;
	}
	cout << sum << endl;
	return 0;
}
 


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,p,n) for(int i=p;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

int N; cin >> N ;

vector<int> A(N); rep(i,N) cin>>A[i];

int j=0;
rep(i,N){
  if(A[i]==j+1) j++;
}

if(j==0) cout << -1 << endl;

else cout << N-j << endl;

return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		String[] pic = new String[a];

		for (int i = 0; i < a; i++) {
			pic[i] = sc.next();
		}
		
		for(int i=0; i<a; i++){
			System.out.println(pic[i]);
			System.out.println(pic[i]);
		}
	}

}


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

using ll = int;
const int maxn = (1 << 18) + 3, maxq = 1e5 + 3, maxl = 10, maxbl = 1 << maxl;

int n, q, v[maxn], w[maxn], blp[maxn], bc[maxn];
std::pair<ll, ll> bt[maxbl], bs[maxbl];

inline int calcBt(int s, std::pair<ll, ll> *b, bool sorted) {
    int l = bc[s];
    b[0].first = b[0].second = 0;
    for(int i = 0, u = s; i < l; ++i, u /= 2) {
        b[1 << i].first = w[u];
        b[1 << i].second = v[u];
    }
    for(int i = 3; i < (1 << l); ++i) {
        auto &bu = b[i - (i & -i)], &bv = b[i & -i];
        b[i].first = bu.first + bv.first;
        b[i].second = bu.second + bv.second;
    }
    if(sorted) {
        std::sort(b, b + (1 << l));
        for(int i = 1; i < (1 << l); ++i) {
            auto &bu = b[i].second, &bv = b[i - 1].second;
            if(bu < bv)
                bu = bv;
        }
        int bl = 0;
        for(int j = 0; j < (1 << l); ++j) {
            if(bl && b[bl - 1].first == b[j].first) {
                b[bl - 1].second = std::max(b[bl - 1].second, b[j].second);
            } else {
                b[bl++] = b[j];
            }
        }
        return bl;
    }
    return 1 << l;
}

inline int lbs(ll w, int bsl) {
    int l = 0, r = bsl;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if(bs[mid].first <= w)
            l = mid;
        else
            r = mid;
    }
    return l;
}

inline ll query(int u, ll l) {
    int bsl;
    if(blp[u]) {
        bsl = calcBt(blp[u], bs, true);
    } else {
        bsl = 1;
        bs[0].first = bs[0].second = 0;
    }
    int btl = calcBt(u, bt, false);
    ll ans = 0;
    for(int i = 0; i < btl; ++i) {
        auto &bu = bt[i];
        if(bu.first > l)
            continue;
        auto it = lbs(l - bu.first, bsl);
        ans = std::max(ans, bu.second + bs[it].second);
    }
    return ans;
}

void initBlp() {
    for(int i = 1; i <= n; ++i) {
        int &p = blp[i] = i, &c = bc[i] = 0;
        for(int j = 0; j < maxl && p; ++j) {
            if(p)
                c += 1;
            p /= 2;
        }
    }
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", v + i, w + i);
    }
    initBlp();
    scanf("%d", &q);
    for(int i = 0; i < q; ++i) {
        int u, l;
        scanf("%d%d", &u, &l);
        printf("%d\n", query(u, l));
    }
    return 0;
}

Measured memory_bytes: 7948
#if defined(LOCAL)
// #define RANDOM_TEST
#define PROBLEM_NAME "c"
const double _max_double_error = 1e-9;
#include "testutils.h"
#endif
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<int>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(b); a > l(c); a--)

#if defined(LOCAL)
bool local = true;
#define L(x...) debug(x)
#else
bool local = false;
#define L(x, ...) (x)
#endif
struct VoidStream { void operator&(std::ostream&) { } };
#define LOG !(local) ? (void) 0 : VoidStream() & cerr

void solve(istream& cin, ostream& cout) {
  l n, m;
  while (cin >> n >> m) {
    vll events;
    l last; cin >> last;
    l worst = 0;
    F(i, 0, n - 1) {
      l x; cin >> x;
      l to = x;
      if (to < last) to += m;
      worst += to - last;
      if (to - last > 1) {
        events.emplace_back(last + 1, 0); // add to active
        events.emplace_back(to, to - last - 1); // how much to remove
        events.emplace_back(last + 1 + m, 0); // add to active
        events.emplace_back(to + m, to - last - 1); // how much to remove
      }
      last = x;
    }
    sort(all(events));
    l active = 0;
    l bonus = 0;
    l answer = worst;
    l j = 0;
    l p = 0;
    while (j < events.size()) {
      l x = events[j].first;
      bonus += active * (x - p);
      answer = min(answer, worst - bonus);
      p = x;
      while (j < events.size() and events[j].first == x) {
        if (events[j].second) {
          bonus -= events[j].second;
          active--;
        } else {
          active++;
        }
        j++;
      }
    }
    cout << answer << lf;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


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

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> shrine(A); for (auto &x : shrine) cin >> x;
    vector<long long> temple(B); for (auto &x : temple) cin >> x;
    while (Q--) {
        long long x; cin >> x;
        long long ls, rs;
        if (shrine[0] > x) {
            ls = -1, rs = shrine[0] - x;
        } else if (shrine[A-1] < x) {
            ls = x - shrine[A-1], rs = -1;
        } else {
            int ok = 0, ng = A;
            while (ng - ok != 1) {
                int med = (ok + ng) / 2;
                if (shrine[med] < x) ok = med;
                else ng = med;
            }
            ls = x - shrine[ok], rs = shrine[ng] - x;
        }
        long long lt, rt;
        if (temple[0] > x) {
            lt = -1, rt = temple[0] - x;
        } else if (temple[B-1] < x) {
            lt = x - temple[B-1], rt = -1;
        } else {
            int ok = 0, ng = B;
            while (ng - ok != 1) {
                int med = (ok + ng) / 2;
                if (temple[med] < x) ok = med;
                else ng = med;
            }
            lt = x - temple[ok], rt = temple[ng] - x;
        }
        long long ans = 1e12;
        if (ls != -1 && lt != -1) ans = min(ans, max(ls, lt));
        if (rs != -1 && rt != -1) ans = min(ans, max(rs, rt));
        if (ls != -1 && rt != -1) ans = min(ans, (min(ls, rt) * 2 + max(ls, rt)));
        if (lt != -1 && rs != -1) ans = min(ans, (min(lt, rs) * 2 + max(lt, rs)));
        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
// **** WHEN THE GOING GETS TOUGH, THE TOUGH GETS GOING. ****
#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define ll             long double
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll              vector<int>
#define mll             map<ll,ll>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define md             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
void hi()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
void bye()
{
    #ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
    #endif
}

void solve()
{
    int n; cin>>n;
    ll p[n+5]={0};
    for(int i=0;i<n;i++) cin>>p[i+1];
    ll dp[n+5];
    memset(dp,0,sizeof(dp));
    dp[1]=p[1],dp[0]=1-p[1];
    for(int i=2;i<=n;i++)
    {
        dp[i]=dp[i-1]*p[i];
        for(int j=i-1;j>=1;j--)
            dp[j]=dp[j]*(1-p[i])+dp[j-1]*p[i];
        dp[0]*=(1-p[i]);
        //for(int j=0;j<=i;j++) cout<<dp[j]<<" "; cout<<"\n";
    }
    ll ans=0.0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[i];
    cout<<ps(ans,10)<<"\n";
}

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

Measured memory_bytes: 3900
#include<iostream>
#include<cmath>

using namespace std;

int main(){

  int n;
  cin >>n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];

  int res=4000001;
  for(int j=-100;j<=100;j++){
    int sum=0;
    for(int i=0;i<n;i++){
      sum+=(a[i]-j)*(a[i]-j);   
      
    }
    res=min(res,sum);
  }

  cout << res << endl;

}


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

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let n = read::<i64>();
  let mut dist: HashMap<i64, i64> = HashMap::new();
  let mut memo = vec![0; n as usize + 1];

  for i in 2..n + 1 {
    let mut x = i;
    for j in 2..i + 1 {
      while 1 < x && x % j == 0 {
        x /= j;
        memo[j as usize] += 1;
      }
    }
  }

  let mut ans: u64 = 1;

  for i in memo {
    if i != 0 {
      ans *= i + 1;
      ans %= 1000000007;
    }
  }

  println!("{:?}", ans % 1000000007);
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, k);
  vector<double> dp(max(k, n) + 1);
  for (int i = max(k, n); i >= 1; --i) {
    if (i >= k) {
      dp[i] = 1;
    } else {
      int ii = i + i;
      dp[i] = (ii >= k ? 1 : dp[ii]) / 2;
    }
  }
  double p = 0;
  for (int i = 1; i <= n; ++i) {
    p += dp[i] / n;
  }
  cout << setprecision(20);
  out(p);
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n,x; cin>>n>>x;
    vll m(n);
    REP(i,n){
        cin >>m[i];
        x -= m[i];
    }
    VSORT(m);
    cout<< n + x/m[0] <<endl;
    return 0;
}


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

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    
    long long N; cin >> N;
    long long divisor = 1;
    for (long long i = 2; i * i < N + 1; ++i) {
        if (N%i == 0)
            divisor = i;
    }cout << divisor + N/divisor - 2 << '\n';
    
    

    return 0;
}



Measured memory_bytes: 3664
from functools import reduce
import math
def lcm_base(x, y):
  return (x * y) // math.gcd(x, y)

def lcm(*numbers):
  return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

n,m = map(int, input().split())
a = list(map(int, input().split()))
a = [i//2 for i in list(set(a))]
nothing = False
cnt_common = -1
for i in a:
  cnt = 0
  while i % 2 == 0:
    i = i//2
    cnt += 1
  if cnt_common == -1:
    cnt_common = cnt
    continue
  if cnt_common != cnt:
    nothing = True
    break

b=lcm_list(a)
if nothing:
  print(0)
else:
  ans = (m-b)//(2*b) + 1
  print(max(ans,0))

Measured memory_bytes: 20548
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <time.h>
using namespace std;
typedef long long ll;

int main(void) {
    int n, d, x[100][100];
    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) cin >> x[i][j];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int v = 0;
            for (int p = 0; p < d; p++) v += pow(x[i][p] - x[j][p], 2);

            for (int p = 0; p < 1000; p++) {
                if (p * p == v) {
                    ans++;  break;
                }
                else if (p * p > v) break;
            }


        }
    }

    cout << ans << endl;

}
/*
g++ -std=c++14 _main.cpp
 */


Measured memory_bytes: 256
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------


S = input()
T = input()
ans = 0
for i in range(len(S)):
	if S[i] != T[i]:
		ans += 1

print(ans)


# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9680
N = int(input())
As = list(map(int,input().split()))
pattern = [0 for _ in range(N)]


for i in range(1,N+1)[::-1]:
    count = 0
    if i > N//2:
        pattern[i-1] = As[i-1]

    else:
        for j in range(2,N//i+1):
            count += pattern[i*j-1]
        if count % 2 == As[i-1]:
            pattern[i-1] = 0
        else:
            pattern[i-1] = 1
s = sum(pattern)
print(s)
if s:
    s = ""
    for i,e in enumerate(pattern):
        if e == 1:
            s += str(i+1)
            s += ' '

    print(s[:-1])


Measured memory_bytes: 10036
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		int min = Integer.MAX_VALUE;

		for(int i=0;i<=(S.length()-3);i++) {
			if(min > Math.abs(Integer.parseInt(S.substring(i, i+3))-753)) {
				min = Math.abs(Integer.parseInt(S.substring(i, i+3))-753);
			}
		}

		System.out.println(min);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main() {
	int n,x,tmp,tmp2;
	long long count = 0;
	cin >> n >> x;
	int b[n+1];
	cin >> tmp;
	b[0] = tmp;
	for (int i = 0; i < n-1; i++){
		cin >> tmp2;
		b[i+1] = tmp + tmp2;
		tmp = tmp2;
	}
	b[n] = tmp;

	for (int i = 0; i < n; i++){
		int diff = b[i] - x;
		if(diff > 0){
			count += diff;
			b[i] -= diff;
			b[i+1] -= diff;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    for (int i = 0; i < N; i++) {
        cin >> m.at(i);
    }
    SORT(m);
    X -= accumulate(ALL(m), 0);
    int ans = 0;
    while (true) {
        X -= m.at(0);
        if (X < 0) {
            break;
        } else if (X == 0) {
            ++ans;
            break;
        }
        ++ans;
    }
    cout << ans + N << endl;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    long long cnt=0;

    for(long long i=1; i<=n; i++) {

        cnt += (i&1);

    }

    cout << fixed << setprecision(12);

    cout << cnt / (long double)n << '\n';

    return 0;

}



Measured memory_bytes: 3776
#include<stdio.h>
#include<string.h>

int main(){
 int base;
 int n,i;
 int out;
 int score;
 char com[10];
 scanf("%d",&n);

 for(i=0;i<n;i++){

     out=0;
     score=0;
     base=0;
     while(out<3){
           scanf("%s",com);
           if(com[1]=='U'){
              out++;
              if(out==3)printf("%d\n",score);
           }
           else if(com[1]=='I'){
                   base++;
                   if(base==4){score++;base--;}
           }
           else if(com[1]=='O'){
                   score+=base+1;
                   base=0;
           }
     }

 }

 return 0;
}


Measured memory_bytes: 2040
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)

print(ans)
            

Measured memory_bytes: 69796
import java.util.Scanner;

public class Main {



	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		
		int X = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();
		
		// ケーキを買う
		X -= A;
		
		int count = 0;
		
		while(X >= B) {
			X -= B;
			count++;
		}
		
		System.out.println(X);
		
	}
}

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

template <std::uint_fast64_t Modulus>
class ModInt {
 private:
  using u64 = std::uint_fast64_t;

  u64 x;

 public:
  constexpr ModInt(const u64 x = 0) noexcept : x(x % Modulus){};
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    x += rhs.x;
    if (x >= Modulus) x -= Modulus;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (x < rhs.x) x += Modulus;
    x -= rhs.x;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    x = x * rhs.x % Modulus;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 n = Modulus - 2;
    while (n) {
      if (n & 1) *this *= rhs;
      rhs *= rhs;
      n /= 2;
    }
    return *this;
  }
  constexpr ModInt operator++(int) noexcept {
    ModInt y = *this;
    x += 1;
    return y;
  }
  constexpr ModInt operator--(int) noexcept {
    ModInt y = *this;
    x -= 1;
    return y;
  }
  constexpr bool operator==(const ModInt rhs) noexcept { return x == rhs.x; }
  constexpr bool operator!=(const ModInt rhs) noexcept { return x != rhs.x; }
  friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
    is >> rhs.x;
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
    os << rhs.x;
    return os;
  }
};

template <typename T>
class Combination {
 private:
  vector<T> f, invf;

 public:
  Combination(int n) : f(n + 1, 1), invf(n + 1, 1) {
    for (int i = 1; i < n + 1; i++) {
      f[i] = f[i - 1] * i;
    }
    invf[n] /= f[n];
    for (int i = n; i > 0; i--) {
      invf[i - 1] = invf[i] * i;
    }
  }

  // nCr
  T comb(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return f[n] * invf[r] * invf[n - r];
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  // B + i, A + i, min(H - A, W - B)
  using mint = ModInt<1000000007>;
  Combination<mint> comb(H + W);
  mint res = 0;
  for (int i = B; i < W; i++) {
    res += comb.comb(H - A - 1 + i, i) * comb.comb(W - 1 - i + A - 1, A - 1);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;
class Main{
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);
		int point, sum, num;
		while(scan.hasNext()){
			num = scan.nextInt();
			int[] search = new int[num + 1];
			point = 2;
			sum = 0;
			while(point <= num){
				if(search[point] == 0){
					sum++;
					for(int i = point; i <= num; i+=point){
						search[i]++;
					}
				}
				point++;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 53656
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int a,b,c,i,j;
    char t;
    while(cin>>a>>t>>b>>t>>c){
        if(c*c==a*a+b*b) i++;
         else if(a==b) j++;
    }
    cout<<i<<endl<<j<<endl;
}

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

int main(){
  string s;
  cin >> s;

  bool flg = false;
  for (char c = 'a'; c <= 'z'; c++)
  {
    flg = false;
    for (int i = 0; i < (int)s.size(); i++)
    {
      if(c==s[i]){
        flg = true;
        break;
      }
    }
    if(!flg){
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
int main() {
	int N; cin >> N;
	if (N<2){
		cout << 0 << endl;
		return 0;
	}
	ll x=1,y=1,z=1;
	REP(i,N){
		x=x*10%MOD;
		y=y*9%MOD;
		z=z*8%MOD;
	}
	cout << mod((x+z)%MOD-2*y,MOD) << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll sum = 0;
  ll ans1 = 0, ans2 = 0;
  for(int i = 0; i < N; i++) {
    sum += A[i];
    if (i % 2 == 0) {
      if (sum < 1) {
        ans1 += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum > -1) {
        ans1 += sum + 1;
        sum = -1;
      }
    }
  }

  sum = 0;
  for(int i = 0; i < N; i++) {
    sum += A[i];
    if (i % 2 == 0) {
      if (sum > -1) {
        ans2 += sum + 1;
        sum = -1;
      }
    } else {
      if (sum < 1) {
        ans2 += 1 - sum;
        sum = 1;
      }
    }
  }

  cout << min(ans1, ans2) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

template<typename T>
string join(vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, a;
    cin >> n >> a;
    if(n % 500 <= a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(b);i>=(int)(a);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(b);i>=(long long int)(a);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;



int arr[g_size];





int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	ll int n,m,T,res;

	int maxi=mx,mini=-mx,count=0;

    int i,j,k;

	string s1,s2;

	char s[100000];

	int ara1[n_size],ara2[n_size];

	cin>>n>>m;

	if(n>=m){
        cout<<m/2<<endl;
	}
	else{
        res=(m-n*2);
        cout<<n+(res/4)<<endl;
	}




}



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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());

		for (int i = 0; i < N; i++) {
			int base = 0;
			int out = 0;
			int point = 0;

			while (out < 3) {
				String str = br.readLine();

				switch (str) {
				case "HIT":
					point += base & 1;
					base = (base | 8) >> 1;
			
					break;
				case "HOMERUN":
					point += Integer.bitCount(base)+1;
					base = 0;
					
					break;
				case "OUT":
					out++;
					break;
				}
			}
			
			System.out.println(point);
		}

	}
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}

int N;
int a[105];

int main(){
  cin>>N;
  REP(N)cin>>a[i];
  int prev=a[0];
  int cnt=1;
  int ans=0;
  for (int i = 1; i < N; i++) {
    if(a[i]==prev)cnt++;
    else {
      ans+=cnt/2;
      cnt=1;
      prev=a[i];
    }
  }
  ans+=cnt/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;
#define double long double
constexpr double inf = 1e17;
constexpr double eps = 1e-8;

struct Solver{
private:
    vector<double> l, r;
public:
    Solver() : l(3, inf), r(3, -inf) {}
    void insert(double d, int v){
        v++;
        chmin(l[v], d);
        chmax(r[v], d);
    }
    vector<double> intersect(){
        vector<double> res;
        rep(i, 3)rep(j, i){
            double tl = (l[j] - l[i]) / (i - j);
            double tr = (r[j] - r[i]) / (i - j);
            if(tl > eps)res.push_back(tl);
            if(tr > eps)res.push_back(tr);
        }
        return res;
    }
    double calculate(double t){
        double mi = inf, ma = -inf;
        rep(i, 3){
            chmin(mi, l[i] + t * i);
            chmax(ma, r[i] + t * i);
        }
        return ma - mi;
    }
};

int main(){

    int N;
    cin >> N;

    Solver X, Y;
    rep(loop, N){
        double x, y;
        cin >> x >> y;
        char c;
        cin >> c;
        if(c == 'L'){ X.insert(x, -1); Y.insert(y, 0); }
        if(c == 'R'){ X.insert(x, 1); Y.insert(y, 0); }
        if(c == 'D'){ X.insert(x, 0); Y.insert(y, -1); }
        if(c == 'U'){ X.insert(x, 0); Y.insert(y, 1); }
    }

    vector<double> ts;
    vector<double> tx = X.intersect(), ty = Y.intersect();
    ts.push_back(0.0);
    ts.push_back(inf);
    ts.insert(ts.end(), all(tx));
    ts.insert(ts.end(), all(ty));

    double ans = inf;
    for(double t : ts)chmin(ans, X.calculate(t) * Y.calculate(t));
    cout << setprecision(20) << ans << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    ll a;
    cin>>a;
    ll arr[a],sum[a],su=0;
    for(ll i=0;i<a;i++){
        cin>>arr[i];
        sum[i]=su%1000000007;
        su=(su%1000000007)+(arr[i]%1000000007);
    }
    ll ans=0;
    for(int i=a-1;i>-1;i--){
        ans+=((arr[i]%1000000007)*(sum[i]%1000000007))%1000000007;
    }
    ans=ans%1000000007;
    cout<<ans;
}
int main(){
    ll bb=1;
    //cin>>a;
    while(bb--){
        solve();
    }
}

Measured memory_bytes: 6724
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] kui = new int[2][n];
		Group[] groups = new Group[n];
		for(int i = 0; i < n; i++) {
			kui[0][i] = scan.nextInt();
			kui[1][i] = scan.nextInt();
			groups[i] = new Group();
		}
		double allLen = 0.0;
		Queue<Branch> q = new PriorityQueue<>();
		for(int i = 0; i < m; i++) {
			int e1 = scan.nextInt()-1;
			int e2 = scan.nextInt()-1;
			int _w = kui[0][e1] - kui[0][e2];
			int _h = kui[1][e1] - kui[1][e2];
			double len = Math.sqrt(_w*_w+_h*_h);
			q.add(new Branch(e1,e2,len));
			allLen += len;
		}
		double resultLen = 0.0;
		while(!q.isEmpty()) {
			Branch _b = q.poll();
			//System.out.println(_b.len);
			Group g1 = groups[_b.e1].getGroup();
			Group g2 = groups[_b.e2].getGroup();
			if(g1==g2) continue;
			Group ng = new Group();
			g1.parent = ng;
			g2.parent = ng;
			resultLen += _b.len;
		}
		System.out.println(allLen-resultLen);
	}
}

class Group{
	Group parent;
	Group(){}
	Group getGroup() {
		return (parent==null)?this:parent.getGroup();
	}
}

class Branch implements Comparable<Branch> {
	int e1,e2;
	double len;
	Branch(int _e1, int _e2, double _len) {
		e1 = _e1;
		e2 = _e2;
		len = _len;
	}
	@Override
	public int compareTo(Branch _b) {
		return (_b.len - this.len>0.0)?1:-1;
	}
}

Measured memory_bytes: 68696
N = int(input())

Flag = True
words = []
for i in range(N):
    word = str(input())
    if not i==0:
        if word[0] != l:
            Flag =  False
        if word in words:
            Flag = False
    l = word[-1]
    words.append(word)

if Flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n = int(input())
S = [input() for _ in range(n)]

ret = []
S0 = set(S[0])

for c in S0 :
    m = float('inf')
    for i in range(n) :
        m = min(m, S[i].count(c))
    ret.append((c, m))
    
ret.sort()
T = []

for c, m in ret :
    if m > 0 :
        for _ in range(m) :
            T.append(c)
            
print(''.join(T))

Measured memory_bytes: 38640
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int count = 0;
        int i = 1;
        while(count < N){
            count += i;
            i++;
        }
        for(int j=1;j<i;j++){
            if(count - N != j){
                sb.Append(j+"\n");
            }
        }
    }
    void Read(){
        N = int.Parse(Console.ReadLine());
    }    
}

Measured memory_bytes: 3160
N = int(input())

mi = 100000000

for a in range(1,N):
    x = a
    sa = 0
    
    while x!=0:
        sa = sa + x%10
        x = x//10
   
    x = N-a
    sb = 0
    
    while x!=0:
        sb = sb +x%10
        x = x //10

    if sa +sb < mi:
        mi = sa + sb

print(mi)

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 1e9
#define MOD 1e9+7
#define LINF (long long)4e18

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
using Pi = pair<int, int>;
using vPi = vector<Pi>;
using vvPi = vector<vector<Pi>>;
using vvvPi = vector<vector<vector<Pi>>>;
using vvvvPi = vector<vector<vector<vector<Pi>>>>;
using Pll = pair<ll, ll>;
using vPll = vector<Pll>;
using Pd = pair<double, double>;
using vPd = vector<Pd>;


int main(){
  string S;
  cin >> S;
  ll ans = 0;
  rep(mask,1<<(S.size()-1)){
    ll now = 0;
    ll a = S[0] - '0';
    rep(i,S.size()-1){
      if(mask & 1<<i){
        now += a;
        a = 0;
      }
      a = a * 10 + S[i+1] - '0';
    }
    
    now += a;
    ans += now;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
// #include<iostream>
// #include<string>
// #include<vector>
// #include<set>
// #include<map>
// #include<algorithm>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUT4(P1,P2,P3,P4) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<" "<<(P4)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

cpp_int N,M,i,A,B,num,ans;
vector<pair<cpp_int,cpp_int>>C;
inline void solve(void){
  IN2(N,M);
  REP(i,N){
    IN2(A,B);
    C.pb(mp(A,B));
  }
  sort(ALL(C));
  for(auto e:C){
    num=min(M,e.second);
    ans+=e.first*num;
    M-=num;
    if(M==0)break;
  }
  OUT(ans);
}

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


Measured memory_bytes: 10604
N = int(input())
A = list(map(int, input().split()))

ans = 'APPROVED'

for i in range(N):
  if A[i] % 2 == 0 and A[i] % 6 != 0 and A[i] % 10 != 0:
    ans = 'DENIED'
    break

print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var D = new Dictionary<string, int>();
        string s;
        int max = 0;
        for (int i = 0; i < n; i++)
        {
            s = Console.ReadLine();
            if (D.ContainsKey(s))
            {
                D[s]++;
                if (D[s] > max) max = D[s];
            }
            else
            {
                D.Add(s, 1);
                if (max == 0) max = 1;
            }
        }
        var A=D.Where(x => x.Value == max).Select(x=>x.Key).ToList();
        A.Sort(StringComparer.OrdinalIgnoreCase);
        A.ForEach(Console.WriteLine);
    }
}



Measured memory_bytes: 42332
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    vector<int> a;
    for(int i=0; i<3; i++) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(), a.end());
    
    int res = 0;
    for(int i=0; i<2; i++) {
        res += a[i+1] - a[i];
    }
    
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int kingaku[] = {6000, 4000, 3000, 2000} ;

	for (int i = 0; i < 4; i++) {
		int t,n;
		cin >> t >> n;
		cout << kingaku[t-1] * n << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;

namespace B
{
	class Program
	{
		static void Main(string[] args)
		{
			var line = Console.ReadLine();
			var lineSplited = line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

			var N = int.Parse(lineSplited[0]);
			var M = int.Parse(lineSplited[1]);

			var K = new int[N];
			var A = new List<List<int>>();
			for (int n = 0; n < N; n++) {
				var _line = Console.ReadLine();
				var _lineSplited = _line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

				K[n] = int.Parse(_lineSplited[0]);
				A.Add(new List<int>());
				for (int k = 0; k < K[n]; k++) {
					A[n].Add(int.Parse(_lineSplited[k + 1]));
				}
			}

			var count = 0;
			bool flag = true;
			for (int m = 0; m < M; m++) {
				flag = true;
				for (int i = 0; i < N; i++) {
					if (A[i].IndexOf(m + 1) == -1) flag = false;
				}
				if (flag)
					count++;
			}

			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 13152
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii; 
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]*a[1]/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define Mod 1000000007

int main()
{
	char L[100002];
	scanf("%s", L);
	
	int i;
	long long ans = 1, pow;
	for (i = 1; L[i] != 0; i++);
	for (i--, pow = 1; i >= 0; i--, pow = pow * 3 % Mod) if (L[i] == '1') ans = (ans * 2 + pow) % Mod;	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1828
L, A, B, M = map(int, input().split())
ans = 0
d = 0
def mul(X, Y):
    Z = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    for i in range(3):
        for j in range(3):
            r = 0
            for k in range(3):
                r += X[i][k] * Y[k][j]
            Z[i][j] = r % M
    return Z

x = 0; a = A
while 1:
    kd0 = max(min((10**d - A + B - 1) // B, L), 0)
    kd1 = max(min((10**(d+1) - A + B - 1) // B, L), 0)

    Q = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    P = [[10**(d+1), 0, 0], [1, 1, 0], [0, B, 1]]
    k = kd1 - kd0
    while k:
        if k & 1:
            Q = mul(P, Q)
        P = mul(P, P)
        k >>= 1
    x, a = (x*Q[0][0]+a*Q[1][0]+Q[2][0]) % M, (x*Q[0][1]+a*Q[1][1]+Q[2][1]) % M
    if kd1 == L:
        break
    d += 1
print(x)

Measured memory_bytes: 3064
ROOT = 3
MOD = 998244353
roots  = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根
iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元

def untt(a,n):
    for i in range(n):
        m = 1<<(n-i-1)
        for s in range(1<<i):
            w_N = 1
            s *= m*2
            for p in range(m):
                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD
                w_N = w_N*roots[n-i]%MOD

def iuntt(a,n):
    for i in range(n):
        m = 1<<i
        for s in range(1<<(n-i-1)):
            w_N = 1
            s *= m*2
            for p in range(m):
                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD
                w_N = w_N*iroots[i+1]%MOD
            
    inv = pow((MOD+1)//2,n,MOD)
    for i in range(1<<n):
        a[i] = a[i]*inv%MOD

def convolution(a,b):
    la = len(a)
    lb = len(b)
    deg = la+lb-2
    n = deg.bit_length()
    if min(la, lb) <= 50:
        if la < lb:
            la,lb = lb,la
            a,b = b,a
        res = [0]*(la+lb-1)
        for i in range(la):
            for j in range(lb):
                res[i+j] += a[i]*b[j]
                res[i+j] %= MOD
        return res

    N = 1<<n
    a += [0]*(N-len(a))
    b += [0]*(N-len(b))
    untt(a,n)
    untt(b,n)
    for i in range(N):
      a[i] = a[i]*b[i]%MOD
    iuntt(a,n)
    return a[:deg+1]

def convolution_all(polys):
    if not polys: return [1]
    #polys.sort(key=lambda x:len(x))
    N = len(polys)
    height = (N-1).bit_length()
    N0 = 1<<(height)
    data = [None]*(N0*2)
    data[N0:N0+N] = polys
    data[N0+N:] = [[1] for _ in range(N0-N)]
    
    #print(data)
    #print(polys)
    for k in range(N0-1,0,-1):
        data[k] = convolution(data[2*k], data[2*k+1])        

    return data[1]

SIZE=10**5 + 10 #998244353 #ここを変更する

inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):
    finv[i-1] = finv[i]*i%MOD
    inv[i] = finv[i]*fac[i-1]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0

dfac = [0]*SIZE  # fac[j] = j! mod MOD
dfac[0] = dfac[1] = 1
for i in range(2,SIZE):
    dfac[i] = dfac[i-2]*i%MOD

import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*h = map(int, read().split())
from collections import Counter

def get(k): # k 個の頂点からiペア作れる場合の数
    res = [1]
    for i in range(k//2):
        res.append(res[-1]*choose(k-2*i,2)%MOD)
    for i in range(2,k//2 + 1):
        res[i] = res[i]*finv[i]%MOD
    return res        


d = Counter(h)
res = []
for k,v in d.items():
    if v >= 2: res.append(get(v))
    if v > n: 
        print(0)
        exit()
    
bad = convolution_all(res)

#print(bad)
#bad = [1,5,7,3]
ans = 0
sgn = 1
for i,ai in enumerate(bad):
    ans += sgn*(dfac[2*n-2*i-1] if i < n else 1)*ai  
    ans %= MOD
    sgn *= -1
    #print(ans)

print(ans%MOD)

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

int main(){
	int n; cin>>n;
	vector<int> v(9,0);
	rep(i,n){
		int a; cin>>a;
		if(a<400) v[0]=1;
		else if(a>=400&&a<800) v[1]=1;
		else if(a>=800&&a<1200) v[2]=1;
		else if(a>=1200&&a<1600) v[3]=1;
		else if(a>=1600&&a<2000) v[4]=1;
		else if(a>=2000&&a<2400) v[5]=1;
		else if(a>=2400&&a<2800) v[6]=1;
		else if(a>=2800&&a<3200) v[7]=1;
		else v[8]++;
	}
	int mx=accum(v);
	int mn=0;
	rep(i,8) mn+=v[i];
	if(v[8]==n) cout<<1<<" "<<mx<<endl;
	else cout<<mn<<" "<<mx<<endl;
}

Measured memory_bytes: 3556