akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <cassert>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long int, null_type, less_equal<long long int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal
#define ll long long
#define ull unsigned long long int
#define INF 1LL << 62
#define mod 998244353
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define zz second.second
#define vi vector<int>
#define vll vector<ll>
#define seta(a,x) memset (a, x, sizeof (a))
#define pp pair<int, int>
#define ppl pair<ll, ll>
#define sz(s) (int)((s).size())
#define all(v) (v).begin(), (v).end()
#define loop(i,s,n) for(int i=s ; i<n ; i++)
#define loopl(i,s,n) for(ll i=s ; i<n ; i++)
#define loopr(i,e,s) for(ll i=e; i>=s ; i--)
#define speedUp ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main() {
	//ab_gupta	
	speedUp;
	int n,k; cin>>n>>k;
	vi h(n);
	loop(i,0,n) cin>>h[i];
	vi dp(n,INT_MAX);
	dp[0]=0;
	for(int i=1;i<n;i++){
		for(int j=max(i-k,0);j<i;j++){
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
}
        


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a,b,c,d;
  a=0;
  b=0;
  c=0;
  d=0;

  cin>>n;
  vector<string>s(n);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
    if(s.at(i)=="AC"){
      a++;
    }
     else if(s.at(i)=="WA"){
      b++;
    }
     else if(s.at(i)=="TLE"){
      c++;
    }
     else if(s.at(i)=="RE"){
      d++;
    }

  }

  cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
  cout<<"WA"<< " "<<"x"<<" "<<b<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<c<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<d<<endl;
}

Measured memory_bytes: 6432
program prob4
    implicit none
    integer(8) :: n
    integer(8), allocatable :: a(:)
    integer(8) :: p(10)
    integer(8) :: s(10)
    integer(8) :: i, j
    integer(8) :: ans
    integer(8) :: cnt
    character(10) :: tmp
    integer(8) :: inttmp

    read(*,*) n
    allocate(a(n))

    p(1) = 1
    do i = 2, 10
        p(i) = p(i-1) * 32
    end do
    do i = 1, n
        read(*,*) tmp
        do j = 1, 10
            s(j) = ichar(tmp(j:j)) - ichar('a')
        end do
        call msort(s)
        a(i) = 0
        do j = 1, 10
            a(i) = a(i) + s(j) * p(j)
        end do
    end do

    call msort(a)

    cnt = 1
    inttmp = a(1)
    ans = 0
    do i = 2, n
        if(a(i) == inttmp)then
            cnt = cnt + 1
        else
            ans = ans + cnt * (cnt - 1) / 2
            inttmp = a(i)
            cnt = 1
        end if
    end do
    ans = ans + cnt * (cnt - 1) / 2

    write(*,*) ans



    deallocate(a)

    stop
contains


  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program prob4

Measured memory_bytes: 4312
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int k;
	cin>>k;
	ll sum=0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int h=1;h<=k;h++){
				sum+=__gcd(__gcd(i,j),h);
			}
		}
	}
	cout<<sum<<ln;
}	

int main(){
	boost_io;
	cout<<setprecision(10);
	solve();
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;

ll int power(ll int x, ll int y, ll int p)  
{  
   ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
 
int main()
{
  fastio();
ll int T;
T=1;

while(T--)
{
string s;
cin>>s;
if(s=="ABC")
  cout<<"ARC"<<endl;
else
  cout<<"ABC"<<endl;

}






    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

vector<int> vi;

int main()
{
    int N, D, X;
    if (scanf("%d%d%d", &N, &D, &X) < 3) return 0;

    vi.resize(N);

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &vi[i]) < 1) return 0;
    }

    int sm = 0;
    for (int i = 0; i < D; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == 0)
            {
                sm++;
                continue;
            }
            else
            {
                for (int k = 1; k < D; k++)
                {
                    if (i == k * vi[j])
                    {
                        sm++;
                    }
                }
            }
        }
    }

    printf("%d\n", sm + X);

    return 0;
}


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

int main() {
    vector<string> row(3);
    for (int i = 0; i < 3; i++) {
        cin >> row[i];
    }

    cout << row[0][0] << row[1][1] << row[2][2] << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 10000; // 998244353;

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

void Main(){
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    REP(i,N-1){
        if(A[i]<0){
            A[i] *= -1;
            A[i+1] *= -1;
        }
    }

    int mn = INF; REP(i,N) chmin(mn, abs(A[i]));
    ll ans = 0; REP(i,N) ans += abs(A[i]);

    if(A[N-1]<0) ans -= 2*mn;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3704
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func dfs(a,x int, ans,c []int, t [][]int)  {
	x += c[a]
	ans[a] = x
	for _, e := range t[a] {
		if ans[e] != -1 {
			continue
		}

		dfs(e,x,ans,c,t)
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	
	n,q := scanInt(),scanInt()
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		ans[i] = -1
	}

	t := make([][]int, n)
	c := make([]int, n)

	for i := 0; i < n-1; i++ {
		a,b := scanInt()-1,scanInt()-1
		t[a] = append(t[a], b)
		t[b] = append(t[b], a)
	}

	for i := 0; i < q; i++ {
		p,x := scanInt()-1,scanInt()
		c[p] += x
	}

	dfs(0,0,ans,c,t)

	for i := 0; i < n; i++ {
		fmt.Print(ans[i])
		if i == n-1 {
			fmt.Println()
		} else {
			fmt.Print(" ")
		}
	}
}


Measured memory_bytes: 81536
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int g[702][702];
int dp[702][702];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) g[i][i] = 1;
    int a[500000], b[500000];
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }
    int d[702] {0};
    queue<int> que;
    vector<int> l, r;
    for(int i = 0; i < n; i++){
        if(d[i] != 0) continue;
        int left = 0, right = 0;
        d[i] = 1;
        left++;
        que.push(i);
        while(que.size()){
            int now = que.front();
            que.pop();
            for(int next = 0; next < n; next++){
                if(g[now][next] == 0){
                    if(d[next] == 0){
                        if(d[now] == 1){
                            d[next] = 2;
                            right++;
                        }
                        if(d[now] == 2){
                            d[next] = 1;
                            left++;
                        }
                        que.push(next);
                    }
                    if(d[next] == d[now]){
                        cout << -1 << endl;
                        return 0;
                    }
                }
            }
        }
        l.push_back(left);
        r.push_back(right);
    }
    int sum = 0;
    for(int x : l) sum += x;
    for(int x : r) sum += x;
    dp[0][0] = 1;
    for(int i = 0; i < (int)l.size(); i++){
        for(int j = 0; j <= 700; j++){
            if(j >= l[i]) dp[i + 1][j] |= dp[i][j - l[i]];
            if(j >= r[i]) dp[i + 1][j] |= dp[i][j - r[i]];
        }
    }
    int mind = 10000;
    for(int j = 0; j <= 700; j++){
        if(dp[(int)l.size()][j]) mind = min(mind, abs(sum - j * 2));
    }
    int rest = n - sum;
    int tk, hs;
    if(rest * 2 < mind){
        tk = (sum - mind) / 2 + rest;
        hs = (sum + mind) / 2;
    }
    else{
        tk = n / 2;
        hs = (n + 1) / 2;
    }
    cout << tk * (tk - 1) / 2 + hs * (hs - 1) / 2 << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  int x = N;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }

  if (N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main() {
    int a, b; cin >> a >> b;
    
    if (a >= 13) {
        cout << b << endl;
        return 0;
    }
    if (a >= 6) {
        cout << b / 2 << endl;
        return 0;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int n;
    cin >> n;
  
  	vector<vector<int>> happy(n,vector<int>(3));
  	rep(i,n) cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
  
    vector<vector<int>> dp(n,vector<int>(3));
    rep(i,3) dp[0][i] = happy[0][i];
    rep(i,n){
      if(i==0) continue;
      rep(j,3) rep(k,3) if(j!=k) 
        dp[i][j] = max(dp[i][j],dp[i-1][k]+ happy[i][j] );
    }
  	int ans = 0;
  	rep(i,3) ans = max(ans,dp[n-1][i]);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11264
#include<stdio.h>

int main(void) {
	int  n, a[100] = { 0 }, i, max, min;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	max = a[0];
	min = a[0];
	for (i = 1; i < n; i++) {
		if (max < a[i]) max = a[i];
		if (min > a[i]) min = a[i];
	}
	printf("%d", max - min);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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

int manhatan(int a, int b, int c, int d){
	return abs(a-b)+abs(c-d);
}


int main(void){

	int N, M; cin >> N >> M;

	vector<int> a(N);
	vector<int> b(N);
	REP(i,N) cin >> a[i] >> b[i];

	vector<int> c(M);
	vector<int> d(M);
	REP(i,M) cin >> c[i] >> d[i];


	REP(i,N){
		vector<pair<int, int>> dist(M);
		REP(j,M){
			dist[j] = make_pair(manhatan(a[i], c[j], b[i], d[j]), j+1);
		}
		SORT(dist);
		cout << dist.front().second << endl;


	}



	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s < t)cout << "Yes"<< endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;

int n, m, x;
vector<vector<int>> v;
vector<int> mon;
int res = INT_MAX;
void dfs(int step, vector<int> state){
  if(step == n){
    vector<int> nows(m);
    int nm = 0;
    rep(i, n){
      if(state[i] == 0) continue;
      nm += mon[i];
      rep(j, m){
        nows[j] += v[i][j];
      }
    }
    bool flag = true;
    rep(i, m){
      if(nows[i] < x) flag = false;
    }
    if(flag) chmin(res, nm);
    return;
  }
  dfs(step+1, state);
  state[step] = 1;
  dfs(step+1, state);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> x;
  v = vector<vector<int>> (n, vector<int> (m));
  mon = vector<int> (n);
  rep(i, n){
    cin >> mon[i];
    rep(j, m) cin >> v[i][j];
    // sort(RALL(v[i]));
  }

  dfs(0, vector<int> (n));
  if(res == INT_MAX) cout << -1 << endl;
  else cout << res << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int H, W;
int dp[10][10];

int main() {
  cin >> H >> W;
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      cin >> dp[i][j];
    }
  }
  for (int k=0; k<10; k++) {
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        dp[i][j] = min(dp[i][k]+dp[k][j], dp[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      int a;
      cin >> a;
      if (a == -1) {
        continue;
      }
      ans += dp[a][1];
    }
  }
  cout << ans << endl;
}


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

typedef long long ll;
ll mod = 10e9;

ll power(ll a, ll b, ll d)
{
    if (b == 0)
    {
        return 1;
    }
    else if (a % 2 == 0)
    {
        return power((a * a) % d, b / 2, d);
    }
    else
    {
        return (a * power((a * a) % d, (b - 1) / 2, d)) % d;
    }
}

ll x, y, z;
void exteneded(ll a, ll b)
{
    if (b == 0)
    {
        z = a;
        x = 1;
        y = 0;
    }
    else
    {
        exteneded(b, a % b);
        int tmep = x;
        x = y;
        y = tmep - (a / b) * y;
    }
}

int modInverse(int A, int M)
{
    A = A % M;
    for (int B = 1; B < M; B++)
        if ((A * B) % M == 1)
            return B;
}

int main()
{
    ll t, i, j, k, n;
    cin >> t;
    ll a[t][3];
    for (i = 0; i < t; i++)
    {
        for (j = 0; j < 3; j++)
        {
            cin >> a[i][j];
        }
    }
    //vector<vector<ll>> dp(t+1,vector<ll>(k+1));
    
    ll dp[t][3];
    for(i=0;i<t;i++){
        for(j=0;j<3;j++){
            dp[i][j]=-1;
        }
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<t;i++){
        for(j=0;j<3;j++){
            for(k=0;k<3;k++){
                if(k!=j){
                    //cout<<"i is "<<i<<" j is "<<j<<" k is "<<k<<endl;
                    dp[i][j]=max(dp[i-1][k]+a[i][j],dp[i][j]);
                    //cout<<"dp is "<<dp[i][j]<<endl;
                }
            }
        }
    }
    ll ans=0;
    for(i=0;i<3;i++){
        ans=max(ans,dp[t-1][i]);
    }
    cout<<ans<<endl;
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int max = 0;
    
    if(a > k) {
        max = k;
        cout << max << endl;
    }
    else {
        max = a;
        k -= a;
        if(b > k) {
            cout << max << endl;
        }
        else {
            k -= b;
            max -= k;
            cout << max << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
vi x;
int main(){
	string s;
	int i,n;
	while(getline(std::cin, s)){
		for(i=0;i<s.size();i++)if (s[i]==',')s[i]=' ';
		stringstream ss(s);
		vi A;
		while(ss>>i)A.push_back(i);
		n=A.size();
		if(x.size()<n){
			x.insert(x.begin(),1,0);
			x.push_back(0);
		}
		vi B(n);
		for(i=0;i<n;i++)B[i]=(x[i]>x[i+1]?x[i]:x[i+1])+A[i];
		x=B;
	}
	cout<<x[0]<<endl;
}

Measured memory_bytes: 1252
#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,M;
  cin >> N >> M;
  vector<int> X(M);
  vector<int> d(M-1);  
  rep(i,M){
    cin >> X[i];
  }
  sort(X.begin(),X.end());
  rep(i,M-1){
    d[i] = X[i+1]-X[i];
  }

  sort(d.begin(),d.end());
  int ans=0;
  rep(i,M-1-(N-1)){
    ans += d[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

struct compare {
    bool operator()(const tuple<int, int, int, int, int> &a, const tuple<int, int, int, int, int> &b) const {
        if (get<0>(a) == get<0>(b)) {
            return get<4>(a) > get<4>(b);
        }
        return get<0>(a) > get<0>(b);
    }
};

int main() {
    int h, w, k;

    int sx, sy;
    int gx, gy;
    cin >> h >> w >> k;
    cin >> sy >> sx >> gy >> gx;
    vector<string> f(h);
    for (int i = 0; i < h; i++) {
        cin >> f[i];
    }
    sx--; sy--; gx--; gy--;
    vector< vector< vector<int> > > visit(h, vector< vector<int> >(w, vector<int>(5, -1)));
    // cost, x, y, dir, step
    priority_queue < tuple<int, int, int, int, int>, vector< tuple<int, int, int, int, int>>, compare > que;

    que.push(make_tuple(0, sx, sy, 4, 0));

    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    // 方向となんます連続で移動してるかを持たせる
    // かくますへの最短距離を持っておく
    int ans = -1;
    while(!que.empty()) {
        auto p = que.top();
        que.pop();

        auto cost = get<0>(p);
        auto cx = get<1>(p);
        auto cy = get<2>(p);
        auto direction = get<3>(p);
        auto step = get<4>(p);

        if (visit[cy][cx][direction] >= 0) {
            continue;
        }

        visit[cy][cx][direction] = cost;
        if (visit[gy][gx][direction] >= 0) {
            ans = visit[cy][cx][direction];
            break;
        }

        if (direction == 4) {
            for (int i = 0; i < 4; i++) {
                int nx = cx + dx[i];
                int ny = cy + dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (f[ny][nx] == '@') { continue; }
                que.push(make_tuple(cost + 1, nx, ny, i, 1));
            }

        } else if (step >= k) {

            for (int i = 0; i < 4; i++) {
                int nx = cx + dx[i];
                int ny = cy + dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (f[ny][nx] == '@') { continue; }
                if (visit[ny][nx][i] >= 0) { continue; }
                que.push(make_tuple(cost + 1, nx, ny, i, 1));
            }
        } else {
            for (int i = 0; i < 4; i++) {
                int nx = cx + dx[i];
                int ny = cy + dy[i];
                if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
                    continue;
                }
                if (visit[ny][nx][i] >= 0) { continue; }
                if (f[ny][nx] == '@') { continue; }
                if (direction == i) {
                    que.push(make_tuple(cost, nx, ny, i, step + 1));
                } else {
                    que.push(make_tuple(cost + 1, nx, ny, i, 1));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

    int H, W;
    cin >> H >> W;
    string tmpS;

    int obst[H][W];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            obst[i][j] = 0;
        }
    }

    for(int i = 0; i < H; i++){
        cin >> tmpS;
        for(int j = 0; j < W; j++){
            if(tmpS[j] == '#'){
                obst[i][j] = 1;
            }
        }
    }

    int sum_yoko[H][W];
    int sum_tate[H][W];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            sum_yoko[i][j] = 0;
            sum_tate[i][j] = 0;
        }
    }

    int tmp_sum = 0;
    int sind, eind;
    for(int i = 0; i < H; i++){
        tmp_sum = 0;
        sind = 0;
        eind = 0;
        for(int j = 0; j < W; j++){
            if(obst[i][j] == 1){
                if(j > 0){
                    for(int k = sind; k<= eind; k++){
                        sum_yoko[i][k] = tmp_sum;
                    }
                    
                }
                tmp_sum = 0;
                sind = j+1;
            }else{//
                tmp_sum++;
                eind = j;
                if(j == W-1){
                    for(int k = sind; k<= eind; k++){
                        sum_yoko[i][k] = tmp_sum;
                    }
                }
            }
        }
    }

    for(int i = 0; i < W; i++){
        tmp_sum = 0;
        sind = 0;
        eind = 0;
        for(int j = 0; j < H; j++){
            if(obst[j][i] == 1){
                if(j > 0){
                    for(int k = sind; k<= eind; k++){
                        sum_tate[k][i] = tmp_sum;
                    }
                }
                tmp_sum = 0;
                sind = j+1;
            }else{//
                tmp_sum++;
                eind = j;
                if(j == H-1){
                    for(int k = sind; k<= eind; k++){
                        sum_tate[k][i] = tmp_sum;
                    }
                }
            }
        }
    }

    // for(int i = 0; i < H; i++){
    //     for(int j = 0; j < W; j++){
    //         cout << sum_yoko[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // for(int i = 0; i < H; i++){
    //     for(int j = 0; j < W; j++){
    //         cout << sum_tate[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            chmax(ans, sum_tate[i][j] + sum_yoko[i][j]-1);
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 47104
H, W = list(map(int, input().split(' ')))
tiles = [list(map(int, input().split(' '))) for i in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]
max_width = 0
for i in range(H):
    dp[i][0] = (tiles[i][0] + 1)%2
    if max_width == 0 and dp[i][0] == 1: max_width = 1
for j in range(W):
    dp[0][j] = (tiles[0][j] + 1)%2
    if max_width == 0 and dp[0][j] == 1: max_width = 1
for i in range(1, H):
    for j in range(1, W):
        if tiles[i][j] == 1:
            dp[i][j] == 0
        else:
            dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1
            max_width = max(max_width, dp[i][j])
print(max_width**2)


Measured memory_bytes: 55816
n=int(input())
s=input()
p=s.count('R')*s.count('G')*s.count('B')
for j in range(1,n-1):
    for i in range(1,min(j,n-j-1)+1):
        x,y,z=s[j-i],s[j],s[j+i]
        if x!=y and y!=z and z!=x:
            p-=1
print(p)

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

int main() {
  int N,K;
  cin >> N>>K;
  int ans=0;
  vector<int>P(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
  }
  sort(P.begin(), P.end());
  for(int i=0;i<K;i++){
    ans+=P[i];
  }
  cout<<ans<<endl;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool
f(vector<int>&ln, int idx, int x, int y) {
  if (idx == 10) return true;
  int z = ln[idx];
  return (x < z && f(ln, idx + 1, z, y)) || (y < z && f(ln, idx + 1, x, z));
}

int main() {

  loop {
    vector<int>ls(10);
    char com;
    int v1, v2;

    int len = 0;
    rep(i, 10) {
      cin >> ls[i] >> com;
      len += ls[i];
    }
    if (!cin) break;

    cin >> v1 >> com >> v2;
    int V = v1 + v2;

    rep (i, 10) {
      ls[i] *= V;
    }

    int le1 = len * v1;
    for (int i=0; i<10; ++i) {
      le1 -= ls[i];
      if (le1 <= 0) {
        cout << -~i << endl;
        break;
      }
    }

  }

  return 0;
}

Measured memory_bytes: 1188
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	cnt := 0

	for i := a; i <= b; i++ {
		s := fmt.Sprintf("%d", i)
		if isKaibun(s) == true {
			cnt++
		}
	}

	fmt.Println(cnt)

}
func isKaibun(s string) bool {
	n := len(s)
	for i, c := range s {
		if c != rune(s[n-i-1]) {
			return false
		}
	}
	return true
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 3244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();

			String s1 = str.substring(0, 2);
			String s2 = str.substring(2, 4);

			int i1 = Integer.parseInt(s1);
			int i2 = Integer.parseInt(s2);

			if (i1 < 13 && i1 != 0) {
				if (i2 < 13 && i2 != 0) {
					System.out.println("AMBIGUOUS");
				} else {
					System.out.println("MMYY");
				}
			} else {
				if (i2 < 13 && i2 != 0) {
					System.out.println("YYMM");
				} else {
					System.out.println("NA");
				}
			}

			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

int main() {
int W,H,x,y,r;
cin >> W >> H >> x >> y >> r;

if ( r <= x && x <= W-r && r <= y && y <= H-r ) {
    cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    typedef pair<int, int> pi;
    typedef pair<ll,ll> pl;

    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector<pi> vpi;
    typedef vector<pl> vpl;
    typedef vector<vi> vvi;

    #define FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
        int n,k;cin>>n>>k;
        int x,sum=0;
        bool flag=true;
        FOR(i,0,k)
        {
            cin>>x;
            sum+=x;
            if(sum>n) {flag=false;break;}
        }

        if(flag) cout<<n-sum;
        else cout<<-1;
        
    }


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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] n=Input.ScanIntArray();
          
          Console.WriteLine($"{Math.Min(n[1],n[2])} {Math.Max(n[1]+n[2]-n[0],0)}");
          
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
def resolve():
    K, N = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    dist = []
    for i in range(N-1):
        dist.append(A[i + 1] - A[i])
    dist.append(abs(A[0] + K - A[-1]))

    print(sum(dist)-max(dist))
    return


resolve()

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

int min(int A, int B);
int max(int A, int B);
 
int main(){
	unsigned long long int N;
	cin >> N;
	int maxn = 100;
	for(unsigned long long int i = 1; i <= sqrt((double)N); i++){
		if(N % i == 0){
			maxn = min(maxn, max(log10((double)i) + 1, log10((double)N / i) + 1));
		}
	}
	cout << maxn << endl;
	return 0;
}

int min(int A, int B){
	if(A > B){
		return (B);
	}else{
		return (A);
	}
}

int max(int A, int B){
	if(A < B){
		return (B);
	}else{
		return (A);
	}
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	long a, b=0;
	scanf("%ld%ld", &a, &b);
	if(( a <= 0 && b >= 0 ) || (a >= 0 && b <=0) ) printf("Zero\n");
	else if( a > 0 && b >0) printf("Positive\n");
	else if((b - a)%2 == 0) printf("Negative\n");
	else printf("Positive\n");
 
	return 0;
}


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

int main( void ) {
    
    int x = 0, ans = 0;
    
    int n;
    cin >> n;
    
    string str;
    cin >> str;
    
    for( char ch : str ) {
        if( ch == 'I' )
            x ++;
        else
            x --;
        
        ans = max( ans, x );
    }
    
    cout << ans;
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
// Problem Specific Parameter:
const int inf=1<<28;

// Description: グラフの型定義(これは最小費用流)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to;};
using G=vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph,int from,int to){ 
	graph[from].push_back({to});
	graph[to].push_back({from});
}

vector<int> node;

bool check(const auto &graph,int v,int p,int d){
	if(node[v]!=-1 and node[v]%2!=d) return false;
	bool ret=true;
	for(auto &e:graph[v]){
		if(e.to==p) continue;
		ret&=check(graph,e.to,v,d^1);
	}
	return ret;
}

using pii=pair<int,int>;
vector<pii> ret;

pii dfs(const auto &graph,int v,int p){
	if(node[v]!=-1){
		chmax(ret[v].first,node[v]);
		chmin(ret[v].second,node[v]);
	}

	for(auto &e:graph[v]){
		if(e.to==p) continue;
		pii tmp=dfs(graph,e.to,v);
		chmax(ret[v].first,tmp.first-1);
		chmin(ret[v].second,tmp.second+1);
	}

	return ret[v];
}

void rest(const auto &graph,int v,int p,int d){
	if(node[v]==-1){		
		if(p==-1){
			node[v]=ret[v].first;
			if(node[v]%2!=d) node[v]++;
		}else{
			if(ret[v].first<= node[p]-1 and node[p]-1<= ret[v].second) node[v]=node[p]-1;
			if(ret[v].first<= node[p]+1 and node[p]+1<= ret[v].second) node[v]=node[p]+1;
		}
	}

	for(auto &e:graph[v]){
		if(e.to==p) continue;
		rest(graph,e.to,v,d^1);
	}
	return;
}



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

	G graph(n);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--,b--;
		add_edge(graph,a,b);
	}

	node.assign(n,-1);
	ret.assign(n,pii(-inf,inf));
	int k;
	cin >> k;
	rep(i,k){
		int v,p;
		cin >> v >> p;
		node[v-1]=p;
	}

	int ok=-1;
	rep(d,2) if(check(graph,0,-1,d)) ok=d;

	dfs(graph,0,-1);
	//rep(v,n) cout << ret[v].first << " " << ret[v].second << endl;
	rep(v,n) if(ret[v].first>ret[v].second) ok=-1;
	
	if(ok==-1){
		puts("No");
	}else{
		puts("Yes");
		rest(graph,0,-1,ok);
		rep(v,n) cout << node[v] << endl;
	}
	return 0;
}

Measured memory_bytes: 15360
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int a,b,c; 
int main(){
	cin>>a>>b>>c;
	if(a>b)
	{
		if(c<=a&&c>=b)
			cout<<"Yes";
		else
			cout<<"No";
	}
	else
	{
		if(c>=a&&c<=b)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const N = 1_000_000_007
const MAX = 2_000_001

var fac, finv, inv []int
var pow25, pow26 []int

func main() {
	sc := NewScanner()

	k := sc.ReadInt()
	s := sc.ReadString()

	fac = make([]int, MAX)
	fac[0] = 1
	fac[1] = 1
	finv = make([]int, MAX)
	finv[0] = 1
	finv[1] = 1
	inv = make([]int, MAX)
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % N
		inv[i] = N - inv[N%i]*(N/i)%N
		finv[i] = finv[i-1] * inv[i] % N
	}

	pow25 = make([]int, MAX)
	pow25[0] = 1
	pow26 = make([]int, MAX)
	pow26[0] = 1
	for i := 1; i < MAX; i++ {
		pow25[i] = pow25[i-1] * 25 % N
		pow26[i] = pow26[i-1] * 26 % N
	}

	ans := 0
	for m := 0; m <= k; m++ {
		mAns := Combi(len(s)+m-1, m)
		mAns = mAns * pow25[m] % N
		mAns = mAns * pow26[k-m] % N
		ans = (ans + mAns) % N
	}
	fmt.Println(ans)
}

func Combi(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % N) % N
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Ceil(divident, dividor int) int {
	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

using namespace std;
int par[200010],ran[200010];

void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i;
		ran[i] = i;
	}
}

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

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	if(ran[x]<ran[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(ran[x]==ran[y]) ran[x]++;
	}
}

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

int main(){
	int n,m,a[100010],b[100010],i,cnt = 0;
	cin >> n >> m;
	for(i=1;i<=n;i++){
		cin >> a[i];
		b[a[i]] = i;
	}
	init(2*n);
	for(i=0;i<m;i++){
		int x,y;
		cin >> x >> y;
		unite(x,y);
	}
	for(i=1;i<=n;i++){
		if(a[i]==i){
			cnt++;
		}else{
			if(same(i,b[i])){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}
		
	

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	fmt.Println(N*(N+1)/2 - N)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
/* 
	Name: Mohit Khare
	CSE - MNNIT Allahabad
	never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define ALL(x) x.begin(), x.end()
#define fastandfurious ios_base::sync_with_stdio(false);
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define X first
#define Y second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define linf 99999999999999999ll	
#define PI 3.1415926535897932384626
#define mod 1000000007
const int maxn=1e5+1;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int main()
{
	//freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
	fastandfurious
	int r,g,b;
	cin>>r>>g>>b;
	int n = r*100 + g*10 + b;
	if(n%4==0)
		cout<<"YES\n";
	else cout<<"NO\n";
	return 0;	
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=100005;

int n,m,q,ecnt,cnt1;
int fa[N];
vector<int>A,B;
int find(int x) {
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
int main() {
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1,u,v,c;i<=q;i++) {
		scanf("%d %d %d",&u,&v,&c);
		if(c==1) {
			A.push_back(u);
			B.push_back(v);
		}
		else {
			int fu=find(u);
			int fv=find(v);
			if(fu!=fv)
				fa[fu]=fv,ecnt++;
		}
	}
	for(int i=0;i<(int)A.size();i++) {
		int fu=find(A[i]);
		int fv=find(B[i]);
		if(fu==fv) {
			printf("No\n");
			return 0;
		}
	}
	long long l=n-ecnt;
	if(A.size()==0) {
		if(m<=ecnt+l*(l-1)/2)
			printf("Yes\n");
		else printf("No\n");
	}
	else {
		if(n<=m&&m<=ecnt+l*(l-1)/2) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100010
#define chmax(a,b) a=max(a,b);
ll a[N],n;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll s=-1;
    for(ll i=0;i<n;i++){
        if(i<a[i])chmax(s,i);
    }
    bool vl=(a[s]-s)%2==1;
    ll t=-1;
    for(ll i=0;i<n;i++){
     if(s<a[i])chmax(t,i);   
    }
    bool vr=(t-s)%2==0;
    cout<<((vl&vr)?"Second":"First")<<endl;
 return 0;   
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(m)]
inf = float('inf')
for a, b in ab:
    cnt = inf
    ans = 0
    for i in range(m):
        v = abs(a - cd[i][0]) + abs(b - cd[i][1])
        if cnt > v:
            cnt = v
            ans = i + 1
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 4001
using namespace std;
ll x,fv[N];
int main(){
	ll i,j;
	for(i=0;i<4000;i++)
	{
		fv[i]=i*i*i*i*i;
	}
	cin>>x;
	for(i=0;i<4000;i++)
	{
		for(j=0;j<4000;j++)
		{
			if(fv[i]+fv[j]==x)
			{
				cout<<i<<" "<<-j<<endl;
				return 0;
			}
			if(fv[i]-fv[j]==x)
			{
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
vector<int> h(100009);
vector<int> dp(100009);
ll ans;
int calc(ll i,ll n,ll k)
{
	for(i=0;i<n;i++)
	{
	    for(int j=0;j<=k;j++)
	    {
	        if(i+j<n)
	        {
	            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
	        }
	    }
	}
	
}
int main()
{
	ll n,i,k;
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	calc(0,n,k);
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  ll h, n;
  cin >> h >> n;
  vll a(n);
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  if (h <= sum) Yes();
  else No();
}

Measured memory_bytes: 1024