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

using namespace std;
int main()
{
    int N;
    int cnt=0;
    bool flag=false;
    cin >> N;
    for(int i=0; i<N; i++)
    {
        int d1, d2;
        cin >> d1 >> d2;

        if(d1==d2)
        {
            cnt++;
            if(cnt==3) 
            {
                flag = true;
            }
        }
        else
        {
            cnt=0;
        }
    }
    if(flag) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3588
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	if i < N - 2:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[N - 1])


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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())

const ll inf = 1 << 25;
const ll mod = 1e9 + 7;

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int ans = max(min(B, D) - max(A, C), 0);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n, m;
ll cnt[100005];
int p[100001];
ll ans = 0;

int main() {
	std::cin >> n >> m;
	std::cin >> p[0];
	--p[0];
	REP(i, 1, m) {
		std::cin >> p[i];
		--p[i];
		++cnt[std::min(p[i - 1], p[i])], --cnt[std::max(p[i - 1], p[i])];
	}

	REP(i, 1, n - 1)cnt[i] += cnt[i - 1];

	rep(i, n - 1) {
		int a, b, c;
		std::cin >> a >> b >> c;
		ans += std::min((ll)a * cnt[i], (ll)b * cnt[i] + c);
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 2328
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define readvec(vec) for(auto& e: vec){cin >> e;}
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int >    vecint;
typedef vector<ll >      vecll;
typedef vector<double >   vecd;
typedef vector<string > vecstr;
typedef vector<char >  vecchar;
typedef vector<bool >  vecbool;
typedef vector<vector<bool> >  vec2bool;
typedef vector<vector<int> >    vec2int;
typedef vector<vector<double> >   vec2d;
////////////////////////////////////////////////
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main()
{
  init();
  int n; cin >> n;
  map<int, int > mp;  int tmp;
  REP(i,n){
    cin >> tmp;
    mp[tmp]++;
  }
  if(mp.size() == 1){
    if(mp.count(0) > 0 && mp[0] == n){
      cout << "Yes" << endl;
      return 0;
    }
  }else if(n%3 == 0 && mp.size() == 2){
    if(mp.count(0) > 0 && mp[0] == n/3){
      auto itr = mp.begin();itr++;
      if(itr->second == 2*(n/3)){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }else if(n%3 == 0 && mp.size() == 3){
    bool ok = true;
    REPvec(itr, mp){
      if(itr->second != n/3){
	ok = false;
      }
    }
    auto itr = mp.begin();
    int x = itr->first;itr++;
    int y = itr->first;itr++;
    int z = itr->first;
    // if((x^(y^z)) != 0)ok = false;
    if((int)(x^y) != z||(int)(y^z) != x||(int)(z^x) != y)ok = false;
    if(ok){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL a(n);
  rep(i, n) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(all(a));
  ll b = a[n/2];
  ll ans = 0;
  rep(i, n) ans += abs(b - a[i]);
  out(ans);
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    lint ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pai acos(-1)
#define maxe max_element
#define mine min_element
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(itr,s) for(itr=s.begin();itr!=s.end();itr++)
#define W while
#define pp pair<ll,ll>
#define ppi pair<int,int>
#define vl vector<ll>
#define vll vector<pp >
#define vi vector<int>
#define vii vector<ppi>
#define debug(x) cerr<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define SIZE 5000 + 1
const ll MAX=1e9;
const ll mod=998244353;
ll expo(ll x,ll n,ll M=mod)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1){ans=(ans*x)%M;}
                x=(x*x)%M;
                n>>=1;
    }
    return ans;
}


void solve()
{

 ll n;
 cin>>n;
 string s;
 set<string> st;
 while(n--)
 {
     cin>>s;
     st.insert(s);
 }
 cout<<st.size()<<endl;


}

int main()
{
  boost;
  ll t=1;
 // cin>>t;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 19208
#!/usr/bin/node
// Generated by CoffeeScript 1.3.3 (minified manually)
(function() {
	var a=[],stdin;
	stdin=process.openStdin();
	stdin.setEncoding('utf8');

	var input_fragment="";
	stdin.on('data', function(input) {
			var ref=(input_fragment+input).split("\n");
			input_fragment=ref.pop();
			for(var i=0;i<ref.length;i++){
				if(ref[i]=='')continue;
				a.push(ref[i]);
			}
	});

	stdin.on('end', function(z) {
		if(input_fragment){
			var ref=(input_fragment+"\n").split("\n");
			input_fragment=ref.pop();
			for(var i=0;i<ref.length;i++){
				if(ref[i]=='')continue;
				a.push(ref[i]);
			}
		}
		a.pop()
		for(var _i=0;_i<a.length;_i++){
			var b = a[_i].split(" ");
			for(var j=0;j<b.length;j++)b[j]=parseInt(b[j]);
			var n=b[0];
			var k=b[1];
			var m=b[2];
			var r=0,i=0;
			for(;++i<n;r%=i)r+=k;
			console.log((r+m)%n+1);
		}
	});
})();

Measured memory_bytes: 8736
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 1005;

inline int qPow(int b, LL e) {
	int a = 1;
	for (; e; e >>= 1, b = (LL)b * b % Mod)
		if (e & 1) a = (LL)a * b % Mod;
	return a;
}

int N, M, A, B, C; LL K;
char S[MN][MN];
int R[2][2], Q[2][2], tmp[2][2];

int main() {
	scanf("%d%d%lld", &N, &M, &K);
	if (!K) return puts("1"), 0;
	for (int i = 1; i <= N; ++i) {
		scanf("%s", S[i] + 1);
		for (int j = 1; j <= M; ++j)
			if (S[i][j] == '#') ++A;
	}
	int ok1 = 0, ok2 = 0;
	for (int i = 1; i <= N; ++i) if (S[i][1] == '#' && S[i][M] == '#') ++ok1;
	for (int j = 1; j <= M; ++j) if (S[1][j] == '#' && S[N][j] == '#') ++ok2;
	if (ok1 && ok2) return puts("1"), 0;
	if (!ok1 && !ok2) return printf("%d\n", qPow(A, K - 1)), 0;
	if (ok1) {
		C = ok1;
		for (int i = 1; i <= N; ++i)
			for (int j = 1; j < M; ++j)
				if (S[i][j] == '#' && S[i][j + 1] == '#') ++B;
	} else {
		C = ok2;
		for (int j = 1; j <= M; ++j)
			for (int i = 1; i < N; ++i)
				if (S[i][j] == '#' && S[i + 1][j] == '#') ++B;
	}
	Q[0][0] = A, Q[1][0] = B, Q[1][1] = C;
	R[0][0] = R[1][1] = 1;
	#define F(i) for (int i = 0; i < 2; ++i)
	--K;
	while (K) {
		if (K & 1) {
			F(i) F(j) tmp[i][j] = 0;
			F(i) F(j) F(k) tmp[i][k] = (tmp[i][k] + (LL)R[i][j] * Q[j][k]) % Mod;
			F(i) F(j) R[i][j] = tmp[i][j];
		}
		F(i) F(j) tmp[i][j] = 0;
		F(i) F(j) F(k) tmp[i][k] = (tmp[i][k] + (LL)Q[i][j] * Q[j][k]) % Mod;
		F(i) F(j) Q[i][j] = tmp[i][j];
		K >>= 1;
	}
	printf("%d\n", (R[0][0] - R[1][0] + Mod) % Mod);
	return 0;
}

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

int     main()
{
  int   N;
  int	N_copy;
  int   fx;
  cin >> N;
  
  N_copy = N;
  while (N_copy >= 1)
  {
    fx += N_copy % 10;
    N_copy /= 10;
  }
  //cout << N << endl << N_copy << endl << fx << endl;
  if (N % fx == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
int main(){
  int r,g,b; cin>>r>>g>>b;
  int judge=10*g+b;
  if( judge%4==0){
    cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int a, b, k;
	cin >> a >> b >> k;
	
	int counter = 0;
	for (int i = max(a, b); i >= 0; i--)
	{
		if (((a % i) == 0) && ((b % i) == 0))
		{
			counter++;
		}
		
		if (counter == k)
		{
			cout << i << endl;
			break;
		}
	}

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 256
import math
import sys
readline = sys.stdin.readline


def main():
    n, m = map(int, readline().rstrip().split())
    aList = sorted(list(map(int, readline().rstrip().split())), reverse=True)
    aSum = sum(aList)
    mLine = aSum / (4 * m)
    print("Yes" if aList[m - 1] >= mLine else "No")


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    int brojObrtanja = 0;
    deque<char> levi, desni;
    for(int i = 0; i < q; ++i)
    {
        int t;
        cin >> t;
        if(t==1)
        {
            brojObrtanja = (brojObrtanja+1)%2;
        }
        else
        {
            int f;
            char c;
            cin >> f >> c;
            if(f==1)
            {
                if(brojObrtanja==0)
                {
                    levi.push_front(c);
                }
                else
                {
                    desni.pb(c);
                }
            }
            else
            {
                if(brojObrtanja==0)
                {
                    desni.pb(c);
                }
                else
                {
                    levi.push_front(c);
                }
            }
        }
    }

    if(brojObrtanja==0)
    {
        for(deque<char>::iterator it = levi.begin(); it != levi.end(); ++it)
        {
            cout << *it;
        }
        cout << s;
        for(deque<char>::iterator it = desni.begin(); it != desni.end(); ++it)
        {
            cout << *it;
        }
        cout << '\n';
    }
    else
    {
        for(deque<char>::reverse_iterator it = desni.rbegin(); it != desni.rend(); ++it)
        {
            cout << *it;
        }
        reverse(all(s));
        cout << s;
        for(deque<char>::reverse_iterator it = levi.rbegin(); it != levi.rend(); ++it)
        {
            cout << *it;
        }
        cout << '\n';
    }

    return 0;
}


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

int main() {

    int n,h;

    cin >> n >> h;

    priority_queue<int> q;

    int a_max = 0;

    while(n--){

        int a,b;

        cin >> a >> b;

        a_max = max(a_max,a);

        q.push(b);
    }

    int count = 0;

    while(!q.empty() && q.top() >= a_max && h > 0){
        h -= q.top();
        q.pop();
        count++;
    }

    if(h > 0){
        if(h%a_max != 0){
            count++;
        }
        count += h/a_max;
    }

    cout << count << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
int n,r,c;
pair<int,pii>a[maxn];
ll ans;

namespace Dsu{
	int f[maxn*3],cnt1[maxn*3],cnt2[maxn*3];
	void init(){
		REP(i,n+r+c)f[i]=i;
		REP(i,n)cnt1[i]=1;
		for(int i=n+1;i<=n+r+c;i++)cnt2[i]=1;
	}
	int find(int x){
		return f[x]==x?x:f[x]=find(f[x]);
	}
	void merge(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		f[x]=y;
		cnt1[y]+=cnt1[x];
		cnt2[y]+=cnt2[x];
	}
}

int main(){
	scanf("%d%d%d",&n,&r,&c);
	REP(i,n)scanf("%d%d%d",&a[i].snd.fst,&a[i].snd.snd,&a[i].fst);
	sort(a+1,a+1+n);
	Dsu::init();
	for(int i=n;i>=1;i--){
		int u=Dsu::find(a[i].snd.fst+n),v=Dsu::find(a[i].snd.snd+n+r),cur1=0,cur2=0;
		if(u==v)cur1=Dsu::cnt1[u],cur2=Dsu::cnt2[u];
		else cur1=Dsu::cnt1[u]+Dsu::cnt1[v],cur2=Dsu::cnt2[u]+Dsu::cnt2[v];
		cur1++;
		if(cur1>cur2)continue;
		ans+=a[i].fst;
		Dsu::merge(i,u);
		Dsu::merge(i,v);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
using namespace std;
 
int main() {
	int x,y,z;
	cin >> x >> y >> z;
 
	int t;
	t = y;
	y = x;
	x = t;
 
	t = z;
	z = x;
	x = t;
	cout << x << " " << y << " " << z;
	return 0;
}

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


#define rep(i, n) for(int i = 0; i < (n); i++)
using ULL = unsigned long long;


vector<int> p[10000];
int h[10000];

void solve() {
	int n; cin >> n;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		p[a-1].push_back(b-1);
		p[b-1].push_back(a-1);
	}

	int c[10000];
	rep(i, n) cin >> c[i];
	sort(c, c + n);
	int cp = n - 1;

	int ans[10000];
	long long M = 0;

	stack<int> s;
	s.push(0); h[0] = -1;
	while (!s.empty()) {
		int q = s.top(); s.pop();
		rep(i, p[q].size()) {
			if (p[q][i] == h[q]) continue;
			h[p[q][i]] = q;
			s.push(p[q][i]);
		}
		ans[q] = c[cp];
		cp--;
	}

	for (int i = 0; i < n - 1; i++) {
		M += c[i];
	}

	cout << M << endl;
	rep(i, n) {
		if (i != 0) cout << " ";
		cout << ans[i];
	}
}

int main() {

	solve();

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> S(H,vector<char>(W));
  int black=0,white=0;
  rep(y,H){
    rep(x,W){
      cin >> S[y][x];
      if(S[y][x]=='#') black++;
    }
  }
  white = H*W-black;
  vector<vector<ll>> D(H,vector<ll>(W));
  vector<vector<bool>> chacked(H,vector<bool>(W));
  rep(h,H) rep(w,W){D[h][w]=1e9;chacked[h][w]=false;}
  queue<pair<int,int>> q;
  q.push(make_pair(0,0));
  D[0][0] = 0;
  chacked[0][0] = true;
  while(!q.empty()){
    pair<int,int> now = q.front(); q.pop();
    if(now.first!=0){
      if(S[now.first-1][now.second] == '.'){
        D[now.first-1][now.second] = min(D[now.first-1][now.second],D[now.first][now.second]+1);
        if(!chacked[now.first-1][now.second]){
          q.push(make_pair(now.first-1,now.second));
          chacked[now.first-1][now.second] = true;
        }
      }
    }
    if(now.second!=0){
      if(S[now.first][now.second-1] == '.'){
        D[now.first][now.second-1] = min(D[now.first][now.second-1],D[now.first][now.second]+1);
        if(!chacked[now.first][now.second-1]) {
          q.push(make_pair(now.first,now.second-1));
          chacked[now.first][now.second-1] = true;
        }
      }
    }
    if(now.first!=H-1){
      if(S[now.first+1][now.second] == '.'){
        D[now.first+1][now.second] = min(D[now.first+1][now.second],D[now.first][now.second]+1);
        if(!chacked[now.first+1][now.second]){
          q.push(make_pair(now.first+1,now.second));
          chacked[now.first+1][now.second] = true;
        }
      }
    }
    if(now.second!=W-1){
      if(S[now.first][now.second+1] == '.'){
        D[now.first][now.second+1] = min(D[now.first][now.second+1],D[now.first][now.second]+1);
        if(!chacked[now.first][now.second+1]) {
          q.push(make_pair(now.first,now.second+1));
          chacked[now.first][now.second+1] = true;
        }
      }
    }
  }
  if(D[H-1][W-1] >= 1e5) cout << -1 << endl;
  else cout << white-D[H-1][W-1]-1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>

struct Stack {
  int i = {};
  int v[100];

  void push(int x) { v[i++] = x; };

  int pop() { return v[--i]; };

  void print() {
    for (int j = 0; j < i; j++) {
      std::cout << v[j];
      if (j < i - 1)
        std::cout << " ";
      else
        std::cout << std::endl;
    }
  };
};

int main() {
  Stack stack;

  std::string s;
  while (std::getline(std::cin, s, ' ')) {
    if (*(s.end() - 1) == '\n') s.pop_back();
    if (s == "+") {
      stack.push(stack.pop() + stack.pop());
    } else if (s == "-") {
      int x = stack.pop();
      stack.push(stack.pop() - x);
    } else if (s == "*") {
      stack.push(stack.pop() * stack.pop());
    } else {
      stack.push(std::atoi(s.c_str()));
    }
    // stack.print();
  }

  std::cout << stack.pop() << std::endl;
}



Measured memory_bytes: 3220
const main = (inputs) => {
  var N = inputs[0]-0;
  var list = inputs[1].split(" ").map(v=>v-0);
  var ans = 0;
  list = list.sort((a,b)=>a-b);

  console.log(list[N/2]-list[N/2-1]);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 28376
N = int(input())
ans = N

# n = 6で取り出すお金
for n in range(N + 1):
    c = 0
    price_by_6 = n
    while price_by_6 > 0:
        c += price_by_6 % 6  # これを繰り返すと必要な回数になる。まず初回にあまりがある場合には1円が必要な分だけ足される。
        price_by_6 //= 6
    price_by_9 = N - n
    while price_by_9 > 0:
        c += price_by_9 % 9  # これを繰り返すと必要な回数になる。まず初回にあまりがある場合には1円が必要な分だけ足される。
        price_by_9 //= 9
    ans = min(ans, c)

print(ans)


Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int tree[400009],ar[100009] ;
vector<pii>v ;
void build(int p , int lo , int hi)
{
    if(lo==hi){tree[p]=ar[lo] ; return ; }
    int md=(lo+hi)/2 ;
    build(p*2,lo,md) ;
    build(p*2+1,md+1,hi) ;
    tree[p]=max(tree[p*2],tree[p*2+1]) ;
}
int query(int p , int lo , int hi , int l , int r)
{
    if(lo>=l && hi<=r) return tree[p] ;
    if(l>hi || r<lo) return 0 ;
    int md=(lo+hi)/2 ;
    int x=query(p*2,lo,md,l,r) , y=query(p*2+1,md+1,hi,l,r) ;
    return max(x,y) ;
}
int main()
{
    int n,t,mx=-1 ; cin>>n>>t ;
    for(int i = 1 ; i <= n ; i++) cin>>ar[i] ;
    build(1,1,n) ;
    for(int i = 1 ; i < n ; i++)
    {
        int x=ar[i] ;
        int y=query(1,1,n,i+1,n) ;
        if(y-x>0 && y-x>mx)
        {
            mx=y-x ;
            v.clear() ; v.push_back({y,x}) ;
        }
        else if(y-x>0 && y-x==mx) v.push_back({y,x}) ;
    }
    cout<<v.size()<<endl ;
}


Measured memory_bytes: 5164
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for(int i=0; i<N; i++)
			p[i] = sc.nextInt();
		
		int ans = 0;
		for(int i=1; i<N-1; i++)
			if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1]))
				ans++;
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <limits>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while (cin>>n, n) {
        map<int, int> m;
        int c=0, res=0, a;
        for (int i=0; i<n; ++i) {
            cin >> a;
            int &ma = m[a];
            ++ma;
            if (c < ma) {
                c = ma; res = a;
            }
            if (n < c*2) {
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                break;
            }
        }
        if (n < c*2) {
            cout << res << endl;
        } else {
            cout << "NO COLOR" << endl;
        }
    }
    return 0;
}

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

int min_prime(int x,int y){
  if(x==0||y==0){
    return (x>y ? x : y);
  }else{
    return (x>y ? y : x);
  }
}

int main(){
  int n,q,q_max=0;
  vector<int> A,Q;
  
  cin >> n;
  for(int i=0,j;i<n;i++){
    cin >> j;
    A.push_back(j);
  }
  cin >> q;
  for(int i=0,j;i<q;i++){
    cin >> j;
    Q.push_back(j);
    q_max > j ? : q_max = j;
  }

  vector< vector<int> > DP;
  DP.resize(n+1);
  for(int i=0;i<=n;i++){
    for(int j=0;j<=q_max;j++){
      DP[i].push_back(0);
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<=q_max;j++){
      if(j<A[i]){
        DP[i+1][j] = DP[i][j];
      }else if(j==A[i]){
        DP[i+1][j] = 1;
      }else{
        DP[i+1][j] = min_prime(DP[i][j], DP[i][j-A[i]]);
	if(DP[i+1][j]>0 && DP[i+1][j]+1<DP[i][j]){
	  DP[i+1][j]++;
	}
      }
    }
  }
  for(const auto& it : Q){
    if(DP[n][it] != 0) cout << "yes" <<endl;
    else cout << "no" << endl;
  }
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const ll INF = 10000000000;
const int MOD = 1000000007;

int main(){
    while(1){
        int n,p;
        cin >> n >> p;
        if(n == 0 && p == 0) break;
        int cnt = p;
        vector<int> a(n,0);
        int i = 0;
        while(1){
            if(cnt > 0) --cnt,++a[i];
            else cnt+=a[i],a[i]=0;
            if(a[i] == p){
                cout << i << endl;
                break;
            }
            ++i;
            if(i==n) i=0;
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include<iostream>

using namespace std;

int main(void){
  int a,b,c,d;
  int n;
  while(cin >> n){
    int count = 0;
    for(a = 0; a < 10;a++){
      for(b = 0;b < 10;b++){
	for(c = 0;c < 10;c++){
	  for(d = 0;d < 10;d++){
	    if(a + b + c + d == n){
	      count++; 
	    }
	  }
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N=int(input())
if 1<=N and N<=9:
  print(N)
elif 10<=N and N<=99:
  print(9)
elif 100<=N and N<=999:
  print(N-90)
elif 1000<=N and N<=9999:
  print(909)
elif 10000<=N and N<=99999:
  print(N-90-9000)
else:
  print(90909)

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

int main()
{
	int l;
	cin>>l;
	string s;
	cin>>s;
	int ans=1;
	char last=s[0];
	for(int i=1;i<l;i++)
	{
		if(last!=s[i]){ans++;last=s[i];}
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

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

#define pb push_back

const int INF = 100100100;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

int main(){

  int a,b;
  int tmp;
  cin >> a >> b;
  if( a < b){
    tmp = a;
    a = b;
    b = tmp;
  }

  while( a%b != 0){
    tmp = a;
    a = b;
    b = tmp%a;
  }

  cout << b << endl;
}

Measured memory_bytes: 3076
N = int(input())
R = [list(map(int, input().split())) for i in range(N)]
B = [list(map(int, input().split())) for i in range(N)]
R.sort(key=lambda x: x[1], reverse=True)
B.sort(key=lambda x: x[0])
count = 0
for i in range(N):  # B
    for j in range(N):  # R
        if R[j][0] < B[i][0] and R[j][1] < B[i][1]:
            count += 1
            R[j][0] = 1000000
            R[j][1] = 1000000
            B[i][0] = -1
            B[i][1] = -1
            break
print(count)


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

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

      long long q,n,k,i,count=0,j=0,l,r,ans=0,p,m,x;
      cin>>n>>k;
      long long a[k];
      for(i=0;i<k;i++)
     { cin>>a[i]; count+=a[i];
     }
     if(count>=n)
     cout<<"Yes";
     else cout<<"No";
      
      
    
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = set(map(int,input().split()))
def helper(A):
    v = min(A)
    ans = set()
    for a in A:
        if a%v!=0:
            ans.add(a%v)
    ans.add(v)
    return ans

while len(A)>1:
    A = helper(A)
print(min(A))

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pii = pair<int,int>;

template<typename T> ostream& operator<< (ostream& os,const vector<T>& vec){ os << "{"; for(T v:vec) os << v << ","; os << "}"; }
template<typename T> ostream& operator<< (ostream& os,const set<T>& st){ os << "{"; for(T v:st) os << v << ","; os << "}"; }
template<typename T,typename U> ostream& operator<< (ostream& os,const pair<T,U>& p){ os << "{" << p.first << "," << p.second << "}"; return os; }

int N;
string w[40];

int main(){
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> w[j];
        }

        int len[5] = {5, 7, 5, 7, 7};

        for (int j = 0; j < N; ++j) {
            int state = 0,acc = 0;
            for (int k = j; k < N && state < 5; ++k) {
                acc += (int)w[k].size();
                if (acc > len[state]) {
                    break;
                } else if (acc == len[state]) {
                    acc = 0; ++state;
                }
            }

            if (state == 5) {
                cout << (j+1) << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3132
n,m,v[10000],w[2500],W[2500],o,x,y,r;F(a){r=1;for(a=m*m;a--;)if(~w[a]&&v[x+a%m+n*(y+a/m)]-w[a])r=0;}main(d,t,f){for(;scanf("%d%d",&n,&m)*n;printf(f<n*n?"%d %d\n":"NA\n",1+f%n,1+f/n)){for(f=0;f<n*n;f++)scanf("%d",v+f);for(x=0;x<m*m;x++)scanf("%d",w+x);for(d=4;d--;){memcpy(W,w,4*m*m);for(x=m*m;x--;o=~w[x]?x:o)w[x]=W[m-1-x/m+x%m*m];for(y=0;y+m<=n;y++)for(x=0;x+m<=n;x++)if((t=x+o%m+(n+o/m)*y)<f?F(),r:0)f=t;}}}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll result = 0;
  
  ll n;
  cin >> n;
  vector<ll> v(n), c(n);
  for(i = 0; i < n; i++)
    cin >> v[i];
  for(i = 0; i < n; i++)
    cin >> c[i];
  for(i = 0; i < n; i++){
    if(v[i] - c[i] > 0)
      result += v[i] - c[i];
  }
    
    
    
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    if(s == "keyence") return puts("YES")*0;
    rep(i,s.size()){
        for(int l = 0; l + i < s.length();l++){
            //cout << s.substr(i,l) << endl;
            string t = s.substr(0,i);
            string f = s.substr(i+l);
            //cout << t+f << endl;
            if(t+f == "keyence"){
                return puts("YES")*0;
            }
        }
    }
    cout << "NO" << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    vector<char> go = {'N', 'W', 'S', 'E'};
    vector<int> cnt(4, 0);
    rep(i, S.size()) rep(j, 4) {
        if (S[i] == go[j]) ++cnt[j];
    }
    string ans = "Yes";
    if (cnt[0] > 0 && cnt[2] == 0) ans = "No";
    if (cnt[1] > 0 && cnt[3] == 0) ans = "No";
    if (cnt[2] > 0 && cnt[0] == 0) ans = "No";
    if (cnt[3] > 0 && cnt[1] == 0) ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
	{
        static const uint64_t kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

const int maxn = 1e5 + 100; 
int h[maxn], dp[maxn]; 
signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	int n;
	cin >> n;
	for(int i=1;i<=n;i++) cin >> h[i]; 
	dp[1] = 0, dp[2] = abs(h[1] - h[2]);
	for(int i=3;i<=n;i++) dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	cout << dp[n];  
}

/*
	Test input:
*/


Measured memory_bytes: 1024
w1, w2 = input().split()
a,b = map(int,input().split())
c = input()
l = [[w1,a],[w2,b]]
ans = ""
for i in range(2):
    x,y = l[i][0],l[i][1]
    if x==c:
        ans += str(y-1)
    else:
        ans += str(y)
    if i==0:
        ans += ' '

print(ans)

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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define MOD 1000000007


signed main()
{
	int a, n;
	cin >> n >> a;
	cout << (n - a + 1) << endl;
}

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

//素数判定
//#include <cmath>
bool is_prime(long long n) {
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (long long i = 3; i <= sqrt(n); i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll v(n + 1, 0);
	for (ll i = 2; i <= n; i++) {
		ll x = i;
		for (ll j = 2; j <= n; j++) {
			if (is_prime(x)) {
				v[x]++;
				break;
			}
			if (!is_prime(j)) continue;
			while (x % j == 0) {
				x /= j;
				v[j]++;
			}
		}
	}
	ll ans = 1;
	for (ll i = 1; i <= n; i++) {
		ans *= (v[i] + 1) % p;
		ans %= p;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	Scanner sc = new Scanner(System.in);
	int[] sosuu = new int[300000];
	public void run() {
		calcSosuu();
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 1) break;
			else calc(n);
		}
	}

	public void calc(int n){
		System.out.print(n + ":");
		for(int i = 0; i < n+1; i++){
			if(sosuu[i] == 1 && n % i == 0){
				System.out.print(" " + i);
			}
		}
		System.out.println();
	}
	public void calcSosuu(){
		sosuu[0] = -1;
		sosuu[1] = -1;
		for(int i = 2; i < 300000; i++){
			if(sosuu[i] == 0 && (i % 7 == 1 || i % 7 == 6)){
				sosuu[i] = 1;
				for(int j = i * 2; j < 300000; j = j + i){
					sosuu[j] = -1;
				}
			}
			else if(sosuu[i] == 0) sosuu[i] = -1;
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 25912
/*#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

void input() {
	CI N >> W;

	int temp;

	for (int i = 0; i < N;i++) {
		CI temp;
		value.push_back(temp);
		CI temp;
		weight.push_back(temp);
	}


	return;
}


int main(void) {
	input();

	for (int i = 0; i < N;i++) {
		for (int j = 0; j <= W;j++) {
			dp[i + 1][j] = max(dp[i + 1][j], value[i] + dp[i][j - weight[i]]);
		}
	}

	CO dp[N][W] E


	return 0;
}
*/

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;


double tempd = 0.0;



void input() {
	

	return;
}


int main(void) {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			CO i << "x" << j <<  "=" << i * j E 
		}
	}

	return 0;
}

Measured memory_bytes: 3096
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int N, A, B, C;
vector<int> l;

ll calc(ll sumMax)
{
	ll res;

	if (0 == sumMax) {
		return 0;
	}
	if (IsOdd(sumMax)) {
		if (IsOdd(sumMax / 2)) {
			res = 0;
		} else {
			res = 1;
		}
	} else {
		res = sumMax;
		if (IsOdd(sumMax / 2)) {
			res = res ^ 1;
		}
	}

	return res;
}

int main()
{
	ll A, B;
	cin >> A >> B;

	ll aAns = 0 < A ? calc(A - 1) : 0;
	ll bAns = calc(B);
	ll sum  = aAns ^ bAns;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    ll X;
    cin >> X;
    ll ans = 0;
    ll q = X / 500;
    ans += 1000 * q;
    X -= q * 500;
    if (X > 0)
    {
        ll y = X / 5;
        ans += 5 * y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  	ll n;
  	cin>>n;
  	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	ll ans=0;
	for(ll i=0;i<n-2;i++)
	{
	  for(ll j=i+1;j<n-1;j++)
	  {
	  	for(ll k=j+1;k<n;k++)
	  	{
	  	  if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k] && a[i]+a[j]> a[k])
			{
			  ans++;	
			}	
		}
	  }
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 3636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        a: u32,
        b: u32,
    };
    println!("{}", if (a + b) % 2 == 0 {(a + b) / 2} else {(a + b + 1)/ 2});
}


Measured memory_bytes: 4352
package main

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

func main() {
	scanInit()

	r := nextInt()
	g := nextInt()
	b := nextInt()
	n := nextInt()

	cnt := 0
	for ri := 0; ri <= 3000; ri++ {
		for gi := 0; gi <= 3000; gi++ {
			bib := n - ri*r - gi*g
			if bib%b != 0 {
				continue
			}
			if bib/b >= 0 && bib/b <= 3000 {
				cnt++
			}
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1800
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		
		//スキャナーで整数を2つ読み取る
	    Scanner sc = new Scanner(System.in);
	    String s1 = sc.next();
	    int a = Integer.parseInt(s1);
	    String s2 = sc.next();
	    int b = Integer.parseInt(s2);
	    double p = Math.pow(10, 9);
	    
	    //a、bが指定の条件(1から１０の９乗)内にあるか確認
	    if(1 <= a && a <= p){
	    	if(1 <= b && b <= p){
	    		//計算
	    		int d = a / b;
	    		int r = a % b;
	    		double f = (double)a / (double)b;
	    		
	    		//計算結果を表示
	    		System.out.println(d + " " + r + " " + String.format("%1$3f",f));
	    	}
	    }
	}
}

Measured memory_bytes: 17288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sample201
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            
            if(a % 2 == 1 && b % 2 == 1){
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> a(n+1,0);
  REP(i,m){
    int p;
    cin >> p;
    a[p]++;
  }
  int cost1=0;
  int cost2=0;
  for(int i=x; i<=n; i++){
    if(a[i]) cost1++;
  }
  for(int i=x; i>=1; i--){
    if(a[i]) cost2++;
  }
  cout << min(cost1,cost2) << endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
    }

    let x = a - b;
    let y = c - x;

    if y > 0 {
        print!("{}", y);
    } else {
        print!("0");
    }
}


Measured memory_bytes: 4352