akhauriyash/Code-Regression huggingface dataset:
class AlgUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n  #各要素の親要素の番号を格納するリスト 要素が根（ルート）の場合は-(そのグループの要素数)を格納する

    def find(self, x): #要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y): #要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x): #要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def same(self, x, y): #要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x): #要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self): #すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self): #グループの数を返す
        return len(self.roots())

    def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self): #print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

if __name__ == "__main__":
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(M)]
    for j in range(M):
        A[j][0] -= 1
        A[j][1] -= 1
    uf = AlgUnionFind(N)
    for i in range(M):
        uf.union(A[i][0], A[i][1])
    count = uf.group_count() - 1
    print(count)





Measured memory_bytes: 28528
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

int can (i32 n, i32 k, i32 *a) {
  i32 p = n * (n + 1) / 2 / k;
  i32 i,j;
  for (i = 1; i <= n; ++i) a[i] = i;
  i32 d = 1;
  for (i = n; i >= 1; --i) {
    if (a[i] <= 0) continue;
    i32 sum = i;
    a[i] = -d;
    for (j = i - 1; j >= 1 && sum < p; --j) {
      if (a[j] <= 0) continue;
      if (j + sum <= p) {
	sum += j;
	a[j] = -d;
      }
    }
    if (sum < p) return 0;
    d++;
  }
  return 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 sum = n * (n + 1) / 2;
  i32 *a = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 k = 2; k <= sum; ++k) {
    if (sum % k != 0) continue;
    if (can (n, k, a)) {
      break;
    }
  }
  i32 i, j;
  i32 cnt = 0;
  for (i = 1; i <= n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      if (a[i] != a[j]) {
	cnt++;
      }
    }
  }
  printf("%" PRIi32 "\n", cnt);
  for (i = 1; i <= n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      if (a[i] != a[j]) {
	printf("%" PRIi32 " %" PRIi32 "\n", i, j);
      }
    }
  }
}

int main (void) {
  run ();
  return 0;
}


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

struct Edge {
	int from;
	int to;
	int cost;
};
struct Node {
	int id;
	int minus;
	vector<Edge>edges;
};
struct aa {
	int now;
	int kal;
	bitset<6>used;
};
class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.kal > r.kal;
	}
};
int M, N, K, D;
int getid(string st) {
	if (st[0] == 'H')return M + N;
	if (st[0] == 'D')return M + N + 1;
	else if (st[0] == 'C')return st[1] - '1';
	else return stoi(st.substr(1))-1 + M;
}

int main() {
	while (1) {
		cin >> M >> N >> K >> D;
		if (!M)break;
		vector<Node>nodes(M + N + 2);
		for (int i = 0; i < M; ++i) {
			int c; cin >> c;
			nodes[i].minus = c;
		}
		const int start = M + N;
		const int goal = M+N+1;
		for (int i = 0; i < D; ++i) {
			string s, t;int e; cin >> s >> t >> e;
			int sid = getid(s), tid(getid(t));
			e *= K;
			nodes[sid].edges.push_back(Edge{ sid,tid,e });
			nodes[tid].edges.push_back(Edge{ tid,sid,e });
		}
		priority_queue<aa,vector<aa>,Compare>que;
		vector<vector<int>>memo(M + N + 2, vector<int>(1 << 6, 1e8));
		memo[start][0] = 0;
		que.push(aa{ start,0,bitset<6>() });
		int ans = 1e8;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			if (atop.now == goal)ans = min(ans, atop.kal);
			for (auto e : nodes[atop.now].edges) {
				bitset<6>nextused(atop.used);
				int nextkal = atop.kal + e.cost;
				
				int nextid = e.to;
				if (nextid < M) {
					if (!nextused[nextid]) {
						nextused[nextid] = true;
						nextkal -= nodes[nextid].minus;
					}
					else {
						continue;
					}
				}
				if (memo[nextid][nextused.to_ulong()]>nextkal) {
					memo[nextid][nextused.to_ulong()] = nextkal;
					que.push(aa{ nextid,nextkal,nextused });
				}
			}
		}
		cout << ans << endl;

	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,x;
    cin>>n>>x;
    int mn=10000000;
    int tot=0;
    f(n){
        int x;
        cin>>x;
        tot+=x;
        mn=min(mn,x);
    }
    int ans=n;
    x-=tot;
    ans+=(x/mn);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	int top = -1;
	int second = -1;

	int[] An ;
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		An = new int[n];
		for(int i=0;i<n;i++){
			An[i] = sc.nextInt();
			if(An[i]>second){
				if(An[i]>top){
					second = top;
					top = An[i];
				} else {
					second = An[i];
				}
			}
		}

		// 出力
		for(int A:An){
			System.out.println(A==top?second:top);
		}
	}

	public static void main(String[] args){
		new Main();
	}
}

Measured memory_bytes: 85372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int n;
  cin >> n;
  vector<double> p(n);
  rep(i,n) cin >> p.at(i);
  vector<vector<double>> dp(n+1,vector<double>(n+1,0));
  dp.at(0).at(0) = 1;
  for(int i=1;i<=n;i++)rep(j,n+1){
    if(j==0) dp.at(i).at(j) = dp.at(i-1).at(j) * (1-p.at(i-1));
    else{
      dp.at(i).at(j) = dp.at(i-1).at(j) * (1-p.at(i-1)) + dp.at(i-1).at(j-1) * p.at(i-1);
    }
  }
  double ans = 0;
  for(int i=n/2 +1;i<=n;i++) ans += dp.at(n).at(i);
  printf("%.10f",ans);
  /*rep(i,n+1){
    rep(j,n+1) cout << dp.at(i).at(j) << " ";
    cout << endl;
  }*/

  return 0;
}



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


int main(){


    int a, b, k;


    cin >> a >> b;


    if( a <= 5 ) k = 0;

    else if( 6 <= a && a <= 12 ) k = b / 2;

    else k = b;


    cout << k << endl;


    return 0;

    }


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
  int key;
  Node *prev, *next;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while (cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while (1) {
    if (cur == nil) break;
    if (isf++ > 0) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNote(Node *t) {
  if (t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNote(nil->next);
}

void deleteLast() {
  deleteNote(nil->prev);
}

void deleteKey(int key) {
  deleteNote(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {insert(key); np++; size++; }
    else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      } else {
        deleteKey(key); nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



Measured memory_bytes: 33796
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/05/02 09:13:07 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

using namespace std;

#define	int	long long
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

typedef long long 			ll;
typedef vector<int>			VI;
typedef vector<vector<int>>	VVI;
typedef pair<int, int>		PII;

// TOP
void	Main()
{
	int	n, m;
	cin >> n >> m;
	VI	V(n);
	// priority_queue<int, vector<int>, greater<int>>	Q;
	ll	sum;
	sum = 0;
	rep(i, n)
	{
		int	x;
		cin >> x;
		sum += x;
		V.at(i) = x;
		// Q.push(x);
	}
	sort(V.begin(), V.end());
	vector<PII>	P(m);
	for (auto& p : P)
		cin >> p.second >> p.first;
	sort(P.begin(), P.end(), greater<>());
	// rep(i, n)
	// {

	// }
	int	i;
	i = 0;
	for (auto p : P)
	{
		bool	flag;
		flag = true;
		rep(j, p.second)
		{
			// if (Q.top() > p.first)
			if (i >= n || V.at(i) > p.first)
			{
				flag = false;
				break;
			}
			// sum += (p.first - Q.top());
			sum += (p.first - V.at(i));
			i++;
			// Q.pop();
			// Q.push(p.first);
		}
		if (flag == false)
			break;
	}
	// while (!Q.empty())
	// {
	// 	sum += Q.top();
	// 	Q.pop();
	// }
	cout << sum << endl;
}
// END

int32_t	main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
		int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x>=r&&x+r<=W&&y>=r&&y+r<=H){
		printf("Yes\n");
	}
else{
		printf("No\n");
	}
	return 0;
}

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

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll ans = 0;
    rep1(i, n) {
        if (i%3 == 0 || i%5 == 0) continue;
        else ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define pi pair<int,int>
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int,ll int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VEC() vector<ll int>v
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

vector<int>v[2*sz];
int vis[2*sz];
int bfs(int x)
{
    queue<int>q;
    int cnt=1;
    q.push(x);
    vis[x]=1;
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(int i=0;i<v[x].size();i++)
        {
          int f=v[x][i];
          if(vis[f]==0)
          {
              vis[f]=1;
              q.push(f);
              cnt++;
          }

        }
    }
    return cnt;

}
int main()
{
   int n,m,res=0,x,y;
   cin>>n>>m;
   for(int i=0;i<m;i++)
   {
       cin>>x>>y;
       v[x].pb(y);
       v[y].pb(x);

   }
   for(int i=1;i<=n;i++)
   {
       if(vis[i]==0)
       {
           res=max(res,bfs(i));
       }
   }
   cout<<res<<endl;
}


Measured memory_bytes: 15748
a,b,c = map(int,input().split())
a1 = abs(b-a)+abs(c-b)
a2 = abs(c-a) + abs(b-c)
b1 = abs(a-b) + abs(c-a)
b2 = abs(b-c) + abs(a-c)
c1 = abs(c-a) + abs(b-a)
c2 = abs(c-b) + abs(a-b)
print(min(a1,a2,b1,b2,c1,c2))

Measured memory_bytes: 38384
def calc(n, k):
    return (n + n - k + 1) * k // 2


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

MOD = 10 ** 9 + 7
print(sum([(calc(N + 1, i) - calc(i, i) + 1) % MOD for i in range(K, N + 2)]) % MOD)


Measured memory_bytes: 16712
import bisect

N = int(input())
S = input()
mod = 10 ** 9 + 7

small = []
large = []
for i in range(N * 2):
    if S[i] == 'B':
        if i % 2 == 0:
            small.append(i)
        else:
            large.append(i)
    else:
        if i % 2 == 0:
            large.append(i)
        else:
            small.append(i)

if len(small) != len(large):
    print(0)
else:
    ans = 1
    for i in range(N):
        large_i = large[i]
        smaller = bisect.bisect_left(small, large_i)
        ans = (ans * (smaller - i)) % mod
    for i in range(1, N + 1):
        ans = (ans * i) % mod
    print(ans)


Measured memory_bytes: 54108
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n;
  cin>>n;
  vi a(n),b(n);
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(all(b));
  reverse(all(b));

  rep(i,n){
    if(a[i]==b[0]){
      cout<<b[1]<<endl;
    }else{
      cout<<b[0]<<endl;
    }
  }

}

Measured memory_bytes: 4736
from operator import itemgetter

n,m = list(map(int,input().split()))
ab = sorted([tuple(map(int, input().split())) for i in range(m)], key=itemgetter(1))

removed = -1
ans = 0

for a,b in ab:
    if a > removed:
        ans += 1
        removed = b-1
print(ans)

Measured memory_bytes: 19084
;; D - Xor Sum 4
 
(defparameter *modulus* (+ (expt 10 9) 7))
(defparameter *max-bits* 60)

(defun main ()
  (print (solve (read)))
  (fresh-line))
 
(defun solve (N)
  (let ((vec (make-array *max-bits* :initial-element 0)))
    ; 各数を2進数に変換したときの各桁の1の個数を求める
    (loop repeat N do (add-bits-to-vector (read-fixnum) vec 0))
    ; 各桁を集約
    (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))
      ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)
      (map 'vector #'(lambda (m) (* m (- N m))) vec)
      :from-end t)))
 
(defun add-bits-to-vector (n vec index)
  "配列vecに整数nの2進各桁を加える"
  (unless (zerop n)
    (multiple-value-bind (m b) (floor n 2)
      (unless (zerop b) (incf (aref vec index)))
      (add-bits-to-vector m vec (1+ index)))))

(defun read-fixnum (&optional (in *standard-input*))
  "readより速い整数専用read. 
   参考: 競技プログラミングでCommon Lispを使っている人と
   これから使うかもしれない人のために, @sansaqua
   https://qiita.com/sansaqua/items/0b6417cb541047e29da4"
  (loop with acc = 0
        with minus = nil
        with skip = t
        for byte = (read-byte in)
        if (<= 48 byte 57)
          do (setf acc (+ (* acc 10) (- byte 48)))
             (setf skip nil)
        else if (= byte 45)
          do (setf minus t)
        else if (not skip)
          return (if minus (- acc) acc)))

(main)


Measured memory_bytes: 7400
<?php
$n    = trim(fgets(STDIN));
$data = [];

$min = 13;
for ($i = 1; $i * $i <= $n; $i++) {
    if ($n % $i === 0) {
        $a   = strlen($i);
        $b   = strlen($n / $i);
        $t   = $a > $b ? $a : $b;
        $min = $t < $min ? $t : $min;
    }
}

print "$min\n";

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

int main(){
    int H,W;
    cin >> H >> W;

    while(H!=0&&W!=0){
        for(int a=1;a<=H;a++){
            for(int b=1;b<=W;b++){
                if((a+b)%2==0){
                    cout << '#';
                }

                else{
                    cout << '.';
                }
            }

        cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


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

using namespace std;

int main() {

    int N;
    cin >> N;

    int n = 1000000007;

    long long p = 1;

    for (int i = 1; i <= N; ++i) {
        p = p * i;
        p = p % n;
    }



    cout << p << endl;
}


Measured memory_bytes: 256
import numpy as np

K,N=map(int,input().split())
A=np.zeros(N)
A=list(map(int, input().split()))
dif=np.zeros(N)

for i in range(N-1):
    dif[i]=A[i+1]-A[i]

dif[N-1]=K-A[N-1]+A[0]

print(int(K-np.max(dif)))

Measured memory_bytes: 34116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N+1);
    FOR(i, 1, N+1) cin >> A[i];
    REP(k, K) {
        vector<ll> B(N+1, 0);
        bool isALLN = true;
        FOR(n, 1, N+1) {
            if(A[n] != N) isALLN = false;
            ll l = max(0, (int)n-(int)A[n]);
            ll r = min(N, n+A[n]);
            B[l]++;
            if(r+1 < N+1) B[r+1]--;
        }
        FOR(n, 1, N+1) B[n] += B[n-1];
        A = B;
        if (isALLN) break;
    }
    FOR(n, 1, N+1) {
        cout << A[n] << " ";
    }
    cout << "\n";
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int solve(int *a, int size)
{
  if (size == 0)
  {
    return 0;
  }
  if (size == 1)
  {
    return a[0];
  }
  REP(i, size)
  {
    if (a[i] == 0)
    {
      return solve(a, i) + solve(a + (i + 1), size - (i + 1));
    }
  }

  REP(i, size)
  {
    a[i]--;
  }
  return solve(a, size) + 1;
}

int main()
{
  int n;
  int h[100];
  cin >> n;
  REP(i, n)
  {
    cin >> h[i];
  }

  cout << solve(h, n) << endl;
}


Measured memory_bytes: 256
# 解説AC(できるといいな)
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a0 = a[0]
d = 1
while a0 % 2 == 0 do
  a0 /= 2
  d *= 2
end
if a.any? {|v| v % d != 0 || (v / d) % 2 == 0}
  puts 0
else
  half_lcm = a.inject(1) { |hl, ai| hl.lcm(ai / 2) }
  puts (m / half_lcm + 1) / 2
end


Measured memory_bytes: 12688
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[1000005][2][2];

int main() {
    int n;
    cin >> n;
    dp[0][0][0] = 1;
    rep(i,n) {
        dp[i+1][0][0] += dp[i][0][0]*8;
        dp[i+1][1][0] += dp[i][0][0] + dp[i][1][0]*9;
        dp[i+1][0][1] += dp[i][0][0] + dp[i][0][1]*9;
        dp[i+1][1][1] += dp[i][1][0] + dp[i][0][1];
        dp[i+1][1][1] += dp[i][1][1]*10;
    }
    cout << dp[n][1][1] << endl;
    return 0;
}

Measured memory_bytes: 34880
#include <iostream>

using namespace std;

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

    if(d == 25){
        cout << "Christmas" << endl;
    }else if(d == 24){
        cout << "Christmas Eve" << endl;
    }else if(d == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n;long int a[100000];

    scanf("%d",&n);

    int i;

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

    long int b[9];

    int sum = 0;

    for(i=0;i<n;i++)
    {
        sum += a[i];
        if(i%2 == 1)
            sum -= a[i]*2;
    }

    b[0] = sum;

    for(i=1;i<n;i++)
    {
        b[i] =  a[i-1]*2 - b[i-1];
    }

    for(i=0;i<n;i++)
        printf("%ld ",b[i]);

    printf("\n");

    return 0;
}

Measured memory_bytes: 2048
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)


n = int(input())

l = list(map(int,input().split()))

if n == 1:
	print(0)
	exit()


minans = float('inf')
chk = float('inf')

for i in range(min(l),max(l)+1):
	test = 0
	#print(i)
	for j in range(len(l)):
		#print(i,(l[j]-i)**2)
		test = test + (l[j]-i)**2
		#print(test)

	if test < minans:
		#print(minans)
		#print(test)
		minans = test
		chk = i

#print(chk)
print(minans)


Measured memory_bytes: 38640
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9 + 9;

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int x;
	cin >> x;


	auto ok = [&](int m) {
		return (x <= m * (m - 1) / 2);
	};

	int l = 0, r = INF;
	rep(i, 100) {
		int m = (r + l) / 2.0;
		if (!ok(m)) {
			l = m;
		}
		else {
			r = m;
		}
	}
	cout << l << endl;


	return 0;
}

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

int main(){
  int n,k = 0;
  cin >> n;
  
  vector<string> s(n),word(n);
  vector<int> num(n);
  
  for(int i = 0;i<n;i++){
    cin >> s.at(i);
    word.at(i) = " ";
    num.at(i) = 0;
  }
  
  sort(s.begin(),s.end());
  word.at(0) = s.at(0);
  
  for(int i = 0;i<n;i++){
    if(word.at(k) != s.at(i)){
      k++;
      word.at(k) = s.at(i);
      num.at(k)++;
    }else{
      num.at(k)++;
    }
  }
  
  int max = 0;
  for(int i = 0;i<n;i++){
    if(max<num.at(i) && word.at(i) != " ") max = num.at(i);
  }
  
  for(int i = 0;i<n;i++){
    if(num.at(i) == max && word.at(i) != " ") cout << word.at(i) << endl;
  }
}

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

#define int         long long
#define pb          push_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 all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
const int M=1000006;
int f[M],inv[M];
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M){
        f[i]=(1LL*i*f[i-1])%hell;
    }
    inv[M-1]=expo(f[M-1],hell-2,hell);
    for(int i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%hell;
    }
}
int C(int n,int r){
    if(n<r or r<0) return 0;
    return (1LL*((1LL*f[n]*inv[r])%hell)*inv[n-r])%hell;
}
int h,w,n,x[3003],y[3003],dp[3003];
int ff(int a,int b){
    return C(a+b,a);
}
int sol(int pos){
    if(dp[pos]!=-1) return dp[pos];
    int ans=ff(h-x[pos],w-y[pos]);
    rep(i,0,n){
        if(x[i]>=x[pos] and y[i]>=y[pos] and i!=pos){
            ans=(ans-ff(x[i]-x[pos],y[i]-y[pos])*sol(i)%hell+hell)%hell;
        }
    }
    return dp[pos]=ans;
}
void solve(){
    compute();
    cin>>h>>w>>n;
    rep(i,0,n){
        cin>>x[i]>>y[i];
    }
    memset(dp,-1,sizeof dp);
    int ans=ff(h-1,w-1);
    rep(i,0,n){
        ans=(ans-ff(x[i]-1,y[i]-1)*sol(i)%hell+hell)%hell;
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, N) for (int i = 0; i < (N); i++)
#define REP(i, a, N) for (int i = a; i < (N); i++)
#define rrep(i, N, k) for (int i = (N); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> count;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        count[A[i]]++;
    }
    bool check = true;
    if (count.size() >= 3) check = false;
    if (count.size() == 2) {
        if (count.rbegin()->first - count.begin()->first > 1) check = false;
        if (count.rbegin()->first < N / 2) check = false;
        if (count.begin()->second != N - (N - count.rbegin()->first) * 2) check = false;
    }
    if (count.size() == 1 && (count.begin()->first > N / 2 && count.begin()->first != N - 1)) check = false;
    cout <<(check ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 5376
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = n;
		if(n%2 == 1) result *= 2;
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21716
import itertools
import string
n=26
alp=string.ascii_lowercase[0:n]

def nextchar(c):
    if c==alp[n-1]:
        return '0'
    z=alp
    return z[alp.find(c)+1]
    
def nextword(c):
    if c==alp[::-1]:
        return -1
    else:
        while True:
            c=c[:len(c)-1]
            l=nextchar(c[-1])
            while l!='0':
                if l not in c:
                    return c[:len(c)-1]+l
                l=nextchar(l)

s=input()
if len(s)<n:
        for i in alp:
            if i not in s:
                print(s+i)
                break
else:
    print(nextword(s))


Measured memory_bytes: 38640
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String s2 = s+s;
		String p = sc.next();
		
		if (s2.contains(p)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		
	}
}


Measured memory_bytes: 26156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int main(){
    int N; cin >> N;
    ll X; cin >> X;
    vector<ll> x(N);
    vector<ll> d(N);
    rep(i,N){
        cin >> x[i];
        d[i] = abs(x[i]-X);
    }
    ll ans = d[0];
    for(int i = 1; i < N; i++){
        ans = gcd(d[i],ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
def main():
  l,r=0,10**9
  while r-l>1:
    m=(l+r)//2
    if sum([(i-1)//m for i in a])<=k: r=m;
    else: l=m;
  print(r)

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

Measured memory_bytes: 30832
#include<iostream>
using namespace std;
int main(){
  int x,y;
  cin >> x>>y;
  int ans= 0;
  if(x==1&&y==1)ans+=400000;
  if(x<=3)ans+=100000*(4-x);
  if(y<=3)ans+=100000*(4-y);
  cout << ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
candle = list(map(int, input().split()))

distance = [0]
for i in range(1, n):
  distance.append(candle[i] - candle[i-1] + distance[i-1])

ans = float('inf')
for i in range(n-k+1):
  res = distance[i+k-1] - distance[i]
  if candle[i+k-1] < 0:
    res += abs(candle[i+k-1])
  elif candle[i] >= 0:
    res += candle[i]
  else:
    res += min(candle[i+k-1], abs(candle[i]))
  ans = min(ans, res)
print(ans)

Measured memory_bytes: 63512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n, h, w;
    cin >> n >> h >> w;
    int ans = (n - h + 1) * (n - w + 1);
    cout << ans;
}



Measured memory_bytes: 256
// AOJ 1252: Confusing Login Names
// 2017.10.12 bal4u@uu

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

#define MIN(a,b) ((a)<=(b)?(a):(b))
#define MAX(a,b) ((a)>=(b)?(a):(b))
#define ABS(a) ((a)>=0?(a):-(a))

typedef struct { char *s; int w; } S;
S nm[202];
char name[202][18];
int M[20][20];

int cmp(S *a, S *b) { return strcmp(a->s, b->s); }

int distance(char *s1, int w1, char *s2, int w2)
{
    int  i, j;

    for (j = 0; j <= w1; j++) M[j][0] = j;
    for (i = 0; i <= w2; i++) M[0][i] = i;
    for (j = 1; j <= w1; j++) {
        for (i = 1; i <= w2; i++) {
            int d, min;
            d = (s1[j-1] != s2[i-1]);
            min =     M[j-1][i  ] + 1;
            if (min > M[j  ][i-1] + 1) min = M[j  ][i-1] + 1;
            if (min > M[j-1][i-1] + d) min = M[j-1][i-1] + d;
            M[j][i] = min;
        }
    }
    return M[w1][w2];
}

int check(char *s1, int w1, char *s2, int w2, int d)
{
	char *t1, *t2, x;
	char buf[50];

	if (ABS(w1-w2) > d) return 0;
	if (distance(s1, w1, s2, w2) <= d) return 1;

	memcpy(buf, s1, w1+1); t1 = s1 = buf, t2 = s2;

	if (d == 1) {
		if (w1 != w2) return 0;
		while (*s1 == *s2) s1++, s2++;
		if (*s1 == *(s2+1) && *s2 == *(s1+1)) return strcmp(s1+2, s2+2) == 0;
		return 0;
	}

	s1 = t1, s2 = t2; while (*s1 == *s2) s1++, s2++;
	if (*s1 == *(s2+1) && *s2 == *(s1+1)) {
		x = *s1, *s1 = *(s1+1), *(s1+1) = x;
		if (distance(t1, w1, t2, w2) < d) return 1;
		if (w1 != w2) return 0;
		while (*s1 == *s2) s1++, s2++;
		if (*s1 == *(s2+1) && *s2 == *(s1+1)) return strcmp(s1+2, s2+2) == 0;
		return 0;
	}
	if (*s1 == *(s2+1) && *s2 == *(s1+2))
		return strcmp(s1+3, s2+2) == 0;
	if (*s1 == *(s2+2) && *s2 == *(s1+1))
		return strcmp(s1+2, s2+3) == 0;

	s1 = t1+w1, s2 = t2+w2;
	while (*s1 == *s2) s1--, s2--;
	if (s2 > t2 && s1 > t1 && *s1 == *(s2-1) && *s2 == *(s1-1)) {
		x = *s1, *s1 = *(s1-1), *(s1-1) = x;
		return distance(t1, w1, t2, w2) < d;
	}
	return 0;
}

int main()
{
	int n, d, i, j, ans;

	while (scanf("%d", &n) && n > 0) {
		scanf("%d", &d);
		for (i = 0; i < n; i++) {
			scanf("%s", name[i]);
			nm[i].s = name[i], nm[i].w = strlen(name[i]);
		}
		qsort(nm, n, sizeof(S), cmp);
		for (ans = 0, i = 0; i < n; i++) for (j = i+1; j < n; j++) {
			if (check(nm[i].s, nm[i].w, nm[j].s, nm[j].w, d)) {
				printf("%s,%s\n", nm[i].s, nm[j].s), ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1824
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

LM = list(map(lambda x : x - 1, L))
LP = list(map(lambda x : x + 1, L))

X = LM + L + LP
# print(LM)
# print(L)
# print(LP)
Xc = Counter(X)
# print(Xc.most_common())
print(Xc.most_common()[0][1])

Measured memory_bytes: 96052
import java.util.Scanner;

public class Main {

	public static int N;
	public static int[] X;

	public static void main(String[] args) {
		init();
		int min = 100 * 100 * 100;
		for (int p = 1; p <= 100; p++) {
			int sum = 0;
			for (int i = 0; i < N; i++) {
				sum += (X[i] - p) * (X[i] - p);
			}
			if (sum < min) {
				min = sum;
			}
		}
		System.out.println(min);
	}

	public static void init() {
		Scanner sc = new Scanner(System.in);
		try {
			N = sc.nextInt();
			X = new int[N];
			for (int i = 0; i < N; i++) {
				X[i] = sc.nextInt();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


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

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}

string s;
int p;

ll bnf();

ll get_digit(){
  
  ll res=0;
  
  if(s[p]=='('){
    p++;
    res=bnf();
    p++;
    return res;
  }

  while('0'<=s[p]&&s[p]<='9') res=res*10+s[p]-'0',p++;
  
  return res;
}

ll bnf2(){

  ll res=get_digit();

  while(p!=s.size()&&!flag){
    
    if(s[p]=='*'){

      p++;

      res=(res*get_digit())%mod;
      
    }
    else if(s[p]=='/'){

      p++;

      ll r=get_digit();
      
      if(!r){
	
	cout<<"NG"<<endl;
	
	flag=1;

	break;
      }
      
      res=(res*mod_pow(r,mod-2))%mod;
      
    }
    else break;
    
  }
  
  return res;
}

ll bnf(){
  
  ll res=bnf2();

  while(p!=s.size()&&!flag){
    
    if(s[p]=='+'){
      
      p++;
      
      res=(res+bnf2())%mod;
      
    }
    else if(s[p]=='-'){

      p++;
      
      res=(res-bnf2()+mod*2)%mod;
      
    }
    else break;
  }

  return res;
}

int main(){

  while(1){

    scanf("%d:",&mod);
    if(!mod) break;
    
    string t;
    
    getline(cin,t);
    
    for(int i=0;i<t.size();i++)
      if(t[i]!=' ') s+=t[i];
	
    p=flag=0;

    ll ans=bnf();
    
    if(!flag) cout<<s<<" = "<<ans<<" (mod "<<mod<<")"<<endl;

    s="";
  }
  
  return 0;
}

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

int main(){
	
	int a,b,s,l;
	scanf("%d %d",&a, &b);
	s = a*b;
	l = 2*a+2*b;
	printf("%d %d\n",s,l);
	return 0;
}


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

typedef pair<int,int> P;

int main ()
{
    int n, m;
    while (cin >> m >> n, n || m) {
        vector<vector<char> > v (n, vector<char>(m, '#'));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                char str;
                cin >> str;
                if ('0' <= str && str <= '9') {
                    v[i][j] = str;
                }
            }
        }

        vector<vector<string> > dp(n, vector<string>(m, ""));

        string res = "";

        for (int i = 0; i < m; i++) {
            if (v[0][i] != '#') {
                if (v[0][i] == '0') {
                    if (i > 0 && dp[0][i-1].size() > 0) {
                        dp[0][i] = dp[0][i-1] + v[0][i];
                    }
                } else {
                    if (i > 0) {
                        dp[0][i] = dp[0][i-1] + v[0][i];
                    } else {
                        dp[0][i] = v[0][i];
                    }
                }
            }
            if (res.size() == dp[0][i].size()) {
                res = max(res, dp[0][i]);
            } else {
                res = res.size() > dp[0][i].size() ? res : dp[0][i];
            }
        }

        for (int i = 1; i < n; i++) {
            if (v[i][0] != '#') {
                if (v[i][0] == '0') {
                    if (dp[i-1][0].size() > 0) dp[i][0] = dp[i-1][0] + v[i][0];
                } else {
                    dp[i][0] = dp[i-1][0] + v[i][0];
                }
            }
            if (res.size() == dp[i][0].size()) {
                res = max(res, dp[i][0]);
            } else {
                res = res.size() > dp[i][0].size() ? res : dp[i][0];
            }
        }

        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                if (v[i][j] != '#') {
                    string s1;
                    if (dp[i-1][j].size() > 0 || v[i][j] != '0') s1 = dp[i-1][j] + v[i][j];
                    string s2;
                    if (dp[i][j-1].size() > 0 || v[i][j] != '0') s2 = dp[i][j-1] + v[i][j];

                    if (s1.size() == s2.size()) {
                        dp[i][j] = max(s1, s2);
                    } else {
                        dp[i][j] = s1.size() > s2.size() ? s1 : s2;
                    }
                    if (res.size() == dp[i][j].size()) {
                        res = max(res, dp[i][j]);
                    } else {
                        res = res.size() > dp[i][j].size() ? res : dp[i][j];
                    }
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1372
from collections import deque

A = deque()

n = int(input())
for i in range(n):
    q = input()
    if q[0] == "0":
        if q[2] == "0":
            A.appendleft(q[4:])
        else:
            A.append(q[4:])
    elif q[0] == "1":
        print(A[int(q[2:])])
    else:
        if q[2] == "0":
            A.popleft()
        else:
            A.pop()


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

using namespace std;

class Solution {
public:
	void solve() {
		vector<vector<int>> a(3, vector<int>(3, 0));
		for(int i=0; i<3; i++)for(int j=0; j<3; j++)cin >> a[i][j];
		int n;
		cin >> n;
		for(int i=0; i<n; i++){
			int b;
			cin >> b;
			for(int j=0; j < 3; j++){
				for(int k=0; k < 3; k++){
					if(a[j][k] == b)a[j][k] = -1;
				}
			}	
		}
		vector<vector<pair<int, int>>> cs({
			{{0,0},{0,1},{0,2}},
			{{1,0},{1,1},{1,2}},
			{{2,0},{2,1},{2,2}},
			{{0,0},{1,0},{2,0}},
			{{0,1},{1,1},{2,1}},
			{{0,2},{1,2},{2,2}},
			{{0,0},{1,1},{2,2}},
			{{0,2},{1,1},{2,0}}
		});
		for(auto c: cs){
			int s = 0;
			for(auto p:c){
				if(a[p.first][p.second] == -1)s++;
			}
			if(s == 3){
				cout << "Yes\n";
				return;
			}
		}
		cout << "No\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int> cnt(n+1,0);
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		cnt[x]++;
	}
	vector<pair<int,int>> v;
	for(int i=1;i<=n;++i)
		if(cnt[i]) v.emplace_back(cnt[i],i);
	sort(v.begin(),v.end(),greater<pair<int,int>>());
	int res=0;
	for(int i=k;i<int(v.size());++i)
		res+=v[i].first;
	cout<<res<<'\n';
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    int m = n;

    while (true) {
        if (n <= 1000) {
            break;
        }
        cnt++;
        n -= 1000;
    }
    n = max(0, 1000 - n);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using ll = long long;
using namespace std;


int main() {
    string w;
    cin >> w;
    for(int i = 0; i < w.size(); i++){
        int count = 0;
        for (int j = 0; j < w.size(); ++j) {
            if (w[i] == w[j]) count++;
        }
        if (count % 2 != 0){
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmpint(const void *a, const void *b){
	return (*(int*)b - *(int*)a);
}

int main(void){
	int len = 0;
	scanf("%d", &len);
	int a[3];
	for(int i=0; i<len;++i){
		scanf("%d %d %d", a, a+1, a+2);
		qsort(a, 3, sizeof(int), cmpint);
		if(a[0]*a[0] == (a[1]*a[1] + a[2]*a[2])){
			puts("YES");
		}else{
			puts("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 0