akhauriyash/Code-Regression huggingface dataset:
class BinaryIndexTree:  # 1-indexed
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


N = int(input())
A = list(map(int, input().split()))
atoi = {a: i+1 for i, a in enumerate(sorted(set(A)))}

bit = BinaryIndexTree(len(atoi) + 5)

for a in A:
    i = atoi[a]
    bit.add(i, 1)


slime = []

p = bit.lower_bound(1 << N)
slime.append(p)
bit.add(p, -1)

for _ in range(N):
    next_slime = []
    for s in slime:
        tot = bit.sum(s - 1)
        p = bit.lower_bound(tot)
        if p == 0:
            print("No")
            exit()
        next_slime.extend([s, p])
        bit.add(p, -1)
    slime = next_slime
print("Yes")

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

typedef long long lint;
typedef long double louble;

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

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 503;
const lint linf = 0x3f3f3f3f3f3f3f3f;

int n;
lint val[_][_]={0},spv[_][_]={0},snv[_][_]={0};
lint f[_][_];

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)val[i][j]=ty();

	for(int i=1;i<=n;i++)
		for(int j=n;j>=i+1;j--)
		{
			spv[i][j]=spv[i][j+1];
			for(int k=1;k<=i;k++)spv[i][j]+=val[j][k];
		}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n+1;j++)
		{
			snv[i][j]=snv[i][j-1];
			for(int k=i;k<j;k++)snv[i][j]=snv[i][j]+val[k][j];
		}

	memset(f,63,sizeof(f));
	f[0][0]=0;
	for(int i=0;i<=n;i++)
		for(int j=i;j<=n;j++)
			if(f[i][j]<linf)
				for(int k=j+1;k<=n+1;k++)
					f[j][k]=min(f[j][k],f[i][j]+(spv[j][k+1]-spv[i][k+1])+snv[j+1][k]);
	lint ans=linf;
	for(int i=0;i<=n;i++)ans=min(ans,f[i][n+1]);
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 8192
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N;
ll A[3000];
ll DP[3000][3000];

ll Calc(int L, int R){
  if (DP[L][R] != 1e16) return DP[L][R];
  
  if (L == R){
    if (N % 2 == 0) return DP[L][R] = -1 * A[L];
    else return DP[L][R] = A[L];
  }

  ll ans;
  if (N % 2 == 0){
    if ((R - L) % 2 == 0){
      ans = min(Calc(L + 1, R) - A[L], Calc(L, R - 1) - A[R]);
    }else{
      ans = max(Calc(L + 1, R) + A[L], Calc(L, R - 1) + A[R]);
    }
  }else{
    if ((R - L) % 2 == 0){
      ans = max(Calc(L + 1, R) + A[L], Calc(L, R - 1) + A[R]);
    }else{
      ans = min(Calc(L + 1, R) - A[L], Calc(L, R - 1) - A[R]);
    }
  }
  return DP[L][R] = ans;
}

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

  fill((ll*)DP, (ll*)(DP + N), 1e16);

  cout << Calc(0, N - 1) << endl;
  
  return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int x,y;
	int ans[n]={0};
	for(int i=0;i<m;i++){
		cin>>x>>y;
		if(h[x-1]<=h[y-1]){
			ans[x-1]=-1;
		}
		if(h[y-1]<=h[x-1]){
			ans[y-1]=-1;
		}
	}

	int count =0;
	for(int i=0;i<n;i++){
		if(ans[i]==0){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
	
}


Measured memory_bytes: 4412
#include <stdio.h>

int main()
{
        int num = 0;
        unsigned long long i, factrial = 1;

        scanf( "%d", &num );
        for ( i = 1 ; i < num+1 ; i = i + 1 )
        {
                factrial = factrial * i;
        }

        fprintf( stdout, "%ld\n", factrial );

        return 0;

}

Measured memory_bytes: 592
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
const int MAX_N=100005;
int par[MAX_N];//父亲数组
void init(int n)
{
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
    }
}



int find(int x)//查询最近的已标记的祖先节点
{
    if(x==par[x])return x;
    else return find(par[x]);
}


void unite(int x,int y)//记x为y的子节点
{
    par[x]=y;
}

int main()
{
    //freopen("c://Users/kkk/Destop/acm.txt","r",stdin);
    int N,M;
    while(1)
    {
    cin>>N>>M;
    if(N==0&&M==0)break;
    int parent;
    init(N+1);
    for(int i=2;i<=N;i++)
    {
        cin>>parent;
        unite(i,parent);
    }
    long long ans=0;
    while(M--)
    {
        char c;int t;
        cin>>c;
        cin>>t;
        if(c=='Q')
        {
            ans+=find(t);
        }
        else if(c=='M')
        {
            par[t]=t;
        }
    }
        cout<<ans<<endl;
    }
    return 0;
}





Measured memory_bytes: 3384
#define vi vector<int>
#include<algorithm>
#include<vector>
#define ll long long
#include<iostream>
using namespace std;

int main(){
	ll n,k,l;
	cin>>n>>k;
	vi v;
	for(int i=0;i<n;i++){
		cin>>l;
		v.push_back(l);
	}
	ll ans =0;
	sort(v.begin(),v.end());
	for(int i=0;i<=k;i++){
		ans +=v[n-i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
a = [chr(ord("A") + i) for i in range(26)]
for i in range(len(s)):
    l = a.index(s[i])
    if l + n <= 25:
        s[i] = a[l + n]
    else:
        s[i] = a[l + n - 26]
print("".join(s))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int a,b,c,k;
  int ans = 0;
  cin >> a >> b >> c >> k;
  if(k <= a) ans = k;
  else if(k <= a+b) ans = a;
  else if(k <= a+b+c) ans = a - (k - a - b);
  cout << ans << endl;
}

Measured memory_bytes: 3652
import sys


#input
lines = [x.strip() for x in sys.stdin.readlines()]
memo={}

def slv(lines):
    ans = rec(str(lines[0]),len(str(lines[0])))

    return ans

def rec(s,n):
    if memo.get(s,None) is not None:
        return memo[s]
    re = 0
    if len(s) ==1:
        return int(s)
    for i in range(0,len(s)):
        l=s[:i]
        r=s[i:]
        if len(l)<1:
            re+=int(r)
        else:
            re += int(l)*(2**(n-i-1))+ rec(r,len(r))
     


    memo[s]=re
    return re


if __name__ == "__main__":
    print(slv(lines))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define iamabatman ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precision cout.precision(10); cout << fixed;
#define endl '\n'
#define ll long long int
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
int main()
{

  iamabatman
  precision
  ll sum=0;
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if(i%3!=0 && i%5!=0)
      sum+=i;
  }
  cout<<sum;
  return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  int max = a[0];
  for(int i = 0; i < n; i++){
    if(max < a[i]) max = a[i];
  }
  int min = a[0];
  for(int i = 0; i < n; i++){
    if(min > a[i]) min = a[i];
  }
  
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
 	int n, m;
 	while(cin >> n >> m) {
 		int sum = 0;
 		for(int i = 0; i < n; i++) 
 			sum += (n - i - 1);
 		for(int i =  0; i < m; i++)
 			sum += (m - i - 1);
 		// printf("%d %d %d %d\n", n, m, even, odd);
 		printf("%d\n", sum);
 	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    ll n;
    cin >> n;
    if(n%2 == 1){
        cout << 0;
        return 0;
    }

    n /= 2;

    ll num = 5 , ans = 0;
    while(n/num > 0){
        ans += n/num;
        num *= 5;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int infty = (int)((1LL << 31) - 1);
struct segment_tree {
  public:
    int n, N;
    vector<int> tr, lz, lzf;
    segment_tree (vector<int> v) {
      n = v.size();
      N = 1;
      while (N < n) N <<= 1;
      tr.resize(2 * N, infty);
      lz.resize(2 * N);
      lzf.resize(2 * N, false);
      for (int i = 0; i < n; i++) tr[N + i] = v[i];
      for (int i = N - 1; i >= 1; i--) tr[i] = min(tr[2 * i], tr[2 * i + 1]);
    }
    inline void pg (int k, int L, int R) {
      if (lzf[k]) {
        tr[k] = lz[k];
        if (k < N) {
          lz[2 * k] = lz[2 * k + 1] = lz[k];
          lzf[2 * k] = lzf[2 * k + 1] = true;
        }
        lzf[k] = false;
      }
    }
    void update (int l, int r, int x, int k = 1, int L = 0, int R = -1) {
      if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return;
      } else if (l <= L && R <= r) {
        lz[k] = x;
        lzf[k] = true;
        pg(k, L, R);
      } else {
        int C = (L + R) >> 1;
        update(l, r, x, 2 * k, L, C);
        update(l, r, x, 2 * k + 1, C, R);
        tr[k] = min(tr[2 * k], tr[2 * k + 1]);
      }
    }
    int getMin (int l, int r, int k = 1, int L = 0, int R = -1) {
       if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return infty;
      } else if (l <= L && R <= r) {
        return tr[k];
      } else {
        int C = (L + R) >> 1;
        return min(getMin(l, r, 2 * k, L, C), getMin(l, r, 2 * k + 1, C, R));
      }
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  segment_tree sgt(vector<int>(n, infty));
  while (q--) {
    int c;
    cin >> c;
    if (c == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      sgt.update(s, ++t, x);
    } else {
      int s, t;
      cin >> s >> t;
      int ret = sgt.getMin(s, ++t);
      cout << ret << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N, A, B;
cin >> N >> A >> B;
long zero = 0;
cout << min(A, B) << ' ' << max(zero, (A + B - N)) << endl;
return 0;
}

Measured memory_bytes: 256
N, x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for k in range(N-1):
    if a[k] < 0:
        a[k] = 0
    if a[k]+a[k+1] > x:
        t = (a[k]+a[k+1])-x
        a[k+1] -= t
        ans += t

print(ans)


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

using namespace std;

#define pt pair<int, int>
#define x first
#define y second
#define what_is(x) cerr << #x << " is " << x << endl;
#define endl '\n'
#define int long long
#define ld long double
random_device rd;
mt19937 rnd(rd());
const int inf = __LONG_LONG_MAX__;

signed main()
{
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for (int i = 0; i < n / 2; ++i)
		if (s[i] != s[n - i - 1])
			++ans;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,a[200005],ans[200005];
vector<int> g[200005];
multiset<int> s;
void dfs(int x,int y){
	s.insert(a[x]);
	multiset<int>::iterator it=s.lower_bound(a[x]);
	int z=0;
	if(++it!=s.end()){
		z=*it;
		s.erase(s.find(z));
	}
	ans[x]=s.size();
	for(int i=0;i<g[x].size();i++){
		int ch=g[x][i];
		if(ch==y)continue;
		dfs(ch,x);
	}
	if(z)s.insert(z);
	s.erase(s.find(a[x]));
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 30572
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,M = MI()
d1 = {}  # d1[i] = 島1と島iの間に定期便が存在するか
d2 = {}  # d1[i] = 島Nと島iの間に定期便が存在するか
for i in range(1,N+1):
    d1[i] = 0
    d2[i] = 0
for _ in range(M):
    a,b = MI()
    if a == 1:
        d1[b] = 1
    if b == N:
        d2[a] = 1
for i in d1.keys():
    if d1[i] == d2[i] == 1:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 135076
package main

import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)

func main() {
  //fmt.Println("Input : ")
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  var a int
  var b int

  if sc.Scan() { a, _ = strconv.Atoi(sc.Text()) }
  if sc.Scan() { b, _ = strconv.Atoi(sc.Text()) }

  fmt.Printf("%d %d %.5f", a/b, a%b, float64(a)/float64(b))
}



Measured memory_bytes: 1140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define N 100005
using namespace std;

int n;
char a[N], b[N];

//void f(int p) {
//	if (p > n) {
//		if (b[n] == b[0]) {
//			b[n] = '\0';
//			cout << b << endl;
//			exit(0);
//		}
//		return;
//	}
//	if (a[p - 1] == 'o') {
//		if (b[p - 1] == 'S') b[p] = b[p - 2], f(p + 1);
//		else b[p] = (b[p - 2] == 'S' ? 'W' : 'S'), f(p + 1);
//	} else {
//		if (b[p - 1] == 'W') b[p] = b[p - 2], f(p + 1);
//		else b[p] = (b[p - 2] == 'S' ? 'W' : 'S'), f(p + 1);
//	}
//}

void f() {
	int i;
	for (i = 2; i <= n; i++) {
		if (a[i - 1] == 'o') {
			if (b[i - 1] == 'S') b[i] = b[i - 2];
			else b[i] = (b[i - 2] == 'S' ? 'W' : 'S');
		} else {
			if (b[i - 1] == 'W') b[i] = b[i - 2];
			else b[i] = (b[i - 2] == 'S' ? 'W' : 'S');
		}
	}
	if (b[n] == b[0]) {
		if (a[0] == 'o') {
			if (b[0] == 'S') b[n + 1] = b[n - 1];
			else b[n + 1] = (b[n - 1] == 'S' ? 'W' : 'S');
		} else {
			if (b[0] == 'W') b[n + 1] = b[n - 1];
			else b[n + 1] = (b[n - 1] == 'S' ? 'W' : 'S');
		}
		if (b[n + 1] == b[1]) {
			b[n] = '\0';
			cout << b << endl;
			exit(0);
		}
	}
}

int main()
{
	cin >> n >> a;
	b[0] = 'S'; b[1] = 'S'; f();
	b[0] = 'S'; b[1] = 'W'; f();
	b[0] = 'W'; b[1] = 'S'; f();
	b[0] = 'W'; b[1] = 'W'; f();
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 512
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    cout << ans;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int p = 0, m = 0, ans = 0;
    for(int i = 0; i < 4; ++i){
        if(s.at(i) == '+') p++;
        else m++;
    }
    ans = p - m;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int H,W;
    cin >> H >> W;
    vector<vector<char>> S(H,vector<char> (W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> S.at(i).at(j);
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int count=0;
            if(S.at(i).at(j)=='.'){
                if(i-1>=0 && j-1>=0){
                    if(S.at(i-1).at(j-1)=='#')
                        count++;
                }
                if(i-1>=0){
                    if(S.at(i-1).at(j)=='#')
                        count++;
                }
                if(i-1>=0 && j+1<=W-1){
                    if(S.at(i-1).at(j+1)=='#')
                        count++;
                }
                if(j-1>=0){
                    if(S.at(i).at(j-1)=='#')
                        count++;
                }
                if(j+1<=W-1){
                    if(S.at(i).at(j+1)=='#')
                        count++;
                }
                if(i+1<=H-1 && j-1>=0){
                    if(S.at(i+1).at(j-1)=='#')
                        count++;
                }
                if(i+1<=H-1){
                    if(S.at(i+1).at(j)=='#')
                        count++;
                }
                if(i+1<=H-1 && j+1<=W-1){
                    if(S.at(i+1).at(j+1)=='#')
                        count++;
                }
                cout << count;
            }
            else{
                cout << S.at(i).at(j);
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=100010;
int n,a[N];
main(){
	scanf("%lld",&n);
	for (int i=1; i<=n; ++i) scanf("%lld",&a[i]);
	int ans=0;
	for (int i=1; i<=n+1; ++i) ans+=abs(a[i]-a[i-1]);
	for (int i=1; i<=n; ++i){
		int maxx=max(a[i-1],a[i+1]),minn=min(a[i-1],a[i+1]);
		if (minn<=a[i]&&a[i]<=maxx) printf("%lld\n",ans);
		else if (a[i]<minn){
			printf("%lld\n",ans-abs(a[i]-minn)*2);
		}
		else{
			printf("%lld\n",ans-abs(a[i]-maxx)*2);
		}
	}
}

Measured memory_bytes: 2048
import java.util.*;
import java.util.stream.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    int nums_cnt = Integer.parseInt(line);
    line = sc.nextLine();
    int[] numbers_ary = Stream.of(line.split(" ")).mapToInt(Integer::parseInt).toArray();
    
    int sum = Arrays.stream(numbers_ary).sum();
    
    int value = (int)(Math.round((double)sum / nums_cnt));
    sum = 0;
    for(int i : numbers_ary)
    {
      sum += (int)Math.pow((i - value),2);
    }
    
    System.out.println(sum);
    
  }
}

Measured memory_bytes: 28372
#include <stdio.h>

int main(void){

  int A[100];
  int i,j,k,n,flag = 1,x = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  while(flag != 0){

    flag = 0;

    for(j=n-1;j>0;j--){
      if(A[j] < A[j - 1]){
	k = A[j];
	A[j] = A[j - 1];
	A[j - 1] = k;
	x++;
	flag = 1;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i == n-1){
      printf("%d",A[i]);
      break;
    }
    printf("%d ",A[i]);
  }
  printf("\n%d\n",x);
  return 0;
}

Measured memory_bytes: 600
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto N = readln.chomp.to!int;

    auto n = N;
    int s;
    while (n) {
        s += n % 10;
        n /= 10;
    }
    writeln(N % s ? "No" : "Yes");
}

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

void fnInput(int& rnStair, vector<int>& rvnFine)
{
  int nFineSiz;
  cin >> rnStair >> nFineSiz;
  rvnFine.resize(rnStair + 1, true);

  for (int i = 0; i < nFineSiz; i++)
  {
    int nFine;
    cin >> nFine;
    rvnFine[ nFine ] = false;
  }
}

llong fnNumOfWays(int nStair, const vector<int>& cnrvnFine)
{
  const llong cnnMod = 1000000007;
  vector<llong> vnDPWays(nStair + 1);
  vnDPWays[0] = 1;

  for (int i = 1; i < vnDPWays.size(); i++)
    if (cnrvnFine[i])
    {
      vnDPWays[i] += vnDPWays[i - 1];
      if (i > 1)
        vnDPWays[i] += vnDPWays[i - 2];

      vnDPWays[i] %= cnnMod;
    }

  return vnDPWays[vnDPWays.size() - 1];
}
  
int main()
{
  int nStair;
  vector<int> vnFine;

  fnInput(nStair, vnFine);
  cout << fnNumOfWays(nStair, vnFine) << endl;

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(m);
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  int res[n] = {};
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (b[i] >= a[j]) {
        res[j]++;
        break;
      }
    }
  }
  int max = 0;
  int temp = 0;
  for (i = 0; i < n; i++) {
    if (temp < res[i]) {
      max = i + 1;
      temp = res[i];
    }
  }
  cout << max << endl;
  return 0;
}



Measured memory_bytes: 3052
var primeNxt = new Array(1000000);

function primeGenerator()
{
    var p, fact, m;
    var maxN = 9999999;
    var primePrv = new Array(1000000);

    // Initial
    for(p=2;p<=maxN;++p){
        primeNxt[p] = p + 1;
        primePrv[p] = p - 1;
    }
    primePrv[2] = 0;
    primeNxt[maxN] = 0;
    
    // Make prime table (primeNxt)
    for(p=2;p*p<=maxN;p=primeNxt[p]){
        for(fact=p;p*fact<=maxN;fact=primeNxt[fact]){
            for(m=p*fact;m<=maxN;m*=p){
                primeNxt[primePrv[m]] = primeNxt[m];
                primePrv[primeNxt[m]] = primePrv[m];
            }
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function(input){
    primeGenerator();
    input.trim().split('\n').forEach(function(val){
        var N = parseInt(val);
        if( N === 1 ){
            console.log(0);
        }
        else if(N===2){
            console.log(1);
        }
        else{
            var i, cnt;

            cnt = 0;
            for(i=2;i<=N;i=primeNxt[i]){
                ++cnt;
            }
            console.log(cnt);
        }
    });
});

Measured memory_bytes: 254552
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
	      		String S = sc.next();
	      		char[] c = S.toCharArray();
	      		char[] X = null, Y=null;
	      		int count = 0;
	      		int ans = 0;
	      		HashSet<String> a = new HashSet<String>();

	      		for(int i=1; i<N; i++){
	      			X = Arrays.copyOfRange(c, 0, i);
	      			Y = Arrays.copyOfRange(c, i, N);
	      			//System.out.println(Arrays.toString(X));
	      			//System.out.println(Arrays.toString(Y));
	      			count=0;
	      			a.clear();
	      			for(int j=0; j<X.length; j++){
	      				String x = String.valueOf(X[j]);
	      				String y = new String(Y);
	      				if(!(a.contains(x))){
	      					if(y.contains(x)){
	      						count++;
	      					}
	      					a.add(x);
	      				}

	      			}
	      			if(ans<count){
	      				ans = count;
	      			}
	      		}
	      		System.out.println(ans);
	}

}

Measured memory_bytes: 21972
#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()
typedef long long ll;
int main(){
    int x,n;
    cin >> x >> n;
    vector<int>p(n);
    rep(i,n)cin >> p[i];
    int a = 0;
    while (1){
        bool okp = true;
        bool okm = true;
        rep(i,n){
            if(x+a == p[i])okp = false;
            if(x-a == p[i])okm = false;
        }
        if(okm){
            cout << x - a << endl;
            return 0;
        }
        if(okp){
            cout << x + a << endl;
            return 0;
        }
        a++;
    }
    
    
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    p[n - 1] /= 2;
    int sum = 0;
    for(int i = 0; i < n; i++) sum += p[i];
    cout << sum << endl;
    return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair <int, int>> xy;

    for(int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        xy.emplace_back(x, y);
    }

    // initialize
    vector<float> white(N);
    vector<float> red(N);
    vector<int> num(N);
    for(int i = 0; i < N; i++)
    {
        white[i] = (i == 0)? 0 : 1;
        red[i]   = (i == 0)? 1 : 0;
        num[i] = 1;
    }

    for (int i=0; i<M; i++)
    {
        int x, y;
        x = xy[i].first;
        y = xy[i].second;
        int w, r;

        white[y] += white[x];
        red[y] += red[x];
        num[x]--, num[y]++;

        if (num[x] == 0)
            white[x] = red[x] = 0;
    }
    
    int ans = 0;
    for (int i = 0; i < N ; i++)
        if (red[i] > 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2164
import java.util.Scanner;

public class Main {//マインスウィーパー
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int H = scan.nextInt();
		int W = scan.nextInt();
		String[] S = new String[H];
		
		for(int i = 0;i<H;i++){
			S[i] = scan.next();
		}
		
		
		char[][] map = new char[H][W];
		
		for(int i = 0;i<H;i++){
			map[i] = S[i].toCharArray();
		}
		
		
		int dx[] = {0,1,1,1,0,-1,-1,-1};
		int dy[] = {1,1,0,-1,-1,-1,0,1};
		
		
		
		
		for(int i = 0;i<H;i++){
			for(int j = 0;j<W;j++){
				int bomcount = 0;
				
				if(map[i][j]=='.') {//まず前提としてあいたマスをチェック
					
					for(int z =0;z<8;z++){//そしたら八方向二爆弾があるかチェック
						int x = j+dx[z];
						int y = i+dy[z];
						if(0<=x&&x<W&&0<=y&&y<H){//もちろんマップ範囲内で
							if(map[y][x]=='#'){
								bomcount +=1;//見つけたらボムカウント入れる
							}
						}
					}
					
					//map[i][j] = String.valueOf(bomcount).charAt(0);//チェックし終わったらあいたマスをボムカウントに変えておく
					map[i][j] = (char)('0'+bomcount);
					
					
				}	
				
				
			}
		}
		

		for(int i = 0;i<H;i++){
			for(int j = 0;j<W;j++){
				System.out.print(map[i][j]);
				
			}
			System.out.println();
		}
		
		
		
		
		
		
		
		
	}

}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll a, b;
	string s;
	cin >> a >> b >> s;
	REP(i, a) if (s[i] < '0' || s[i] > '9') {
		cout << "No" << endl;
		return 0;
	}
	if (s[a] != '-') {
		cout << "No" << endl;
		return 0;
	}
	REP(i, b) if (s[a+1+i] < '0' || s[a+1+i] > '9') {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,a,b,i;
    cin>>n>>m;
    int Graph[n+1][n+1];
    memset(Graph,0,sizeof(Graph));
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        Graph[a][b]++;
        Graph[b][a]++;
    }
    int path[n];
    for (i=0;i<n;i++)
        path[i]=i+1;
    ll ans=0;
    do{
        bool flag=true;
        if (path[0]!=1)
            continue;
        for (i=0;i<n-1;i++)
        {
            if (Graph[path[i]][path[i+1]]==0)
            {
                flag=false;
                break;
            }
        }
        if (flag)
            ans++;
    } while (next_permutation(path,path+n));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String a = s.substring(0, 1);
		int b = s.length() - 2;
		String c = s.substring(s.length() - 1, s.length());
		System.out.println(a + b + c);
		//System.out.println((s.substring(0, 1)) + (s.length() -2) + (s.substring(s.length() -1, s.length())));
	}
}

Measured memory_bytes: 23636
mod = 7+10**9
def ncr(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod

X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
  print(0)
  exit()

n = (2*Y-X) // 3
m = (2*X-Y) // 3
if n < 0 or m < 0:
  print(0)
  exit()

ans = ncr(n+m,n,mod)
print(ans)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

if s_in() in ['hi', 'hi'*2, 'hi'*3, 'hi'*4, 'hi'*5]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <sstream>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define pll pair<long long,long long>
#define pld pair<long double,long double>
#define ios     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll mod=1000000007;
ll gcd (ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll fastexp(ll x ,ll n)
{
    ll result =1;
    while(n>0)
    {
        if(n%2==1)
            result*=x;
        x*=x;
        n=n/2;
    }
    return result;
}

ll modularExp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=((x%mod)*(x%mod))%mod;
        n=n/2;
    }
    return (result)%mod;
}
bool isPrime(ll n)
{
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
bool mycomp(pll &a,pll &b)
{
    if(a.F!=b.F)
        return a.F < b.F;
    else
        return a.S < b.S;
}

ll INF=1e18;

void solve()
{
     string s,t;
     cin>>s>>t;
     ll n=s.length();
     ll m=t.length();
     ll i,j;
     vector< vector<ll> > dp(n+1,vector<ll> (m+1));
     for(i=0;i<=n;i++)
     {
          for(j=0;j<=m;j++)
          {
               if(i==0 || j==0 )
               {
                    dp[i][j]=0;
                    continue;
               }
               else if(s[i-1]==t[j-1])
                    dp[i][j]=1+dp[i-1][j-1];
               else 
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
     }
     ll x=n,y=m;
     if(dp[x][y]==0)
     {
          cout<<"";
          return ;
     }
     
     string ns;
     while(x>=1 && y>=1)
     {
          ll val =dp[x][y];
          if(s[x-1]==t[y-1])
          {
               ns+=s[x-1];
               x--;
               y--;
          }
          else 
          {
               if(val==dp[x-1][y])
                    x-=1;
               else if(val==dp[x][y-1])
                    y-=1;
          }
     }
     reverse(ns.begin(),ns.end());
     cout<<ns;
     
}

int main()
{
    ios;
    ll t;
//    cin>>t;
  t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 70784
def comb(n, k, L):
    X = [[0] * n for _ in range(n)]
    for A, a, b in L:
        for i in range(len(A)):
            for j in range(len(A)):
                X[i+a][j+b] = A[i][j] + k if A[i][j] else 0
    return X
def ans(A):
    for a in A:
        print("".join([chr(b+97) if b else "." for b in a]))
a3 = [[1, 0, 0], [1, 0, 0], [0, 2, 2]]
a4 = [[1, 2, 3, 3], [1, 2, 4, 4], [5, 5, 6, 7], [8, 8, 6, 7]]
a5 = [[1, 1, 2, 2, 3], [4, 0, 5, 5, 3], [4, 7, 0, 0, 8], [9, 7, 0, 0, 8], [9, 5, 5, 6, 6]]
a6 = [[1, 0, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0], [0, 2, 2, 0, 2, 2], [1, 0, 0, 1, 0, 0], [1, 0, 0, 1, 0, 0], [0, 2, 2, 0, 2, 2]]
a7 = [[1, 0, 0, 1, 0, 0, 3], [1, 0, 0, 1, 0, 0, 3], [0, 2, 2, 0, 2, 2, 4], [1, 0, 0, 1, 0, 0, 4], [1, 0, 0, 1, 0, 0, 5], [0, 2, 2, 0, 2, 2, 5], [6, 6, 7, 7, 8, 8, 0]]

N = int(input())
if N <= 2:
    print(-1)
    exit()
if N <= 7:
    X = [a3, a4, a5, a6, a7][N-3]
elif N == 11:
    X = comb(11, 0, [[a4, 0, 0], [a7, 4, 4]])
elif N == 14:
    X = comb(14, 0, [[a7, 0, 0], [a7, 7, 7]])
else:
    b = N % 4
    a = (N - b * 5) // 4
    L = []
    i = 0
    for _ in range(a):
        L.append([a4, i, i])
        i += 4
    for _ in range(b):
        L.append([a5, i, i])
        i += 5
    X = comb(N, 0, L)

ans(X)

Measured memory_bytes: 12004
io = STDIN
n=io.gets.to_i
l=io.gets.split.map(&:to_i).sort
cnt=0
#a+b>c
#b+c>a  c>a-b
#c+a>b  c>b-a
(0...n-2).each do |i|
   (i+1...n-1).each do |j|
      apb=l[i]+l[j]
      k=l[j+1...n].bsearch_index{|c|c>=apb}
      cnt+=k||n-1-j
   end
end
p cnt


Measured memory_bytes: 1912
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    bool check=1;
    while(1){
        int ans=n;
       // cout<<ans<<endl;
        if(ans%10==((ans/10)%10)){
            ans/=10;
            if(ans%10==((ans/10)%10)){
                cout<<n<<endl;
                return 0;
            }
            else{
                n++;
                continue;;
            }
        }else{
            n++;
            continue;
        }
    }
    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N, T;
    cin >> N >> T;
    struct Food {
        ll time;
        ll value;
    };
    vector<Food> foods(N);
    rep(i,0,N) {
        cin >> foods[i].time >> foods[i].value;
    }
    sort(foods.begin(), foods.end(), [](Food lhs, Food rhs){
        return lhs.time < rhs.time;
    });
    auto dp = make_vec_nd(numeric_limits<ll>::min(), foods.size()+1, T);
    rep(t,0,T) {
        dp[0][t] = 0;
    }
    rep(n,1,foods.size()+1) {
        rep(t,0,T) {
            dp[n][t] = dp[n-1][t];
            if (t >= foods[n-1].time) {
                dp[n][t] = max(dp[n][t], foods[n-1].value + dp[n-1][t-foods[n-1].time]);
            }
        }
    }
    auto max_val_tail = make_vec_nd(numeric_limits<ll>::min(), foods.size()+1);
    rep(n,1,foods.size()+1) {
        max_val_tail[n] = max(max_val_tail[n-1], foods[foods.size()-n].value);
    }
    ll ans = numeric_limits<ll>::min();
    rep(n,0,foods.size()+1) {
        ll ans_loc = dp[n][T-1] + max_val_tail[N-n];
        ans = max(ans, ans_loc);
    }
    cout << ans << endl;
}



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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
using vertex = struct vertex{ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using _vertex = struct _vertex{ll to;_vertex(ll to):to(to){}};
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using _edge = struct _edge{ll from,to;_edge(ll from,ll to):from(from),to(to){}};
using un_weighted_adjlist = vector<vector<_vertex>>;
using weighted_adjlist = vector<vector<vertex>>;
using un_weighted_edge = vector<_edge>;
using weighted_edge = vector<edge>;
main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,q;
  cin>>n>>q;
  vector<ll> a(n-1),b(n-1);
  rep(i,n-1)cin>>a[i]>>b[i];
  vector<ll> p(q),x(q);
  rep(i,q)cin>>p[i]>>x[i];

  un_weighted_adjlist adj(n);
  rep(i,n-1){
    a[i]--;b[i]--; // 0-indexed
    adj[a[i]].push_back(b[i]);
    adj[b[i]].push_back(a[i]);
  }

  // BFSでDAGにする
  queue<ll> que;
  que.push(0);
  vector<bool> used(n,false);
  un_weighted_adjlist dag(n);
  while(!que.empty()){
    ll now=que.front();
    que.pop();
    used[now]=true;
    for(const auto& next:adj[now]){
      if(used[next.to])continue;
      dag[now].push_back(next.to);
      que.push(next.to);
    }
  }

  // 各頂点のカウント
  vector<ll> res(n);
  rep(i,q){
    p[i]--;
    res[p[i]]+=x[i];
  }

  //DAGを根からBFSする
  que.push(0);
  while(!que.empty()){
    ll now=que.front();
    que.pop();
    for(const auto& next:dag[now]){
      res[next.to]+=res[now];
      que.push(next.to);
    }
  }

  rep(i,n)cout<<res[i]<<" ";
  cout<<endl;


}


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

int main(void)
{
  int n;
  std::cin >> n;

  std::vector<int> l(n);
  for (int i = 0; i < n; i++) {
    std::cin >> l.at(i);
  }

  std::sort(l.begin(), l.end());

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if ((l[i]+ l[j] > l[k]) && (l[i] != l[j]) && (l[j] != l[k])) {
          cnt++;
        }
      }
    }
  }

  std::cout << cnt << std::endl;

  return 0;
}

Measured memory_bytes: 3576
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
def dijkstra():
    d[0] = 0
    q = [[0,0]]
    while q:
        dx, x = heappop(q)
        for y in v[x]:
            if d[y] > dx+1:
                d[y] = dx+1
                heappush(q,[d[y],y])
n,m = LI()
v = [[] for i in range(n)]
for i in range(m):
    a,b = LI()
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
d = [float("inf") for i in range(n)]
dijkstra()
if d[n-1] <= 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
"""

#D
k = I()
ans = [i+k//50 for i in range(50)]
k %= 50
for i in range(k):
    ans[i] += 51
    for j in range(50):
        ans[j] -= 1
print(50)
print(*ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39024
N = int(input())
T = list(map(int,input().split()))
V = list(map(int,input().split()))

Tsum = sum(T)
keika = []
tmp = 0
for i in range(N):
    keika.append([tmp,tmp+T[i]])
    tmp += T[i]

G = [[0]*(N+1) for i in range(2*Tsum+1)]

for i in range(2*Tsum+1):
    G[i][0] = min(i/2,Tsum-i/2)
for i in range(N):
    t0,t1 = keika[i]
    for j in range(2*t0):
        G[j][i+1] = V[i] + t0 - j/2
    for j in range(2*t0,2*t1+1):
        G[j][i+1] = V[i]
    for j in range(2*t1+1,2*Tsum+1):
        G[j][i+1] = V[i] + j/2 - t1

ans = 0
for i in range(2*Tsum):
    v0 = min(G[i])
    v1 = min(G[i+1])
    ans += (v0+v1)/4
print(ans)

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

int main()
{
  int h,m,s;
  
  cin>>s;//cin>> ??? c in >>(insert)
  
  h = s/3600;
  s-= 3600*h;
  
  m = s/60;
  s-= 60*m;
  
  cout<<h<<":"<<m<<":"<<s<<endl;//cout<< ??? c out <<(insert)
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


int main() {
  lint n; cin >> n;
  vector< pair<lint,lint> > p(n,pair<lint,lint>(0,0));
  for(lint i=0;i<n;i++) {
    lint a,b; cin >> a >> b;
    p[i].first = b; p[i].second = a;
  }

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

  lint sum=0;
  for(lint i=0;i<n;i++) {
    sum += p[i].second;
    if(sum > p[i].first) {
      cout << "No\n";
      return 0;
    }
  }

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

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
typedef long double ld;
typedef double db;
//typedef acos(-1) PI;

#define PI acos(-1)

int main(){
	int n;
	cin>>n;
	db ans=2*PI*n;
	//printf("%.9Lf\n",ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int[] d = na(n);

    int max = Arrays.stream(d).max().getAsInt();
    long[] a = new long[max + 1];
    for (int v : d) {
      a[v]++;
    }

    if (d[0] != 0 || a[0] != 1) {
      System.out.println(0);
      return;
    }

    long ret = 1;
    int mod = 998244353;
    for (int i = 0; i < max; i++) {
      ret *= pow(a[i], a[i + 1], mod);
      ret %= mod;
    }

    System.out.println(ret);

  }

  public static long pow(long a, long n, long mod) {
    // a %= mod;
    long ret = 1;
    int x = 63 - Long.numberOfLeadingZeros(n);
    for (; x >= 0; x--) {
      ret = ret * ret % mod;
      if (n << 63 - x < 0)
        ret = ret * a % mod;
    }
    return ret;
  }


  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

using namespace std;

typedef long long ll;
typedef std::vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int n, m;
	cin >> n >> m;
	vector<int> s(n, 0), g(n, 0);
	n--;
	FOR(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (a == 0)s[b] = 1;
		else if (b == n)g[a] = 1;
	}
	string ans = "IMPOSSIBLE";
	FOR1(i, n) {
		if (s[i] && g[i])ans = "POSSIBLE";
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792