akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<unordered_map>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    unordered_map<string, int> mp;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans = 0;
    for (auto p: mp) {
        int s = p.second;
        ans += (ll)s * (s - 1) / 2; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 10660
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
//A,T,G,C==0,1,2,3
//GCA
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 888
function Main(inp) {
    var input = inp.split('\n')[0].split(' ').map(function(n) {
        return Number(n);
    });
    var numbers = input[0];
    var colors = input[1];
    // 1個目 colors 通り
    // 2個目 colors - 1 通り, 3個目 colors - 1 通り, ...
    // colors * (colors - 1) ^ (numbers - 1)
    var patterns = colors * Math.pow(colors - 1, numbers - 1); 
    console.log(patterns);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
const int  M = 1e9 + 7;

vector<vector<double>> dp;

double f(int n, int heads, vector<double> &v)
{

	if(n == 0)
	{
		if(2*heads > v.size())
			return 1;
		else
			return 0;
	}

	if(dp[n][heads] != -1)
		return dp[n][heads];
	double t1 = (dp[n-1][heads + 1] == -1) ? f(n-1, heads + 1, v) : dp[n-1][heads + 1];
	double t2 = (dp[n-1][heads] == -1) ? f(n-1, heads, v) : dp[n-1][heads];
	//cout << n << " " << heads << " " << v[n] << endl;
	//return v[n] * f(n-1, heads + 1, v)  + (1-v[n])*f(n-1, heads, v);
	return v[n-1] * t1  + (1-v[n-1])*t2;
}

int main()
{

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

	int n, i, j, wt, m;
	
	cin >> n;
	vector<double> v(n);
	for(i = 0; i < n; i++)
		cin >> v[i];

	dp.resize(n + 1);
	for(i = 0; i <= n; i++)
		dp[i].resize(n + 1, 0);

	dp[0][0] = 1.0;

	//cout << setprecision(10) << f(n, 0, v);

	for(i = 1; i <= n; i++)             // i is for every coin...
	{
		for(j = 0; j <= i; j++)         // j is the number of heads
		{
			if(j == 0)
				dp[i][j] = dp[i-1][j] * (1.0 - v[i-1]);
			else
				dp[i][j] = dp[i-1][j-1] * v[i-1] + dp[i-1][j] * (1.0-v[i-1]);
		}

	}
	double sum = 0.0;
	for(i = (n+1)/2; i <= n; i++)
		sum += dp[n][i];
	cout << setprecision(10) << sum;
}


Measured memory_bytes: 74120
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int dp[41][1<<18];


int main(){
    int n,x,y,z;
    cin >> n >> x >> y >> z;
    int ng=0;
    ng|=1<<z;
    ng|=1<<y+z;
    ng|=1<<x+y+z;
    int mask=(1<<x+y+z+1)-1;
    dp[0][1]=1;
    for (int i = 0; i < n; i++) {
        for (int k = 0; k <= mask; k++) {
            for (int j = 1; j <= 10; j++) {
                int nx=(k<<j)&mask;
                nx|=1;
                if((nx&ng)==ng) continue;
                dp[i+1][nx]+=dp[i][k];
                dp[i+1][nx]%=mod;
            }
        }
    }
    LL ans=1;
    for (int i = 0; i < n; i++){
        ans*=10;
        ans%=mod;
    }
    for (int i = 0; i <= mask; i++) {
        ans=(ans+mod-dp[n][i])%mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 41216
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  inputInt(N);
  inputIntArray(w,N);
  vector<int> sum(N+1,0);//0~N
  
  //main
  for(int i=0; i<N; i++){//累積和
      sum[i+1] = sum[i] + w[i]; //sum[i]→i番目までの和 w[i]→i+1番目のおもりの重さ。
  }
  
  int mindiff = 1e9;
  int ans = 0;
  for(int T=1; T<N; T++){
    int diff = abs(sum[T] - (sum[N]-sum[T]));
    if(diff < mindiff){
      mindiff = diff;
      ans = T;
    }
  }

  // output
  output(mindiff);
  
  return 0;
}

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

int main()
{
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	sort(a, a + 5);
	for (int j = 4; j > -1; j--) {
		cout << a[j];
		if (j != 0) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 3128
s = input()
k = int(input())

first_pos = -1
for i in range(len(s)):
    if s[i] != '1':
        first = s[i]
        first_pos = i + 1
        break

if first_pos == -1 or first_pos > k:
    print(1)
else:
    print(first)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int md=1000000007;
int n,m;
int main()
{
	long long ans=0;
	scanf("%d%d",&n,&m);
	if(n+1==m||m+1==n||n==m)
	{
		ans=1;
		for(int i=1;i<=n;i++)ans=ans*i%md;
		for(int i=1;i<=m;i++)ans=ans*i%md;
		if(n==m)ans=ans*2%md;
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n)cin>>d[i];
	SORT(d);
	int l = d[n/2-1], r = d[n/2];
	cout << r - l << endl;
}


Measured memory_bytes: 3740
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = list(map(int, list(sr())))
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 1 - S[i+1]
        count += 1

answer = min(count, len(S) - count)
print(answer)


Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

class UnionFind{
  public:
    vector<int> par;

    UnionFind(int n):par(n,-1){}
    void init(int n){par.assign(n,-1); }

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

    bool issame(int x,int y){
      return root(x)==root(y);
    }

    bool merge(int x,int y){
      x=root(x); y=root(y);
      if(x==y) return false;
      if(par[x]>par[y])swap(x,y);
      par[x]+=par[y];
      par[y]=x;
      return true;
    }

    int size(int x){
      return -par[root(x)];
    }
};

int main(){
  long long N,M; cin>>N>>M;
  vector<int> A(M),B(M);
  for(int i=0;i<M;i++){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }

  UnionFind uf(N);

  long long cur=N*(N-1)/2;
  vector<long long> res;

  for(int i=0;i<M;i++){
    res.push_back(cur);

    int a=A[M-1-i],b=B[M-1-i];
    if(uf.issame(a,b)) continue;

    long long sa = uf.size(a),sb=uf.size(b);
    cur-=sa*sb;
    uf.merge(a,b);
  }
  
  reverse(res.begin(),res.end());
  for(int i=0;i<res.size();i++) cout<<res[i]<<endl;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
#define INF 100000000
#define MAX_N 150005
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;

int main(){
    double T,D,ta,tb,da,db;
    double ans=INF;
    cin>>T>>D>>ta>>tb>>da>>db;
    rep(i,0,1001){
        rep(j,0,1001){
            double V=da*i+db*j;
            if(V>D)break;
            double ANS=abs(T-(da*i*ta+db*j*tb)/V);
            ans=min(ans,ANS);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  string s;
  cin>>s;
  ll cnt_a=0;
  ll ans=0;
  for (int i=0; i<s.size()-1; i++) {
    if (s[i]=='A') {
      cnt_a++;
    }
    else if (s[i]=='B'&&s[i+1]=='C') {
      i++;
      ans+=cnt_a;
    }
    else {
      cnt_a=0;
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}




Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */
ll dp[50 + 1][50 + 1][2501];
int main() {
    int N, A; cin >> N >> A;
    int a[N];rep(i, N) cin >> a[i];
    rep(i, N+1)dp[i][0][0] = 1;
    for(int i = 0;i < N;++i){
        for(int j = 0;j < N;++j){
            for(int k = 0;k <= 2500;++k){
                dp[i + 1][j + 1][k] = dp[i][j + 1][k];
                if(k >= a[i]){
                    dp[i + 1][j + 1][k] += dp[i][j][k - a[i]];
                }
            }
        }
    }
    ll ans = 0;
    rep(i, N){
        ans += dp[N][i + 1][A * (i + 1)];
    }
    cout << ans << endl;
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < n; i++)
#define REP(n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using INT64 = long long;
using UINT64 = unsigned long long;

#define MOD 1000000007

int main(void)
{
    IOS
    int n,m; cin >> n>>m;
    vector<int> v(n+1,0);
    REP(m) {
        int a;
        cin >> a;
        v[a] = 1;
    }

    vector<INT64> a(n+1,0);

    FOR(i,1,n+1) {
        if (v[i] == 1) {
            a[i] = 0;
            continue;
        }
        if (i == 1) {
            a[i] = 1;
        } else if (i == 2) {
            a[i] = a[i-1] + 1;
        } else {
            a[i] = a[i-1] + a[i-2];
        }
        a[i] %= MOD;
    }

    cout << a[n] << endl;


    return 0;
}


Measured memory_bytes: 1408
/*input
2 1
-1 1000000000
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n, k; cin >> n >> k;
	vector<ll> v(n), actpos, actneg;
	vector<long double> pos, neg;
	bool yes = false;
	for(ll i = 0; i < n; i++) {
		cin >> v[i];
		if(v[i] > 0) {
			yes = true;
			pos.push_back(logl((long double)(v[i])));
			actpos.push_back(v[i]);
		}
		if(v[i] < 0) {
			neg.push_back(logl((long double)(-v[i])));
			actneg.push_back(-v[i]);
		}
	}
	ll f = 1;
	if(!yes) {
		if(k & 1) {
			sort(v.begin(), v.end(), greater<ll>());
			for(ll i = 0; i < k; i++) {
				f = (f * v[i]) % MOD;
			}
			f = (f + (ll)1000000000 * MOD) % MOD;
		}
		else {
			sort(v.begin(), v.end());
			for(ll i = 0; i < k; i++) {
				f = (f * v[i]) % MOD;
			}
			f = (f + (ll)1000000000 * MOD) % MOD;
		}
	}
	else if(k == n) {
		for(ll i = 0; i < n; i++) {
			f = (f * v[i]) % MOD;
		}
		f = (f + (ll)1000000000 * MOD) % MOD;
	}
	else {
		sort(pos.begin(), pos.end(), greater<long double>());
		sort(neg.begin(), neg.end(), greater<long double>());
		sort(actpos.begin(), actpos.end(), greater<ll>());
		sort(actneg.begin(), actneg.end(), greater<ll>());
		vector<long double> prefneg(neg.size() + 1, 0), prefpos(pos.size() + 1, 0);
		for(ll i = 0; i < pos.size(); i++) {
			prefpos[i + 1] = prefpos[i] + pos[i];
		}
		for(ll i = 0; i < neg.size(); i++) {
			prefneg[i + 1] = prefneg[i] + neg[i];
		}
		pair<ll, ll> best;
		long double mx = -1;
		for(ll i = 0; i <= neg.size(); i += 2) {
			ll j = k - i;
			if(j > pos.size() || j < 0) continue;
			if(prefneg[i] + prefpos[j] > mx) {
				mx = prefneg[i] + prefpos[j];
				best.first = i;
				best.second = j;
			}
		}
		if(mx < -0.5) {
			f = 0;
		}
		else {
			for(ll i = 0; i < best.first; i++) {
				f = (f * actneg[i]) % MOD;
			}
			for(ll i = 0; i < best.second; i++) {
				f = (f * actpos[i]) % MOD;
			}
			f = (f + (ll)1000000000 * MOD) % MOD;
		}
	}
	cout << f << endl;
	return 0;
}

Measured memory_bytes: 14584
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		sort(ALLR(A));
		ll a=0;
		REP(i, N) {
			a+=A[i];
			i++;
		}
		ll b=accumulate(ALL(A), 0LL)-a;
		ll ans=a-b;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
typedef uint_fast16_t fint16;
typedef uint_fast32_t fint32;
typedef uint_fast64_t fint64;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define exists(x,m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

struct SegTree {
	const int n;
	vi T;

	SegTree(int size):n(size) {
		T = vi(4*n+1, 0);
	} 

	void update(int index, int val, int v, int tl, int tr) {
		if (tl == tr) {
			T[v] = val;
		} else {
			int mid = (tl + tr)/2;
			if (index <= mid) {
				update(index, val, 2*v, tl, mid);
			} else {
				update(index, val, 2*v+1, mid+1, tr);
			}	
			T[v] = max(T[2*v], T[2*v+1]);	
		}
	}

	void update(int index, int val) {
		update(index, val, 1, 0, n-1);
	}

	int get_max(int l, int r, int v, int tl, int tr) {
		if (l > tr or r < tl) return 0;
		if (l <= tl and tr <= r) return T[v];
		int mid = (tl + tr)/2;
		int L = get_max(l, r, 2*v, tl, mid);
		int R = get_max(l, r, 2*v+1, mid+1, tr);
		return max(L, R);
	}

	int get_max(int l, int r) {
		return get_max(l, r, 1, 0, n-1);
	}

};


int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int ans = 0;
	int n, k; cin >> n >> k;
	SegTree st = SegTree(300001);
	rep(i, n) {
		int x; cin >> x;
		int top = min(x + k, 300000);
		int bot = max(0, x-k);
		int prev_max = st.get_max(bot, top);
		ans = max(ans, 1 + prev_max);
		st.update(x, 1 + prev_max);
	}
	cout << ans;
}

Measured memory_bytes: 7944
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {

	string a;

	cin >> a;

	if (a == "ARC") {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;

	}




}

Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
	int a,b;
	while(scanf("%X%X",&a,&b)!=EOF)
	{
		if(a>b)
		{
			printf(">\n");
		}
		if(a==b)
		{
			printf("=\n");
		}
		if(a<b)
		{
			printf("<\n");
		}
	}
}

Measured memory_bytes: 128
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> W >> H;
	vector<pair<long long int, bool>>v(W + H);
	for (int i = 0; i < W; i++) {
		int a;
		cin >> a;
		v[i] = { a,true };
	}
	for (int i = W; i < H + W; i++) {
		int a;
		cin >> a;
		v[i] = { a,false };
	}
	sort(v.begin(), v.end());
	H++;
	W++;
	for (auto i : v) {
		if (i.second) {
			ans += i.first*H;
			W--;
		}
		else {
			ans += i.first*W;
			H--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A[] = new int[N];
		
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
		}
		
		Arrays.sort(A);
		System.out.println(A[N-1]-A[0]);

	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	string a;
	cin >> a;
	int r = 0;
	for (int i = 0; i < a.size(); i++)
	{
		if (r == 0)
		{
			if (a[i] == 'C')r++;
		}
		else if (r == 1)
		{
			if (a[i] == 'F')r++;
		}
	}
	//printf("%c%c%c\n", a[0]+'A'-'a',b[0]+'A'-'a',c[0]+'A'-'a');
	//cout << max(a*b,c*d) << endl;
	printf((r==2) ? "Yes\n" :"No\n");
}

Measured memory_bytes: 256
<?php

fgets(STDIN);
$array = explode(" ", trim(fgets(STDIN)));
echo gcd2($array);

function gcd2($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

function gcd($a, $b){
    list($a, $b) = [max($a, $b), min($a, $b)];
    while(1){
        $c =  $a % $b;
        if($c == 0)return $b;
        $a = $b;
        $b = $c;
    }
}



Measured memory_bytes: 12792
#include<stdio.h>
#define MAX 10000
#define NO -1

struct tree { int p, l, r;};
struct tree T[MAX];
int n;

  void Preorder ( int u ) {
    if ( u == NO ) return;
      printf(" %d", u);
      Preorder(T[u].l);
      Preorder(T[u].r);
  }

  void Inorder ( int u ) {
    if ( u == NO ) return;
      Inorder(T[u].l);
      printf(" %d", u);
      Inorder(T[u].r);
  }

  void Postorder ( int u ) {
    if ( u == NO ) return;
      Postorder(T[u].l);
      Postorder(T[u].r);
      printf(" %d", u);
  }

  int main(void) {
    int i, v, l, r, f, root;
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ) {
      T[i].p = NO;
    }

    for ( i = 0; i < n; i++ ) {
      scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if ( l != NO ) T[l].p = v;
        if ( r != NO ) T[r].p = v;
    }

    for ( i = 0; i < n; i++ ) {
      if ( T[i].p == NO ) root = i;
    }

    printf("Preorder\n");
    Preorder(root);
    printf("\nInorder\n");
    Inorder(root);
    printf("\nPostorder\n");
    Postorder(root);
    printf("\n");

    return 0;

}





Measured memory_bytes: 2136
// abc132_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#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 REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int mod_pow(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

ll factorial[200001];
void make_factorial(int mo){ factorial[0] = 1; REPN(i, 1, 200001) factorial[i] = (i * factorial[i-1]) % mo; }
ll get_factorial(int n){ return n >= 0 ? factorial[n] : 0; }

ll nCk(int n, int k, int mo){
    ll a = get_factorial(n);
    ll b = get_factorial(n-k) * get_factorial(k) % mo;
    ll b_inv = mod_pow(b, mo-2, mo);
    return a * b_inv % mo;
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, K;
    cin >> N >> K;

    int b = K;
    int r = N - K;

    make_factorial(MOD);

    REPN(i, 1, K+1){
        ll ans = (nCk(r+1, i, MOD) * nCk(b-1, i-1, MOD)) % MOD;
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
N = int(input())
A = []
for i in range(N):
    Ai = int(input())
    A.append(Ai)

B = sorted(A, reverse=True)
maxnum1 = B[0]
maxnum2 = B[1]

for i in range(N):
    if A[i] != maxnum1:
        print(maxnum1)
    else:
        print(maxnum2)

Measured memory_bytes: 70104
import java.util.Scanner;

class B {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int X = sc.nextInt();
        final int ans = X / 500 * 1000 + X % 500 / 5 * 5;
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String... args) {
        B.main();
    }
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    using P = pair<i64, i64>;
    vector<P> X(N);
    REP(i, N) cin >> X[i].first >> X[i].second;

    i64 minc = N;
    REP(i, N) {
        REP(j, N) {
            if (i == j) continue;
            i64 p = X[i].first - X[j].first;
            i64 q = X[i].second - X[j].second;

            i64 cost = N;
            REP(k, N) {
                REP(l, N) {
                    if (k == l) continue;
                    i64 dx = X[k].first - p;
                    i64 dy = X[k].second - q;
                    if (dx == X[l].first && dy == X[l].second) cost--;
                }
            }
            chmin(minc, cost);
        }
    }
    cout << minc << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int x, int y){ /*x=<y*/
  if(x==0){
    return y;
  } else {
    return gcd(y%x, x);
  }
}

int main(){
  int a, b;
  int c, ans1, ans2;
  while(scanf("%d %d", &a, &b) != EOF){
    if(a>b){
      c = a;
      a = b;
      b = c;
    }
    ans1 = gcd(a, b);
    ans2 = b / ans1 * a;
    printf("%d %d\n", ans1, ans2);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;
    if (h == 1 || w == 1) {cout << 1 << endl; return 0;}
    ll tmp = h * w;
    if (tmp&1) cout << tmp/2+1 << endl;
    else cout << tmp/2 << endl;
    return 0;
}

Measured memory_bytes: 256
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll n,i;
  cin>>n;
  if(n>=400 && n<=599)
    cout<<8;
  if(n>=600 && n<=799)
    cout<<7;
  if(n>=800 && n<=999)
    cout<<6;
  if(n>=1000 && n<=1199)
    cout<<5;
  if(n>=1200 && n<=1399)
    cout<<4;
  if(n>=1400 && n<=1599)
    cout<<3;
  if(n>=1600 && n<=1799)
    cout<<2;
  if(n>=1800 && n<=1999)
    cout<<1;
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 1e5 + 7;
ll ar[N];
ll pos[N] = {};

int main()
{
	fastio;

	ll n, x, m;
	cin >> n >> x >> m;

	if (n <= 100000)
	{
		ll res = x;
		for (ll i = 2; i <= n; ++i)
		{
			x = (x * x) % m;
			res += x;
		}
		cout << res << '\n';
		return 0;
	}

	ar[1] = x;
	pos[x] = 1;

	int len = 2;
	ll res = 0;
	for (; len <= n; ++len)
	{
		ar[len] = (ar[len-1] * ar[len-1]) % m;

		if (len == n || ar[len] == 0)
		{
			for (int i = 1; i <= len; ++i)
				res += ar[i];
			break;
		}
		else if (pos[ar[len]] == 0)
		{
			pos[ar[len]] = len;
		}
		else
		{
			ll lt = pos[ar[len]], rt = len-1;
			ll sum = 0;

			for (int i = lt; i <= rt; ++i)
				sum += ar[i];

			n -= (lt - 1);
			for (int i = 1; i < lt; ++i)
				res += ar[i];

			ll segment_len = (rt - lt + 1);
			res += (n / segment_len) * sum;
			for (int i = lt; i < lt + (n % segment_len); ++i)
				res += ar[i];

			break;
		}
	}
	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 4700
#include<stdio.h>
int main(void){
    int a[3];
    int joint;
    int i;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    do{
        for(i=0; i<2; i++){
            if(a[i] > a[i+1]){
                joint = a[i];
                a[i] = a[i+1];
                a[i+1] = joint;
            }
        }
    }while(!(a[0] <= a[1] && a[1] <= a[2] && a[0] <= a[2]));
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}

Measured memory_bytes: 596
N,M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    min_distance = 10 ** 10
    min_index = 0
    for j in range(M):
        distance = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if  distance < min_distance:
            min_distance = distance
            min_index = j
    print(min_index+1)





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

int main() {
    int N, M; cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<int> idx[N+1];
    for (int i=1; i<N+1; i++) idx[i] = vector<int>();
    for (int i=0; i<M; i++) {
        cin >> P[i] >> Y[i];
        idx[P[i]].push_back(Y[i]);
    }
    for (int i=1; i<=N; i++) sort(idx[i].begin(), idx[i].end());
    for (int i=0; i<M; i++) {
        int y_i = int(lower_bound(idx[P[i]].begin(), idx[P[i]].end(), Y[i]) - idx[P[i]].begin()) + 1;
        cout << setw(6) << setfill('0') << P[i];
        cout << setw(6) << setfill('0') << y_i << endl;
    }
}

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

int main(){
  string str;
  cin >> str;
  string resb = "";
  int back = 0;
  for(int i=str.length()-1; i>=0; i--){
    if(str[i] != 'B'){
      if(back > 0) back--;
      else resb += str[i];
    }else{
      back++;
    }
  }
  string res = "";
  for(int i=resb.length()-1; i>=0; i--) res += resb[i];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

int const INF = 1e9;

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

struct state {
  int score_k;
  int type;
  int last[26];
  int score;
  std::vector<state>::iterator prev;
  bool operator< (state const& rhs) const { return score_k > rhs.score_k; } // reverse order
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  int const B = 850;
  int const K = 2;
  std::vector<int> t(D);
  
  std::vector<std::vector<state>> states(D+1);
  auto beam_step = [&](int d, int k) {
    auto& prev = states[d];
    auto& curr = states[d+1];
    curr.reserve(prev.size()*26);
    int dd = std::min(d+k, D-1);
    for(auto it = prev.begin(); it != prev.end(); ++it) {
      for(int T = 0; T < 26; ++T) {
        curr.push_back(*it);
        state& st = curr.back();
        st.prev = it;
        st.last[T] = d;
        st.type = T;
        st.score_k = st.score + s[d][T];
        for(int cx = 0; cx < 26; ++cx) {
          st.score_k -= c[cx]*(d+dd - 2*st.last[cx])*(dd-d+1)/2;
        }
      }
    }
    std::sort(curr.begin(), curr.end());
    if(curr.size() > B) curr.resize(B);
    for(auto& st: curr) {
      st.score += s[d][st.type];
      for(int cx = 0; cx < 26; ++cx) {
        st.score -= c[cx]*(d - st.last[cx]);
      }
    }
  };
  
  auto beam_search = [&](int k) {
    states.assign(D+1, std::vector<state>());
    states[0].emplace_back();
    states[0][0].score = 0;
    states[0][0].score_k = 0;
    std::fill_n(states[0][0].last, 26, -1);
    for(int d = 0; d < D; ++d) beam_step(d, k);
    auto it = states[D].begin();
    for(int d = D-1; d >= 0; it = it->prev, --d) {
      t[d] = it->type;
    }
  };
  beam_search(K);
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 1006372
import Control.Applicative

main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $　solve a b 
    
solve :: Int -> Int -> String
solve a b = if elem a [1,3,5,7,8,10,12] && elem b [1,3,5,7,8,10,12] 
            || elem a [4,6,9,11] && elem b [4,6,9,11] || a == 2 && b == 2
            then "Yes" else "No"

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    string S;
    cin >> S;
    if (S == "SUN") {
        print(7);
    } else if (S == "MON") {
        print(6);
    } else if (S == "TUE") {
        print(5);
    } else if (S == "WED") {
        print(4);
    } else if (S == "THU") {
        print(3)
    } else if (S == "FRI") {
        print(2)
    } else if (S == "SAT") {
        print(1);
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int field[12][12];

char search(int y,int x) {
  if(field[y][x+1] == 1) { //A
    if(field[y][x+2] == 1) {
      return 'C';
    }
    if(field[y+1][x] == 1&&field[y+1][x+1] == 1) {
      return 'A';
    }
    if(field[y+1][x] == 1&&field[y+1][x-1] == 1) {
      return 'G';
    }
    if(field[y+1][x+1] == 1&&field[y+1][x+2] == 1) {
      return 'E';
    }
  }
  if(field[y+2][x] == 1) {
    return 'B';
  }
  if(field[y+1][x-1] == 1) {
    return 'D';
  }
  if(field[y+2][x+1] == 1) {
    return 'F';
  }
  return 'X';
}

void solve() {
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      if(field[i+1][j+1] != 0) {
        cout << search(i+1,j+1) << endl;
        return;
      }
    }
  }
}

int main() {
  string str;
  while(1) {
    for(int i=0;i<8;i++) {
      getline(cin,str);
      if(str.size() == 0) return 0;
      for(int j=0;j<8;j++) {
        field[i+1][j+1] = atoi(str.substr(j,1).c_str());
      }
    }
    solve();
    getline(cin,str); //kill \n
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
using namespace std;
int main(void) {
	string s;
	int n=0;
	int res=0;
	cin >> n>>s;
	for (int i = 0; i < 100; i++) {
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}
	
	



Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

LL n, k;
LL a[101010];
const LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 1010101;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}



int main(){
    cin >> n >> k;
    REP(i, n)cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    LL ans = 0;
    REP(i, n - k + 1){
        ans += combi(n - i - 1, k - 1) * a[i];
        ans %= MOD;
    }
    reverse(a, a + n);
    LL rans = 0;
    REP(i, n - k + 1){
        rans += combi(n - i - 1, k - 1) * a[i];
        rans %= MOD;
    }
    cout << (ans - rans + MOD + MOD) % MOD << endl;
}

Measured memory_bytes: 24704
// Aizu Vol-2 0206: Next Trip
// 2017.8.6

#include <stdio.h>

int main()
{
	int L, m, n;
	int i, k, s;

	while (1) {
		scanf("%d", &L);
		if (L == 0) break;
		for (s = k = 0, i = 1; i <= 12; i++) {
			scanf("%d%d", &m, &n);
			s += m - n;
			if (s >= L && k == 0) k = i;
		}
		if (k == 0) puts("NA");
		else printf("%d\n", k);
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,sum=0;
  cin >> a;
  int b,c;
  rep(i,a){
    cin >> b >> c;
    sum += c - b + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3616
a,b,k = map(int, input().split())
c = []
d = 1
for i in range(1,min(a,b)//2+1):
    if (a%i + b%i) == 0:
        c.append(i)
if max(a,b) % min(a,b) == 0:
    c.append(min(a,b))
print(c[-k])

Measured memory_bytes: 3060
from itertools import *
f=lambda:map(int,input().split())
N,M=f()
a=[[*f()] for i in range(M)]
a=[*a,*[[y,x] for x,y in a]]
p=[(1,*i)for i in [*permutations(range(2,N+1))]]
print([sum(1 for y in range(N-1)if [x[y],x[y+1]] in a)for x in p].count(N-1))

Measured memory_bytes: 10140
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let s = buf.trim();
    let ans = s.chars().map(|c| c.to_string().parse::<u64>().unwrap()).sum::<u64>();
    if ans == 1 {
        println!("10");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n;
    cin >> n;
    
    vector<int> v(n);
    for (auto &x : v) cin >> x;
    
    int dp[n+1][n+1];
    memset(dp, 0x00, sizeof(dp));
    
    for (int len = 1; len <= n; ++len) {
        for (int L = 0, R = L+len; R <= n; ++L, ++R) {
            if ((n - len) & 1) {
                dp[L][R] = min(dp[L+1][R] - v[L], dp[L][R-1] - v[R-1]);
            }
            else {
                dp[L][R] = max(dp[L+1][R] + v[L], dp[L][R-1] + v[R-1]);
            }
        }
    }
    
    cout << dp[0][n] << "\n";
    
    return 0;
}

Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(whole(a));
    //reverse(whole(a));
    vector<P> b(m);
    rep(i, m) cin >> b[i].first >> b[i].second;
    auto comp = [](P a, P b) {
        return a.second > b.second;
    };
    sort(whole(b), comp);
    ll ans = 0;
    int id = 0;
    rep(i, n) {
        if (b[id].first==0) {
            id++;
        }
        if (a[i]<b[id].second) {
            ans += b[id].second;
            b[id].first--;
        }
        else {
            ans += a[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

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

inline void Main() {
  // code
  int a, b;
  cin >> a >> b;

  if(a - 2*b <= 0) {
    cout << 0 << endl;
  } else {
    cout << a - 2*b << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


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


using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}

double const eps = 1e-10;
ll const mod = 1e9+7;

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

    int n,m;
    int k = INT_MAX;
    cin >> n >> m;
    pair<int,int> a[55],b[55];

    for ( int i = 1; i <= n; i++ )
        cin >> a[i].first >> a[i].second;
    for ( int i = 1; i <= m; i++ )
        cin >> b[i].first >> b[i].second;

    for ( int i = 1; i <= n; i++ )
    {
        int pos = 0;
        for ( int j = 1; j <= m; j++ )
        {
            int bingo = abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
            if ( bingo < k )
            {
                k = bingo;
                pos = j;
            }
        }
        cout << pos << endl;
        k = INT_MAX;
    }


    return 0;

    // 274751WM
}


Measured memory_bytes: 256