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

const int MAX = 510000;
const int MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll N, M, L;
  cin >> N >> M;
  ll ans = 1;
  L = sqrt(M);
  for (int i = 2; i <= L; i++) {
    int cnt = 0;
    while (M % i == 0) {
      M /= i;
      cnt++;
    }
    if (cnt > 0) ans = ans * COM(N + cnt - 1, cnt) % MOD;
  }
  if (M >= 2) ans = ans * N % MOD;

  cout << ans << endl;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
float sum;
int n,m,a[11][11],sumn;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int l=1;l<=m;l++)
			cin>>a[i][l];
	for(int i=1;i<=n-1;i++)
		for(int l=i+1;l<=n;l++){
			for(int j=1;j<=m;j++)
				sum+=abs(a[i][j]-a[l][j])*abs(a[i][j]-a[l][j]);
			if(int(sqrt(sum))==sqrt(sum))
				sumn++;
			sum=0;
		}
	cout<<sumn;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T, class S> inline T pow_L(T a, S b){
  T res=1;
  res = 1;
  while(b){
    if(b&1){
      res *= a;
    }
    b >>= 1;
    a *= a;
  }
  return res;
}
int main(){
  int K, N, res;
  rd(N);
  rd(K);
  res = K * (pow_L((K-1),(N-1)));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// {
//   int N, K, res;
//   rd(N, K);
//   res = K * ((K-1) ** (N-1));
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <cassert>
#include <algorithm>
#include <functional>
#include<stdio.h>

using namespace std;

//flagを用いたバブルソート
int selectionSort(int A[], int N) {
	int sw = 0;
	int tmp;
	int minj;
	int i;
	int j;
	for (i = 0; i < N-1; ++i) {
		 minj = i;
		 for (j = i; j < N; ++j) {
			 if (A[j] < A[minj]) {

				 minj = j;
			 }
		 }
			tmp = A[i];
			A[i] = A[minj];
			A[minj] = tmp;
				if (i != minj) {
					++sw;
				}
			
			

		}
		return sw;
	}
	
	



int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];

	sw = selectionSort(A, N);

	for (int i = 0; i < N; ++i) {
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}


Measured memory_bytes: 3092
a = list(map(int, input().split()))

goukei = 0

x = 0
y = 0

for n in range(a[0] + 1):

	x = n
	sum = 0
	while True :
		y = x % 10
		x = x // 10
		sum = sum + y
		if (x == 0):
			break

	goukei = goukei + n if( (sum >= a[1]) and (sum <= a[2]) ) else goukei

#	print(sum)
#	print(goukei)
#	print("-----------")
print(goukei)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int f[100001],n,m,q;
int getf(int u){
	if(u==f[u])return u;
	else return f[u]=getf(f[u]);
	}
int merge(int u,int v){
	int t1=getf(u);
	int t2=getf(v);
	if(t1!=t2){
		f[t2]=t1;
			}
}	
int main(){
	int v1,v2;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)f[i]=i;
	for(int i=0;i<m;i++){
		scanf("%d%d",&v1,&v2);
		merge(v1,v2); 
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d%d",&v1,&v2);
		if(getf(v1)==getf(v2))printf("yes\n");
		else printf("no\n");
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, cnt = 0, tmp;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> tmp;
    cnt += tmp;
  }
  if (cnt % 2 == 0) cout << "YES" << '\n';
  else cout << "NO" << '\n';
}


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

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while (b<=a)
	{
		b*=2;
		k--;
	}
    while (c<=b)
	{
		c*=2;
		k--;
	}
    cout<<((k>=0)?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3552
import collections
N = int(input())
l = list(map(int,input().split()))
c = collections.Counter(l)
dic = sorted(c.items(), reverse=True)
r = []
for j in dic:
    k = j[0]
    v = j[1]
    if v >= 4:
    	r.append(k)
    	r.append(k)
    elif v >= 2:
    	r.append(k)
    if len(r) >= 2:
      print(r[0]*r[1])
      exit()
print(0)

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int a,b;
  cin>>a>>b;
  if((a+1)/2>=b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(a.begin(), a.end(), greater<int>());

  priority_queue<int> que;

  que.push(a[0]);

  ll ans = 0;
  FOR(i, 1, n) {
    int t = que.top(); que.pop();
    ans += t;
    que.push(a[i]);
    que.push(a[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 5056
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,a[101010],te,has;
vector<ll> v1,v2;
vector<pair<ll,ll> > V1,V2;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i+=2)
        v1.pb(a[i]);
    for(i=2;i<=n;i+=2)
        v2.pb(a[i]);
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    for(i=0;i<(n/2);i++)
    {
        te++;
        if(i==(n/2)||v1[i]!=v1[i+1])
        {
            V1.pb(mp(te,v1[i]));
            te=0;
        }
    }
    for(i=0;i<(n/2);i++)
    {
        te++;
        if(i==(n/2)||v2[i]!=v2[i+1])
        {
            V2.pb(mp(te,v2[i]));
            te=0;
        }
    }
    V1.pb(mp(0,-2));
    V2.pb(mp(0,-1));
    sort(V1.begin(),V1.end());
    sort(V2.begin(),V2.end());
    reverse(V1.begin(),V1.end());
    reverse(V2.begin(),V2.end());
    //for(i=0;i<V1.size();i++)    cout<<i<<" "<<V1[i].fi<<" "<<V1[i].se<<"\n";
    //for(i=0;i<V2.size();i++)    cout<<i<<" "<<V2[i].fi<<" "<<V2[i].se<<"\n";
    if(V1[0].se!=V2[0].se)has=n-V1[0].fi-V2[0].fi;
    else    has=min(n-V1[0].fi-V2[1].fi,n-V1[1].fi-V2[0].fi);
    cout<<has<<"\n";
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = nm[0];
            var M = nm[1];

            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            long sum = 0;
            foreach(var d in input)
            {
                sum += d;
            }

            Console.WriteLine($"{(N - sum >= 0 ? N - sum : -1)}");
        }
    }
}


Measured memory_bytes: 29252
import sys
n,k=[int(i) for i in input().split()]
arr=[int(i) for i in input().split()]
dp=[sys.maxsize]*(n+1)
dp[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            dp[i]=min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i])
print(dp[n-1])
    
    



Measured memory_bytes: 52448
n,c,k=map(int,input().split())
s=[]
for i in range(n):
    s.append(int(input()))
s.sort()
ans=1
count=0
a=s[0]
for i in range(n):
    if s[i]-a>k:
        a=s[i]
        count=1
        ans+=1
    else:
        count+=1
    if count==c:
        if i!=n-1:
            count=0
            ans+=1
            a=s[i+1]
    #print(a,count,ans)
print(ans)


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

int a, b, c, n, k, s;

int main (){
	cin >> a>> b>> c>>k;
	n= max(c,max(a,b));
	s= a+b+c-n;
	for(int i=1;i<=k;i++){
		n=2*n;
	}
	cout << n + s << endl;
	
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,v[maxn],c[maxn],ans;
int main(){
	n=read();
	FOR(i,1,n) v[i]=read();
	FOR(i,1,n) c[i]=read();
	FOR(i,1,n) if(v[i]>c[i]) ans+=v[i]-c[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 256
num = input()
L = list(map(int,input().split()))
n = int(input())

for _ in range(n):
    c, b, e = [int(x) for x in input().split()]
    if c == 0:
        print(min( L[b:e] ))
    elif c == 1:
        print(max( L[b:e] ))


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
using namespace std;
using ii = pair<int, int>;
using ll = long long int;


int arr[10][10];

int main (){
	FASTIO;

	//freopen("./input.txt", "r", stdin);

	int h,w,k; cin >> h >> w >> k;

	rep(i, 0, h){
		rep(j, 0, w) {
			char a; cin >> a;
			if(a == '.') arr[i][j] = 1;
			else if(a == '#') arr[i][j] = 2;
		    else arr[i][j] = 0; 
        }
	}

	int ans = 0;

    for(int i = 0; i < (1 << h); i++){
		int row[10];
        memset(row, 0, sizeof(row));
		int ii = i, idx = 0;
		while(ii) {
			row[idx++] = ii % 2;
			ii /= 2;
		}

		rep(j, 0, (1 << w )){
			int col[10];
            memset(col, 0, sizeof(col));
			int jj = j, jdx = 0;
			while(jj) {
				col[jdx++] = jj % 2;
				jj /= 2;
			}
            int rlt = 0;
			rep(id, 0, h) {
				if(!row[id]) continue;
				rep(jd, 0, w) {
					if(!col[jd]) continue;
					if(arr[id][jd] == 2) {
                        rlt++;
                    }
				}
                cout << endl;
			}
			if(rlt == k) ans++;
		}
       // cout << "----------:: " << i << endl;
	}


	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

/*
void fo(int id){
	freopen((toString(id)+".txt").c_str(),"w",stdout);
}
*/
string s;
int k;

/*
The biggest answer in [l,r] with k left
*/

int d[305][305][305];
bool f[305][305][305];

int dp(int l,int r,int k){
	//cout<<l<<" "<<r<<" "<<k<<endl;
	int retv;
	if(k<0){
		return 0;
	}else{
		if(f[l][r][k]) return d[l][r][k];
		
		if(l==r){
			retv=1;
		}else{
			if(l>r){
				retv=0;
			}else{
				retv=max(dp(l+1,r,k),dp(l,r-1,k));
				if(k>=1){
					retv=max(retv,dp(l+1,r-1,k-1)+2);
				}
				if(s[l]==s[r]){
					retv=max(retv,dp(l+1,r-1,k)+2);
				}
			}
		}
	}

	f[l][r][k]=true;
	d[l][r][k]=retv;
	return retv;
}

int main(int argc,char* argv[]){
	cin>>s>>k;
	cout<<dp(0,s.size()-1,k);
	return 0;
}


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

using ll = long long;

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

    auto dp = map<ll, ll>();
    const function<ll(ll)> f = [&](const ll N)
    {
        if (N == 0) return 1LL;
        if (N == 1) return 2LL;

        if (dp.count(N)) return dp[N];

        return dp[N] = (f(N/2) + f((N-1)/2) + f((N-2)/2)) % int(1e9+7);
    };

    cout << f(N) << endl;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  char ch[n];
  for(int i=0;i<n;i++){
    cin >> ch[i];
  }
  ch[k-1]=int(ch[k-1]+32);
  for(int i=0;i<n;i++){
    cout << ch[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
R, G, B = map(int, input().split())
K = int(input())

ng = True
for ig in range(K):
    ib = K - ig
    if G * (2**ig) > R and B * (2** ib) > G * (2**ig):
        ng = False
        break

if ng:
    print('No')
else:
    print("Yes")


Measured memory_bytes: 9168
w, h, n = list(map(int, input().split()))

points_dir = []
for i in range(n):
  points_dir.append(list(map(int, input().split())))


left_lim = 0
right_lim = w
bottom_lim = 0
top_lim = h

for i in range(n):
  if points_dir[i][2] == 1:
    left_lim = points_dir[i][0] if points_dir[i][0] > left_lim else left_lim
  elif points_dir[i][2] == 2:
    right_lim = points_dir[i][0] if points_dir[i][0] < right_lim else right_lim
  elif points_dir[i][2] == 3:
    bottom_lim = points_dir[i][1] if points_dir[i][1] > bottom_lim else bottom_lim
  elif points_dir[i][2] == 4:
    top_lim = points_dir[i][1] if points_dir[i][1] < top_lim else top_lim

if right_lim - left_lim < 0 or top_lim - bottom_lim < 0:
  print("0")
else:
  print((right_lim - left_lim) * (top_lim - bottom_lim))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <numeric>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

int main(){
    int N;
    cin >> N;
    int P[N];
    for(int i=0;i<N;i++){
        cin >> P[i];
    }
    sort(P, P+N);
    reverse(P,P+N);
    P[0] = P[0]/2;
    int sum = std::accumulate(P, P + N, 0);
    cout << sum <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll m[101][101];
vector<ll> p;

int main() {

    int n;
    cin >> n;
    ll a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        if (i == 0) 
            p.push_back(a);
        p.push_back(b);
    }

    for (int i = 0; i < n; i++) 
        m[i][i] = 0;
    // l: length
    for (int l = 1; l < n; l++) {
        for (int i = 0; i < n - l; i++) {
            int j = i + l;
            m[i][j] = (1 << 21);
            for (int k = i; k < j; k++) {
                ll q = m[i][k] + m[k+1][j] + p[i] * p[k+1] * p[j+1];
                
                if( q < m[i][j] )
                    m[i][j] = q;
            }
        }
    }

    cout << m[0][n-1] << '\n';
}




Measured memory_bytes: 3240
#include <stdio.h>

int a, b, c;
int cnt;

int main() {
  scanf("%d%d%d", &a, &b, &c);
  for(int i = a; i <= b; i++) {
    if(c%i==0)++cnt;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9
int n,c;


int main(){
    static int bp[1<<16];
    rep(i,1<<16)bp[i]=-1;
    while(cin>>n>>c){
        int bit[31]={};
        if(n==0&&c==0)break;
        
        int p[31][20]={};
        rep(i,n)rep(j,16)cin>>p[i][j];
        
        rep(i,c){
            int bin=0;
            rep(j,16){
                int a;
                cin>>a;
                bin|=a<<j;
            }
            bit[i]=bin;
        }
        bit[c]=0;
        
//        int b[31][20]={};
//        rep(i,c)rep(j,16)cin>>b[i][j];
        
        int dp[1<<16][31]={};
        rep(i,1<<16)rep(j,31)dp[i][j]=-INF;
        
        
        dp[0][0]=0;
        for(int i=1;i<=n;i++){
            int zero=0;
            rep(k,16){
                if(p[i-1][k]==1){
                    zero=(zero|(1<<k));
                }
            }
            rep(j,1<<16){
                if(j==zero)continue;
                int m=(zero|(int)j);
                dp[m][i-1]=max(dp[m][i-1],dp[j][i-1]);
            }
            
            
            rep(j,1<<16){
                rep(k,c+1){
                    int x=(int)j;
                    int z=0;
                    int num=j&bit[k];
                    if(bp[num]==-1){
                        z=__builtin_popcount(num);
                        bp[num]=z;
                    }else{
                        z=bp[num];
                    }
                    unsigned int val=((unsigned int)j & (~ (unsigned int)(bit[k])));
                    if(dp[j][i-1]!=-INF) dp[val][i] = max( dp[val][i],dp[j][i-1]+z );
                }
            }
            
            
            
        }
        int ans=-1;
        rep(i,1<<16){
            ans=max(ans,dp[i][n]);
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 9368
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool sumi[114514];
int a[114514],pos[114514],num[114514];
vector<int> v;
int main()
{
	int n,m,q,lo=0;
	scanf("%d %d",&m,&n);
	scanf("%d",&q);
	rep(i,q){
		scanf("%d",&a[i]);a[i]--;
	}
	for(int i=q-1;i>=0;i--){
		if(sumi[a[i]]) continue;
		v.pb(a[i]);sumi[a[i]]=true;
	}
	rep(i,n){
		if(!sumi[i]) v.pb(i);
	}
	//rep(i,n) cout<<v[i]<<' ';cout<<endl;
	rep(i,n) pos[v[i]]=i;
	int t=n-1;
	for(;t>0;t--){
		if(v[t]<v[t-1]) break;
	}
	//cout<<t<<endl;
	memset(num,0,sizeof(num));num[0]=m;
	int hi=0;
	for(int i=q-1;i>=0;i--){
		if(num[pos[a[i]]]>0){
			num[pos[a[i]]]--;
			num[pos[a[i]]+1]++;
			hi=max(hi,pos[a[i]]+1);
			//while(lo<n && num[lo]<1) lo++;
		}
		else if(hi<pos[a[i]]){
			cout<<"No"<<endl;return 0;
		}
	}
	rep(i,n){
		if(num[i]>0 && t>i){
			cout<<"No"<<endl;return 0;
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
const ll mod = 1e9 + 7;

int main()
{
    int n, x, ans = 0;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));
    rep(i, n - 1)
    {
        if (x >= a[i])
        {
            ans++;
            x -= a[i];
        }
        else
            break;
    }
    if (x == a[n - 1])
        ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//product of minimum 9 prime numbers is above 1e9

int main() {
    int n, m; cin >> n >> m;
    
    
    vector<vector<int> > come(n);
    vector<vector<int> > go(n);
    rep(i, m) {
        int x, y; cin >> x >> y; x--; y--;
        come[y].eb(x);
        go[x].eb(y);
    }
    
    queue<int> q;
    int dp[n]; fill_n(dp, n, 0);
    
    vector<int> c(n);
    rep(i, n) c[i] = SZ(come[i]);
    rep(i, n) if (SZ(come[i]) == 0) q.push(i);
    
    
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        rep(i, SZ(go[cur])) {
            int nxt = go[cur][i];
            c[nxt]--;
            if (c[nxt] == 0) {
                q.push(nxt);
                dp[nxt] = dp[cur] + 1;
            }
        }
    }
    
    int ans = 0;
    rep(i, n) chmax(ans, dp[i]);
    out(ans);
}


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

int main()
{
    int A, B, count = 0;
    cin >> A >> B;
    for (int i = A; i <= B; i++)
    {
        if (i / 10000 % 10 == i % 10 && i / 1000 % 10 == i / 10 % 10)
        {
            count++;
        }
    }
    cout << count << endl;
}


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

struct position{
    int y, x;
};

const position move_patterns[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

bool if_in_space(int H, int W, int y, int x){
    return 0 <= y && 0 <= x && y < H && x < W;
}

int main(){
    int H, W;
    cin >> H >> W;
    string space[H];
    int score = 0;
    for(int i = 0; i < H; i++){
        cin >> space[i];
        for(int j = 0; j < W; j++){
            score += (space[i][j] == '.');
        }
    }
    queue<pair<int, position>> position;
    position.push({0, {0, 0}});
    space[0][0] = '#';
    while(!position.empty()){
        if(position.front().second.y == H - 1 && position.front().second.x == W - 1){
            cout << score - position.front().first - 1 << endl;
            return 0;
        }
        for(int i = 0; i < 4; i++){
            if(if_in_space(H, W, position.front().second.y + move_patterns[i].y, position.front().second.x + move_patterns[i].x)){
                if(space[position.front().second.y + move_patterns[i].y][position.front().second.x + move_patterns[i].x] == '.'){
                    space[position.front().second.y + move_patterns[i].y][position.front().second.x + move_patterns[i].x] = '#';
                    position.push({position.front().first + 1, {position.front().second.y + move_patterns[i].y, position.front().second.x + move_patterns[i].x}});
                }
            }
        }
        position.pop();
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
import math
from collections import defaultdict

d = defaultdict(lambda : defaultdict(int))

K = int(input())

res = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        d[a][b] = math.gcd(a,b)

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            res += d[d[a][b]][c]

print(res)


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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
	FASTIO;
	ll n,k,i,j,d,r;
	cin>>n>>k;
	std::map<int, int>MAP;
	for(i=0;i<k;i++)
	{
        cin>>d;
        for(j=0;j<d;j++)
        {
            cin>>r;
            MAP[r]=j;
        }
	}
	cout<<n-MAP.size()<<"\n";

}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements <=num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//Sort(v);
//v.erase(unique(all(v)),v.end());
//It keeps unique elements in sorted order....
//#define int long long int
void solve(){
	int n,x,y;
	cin>>n>>x>>y;
	vi ans(n);
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int mn=min(j-i,Abs(x-i)+1+Abs(j-y));
			ans[mn]++;
		}
	}
	for(int i=1;i<n;i++) cout<<ans[i]<<endl;
}
 
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
} 

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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    loop(n) {
        cin >> arr[i];
    }
    auto Can = [&arr, k](int len) {
        int res = 0;
        for (int x : arr) {
            res += (x - 1) / len;
        }
        return res <= k;
    };
    int l = 1;
    int r = *max_element(all(arr));
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (Can(mid)) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    cout << r + 1 << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n-1; i++){
        for(int j = 1; j*j <= i; j++){
            if(i%j == 0){
                if(j*j == i) ans++;
                else ans += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    S = II()
    if S == 10**18:
        x1,y1,x2,y2,x3,y3 = 0,0,10**9,0,0,10**9
    else:
        x1,y1,x2,y2 = 0,0,10**9,1
        y3 = 0 if S < 10 ** 9 else S // 10**9 + 1
        x3 = S % 10**9 if y3 == 0 else 10**9 - S % 10 ** 9
    print(x1,y1,x2,y2,x3,y3)
    assert(abs(x3*y2-y3*x2)==S)
    assert(x3 <= 10**9)
    assert(y3 <= 10**9)



if __name__ == '__main__':
    main()

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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array

int main() {
    int n, k, input, ans=0;
    cin >> n >> k;
    queue<int> que;
    rep(i, k) {
        cin >> input;
        ans += input;
        que.push(input);
    }
    int now = ans; // nowは進行中の内容
    rep(i, n-k) {
        cin >> input;
        now = now - que.front() + input;
        que.pop();
        que.push(input);
        if(ans < now) ans = now;
    }
    cout << setprecision(8) << (ans + k)/2.0 << endl;
    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}

Measured memory_bytes: 1024
n = int(input())
l = list(map(int, input().split()))
l.sort()
if len(l) < 3:
  print(0)
else:
  cnt = 0
  for i in range(n-2):
    for j in range(i+1, n-1):
      if l[i] < l[j]:
        for k in range(j+1, n):
          if l[j] < l[k] < l[i] + l[j]:
            cnt += 1
          elif l[k] >= l[i] + l[j]:
            break
  print(cnt)

Measured memory_bytes: 9132
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

bool test(string str,string res) {
	if (str[str.length() - 1] == 'o' && res[str.length() - 1] == 'S' && res[str.length() - 2] == res[0]) {
		
		return true;
	}
	else if (str[str.length() - 1] == 'o' && res[str.length() - 1] == 'W') {
		if (res[str.length() - 2] != res[0]) {
			return true;
		}
	}
	else if (str[str.length() - 1] == 'x' && res[str.length() - 1] == 'S') {
		if (res[str.length() - 2] != res[0]) {
			return true;
		}
	}
	else if (str[str.length() - 1] == 'x' && res[str.length() - 1] == 'W') {
		if (res[str.length() - 2] == res[0]) {
			return true;
		}
	}
	return false;
}
bool test2(string str, string res) {
	if (str[0] == 'o' && res[0] == 'S' && res[str.length() - 1] == res[1]) {

		return true;
	}
	else if (str[0] == 'o' && res[0] == 'W') {
		if (res[str.length() - 1] != res[1]) {
			return true;
		}
	}
	else if (str[0] == 'x' && res[0] == 'S') {
		if (res[str.length() - 1] != res[1]) {
			return true;
		}
	}
	else if (str[0] == 'x' && res[0] == 'W') {
		if (res[str.length() - 1] == res[1]) {
			return true;
		}
	}
	return false;
}

string solve(string str,string res) {
	for (int i = 2; i < str.length(); i++) {
		if (str[i - 1] == 'o' && res[i - 1] == 'S') {
			res.push_back(res[i - 2]);
		}
		else if (str[i - 1] == 'o' && res[i - 1] == 'W') {
			if (res[i - 2] == 'S') {
				res.push_back('W');
			}
			else {
				res.push_back('S');
			}
		}
		else if (str[i - 1] == 'x' && res[i - 1] == 'S') {
			if (res[i - 2] == 'S') {
				res.push_back('W');
			}
			else {
				res.push_back('S');
			}
		}
		else {
			res.push_back(res[i - 2]);
		}
	}
	return res;
}


int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n;
	string str,res,res2,res3,res4;
	cin >> n >> str;
	//ss
	res = "SS";
	res2 = "SW";
	res3 = "WS";
	res4 = "WW";
	res = solve(str, res);
	res2 = solve(str, res2);
	res3 = solve(str, res3);
	res4 = solve(str, res4);

	if (test(str, res)&& test2(str, res)) { cout << res << endl; return 0; }
	if (test(str, res2) && test2(str, res2)) { cout << res2 << endl; return 0; }
	if (test(str, res3) && test2(str, res3)) { cout << res3 << endl; return 0; }
	if (test(str, res4) && test2(str, res4)) { cout << res4 << endl; return 0; }
	
	cout << -1 << endl;
}


Measured memory_bytes: 1272
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 1e3 + 100;

int n, m;
char g[maxn][maxn];

typedef long long ll;

void init() {
    for (int i = 0; i <= m + 1; ++i) g[0][i] = g[n + 1][i] = '.';
    for (int i = 0; i <= n + 1; ++i) g[i][m + 1] = '.';
}

bool check() {
    return true;
}

int main() {
    int cmd;
    while (scanf("%d", &cmd) != EOF) {
        int a, b;
        if (cmd == 1) puts("Hello World");
        else if (cmd == 2) {
            scanf("%d%d", &a, &b);
            printf("%d\n", a + b);
        }
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;

class Main  {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] arr = br.readLine().toCharArray();
        int n = arr.length;
        long[] dp = new long[2];
        dp[1] =1;
        for(int i = n-1; i >= 0; --i){
            long[] newdp = new long[2];
            int dig = arr[i]-'0';
            newdp[0] = dp[0]+dig;
            newdp[1] = Math.min(dp[0]+(10-dig), dp[1]+(10-dig-1));
            if(dig < 9){
                newdp[0] = Math.min(newdp[0], dp[1]+dig+1);
            }
            dp = newdp;
        }
        System.out.println(Math.min(dp[0], dp[1]+1));
    }
}

Measured memory_bytes: 47700
n=int(input())
p = []
for i in range(n):
    ta,tb,tc = map(int,input().split())
    p.append([ta,tb,tc])

p.sort(key=lambda x: x[2])
a,b,c=p[-1]
for y in range(101):
    for x in range(101):
        h=c+abs(a-x)+abs(b-y)
        if all(k==max(h-abs(i-x)-abs(y-j),0) for i,j,k in p):
            print(x,y,h)
            exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	unordered_map<string, int> mp;
	mp["AC"] = 0;
	mp["WA"] = 0;
	mp["TLE"] = 0;
	mp["RE"] = 0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string temp;
		cin>>temp;
		mp[temp]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ll res = 0;
	while (true) {
		bool flag = true;
		ll sousa = 0;
		vector<ll> minus(n, 0);
		for (int i = 0; i < n; i++) {
			if (a[i] < n) continue;
			ll tmp = 0;
			tmp = (a[i] - n) / n + 1;
			a[i] -= tmp*n;
			//cout << tmp << endl;
			sousa += tmp;
			res += tmp;
			minus[i] = tmp;
		}
		for (int i = 0; i < n; i++) {
			a[i] += (sousa-minus[i]);
			if (a[i] >= n) flag = false;
		}
		if (flag) break;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())


def dfs(acc, sevens, fives, threes):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if sevens >= 1 and fives >= 1 and threes >= 1:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7', sevens+1, fives, threes),
        dfs(acc + '5', sevens, fives+1, threes),
        dfs(acc + '3', sevens, fives, threes+1)
    ])


print(dfs('0', 0, 0, 0))


Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w = LI()
sy, sx = LI()
gy, gx = LI()
sy -= 1
sx -= 1
gy -= 1
gx -= 1
maze = [input() for _ in range(h)]
dist = [[inf] * w for _ in range(h)]
que = deque([(sy, sx)])
dist[sy][sx] = 0
while que:
    y, x = que.popleft()
    for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
        ny, nx = y + dy, x + dx
        if 0 <= ny < h and 0 <= nx < w:
            if maze[ny][nx] == '.' and dist[ny][nx] > dist[y][x]:
                dist[ny][nx] = dist[y][x]
                que.appendleft((ny, nx))
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            ny, nx = y + dy, x + dx
            if 0 <= ny < h and 0 <= nx < w:
                if maze[ny][nx] == '.' and dist[ny][nx] > dist[y][x] + 1:
                    dist[ny][nx] = dist[y][x] + 1
                    que.append((ny, nx))
if dist[gy][gx] == inf:
    print(-1)
else:
    print(dist[gy][gx])

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

using namespace std;

#define ll long long int 
const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) 
{
    visited[a] = true;
    for(int b : edges[a]) 
    {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if(in_degree[b] == 0) 
        {
            dfs(b);
        }
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while(m--) 
    {
        int a, b;
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for(int i = 1; i <= n; ++i) 
    {
        if(!visited[i] && in_degree[i] == 0) 
        {
            dfs(i);
        }
    }
    int answer = 0;
    for(int i = 1; i <= n; ++i) 
    {
        answer = max(answer, dist[i]);
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 14528
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b)
{
    return *(int *)a-*(int *)b;
}
int main (void)
{
    int n;
    scanf("%d", &n);
    int d[n];
    for (int i = 0; i < n; i++ )
        scanf("%d", &d[i]);
    qsort(d, n, sizeof(int), cmp);
    printf("%d", d[n/2] - d[n/2-1]);
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i, l, r) for (ll i = (l); i < (r); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }

// char s[210];
// char t[110]; #fix:2
char s[220], t[110];
int main()
{
  scanf("%s%s", s, t);
  ll n = strlen(s);
  // rep(i, 0, n) #fix:1
  for (int i = 0; i < n; i++)
  {
    if (!strcmp(s + i, t))
    {
      puts("Yes");
      return 0;
    }
    s[n + i] = s[i];
  }
  puts("No");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;


int main() {
    int N, M, L;
	cin >> N >> M >> L;
    vector<vector<int>> fuel(N, vector<int>(N, INF));
    rep (i, N) fuel[i][i] = 0;

    rep (i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        fuel[A][B] = fuel[B][A] = C;
    }

    // ワーシャルフロイド法
    rep (i, N) rep (j, N) rep (k, N) {
        chmin(fuel[j][k], fuel[j][i] + fuel[i][k]);
    }

    vector<vector<int>> dist(N, vector<int>(N, INF));
    rep (i, N) rep(j, N) {
        if (i==j) dist[i][j] = 0;
        else if (fuel[i][j] <= L) dist[i][j] = 1;
    }

    // ワーシャルフロイド法
    rep (i, N) rep(j, N) rep(k, N) {
        chmin(dist[j][k], dist[j][i] + dist[i][k]);
    }

    int Q;
    cin >> Q;
    rep (i, Q) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        if(dist[t][s] < INF) cout << dist[t][s] - 1 << endl;
        else cout << -1 << endl;
    }
	return 0;
}


Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**6)

n = int(input())
s = input()

def pcnt(x):
    return bin(x).count('1')

def f(x):
    if x == 0: return 0
    return f(x%pcnt(x))+1

x = [0]*n

for i in range(n):
    x[i] = int(s[i])

# 元のpopcountを求める
pc = sum([x[i] for i in range(n)])

ans = [0]*n

# b: 元のbit
for b in range(2):
    npc = pc
    if b == 0: npc += 1
    else: npc -= 1
        
    if npc <= 0: continue # 0除算が発生するため
    
    # 元の数をpopcountで割ったあまりを求める
    # 例えば2進数1101を10進数に変換するには、1, 1の2倍の2に1を足して3, 3の2倍の6に0を足して6, 6の2倍に1を足して13、と計算できる。今回はこれを%npcする操作が加わる
    r0 = 0
    for i in range(n):
        r0 = (r0*2)%npc
        r0 += x[i]
    
    # 一番下の桁からループを回す
    # i桁目をフリップしたときのあまりを求める
    # 下からi桁目をフリップすると2^i変わる。その値をkとして計算する。同じループの中で2^i(k)のあまりも求める
    k = 1
    for i in range(n-1, -1, -1):
        if x[i] == b:
            r = r0
            if b == 0: r = (r+k)%npc
            else: r = (r-k+npc)%npc # r-kだけだとマイナスになることがある
            ans[i] = f(r)+1
        k = (k*2)%npc

print(*ans)

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N, 0);
  REP(i, N) cin >> H.at(i);
  vector<vector<ll>> A(N, vector<ll>(0));
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    A.at(a).push_back(b);
    A.at(b).push_back(a);
  }
  ll ans = 0;
  REP(i, N) {
    bool t = true;
    REP(j, A.at(i).size()) {
      if (H[i] <= H[A.at(i).at(j)]) t = false;
    }
    if (t) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9856
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

int main() {
  int n;
  while(cin >>n && n){
    vector< vector<int> > v(n, vector<int>(n));
    REP(i, n) REP(j, n) cin >>v[i][j];
    REP(i, n){
      v[i].push_back(accumulate(v[i].begin(), v[i].end(), 0));
      REP(j, v[i].size()){
        printf("%5d", v[i][j]);
      }
      cout <<endl;
    }
    int ss = 0;
    REP(j, n){
      int s = 0;
      REP(i, n) s += v[i][j];
      printf("%5d", s);
      ss += s;
    }
    printf("%5d", ss);
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
n, m = list(map(int, input().split(' ')))
x = []
y = []
z = []
for i in range(n):
    a, b, c = list(map(int, input().split(' ')))
    x.append(a)
    y.append(b)
    z.append(c)
    
def maximize(a, b, c):
    ans = sorted(list(range(n)), reverse=True, key=lambda i: a * x[i] + b * y[i] + c * z[i])[:m]
    return sum(a * x[i] + b * y[i] + c * z[i] for i in ans)

ma = -1
for a in [-1, 1]:
    for b in [-1, 1]:
        for c in [-1, 1]:
            ma = max(ma, maximize(a, b, c))
print(ma)

Measured memory_bytes: 3188