akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N;

    cin >> N;

    int n[N];

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

    sort(n, N + n);

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

    return (0);
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

# 割引券を使用しない
result = min(a) + min(b)

# 割引券を使用する
for i in range(M):
    x, y, c = map(int,input().split())
    result = min(result, a[x-1]+b[y-1] -c)

print(result)

Measured memory_bytes: 18736
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;

  ll e = 0;
  ll o = 0;

  rep(i,n)
  {
    ll a;
    cin >> a;
    (a % 2 ? o : e) += 1; 
  }

  if(o % 2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
 
using namespace std;
 
int main(){
 
    int n,m;
    cin >> n >> m;
    char mat[n][m];
    queue<pair<int, pair<int,int>>> q;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> mat[i][j];
            if(mat[i][j] == '#'){
                q.push(make_pair(0,make_pair(i,j)));
            }
        }
    }
    int x[] = {0,0,1,-1};
    int y[] = {-1,1,0,0};
    int ans = 0;
    while(!q.empty()){
        pair<int,pair<int,int>> p = q.front();
        q.pop();
        ans = max(ans,p.first);
        for(int i = 0; i < 4; i++){
            int r = p.second.first + x[i];
            int s = p.second.second + y[i];
            if(r >= 0 && r < n && s >= 0 && s < m && mat[r][s] == '.'){
                mat[r][s] = '#';
                q.push(make_pair(p.first+1,make_pair(r,s)));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n, W, w[100], v[100];
long long dp[100][100001];

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> W;
	for (int i=0; i<n; ++i)
		cin >> w[i] >> v[i];
	for (int i=0; i<n; ++i)
		dp[i][0] = 0;
	for (int i=0; i<=W; ++i) {
		if (i < w[0])
			dp[0][i] = 0;
		else
			dp[0][i] = v[0];
	}
	for (int i=1; i<n; ++i) {
		for (int j=1; j<=W; ++j) {
			dp[i][j] = dp[i-1][j];
			if (j >= w[i])	
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
		}
	}
	cout << dp[n-1][W] << endl;
	return 0;
}


Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

int main() {
  unsigned R, C, N;
  std::cin >> C >> R >> N;
  std::vector<std::pair<std::pair<unsigned, unsigned>, unsigned>> V;
  auto edge = [&](unsigned i, unsigned j) -> bool {
    return (i == 0 || i == C) || (j == 0 || j == R);
  };
  for (unsigned i = 0; i < N; ++i) {
    unsigned x0, y0, x1, y1;
    std::cin >> x0 >> y0 >> x1 >> y1;
    if (edge(x0, y0) && edge(x1, y1)) {
      V.push_back(std::make_pair(std::make_pair(x0, y0), i));
      V.push_back(std::make_pair(std::make_pair(x1, y1), i));
    }
  }
  auto cmp = [&](std::pair<std::pair<unsigned, unsigned>, unsigned> i,
                 std::pair<std::pair<unsigned, unsigned>, unsigned> j) -> bool {
    if (i.first.first == 0) {
      if (j.first.first != 0) { return true; }
      else { return i.first.second < j.first.second; }
    } else if (i.first.second == R) {
      if (j.first.first == 0) { return false; }
      else if (j.first.second != R) { return true; }
      else { return i.first.first < j.first.first; }
    } else if (i.first.first == C) {
      if (j.first.second == 0) { return true; }
      else if (j.first.first != C) { return false; }
      else { return i.first.second > j.first.second; }
    } else {
      if (j.first.second != 0) { return false; }
      else { return i.first.first > j.first.first; }
    }
  };
  std::sort(V.begin(), V.end(), cmp);
  std::stack<unsigned> stack;
  for (unsigned i = 0; i < V.size(); ++i) {
    if (!stack.empty() && V[i].second == stack.top()) {
      stack.pop();
    } else {
      stack.push(V[i].second);
    }
  }
  std::cout << (stack.empty() ? "YES" : "NO") << std::endl;
  return 0;
}


Measured memory_bytes: 5356
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<pii>a;
    rep(i,n){
        int c,d;
        cin >> c >> d;
        a.emplace_back(d,c);
    }
    sort(a.begin(),a.end());
    bool f = true;
    ll now = 0;
    rep(i,n){
        if(now + a[i].second <=  a[i].first){
            now += a[i].second;
        }else f = false;
    }
    if(f)puts("Yes");
    else puts("No");
    
}

Measured memory_bytes: 2420
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<long long int>v(N * 2);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	long long int ans = 0;
	for (int i = 0; i < N * 2; i += 2)ans += v[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    s = IS()
    n = len(s)
    dp = DD2(n,2)
    dp[0][0] = 1
    dp[0][1] = -1
    for i in range(1, n):
        if s[i-1] == s[i]:
            dp[i][0] = dp[i-1][1] + 1
        else:
            dp[i][0] = max(dp[i-1][0], dp[i-1][1]) + 1
        if i-2>=0:
            dp[i][1] = max(dp[i-2][0], dp[i-2][1])+1
    print(max(dp[-1][0],dp[-1][1]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 36760
/*
参考にしたもの
・蟻本
・drkenさんのライブラリ
https://github.com/drken1215/algorithm/blob/master/DataStructure/union_find_tree_size.cpp
辺のverifyはしていない（は？）
*/

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;


struct UnionFind{
    vector<int> par;
    vector<int> es;
    UnionFind(int N) : par(N,-1),es(N,0) {}
    
    //初期化
    void init(int N){
        par.assign(N,-1);
        es.assign(N,0);
    }

    int find(int x){
        if(par[x]<0) return x;
        else return par[x]=find(par[x]);
    }

    int usize(int x) {return -par[find(x)];}

    int esize(int x) {return es[find(x)];}
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        es[x]++;
        if(x==y) return;

        if(usize(x)<usize(y)) swap(x,y);
        par[x]+=par[y];
        es[x]+=es[y];
        par[y]=x;
    }

    bool same(int x,int y) {return find(x)==find(y);}

};

signed main(void){
    int N,M;
    cin>>N>>M;
    int A[110000],B[110000];
    for(int i=1;i<=M;i++){
        cin>>A[i]>>B[i];
        A[i]--; B[i]--;
    } 

    ll now=(ll)N*(N-1)/2;
    vector<ll> ans;
    UnionFind uf(N);
    ans.push_back(now);
    for(int i=M;i>=2;i--){
        int a=A[i],b=B[i];
        if(uf.same(a,b)) ;
        else{
            now-=(ll)uf.usize(a)*uf.usize(b);
            uf.unite(a,b);
        }
        ans.push_back(now);
    }
    reverse(ans.begin(),ans.end());
    for(ll i:ans){
        cout<<i<<endl;
    }
}

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <climits>
#include <cmath>
#include <algorithm>

using namespace std;
using ll = long long;

int H, W;

typedef struct
{
    int x;
    int y;
} Position;

inline bool isSame(Position p, Position q)
{
    return p.x == q.x && p.y == q.y;
}

inline bool isNeighbor(Position p, Position q)
{
    int d_x = abs(p.x - q.x);
    int d_y = abs(p.y - q.y);

    return (d_x + d_y) == 1;
}

int main()
{
    cin >> H >> W;
    vector<Position> loads;

    // make load list
    for (size_t i = 0; i < H; i++)
    {
        for (size_t j = 0; j < W; j++)
        {
            char c;
            cin >> c;
            if (c == '.')
            {
                loads.push_back(Position{i, j});
            }
        }
    }

    vector<vector<int>> dp(loads.size(), vector<int>(loads.size(), INT_MAX));

    // initial cost
    for (size_t i = 0; i < loads.size(); i++)
    {
        for (size_t j = 0; j < loads.size(); j++)
        {
            Position pos1 = loads[i];
            Position pos2 = loads[j];
            if (isSame(pos1, pos2))
            {
                dp[i][j] = 0;
            }
            else if (isNeighbor(pos1, pos2))
            {
                dp[i][j] = 1;
            }
        }
    }

    for (size_t k = 0; k < loads.size(); k++)
    {
        for (size_t i = 0; i < loads.size(); i++)
        {
            for (size_t j = 0; j < loads.size(); j++)
            {
                if (dp[i][k] == INT_MAX || dp[k][j] == INT_MAX) {
                    continue;
                }
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    int ans = 0;
    for (size_t i = 0; i < loads.size(); i++)
    {
        for (size_t j = 0; j < loads.size(); j++)
        {
            if (dp[i][j] == INT_MAX){
                continue;
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
        
}

Measured memory_bytes: 896
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      _s: String,
      _t: String,
   }
   let s: Vec<_> = _s.as_bytes().iter().map(|&c| (c - b'a') as usize).collect();
   let t: Vec<_> = _t.as_bytes().iter().map(|&c| (c - b'a') as usize).collect();
   let n = s.len();

   let mut alps: Vec<_> = (b'a'..b'z' + 1).map(|_| vec![]).collect();
   for i in 0..n {
      alps[s[i]].push(i);
   }
   for a in alps.iter() {
      for i in 1..a.len() {
         if t[a[0]] != t[a[i]] {
            println!("No");
            return;
         }
      }
   }

   let mut alps: Vec<_> = (b'a'..b'z' + 1).map(|_| vec![]).collect();
   for i in 0..n {
      alps[t[i]].push(i);
   }
   for a in alps.iter() {
      for i in 1..a.len() {
         if s[a[0]] != s[a[i]] {
            println!("No");
            return;
         }
      }
   }
   println!("Yes");
}


Measured memory_bytes: 16376
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef     long long               ll;
typedef     vector<ll>              vll;
#define     meme(s)                 memset(s,0,sizeof(s))
#define     rall(s)                 s.rbegin(),s.rend()
#define     i(x)                    scanf("%lld",&(x))
typedef     unordered_map<ll,ll>    mll;
#define     pb                      push_back
#define     in2(x,y)                i(x),i(y)
#define     EL                      cout<<'\n'
#define     fio                     ios_base::sync_with_stdio(false),cin.tie(NULL)
#define     all(s)                  s.begin(),s.end()
typedef     unordered_map<ll,vll>   circuit;
typedef     unordered_map<ll,bool>  is;
const ll    MOD=                    1e9+7;
#define     no                      cout<<"NO\n"
#define     yes                     cout<<"YES\n"
#define     fr(n,x)                 for(int n=0;n<x;n++)
#define     pf(x)                   printf("%lld\n",(x))
const ll    mx=                     2e7;
#define     segtree                 ll L=2*node,R=L+1,mid=(l+r)/2
#define     cs(n)                   printf("Case %lld: ",(n))
typedef     pair<ll,ll>             pll;
typedef     set<ll>                 sll;
#define     X                       first
#define     Y                       second
#define T(j) ll t;cin>>(t);for(ll j=1;j<=t;j++)



void solve()
{
    ll x,y;
    cin>>x;
    ll d;
    ll res=0;
    fr(n,x)
    {
      cin>>d;
      if(d%2 && (n+1)%2)res++;
    }
    cout<<res;
   
}
int main() {
	fio;
    //T(n)
        //cs(n),
        solve();

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main(){
    string S;
    cin >> S;
    int N = S.length();
    int ans = 0;
    for(int i = 1; i < N; i++){
        if(S[i - 1] != S[i])ans++;
    }
    cout << ans << endl;
}

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

int main(void){
	
	double xa,ya,ra,xb,yb,rb,ab;
	int n,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
	ab = sqrt( (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) );

	if(ab<ra-rb){
		printf("2\n");
	}else if(ab<rb-ra){
		printf("-2\n");
	}else if((rb-ra<=ab || ra-rb<=ab) && ab<=ra+rb){
		printf("1\n");
	}else if(ab>ra+rb){
		printf("0\n");
	}
	}
	
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;

const int N = 100006;


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int x;
    cin >> x;
    x >= 30 ? cout << "Yes\n" : cout << "No\n";

    return 0; 
}


Measured memory_bytes: 3576
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
  int H, W;
  while (true)
    {
      cin >> H >> W;
      if (H == 0 && W == 0) break;
      for ( int i = 0; i < H; i++ ){
        for ( int j = 0; j < W; j++ ){
          if (i==0 || i == H-1)
            {
              cout << "#";
            }
          else if (j==0 || j==W-1)
            {
              cout << "#";
            }
          else
            {
              cout << ".";
            }
        }
        cout << endl;
      }
      cout << endl;
    }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int a, b, ans;
	char c;
	cin >> a >> c >> b;
	if (c == '+')
		ans = a + b;
	else
		ans = a - b;
	cout << ans << endl;
	return 0;
}
	
	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

int64_t A[100010];
int64_t data[100010];
int main(){
    int N;
    cin >> N;

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

    data[0] = abs(A[0]);
    int64_t sum = data[0];
    for(int i = 0; i < N - 1; ++i){
        data[i+1] = abs(A[i+1] - A[i]);
        sum += data[i+1];
    }
    sum += abs(A[N-1]);

    for(int i = 0; i < N; ++i){
        int64_t ans = sum;
        ans -= data[i];
        if(i == 0){
            ans -= data[i+1];
            ans += abs(A[i + 1]);
        }
        else if(i != N - 1){
            ans -= data[i+1];
            ans += abs(A[i + 1] - A[i - 1]);
        }
        else {
            ans -= abs(A[N-1]);
            ans += abs(A[N-2]);
        }
        cout << ans << endl;    
    }
}

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

using namespace std;

typedef long long ll;

const int N = 100100;
const int Mod = 1e9 + 7;

int a[N];
int Inv[N];
int Fact[N];
int iFact[N];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

int C(int n, int k)
{
    if(n < 0 || k < 0 || n < k) return 0;
    return mul(Fact[n], mul(iFact[k], iFact[n - k]));
}

int main()
{
    Inv[1] = 1;
    for(int i = 2; i < N; i++)  Inv[i] = (Mod - mul(Mod / i, Inv[Mod % i])) % Mod;

    Fact[0] = iFact[0] = 1;
    for(int i = 1; i < N; i++)  Fact[i] = mul(i, Fact[i - 1]);
    for(int i = 1; i < N; i++)  iFact[i] = mul(Inv[i], iFact[i - 1]);

    int n, k;   cin >> n >> k;

    for(int i = 0; i < n; i++)  scanf("%d", a + i);

    sort(a, a + n);

    for(int i = 0; i < n; i++)  a[i] = (a[i] % Mod + Mod) % Mod;

    int Ans = 0;

    for(int i = 0; i < n; i++)
    {
        add_self(Ans, mul(a[i], C(i, k - 1)));
        sub_self(Ans, mul(a[i], C(n - i - 1, k - 1)));
    }

    cout << Ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string Solve(string s, int K)
        {
            int N = s.Length;
            var set = new HashSet<string>();
            for (int i = 0; i < N; ++i)
            {
                for (int j = 1; j <= K && i + j <= N; ++j)
                {
                    set.Add(s.Substring(i, j));
                }
            }
            return set.OrderBy(t => t).ElementAt(K - 1);
        }
        static void Main(string[] args)
        {
            var s = Read();
            var K = ReadInt();
            Console.WriteLine(Solve(s, K));
        }
    }
}


Measured memory_bytes: 12896
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int a[MAXN],b[MAXN],a1[MAXN],b1[MAXN];
int ans,n,sum;
int main(){
    SF("%d",&n);
    for(int i=0;i<n;i++)
        SF("%d",&a[i]);
    for(int i=0;i<n;i++)
        SF("%d",&b[i]);
    for(int i=0;i<29;i++){
        for(int j=0;j<n;j++){
            a1[j]=a[j]%(1<<(i+1));
            b1[j]=b[j]%(1<<(i+1));
        }
        sort(b1,b1+n);
        sum=0;
        for(int j=0;j<n;j++){
            int s1=lower_bound(b1,b1+n,(1<<i)-a1[j])-b1;
            int t1=lower_bound(b1,b1+n,2*(1<<i)-a1[j])-b1;
            int s2=lower_bound(b1,b1+n,3*(1<<i)-a1[j])-b1;
            int t2=lower_bound(b1,b1+n,4*(1<<i)-a1[j])-b1;
            sum+=(t1-s1)+(t2-s2);
        }
        if(sum&1)
            ans+=(1<<i);
    }
    PF("%d",ans);
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


auto solve() {
    int n, h, w;
    cin >> n >> h >> w;

    return (n - h + 1) * (n - w + 1);
}


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

    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
 
 
using namespace std;
 
 
const int N = 4e5 + 219;
const ll M = 3e5 + 19;
const ll inf = 1e15 + 10;
const ll mod = 1e9 + 7;
 
 
ll n, k, a[N], S[N], cnt[N], First[N], Last[N], nx[N];
vector <ll> g[N], b, c;
bool vis[N], add[N];


void dfs(int u, int p1 = -1) {
    vis[u] = 1;
    b.pb(u);
    if (vis[nx[u]]) {
        b.pb(nx[u]);
        return;
    }
    dfs(nx[u]);
}


void outt(int x) {
    stack<ll> st;
    for (int i = x; i <= n; i++) {
        if (!add[a[i]]) {
            st.push(a[i]);
            add[a[i]] = 1;
        } else {
            while (add[a[i]]) {
                add[st.top()] = 0;
                st.pop();
            }
        }
    }
    while (!st.empty()) {
        c.pb(st.top());
        st.pop();
    }
    reverse(c.begin(), c.end());
    for (int i = 0; i < c.size(); i++)
        cout << c[i] << " ";
}

 
int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    memset(First, -1, sizeof(First));
    memset(Last, -1, sizeof(Last));
    for (int i = n; i >= 1; i--)
        First[a[i]] = i;
    S[n + 1] = -1;
    for (int i = n; i >= 1; i--) {
        cnt[a[i]]++;
        if (Last[a[i]] == -1)
            S[i] = i;
        else
            S[i] = S[Last[a[i]] + 1];
        Last[a[i]] = i;
    }
    for (int i = 1; i <= n + 1; i++) {
        if (S[i] == -1)
            nx[i] = 1;
        else
            nx[i] = First[a[S[i]]] + 1;
        // cout << i << " " << nx[i] << endl;
    }
    dfs(1);
    // for (int i = 0; i < b.size(); i++)
    //     cout << b[i] << " ";
    // cout << endl;
    for (ll i = 0; i < b.size(); i++)
        if (b[i] == b[b.size() - 1]) {
            ll x = i;
            ll y = b.size() - i - 1;
            // cout << x << " " << y << endl;
            if (k <= x)
                outt(b[k - 1]);
            else {
                if ((k - x) % y == 0)
                    outt(b[b.size() - 2]);
                else
                    outt(b[i - 1 + (k - x) % y]);
            }
            return 0;
        }
}

Measured memory_bytes: 40944
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! p {
    ($($x:expr),*) => {
        $(println!("{:?}", $x);)*
    };
}
macro_rules! pr {
    ($($x:expr),*) => {
        $(println!("{}", $x);)*
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused_imports)]
use std::cmp::*;
trait Each: Iterator {
    fn each<F>(self, mut f: F)
    where
        Self: Sized,
        F: FnMut(Self::Item),
    {
        self.fold((), move |(), item| f(item));
    }
}
impl<T: Iterator> Each for T {}

fn main() {
    input! {
       mut v:[i32;3]
    }
    v.sort();
    v.dedup();
    
    if v.len() == 2 {
        print!("Yes");
    } else {
        print!("No");
    }
}


Measured memory_bytes: 4352
n = int(input())
s=[input().split() for i in range(n)]
title = input()
answer = []
a = False
id = 0
for i in range(n):
  if title == s[i][0]:
    id = i
sum = 0
for i in range(id+1,n):
  sum += int(s[i][1])
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int N=2e5+5;
const int W=2019;

signed main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){

string s;
cin>>s;
int ans=0;
int x=0;
unordered_map<int,int>m;

int h[N]={};
h[0]=1;
int j=10;
for(int i=1;i<N;i++){
    h[i]=(j)%W;
    j=(j*10)%W;
}

int rem=0;
m[0]=1;
for(int i=0;i<s.size();i++){

    rem+=((h[s.size()-i-1]*(s[i]-'0')));
    rem%=W;
    if(m.count(rem)>0)
    ans+=m[rem];

    m[rem]++;

}
cout<<ans<<endl;

}


}



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

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int last_digit(int n)
{
    int ans = 0;
    while (n != 0)
    {
        ans = n % 10;
        n /= 10;
    }
    return ans;
}
int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    ll ans = 0;
    ans += (n / x) * t;
    if (n % x != 0)
    {
        ans += t;
    }
    cout << ans;
}


Measured memory_bytes: 3520
N = input()
K = int(input())

a = [0] * (K + 1)
b = [0] * (K + 1)

t = int(N[0])

a = 1
b[0] = 1
b[1] = t - 1

for c in N[1:]:
    t = int(c)
    for i in range(K - 1, -1, -1):
        b[i + 1] += b[i] * 9
    if t != 0:
        if t != 1 and a + 1 <= K:
            b[a + 1] += t - 1
        if a <= K:
            b[a] += 1
        a += 1

if a == K:
    print(b[K] + 1)
else:
    print(b[K])


Measured memory_bytes: 3064
n, m = map(int, input().split())
h = list(map(int, input().split()))
lis = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    h[a-1]
    h[b-1]

    if h[a-1] < h[b-1]:
        lis[a-1] = 0
    elif h[a-1] > h[b-1]:
        lis[b-1] = 0
    else:
        lis[a-1]=0
        lis[b-1]=0

print(len([i for i in lis if i == 1]))

Measured memory_bytes: 20008
n,a,b=map(int,input().split())
if (b-a)%2==0:
  print((b-a)//2)
else:
  c=min(b-1,n-a)
  e=min(a-1,n-b)
  d=(b-a-1)//2+e+1
  print(min(c,d))

Measured memory_bytes: 9188
def calc():
  N,W=map(int,input().split())
  dp=[-1]*(W+1)
  dp[0]=0
  for i in range(N):
    w,v=map(int,input().split())
    for j in range(W-w,-1,-1):
      if dp[j]!=-1:
        if dp[j+w]<dp[j]+v:
          dp[j+w]=dp[j]+v
  print(max(dp))
  
calc()

Measured memory_bytes: 9772
#include <bits/stdc++.h>
using namespace std;
int main () {
  int x, a, b, c;
  cin >> x >> a >> b;
  c = b - a;
  if ((a-b) >= 0) cout << "delicious" << endl;
  else if (x < c) cout << "dangerous" << endl;
  else cout << "safe"  << endl;
  
}

Measured memory_bytes: 256
N, P = [int(_) for _ in input().split()]

mp = {}
for i in range(2, int(P**0.5) + 1):
    while P % i == 0:
        mp[i] = mp.get(i, 0) + 1
        P //= i
mp[P] = mp.get(P, 0) + 1
ans = 1
for i in mp.keys():
    ans *= max(i ** (mp[i] // N), 1)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int x;
	cin >> x;
	if (x == 7 || x == 5 || x == 3)
		puts("YES");
	else
		puts("NO");
}

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

	solve();
}


Measured memory_bytes: 256
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}

#[fastout]
fn main() {
  input! {
     N:usize,
     XYP:[(i64,i64,i64);N]
  }
  let N: usize = N;
  let mut XYP: Vec<(i64, i64, i64)> = XYP;
  let inf = std::i64::MAX;
  let mut xkyori = vec![vec![0; N]; 2usize.pow(N as u32)];
  let mut ykyori = vec![vec![0; N]; 2usize.pow(N as u32)];

  for pat_i in 0..2usize.pow(N as u32) {
    for i in 0..N {
      if pat_i >> i & 1 != 1 {
        // 都市 i に鉄道が引かれている場合は0なので省略。
        // すべての路線への距離の最小値を求める。
        let (x, y, p) = XYP[i];
        xkyori[pat_i][i] = x.abs();
        ykyori[pat_i][i] = y.abs();
        for j in 0..N {
          if pat_i >> j & 1 == 1 {
            xkyori[pat_i][i] = min(xkyori[pat_i][i], (x - XYP[j].0).abs());
            ykyori[pat_i][i] = min(ykyori[pat_i][i], (y - XYP[j].1).abs());
          }
        }
        xkyori[pat_i][i] *= p;
        ykyori[pat_i][i] *= p;
      }
      debug!(pat_i, i, xkyori[pat_i]);
    }
  }
  debug!(xkyori);
  debug!(ykyori);
  // ここまでで前処理。xkyoriとykyoriが計算できた。
  let mut ans = vec![inf; N + 1];
  // 3進数を計算。0=線路なし,1=X路線, 2=Y路線
  for pat_i in 0..3usize.pow(N as u32) {
    // pat_xとpat_yの作成
    let mut k = N;
    let mut pat = pat_i;
    let mut pat_x = 0;
    let mut pat_y = 0;
    for i in 0..N {
      match pat % 3 {
        1 => pat_x += 2usize.pow(i as u32),
        2 => pat_y += 2usize.pow(i as u32),
        _ => k -= 1,
      }
      pat /= 3;
    }
    let mut t_ans = 0;
    for i in 0..N {
      t_ans += min(xkyori[pat_x][i], ykyori[pat_y][i]);
    }
    ans[k] = min(ans[k], t_ans);
  }
  for a in ans {
    println!("{}", a);
  }
}


Measured memory_bytes: 11804
/**
 * @Author:      G_BG
 * @DateTime:    2018-10-06 22:27:07
 * @Description: 
 */
#include<bits/stdc++.h>
using namespace std;
#define MST(a, b) memset(a, b, sizeof(a));
#define CLR(a) MST(a, 0);
#define pb push_back
#define rep(x, y, z) for (int x = y; x < z; ++x)
#define dwn(x, y, z) for (int x = y; x >= z;--x)
#define lowbit(x) (x & (-x))
typedef long long LL;
typedef unsigned long long ULL;
const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int mod = 1e9+7;
const int maxn=1e5+10;
set<int> dict;
int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;cin >> n >> m;
	int x = (int)sqrt(m);
	for(int i = 1;i <= x;i++){
		if(m%i == 0) dict.insert(i),dict.insert(m/i);
	}
	int ans = 1;
	for(auto i = dict.begin();i != dict.end();i++){
		if(m/(*i) >= n) {
			ans = *i;
		}
		else break;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

class Segtree {
private:
    int n;
    vector <int> tr;
    int neutral_tr = 0;

    int merge(int a, int b) {
        return max(a, b);
    }

    void build(const vector <int>& a) {
        forn (i, 0, n) 
            tr[i + n] = a[i];
        for (int i = n - 1; i > 0; i--)
            tr[i] = merge(tr[2 * i], tr[2 * i + 1]);
    }
public:
    Segtree(const vector <int>& a) {
        n = sz(a);
        tr.resize(2 * n, neutral_tr);
        build(a);
    }

    int get(int l, int r) {
        int ans = neutral_tr;
        for (l += n, r += n; l < r; l /= 2, r /= 2) {
            if (l % 2)
                ans = merge(ans, tr[l++]);
            if (r % 2)
                ans = merge(ans, tr[--r]);
        }
        return ans;
    }
};

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    int mx = 0;
    vector <int> left(n);
    forn (i, 0, n) {
        if (s[i] == 'o')
            left[i] = mx + 1;
        if (i - c >= 0)
            chkmax(mx, left[i - c]);
    }

    mx = 0;
    vector <int> right(n);
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'o')
            right[i] = mx + 1;
        if (i + c < n)
            chkmax(mx, right[i + c]);       
    }

    vector <int> sum(n);
    forn (i, 0, n)
        sum[i] = left[i] + right[i] - 1;

    //cout << left << " " << right << "\n" << sum << "\n";

    forn (i, 0, n)
        if (sum[i] > k)
            return 0;

    Segtree tr(sum);
    forn (i, 0, n) {
        if (sum[i] == k && 
            tr.get(max(0, i - c), i) < k &&
            tr.get(i + 1, min(n, i + c + 1)) < k)
            cout << i + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 5780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

int main(){
	int n;
	cin >> n;
	
	ll ans = 1;
	const ll mod = (ll)1e9+7;
	
	REP(i,n){
		ans *= 10;
		ans %= mod;
	}
	
	ll a = 1;
	REP(i,n){
		a *= 8;
		a %= mod;
	}
	ll b = 1;
	REP(i,n){
		b *= 9;
		b %=mod;
	}
	
	ans = (ans + a  - 2*b )%mod;
	if(ans < 0){
		ans = (ans+mod)%mod;
	}
	cout  << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> dp(n, 1e9);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        if(i + 1 < n)
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
        if(i + 2 < n)
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
    }
    cout << dp[n - 1] << endl;
}


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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    char c;
    rep(i, N) {
        cin >> c;
        if (i == K - 1) {
            cout << (char)(c - 'A' + 'a');
        } else {
            cout << c;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a - c) * (b - d);
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    vector<int> suma(n+1);
    vector<int> sumb(n);
    for(int i=0;i<n;i++){
        suma[i+1]=suma[i]+a[i];
        sumb[i+1]=sumb[i]+b[i];
    }
    int res=0;
    for(int i=0;i<n;i++){
        int sc=suma[i+1]+sumb[n]-sumb[i];
        res=max(res,sc);
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }

    long long yen=1000;

    for(int i=0;i<n-1;i++)
    {
        if(a[i]<a[i+1])
        {
            long long products=yen/a[i];
            yen=yen%a[i];
            yen+=products*a[i+1];
        }
    }

    cout<<yen<<endl;
    exit(0);
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int thr = in.nextInt();
        in.close();
        int ans = num < thr ? 0 : 10;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin  >> m >> n;
	int sum=0;
	for(int i=0;i<n;i++){
		int a; cin >> a;
		sum+=a;
	}
	if(sum>m)printf("-1\n");
	else  printf("%d\n",m-sum );
}

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

int main(){
    int a,b;
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }if(a > b){
        cout << "a > b" << endl;
    }if(a == b){
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
class fastin{
	private: int _ch,_f;
	public: inline fastin& operator>>(char&c) {c=getchar(); return *this;}
		template<typename _Tp> inline fastin& operator>>(_Tp&_x){
		_x=0; while(!isdigit(_ch)) _f|=(_ch==45),_ch=getchar();
		while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
		_f&&(_x=-_x,_f=0); return *this;}
	fastin() {_ch=_f=0;}
}fin;
class fastout{
#define endl '\n'
	private: int _num[32],_head;
	public: inline fastout& operator<<(char c) {putchar(c); return *this;}
		template<typename _Tp> inline fastout& operator<<(_Tp _x){
		_Tp _k; if(_x==0) {putchar('0'); return *this;} if(_x<0) putchar('-'),_x=-_x;
		while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
		while(_head>0) putchar(_num[_head]),--_head; return *this;}
	fastout() {_head=0;}
}fout;
// ----------------------------
#define int ll
// using namespace std;
const int maxn=204;
const int mod=998244353,inf=1000000007;

ll base[70];
int a[maxn];
std::string b;
signed main()
{
	int T;
	fin>>T;
	while(T--)
	{
		int n; fin>>n;
		for(rgi i=1;i<=n;++i) fin>>a[i];
		std::cin>>b;
		memset(base,0,sizeof(base));
		bool y=1;
		for(rgi i=n;i>=1&&y;--i)
		{
			if(b[i-1]=='0')
			{
				int x=a[i];
				for(rgi j=0;j<64;++j)
					if((x>>j)&1)
					{
						if(!base[j]) {base[j]=x; break;}
						else x^=base[j];
					}
			}
			else
			{
				int x=a[i];
				for(rgi j=0;j<64;++j)
					if((x>>j)&1)
					{
						if(base[j]) x^=base[j];
						else break;
					}
				if(x) y=0;
			}
		}
		std::cout<<(!y)<<endl;
	}
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 3576
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

X,Y,Z,K = nums()
A = nums()
B = nums()
C = nums()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

AB = [bi + ai for bi in B for ai in A]
AB.sort(reverse=1)
res = []
for ab_sum in AB[:K]:
    for ci in C[:K]:
        res.append(ab_sum + ci)
res.sort(reverse=True)
for ans in res[:K]:
    print(ans)

Measured memory_bytes: 140148
A, B = gets.chomp.split(' ').map(&:to_i)
if A == B
  puts A
  exit
end
if A.odd?
  pair_range_count = B - (A + 1) + 1
  pair_count = pair_range_count / 2
  pair_xor_ans = pair_count.even? ? 0 : 1
  ans =
    if pair_range_count % 2 == 0
      A ^ pair_xor_ans
    else
      A ^ pair_xor_ans ^ B
    end
  puts ans
else
  range_count = B - A + 1
  pair_count = range_count / 2
  pair_xor_ans = pair_count.even? ? 0 : 1
  ans =
    if range_count % 2 == 0
      pair_xor_ans
    else
      pair_xor_ans ^ B
    end
  puts ans
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	sort(a, a + n);
	int mx = a[n - 1];

	int s = 0;
	for (int i = 0; i < n - 1; i++) {
		s += a[i];
	}
	cout << s + mx / 2 << endl;

	return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<ll,ll> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    ll n,d,ans;
    ans=0;
    cin>>n>>d;
    vector<Pii> p(n);
    d *= d;
    rep(i,n){
        ll x,y;
        cin>>x>>y;
        x*=x;y*=y;
        ll dis = x+y;
        if(dis<=d)ans++;
    }
    
    

    cout<<ans;



    return 0;
}

Measured memory_bytes: 6420
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N) ], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Measured memory_bytes: 29352