akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e11;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;

ll N, A, B, C, D;
map<ll, ll> mp;
set<ll> st;

priority_queue<pll, vector<pll>, greater<pll> > pq;

void f(ll cur, ll x, ll w, ll v) {
	if(INF / (cur-x) / D == 0) v = w+v;
	else v = min(w + v, min(INF, w + (cur-x) * D));
	if(mp.find(x) != mp.end()) {
		if(mp[x] > v) {
			mp[x] = v;
			pq.push({v, x});
		}
	}
	else mp[x] = v, pq.push({v, x});
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int T; cin >> T;
	while(T--) {
		cin >> N >> A >> B >> C >> D;

		mp.clear();
		while(!pq.empty()) pq.pop();

		mp[N] = 0; pq.push({0, N});
		while(!pq.empty()) {
			ll cur = pq.top().se, w = pq.top().fi; pq.pop();

			if(cur == 1) {
				cout << w + D << endl;
				break;
			}

			if(cur % 2) {
				f(cur, cur/2, w, D+A);
				f(cur, cur/2+1, w, D+A);
			}
			else f(cur, cur/2, w, A);

			if(cur % 3 == 0) f(cur, cur/3, w, B);
			if(cur % 3 == 1) f(cur, cur/3, w, D+B);
			if(cur % 3 == 2) f(cur, cur/3+1, w, D+B);

			if(cur % 5 == 0) f(cur, cur/5, w, C);
			if(cur % 5 == 1) f(cur, cur/5, w, C+D);
			if(cur % 5 == 2) f(cur, cur/5, w, C+2*D);
			if(cur % 5 == 3) f(cur, cur/5+1, w, C+2*D);
			if(cur % 5 == 4) f(cur, cur/5+1, w, C+D);
		}
	}
}

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

using namespace std;

typedef long long int ll;

int main(){
  int N;
  vector<float> v;
  cin >> N;

  for(int i=0;i<N;i++){
    float vi;
    cin >> vi;
    v.emplace_back(vi);
  }

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

  float ans=v[0];

  for(int i=1;i<N;i++){
    ans=(ans+v[i])/2;	//printf("ans=%f\n",ans);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e4+5, MOD = 1e9+7, BASE = 31, MASK = (1 << 10) - 1;
int main () {
	ll n;
	scanf ("%lld",&n);
	ll pw=1;
	for (int i = 1; ; i++) {
		if ((pw *= 26) >= n) {
			string ans; n--;
			for (int j = 0; j < i; j++) ans += 'a' + n%26, n /= 26;
			reverse(all(ans));
			return !printf("%s\n",ans.c_str()); 
		} else n -= pw; 
	}
	return 0;
}


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

int main(){
    string a,b;
    cin >> a >> b;
    string s=a+b;
    int num=atoi(s.c_str());
    bool ans=false;
    for(int i=1;i*i<=num;i++){
        if(i*i==num) ans=true;
    }
    puts(ans?"Yes":"No");
}


Measured memory_bytes: 256
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=1010;

int mx[]={-1, 0, 0, 1};
int my[]={0, -1, 1, 0};

priority_queue<pair<int,ii>, vector<pair<int,ii>>, greater<pair<int,ii>> >pq;
int dis[N][N];
char a[N][N];
int n,m;

bool inside(int x, int y){
    return x>=0 && x<n && y>=0 && y<m;
}


int main(){
    scanf("%d%d",&n,&m);
    int xs,ys;
    scanf("%d%d",&xs,&ys);
    int xd,yd;
    scanf("%d%d",&xd,&yd);

    xs--, ys--;
    xd--, yd--;

    for(int i=0 ; i<n ; i++)
        scanf("%s",&a[i]);


    for(int i=0 ; i<n ; i++)
        for(int j=0 ; j<m ; j++)
            dis[i][j]=inf;

    dis[xs][ys]=0;
    pq.push({0,{xs,ys}});

    while(pq.size()){
        int c=pq.top().F;
        int x=pq.top().S.F;
        int y=pq.top().S.S;
        pq.pop();

        if(dis[x][y] > c)
            continue;

        for(int k=0 ; k<4 ; k++){
            int nx=x+mx[k];
            int ny=y+my[k];
            if(inside(nx, ny) && a[nx][ny] == '.' && dis[x][y] < dis[nx][ny]){
                dis[nx][ny]=dis[x][y];
                pq.push({dis[nx][ny],{nx, ny}});
            }
        }

        for(int nx=x-2 ; nx<=x+2 ; nx++){
            for(int ny=y-2 ; ny<=y+2 ; ny++){
                if(inside(nx, ny) && a[nx][ny] == '.' && dis[x][y]+1 < dis[nx][ny]){
                    dis[nx][ny]=1+dis[x][y];
                    pq.push({dis[nx][ny],{nx, ny}});
                }
            }
        }

    }

    if(dis[xd][yd] == inf) printf("-1\n");
    else printf("%d\n",dis[xd][yd]);

}


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

#define int long long int 

int32_t main()
{
  int x,y,z;
  cin>>x>>z>>y;
  vector<int> s(z);
  for(int i=0;i<z;i++)
   cin>>s[i];
   sort(s.begin(),s.end());
   int p=(lower_bound(s.begin(),s.end(),y)-s.begin());
    int q=z-(lower_bound(s.begin(),s.end(),y)-s.begin());
  cout<<min(p,q)<<endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<P, long long int> Q;

#define INF 1000000000000

long long int parr[100010];
long long int rankk[100010];

void init(long long int n) {
	for (long long int i = 0; i < n; i++) {
		parr[i] = i;
		rankk[i] = 0;
	}
}

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

void unite(long long int x, long long int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (rankk[x] < rankk[y]) {
		parr[x] = y;
	}
	else {
		parr[y] = x;
		if (rankk[x] == rankk[y]) rankk[x]++;
	}
}

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

long long int cost(P a, P b) {
	return min(abs(a.first-b.first), abs(a.second-b.second));
}

struct edge {
	long long int u, v, cost;
};

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

edge es[300000];
long long int V, E;

long long int kruskal() {
	sort(es, es + E, comp);
	init(V);
	long long int res = 0;
	for (long long int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main() {
	long long int n;
	cin >> n;
	long long int x, y;
	vector<Q> dx(n);
	vector<Q> dy(n);
	for (long long int i = 0; i < n; i++) {
		cin >> x >> y;
		dx[i] = Q(P(x, y), i);
		dy[i] = Q(P(y, x), i);
	}
	sort(dx.begin(), dx.end());
	sort(dy.begin(), dy.end());
	V = n;
	E = 0;
	for (long long int i = 1; i < n; i++) {
		edge e;
		e.u = dx[i-1].second;
		e.v = dx[i].second;
		e.cost = cost(dx[i-1].first, dx[i].first);
		es[E] = e;
		E++;
	}
	for (long long int i = 1; i < n; i++) {
		edge e;
		e.u = dy[i - 1].second;
		e.v = dy[i].second;
		e.cost = cost(dy[i - 1].first, dy[i].first);
		es[E] = e;
		E++;
	}
	cout << kruskal() << endl;

	return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<ll,ll> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};



int K[120000];
int S[120000];
ll sum[120000];

ll SS(int a,int b){
  return sum[b+1]-sum[a];
}

bool vis[2100][2100];

int main() {

  ll N, M, L;
  cin >> N >> M >> L;
  rep(i, N) cin >> K[i];
  rep(i, N) --K[i];
  rep(i, M) cin >> S[i];

  rep(i,M) sum[i+1] = sum[i] + S[i];
  sort(K,K+N);
  priority_queue<pair<ll,PI> > q;
  if(N==1){
    cout << 0 << endl;
    return 0;
  }else if(N==2){
    cout << SS(K[0],K[1])/L*2 << endl;
    return 0;
  }
  
  q.push(mp(-SS(K[0],K[1])/L,mp(0,1)));
  ll ans = 1LL<<50LL;
  while(!q.empty()){
    ll cc=-q.top().F;
    PI cv=q.top().S;
    q.pop();
    if(vis[cv.F][cv.S]) continue;
    vis[cv.F][cv.S] = true;
    //cout << cc << ' ' << cv.F << ' ' << cv.S << endl;
    int nidx = max(cv.F,cv.S) + 1;
    if(nidx==N-1){
      //cout << cv.F << ' ' << K[N-1] << ' ' << SS(K[cv.F, K[N-1])/ L << endl;
      //cout << cv.S << ' ' << K[N-1] << ' ' << SS(cv.S, K[N-1])/ L << endl;      
      ans = min(ans,cc + SS(K[cv.F], K[N-1])/L + SS(K[cv.S], K[N-1])/L);
      //cout << ans << endl;
      continue;
    }
    
    q.push(mp(-cc-SS(K[cv.F],K[nidx])/L,mp(cv.S,nidx)));
    q.push(mp(-cc-SS(K[cv.S],K[nidx])/L,mp(cv.F,nidx)));    
  }

  cout << ans << endl;
}

Measured memory_bytes: 33696
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int c[3][3];
  REP(i,3)REP(j,3)cin>>c[i][j];
  if(c[0][0]+c[1][1]+c[2][2]==c[0][1]+c[1][2]+c[2][0] and
  c[0][1]+c[1][2]+c[2][0]==c[0][2]+c[1][0]+c[2][1]){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n;
  cin>>n;
  if(n<105)cout<<0<<endl;
  else if(n<135)cout<<1<<endl;
  else if(n<165)cout<<2<<endl;
  else if(n<189)cout<<3<<endl;
  else if(n<195)cout<<4<<endl;
  else cout<<5<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y;
}a[500001];
int n,ans;
bool cmp(aaa a,aaa b){
	return a.x<b.x;
}
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)if(a[i].y%2!=i%2)ans++;
	printf("%d",ans/2);
}
/*
简单观察即可发现翻转3个数相当于交换两个相隔的数，
这种操作对于奇数位和偶数位分别是没有影响的。
也就是说，我们可以任意交换奇数位上的数和偶数位上的数，
但对于奇数位上的数和偶数位上的数要交换的话得花1代价。
那么不难发现最后答案就是原序列排序后原来奇数位上的数跑到偶数位上的数的个数 
*/

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
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;
}

int main(void)
{
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
long long n,m;//注意n,m的取值范围
int main()
{
    long long sum=0;
    long long ans=0;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        if(m>2*n)
        {
            m/=2;//让多的减少去和少的匹配，因为过程中会出现n和m剩余的情况
           sum=m-n;
           ans=n+sum/2;
        }
        else
        {
            ans=m/2;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N;      //参加人数
    int X[100]; //参加人数の座標
    int i, max_coordinate = 0;
    int consumed_energy, at_point;
    int sum[100], min;

    // input the data
    scanf("%d", &N);
    for (i = 0; i < N; i++)
    {
        scanf("%d", &X[i]);
    }

    // find max coordinate
    for (i = 0; i < N; i++)
    {
        if (max_coordinate < X[i])
            max_coordinate = X[i];
    }
    // printf("max = %d\n", max_coordinate);

    for (i = 0; i < 100; i++)
    {
        sum[i] = 0;
    }

    //
    for (at_point = 1; at_point <= max_coordinate; at_point++)
    {
        consumed_energy = 0;
        for (i = 0; i < N; i++)
        {
            consumed_energy = (X[i] - at_point) * (X[i] - at_point);
            sum[at_point - 1] += consumed_energy;
        }
    }

    // for (i = 0; i < max_coordinate; i++)
    // {
    //     printf("sum[%d] = %d\n", i, sum[i]);
    // }

    // find minimum sum
    min = sum[0];
    for (i = 0; i < max_coordinate; i++)
    {
        if (min > sum[i])
            min = sum[i];
    }
    printf("%d", min);
    return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
  string a;
  string b;
  cin >> a >> b;
  int cnt = 0;

    for(int i = 0 ; i < a.size() ; i++ )
    {
      if(b[0] == a[i])
      {
        for(int j = 0; j< b.size(); j++)
        {
          if(b[j] != a[(i + j)%a.size()])break;
          else cnt++;
        }
        if(cnt == b.size())
        {
          cout << "Yes" << endl;
          return 0;
        }
      }
      cnt = 0;
    }
    cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    int n;
    string s,t;
    cin >> n>>s>>t;
    rep(i,n) {
        cout << s[i] << t[i];
    }
}

Measured memory_bytes: 384
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    string s;cin>>s;
    ll n = sz(s);
    ll k = 0;
    rep(i, n-1){
        if (s[i]!=s[i+1]){
            chmax(k, min(i+1, n-(i+1)));
        }
    }
    reverse(all(s));
    rep(i, n-1){
        if (s[i]!=s[i+1]){
            chmax(k, min(i+1, n-(i+1)));
        }
    }

    cout << n - k << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


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

int H, W;

int allblank(vector<vector<char>> table,int i, int j);

int main() {
  
  cin >> H >> W;
  
  vector<vector<char>> table(H,vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table.at(i).at(j);
    }
  }
  
  int count = 0;
  for (int i = 0; i < H; i++) {
    count = 0;
    for (int j = 0; j < W; j++) {
      if (allblank(table, i, j) == 1) {
        if (j == W - 1 && count != 0) cout << endl;
        continue;
      }
      
      cout << table.at(i).at(j);
      count ++;
      
      if (j == W - 1 && count != 0) cout << endl;
      
    }
  }
}

int allblank(vector<vector<char>> table,int i, int j) {
  int countW = 0, countH = 0;
  
  for (int h = 0; h < H; h++) {
    if (table.at(h).at(j) != '.') {
      countH++;
      break;
    }
  }
  
  for (int w = 0; w < W; w++) {
    if (table.at(i).at(w) != '.') {
      countW++;
      break;
    }
  }
  
  if (countH * countW > 0) return 0;
  return 1;
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

void dfs(string s = "a") {
    if (n == s.size()) {
        cout << s << endl;
        return;
    }
    vector<int> a(10);
    rep (i, s.size()) a[s[i] - 'a']++;
    int maxi = 0;
    rep (i, n) if (a[i]) maxi = min(n - 1, i + 1);
    if (maxi >= n - 1) maxi = n - 1;
    rep (i, maxi + 1) dfs(s + char('a' + i));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n;
    dfs();
    
    return 0;
}



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

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        string str = cin.next();

        // 00な場合は年。
        // 13より大きい場合は年。
        // 両方が年だったらNA
        // 片方が年だったら。。
        // 両方が月だったらAMBIGUOUS

        char[] upper = new char[2];
        char[] lower = new char[2];

        upper[1] = str[1];
        upper[0] = str[0];

        int upper_ = int.Parse(new string(upper));

        lower[1] = str[3];
        lower[0] = str[2];

        int lower_ = int.Parse(new string(lower));

        bool upperYear = IsYear(upper_);
        bool lowerYear = IsYear(lower_);

        if (upperYear && lowerYear)
        {
            Console.WriteLine("NA");
        }
        else if (!upperYear && !lowerYear)
        {
            Console.WriteLine("AMBIGUOUS");
        }
        else if (upperYear)
        {
            Console.WriteLine("YYMM");
        }
        else
        {
            Console.WriteLine("MMYY");
        }
    }

    bool IsYear(int n)
    {
        if (n == 0) { return true; }
        if (n >= 13) { return true; }
        return false;
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  LL x, t;
  scanf("%lld %lld", &x, &t);
  LL ans = x-t <= 0 ? 0 : x-t;
  printf("%lld", ans);

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 300010
struct Point
{
	int x,y;
	bool operator < (const Point &a) const
	{
		return x<a.x;
	}
}p[MAXN];
struct node
{
	int l,r,w,lazy;
}tree[MAXN*4];
void PushUp(int i)
{
	if(tree[i].l==tree[i].r) return ;
	tree[i].w=max(tree[i<<1].w,tree[i<<1|1].w);
}
void PushDown(int i)
{
	if(tree[i].l==tree[i].r||!tree[i].lazy) return;
	int tmp=tree[i].lazy;
	tree[i<<1].lazy+=tmp,tree[i<<1].w+=tmp;
	tree[i<<1|1].lazy+=tmp,tree[i<<1|1].w+=tmp;
	tree[i].lazy=0;
}
void Build(int i,int l,int r)
{
	tree[i].l=l,tree[i].r=r,tree[i].lazy=0,tree[i].w=0;
	if(l==r)
		return;
	int mid=(l+r)/2;
	Build(i<<1,l,mid);
	Build(i<<1|1,mid+1,r);
}
void Modify(int i,int l,int r,int k)
{
	if(tree[i].l>r||tree[i].r<l) return;
	if(l<=tree[i].l&&tree[i].r<=r)
	{
		tree[i].lazy+=k;
		tree[i].w+=k;
		return;
	}
	PushDown(i);
	Modify(i<<1,l,r,k);
	Modify(i<<1|1,l,r,k);
	PushUp(i);
}
int st[2][MAXN],top[2];
int ans,w,h,n;
void Solve()
{
	sort(p+2,p+1+n);
	Build(1,1,n);
	top[0]=top[1]=0;
	st[0][0]=st[1][0]=1;
	Modify(1,1,n,h<<1);
	for(int i=2;i<=n;i++)
	{
		Modify(1,1,i-1,(p[i].x-p[i-1].x)<<1);
		ans=max(ans,tree[1].w);
		if(p[i].y>=(h>>1))
		{
			Modify(1,st[0][top[0]],i-1,(p[i].y-h)<<1);
			while(top[0]&&p[st[0][top[0]]].y>=p[i].y)
			{
				Modify(1,st[0][top[0]-1],st[0][top[0]]-1,(p[i].y-p[st[0][top[0]]].y)<<1);
				top[0]--;
			}
			st[0][++top[0]]=i;
		}
		else
		{
			Modify(1,st[1][top[1]],i-1,-p[i].y<<1);
			while(top[1]&&p[st[1][top[1]]].y<=p[i].y)
			{
				Modify(1,st[1][top[1]-1],st[1][top[1]]-1,(p[st[1][top[1]]].y-p[i].y)<<1);
				top[1]--;
			}
			st[1][++top[1]]=i;
		}
	}
}
int main()
{
	scanf("%d%d%d",&w,&h,&n);
	n++;
	for(int i=2;i<=n;++i)
		scanf("%d%d",&p[i].x,&p[i].y);
	p[++n].x=w,p[n].y=h;
	Solve();
	swap(w,h);
	for(int i=1;i<=n;i++)
		swap(p[i].x,p[i].y);
	Solve();
	printf("%d\n",ans);
}

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

int main(){
    int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(),A.end(),greater<long long>());
    long long sum = 0;
    priority_queue<long long> que;
    que.push(A[0]);
    for(int i = 1; i < N; i++){
        long long a = que.top(); que.pop();
        sum += a;
        que.push(A[i]);
        que.push(A[i]);
    }
    

    cout << sum << endl;
}

Measured memory_bytes: 6928
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

x=I()
if x==3 or x==5 or x==7:
    print("YES")
else:
    print("NO")

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    bool ok=false;
    FOR(i,0,25)FOR(j,0,15){
        if (i*4+j*7==n){
            ok=true;
            break;
        }
    }
    if (ok){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
'''A - Beginning
https://atcoder.jp/contests/keyence2019/tasks/keyence2019_a

>>> main([1,7,9,4])
YES
>>> main([1,9,7,4])
YES
>>> main([1,2,9,1])
NO
>>> main([4,9,0,8])
NO
'''


def main(n):
    n = sorted(n)

    if n == [1, 4, 7, 9]:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    n = map(int, input().split(' '))
    main(n)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];

    ll X = 0;
    rep(i,2,N)X ^= A[i];
    bool ok = true;
    ll S;
    if(A[0] + A[1] < X)ok = false;
    else S = (A[0] + A[1])-X;
    ll ans = 0;
    if(S%2 == 1)ok = false;
    S/=2;
    ll i = 2;
    ll X2 = X;
    while(S >= 1){
        if(S%2 == 1){
            if(X%2 == 1)ok = false;
            else ans += i/2;
        }
        S/=2;
        X/=2;
        i*=2;
    }
    ll X3 = X2;
    ll now = 1;
    while(X3 >= 2){
        now*= 2;
        X3/=2;
    }
    if(ok && ans <= A[0]){
        while(now >= 1){
            if((X2^now) <= X2 && now+ans <=A[0]){
                ans += now;
            }
            now/=2;
        }
        if(ans == 0)cout<<-1;
        else cout<<A[0]-ans;
    }
    else cout<<-1;
    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  for (int i = 0; i < h; i++) cin >> a.at(i);
  
  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;

  for (int i = 0; i < h; i++) {
    cout << '#' << a.at(i) << '#' << endl;
  }

  for (int i = 0; i < w + 2; i++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#define LL long long
#define PP std::pair<LL,LL>
#define TT std::tuple<LL,LL,LL>
int N;
LL ans;
std::vector<TT> G;
int par[100010];
int rank[100010];
void init(int n){
    for(int i=0;i<n;i++)par[i]=i,rank[i]=0;
}
int find(int x){
    if(par[x]==x)return x;
    else return par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return ;
    if(rank[x]<rank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rank[x]==rank[y])rank[x]++;
    }
}

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

std::vector<PP> sx,sy;
int main(){
    std::cin>>N;
    init(N);
    for(int i=0;i<N;i++){
        LL x, y;
        std::cin>>x>>y;
        sx.emplace_back(PP{x,i});
        sy.emplace_back(PP{y,i});
    }
    std::sort(sx.begin(),sx.end());
    std::sort(sy.begin(),sy.end());
    for(int i=0;i<N-1;i++){
        G.push_back(TT{sx[i+1].first-sx[i].first ,sx[i].second ,sx[i+1].second}); 
    }
    for(int i=0;i<N-1;i++){
        G.push_back(TT{sy[i+1].first-sy[i].first ,sy[i].second ,sy[i+1].second});
    }
    std::sort(G.begin(),G.end());
    for(auto u:G){
        int a,b,c;
        std::tie(a,b,c)=u;
        if(!same(b,c)){
            unite(b,c);
            ans+=a;
        }
    }
    std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 13792
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    

    internal static void Main(string[] args)
    {
        string S = ReadLine();
        int res = 0;

        foreach (char c in S.ToCharArray()) {
            if (c == '+') {
                res++;
            } else {
                res--;
            }
        }


        WriteLine(res);
    }
}

Measured memory_bytes: 11092
#include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <bitset>
    #include <vector>
    #include <map>
    #include <set>
    #include <queue>
    #include <deque>
    #include <algorithm>
    #include <complex>
    #define INF 1100000000000000000LL
    using namespace std;
    typedef long long int ll;
    typedef pair<ll, ll> P;
     
    int main()
    {
    	int n;
    	scanf("%d", &n);
    	vector<P> v;
    	for(int i=0; i<n; i++){
    		ll x, y;
    		scanf("%lld %lld", &x, &y);
    		if(x>y) swap(x, y);
    		v.push_back(P(x, y));
    	}
    	sort(v.begin(), v.end());
    	ll min=v[0].first;
    	ll max=0;
    	multiset<ll> st, st1, st2;
    	for(int i=0; i<n; i++){
    		st.insert(v[i].second);
    		st2.insert(v[i].second);
    		st1.insert(v[i].first);
    		if(max<v[i].second) max=v[i].second;
    	}
    	auto itr1=st.begin(), itr2=st.end(); itr2--;
    	ll ans1=max-min, ans2=*itr2-*itr1, ans;
    	for(int i=n-1; i>=0; i--){
    		st.insert(v[i].first);
    		auto itr=st.lower_bound(v[i].second);
    		st.erase(itr);
    		auto itr1=st.begin(), itr2=st.end(); itr2--;
    		if(ans2>*itr2-*itr1) ans2=*itr2-*itr1;
    	}
    	ans=ans1*ans2;
    	itr1=st1.end(), itr2=st2.begin(); itr1--;
    	if(ans>(*itr1-min)*(max-*itr2)) ans=(*itr1-min)*(max-*itr2);
    	for(int i=n-1; i>=0; i--){
    		st1.insert(v[i].second);
    		auto itr=st1.lower_bound(v[i].first);
    		st1.erase(itr);
    		st2.insert(v[i].first);
    		itr=st2.lower_bound(v[i].second);
    		st2.erase(itr);
    		auto itr1=st1.end(), itr2=st2.begin(); itr1--;
    		if(ans>(*itr1-min)*(max-*itr2)) ans=(*itr1-min)*(max-*itr2);
    	}
    	printf("%lld\n", ans);
    	return 0;
    }

Measured memory_bytes: 32364
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int D, G; cin >> D >> G;
  int p[D], c[D]; rep(i, D) cin >> p[i] >> c[i];

  int result = INF;
  rep(mask,(1<<D)) {
    int s=0, num=0, result_max=-1;
    rep(i,D) {
      if (mask>>i & 1) {
        s += 100 * (i+1) * p[i] + c[i];
        num += p[i];
      } else {
        result_max = i;
      }
    }
    if (s<G) {
      int s1 = 100 * (result_max+1);
      int need = ceil((double)(G-s) / s1);
      if (p[result_max] <= need) continue;
      num += need;
    }
    result = min(result, num);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    T = readline().strip()
    
    ans = 0
    for s, t in zip(S, T):
        if s != t:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 73672
#include <iostream>
#include <vector>
#include <string>
#include <cctype>

int main() {
    int a, b, c, d;
    std::vector<std::vector<char>> field;

    while (1) {
        field.clear();
        std::string raw_field;
        std::cin >> raw_field;
        if (raw_field == "#") return 0;
        field.push_back(std::vector<char>());
        for (char c : raw_field) {
            if (std::isdigit(c)) {
                for (int i = 0; i < c - '0'; i++) {
                    field.back().push_back('.');
                }
            }
            else if (c == 'b') {
                field.back().push_back('b');
            }
            else if (c == '/') {
                field.push_back(std::vector<char>());
            }
        }

        std::cin >> a >> b >> c >> d;

        field[a-1][b-1] = '.';
        field[c-1][d-1] = 'b';

        raw_field = "";
        for (auto field_line : field) {
            int dot_count = 0;
            for (auto point : field_line) {
                if (point == '.') {
                    dot_count++;
                }
                else if (point == 'b') {
                    if (dot_count) {
                        raw_field += std::to_string(dot_count);
                    }
                    dot_count = 0;
                    raw_field += 'b';
                }
            }
            if (dot_count) {
                raw_field += std::to_string(dot_count);
            }
            raw_field += "/";
        }
        raw_field.pop_back();
        std::cout << raw_field << std::endl;
    }

    return 0;
}


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

int main(){
	int div=512;
	int weight[10];
	int W;
	while(cin>>W){
      div=512;
		for(int i=0;i<10;i++){
			weight[i]=W/div;
            W=W%div;
			div=div/2;
		}
      int flag=0;
		for(int j=0;j<10;j++){
                      int a=1;
          if(weight[9-j]>0){

            for(int k=0;k<j;k++){
              a=a*2;
            }
            if(flag==1){cout<<" ";}
		cout <<a;
            flag=1;
		}

        }
 	cout<<endl;     
}
  return 0;
    }
  




Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll t,i,j,n,m,l=0,r;
    cin>>n;
    for(i=1; ;i++)
    {
        l+=i;
        if(l>=n)
        {
            cout<<i<<"\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='C'&&n==0) n++;
        if(s[i]=='F'&&n==1) n++;
    }
    if(n==2) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{	 
	int a, b, f, cf; 
	
	scanf("%d%d", &a, &b);
	if(!a) f = 0;
	else if(a > 0) f = 1;
	else if(b < 0){
		cf = b - a;
		if(cf & 1) f = 1;
		else f = -1;
	}
	else f = 0;
	if(f == 1) puts("Positive");
	else if(!f) puts("Zero");
	else puts("Negative");
		
	return 0;
}

Measured memory_bytes: 1644
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int main(){

    int N;
    cin  >> N;
    vector<int> A(N+2,0);

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

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

    for(int i = 1;i <= N;i++){
    	int sum = s + abs(A[i+1]- A[i-1]) - abs(A[i] - A[i-1]) - abs(A[i+1]-A[i]);
    	cout << sum << endl;
    }

    return 0;

}


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

int main() {
	int N, Y;
	int z;
	cin >> N >> Y;
	for (int x = 0; x <= N; x++) {
		for (int y = 0; x + y <= N; y++) {
			z = N - x - y;
			if (10000 * x + 5000 * y + 1000 * z == Y) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	return 0;
}

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

using namespace std;

const int N=110;

int h,w,px,py,f[N][N][N][N],col[N][N],row[N][N];
bool mp[N][N];

void Init()
{
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;++i)
		for (int j=1;j<=w;++j)
		{
			char ch=getchar();
			while (ch!='o' && ch!='.' && ch!='E') ch=getchar();
			if (ch=='E') px=i,py=j;
			if (ch=='o') mp[i][j]=1;
			else mp[i][j]=0;
		}
}

int Col(int r,int l,int x)
{
	if (l>r) return 0;
	return col[r][x]-col[l][x];
}

int Row(int r,int l,int x)
{
	if (l>r) return 0;
	return row[x][r]-row[x][l];
}

void Solve()
{
	
	for (int i=1;i<=h;++i)
		for (int j=1;j<=w;++j)
		{
			col[i][j]=col[i-1][j]+mp[i][j];
			row[i][j]=row[i][j-1]+mp[i][j];
		}
	int ans=0;
	for (int a=px;a>0;--a)
		for (int b=px;b<=h;++b)
			for (int c=py;c>0;--c)
				for (int d=py;d<=w;++d) f[a][b][c][d]=-1e9;
	f[px][px][py][py]=0;
	for (int a=px;a>0;--a)
		for (int b=px;b<=h;++b)
			for (int c=py;c>0;--c)
				for (int d=py;d<=w;++d)
				{
					if (a>1 && a-1>b-px) 
						f[a-1][b][c][d]=max(f[a-1][b][c][d],f[a][b][c][d]+Row(min(w-(py-c),d),max(c-1,d-py),a-1));
					if (b<h && h-b>px-a) 
						f[a][b+1][c][d]=max(f[a][b+1][c][d],f[a][b][c][d]+Row(min(w-(py-c),d),max(c-1,d-py),b+1));
					if (c>1 && c-1>d-py) 
						f[a][b][c-1][d]=max(f[a][b][c-1][d],f[a][b][c][d]+Col(min(h-(px-a),b),max(a-1,b-px),c-1));
					if (d<w && w-d>py-c) 
						f[a][b][c][d+1]=max(f[a][b][c][d+1],f[a][b][c][d]+Col(min(h-(px-a),b),max(a-1,b-px),d+1));
					ans=max(ans,f[a][b][c][d]);
				}
	
	printf("%d\n",ans);
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 242048
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N, Q;
ll c[501000];
vector<ll> v[505000];
ll idx[501000];
ll l[501000], r[501000];
vector<ll> query[501000];
struct SegmentTree {
private:
    int n;
    vector<int> node;
 
public:
    SegmentTree() {
        int sz = 500100;
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = 0;
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }
 
    void add(int x, int val) {
        x += (n - 1);
        node[x] += val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = (node[2*x+1] + node[2*x+2]);
        }
    }
    // hannkaikukann 
    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
 
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return (vl + vr);
    }
};

ll ans[501000];

void print(SegmentTree seg) {
    for(int i = 0; i <= N; i++) {
        cerr << seg.getsum(i, i + 1) << " ";
    }
    cerr << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Q;
    for(int i = 0; i < N; i++) {
        v[i].push_back(-1);
    }
    for(int i = 0; i < N; i++) {
        cin >> c[i];
        c[i]--;
        v[c[i]].push_back(i);
    }
    for(int i = 0; i < N; i++) {
        v[i].push_back(N);
    }
    SegmentTree seg;
    for(int i = 0; i < N; i++) {
        idx[i]++;
        seg.add(v[i][idx[i]], 1);
    }
    for(int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
        query[l[i]].push_back(i);
    }
    for(int i = 0; i < N; i++) {
        seg.add(i, -1);
        if(i > 0) {
            idx[c[i-1]]++;
            seg.add(v[c[i-1]][idx[c[i-1]]], 1);
        }
        //print(seg);
        for(auto q : query[i]) {
            ans[q] = 1 + seg.getsum(i, r[q] + 1);
        }
    }
    for(int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main()
{
    int N;
    double ans = 0.0, A;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> A;
        ans += 1.0 / A;
    }
    ans = 1.0 / ans;
    cout <<  ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[105];
    while(~scanf("%d",&n))
    {
        int MIN=INT_MAX,MAX=INT_MIN;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            MIN=min(MIN,a[i]);
            MAX=max(MAX,a[i]);
        }
        printf("%d\n",MAX-MIN);
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 10000010;
const LL mod = 998244353;
LL pw[SIZEN];
LL fac[SIZEN];
LL inv[SIZEN];
int N;
LL qpow(LL x,LL len){
    LL ret = 1;
    for(;len;len>>=1){
        if(len & 1)ret = ret * x % mod;
        x = x * x % mod;
    }
    return ret;
}
LL C(int n,int m){
    if(n < m)return 0;
    return fac[n] * inv[m] % mod * inv[n-m] % mod;
}
int main(){
    scanf("%d",&N);
    for(int i = 0;i <= N;i++)pw[i] = (i == 0?1:pw[i-1] * 2 % mod);
    for(int i = 0;i <= N;i++)fac[i] = (i == 0?1:fac[i-1] * i % mod);
    for(int i = N;i >= 0;i--)inv[i] = (i == N?qpow(fac[N],mod-2):inv[i+1] * (i+1) % mod);
    LL ans = qpow(3,N);
    for(int i = N/2+1;i <= N;i++){
        // printf("C(%d,%d) = %lld\n",N,i,C(N,i));
        ans = (ans - 2*C(N,i) * pw[N-i] % mod) % mod;
    }
    printf("%lld",(ans+mod)%mod);
    return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  int64 ans = 0;
  int32 mx = 0;
  REP(i,n){
    int32 a;
    cin >> a;
    ans += max<int32>(0,mx-a);
    chmax(mx,a);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;
inline int read() {
	int x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int N = 1e5+11;
int n;
int a[N],b[N],c[N];
LL sum[N],ans;

int main() {
	n = read(); 
	For(i, 1, n) a[i]=read(); sort(a+1,a+n+1);
	For(i, 1, n) b[i]=read(); sort(b+1,b+n+1);
	For(i, 1, n) c[i]=read(); sort(c+1,c+n+1);
	For(i, 1, n) sum[i] = n+1-(upper_bound(c+1, c+n+1, b[i])-c); 
	Dow(i, n, 1) sum[i]+=sum[i+1];
	For(i, 1, n) {
		int pos = upper_bound(b+1, b+n+1, a[i])-b; 
		ans+=sum[pos];
	}
	printf("%lld\n",ans);
	return 0;
}









Measured memory_bytes: 2304
#include <iostream>

using namespace std;

int R, C;
int a[15][10005];
int x[10005];
int cnt[1050];

int main(void)
{
	for(int i = 0; i < (1<<10); i++){
		for(int j = 0; j < 10; j++){
			if(i & (1<<j)) cnt[i]++;
		}
	}
	
	while(1){
		cin >> R >> C;
		if(R == 0 && C == 0) break;
		for(int i = 0; i < R; i++){
			for(int j = 0; j < C; j++){
				cin >> a[i][j];
			}
		}
		for(int i = 0; i < C; i++){
			x[i] = 0;
			for(int j = 0; j < R; j++){
				x[i] |= (a[j][i] << j);
			}
		}
		
		int S = 1<<R, ans = 0;
		for(int i = 0; i < S; i++){
			int tmp = 0;
			for(int j = 0; j < C; j++){
				tmp += max(cnt[x[j]^i], R - cnt[x[j]^i]);
			}
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s;
    rep(i,h){
        string t;
        cin >> t;
        s.push_back(t);
    }

    int ans = 0;
    for(int sy=0; sy<h; sy++){
        for(int sx=0; sx<w; sx++){
            for(int gy=0; gy<h; gy++){
                for(int gx=0; gx<w; gx++){
                    if( (sx==gx && sy==gy) || (s[sy][sx]=='#' || s[gy][gx]=='#')){
                        continue;
                    }
                    vector<vector<int>> dist(h,vector<int>(w,INF));
                    queue<P> que;
                    que.push({sx,sy});
                    dist[sy][sx] = 0;
                    vector<int> dx{1,-1,0,0};
                    vector<int> dy{0,0,1,-1};
                    while(!que.empty()){
                        int x = que.front().first;
                        int y = que.front().second;
                        que.pop();
                        rep(i,4){
                            int ix = x+dx[i]; 
                            int iy = y+dy[i];
                            if(ix<0 || ix>=w || iy<0 || iy>=h) continue;
                            if(dist[iy][ix] <= dist[y][x]+1 || s[iy][ix]=='#') continue;
                            dist[iy][ix] = dist[y][x]+1;
                            que.push({ix,iy});
                        }
                    }
                    ans = max(ans,dist[gy][gx]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
		
		System.out.println(Math.abs(x-a) > Math.abs(x-b) ? 'B' : 'A');
	}

}


Measured memory_bytes: 23760
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(m)]

ans=-1
for i in range(1000):
    OK=True
    STR=str(i)
    if len(STR)==n:
        for g in range(m):
            if int(STR[sc[g][0]-1])!=sc[g][1]:
                OK=False
                break
    else:
        OK=False
    if OK:
        ans=i
        break
print(ans)

Measured memory_bytes: 3064
n = int(input())
if not n%2:
    n -= 1

result = 0

for i in range(1,n+2,2):
    cnt = 0

    for ii in range(1,i+2,2):
        if i%ii == 0:
            cnt += 1

    if cnt >= 8:
        result += 1

print(result)

Measured memory_bytes: 3060