akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

#define X real()
#define Y imag()
typedef double D;
typedef complex<double>P;
#define EPS (1e-9)

int main(){
    int n;
    cin >> n;
    REP(i,n){
        double xa, ya, ra, xb, yb, rb;
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        P pa(xa,ya), pb(xb,yb);
        D distance = sqrt(norm(pa-pb));

        //cout << "distance = " << distance << endl;
        if(ra-rb > distance){
            cout << 2 << endl;
            continue;
        }
        if(rb-ra > distance){
            cout << -2 << endl;
            continue;
        }
        if(distance > ra+rb){
            cout << 0 << endl;
            continue;
        } else {
            cout << 1 << endl;
            continue;
        }

    }
    return 0;
}

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

typedef long long LL;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;scanf("%d",&n)
#define MSET(arr,val)  memset(arr,val,sizeof(arr))

int main(){
  INT(n);
  vector<tuple<int, int, int>> xy, yx;
  REP(i, n){
    INT(x); INT(y);
    xy.PB(MT(x, y, i));
    yx.PB(MT(y, x, i));
  }
  sort(xy.begin(), xy.end());
  sort(yx.begin(), yx.end());
  map<int, vector<pair<int, int>>> gr;
  int u, v, c;
  REP(i, n - 1){
    u = get<2>(xy[i]);
    v = get<2>(xy[i + 1]);
    c = min(abs(get<0>(xy[i + 1]) - get<0>(xy[i])), abs(get<1>(xy[i + 1]) - get<1>(xy[i])));
    gr[u].PB(MP(-c, v));
    gr[v].PB(MP(-c, u));
    u = get<2>(yx[i]);
    v = get<2>(yx[i + 1]);
    c = min(abs(get<0>(yx[i + 1]) - get<0>(yx[i])), abs(get<1>(yx[i + 1]) - get<1>(yx[i])));
    gr[u].PB(MP(-c, v));
    gr[v].PB(MP(-c, u));
  }
  bool added[n + 1]; MSET(added, false);
  LL ans = 0;
  priority_queue<pair<int, int>> pq;
  pq.push(MP(0, 0));
  while (0 < SZ(pq)){
    c = pq.top().first;
    u = pq.top().second;
    pq.pop();
    if (!added[u]){
      added[u] = true;
      ans -= c;
      FOR(it, gr[u]){
        pq.push(*it);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;



main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    unordered_map<ll, int> mp;
    ll at = 0;
    ll re = 0;
    mp[0]=1;    
    REP(i,n){
        ll x; cin>>x; at += x;
        re += mp[at]; mp[at]++;
    }
    cout<<re<<endl;
} 

Measured memory_bytes: 8520
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    string s;
    cin >> s;
    string ans = s.substr(0, 3);
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>


using namespace std;


int main()
{
	int n;
	string str;

	cin >> n;
	cin >> str;

	int count = 0;
	for(int i = 0; i < n ; i++){
		if(i == n - 1)
			break;

		if(str[i] == 'O' && str[i + 1] == 'X'
		|| str[i] == 'X' && str[i + 1] == 'O'){
			count++;
			i++;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3324
#include <iostream>

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int b10000(-1), b5000(-1), b1000(-1);
  bool found(false);

  for (b10000 = 0; b10000 <= N; b10000++) {
    for (b5000 = 0; b5000 <= N; b5000++) {
      int rest = Y - b10000 * 10000 - b5000 * 5000;
      b1000 = rest / 1000;
      if (b1000 >= 0 && (b10000 + b5000 + b1000 == N)) {
        found = true;
        break;
      }
    }
    if (found) break;
  }
  if (!found) {
    b10000 = -1;
    b5000 = -1;
    b1000 = -1;
  }

  cout << b10000 << " " << b5000 << " " << b1000 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define P 1000000007
using namespace std;

int powmp(long long x,long long n){
	const long long p = 1000000007;
	if(n==0) return 1;
	long long y = x%p;
	if(n==1) return y;
	long long tmp = (powmp(y,n/2))%p;
	if(n%2==0) return (tmp*tmp)%p;
	else return (powmp(y,n-1)*y)%p;
}

int main(int argc, char const *argv[])
{
	int n,a,b;
	cin >> n >> a >> b;
	int c = 0;
	int cf = 0;
	string str;
	cin >> str;
	REP(i,n){
		if(str[i]=='a'){
			if(c<a+b){
				cout << "Yes" << "\n";
				c++;
			}
			else cout <<"No"<<"\n";
		}
		else if(str[i]=='b'){
			if(c<a+b&&cf<b){
				cout << "Yes" << "\n";
				c++;
			}
			else cout <<"No"<<"\n";
			cf++;
		}
		else{
			cout <<"No"<<"\n";
		}
	}

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

Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

// a,b の最大公約数と、ax + by = gcd(a,b) となる x,y を求める
long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a;
    if(b != 0){
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return g;
}

// ax ≡ gcd(a, m) (mod m) となる x を求める
// a, m が互いに素ならば、関数値は mod m での a の逆数となる
long long mod_inverse(long long a, long long m)
{
    long long x, y;
    extgcd(a, m, x, y);
    return (x % m + m) % m;
}

// 階乗数の事前計算を用いた各種組合せ
class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = mod_inverse(factorial[i], mod);
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        return getCombination(n+r-1, r);
    }
};

const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    FactorialCalculation calc(n, MOD);

    vector<vector<int> > weight(n, vector<int>(1, INF));
    for(int i=0; i<n; ++i){
        int c, w;
        cin >> c >> w;
        weight[c-1].push_back(w);
    }
    for(int i=0; i<n; ++i)
        sort(weight[i].begin(), weight[i].end());
    sort(weight.begin(), weight.end());
    int m = 0;
    while(m < n && weight[m].size() > 1)
        ++ m;
    weight.resize(m);
    if(m == 1){
        cout << 1 << endl;
        return 0;
    }

    vector<int> cnt(m, 0);
    for(int i=0; i<m; ++i){
        int a = weight[0][0];
        if(i == 0)
            a = weight[1][0];
        while(a + weight[i][cnt[i]] <= y)
            ++ cnt[i];
        if(cnt[i] > 0){
            while(weight[i][0] + weight[i][cnt[i]] <= x)
                ++ cnt[i];
        }
    }

    int sum = 0;
    long long ans = 1;
    for(int i=0; i<m; ++i){
        sum += cnt[i];
        ans *= calc.getCombination(sum, cnt[i]);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16384
#include <iostream>
#include <vector>

using namespace std;

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

	int gn, kn;
	if (k % 2 == 1) {
		gn = k / 2;
		kn = k / 2 + 1;
	} else {
		gn = k / 2;
		kn = k / 2;
	}

	cout << gn * kn << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
int n,a[200005],k;
long long int ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i]-=i;
	}
	sort(a+1,a+1+n);k=a[n/2+1];
	for(int i=1;i<=n;i++) ans+=(abs)(a[i]-k);
    printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<ll, ll>P;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void SAY(bool YES){cout<<(YES?"YES":"NO")<<endl;};
void Say(bool Yes){cout<<(Yes?"Yes":"No")<<endl;};

const ll MOD = 1000000007;

int main(){

    vector<ll>flg(101010, 0);
    ll N;
    cin >> N;
    vector<ll>nxt(101010, 0);
    for(ll i = 1; i <= N; i++)cin >> nxt[i];
    for(ll ans = 0, pos = 1;;pos = nxt[pos]){
        if(pos == 2){
            cout << ans << endl;
            return 0;
        }
        if(flg[pos]){
            cout << -1 << endl;
            return 0;
        }
        flg[pos] = 1;
        ans++;
    }

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, number_m, number_c, i, j, temp_sum, count = 0;
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    number_c = Integer.parseInt(sc.next());
    int[] array_b = new int[number_m];
    int[] array_a = new int[number_m];
    for(i = 0; i < number_m; i++) array_b[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n; i++) {
      temp_sum = number_c;
      for(j = 0; j < number_m; j++) {
        array_a[j] = Integer.parseInt(sc.next());
        temp_sum += array_a[j] * array_b[j];
      }
      if(temp_sum > 0) count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 23892
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll n,m,k;
cin>>n>>m>>k;
vector<string>v;
for(ll i=0;i<n;i++)
{
    string s;
    cin>>s;
    v.pb(s);
}
vector<ll>arr;
for(ll i=0;i<n-1;i++)
{
    arr.pb(i);
}
ll x=arr.size();
ll ans=n+m;
for(ll i=0;i<(1<<x);i++)
{
    ll j=i;
    vector<ll>sub;
    ll cnt=0;
    while(j>0)
    {
        if(j&1)
        {
            sub.pb(arr[cnt]);
        }
        cnt++;
        j=j>>1;
    }
    if(sub.size()==0)
    {
        bool flag=true;
        ll cnt=0;
        ll sum=0;
        ll prev=0;
        for(ll i=0;i<m;i++)
        {
            for(ll j=0;j<n;j++)
            {
                if(v[j][i]=='1')
                {
                    sum++;
                }
            }
            if(sum>k)
            {
                cnt++;
                sum=sum-prev;
                if(sum>k)
                {
                    flag=false;
                    break;
                }
                prev=sum;
            }
        }

        if(flag)
        {
            ans=min(ans,cnt);
        }

    }else
    {
        ll val=sub.size();
        sub.pb(-1);
        sub.pb(n-1);
        sort(sub.begin(),sub.end());
        vector< vector<ll> >temp(val+1,vector<ll>(m,0));
        for(ll i=0;i<m;i++)
        {
            for(ll j=0;j<(ll)sub.size()-1;j++)
            {
                ll x=sub[j];
                ll y=sub[j+1];
                ll sum=0;
                for(ll w=x+1;w<=y;w++)
                {
                    if(v[w][i]=='1')
                    {
                        sum++;
                    }
                }
                temp[j][i]=sum;
            }
        }
        bool flag=true;
        ll var=val+m-1;
        for(ll j=0;j<m-1;j++)
        {
            bool tflag=true;
            for(ll i=0;i<temp.size();i++)
            {
                if(temp[i][j]>k)
                {
                    flag=false;
                    break;
                }
            }
            if(flag==false)
            {
                break;
            }
            for(ll i=0;i<temp.size();i++)
            {
                if(temp[i][j]+temp[i][j+1]>k)
                {
                    tflag=false;
                    break;
                }
            }
            if(tflag==true)
            {
                var--;
            for(ll i=0;i<temp.size();i++)
            {
                temp[i][j+1]+=temp[i][j];
            }
            }

        }
        if(flag)
        {

            ans=min(ans,var);
        }

    }

}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int k,a,b;
    cin >> k >> a >> b;
    rep(i,1000){
        int ans = k * i;
        if(a <= ans && ans <= b){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <time.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;

int n,m,a[maxn];
vector<int> v1l[maxn],v1r[maxn];
vector<int> v2l[maxn],v2r[maxn];

ll res[maxn];
int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif
  cin>>n>>m;
  ll sum=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(i==1)continue;
    if(a[i]>a[i-1]){
      sum+=a[i]-a[i-1];
      v1r[a[i]].push_back(a[i-1]);
      v1l[a[i-1]].push_back(a[i]);
    } else {
      int tt=m-a[i-1]+a[i];
      sum+=tt;
      v2l[a[i-1]].push_back(a[i]+m);
      v2r[a[i]+m].push_back(a[i-1]);
    }
  }
  ll reduce=0;
  int cnt=0;
  int cnt0=v1l[1].size();
  for(int i=2;i<=m;i++){
    reduce+=cnt;
    res[i]+=reduce;
    cnt+=cnt0;
    cnt0=v1l[i].size();
    cnt-=v1r[i].size();
    for(int j=0;j<(int)v1r[i].size();j++){
      int tt=v1r[i][j];
      reduce-=(i-tt-1);
    }
  }
  reduce=0,cnt=0,cnt0=0;
  for(int i=2;i<=m+m;i++){
    reduce+=cnt;
    res[i>m?i-m:i]+=reduce;
    cnt+=cnt0;
    cnt0=v2l[i].size();
    cnt-=v2r[i].size();
    for(int j=0;j<(int)v2r[i].size();j++){
      int tt=v2r[i][j];
      reduce-=(i-tt-1);
    }
  }
  ll mx=0;
  for(int i=1;i<=m;i++)mx=max(mx,res[i]);
  cout<<sum-mx<<endl;
  return 0;
}


Measured memory_bytes: 24832
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

struct Sector
{
	bool canReach[13000];
};
Sector board[81][81];

int h, w;
int a[100][100];
int b[100][100];
int d[100][100];

void convertInto(int tr, int tc, int sr, int sc, int dNum)
{
	for (int i = 0 ; i <= 12800 ; i++)
	{
		if (board[sr][sc].canReach[i] == true)
		{
			board[tr][tc].canReach[i + dNum] = true;
			board[tr][tc].canReach[i - dNum] = true;
		}
	}
}

int main()
{
	scanf("%d%d", &h, &w);
	for (int i = 0 ; i < h ; i++)
		for (int j = 0 ; j < w ; j++)
			scanf("%d", &(a[i][j]));
	for (int i = 0 ; i < h ; i++)
		for (int j = 0 ; j < w ; j++)
		{
			scanf("%d", &(b[i][j]));
			d[i][j] = abs(a[i][j] - b[i][j]);
		}
		
	board[0][0].canReach[6400 - d[0][0]] = true;
	board[0][0].canReach[6400 + d[0][0]] = true;
	for (int r = 0 ; r < h ; r++)
	{
		for (int c = 0 ; c < w ; c++)
		{
			int nr, nc;
			//上 
			nr = r - 1;
			nc = c;
			if ((0 <= nr) && (nr < h))
				convertInto(r, c, nr, nc, d[r][c]);
			
			nr = r;
			nc = c - 1;
			if ((0 <= nc) && (nc < w))
				convertInto(r, c, nr, nc, d[r][c]);
		}
	}
	
	int minDist = -1;
	for (int i = 0 ; i <= 12800 ; i++)
	{
		if (board[h-1][w-1].canReach[i] == true)
		{
			int curDist = abs(i - 6400);
			if ((minDist == -1) || (minDist > curDist))
				minDist = curDist;
		}
	}


	printf("%d\n", minDist);
	

	return 0;
}




Measured memory_bytes: 82048
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a,ll m=mod) {
  ll b=m,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+m)%m;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n,ll m=mod){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%m;
    a=a*a%m;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
ll N,M,K,H,W,A,B,C,D;
string s,t;
ll ans;
int main(){
  startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j;
  cin>>N;
  print((N^1));
  // }
}

Measured memory_bytes: 3668
#include<iostream>
#include<complex>
#include<map>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(c)   (c).begin(),(c).end()

#define P(i)  (2*i+0)
#define D(i)  (2*i+1)

const int N = 100;
const int inf = (1<<25);
int cap[500][500];
bool visited[500];
int flow[500][500];
int layer[500];

void make_layer(int n,int s,int t){
  queue<int> Q;
  Q.push(s);
  layer[s]=0;
  while(!Q.empty()){
    int now=Q.front();Q.pop();
    rep(i,n){
      if (cap[now][i]-flow[now][i] >0 && layer[i] == -1){
	layer[i]=layer[now]+1;
	Q.push(i);
      }
    }
  }
}

int augment(int now,int t,int n,int f){
  if (now==t||f==0)return f;
  if (visited[now])return 0;
  visited[now]=true;
  rep(i,n){
    if (layer[now] < layer[i]){
      int tmp = augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
      if (tmp > 0){
	flow[now][i]+=tmp;
	flow[i][now]=-flow[now][i];
	visited[now]=false;
	return tmp;
      }
    }
  }
  return 0;
}

int dinic(int n,int s,int t){
  int ansflow=0;
  rep(i,n)rep(j,n)flow[i][j]=0;
  bool flag=true;
  while(flag){
    fill(layer,layer+n,-1);
    fill(visited,visited+n,false);
    flag=false;

    make_layer(n,s,t);
    if (layer[t] == -1)break;

    for(int f=1;f;flag=true){
      f = augment(s,t,n,inf);
      if (f == 0)break;
      ansflow+=f;
    }
  }
  return ansflow;
}

int dist[N][N];
void wf(int n){
  rep(k,n)rep(i,n)rep(j,n)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
}

main(){
  int n,m,L;
  while(cin>>n>>m>>L){
    int node=n*2+2;
    int src=n*2,sink=n*2+1;
    rep(i,node)rep(j,node)cap[i][j]=0;
    rep(i,n){
      rep(j,n)dist[i][j]=inf;
      dist[i][i]=0;
    }    

    rep(i,n){
      //cap[src][P(i)]=inf;
      //cap[D(i)][sink]=inf;
    }

    rep(i,m){
      int f,t,c;
      cin>>f>>t>>c;
      dist[f-1][t-1]=dist[t-1][f-1]=c;
    }
    
    rep(i,n){
      cin>>cap[src][P(i)];
    }

    rep(i,n){
      cin>>cap[D(i)][sink];
    }

    wf(n);
    rep(i,n){
      rep(j,n){
	if (dist[i][j] < L){
	  cap[P(i)][D(j)]=inf;
	}
      }
    }

    cout << dinic(node,src,sink)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <cstring>

using namespace std;

int dx[3]={0,3,6};
int dy[3]={0,3,6};

int main(void){
	int n;
	bool first = true;;
	cin >> n;
	
	for(int i=0;i<n;i++){
		int mat[9][9];
		bool ast[9][9];
		int worksp[10];
		
		
		if(!first) cout << endl;
		memset(ast, false, sizeof(ast));
		for(int j=0;j<9;j++){
			for(int k=0;k<9;k++){
				cin >> mat[j][k];
			}
		}
		
		//check every rows
		for(int j=0;j<9;j++){
			memset(worksp, -1, sizeof(worksp));
			
			for(int k=0;k<9;k++){
				if(worksp[mat[j][k]] == -1){ //unexist yet
					worksp[mat[j][k]] = k;
				}else{
					ast[j][k] = true;
					ast[j][worksp[mat[j][k]]] = true;
					//cout << "line " << mat[j][k] << endl;
				}
			}
		}
		//check every cols
		for(int j=0;j<9;j++){
			memset(worksp, -1, sizeof(worksp));
			
			for(int k=0;k<9;k++){
				if(worksp[mat[k][j]] == -1){ //unexist yet
					worksp[mat[k][j]] = k;
				}else{
					ast[k][j] = true;
					ast[worksp[mat[k][j]]][j] = true;
					//cout << "cols " << mat[k][j] << endl;
				}
			}
		}
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				memset(worksp, -1, sizeof(worksp));
				
				for(int p=0;p<3;p++){
					for(int q=0;q<3;q++){
						if(worksp[mat[dx[j]+p][dy[k]+q]] == -1){
							worksp[mat[dx[j]+p][dy[k]+q]] = p*10+q;
						}else{
							ast[dx[j]+p][dy[k]+q] = true;
							ast[dx[j] + worksp[mat[dx[j]+p][dy[k]+q]] / 10][dy[k] + worksp[mat[dx[j]+p][dy[k]+q]] % 10] = true;
						}
					}
				}
			}
		}
		//check every square
		
		for(int j=0;j<9;j++){
			for(int k=0;k<9;k++){
				if(ast[j][k]){
					cout << "*" << mat[j][k];
				}else{
					cout << " " << mat[j][k];
				}
			}
			cout << endl;
		}
		first = false;
	}
}

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

int main(){
    int h,w,d,memo = 0;
    cin >> h >> w >> d;
    
    char cells[h][w];
    
    rep(i,0,h){
        rep(j,0,w){
            cin >> cells[i][j];   
        }
    }
    
    
    rep(i,0,h){
        rep(j,0,w-d+1){
            rep(k,0,d){
                if(cells[i][j+k] == '#'){
                    break;
                }
                else if(k == d-1){
                    memo++;
                }
            }
        }   
    }
    
    rep(i,0,w){
        rep(j,0,h-d+1){
            rep(k,0,d){
                if(cells[j+k][i] == '#'){
                    break;
                }
                else if(k == d-1){
                    memo++;
                }
            }
        }   
        
    }
    
    
    
    cout << memo << endl;
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
#define fi first
#define se second
using namespace std;

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



int main() {

	int n, m;

	cin >> n >> m;
	cout << (n - 1)*(m - 1) << endl;

	

	return 0;
}

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

d1=0
d2=0
d3=0
d9=0
for i in range(n):
    if x[i]>y[i]:
        d=x[i]-y[i]
    else:
        d=y[i]-x[i]
    d1+=d

for i in range(n):
    d=(x[i]-y[i])**2
    d2+=d
d2=d2**(1/2)

for i in range(n):
    if x[i]>y[i]:
        d=(x[i]-y[i])**3
    else:
        d=(y[i]-x[i])**3
    d3+=d
d3=d3**(1/3)
z=[]
for i in range(n):
    if x[i]>y[i]:
        d=x[i]-y[i]
    else:
        d=y[i]-x[i]
    z.append(d)
d9=max(z)

print(f'{d1:.6f}')
print(f'{d2:.6f}')
print(f'{d3:.6f}')
print(f'{d9:.6f}')


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

vector<long long> s;
int n;

bool isOK(long long mid){
    long long m = mid;
    for (size_t i = 0; i <= n; i++)
    {
        std::vector<long long>::iterator it_j = lower_bound(s.begin() + i, s.end(), m + s[i]);
        if (s.end() <= it_j){
            continue;
        }
        std::vector<long long>::iterator it_k = lower_bound(it_j, s.end(), m + *it_j);
        if (s.end() <= it_k){
            continue;
        }
        if((s[n] - (*it_k - s[i]) ) < m){
            continue;
        }
        return true;
    }
    return false;
}

int main(void)
{
    cin >> n;
    s.resize(n);

    s[0] = 0;

    for (size_t i = 0; i < n; ++i)
    {
        int a;
        cin >> a;
        s[i+1] = s[i] + a;
    }
    
    long long  MaxOfMin = 0;
    long long  PossibleMaxM = s[n] / 3;

    long long ng = PossibleMaxM; //「m = 0」が条件を満たすこともあるので、初期値は -1
    long long ok = -1;

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    // for (long long m = 0; m <= PossibleMaxM; m++)
    // {
    //     for (size_t i = 0; i <= n; i++)
    //     {
    //         std::vector<long long>::iterator it_j = lower_bound(s.begin() + i, s.end(), m + s[i]);
    //         if (s.end() <= it_j){
    //             continue;
    //         }
    //         std::vector<long long>::iterator it_k = lower_bound(it_j, s.end(), m + *it_j);
    //         if (s.end() <= it_k){
    //             continue;
    //         }
    //         if((s[n] - (*it_k - s[i]) ) < m){
    //             continue;
    //         }
    //         MaxOfMin = m;
    //         break;
    //     }
    // }
    
    cout << ok << endl;
    return 0;   
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N,M;
ll a[105],weight[15];
map<ll,bool> MAP,PRE,CURRENT;
vector<ll> V,CAN_NOT;

void recursive(int index,ll add_sum){

	if(index == M){

		MAP[add_sum] = true;
		V.push_back(add_sum);

		return;
	}

	//足さない
	recursive(index+1,add_sum);

	//+(-weight[index])
	recursive(index+1,add_sum-weight[index]);

	//+weight[index]
	recursive(index+1,add_sum+weight[index]);
}

void func(){

	MAP.clear();
	V.clear();
	CAN_NOT.clear();
	PRE.clear();
	CURRENT.clear();

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

		scanf("%lld",&a[i]);
	}

	for(int i = 0; i < M; i++){

		scanf("%lld",&weight[i]);
	}

	recursive(0,0);

	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	bool FLG = true;

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

		auto at = MAP.find(a[i]);

		if(at == MAP.end()){
			FLG = false;
			CAN_NOT.push_back(a[i]);
		}
	}

	if(FLG){
		printf("0\n");
		return;
	}

	ll ans = HUGE_NUM;

	for(int i = 0; i < V.size(); i++){

		PRE[abs(CAN_NOT[0]-V[i])] = true;
		if(CAN_NOT.size() == 1){ //コーナーケース

			ans = min(ans,abs(CAN_NOT[0]-V[i]));
		}
	}

	for(int i = 1; i < CAN_NOT.size(); i++){

		for(int k = 0; k < V.size(); k++){

			auto at = PRE.find(abs(CAN_NOT[i]-V[k]));

			if(at != PRE.end()){

				CURRENT[abs(CAN_NOT[i]-V[k])] = true;

				if(i == CAN_NOT.size()-1){

					ans = min(ans,abs(CAN_NOT[i]-V[k]));
				}
			}
		}

		PRE.clear();
		PRE = CURRENT;
		CURRENT.clear();
	}

	if(ans == HUGE_NUM){

		printf("-1\n");
	}else{

		printf("%lld\n",ans);
	}
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 11364
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define mod 1000000007

char lis[] = "AGCT";

bool check_agc(char *last) {
    if ((last[0] == 'A') && (last[1] == 'G') && (last[2] == 'C')) return false;
    if ((last[1] == 'A') && (last[2] == 'G') && (last[3] == 'C')) return false;
    return true;
}

bool check(char *last) {
    if (!check_agc(last)) return false;
    for (int i=0; i<3; i++) {
        char buf = last[i];
        last[i] = last[i+1];
        last[i+1] = buf;
        if (!check_agc(last)) {
            last[i+1] = last[i];
            last[i] = buf;
            return false;
        }
        last[i+1] = last[i];
        last[i] = buf;
    }
    return true;
}

int ret_num(char *s) {
    int buf = 0;
    if (s[0] == 'G') buf += 16;
    else if (s[0] == 'C') buf += 32;
    else if (s[0] == 'T') buf += 48;
    if (s[1] == 'G') buf += 4;
    else if (s[1] == 'C') buf += 8;
    else if (s[1] == 'T') buf += 12;
    if (s[2] == 'G') buf += 1;
    else if (s[2] == 'C') buf += 2;
    else if (s[2] == 'T') buf += 3;
    return buf;
}

long int counting(char *last, int count, int n, int **mem) {
    long int buf = 0;
    if (count == n) return 1;
    int num = ret_num(last);
    if (mem[count][num] != -1) return mem[count][num];
    for (int i=0; i<4; i++) {
        last[3] = lis[i];
        if (check(last)) {
            char last_next[5];
            for (int i=0; i<4; i++) {
                last_next[i] = last[i+1];
            }
            last_next[4] = '\0';
            buf = (buf + counting(last_next, count+1, n, mem)) % mod;
        }
    }
    mem[count][num] = buf;
    return buf;
}

int main() {
    int n = 0;
    scanf("%d", &n);
    long int memo[n][64];
    long int *mem[n];
    for (int i=0; i<n; i++) {
        for (int j=0; j<64; j++) {
            memo[i][j] = -1;
        }
        mem[i] = memo[i];
    }
    long int ans = 0;
    char last[] = "TTTT";
    ans = counting(last, 0, n, mem);
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int gcd(int a, int b, int& x, int& y){
	if(b == 0){
		x = 1;
		y = 0;
		return a;
	}
	int ret = gcd(b, a % b, y, x);
	y -= (a / b) * x;
	return ret;
}

int main(){
	FIO
	
	int a, b;
	cin >> a >> b;
	int x, y;
	gcd(a, b, x, y);
	cout << x << ' ' << y << '\n';
	return 0;
}



Measured memory_bytes: 3160
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

s = sum(a)
l = [0] * 10**6
for ai in a:
    l[ai-1] += 1

for i in range(q):
    s += (bc[i][1] - bc[i][0]) * l[bc[i][0]-1]
    l[bc[i][1]-1] += l[bc[i][0]-1]
    l[bc[i][0]-1] = 0
    print(s)

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

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner scan = new Scanner(System.in);
int        N = scan.nextInt();
long A[]=new long [N];
long p=0;
for(int i=0;i<N;i++){
    A[i]=scan.nextLong();
    if(i>0){if(A[i]<A[i-1]){p=p+A[i-1]-A[i];
    A[i]=A[i-1];}}

}
System.out.println(p);
    }
}


Measured memory_bytes: 51496
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 1000
using namespace std;
char s[N][N];
int d[N][N],p[N*N][2],tail,ans,n,m,k,sx,sy,step[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
void bfs()
{
	memset(d,63,sizeof(d));
	p[1][0]=sx;p[1][1]=sy;tail=1;
	d[sx][sy]=0;
	for(int i=1;i<=tail;i++)
	{
		int x=p[i][0],y=p[i][1];
		for(int j=0;j<4;j++)
		{
			int xx=x+step[j][0],yy=y+step[j][1];
			if(xx>0 && xx<=n && yy>0 && yy<=m && d[xx][yy]>d[x][y]+1 && s[xx][yy]=='.')
			{
				d[xx][yy]=d[x][y]+1;
				p[++tail][0]=xx;p[tail][1]=yy;
			}
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) 
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) if(s[i][j]=='S') sx=i,sy=j;
	}
	bfs();
	ans=999999999;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(d[i][j]>k) continue;
			int t=min(min(i-1,n-i),min(j-1,m-j));
			if(t==0) {printf("1\n");return 0;}
			int tt=t/k;
			if(t%k) tt++;
			ans=min(ans,tt);
		}
	printf("%d\n",ans+1);
	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d) {
        printf("Yes\n");
        return 0;
    }
    if ( abs(a - b) <= d && abs(c - b) <= d) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  long result = 0;
  for (int i = 0; i < n; ++i) {
    result += i;
  }
  cout << result;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int     number,cnt,i,b;
    int     a[100000];

    scanf("%d",&number);
    scanf("%d",&b);

    cnt=0;
    while(number>0)
    {
        a[cnt]=number%b;
        number=number/b;
        cnt++;
    }
    printf("%d",cnt);
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

    vector<int> hv;
    for (int i = 0; i < N; i++) {
        int h;
        cin >> h;
        hv.push_back(h);
    }
    sort(hv.begin(), hv.end());

    vector<int> hdiff;
    for (int i = 0; i + K - 1 < N; i++) {
        hdiff.push_back(hv[i + K - 1] - hv[i]);
    }

    sort(hdiff.begin(), hdiff.end());

    cout << hdiff[0] << endl;

    return 0;
}


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


namespace ConsoleApp15
{
    class Class336
    {
        readonly static long mod = 998244353;
        static long N, M, K;
        static void Main()
        {
            var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = nmk[0]; M = nmk[1]; K = nmk[2];
            var md = new Modular(N);
            var ans = 0L;
            for(int i = 0; i < K + 1; i++)
            {
                ans += Calc(i);
            }
            Console.WriteLine(ans % mod);
        }
        static long Calc(int num)
        {
            
            var r = M * Modular.Ncr((int)N - 1, num) * Modular.Pow(M - 1, (int)N - 1 - num);
            return (long)r;
        }
    }
    class Modular
    {
        private const int M = 998244353;
        private long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return a.value + b.value;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    var p = Pow(a, n / 2);
                    return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        public static Modular Fac(int n)   //階乗
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Ncr(int n, int r) //nCr
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : Fac(n) / (Fac(r) * Fac(n - r));
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }
    }
}


Measured memory_bytes: 42916
#include <iostream>

using namespace std;
int a,b;
int s;
int n;
int main(){
  int counter=0;
  cin >> n;
  for (int i=1;i<=n;i++) {
    int temp=0;
    if(i%2==0)
        continue;
    else{
      for (int j=1;j<=n;j++) {
        if(i%j==0)
          temp++;
      }
      if(temp==8)
        counter++;
    }
  }
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

#define MAXN 600

typedef array<short,4> tile;

int n;
tile a[MAXN];
long d[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++)
		for (int j=0; j<4; j++)
			scanf("%hd", &a[i][j]);
	return 1;
}

void init() {
}

tile rotate(const tile &x, int k=1) {
	tile y;
	for (int i=0; i<4; i++) y[(i+k) % 4] = x[i];
	return y;
}

tile normalize(const tile &x) {
	tile z=x;
	for (int i=1; i<4; i++) {
		tile y=rotate(x, i);
		if (y<z) z=y;
	}
	return z;
}

int mirror(const tile &x) {
	int r = 1;
	for (int i=1; i<4; i++) {
		tile y=rotate(x, i);
		if (y==x) r++;
	}
	return r;
}

tile get_face(const tile &u, const tile &d, int x, int y) {
	return normalize({u[x], u[y], d[3-y], d[3-x]});
}

//use id to speed up
long id(const tile &x) {
	return x[0]*1000000000L + x[1]*1000000L + x[2]*1000L + x[3];
}

long get_face_id(const tile &u, const tile &d, int x, int y) {
	long z = id({u[x], u[y], d[3-y], d[3-x]});
	long r = z;
	for (int i=0; i<3; i++) {
		z = z/1000L + z%1000L * 1000000000L;
		if (z<r) r = z;
	}
	return r;
}

long solve() {
	map<long,long> ct;
	map<long,long> mi;
	for (int i=0; i<n; i++) {
		a[i] = normalize(a[i]);
		d[i] = id(a[i]);
		ct[d[i]]++;
		mi[d[i]] = mirror(a[i]);
	}
	long ans = 0;
	for (int i=0; i<n; i++) {
		ct[d[i]]--;
		for (int j=i+1; j<n; j++) {
			ct[d[j]]--;
			for (int k=0; k<4; k++) {
				tile d=a[i], u=rotate(a[j], k);
				//tile f[4];
				long g[4];
				long r = 1;
				for (int t=0; t<4; t++) {
					//f[t] = get_face(u, d, t, (t+3)%4);
					//g[t] = id(f[t]);
					g[t] = get_face_id(u, d, t, (t+3)%4);
					auto p = ct.find(g[t]);
					if (p == ct.end()) {
						r = 0;
						break;
					}
					r *= mi[g[t]] * (p->second--);
				}
				//printf("* %d %d %d: %ld\n", i, j, k, r);
				ans += r;
				for (int t=0; t<4; t++) {
					auto p = ct.find(g[t]);
					if (p == ct.end()) break;
					p->second++;
				}
			}
			ct[d[j]]++;
		}
		ct[d[i]]++;
	}
	return ans/3;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int maxn=55;
int dfn[maxn],low[maxn];
int vis[maxn],bridge[maxn][maxn];
vector<int> g[maxn];

void tarjan(int cur,int father,int dep)
{
    int child=0;
    vis[cur]=1;dfn[cur]=low[cur]=dep;
    for(int i=0;i<g[cur].size();i++)
    {
        int j=g[cur][i];
        if(j!=father && vis[j]==1)
            low[cur]=min(low[cur],dfn[j]);
        if(vis[j]==0)
        {
            tarjan(j,cur,dep+1);
            child++;
            low[cur]=min(low[cur],low[j]);

            if(low[j]>dfn[cur])
            {
                 bridge[cur][j]=1;
                // cout<<cur<<":"<<j<<endl;
            }

        }
    }
}

int main()
{
    int n,m;
    int ans=0;
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        bridge[i][j]=0;
    memset(vis,0,sizeof(vis));
    tarjan(1,-1,0);

    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(bridge[i][j])
        ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> B(N - 1);
  for_each(begin(B), end(B), [](auto& x) { cin >> x; });
  B.emplace_back(2000000);

  ll ans = B[0];
  for (ll i = 0; i < N-1; i++) {
    ans += min(B[i], B[i + 1]);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int linearSearch(int A[], int n, int key){
  int i = 0;

  A[n] = key;
  while(A[i] != key)
    i++;
  if(i == n)   return 0;
  else         return 1;
}

int main(){
  int n, S[10000], q, T[10000], i, cnt = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &S[i]);

  scanf("%d", &q);
  for(i = 0; i < q; i++)
    scanf("%d", &T[i]);
   
  for(i = 0; i < n; i++)
    if(linearSearch(S, n, T[i]) == 1 && i < q)
      cnt++;

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 648
#include <iostream>

int main(){
  int a, b, c;
  std::cin >> a >> b >> c;

  if(a == b + c || b == a + c || c == a + b){
    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }
  return 0;
}


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

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);

    ArrayList<String> list1 = new ArrayList<String>();
    for (int i = 0; i < n; i++){
      list1.add(br.readLine());
    }
    for(int i = 1; i <= 13; i++){
      if (list1.contains("S " + i) == false)
        System.out.println("S " + i);
    }
    for(int i = 1; i <= 13; i++){
      if (list1.contains("H " + i) == false)
        System.out.println("H " + i);
    }
    for(int i = 1; i <= 13; i++){
      if (list1.contains("C " + i) == false)
        System.out.println("C " + i);
    }
    for(int i = 1; i <= 13; i++){
      if (list1.contains("D " + i) == false)
        System.out.println("D " + i);
    }
  }
}

Measured memory_bytes: 24232
A = int(input())
B = int(input())

ans = 0
if (A == 1 and B == 2) or (A == 2 and B == 1):
    ans = 3
elif (A == 1 and B == 3) or (A == 3 and B == 1):
    ans = 2
elif (A == 2 and B == 3) or (A == 3 and B == 2):
    ans = 1

print(ans)


Measured memory_bytes: 3060