akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <numeric>
#include <algorithm>

using namespace std;

struct Cerulean {
    int64_t pos = 0;
    int64_t hp = 0;
};

constexpr int64_t attack_count(int64_t hp, int64_t atk)
{
    return hp <= 0 ? 0 : (hp / atk + (hp % atk ? 1 : 0));
}

constexpr int64_t enough_damage(int64_t hp, int64_t atk)
{
    return hp <= 0 ? 0 : (hp + (hp % atk == 0 ? 0 : atk - hp % atk));
}

int main()
{
    int64_t N,D,A;
    cin >> N >> D >> A;
    vector<Cerulean> ceruleans(N);
    for(auto& c : ceruleans) cin >> c.pos >> c.hp;
    sort(begin(ceruleans), end(ceruleans), [](const auto& x, const auto& y){ return x.pos < y.pos; });
    if(D > 0){
        size_t i = 0;
        size_t j = 1;
        int64_t damage = enough_damage(ceruleans[0].hp, A);
        for(; j < ceruleans.size(); ){
            while(ceruleans[j].pos - ceruleans[i].pos > 2 * D){
                damage -= enough_damage(ceruleans[i].hp, A);
                ++i;
            }
            ceruleans[j].hp = max(0L, ceruleans[j].hp - damage);
            damage += enough_damage(ceruleans[j].hp, A);
            ++j;
        }
    }
    
    int64_t count = 0;
    for(const auto& c : ceruleans){
        count += attack_count(c.hp, A);
    }
    cout << count << '\n';
}
/*
2 * * * 4       2
----------------------
1 2 3 4 5 6 7 8 9 10
*/


Measured memory_bytes: 3328
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])


Measured memory_bytes: 48108
#include<bits/stdc++.h>
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#include<bitset>
typedef long long ll;
const ll mod = 1e9 + 7;
const int t = 60;
void input(){
   ll n; scanf("%lld", &n);
   vector<ll>a(n);
   f(i, n) scanf("%lld", &a[i]);
   vector<vector<ll> > one_cnt(n, vector<ll>(t, 0));
   f(i, n){
    ll x= a[i];
    ll k = 0;
    while(x > 0){
        ll y  = x % 2;
        if(y == 1)one_cnt[i][k]++;
        ++k;
        x /= 2;
    }
   }
   for(ll j = 0; j < t; ++j){
       for(ll i = n - 2; i >= 0; --i){
        one_cnt[i][j] += one_cnt[i + 1][j];
       }
   }
    ll ans = 0LL;
    ll k = 1LL;
    f(i, n - 1){
        k = 1LL;
        f(j, t){
            ll x = (n - 1 - i) - one_cnt[i + 1][j];
            if(one_cnt[i][j] == one_cnt[i + 1][j] + 1){
                ans = (ans + ( k * x % mod)) % mod;
            }else{
                ans = (ans + ( k * ((ll)one_cnt[i + 1][j])) % mod) % mod;
            }
             k = (k * 2LL) % mod;
        }

    }
    printf("%d\n", (int)ans);
}
int main(){
    input();
    return 0;
}



Measured memory_bytes: 154880
#include<stdio.h>
    
    int min(long long a,long long b){
        if(a < b) return a;
        else return b;
    }

    int main(){
    	long long n,t,i,sum = 0;
    	scanf("%lld %lld",&n,&t);
        long long a[n];
    	for(i = 0;i < n;i++)
    	scanf("%lld",&a[i]);
    	for(i = 0;i < n;i++){
            sum += min(a[i+1] - a[i],t);
    	}
    	printf("%lld\n",sum);
    	
    }

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//???????????????
		int time = sc.nextInt();
		//??????
		int hour = time / 60 / 60;
		//???
		int minutse = time / 60 % 60;
		//?§?
		int secound = time % 60;
		//???????????¨???
		System.out.println(hour +":"+ minutse + ":" + secound);
	}
}

Measured memory_bytes: 26320
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=1e18;
string s;
int main(){
	cin>>s;
	if(s.size()==2)
		cout<<s;
	else
		for(int i=s.size()-1;i>=0;i--)
			cout<<s[i];
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  using P = pair<int, int>;
  vector<P> v(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    v[i] = P(a, b);
  }
  sort(v.begin(), v.end(), [&](const P& a, const P& b) {
      return a.second == b.second ? a.first < b.first : a.second < b.second;
    });
  int x = -1;
  int ans = 0;
  rep(i, m) {
    if(x <= v[i].first) {
      ++ans;
      x = v[i].second;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 41;
int n;
int m1[N];
int m2[N];
int cost[N];
int r1,r2;
int dp[N][412][421];

int gcd(int a , int b)
{
	if(a==0 && b==0) return 1;
	if(a==b) return a;
	if(a ==0 || b==0) return max(a,b);
	if(a<b) swap(a,b);
	
	if(a%b==0) return b;
	else return gcd(a%b , b);
}

int rec(int x , int one , int two)
{
	if(x==n)
	{
		int potato = gcd(one,two);
		one = one/potato;
		two = two/potato;
		
		if(one == r1 && two == r2) return 0;
		else return 1e9;
	}
	
	if(dp[x][one][two]!=-1) return dp[x][one][two];
	
	int ret = 0;
	ret = min( rec(x+1 , one + m1[x] , two + m2[x]) + cost[x] , rec(x+1 , one , two) );
	
	return dp[x][one][two] = ret;
}


int main()
{
	cin >> n >> r1 >> r2;
	
	memset(dp,-1,sizeof(dp));
	
	for(int i=0;i<n;i++)
	{
		scanf("%d%d%d",&m1[i],&m2[i],&cost[i]);
	}
	int ans = rec(0,0,0);
	if(ans > 1e8) puts("-1");
	else cout << ans;
}

























































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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<string> s(n);
	vector<int> t(n); 
	for (int i=0; i<n; i++)
		cin>>s[i]>>t[i];
	string x; cin>>x;
	bool ok=false;
	int ret=0;
	for (int i=0; i<n; i++) { 
		if (ok) ret+=t[i];
		if (s[i]==x) ok=true;
	}
	cout<<ret<<endl;
	return 0;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const int MAX_N = (1 << 17);

template<typename T> class LazyRMQ {
    public:
    int n;
    T inf = INT_MAX;
    T data[2*MAX_N-1];
    T lazy[2*MAX_N-1];

    LazyRMQ(int m, T init_value=INT_MAX){
        // 2のべき乗にする
        n = 1;
        while(n < m) n <<= 1;
        rep(2*n-1){
            data[i] = init_value;
            lazy[i] = 0;
        }
    }

    void eval(int k, int kl, int kr){
        if(lazy[k] == 0) return;
        if(data[k] == inf) data[k] = 0;
        data[k] += lazy[k];
        if(kr - kl > 1){
            lazy[2*k+1] += lazy[k];
            lazy[2*k+2] += lazy[k];
        }
        lazy[k] = 0;
    }

    // [s,t)
    void add(int s, int t, int k, int kl, int kr, T x){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return;
        if(s <= kl && kr <= t){
            lazy[k] += x;
            eval(k, kl, kr);
            // cerr << s << " " << t << " " << k << " " << kl << " " << kr << ": " << data[k] << " " << lazy[k] << endl;
            return;
        }
        int kc = (kl+kr)/2;
        add(s, t, 2*k+1, kl, kc, x);
        add(s, t, 2*k+2, kc, kr, x);
        data[k] = min(data[2*k+1], data[2*k+2]);
    }

    // [s,t)
    T find(int s, int t, int k, int kl, int kr){
        eval(k, kl, kr);
        if(kr <= s || t <= kl) return inf;
        if(s <= kl && kr <= t){
            // cerr << "[" << kl << ", " << kr << ") " << data[k] << endl;
            return data[k];
        }
        int kc = (kl+kr)/2;
        T vl = find(s, t, 2*k+1, kl, kc);
        T vr = find(s, t, 2*k+2, kc, kr);
        // cerr << "[" << kl << ", " << kr << ") " << vl << " " << vr << endl;
        return min(vl, vr);
    }
};


int main(){
    int n,nq,q,s,t,x;
    cin >> n >> nq;
    
    LazyRMQ<int> rmq(n, 0);
    for(int i=0;i<nq;i++){
        cin >> q >> s >> t;
        if(q == 1){
            cout << rmq.find(s, t+1, 0, 0, rmq.n) << endl;
        }else{
            cin >> x;
            rmq.add(s, t+1, 0, 0, rmq.n, x);
        }
    }
}


Measured memory_bytes: 5176
#include <iostream>
#include <queue>
using namespace std;
signed main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n,m,o;
  cin>>n>>m;
  queue<int> l[n+1];
  int info;
  for(int i=0;i<m;i++){
    cin>>info;
    if(info==0){
      cin>>o;
      cout<<l[o].front()<<"\n";
      l[o].pop();
    }else{
      cin>>o;
      int s=1;
      for(int j=2;j<=n;j++){
	if(l[j].size()<l[s].size()) s=j;
      }
      l[s].push(o);
    }
  }
  return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main()
{
    float d, t;
    int s;
    cin >> d >> t >> s;
    float k = d / t;
    int r = floor(k);
    if (r < s)
    {
        cout << "Yes" << endl;
    }
    else if (r == s && floor(k) == ceil(k))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3836
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a >= b && a >= c) {
            System.out.println(b+c);
        } else if (b >= a && b >= c) {
            System.out.println(a+c);
        } else {
            System.out.println(a+b);
        }

		sc.close();
	}
}


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

typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return b<a?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 1000007 , mo = 998244353;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

lint jc[_],rjc[_];

inline void init(int n=_-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}

inline lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}

inline lint crx(int n,int m)
{
	return C(n+m,m);
}

int n,m;

int main()
{
	n=ty(),m=ty();
	if(n<m)swap(n,m);

	init(n+m);
	
	lint ans=0;
	for(int i=1;i<=m;i++)ans=(ans+crx(i,i)*crx(n-i,m-i)%mo)%mo;
	ans=(ans*inva(crx(n,m))%mo*inva(2)%mo+n)%mo;
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 15872
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 // ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
 
 
fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        a: u32,
        b: u32,
    }
    let mut result = 1;
    let mut cnt = 0;
    while result < b {
    	result += a - 1;
        cnt += 1;
    }
    println!("{}",cnt);
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
pii r[125252];

int dp[125252];

int main(){
    scanf("%d",&n);
    REP(i,n){
        int x,l;
        scanf("%d%d",&x,&l);
        r[i] = pii(x-l,x+l);
    }
    sort(r,r+n);
    fill(dp,dp+n+1,-1<<30);
    dp[0] = 0;
    REP(i,n){
        // dont use
        CHMAX(dp[i+1], dp[i]);
        // use
        int nxt = lower_bound(r,r+n,pii(r[i].second,-1)) - r;
        CHMAX(dp[nxt], dp[i]+1);
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define N 200010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int x,y,a,b,c,p[N],q[N],r[N];
ll ans;
priority_queue<int,vector<int>,greater<int> > q1,q2;
int main(){
	x=read(),y=read(),a=read(),b=read(),c=read();
	for(int i=1;i<=a;++i){
		p[i]=read();
	}
	for(int i=1;i<=b;++i){
		q[i]=read();
	}
	for(int i=1;i<=c;++i){
		r[i]=read();
	}
	sort(p+1,p+a+1,greater<int>());
	sort(q+1,q+b+1,greater<int>());
	sort(r+1,r+c+1,greater<int>());
	for(int i=1;i<=x;++i){
		ans+=p[i],q1.push(p[i]);
	}
	for(int i=1;i<=y;++i){
		ans+=q[i],q2.push(q[i]);
	}
	for(int i=1;i<=c;++i){
		if(q1.top()<q2.top()){
			if(r[i]>q1.top()){
				ans-=q1.top();
			q1.pop();
			ans+=r[i];
			q1.push(r[i]);
			}
			else break;
		}
		else{
			if(r[i]>q2.top()){
				ans-=q2.top();
				q2.pop();
				ans+=r[i];
				q2.push(r[i]);
			}
			else break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define INF 1000000000000000

struct edge {
	long long int to, cost;
	edge(long long int to, long long int cost) :to(to), cost(cost) {}
};

vector< vector<edge> > graph;

vector<long long int> dist;

bool bellman(long long int n, long long int s) {
	dist = vector<long long int>(n, INF);
	dist[s] = 0;
	for (long long int i = 0; i < n-1; i++) {
		for (long long int j = 0; j < n; j++) {
			for (long long int k = 0; k < graph[j].size(); k++) {
				edge e = graph[j][k];
				if (dist[j] != INF && dist[e.to] > dist[j] + e.cost) {
					dist[e.to] = dist[j] + e.cost;
				}
			}
		}
	}
	vector<int> hh(n, 0);
	for (long long int i = 0; i < n; i++) {
		for (long long int j = 0; j < n; j++) {
			for (long long int k = 0; k < graph[j].size(); k++) {
				edge e = graph[j][k];
				if (dist[j] != INF && dist[e.to] > dist[j] + e.cost) {
					dist[e.to] = dist[j] + e.cost;
					hh[e.to] = 1;
				}
				/*if (dist[j] != INF&&hh[j] == 1) {
					hh[e.to] = 1;
				}*/
			}
		}
	}

	if (hh[n-1] == 1) {
		return true;
	}

	return false;
}

int main() {
	//cout << INF << endl;
	long long int n, m;
	cin >> n >> m;

	graph = vector< vector<edge> >(n);

	long long int a, b, c;

	for (long long int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		a--;
		b--;
		graph[a].push_back(edge(b, -c));
	}

	if (bellman(n, 0)) {
		cout << "inf" << endl;
	}
	else {
		cout << -dist[n - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
using namespace std;

int n;
bool bad[10];

bool check(int x)
{
	while(x > 0)
	{
		if(bad[x%10]) return false;
		x /= 10;
	}
	return true;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	int k;
	cin >> n >> k;
	memset(bad, false, sizeof(bad));
	for(int i = 1; i <= k; i++)
	{
		int d;
		cin >> d;
		bad[d] = true;
	}
	while(check(n) == false)
		n ++;
	cout << n << endl;
	
	return 0;
}


Measured memory_bytes: 256
import itertools

N = int(input())
ORIGIN = tuple(range(1, N+1))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a , b = 0, 0

for i, group in enumerate(itertools.permutations(ORIGIN, N)):
  if group == P:
    a = i + 1
  if group == Q:
    b = i + 1

print(abs(a-b))

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(i, a, b) for (int __i = a; i < b; i++)
#define rep(i, n) reps(i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

string to_3shin(int x)
{
    string ret;
    while (x)
    {
        ret += to_string(x % 3);
        x /= 3;
    }
    reverse(ret.begin(), ret.end());
    for (int i = 0; ret.length() < 9; i++)
    {
        // cout << i << "," << ret.length() << endl;
        ret = "0" + ret;
    }
    return ret;
}

vector<ll> ret_ngs()
{
    vector<ll> v;
    for (int i = 0; i < pow(3, 9); i++)
    {
        string s = to_3shin(i);
        int tmp = 0;
        bool f1 = false, f2 = false, f3 = false;
        for (int i = 0; i <= 8; i++)
        {
            if (s[i] == '0')
            {
                tmp += 3 * pow(10, i);
                f1 = true;
            }
            else if (s[i] == '1')
            {
                tmp += 5 * pow(10, i);
                f2 = true;
            }
            else
            {
                tmp += 7 * pow(10, i);
                f3 = true;
            }
        }
        if (f1 && f2 && f3)
            v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    return v;
}

int ret_digit(int x)
{
    int ret = 0;
    while (x)
    {
        ret++;
        x /= 10;
    }
    return ret;
}

bool check(int x)
{
    bool f1 = false, f2 = false, f3 = false;
    while (x)
    {
        int ret = x % 10;
        if (ret == 3)
            f1 = true;
        else if (ret == 5)
            f2 = true;
        else if (ret == 7)
            f3 = true;
        else
            return false;

        x /= 10;
    }
    return (f1 && f2 && f3);
}

signed main()
{
    int n;
    cin >> n;

    int cnt = 0;
    int digit = ret_digit(n);
    vector<int> v = ret_ngs();

    for (int j = 3; j <= digit; j++)
    {
        set<int> ss;
        for (int i = 0; i < v.size(); i++)
            ss.insert(v[i] / pow(10, 9 - j));

        // for (auto itr = ss.begin(); itr != ss.end(); itr++)
        // if (*itr <= n && check(*itr))
        // cout << *itr << " ";
        // cout << endl;

        for (auto itr = ss.begin(); itr != ss.end(); itr++)
        {
            if (*itr <= n && check(*itr))
                cnt++;
        }
    }
    cout << cnt << endl;
    // cout << lower_bound(all(v), n) - v.begin() << endl;
    // cout << lower_bound(all(ss), n) - ss.begin() << endl;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    unsigned long long a,b,x{},c,t;
    cin>>a>>b;
    fr(i,n-2){
        cin>>c;
        x^=c;
    }
    if((a+b-x)&1u) return cout<<-1<<'\n',0;
    t=(a+b-x)>>1u;
    if(t&x) return cout<<-1<<'\n',0;
    if(t>a) return cout<<-1<<'\n',0;
    for(unsigned r=40;r--;){
        if(((x>>r)&1u)and((t|(1ull<<r))<=a)) t|=(1ull<<r);
    }
    cout<<(t?(long long)(a-t):-1)<<'\n';
}

Measured memory_bytes: 3636
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(x:i64));
    let ab_max = 1000i64;
    for a in -ab_max..ab_max {
        for b in -ab_max..ab_max {
            if a.checked_pow(5u32)
                .and_then(|a5| b.checked_pow(5u32).and_then(|b5| a5.checked_sub(b5)))
                == Some(x)
            {
                return format!("{} {}", a, b);
            }
        }
    }
    panic!()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}
tests! {
    test1: "33\n" => "2 -1\n",
    test2: "1\n" => "0 -1\n",
}


Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <list>
#define N 10000
using namespace std;

list<int> l;
bool color[N]={false};
vector<int> adj[N];
int n;

void topo(int k){
	for(int i=0;i<adj[k].size();i++){
		if(!color[adj[k][i]])topo(adj[k][i]);
	}
	l.push_front(k);
	color[k]=true;
}

int main(void){
	int u,v;
	int e;
	cin>>n>>e;
	for(int i=0;i<e;i++){
		cin>>u>>v;
		adj[u].push_back(v);	// ??£??\???????????????
	}
	for(int i=0;i<n;i++){
		if(!color[i])topo(i);
	}
	for(list<int>::iterator it=l.begin();it!=l.end();it++)cout<<*it<<endl;
	return 0;
}

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


int main()
{
	int n;
	cin>>n;
	long long int p;
	if(n==0)
	{p=2;}
	else if(n==1)
	{p=1;}
	else
	{
		long long int jianer=2,jianyi=1;
		for(int i=2;i<=n;i++)
		{
			p=jianer+jianyi;
			jianer=jianyi;
			jianyi=p;
		}
	}
	cout<<p;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define clt(x) 63-__builtin_clzll(x)
#define bct(x) __builtin_popcountll(x)
#define all(v) (v).begin(),(v).end()
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pair<ll,ll>>
#define maxq priority_queue<ll>
#define minq priority_queue<ll,vector<ll>, greater<ll>>
#define cont continue;
#define reto return 0;
#define sz size()
#define spmod 1116295198451
#define mod 1000000007
#define md 998244353 
#define N 2e5+10
//typedef tree<int,null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> //pbds;

ll dp[2009];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n;
  cin>>n;
  dp[0]=1;
  ll i=1,j;
  while(i<=n)
  {
    j=3;
    while(j<=i-3)
    {
      dp[i]+=dp[j];
      dp[i]%=mod;
      j++;
    }
    if(i>2)
      dp[i]++;
    dp[i]%=mod;
    i++;
  }
  deb(dp[n]);
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	ll ans=a[0]/2;
	a[0]%=2;
	for(int i=1;i<n;i++){
		if(a[i-1]>0&&a[i]>0){
			a[i]--;
			ans++;
		}
		ans+=a[i]/2;
		a[i]%=2;
	}
	cout<< ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1400
from itertools import*
from numpy import*
n,*a=map(int,open(0).read().split())
if set(a)=={0}:
    print(0)
    exit()
a=array(a)
count=0
ans=0
while 1:
    count=min(a[a!=0])
    ans+=count*sum(k for k,v in groupby(a>0)if k==True)
    a=a-min(a[a!=0])
    a[a<0]=0
    if sum(a)==0:
        break
print(ans)

Measured memory_bytes: 12512
import sys
sys.setrecursionlimit(10**8)

N,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(N)]

dp=[[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for j in range(0,W+1):
        if (j-wv[i][0])>=0:
            dp[i+1][j] = max([dp[i][j],dp[i][j-wv[i][0]] + wv[i][1]])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])

Measured memory_bytes: 120172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
貪欲は無理
(100,0),(10,0),(-80,0),(-80,0)
の答えが(110,0)になる

うまいこと前処理する？
ある基準に従ってソート？

１次元のとき：正か負かどっちかのものだけを取ればいい。
２次元のとき：？？
*/

ll n,x[110],y[110],m=4000000;
pair<ll,ll> p[110];
double ans=0,dx[4000010],dy[4000010];


void init(){
	cin>>n;
	rep(i,n)cin>>x[i]>>y[i];
	// rep(i,n)p[i]={x[i],y[i]};
	// sort(p,p+n);
	rep(i,m){
		dx[i]=cos(M_PI*2*i/m);
		dy[i]=sin(M_PI*2*i/m);
	}
}

int main(void){
	init();
	rep(i,m){
		ll tx=0,ty=0;
		rep(j,n){
			if(dx[i]*x[j]+dy[i]*y[j]>0){
				tx+=x[j];
				ty+=y[j];
			}
		}
		ans=max(ans,sqrt(pow(tx,2)+pow(ty,2)));
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 62848
a, b = map(int, input().split())

myans = ''
if a > b:
    for i in range(a):
        myans += str(b)
elif b > a:
    for i in range(b):
        myans += str(a)
else:
    for i in range(a):
        myans += str(a)
    
print(myans)

Measured memory_bytes: 3060
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    r=INT()
    print(r*r)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;



int main() {

    vector<int> heights;

    int height;

    while (cin >> height) {

        heights.push_back(height);

    }

    sort(heights.rbegin(), heights.rend());

    for (int i = 0; i != 3; ++i) {

        cout << heights[i] << endl;

    }

    return 0;

}

Measured memory_bytes: 1216
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	/**
	 * @param args
	 */
	static int[] score_W = new int[10];
	static int[] score_K = new int[10];
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		read();
		slove();
	}
	static boolean read(){
		for(int i = 0; i < 10; i++){
			score_W[i] = sc.nextInt();
		}
		for(int j = 0; j < 10; j++){
			score_K[j] = sc.nextInt();
		}
		return true;
	}
	static void slove(){
		java.util.Arrays.sort(score_W);
		java.util.Arrays.sort(score_K);
		int w = score_W[7]+score_W[8]+score_W[9];
		int k = score_K[7]+score_K[8]+score_K[9];
		System.out.print(w);
		System.out.println(" " + k);
		
	}
	
}

Measured memory_bytes: 11000
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, n = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
inf = float('inf')
dp = [inf] * (h + 1)
dp[0] = 0
for a, b in ab:
    for j in range(h):
        if dp[j] != inf:
            if a + j > h:
                dp[-1] = min(dp[-1], dp[j] + b)
            else:
                dp[a + j] = min(dp[a + j], dp[j] + b)
print(dp[-1])


Measured memory_bytes: 48860
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
struct BIT{
private:
    ll u;
    vector<ll> bit;
public:
    BIT(ll n){
        u=1;while(u<n)u*=2;
        bit.resize(u+10,0);
        
    }
    void add(ll n,ll x){
        ll i=n;
        bit[i]+=x;
        bit[i]%=mod;
        while(i<u){
            i+=i&(-i);
            bit[i]+=x;
            bit[i]%=mod;
        }

    }
    ll sum(ll n){
        ll i=n;
        ll ret=0;
        while(i>0){
            ret+=bit[i];
            i-=i&(-i);
            ret%=mod;
        }
        return ret;
    }
};
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    string s;cin>>s;
    int q;cin>>q;
    vector<BIT> b(26,n+1);
    rep(i,0,n){
        int num=s[i]-'a';
        b[num].add(i+1,1);
    }
    rep(i,0,q){
        int a;cin>>a;
        if(a==2){
            int l,r;cin>>l>>r;
            int cnt=0;
            rep(j,0,26){
                int t=b[j].sum(r)-b[j].sum(l-1);
                if(t>0)cnt++;
            }
            cout<<cnt<<endl;
        }
        else{
            int l;cin>>l;char f;cin>>f;
            int num=f-'a';
            int nu=s[l-1]-'a';
            b[nu].add(l,-1);
            b[num].add(l,1);
            s[l-1]=f;
        }
    }
}







Measured memory_bytes: 111612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	while(cin>>n,n){
		vi hp(n);
		rep(i,n)cin>>hp[i];
		int m;
		cin>>m;
		vp a,b;
		rep(i,m){
			string c,d;int e,f;
			cin>>c>>e>>d>>f;
			if(d=="Single")a.pb(pii(e,f));
			if(d=="All")b.pb(pii(e,f));
		}
		vi dps(1000000,inf),dpa(1000000,inf);
		dps[0]=dpa[0]=0;
		rep(i,a.size())rep(j,1000000){
			int t=j-a[i].second;
			if(t<0)t=0;
			dps[j]=min(dps[j],dps[t]+a[i].first);
		}
		rep(i,b.size())rep(j,1000000){
			int t=j-b[i].second;
			if(t<0)t=0;
			dpa[j]=min(dpa[j],dpa[t]+b[i].first);
		}
		int out=inf;
		rep(i,1000000)if(dpa[i]!=inf){
//			cout<<i<<" "<<dpa[i]<<endl;
			int sum=dpa[i];
			bool h=true;
			rep(j,n){
				int t=hp[j]-i;
				if(t<=0)continue;
				if(dps[t]==inf)h=false;
				sum+=dps[t];
			}
			if(h)out=min(out,sum);
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 8992
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut a: Vec<Vec<char>> = Vec::new();
    let mut b: Vec<Vec<char>> = Vec::new();

    for _ in 0..n {
        let line: Vec<char> = iterator.next().unwrap().chars().collect();
        a.push(line);
    }
    for _ in 0..m {
        let line: Vec<char> = iterator.next().unwrap().chars().collect();
        b.push(line);
    }

    let mut ans = false;
    for i in 0..(n - m + 1) {
        for j in 0..(n - m + 1) {
            let mut matched = true;
            for k in 0..m {
                for l in 0..m {
                    if b[k][l] != a[i + k][j + l] {
                        matched = false;
                    }
                }
            }
            if matched {
                ans = true;
            }
        }
    }

    return if ans {
        "Yes".to_string()
    } else {
        "No".to_string()
    };
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	string s;
	cin >> n >> s;
	for(int i = 0;i<n;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
			ans++;
	}
	cout << ans;
	
	return 0;
}

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

int main() {
  int N;
  int count=0;
  int sum=0;
  bool Judge = true;

  cin >> N;

  int A[N];

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

  while (Judge) {
      Judge = false;
      for(int i=0; i<N; i++) {
          if (A[i]%2 == 0) {
              count += 0;
          } else {
              count += 1;
          }
      }
      if(count == 0) {
          for(int i=0; i<N ;i++) {
              A[i] /= 2;
          }
          Judge = true;
          sum += 1; 
      }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void A(string t){
  cout<<t<<endl;
  exit(0);
}

int main() {
  int x,y; cin >> x >> y;
  if(y%2==1) A("No");
  y/=2;
  if(x<=y&&y<=2*x) A("Yes");
  A("No");
 
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
long long arr[maxn], cnt[maxn];
int M(){
    int n, k;
    if(!~scanf("%d %d", &n, &k)) return 0;
    for(int e = 0; e < n; e++) scanf("%lld", arr + e);
    sort(arr, arr + n);
    int pos = lower_bound(arr, arr + n, k) - arr;
    if(pos != n && (arr[pos] == k)) printf("POSSIBLE\n");
    else{
        if(k > arr[n-1]) printf("IMPOSSIBLE\n");
        else{
            for(int e = 1; e < n; e++)
                if(__gcd(arr[e], arr[0]) == 1)
                    return printf("POSSIBLE\n"), 1;
            for(int e = 0; e < n; e++){
                if(arr[e] > k){
                    int vpos = lower_bound(arr, arr + n, arr[e] - k) - arr;
                    if(vpos != n && (arr[vpos] == arr[e] - k))
                        return printf("POSSIBLE\n"), 1;
                }
            }
            printf("IMPOSSIBLE\n");
        }
    }
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    int a, b, sum, flag;

    while(scanf("%d %d", &a, &b) != EOF){
        flag=0;
        sum=a+b;
        while(sum!=0){
            if(sum>0){
                sum=sum/10;
            }
            flag++;
        }
        printf("%d\n", flag);
    }

    return 0;
}



Measured memory_bytes: 2052
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

// struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
// constexpr double PI  = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
// inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template <class T> inline T sqr(T x) { return x * x; }

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i, 0, n) cin >> a[i];
    VI cnts(100000 + 1);
    REP(i, 0, n) cnts[a[i]]++;
    int ans = max(cnts[1] + cnts[0], cnts[100000] + cnts[100000 - 1]);
    REP(i, 1, 100000 + 1) ans = max(ans, cnts[i - 1] + cnts[i] + cnts[i + 1]);
    cout << ans << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
        private static int[][] c;
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int[] x = new int[N];
                for (int i = 0; i < N; i++) {
                        x[i] = sc.nextInt();
                }
                c = new int[20][N];
                int L = sc.nextInt(), Q = sc.nextInt();
                int idx = 0;
                while (idx < N && x[idx] - x[0] <= L) {
                        idx++;
                }
                if (idx == N) {
                        for (int i = 0; i < Q; i++) {
                                System.out.println(1);
                        }
                        return;
                }
                c[0][0] = idx - 1;
                for (int i = 1; i < N; i++) {
                        while (idx < N && x[idx] - x[i] <= L) {
                                idx++;
                        }
                        if (idx == N) {
                                while (i < N) {
                                        c[0][i] = N - 1;
                                        i++;
                                }
                        } else {
                                c[0][i] = idx - 1;
                        }
                }
                for (int i = 1; i < 20; i++) {
                        for (int j = 0; j < N; j++) {
                                c[i][j] = c[i-1][c[i-1][j]];
                        }
                }
                for (int i = 0; i < Q; i++) {
                        int A = sc.nextInt() - 1, B = sc.nextInt() - 1;
                        if (A > B) {
                                int C = A;
                                A = B;
                                B = C;
                        }
                        System.out.println(calc(A,B));
                }
        }
        public static int calc(int A, int B) {
                int idx = 0;
                while (c[idx][A] < B) {
                        idx++;
                }
                if (idx == 0) {
                        return 1;
                } else {
                        return (1 << (idx - 1)) + calc(c[idx - 1][A], B);
                }
        }
}

Measured memory_bytes: 41720
#!/usr/bin/env python3
import sys
import math


def norm(a: "List[int]", b: "List[int]"):
    sqrSum = 0
    for i in range(len(a)):
        sqrSum += (a[i]-b[i])**2
    return math.sqrt(sqrSum)


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            if i == j:
                continue
            diff = norm(X[i], X[j])
            if diff == math.floor(diff):
                count += 1
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [[int(next(tokens)) for _ in range(D)]
         for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D, X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string o,e;
  cin>>o>>e;
  int a=o.size()+e.size();
  vector<char> x(a);
  for(int i=0;i<a;i++){
    if(i%2==0){
      x[i]=o[i/2];
    }
    else{
      x[i]=e[i/2];
    }
  }
    for(int i=0;i<a;i++){
      cout<<x[i];
    }
}

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

const int MAX = int(1e5) +1;
int a[MAX];
int b[MAX];
int c[MAX];

int main()
{
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);

    ll ans = 0;
    rep(j,n) {
        auto aiter = lower_bound(a, a+n, b[j]);
        ll x = distance(a, aiter);

        auto citer = upper_bound(c, c+n, b[j]);
        ll y = n-(int)distance(c, citer);

        ans += x * y;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
from math import factorial

N,M=map(int,input().split())

if M==1:
  print(1)
  exit()
MOD=(10**9)+7
def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(n**0.5) + 2
    for num in range(2,tmp):
        count=0
        while n % num == 0:
            n //= num
            count+=1
        if count>0:
          factor.append(count)
    #リストが空ならそれは素数
    if not factor:
        return [1]
    elif n!=1:
        factor.append(1)
        return factor
    else:
        return factor


factor=trial_division(M)

ans=1
for a in factor:
  for i in range(a):
    ans*=N+i
  ans //= factorial(a)
  ans%=MOD

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int N,T[100000],A[100000];
    cin>>N;
    for(int i=0;i<N;i++)cin>>T[i];
    for(int i=0;i<N;i++)cin>>A[i];
    
    int C[100000];
    for(int i=0;i<N;i++)C[i]=-1;
    C[0]=T[0];
    for(int i=1;i<N;i++){
        if(T[i]!=T[i-1]) C[i]=T[i];
    }
    
    if(C[N-1]!=-1&&C[N-1]!=A[N-1]){
        cout<<0<<endl;
        return 0;
    }
    
    C[N-1]=A[N-1];
    bool dame=0;
    for(int i=N-2;i>=0;i--){
        if(A[i+1]!=A[i]){
            if(C[i]!=-1&&C[i]!=A[i]){
                dame=1;
                break;
            }                
            C[i]=A[i];
        }else{
            if(C[i]!=-1&&C[i]>A[i]){
                dame=1;
                break;
            }
        }
    }

    if(dame){
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;
    for(int i=0;i<N;i++){
        if(C[i]==-1){
            ans=(ans*min(A[i],T[i]))%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
const int MAX_N = 1e5 + 5;

vector<int> graph[MAX_N];
bool visited[MAX_N];

void dfs(int i){
	visited[i] = true;
	for(auto x : graph[i]){
		if(visited[x])	continue;
		dfs(x);
	}
}

int main(){
	fast_io();
	int n, m;
	cin >> n >> m;
	memset(visited, false, sizeof(visited));
	for(int i = 0; i < m; i++){
		int x, y, z;
		cin >> x >> y >> z;
		graph[x].pb(y);
		graph[y].pb(x);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(visited[i])	continue;
		ans++;
		dfs(i);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
int n,m,f[1000001],ans;
bool fl[1000001];
int find(int x)
{
	return f[x]?f[x]=find(f[x]):x;
}
void merge(int x,int y)
{
	int fx=find(x);
	int fy=find(y);
	if(fx!=fy)
		f[fx]=fy;
	return;
}
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		merge(x,y);
	}
	for(int i=1;i<=n;i++)
		fl[find(i)]=true;
	for(int i=1;i<=n;i++)
		ans+=fl[i];
	cout<<ans;
}

Measured memory_bytes: 1152
n, m = map(int, input().split())
c = list(map(int, input().split()))

dp = [0] * (n+1)

for i in range(1, n+1):
  dpi = 10 ** 9
  for j in range(m):
    if(i-c[j]>=0):
      tmp = dp[i-c[j]] + 1
      if(tmp < dpi):
        dpi = tmp
  dp[i] = dpi
  
  
print(dp[n])


Measured memory_bytes: 7252
#include<iostream>
using namespace std;
int main(){

  int m,a,b,ans;
  int p[201];

  cin >> m >> a >> b;
  while(m != 0 || a != 0 || b != 0){
    for(int i = 0;i < m;i++){
      cin >> p[i];
    }
    for(int i = a;i <= b;i++){
      if(i == a) ans = a;
      else if(p[i-1]-p[i] >= p[ans-1]-p[ans]) ans = i;
    }
    cout << ans << endl;
    cin >> m >> a >> b;
  }

  return (0);
}

Measured memory_bytes: 3068