akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, d[100001], max_d = 0;
ll c[100001];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", d + i), c[d[i]]++, max_d = max(max_d, d[i]);
		if (d[i] == 0 && i != 0) {
			printf("0\n");
			return 0;
		}
	}
	ll sum = 1;
	for (int i = 1; i <= max_d; i++)
		for (int j = 0; j < c[i]; j++)
			sum = sum * c[i - 1] % 998244353;
	printf("%lld\n", sum);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));
    vector<vector<int>> num(H, vector<int>(W, -1));
    int cnt = 0;
    rep(i, H) rep(j, W){
        cin >> s[i][j];
        if(s[i][j] == '.'){
            cnt++;
        }
    }
    queue<int> xq, yq;
    yq.push(0); xq.push(0);
    num[0][0] = 1;
    int ans = -1;
    while(yq.size()){
        int y = yq.front(), x = xq.front();
        vector<int> yv = {0,1,0,-1}, xv = {1,0,-1,0};
        rep(i, 4){
            int yt = y + yv[i], xt = x + xv[i];
            if(yt < 0 || yt >= H || xt < 0 || xt >= W) continue;
            if(num[yt][xt] == -1 && s[yt][xt] == '.'){
                yq.push(yt); xq.push(xt);
                num[yt][xt] = num[y][x] + 1;
            }
        }
        yq.pop(); xq.pop();
        if(num[H-1][W-1] != -1){
            ans = cnt - num[H-1][W-1];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int N = 109;
int a[N];
int main()
{
    //freopen("in.txt","r",stdin);
    int n; cin>>n;
    int sum  = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    double db = 1.0*sum/n;
    int index = 0;
    double minn = 999999.0;// cout<<db<<endl;
    for(int i = 0; i < n; i++)
    {
        if(fabs(a[i]*1.0-db)<minn) {
            index=i; minn = fabs(a[i]*1.0-db);}
    }
    cout<<index<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * @author torith
 * @date 2018-11-04
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;

    map<int,int> rec;
    vector<pair<int,int>> par;

    for (int i = 0; i < M; ++i) {
        int P,Y; cin >> P >> Y;
        rec[Y] = P;
        par.push_back(make_pair(P,Y));
    }

    int A[100001] = {};
    map<int,int> B;
    for(auto &m : rec){
        B[m.first] = A[m.second] + 1;
        A[m.second]++;
    }

    for (auto & p : par){
        cout << setfill('0') << right << setw(6) << p.first
             << setfill('0') << right << setw(6) << B[p.second] << "\n";
    }

    return 0;
}



Measured memory_bytes: 12148
#include<stdio.h>
#include<string.h>
int main(void)
{
  int count=0,len,i;
  char str[128];
  
  fgets(str,sizeof(str),stdin);
  len = strlen(str)-1;
  for(i=0;i < len/2;i++)
  {
    if(str[i] != str[len-i-1])
    {
      count++;
    }
  }
  printf("%d",count);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef pair<int,int>P;
#define F first
#define S second

int n,T,s,t;
vector<P>v[100009];
int E_aru[100009];


void END(){
  cout<<"No"<<endl;
  exit(0);
}

void YEAY(){
  cout<<"Yes"<<endl;
  exit(0);
}



int dfs0(int x,int par);
int dfs(int x,int par){

  int ofset = -T;
  int p_cost=-1;
  if(x==s)ofset=0;

  vector<P>vec;
  r(i,v[x].size()){
    if(E_aru[x] == v[x][i].F)continue;
    if(v[x][i].F == par){
      p_cost = i;
      v[x][p_cost].S -= T;
      continue;
    }
    vec.push_back( P(v[x][i].S,i) );
  }

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

  r(i,vec.size()){

    if(v[x][vec[i].S].S + ofset <=0 )END();
    dfs( v[x][vec[i].S].F , x );

    if(p_cost != -1)v[x][p_cost].S -= T;
    ofset -= T;
  }

  if(E_aru[x] != -1){
    r(i,v[x].size()){
      if(E_aru[x] != v[x][i].F)continue;
      if(v[x][i].S +  ofset <=0 )END();
      dfs( E_aru[x] , x );
    }
  }

  if(x==t)YEAY();

  if(p_cost != -1 &&  v[x][p_cost].S <= 0)END();
}


signed main(){
  memset(E_aru,-1,sizeof(E_aru));
  cin>>n;
  cin>>T>>s>>t; s--; t--;

  r(i,n-1){
    int a,b,c;
    cin>>a>>b>>c; a--; b--;
    v[a].push_back(P(b,c));
    v[b].push_back(P(a,c));
  }

  dfs0(s,-1);
  dfs(s,-1);

  cout<<"DAME"<<endl;
  exit(1);
}





int dfs0(int x,int par){
  if(x==t)return 1;
  int res=0;
  r(i,v[x].size()){
    if(v[x][i].F==par)continue;
    int X=dfs0(v[x][i].F,x);
    if(X==1)E_aru[x] = v[x][i].F , res=1;
  }
  return res;
}


Measured memory_bytes: 12364
#include <bits/stdc++.h>
using namespace std;
#define F first  
#define S second
#define ll long long
#define pb push_back
#define pr pair<ll,ll>

const ll N=1e5+9,mod=1e9+7,inf=1e18;

int r,c,vis[22][22];
string s[22];



int bfs(int i,int j)
{
	queue< pair< pair<int,int>,int > > q;
	q.push({ {i,j},0});
	int mx=0;
	vis[i][j]=true;
	while(!q.empty())
	{
		auto p=q.front();
		q.pop();
        if(s[p.F.F][p.F.S]=='#')continue;
        mx=max(mx,p.S);
        if( !vis[p.F.F][p.F.S+1])  
        	{
        		vis[p.F.F][p.F.S+1]=true;
        		q.push(  {  {p.F.F,p.F.S+1} ,p.S+1} );
        	}
        if( !vis[p.F.F][p.F.S-1]) 
        {
        	vis[p.F.F][p.F.S-1]=true;
          q.push(  {  {p.F.F,p.F.S-1} ,p.S+1} );
        } 
         if( !vis[p.F.F+1][p.F.S])
         {
         	vis[p.F.F+1][p.F.S]=true;
         	 q.push(  {  {p.F.F+1,p.F.S} ,p.S+1} );
         } 
         if( !vis[p.F.F-1][p.F.S]) 
         	{
         		vis[p.F.F-1][p.F.S]=true;
         		 q.push(  {  {p.F.F-1,p.F.S} ,p.S+1} );
         	}

	}
	return mx;
}

int main()
{
	cin>>r>>c;
	for(int i=0;i<=c+1;i++)
	{
		s[0].pb('#');
		s[r+1].pb('#');
	}
    for(int i=1;i<=r;i++)
    {
    	cin>>s[i];
    	s[i]="#"+s[i]+"#";
    }
    int mx=0;

    for(int i=1;i<=r;i++)
    {
    	for(int j=1;j<=c;j++)
    	{
    		
    		memset(vis,0,sizeof vis);
    		mx=max(mx,bfs(i,j));
    	}
    }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int, int>P;
typedef long long ll;

int main() {
	int n, a, b; scanf("%d%d%d", &n, &a, &b);
	int cnt = n;
	rep(i, n) {
		int t; scanf("%d", &t);
		if (a <= t&&t < b)cnt--;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int ans = 0, n;

void func(vector<vector<int> >& v, int id, map<int, int>& mp){
  if(mp[id] > 0){
    return;
  }
  mp[id]++;
  if(mp.size() == n){
    ans++;
    mp.erase(id);
    return;
  }
  for(int i = 0; i < v[id].size(); i++){
    func(v, v[id][i], mp);
  }
  mp.erase(id);
  return;
}

void solve(){
  int m; cin >> n >> m;
  vector<vector<int> > v(n + 1);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  map<int, int> mp;
  mp[1]++;
  for(int i = 0; i < v[1].size(); i++){
    func(v, v[1][i], mp);
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;


int N;

long long int x[100005];

long long int MOD = 1000000007;


long long int K[200005];
long long int Int_inv[200005];

long long int POW(long long int a, long long int k) {
	if (k == 0) { return 1; }
	if (k % 2 == 1) { return (a*POW(a, k - 1)) % MOD; }

	long long int ret = POW(a, k / 2);
	return (ret*ret) % MOD;
}


long long int INV(long long int a) {
	return POW(a, MOD - 2);
}

int check[2050][2050];
long long int P_val[2050][2050];

long long int P(int i, int j) {

	if (i<=2000 && j<=2000 && check[i][j] == 1) {
		return P_val[i][j];
	}
	long long int ret = K[N - 1];
	ret *= Int_inv[j - i + 1];
	ret %= MOD;
	ret *= Int_inv[j - i];
	ret %= MOD;

	if (i <= 2000 && j <= 2000) {
		check[i][j] = 1;
		P_val[i][j] = ret;
	}

	return ret;
}

long long int Q(int i) {
	long long int ret = K[N - 1];
	ret *= Int_inv[N - i];

	return ret %= MOD;
}

long long int T(int i) {
	long long int ret = K[N - 1];

	ret *= (N - i - 1);
	ret %= MOD;

	ret *= Int_inv[N - i];

	return ret%MOD;
}

long long int S(int i) {
	long long int ret = K[N - 1];
	ret *= (i - 1);
	ret %= MOD;
	ret *= Int_inv[i];

	return ret%MOD;
}

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> x[i];
	}
	K[0] = 1;
	for (int i = 1; i <= 200000; i++) {
		K[i] = K[i - 1] * i;
		K[i] %= MOD;
	}

	
	for (int i = 1; i <= 200000; i++) {
		Int_inv[i] = INV(i);
	}

	long long int ans = 0;

/*	for (int i = 1; i <= N - 2; i++) {
		for (int j = i + 1; j <= N - 1; j++) {
			ans += ((x[j] - x[i])*P(i, j)) % MOD;
			ans %= MOD;
		}
	}
	*/


	for (int j = 2; j <= N - 1; j++) {
		ans += (x[j] * S(j))%MOD;
		ans %= MOD;
	}

	for (int i = 1; i <= N - 2; i++) {
		ans += MOD - ((x[i] * T(i)) % MOD);
		ans %= MOD;
	}

	for (int i = 1; i <= N - 1; i++) {
		ans += ((x[N] - x[i])*Q(i)) % MOD;
		ans %= MOD;
	}
	
	cout << ans << endl;

/*	long long int tmp=0;
	int j = 11;
	for (int i = 1; i <= j - 1; i++) {
		tmp += P(i, j);
		tmp %= MOD;
	}
	cout << "tmp= " << tmp << endl;

	cout << "S= " << S(j) << endl;

	tmp = 0;

	int i = 3;
	for (int j = i + 1; j <= N - 1; j++) {
		tmp += P(i, j);
		tmp %= MOD;
	}
	cout << "tmp= " << tmp << endl;
	cout << "T= " << T(i) << endl;*/
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int INF = 1001001001;
int main() {
    int n;
    int p[110];
    int dp[110][110];
    cin >> n;
    for(int i = 1;i<=n;i++) cin >> p[i-1] >> p[i];
    for(int i = 0;i<=n;i++) dp[i][i] = 0;
    for(int l = 2;l<=n;l++) {
        for(int i = 1;i <= n-l+1;i++) {
            int j = i+l-1;
            dp[i][j] = INF;
            for(int k = i;k<j;k++) {
                chmin(dp[i][j],dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    cout << dp[1][n] << endl;
}


Measured memory_bytes: 3124
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

using namespace std;

typedef long long LL;

int n;

char s[3333];

bool ok(int l, int r) {

    for (;l<r;l++,r--) {
        if(s[l]!=s[r]) return 0;
    }
    return 1;

}

int main() {
  
  scanf("%s", s+1);

  n = strlen(s+1);

  if (ok(1, n) && ok(1, (n-1)/2) && ok((n+3)/2,n)) cout << "Yes";
  else cout << "No";
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

vector <ll> factorials;
vector <ll> inv_factorials;
ll mod=1e9+7;

ll modExp(ll x, ll n)
{
    if (n==0) return 1;
    if (n==1) return x%mod;
    ll ans = modExp(x,n/2);
    ans = (ans*ans)%mod;
    if (n%2) ans*=x;
    return ans%mod;
}

ll modInv(ll a)
{
    return modExp(a, mod-2);
}

ll choose(ll n, ll k) 
{
    if (k==0) return 1;
    if (k<0 || k>n) return 0;
    ll ans = factorials[n] * inv_factorials[k] % mod;
    return (ans * inv_factorials[n - k]) % mod;
}

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

    const int kRange = 3e6;
    factorials.resize(kRange + 1, 1);
    inv_factorials.resize(kRange + 1, 1);
    loop(i,2, kRange+1)
    {
        factorials[i]=(factorials[i-1]*i)%mod;
    }
    inv_factorials[kRange] = modInv(factorials[kRange]);
    for (int i = kRange - 1; i >= 0; --i) {
        inv_factorials[i] = (inv_factorials[i + 1] * (i + 1)) % mod;
    }

    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans=0;
    for (ll j=c1; j<=c2; ++j)
    {
        ll temp = (choose(r2+j+1, j+1)-choose(r1+j, j+1)+mod)%mod;
        ans = (ans+temp)%mod;
    }
    cout << ans << "\n";
    return 0;
}


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

using Weight = int;
struct Edge {
	int src, dst; Weight weight;
	Edge() {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;

struct UnionFind {
	vector<int> par;
	int cnt;
	UnionFind(int size_) : par(size_, -1), cnt(size_) {}
	void unite(int x, int y) {
		if((x = find(x)) != (y = find(y))) {
			if(par[y] < par[x]) swap(x, y);
			par[x] += par[y]; par[y] = x; cnt--;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	int size(int x) { return -par[find(x)]; }
	int size() { return cnt; }
};

bool operator < (const Edge &e, const Edge &f) { return e.weight < f.weight; }
pair<Weight, Edges> kruskal(int N, Edges es) {
	UnionFind uf(N);
	Weight total = 0; Edges T;
	for(auto &e : es) if(!uf.same(e.src, e.dst)) {
		T.push_back(e); total += e.weight; uf.unite(e.src, e.dst);
	}
	return make_pair(total, T);
}

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

	int n, m;
	while(cin >> n >> m, n) {
		Edges G;
		for(int i = 0; i < m; i++) {
			int a, b, d;
			char c;
			cin >> a >> c >> b >> c >> d;
			G.push_back(Edge(a, b, d / 100 - 1));
		}
		sort(G.begin(), G.end());
		auto res = kruskal(n, G);
		cout << res.first << endl;
	}
}

Measured memory_bytes: 3308
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$code = getq(1);
if(abs($code[0]-$code[2])<=$code[3]){
	echo "Yes\n";
}else if(abs($code[0]-$code[1])<=$code[3]&&abs($code[1]-$code[2])<=$code[3]){
	echo "Yes\n";
}else{
	echo "No\n";
}
?>


Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int a = 2;
int b = 5;
int c = 4;

// vector<int> v = {2, 5, 4};
// int v[] = {2, 5, 4};
vector<int> v;

int main() {
    // int max_value = max({1, 2, 3});
    rep(i, 3) {
        int t;
        cin >> t;
        v.push_back(t);
    }
    
    int m = max_element(v.begin(), v.end()) - v.begin();
    
    int dist = 0;
    for (int i = 0; i < 3; i++) {
        if (i == m) {
            continue;
        }
        dist += abs(v[m] - v[i]);
    }

    if (dist % 2 == 0) {
        cout << dist / 2 << endl;
        return 0;
    }

    // 奇数の場合
    cout << ((dist + 1) / 2) + 1 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort()

if a[0] == 0:
  print(0)
  exit()

a.sort(reverse=True)
ans = 1

for i in range(n):
  ans *= a[i]
  if ans > 10 ** 18:
    ans = -1
    break

print(ans)

Measured memory_bytes: 21420
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll W, A, B;
	cin >> W >> A >> B;
	cout << max(ll(0),abs(A-B)-W)<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
using boost::integer::gcd;
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    int m = *max_element(a.begin(), a.end());
    int g = accumulate(a.begin(), a.end(), a[0], [](int a, int b){ return gcd(a, b); });
    if (m >= k && k % g == 0) {
        puts("POSSIBLE");
    } else {
        puts("IMPOSSIBLE");
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mx 1000000
using namespace std;
typedef long long LL;
int arr[mx];

int main()
{
    int i, j, t, x, n,a,y,b,flag=0,x1,y1;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}



Measured memory_bytes: 3620
#include <iostream>

using namespace std;

#include <iostream>
using namespace std;

int main()
{
	int num , x , i;
	cin >> num;
	long long sum = 0, min = 100000000000, max = -100000000000;
	
	for ( i = 0; i < num; i++)
	{
		cin >> x;
		sum = sum + x;

		if (x < min)
			min = x;
		if (x > max)
			max = x;
	}
	cout << min << " " << max << " " << sum << endl;
}


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

int main(){
  int a, b;
  int cnt = 0;
  cin >> a >> b;
  
  for(int i=a; i<=b; i++){
    string s = std::to_string(i);

    if(s[0] == s[4] && s[1] == s[3])
      cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt();
        boolean[][] field = new boolean[100][100];
        for (int i = 0; i < 50; i++) {
            for (int j = 0; j < 100; j++) {
                field[i][j] = true;
            }
        }
        for (int i = 0; i < a - 1; i++) {
            int x = i / 50 * 2;
            int y = i % 50 * 2;
            field[x][y] = false;
        }
        for (int i = 0; i < b - 1; i++) {
            int x = i / 50 * 2 + 51;
            int y = i % 50 * 2;
            field[x][y] = true;
        }
        System.out.println("100 100");
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                System.out.print(field[i][j] ? '#' : '.');
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 26940
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val as = in.readLine().split("\\s+").map(_.toInt)

    val lasts = Array.ofDim[Int](3)
    var pattern = 1L

    for (
      i <- 0 until n
    ) {
      pattern = pattern * lasts.count(_ == as(i)) % 1000000007
      val index = lasts.indexOf(as(i))
      if ( index != -1) {
        lasts(lasts.indexOf(as(i))) = as(i) + 1
      }
    }

    System.out.println(pattern)
  }
}


Measured memory_bytes: 53012
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int N, K, Q, t;
int A[MAX_N];
int main(void)
{
	cin >> N >> K >> Q;
	for (int i = 0; i < Q; i++)
	{
		cin >> t;
		A[t]++;
	}
	for (int i = 1; i <= N; i++)
	{
		if (A[i] + K - Q > 0)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
use proconio::input;

fn count(a: &Vec<usize>, b: &Vec<usize>, c: &Vec<usize>) -> usize {
    let mut result = 0;
    for i in a {
        let j_index = match b.binary_search_by(|insert| insert.cmp(&i)) {
            Ok(ind) => ind,
            Err(ind) => ind,
        };
        for j in b[j_index..].iter() {
            let k_index = match c.binary_search_by(|insert| insert.cmp(&j)) {
                Ok(ind) => ind,
                Err(ind) => ind,
            };
            result += if let Ok(_) = c.binary_search(&(j - i + j)) {
                c.len() - k_index - 1
            } else {
                c.len() - k_index
            }
        }
    }
    result
}

fn main() {
    input! {
        _n: usize,
        s: String,
    }
    let (mut r, mut g, mut b) = (
        Vec::<usize>::new(),
        Vec::<usize>::new(),
        Vec::<usize>::new(),
    );
    for (i, c) in s.chars().enumerate() {
        match c {
            'R' => r.push(i),
            'G' => g.push(i),
            'B' => b.push(i),
            _ => panic!(),
        }
    }
    let result = count(&r, &g, &b)
        + count(&r, &b, &g)
        + count(&g, &r, &b)
        + count(&g, &b, &r)
        + count(&b, &g, &r)
        + count(&b, &r, &g);
    println!("{}", result);
}


Measured memory_bytes: 2176
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    vi a(n);
    for(int &i : a) cin>>i;
    int mx = 0, ans = 0;
    for(int i : a){
        if(i < mx) ans += mx-i;
        mx = max(mx,i);
    }
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            input_iter = LazyLoadAllLines();
            //------------------------------------------------//
            //var n = Read<long>();
            //var s = Read();
            //var als = Read<long>(n);
            //var sls = Read(n);
            /*List<Tuple<string, long>> scls = new List<Tuple<string, long>>();
            for (int i = 0; i < m; ++i)
            {
                scls.Add(new Tuple(Read(), Read<long>()));
            }*/
            //List<List<long>> abls = new List<List<long>>();
            //List<long> cls = new List<long>();
            /*List<long> edgeNum = Enumerable.Repeat(0L, (int)n).ToList();
            for (int i = 0; i < n - 1; ++i)
            {
                abls.Add(Read<long>(2));
                abls[i].Add(i);
                abls[i].Add(-1);
                --abls[i][0];
                --abls[i][1];
                //cls.Add(Read<long>());
                ++edgeNum[(int)abls[i][0]];
                ++edgeNum[(int)abls[i][1]];
            }*/

            //als.Sort((l, r) => (r - l));
            //sls.Sort(StringComparer.OrdinalIgnoreCase);

            var n = Read<long>();

            Console.WriteLine((n + 1) / 2);
        }

        static IEnumerator<string> input_iter;

        static IEnumerator<string> LazyLoadAllLines(bool doSplit = true)
        {
            string line;
            if (doSplit)
            {
                do
                {
                    line = Console.ReadLine();
                    foreach (var s in line.Split(' '))
                        yield return s;
                } while (line != null);
            }
            else
            {
                do
                {
                    line = Console.ReadLine();
                    yield return line;
                } while (line != null);
            }
        }
        static _T Read<_T>() where _T : struct
        {
            input_iter.MoveNext();
            return (_T)Convert.ChangeType(input_iter.Current, typeof(_T));
        }
        static string Read()
        {
            input_iter.MoveNext();
            return input_iter.Current;
        }
        static List<_T> Read<_T>(long num) where _T : struct
        {
            List<_T> res = new List<_T>();
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add((_T)Convert.ChangeType(input_iter.Current, typeof(_T)));
            }
            return res;
        }
        static List<string> Read(long num)
        {
            List<string> res = new List<string>();
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add(input_iter.Current);
            }
            return res;
        }

    }
}


Measured memory_bytes: 11220
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b, c ] <- sort <$> readInts
	putStrLn $ which "Yes" "No" $ a + b == c


Measured memory_bytes: 508
//
//  main.c
//  ITP1_11_C
//
//  Created by k16031kk on 2018/05/30.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int area[6];
    int s[6];
    for(int i=0; i<6; i++) {
        scanf("%d", &area[i]);
    }
    for(int i=0; i<6; i++) {
        scanf("%d", &s[i]);
    }
    int a=0;
    int flag=0;
    for(int i=0; i<3; i++) {
        a=area[0];
        area[0]=area[3];
        area[3]=area[5];
        area[5]=area[2];
        area[2]=a;
        if(memcmp(area, s, sizeof(int)*6)==0) {
            flag=1;
            break;
        }
        for(int j=0; j<3; j++) {
            a=area[0];
            area[0]=area[1];
            area[1]=area[5];
            area[5]=area[4];
            area[4]=a;
            if(memcmp(area, s, sizeof(int)*6)==0) {
                flag=1;
                break;
            }
            for(int k=0; k<3; k++) {
                a=area[0];
                area[0]=area[4];
                area[4]=area[5];
                area[5]=area[1];
                area[1]=a;
                if(memcmp(area, s, sizeof(int)*6)==0) {
                    flag=1;
                    break;
                }
                for(int l=0; l<3; l++) {
                    a=area[0];
                    area[0]=area[2];
                    area[2]=area[5];
                    area[5]=area[3];
                    area[3]=a;
                    if(memcmp(area, s, sizeof(int)*6)==0) {
                        flag=1;
                        break;
                    }
                }
            }
        }
    }
    if(flag==1) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}




Measured memory_bytes: 2104
a, b = list(map(int, input().split()))
grid = list()
grid.append([-1 for _ in range(b + 2)])
for t in range(0, a):
    grid.append([-1])
    line = list(input())
    for k in range(len(line)):
        if line[k] == '#':
            grid[t + 1] += [-1]
        else:
            grid[t + 1] += [0]
    grid[t + 1] += [-1]
grid.append([-1 for _ in range(b + 2)])
grid[1][1] = 1
for x in range(1, a + 1):
    for y in range(1, b + 1):
        if grid[x][y] > 0:
            if grid[x + 1][y] != -1:
                grid[x + 1][y] += grid[x][y]
            if grid[x][y + 1] != -1:
                grid[x][y + 1] += grid[x][y]
print(grid[-2][-2] % (10 ** 9 + 7))

Measured memory_bytes: 157296
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e-a > k) cout << ":(" << endl;
	else cout << "Yay!" << endl;



	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d%d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    {
    if(a==0&&b==0)printf("0\n");
    if(c>=d&&c>e)printf("%d\n",c);
    else if(d>c&&d>e)printf("%d\n",d);
    else if(e>c&&e>d)printf("%d\n",e);
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
A = list(map(int, input().split()))

def obj_func(v, base):
  return abs(v - base)

ai = aj = max(A)
base = ai / 2
min_obj = 10**10
for a in A:
  if a == ai:
    continue
  obj = obj_func(a, base)
  if obj < min_obj:
    min_obj = obj
    aj = a

print(ai, aj)

Measured memory_bytes: 14428
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A(K);
    for (int i = 0; i < K; ++i)
    {
        int dt;
        cin >> dt;
        d[i] = dt;
        A[i].reserve(d[i]);
        for (int j = 0; j < d[i]; ++j)
        {
            int temp;
            cin >> temp;
            --temp;
            A[i][j] = temp;
        }
    }

    vector<int> num(N, 0);
    for(int i = 0; i < K; ++i) for (int j = 0; j < d[i]; ++j) ++num[A[i][j]];
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (num[i] == 0) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nk = readInts()
    let (n, k) = (nk[0], nk[1])
    //__________________________________ここまで入力処理
    let surplus = n % k
    
    print(min(surplus, abs(surplus - k)))
}


main()




Measured memory_bytes: 13488
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N,M;
  cin>>N>>M;
  if(N>=2 && M>=2) {
  ll A=(N-2)*(M-2);
  cout<<A<<endl;
  }
  if(N==1 && M==1)
    cout<<"1"<<endl;
  else if(N==1 || M==1) {
    cout<<max(N,M)-2<<endl;
  }
}


Measured memory_bytes: 256
H,W=gets.split.map(&:to_i)

map = []
bcount = 0
H.times do
    s = gets.chomp.chars
    map << s
    bcount += s.count('#')
end

walked = Array.new(H) { Array.new(W,false) }
q = [[0,0,1]]
loop do
    if q.empty?
        puts -1
        exit
    end
    x,y,d = q.shift
    next if walked[y][x]
    walked[y][x] = true
    if x == W-1 && y == H-1
        puts H*W - bcount - d
        exit
    end

    q << [x-1,y,d+1] if 0 <= x-1 && !walked[y][x-1] && map[y][x-1] == '.'
    q << [x+1,y,d+1] if x+1 < W && !walked[y][x+1] && map[y][x+1] == '.'
    q << [x,y-1,d+1] if 0 <= y-1 && !walked[y-1][x] && map[y-1][x] == '.'
    q << [x,y+1,d+1] if y+1 < H && !walked[y+1][x] && map[y+1][x] == '.'
end

Measured memory_bytes: 2044
#include <iostream>
#include <set>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a,b,c;
	for (int i = 0; i < n; ++i) {
		int ai;
		cin >> ai;
		ai--;
		a.push_back(ai);
	}
	for (int i = 0; i < n; ++i) {
		int bi;
		cin >> bi;
		b.push_back(bi);
	}
	for (int i = 0; i < n-1; ++i) {
		int ci;
		cin >> ci;
		c.push_back(ci);
	}
	int score = 0;
	for (int i = 0; i < n; ++i) {
		int eat = a[i];
		score += b[eat];
		if (i != 0) {
			int last = a[i - 1];
			if (last+1 == eat) {
				score += c[last];
			}
		}
	}
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

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

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll K;
    in >> K;
    ll ans = 0;
    REP(i, K) REP(j, K) REP(k, K) {
        ans += gcd(gcd(i+1,j+1), k+1);
    }
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 3652
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;

    // ありえる水の容量を列挙
    int a = 0;
    vector<int> tmp = {};
    while(100 * A * a <= F){
        tmp.push_back(100 * A * a);
        a++;
    }

    vector<int> water;
    for(auto & w : tmp){
        int b = 0;
        while(w + 100 * B * b <= F){
            water.push_back(w + 100 * B * b);
            b++;
        }
    }

    // ありえる砂糖の容量を列挙
    a = 0;
    vector<int> tmp2 = {};
    while(C * a <= F){
        tmp2.push_back(C * a);
        a++;
    }

    vector<int> sugar = {};
    for(auto & s : tmp2){
        int b = 0;
        while(s + D * b <= F){
            sugar.push_back(s + D * b);
            b++;
        }
    }

    sort(water.begin(),water.end());
    sort(sugar.begin(),sugar.end());
    water.erase(unique(water.begin(), water.end()), water.end());
    sugar.erase(unique(sugar.begin(), sugar.end()), sugar.end());

    double max_con = 0;
    int max_w, max_s;
    for(auto & w: water){
        for (auto & s: sugar){
            if (w+s <= F && (double) s/(w+s) <= (double) E/(100+E) && max_con <= (double) s/(w+s)){
                max_con = (double) s/(w+s);
                max_w = w;
                max_s = s;
            }
        }
    }

    cout << (max_w+max_s) << " " << max_s << "\n";


    return 0;
}



Measured memory_bytes: 1400
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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 = 1LL << 60;

//input
int N;
long long h[100100];

//DP table
long long dp[100100];

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)  cin >> h[i]; 
    for (int i = 0; i < 100100; ++i) dp[i] = INF;

    dp[0] = 0;
    
    for (int i = 1; i < N; ++i) {
       chmin(dp[i], dp[i - 1] + abs(h[i] - h[i -1]));
       if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
		int number;
		cin>>number;
		int first=0;
		int third=0;
		first=number/100;
		third=number%10;
		if(first==third)
		cout<<"Yes"<<endl;
		else 
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b >= c) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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




int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b;
	cin>>a>>b;
	if(b%a==0){
		cout<<a+b;
	}else{
		cout<<b-a;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int h[100005] = {0};
int main()
{
	int n, a;
     cin >> n ; 
	 int sum = 0;
	 int p;
	 p = 0;
	 for (int i = 1; i <= n; i++) {
		 cin >> a;
		 sum += abs(p - a);
		 h[i] = a;
		 p = a;
	 }
	 sum += abs(a);
	 for (int i = 1; i <= n; i++) {
		 if ((h[i] - h[i - 1])*(h[i + 1] - h[i])<0)cout<<sum-2*min(abs(h[i] - h[i - 1]),abs(h[i+1] - h[i]))<<endl;
		 else cout<<sum<<endl;

	 }
	// cout << sum << endl;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
using namespace std;


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  
  int A,B;
  cin >> A >> B;
  
  if ( A >= 10 || B >= 10 ){
    cout << -1 << endl;
  }
  else{
    cout << A*B << endl;
  }
}



Measured memory_bytes: 256
var
    a:array[0..100010] of longint;
    i,n,s,t:longint;
procedure qsort(l,r:longint);
var
    i,j,t,mid:longint;
begin
    i:=l; j:=r; mid:=a[(l+r) div 2];
    repeat
        while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then
        begin
            t:=a[i]; a[i]:=a[j]; a[j]:=t;
            inc(i); dec(j);
        end;
    until i>j;
    if l<j then qsort(l,j);
    if i<r then qsort(i,r);
end;
begin
    read(n);
    for i:=1 to n do read(a[i]);
    qsort(1,n);
    s:=0; t:=1;
    for i:=2 to n+1 do
    begin
        if a[i]=a[i-1] then inc(t);
        if a[i]<>a[i-1] then
        begin
            if t>=a[i-1] then s:=s+t-a[i-1]
            else s:=s+t;
            t:=1;
        end;
    end;
    writeln(s);
end.

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

#define test(a) cout<<#a<<':'<<a<<endl

class tree{
public:
  tree* par;
  vector<tree*> chi;
  int cnt;
};


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  ll n;cin>>n;
  ll ans = (n * (n - 1)) / 2;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,ans,x,n,sum,c,w,h,y;
    	cin>>w>>h>>x>>y;
    	cout<<fixed<<setprecision(9);
    	lld k=(w*h*1.00)/2.00;
    	if(x*2==w && y*2==h)
    	cout<<k<<" "<<1;
		else
		cout<<k<<" "<<0;
    } 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int x, y, z = 0;
	while (x != -1 || y != -1 || z != -1) {
		cin >> x >> y >> z;
		if (x == -1 && y == -1 && z == -1)
			return 0;

		if (x == -1 || y == -1)
			cout << "F" << endl;
		else if (x + y >= 80)
			cout << "A" << endl;
		else if (x + y >= 65)
			cout << "B" << endl;
		else if ((x + y < 30))
			cout << "F" << endl;
		else if ((x + y >= 50) || z >= 50)
			cout << "C" << endl;
		else if ((x + y >= 30))
			cout << "D" << endl;
	}

	return 0;
}



Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		for (int i=1;i <= 5;i++) {
			if(sc.nextInt() == 0) {
				System.out.println(i);
				break;
			}
		}

		sc.close();

	}

}

Measured memory_bytes: 26972
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF (1<<30)

// 素因数分解O(√n)
map<int, int> prime_factor(int n) {
	map<int, int> res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

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

	int cnt=0;

	map<int,int> m;
	for (int i = 1; i <= N; i++) {
		map<int,int> t = prime_factor(i);
		for (auto x : t) {
			m[x.first] += x.second;
		}
	}

	for (auto i : m) {
		for (auto j : m) {
			for (auto k : m) {
				if(i.first == j.first || j.first == k.first || i.first == k.first) continue;
				if(i.first > j.first) continue;
				if (i.second >= 4 && j.second >= 4 && k.second >= 2) {
					//cout << i.first <<" "<< j.first <<" "<< k.first << endl;
					cnt++;
				}
			}
		}
	}

	for (auto i : m) {
		for (auto j : m) {
			if(i.first == j.first) continue;
			if(i.second >= 4 && j.second >= 14) cnt++;
		}
	}
	for (auto i : m) {
		for (auto j : m) {
			if (i.first == j.first) continue;
			if (i.second >= 2 && j.second >= 24) cnt++;
		}
	}
	for (auto i : m) {
		if(i.second >= 74) cnt++;
	}

	
	
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N;
  string S;
  cin >> N >> S;

  bool flag = false;
  while(!flag){
    flag = true;
    int length = S.size();
  for(int i = 0; i < length-1; i++){
    if(S.at(i) == S.at(i+1)){
      S.erase(i,1);
      flag = false;
      length--;
    }
  }
  }
  
  cout << S.size() << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    cout << "ABC" + to_string(n) << endl;
}


Measured memory_bytes: 256