akhauriyash/Code-Regression huggingface dataset:
/*input
7
0010101
1 2
2 3
1 4
4 5
1 6
6 7
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int n;
bool mark[maxn];
bool vis[maxn];

int l[maxn],r[maxn];
int cnt[maxn];
vector<int> edge[maxn];
void dfs(int u){
	vis[u]=1;
	l[u]=r[u]=0;
	cnt[u]=0;
	pii mx=MP(0,0);
	for(int v:edge[u]) if(!vis[v]){
		dfs(v);
		r[v]+=cnt[v];
		l[v]+=cnt[v];
		if(mx<MP(r[v],l[v])) mx=MP(r[v],l[v]);
		cnt[u]+=cnt[v];
		r[u]+=r[v];
	}
	if(mark[u]) cnt[u]++;
	if(mx.S>r[u]-mx.F){
		l[u]=mx.S-(r[u]-mx.F);
	}
	else l[u]=r[u]%2;
	// cout<<u<<' '<<l[u]<<' '<<r[u]<<' '<<cnt[u]<<'\n';
}

int main(){
	IOS;
	cin>>n;
	string s;
	cin>>s;
	REP(i,n) mark[i]=(s[i]=='1');

	REP(i,n-1){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
	}

	int ans=-1;

	REP(i,n){
		// cout<<"solve:"<<i<<'\n';
		REP(j,n) vis[j]=0;
		dfs(i);
		if(r[i]%2) continue;

		if(l[i]==0){
			if(ans==-1||ans>r[i]/2) ans=r[i]/2;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void) {
    long int N,M,a=0,i;
    
    cin >> N >> M;
   long int H[N],S[N];
long int A[M][2];
     for(i=0;i<N;++i){
         cin >> H[i];
         S[i] = 1;
     }
    
for(i=0;i<M;++i){
    cin >> A[i][0] >> A[i][1];
    if(H[A[i][0]-1]<H[A[i][1]-1]){
        S[A[i][0]-1] = 0;
    }
    else if(H[A[i][0]-1]>H[A[i][1]-1]){
         S[A[i][1]-1] = 0;
    }
    else{
        S[A[i][0]-1] = 0;
        S[A[i][1]-1] = 0;
    }
}
REP(i,N){
    if(S[i]==1){
        a++;
    }

}

printf("%ld\n",a);
  return 0;
}

Measured memory_bytes: 6872
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
 
int main(){
  int N;
  int D;
  int X[15][15];
  cin >> N >> D;

  for(int i=0;i<N;++i){
  	for(int j=0;j<D;++j){
      cin >> X[i][j];
    }
  }
  
  int counter = 0;
  for(int i=0;i<N-1;++i){
  	for(int j=i+1;j<N;++j){
      int total = 0;
      for(int k=0;k<D;++k) total += pow((X[i][k] - X[j][k]),2);
      float root = sqrtf((float) total);
      
      if(floor(root) == root ) counter++; 
    }
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
pair<int, int>p[100010];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> p[i].first;
		p[i].second = i;
	}
	sort(p,p + n);
	rep(i, n) {
		cout << p[i].second+1 << ' ';
	}
}

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

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

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

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

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

main = do
	[ d, n ] <- readInts
	print $ ( * 100^d ) $ ( !! ( n - 1 ) ) $ do
		x <- [ 0 .. ]
		guard $ x `mod` 100 /= 0
		return x

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

const int N=6005;
const long long MOD=1e9+7;
int n,m;
long long dp[N][N][2],ans;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) dp[0][i][0]=1;
	dp[0][0][1]=1;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j][0]%=MOD;
			dp[i][j][1]%=MOD;
			if(j>0)
			{
				if(j==1) dp[i+1][j-1][1]+=dp[i][j][0];
				else dp[i+1][j-1][0]+=dp[i][j][0];
				dp[i+1][j-1][1]+=dp[i][j][1];
				if(j==1) dp[i+1][j][1]+=dp[i][j][0];
				else dp[i+1][j][0]+=dp[i][j][0];
				dp[i+1][j][1]+=dp[i][j][1];
			}
			if(j<n)
			{
				dp[i+1][j+1][0]+=dp[i][j][0];
				dp[i+1][j+1][1]+=dp[i][j][1];
				dp[i+1][j][0]+=dp[i][j][0];
				dp[i+1][j][1]+=dp[i][j][1];
			}
		}
	}
	for(int i=0;i<=n;i++) ans=(ans+dp[m][i][1])%MOD;
	printf("%lld\n",ans);
}

Measured memory_bytes: 156348
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

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

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << endl;
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << endl;
	}
}

void executeCode() {
	ll a;
	cin >> a;
	cout << (a + pow(a, 2) + pow(a , 3)) << endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int n,k;cin>>n>>k;
        int a[n]={0};
        rep(i,n)cin>>a[i];
        rep(i,k){
            int pre[n+1]={0};
            rep(i,n){
                pre[min(n,i+a[i]+1)]--;
                pre[max(0,i-a[i])]++;
            }
            repA(i,1,n){
                pre[i]+=pre[i-1];
            }
            rep(i,n)a[i]=pre[i];
            int f=1;
            rep(i,n){
                if(a[i]!=n){
                    f=0;break;
                }
            }
            if(f)break;
        }
        rep(i,n){
            cout<<a[i]<<" ";
        }
    }   
    timecalculater();
    return 0;   
} 

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<n; i++){
        int q = (n-1)/i;
        ans += q;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> P;
typedef pair<P,int> Q;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int h,w;
  vector<vector<char>> c(22,vector<char>(22,'#'));
  vector<vector<bool>> a(22,vector<bool>(22,false));
int res(int i,int j){
  int d=0;
  vector<vector<bool>> b=a;
  b[i][j]=true;
  queue<Q> q;
  if(c[i][j]=='.'){
    q.push(Q(P(i-1,j),1));
    q.push(Q(P(i+1,j),1));
    q.push(Q(P(i,j-1),1));
    q.push(Q(P(i,j+1),1));
  }
  while(!q.empty()){
    Q x=q.front();
    q.pop();
    if(c[x.first.first][x.first.second]=='.'){
      if(!b[x.first.first][x.first.second]){
        d=max(d,x.second);
        b[x.first.first][x.first.second]=true;
    q.push(Q(P(x.first.first-1,x.first.second),x.second+1));
    q.push(Q(P(x.first.first+1,x.first.second),x.second+1));
    q.push(Q(P(x.first.first,x.first.second-1),x.second+1));
    q.push(Q(P(x.first.first,x.first.second+1),x.second+1));
      }
    }
  }
  return d;
}
int main(){
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>c[i+1][j+1];
    }
  }
  int m=0;
  rep(i,h){
    rep(j,w){
      m=max(res(i+1,j+1),m);
    }
  }
  cout<<m;
}

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

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  ll k;
  cin >> k;
  if(k%7==0)k/=7;
  k*=9;
  ll l=1;
  rep(i,10000000){
    l=l*10%k;
    if(l%k==1){
      cout << i+1;
      return 0;
    }
  }
  cout << -1;
}

Measured memory_bytes: 3600
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define P_B push_back
#define E_B emplace_back
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  ll S, W;

  cin >> S >> W;
  if(W >= S) cout << "unsafe" << endl;
  else cout << "safe" << endl;


  return 0;
}


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

int main() {
int n;
	string s;
cin>>n;
cin>>s;
int ans=0;
int temp[10][10][10]={0};
for(int i=0;i<10;i++){

for(int j=1;j<n-1;j++){
int temp1[10]={0};
int temp2[10]={0};

if(s[j]-'0'==i){
for(int k=0;k<j;k++){
temp1[s[k]-'0']=1;}
for(int k=j+1;k<n;k++){
temp2[s[k]-'0']=1;
}
}

for(int k=0;k<10;k++){
for(int l=0;l<10;l++){
if(temp1[k]==1&&temp2[l]==1){
temp[i][k][l]=1;
}
}
}
}
}
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++){
if(temp[i][j][k]==1){
ans++;
}
}
}
}
cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  int min_cost = n;
  for(int i = 0; i <= n; ++i){
    int cost = 0;
    int tmp = i;
    while(tmp > 0){
      cost += tmp % 6;
      tmp /= 6;
    }
    
    tmp = n - i;
    while(tmp > 0){
      cost += tmp % 9;
      tmp /= 9;
    }
    
    min_cost = min(cost, min_cost);
  }
  
  cout << min_cost << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

N = ii()
A = li()
'''
for i in reversed(range(N//2)):
    ind = i+1
    ind += i+1
    while(ind-1 < N):
        A[i] += A[ind-1]
        ind += i+1
    A[i] %= 2
'''

for i in reversed(range(N)):
    ind = 2*(i+1)
    while(ind-1 < N):
        A[i] += A[ind-1]
        ind += i+1
    if i < N//2:
        A[i] %= 2

ans = ''
print(sum(A))
for i in range(N):
    if A[i]%2 == 1:
        ans += str(i+1) + ' '

if ans != '':
    print(ans[:-1])

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

int main(){
  int k;
  string s; 
  cin >> k;
  cin >> s;
  int s_len = s.length();
  string s_part = s.substr(0, k);
  
  if(s_len <= k){
    cout << s << endl;
  }else{
    cout << s_part << "..." << endl;
  }
  
}

Measured memory_bytes: 3580
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll A, B, M, i, a[100001], b[100001], x[100001], y[100001], c[100001], min=INF;

    cin >> A >> B >> M;

    for(i=1; i<=A; i++){
        cin >> a[i];
    }
    for(i=1; i<=B; i++){
        cin >> b[i];
    }
    for(i=1; i<=M; i++){
        cin >> x[i] >> y[i] >> c[i];
        chmin(min, a[x[i]]+b[y[i]]-c[i]);
    }
    sort(a+1, a+A+1);
    sort(b+1, b+B+1);

    chmin(min, a[1]+b[1]);

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long int
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
const int inf = 0x3f3f3f3f;
#define Maxn 200000
long long a[Maxn+5];
long long pre[Maxn+5];
long long roo[Maxn+5];
int main(){
	int n;
	while (cin >> n ){
		for (int i = 0; i < n; i++)
			cin >> a[i];
		long long ans = -1;
		pre[0] = a[0];
		roo[n - 1] = a[n - 1];
		for (int i = 1; i < n; i++)
			pre[i] = pre[i - 1] + a[i];
		for (int i = n - 2; i >= 0; i--)
			roo[i] = roo[i + 1] + a[i];
		for (int i = 1; i <= n - 3; i++){
			long long ls = pre[i] ;
			long long rs = roo[i + 1];
			long long l1, l2, r1, r2;
			long long lz = lower_bound(pre, pre + i + 1, ls / 2)-pre;
			if (lz != 0)lz--;
			l1 = pre[lz];
			l2 = ls - l1;
			long long rz = lower_bound(pre, pre + n, ls + rs / 2) - pre;
			if (rz != i + 1)rz--;
			r1 = pre[rz] - pre[i];
			r2 = rs - r1;
			long long zs = max(l1, max(l2, max(r1, r2)));
			zs = abs(zs - min(l1, min(l2, min(r1, r2))));
			if (ans == -1 || ans > zs)
				ans=zs;
			l1 = pre[lz + 1];
			l2 = ls - l1;
			r1 = pre[rz] - pre[i];
			r2 = rs - r1;
			zs = max(l1, max(l2, max(r1, r2)));
			zs = abs(zs - min(l1, min(l2, min(r1, r2))));
			if (ans == -1 || ans > zs)
				ans = zs;
			l1 = pre[lz + 1];
			l2 = ls - l1;
			r1 = pre[rz+1] - pre[i];
			r2 = rs - r1;
			zs = max(l1, max(l2, max(r1, r2)));
			zs = abs(zs - min(l1, min(l2, min(r1, r2))));
			if (ans == -1 || ans > zs)
				ans = zs;
			l1 = pre[lz];
			l2 = ls - l1;
			r1 = pre[rz+1] - pre[i];
			r2 = rs - r1;
			zs = max(l1, max(l2, max(r1, r2)));
			zs = abs(zs - min(l1, min(l2, min(r1, r2))));
			if (ans == -1 || ans > zs)
				ans = zs;
		}
		cout << ans << endl;
	}
	return 0;
}


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

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    char input = sc.nextLine().charAt(0);
    
    if(input >= 'A' && input <= 'Z'){
      System.out.println('A');
    } else {
      System.out.println('a');
    }
  }
}


Measured memory_bytes: 26924
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
			List<Integer> ys = new ArrayList<Integer>();
			for (int i = 0; i < n; i++) {
				ys.add(sc.nextInt());
			}
			int count = 0;
			int size = ys.size();
			int i = 0;
			for (; count <= 10000; count++) {
				if (ys.get(i) == x) {
					i++;
				}
				if (i >= size) {
					break;
				} else {
					x = (a * x + b) % c; 
				}
			}
			if (count > 10000) {
				System.out.println(-1);
			} else {
				System.out.println(count);
			}
		}
	}
}

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

char a[100][100], b[102][102];

int main()
{
  int H,W;
  cin >> H >> W;
  rep(i, H)
    cin >> a[i];
  rep(i, H+2) {
    rep(j, W+2) {
      b[i][j] = '#';
    }
  }
  rep(i, H) {
    rep(j, W) {
      b[i+1][j+1] = a[i][j];
    }
  }
  rep(i, H+2)
  {
    rep(j, W+2) {
      cout << b[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define debug(x)			{ cerr << #x << " = " << x << endl; }
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define vi					vector<int>
#define vii					vector<vi>
#define max(x,y)			(x>y)?x:y
#define min(x,y)			(x<y)?x:y
#define mid(s,e)			(s+(e-s)/2)

using namespace std;
bool isPrime(int n)  
{  
    if (n <= 1)  return false;  
    if (n <= 3)  return true;  
    
    if (n%2 == 0 || n%3 == 0) return false;  
    
    for (int i=5; i*i<=n; i=i+6)  
        if (n%i == 0 || n%(i+2) == 0)  
           return false;  
    
    return true;  
} 
int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	ll x;
	cin>>x;
	while(!isPrime(x)) {
		x++;
	}
	cout<<x;

	return 0;
}



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

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }
  
  vector<int> tmp = c.at(0);
  sort(tmp.begin(), tmp.end());
  int tmp_a = tmp.at(0);
  bool flag = false;
  for (int i = tmp_a; i >= 0; i--) {
    int tmp_b = c.at(0).at(0) - tmp_a;
    int tmp_bb = c.at(0).at(1) - tmp_a;
    int tmp_bbb = c.at(0).at(2) - tmp_a;
    if (c.at(1).at(0) - tmp_b == c.at(1).at(1) - tmp_bb) {
      if (c.at(1).at(0) - tmp_b == c.at(1).at(2) - tmp_bbb) {
        if (c.at(2).at(0) - tmp_b == c.at(2).at(1) - tmp_bb) {
          if (c.at(2).at(0) - tmp_b == c.at(2).at(2) - tmp_bbb) {
            flag = true;
            break;
          }
          if (flag) break;
        }
        if (flag) break;
      }
    if (flag) break;
    }
  }
  
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
const main = (line) => {
	const Ns = [line.substring(0,2),line.substring(2,4)].map(Number)
  if(Ns[0] <= 12 && Ns[0] > 0 && Ns[1] <= 12 && Ns[1] > 0 )  return console.log("AMBIGUOUS")
  if((Ns[0] === 0 || Ns[0] > 12) && Ns[1] <= 12 && Ns[1] > 0)  return console.log("YYMM")
  if(Ns[0] <= 12 && Ns[0] > 0 && (Ns[1] === 0 || Ns[1] > 12))  return console.log("MMYY")
  console.log("NA")
  }

main(require("fs").readFileSync("/dev/stdin", "utf8"))

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

#define endl '\n'

int const N = 200020, inf = (int) 2e9;
int n, a[N], lis[N], ans[N];
vector<int> adj[N];

void dfs(int v = 0, int p = -1){
    int pos = (int) (lower_bound(lis, lis + N, a[v]) - lis);
    int ant = lis[pos];
    lis[pos] = a[v];
    ans[v] = (int) (lower_bound(lis, lis+N, inf) - lis) - 1;
    for (int f : adj[v]){
        if (f == p) continue;
        dfs(f, v);
    }
    lis[pos] = ant;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    lis[0] = -inf;
    for (int i=1; i<N; i++) lis[i] = inf;

    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n-1; i++){
        int u,v; cin >> u >> v; u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    dfs();
    for (int i=0; i<n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 31088
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  int h, a;
  cin >> h >> a;
  if (h % a == 0) {
    cout << h / a << "\n";
  } else {
    cout << h / a + 1 << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,max(0,ceil((H-pointB)/maxA))+nb)
print(ans)

Measured memory_bytes: 7512
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {
	
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int l;
    string s,t;
    char *S,*T;
    cin>>s>>t;
    S = strdup(s.c_str());
    T = strdup(t.c_str());
    l = s.size();
    if(strncmp(S,T,l)==0) cout<<"Yes";
    else cout<<"No";
    
    
	return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;cin >> a >> b;
    if (a==1 || b==1){
        if (a==b){
            cout << "Draw";
        }
        else if (a<b) cout << "Alice";
        else cout << "Bob";
    }
    else {
        if (a==b){
            cout << "Draw";
        }
        else if (a>b) cout << "Alice";
        else cout << "Bob";
    }
}

Measured memory_bytes: 3580
a,b,c,d=map(int,input().split())
x=0
list=[]
list.append(a)
list.append(b)
list.append(c)
list.append(d)
for i in range(4):
    if list[i]==1:
        x+=1000
    elif list[i]==9:
        x+=900
    elif list[i]==7:
        x+=70
    elif list[i]==4:
        x+=4
print("YES" if x==1974 else "NO")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
   string b;
   int g;
   cin >> g;
   cin >> b;
   int l = b.length();
   if(l <= g){
       cout << b;
   }else if(l > g){
       b = b.substr(0, g);
       cout << b  << "...";
   }
   
    return 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
int main(){
    ll h,w;cin>>h>>w;
    if(h>=2&&w>=2)cout<<(h-2)*(w-2)<<endl;
    else{
	if(h==1&&w==1)cout<<"1"<<endl;
	else cout<<h*w-2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(' ')))

p = 0
m = 0
c = 1
for a in A:
	p += c*a # A1-A2+A3-...
	c *= -1

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

x = [0]*(N+1)

x[1] = p
for i in range(2,N+1):
	x[i] = 2*A[i-1] - x[i-1]


ans = "".join(map(lambda s:str(s)+" ",x[1:]))
print(ans)


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

int main()
{
  int a,b,c[5] ;  
  cin >> a >> b;
  int count = 0;
  for(int i=a;i<=b;++i){
    int tmp = i;
    for(int j=0;j<5;j++){
      c[j]=tmp%10 ;
      tmp/=10;
    }
    if(c[0]==c[4] && c[1]==c[3])
         count++;
  }
    cout << count << "\n" ;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N;
    cin>>N;
    vector<double> p(N+1);
    for(int i=0;i<N;i++)cin>>p[i+1];

    vector< vector<double> > dp(2+N/2, vector<double>(N+1, 0));
    for(int i=1;i<=1+N/2;i++)dp[i][0]=1;
    double ans = 0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=dp[i][j-1]*p[j]+dp[i-1][j-1]*(1-p[j]);
        }
        if(i==1+N/2){
            printf("%.10lf\n",dp[1+N/2][N]);
            return 0;
        }
        //cout<<ans<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 35584
# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())
k = int(raw_input())

c = (list(s))[k-1]

def sub(x):
    global c
    if x != c:
        return "*"
    else:
        return x

ans = "".join(map(sub, s.strip()))

print ans

Measured memory_bytes: 2568
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int k, s;
    cin >> k >> s;

    int ans = 0;
    for (int x = 0; x <= k; ++x) for (int y = 0; y <= k; ++y) {
        int z = s - x - y;
        if (0 <= z && z <= k) ans++;
    }

    cout << ans << '\n';

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n;
int a[maxn];

int main(){
    migmig
    cin >> n;
    int cnt = 1;
    for (int i = 1 ; i <= n ; i ++){
        cin >> a[i];
        if(a[i] == cnt){
            cnt++;
        }
    }
    if(cnt == 1){
        dokme(-1);
    }
    cout << n - cnt + 1;
    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    
    char buf[16];
    scanf("%16s",buf);
    
    if(buf[strlen(buf)-1] == '2' || buf[strlen(buf)-1] == '4' || buf[strlen(buf)-1] == '5' || buf[strlen(buf)-1] == '7' || buf[strlen(buf)-1] == '9')
        printf("hon\n");
    else if(buf[strlen(buf)-1] == '0' || buf[strlen(buf)-1] == '1' || buf[strlen(buf)-1] == '6' || buf[strlen(buf)-1] == '8')
        printf("pon\n");
    else if(buf[strlen(buf)-1] == '3')
        printf("bon\n");

    return 0;
}

Measured memory_bytes: 2088
import           Data.List

main :: IO ()
main = do
    _      <- fmap read getLine :: IO Int
    [t, a] <- fmap (map read . words) getLine :: IO [Double]
    hs     <- fmap (map read . words) getLine :: IO [Double]
    print $ solve t a hs

solve :: Double -> Double -> [Double] -> Int
solve t a hs = minindex ds where ds = map (\h -> abs $ t - a - h * 0.006) hs

minindex :: Ord a => [a] -> Int
minindex ls = fst . head $ sortOn snd $ zip [1 ..] ls


Measured memory_bytes: 1276
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
int main() {
    cout.precision(15);
    cout << fixed;
    ll X;
    cin >> X;
    ll rot=1;
    while(rot*360 % X !=0)++rot;
    cout<<(rot)*360/X<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
using namespace std;

int main() {
	int n, k, a, b[200000] = {};
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		b[a - 1]++;
	}
	sort(b, b + n, greater<int>());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += b[i];
	}
	cout << n - ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
    ll a,b,k;
    cin>>a>>b>>k;
    ll use=min(k,a);
    a-=use;
    k-=use;
    b-=min(b,k);
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M;
vector<int>G[500];
main()
{
	cin>>N>>M;
	UF uf(N);
	int ans=N;
	for(int i=0;i<M;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
		ans-=uf.unite(u,v);
	}
	for(int i=0;i<N;i++)ans+=G[i].size()-1;
	cout<<ans<<endl;
}



Measured memory_bytes: 3200
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int mx=-10000000;
        int mi=10000000;
        long sum=0;
        for(int i=0;i<N;i++){
            int a=sc.nextInt();
            sum+=a;
            if(mx<a){mx=a;}
            if(mi>a){mi=a;}
        }
        System.out.printf("%d %d %d\n",mi,mx,sum);
    }     
}


Measured memory_bytes: 41336
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int ans=0;
    string s;
    cin>>s;
    int a1[20]={},a2[20]={};
    long long d[20][20][20]={};
    for(int i=0;i<n-2;i++){
        if(a1[s.at(i)-'0']==0){
            a1[s.at(i)-'0']++;
            for(int j=i+1;j<n-1;j++){
                if(a2[s.at(j)-'0']==0){
                    a2[s.at(j)-'0']++;
                    for(int k=j+1;k<n;k++){
                        d[s.at(i)-'0'][s.at(j)-'0'][s.at(k)-'0']++;
                    }
                }
            }
        }
        for(int z=0;z<10;z++){
                a2[z]=0;
            }
        
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                if(d[i][j][k]>0) ans++;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 384
function Main(input) {
    var N = parseInt(input[0], 10);
    var W = input.slice(1).map(w => parseInt(w, 10));

    var result = 0;
    var smallSum = 0;
    var bigSum = 0;
    var diff = 0;

    for (var i = 0; i < W.length; i++) {
        smallSum = 0;
        bigSum = 0;
        for (var j = 0; j < W.length; j++) {
            if (i >= j) {
                smallSum += W[j];
            } else {
                bigSum += W[j];
            }
        }
        diff = Math.abs(smallSum - bigSum);
        if (i === 0) {
            result = diff;
        } else {
            result = result > diff ? diff : result;
        }
    }

    console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

int main()
{
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	int dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(j==0)
			{
				dp[i][j]=a[i][j]+max(dp[i-1][j+1],dp[i-1][j+2]);
			}
			else if(j==1)
			{
				dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j+1]);
			}
			else{
				dp[i][j]=a[i][j]+max(dp[i-1][j-1],dp[i-1][j-2]);
			}
		}
	}
	int ans=dp[n-1][0];
	for(int i=1;i<3;i++)
		ans=max(ans,dp[n-1][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n,m;

int solve(){
    int d = sqrt(m + 0.5);
    int ans = 0;
    for (int i = d; i >= 1; i--){
        if (m%i == 0) {
            if(i>=n)ans = max(ans,m/i);
            if(m/i>=n)ans = max(ans, i);
        }
    }
    return ans;
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>m;
    
    cout<<solve()<<endl;
    
    
    
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;
const long long MOD = 1000000007;

long long dat[2 * MAX_N - 1];

ll fact(ll n) {
	if (n == 1) return 1;
	return n * fact(n - 1);
}

ll gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

int main(void) {
	ll h, w,n;
	cin >> h >> w >> n;
	ll m = max(h, w);
	if (n % m == 0) cout << n / m << endl;
	else cout << n / m + 1 << endl;
}

Measured memory_bytes: 764
import java.util.Scanner;
class Main
{
	static int counter = 0;
	static void shell( int A[] )
	{
		int G[] = {0,1,4,13,40,121,364,1093,3280,9841,29524,88573,265720,797161,1000001}, i;
		for( i = 1 ; G[i] <= A.length ; i++ );
		
		System.out.println(--i);
		for(  ; 1 <= i ; i-- )
		{
			insertion( A, G[i] );
			if( i==1 )
				System.out.println(G[i]);
			else
				System.out.print(G[i]+" ");
		}
		System.out.println(counter);
	}
	static void insertion( int A[], int g )
	{
		int j;
		for( int i = g ; i < A.length ; i++ )
		{
			int v = A[i];
			for( j = i-g ; 0<=j && v<A[j] ; j-=g )
			{
				counter++;
				A[j+g] = A[j];
			}
			A[j+g] = v;
		}
	}
	public static void main( String[] args )
	{
		Scanner sc = new Scanner( System.in );
		
		int n = sc.nextInt();
		int A[] = new int[n];
		for( int i = 0 ; i < n ; i++ )
			A[i] = sc.nextInt();
		shell( A );
		for( int i = 0 ; i < n ; i++ )
			System.out.println( A[i] );
	}
}

Measured memory_bytes: 298612
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct Seg {
    bool fav;
    int height;
    Seg() { 
	fav = false;
	height = -1;
    }
    Seg inc(bool fav_) const {
	Seg z = *this;
	z.fav = z.fav || fav_;
	z.height++;
	return z;
    }
};
Seg operator+(const Seg &x, const Seg &y) {
    Seg z;
    z.fav = x.fav || y.fav;
    z.height = max(x.height, y.height);
    return z;
}

const int MAXN = 200111;
int N;
VI G[MAXN];
VI ord;
char S[MAXN];
Seg up[MAXN], dw[MAXN];
vector<Seg> L[MAXN], R[MAXN];

LL answer;

void treeDP() {
    ord.clear(); ord.reserve(N);
    ord.push_back(0);
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) {
	    ord.push_back(*e);
	    G[*e].erase(remove(G[*e].begin(), G[*e].end(), v), G[*e].end()); // remove parent
	}
    }

    REP (i_, N) {
	int v = ord[N-1-i_];
	int m = G[v].size();
	L[v].assign(m+1, Seg());
	R[v].assign(m+1, Seg());
	REP (i, m)
	    L[v][i+1] = L[v][i] + up[G[v][i]];
	for (int i=m; i--; )
	    R[v][i] = up[G[v][i]] + R[v][i+1];
	up[v] = R[v][0].inc(S[v] == '1'); // up[v] = L[v].all + v own
    }

    const int INF = 1<<29;

    dw[0] = Seg();
    REP (i_, N) {
	int v = ord[i_];
	//ans[v] = (R[v][0] + dw[v]).inc(S[v] == '1'); // when v == 0, dw[v] is an empty tree

	int lo = INF, hi[3] = { };
	auto update = [&](int h) {
	    hi[2] = h;
	    if (hi[1] < hi[2]) swap(hi[1], hi[2]);
	    if (hi[0] < hi[1]) swap(hi[0], hi[1]);
	};

	if (S[v] == '1') {
	    amin(lo, 0);
	}

	if (v) {
	    if (dw[v].fav) amin(lo, dw[v].height+1);
	    update(dw[v].height+1);

	    // dw[v] * up[v];
	    if (dw[v].height <= up[v].height && dw[v].fav) {
		answer++;
	    } else if (dw[v].height >= up[v].height && up[v].fav) {
		answer++;
	    }
	}

	REP (i, G[v].size()) {
	    int w = G[v][i];
	    if (up[w].fav) amin(lo, up[w].height+1);
	    update(up[w].height+1);
	}

	if (lo <= hi[1]) {
	    answer += hi[1] - lo + 1;
	}

	REP (i, G[v].size()) {
	    int w = G[v][i];
	    dw[w] = (R[v][i+1] + dw[v] + L[v][i]).inc(S[v] == '1'); // add v own
	}
    }
}



void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }
    scanf("%s", S);
    treeDP();

    printf("%lld\n", answer);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 41076
#include<iostream>
#include<queue>
#include<map>
using namespace std ;

int N ;
int p[2][110] ;

int func(){
	int t[2][110] = {} ;
	queue<int> q1,q2,q3 ;
	
	q1.push(0) ; q2.push(0) ; q3.push(0) ;
	q1.push(1) ; q2.push(0) ; q3.push(0) ;
	
	while( q1.size() ){
		int x   = q1.front() ;
		int pos = q2.front() ;
		int cnt = q3.front() ;
		q1.pop() ; q2.pop() ; q3.pop() ;
		
		if( p[x][pos] == 1 ){
			while( pos < N && p[x][pos] == 1 ) pos++ ;
			pos-- ;
		}
		else if( p[x][pos] == 2 ){
			while( pos > 0 && p[x][pos] == 2 ) pos-- ;
		}
		
		if( t[x][pos] ) continue ;
		t[x][pos] = 1 ;
		
		if( pos == N-1 ) return cnt ;
		
		x = (x+1) % 2 ;
		for( int i=0 ; i<=2 ; i++ ){
			if( N > pos + i ){
				q1.push( x ) ;
				q2.push( pos + i ) ;
				q3.push( cnt + 1 ) ;
			}
		}
	}
	return -1 ;
}

int main(){
	
	while( cin >> N , N ){
		for( int i=0 ; i<N ; i++ ) cin >> p[0][i] ;
		for( int i=0 ; i<N ; i++ ) cin >> p[1][i] ;
		
		int ans = func() ;
		
		if( ans >= 0 ) cout << ans << endl ;
		else cout << "NA" << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    int ans = 0;
    for(int i=0; i<4; i++) {
        if(S[i] == '+') {
            ans ++;
        } else {
            ans --;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 384