akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N); i >= (n+1); i--)
#define p(s) cout<<(s)<< endl
#define p2(a, b) cout<<(a) << " " << (b) << endl
using namespace std;
typedef long long ll;

bool isPrime[1000010];
ll field[1010][1010];
ll dy[4] = {0, -1, 0, 1};
ll dx[4] = {1, 0, -1, 0};
vector<ll> edge[1000010];
const int MAX_SIZE=1000000;
pair<ll, ll> memo[1000010]; // takara, last_num
void hurui(ll n){
	isPrime[0] = isPrime[1] = false;
	for(ll i = 2; i < n + 1; i++) isPrime[i] = true;
	for(ll i = 2; i*i<= n; i++){
		for(ll j=i*2; j<n+1; j += i){
			isPrime[j] = false;
		}
	}
}

void make_cave(){
	ll ny = 500;
	ll nx = 499;
	ll step = 1;
	ll dir = 0;
	ll i = 1;
	while(1){
		ll next_y = ny + dy[dir]*step;
		ll next_x = nx + dx[dir]*step;
		if(next_y == ny){
			if(next_x > nx){
				REP(x, nx, next_x){
					field[ny][x] = i;
					i++;
					if(i>MAX_SIZE) return;
				}
			}else{
				RREP(x, next_x, nx){
					field[ny][x] = i;
					i++;
					if(i>MAX_SIZE) return;
				}
			}
			nx = next_x;
		}
		else{
			if(next_y > ny){
				REP(y, ny, next_y){
					field[y][nx] = i;
					i++;
					if(i>MAX_SIZE) return;
				}
			}else{
				RREP(y, next_y, ny){
					field[y][nx] = i;
					i++;
					if(i>MAX_SIZE) return;
				}
			}

			ny = next_y;
		}

		dir = (dir+1)%4;
		if(dir%2==0){
			step++;
		}
	}
}
ll m, n;
pair<ll, ll> dfs(ll cur_num){
	if(memo[cur_num].second != 0) return memo[cur_num];
	ll cnt = 0;
	ll last_num = 0;
	if(isPrime[cur_num]){
		cnt = 1;
		last_num = cur_num;
	}
	pair<ll, ll> ret = {0, 0};
	for(ll next_num: edge[cur_num]){
		if(next_num > m) continue;
		pair<ll, ll> next_memo = dfs(next_num);
		if(next_memo.first > ret.first){
			ret = next_memo;
		}else if(next_memo.first == ret.first && next_memo.second > ret.second){
			ret = next_memo;
		}
	}
	if(ret.second == 0){
		ret = {cnt, last_num};
	}else{
		ret.first+=cnt;
	}
	return memo[cur_num] = ret;
};
int main() {
	hurui(MAX_SIZE);
	make_cave();
	REP(y, 0, 1000-1){
		REP(x, 0, 1000){
			ll now = field[y][x];
			REP(xx,max(0LL, x-1), min(x+2,1000LL)){
				edge[now].push_back(field[y+1][xx]);
			}
		}
	}
	while(cin >> m >> n && m){
		REP(i,0,1000005){
			memo[i] = {0, 0};
		}
		pair<ll, ll> ans = dfs(n);
		p2(ans.first, ans.second);
	}

	return 0;
}


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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m; assert(b>=0); for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, a[1010], b[1010], c[1010], res;

signed main() {
	cin >> n >> m;
	rep(i,n) cin >> a[i] >> b[i] >> c[i];
	rep(q,2) rep(w,2) rep(e,2) {
		pii x[1010], y[1010], z[1010], s[1010] = {};
		rep(i,n) {
			x[i] = {a[i] * (q==0 ? 1 : -1), i};
			y[i] = {b[i] * (w==0 ? 1 : -1), i};
			z[i] = {c[i] * (e==0 ? 1 : -1), i};
			s[i] = {x[i].fi + y[i].fi + z[i].fi, i};
		}
		sort(s,s+n);
		reverse(s,s+n);
		int t[3] = {};
		rep(i,m) t[0] += a[s[i].se], t[1] += b[s[i].se], t[2] += c[s[i].se];
		chmax(res, abs(t[0]) + abs(t[1]) + abs(t[2]));
	}
	cout << res << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() {
    lli n;
    cin>>n;
    vector<pair<lli,lli>>points(n);
    for(lli i=0;i<n;i++)
    cin>>points[i].first>>points[i].second;
    vector<lli>pehla,dusra;
    for(auto i:points)
    {
        pehla.push_back(i.first-i.second);
        dusra.push_back(i.first+i.second);
    }
    sort(pehla.begin(),pehla.end());
    sort(dusra.begin(),dusra.end());
    cout<<max(abs(pehla[0]-pehla[n-1]),abs(dusra[0]-dusra[n-1]));
	return 0;
}

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

int main(void){
  int x,y;
  
  cin >> x >> y;
 
  /*if( (y % 2) != 0){
    cout << "NO";
    return 0;
  }*/
  
  for(int i = 0; i <= x;i++){
    int expection = 0;
    expection += 4 * (x- i);
    expection += 2 * i;
    
    if(expection == y){
     //cout << i << endl;
     cout << "Yes";
     return 0;
    }
  }
  
  cout << "No";
  return 0;
    }

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

int main(){
  ll n,m;
  cin >> n >> m;
  
  if(min(n,m)==1){
    cout << max((ll)1,m) << endl;
    return 0;
  }
  
  ll i,j;
  vector<ll> p(60,1);
  i=2;
  j=0;
  while(m>=i*i){
    if(m%i==0){
      p.at(j)=i;
      m=m/i;
      j++;
    }else{
      i++;
    }
  }
  p.at(j)=m;
  
  ll ans=1,c=0,k;
  for(i=0;i<=j+1;i++){
   /* if(i!=0){
      cout << p.at(i-1) << endl;
    }*/
    if(i!=j+1&&(i==0||p.at(i)==p.at(i-1))){
      c++;
    }else{
      for(k=0;k<c/n;k++){
        ans *= p.at(i-1);
      }
      //cout << '<' << c << '>' << endl;
      c=1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
//const ll mod=1e9+7;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////
ll modpow(ll a,ll b){
  ll r=1;
  while(b>0){
    if(b%2==1)(r*=a)%=mod;
    (a*=a)%=mod;
    b/=2;
  }
  return r;
}

int main(){
    
    int n;
    cin>>n;
    vector<ll> d(n);
    int mx=0;
    rep(i,n){
        int a;
        cin>>a;
        if(i==0&&a!=0){
            cout<<0<<endl;
            return 0;
        }
        d[a]++;
        chmax(mx,a);
    }
    if(d[0]>1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    
    for(int i=mx-1;i>=0;i--){
        if(d[i]==0){
            cout<<0<<endl;
            return 0;
        }
        ans*=modpow(d[i],d[i+1]);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
function main(lines) {
    const input = lines.split('\n')
    const array = input[1].split(' ').map(function(val){return parseInt(val,10)})
    const min = array.reduce(function(a,b){return Math.min(a,b)})
    const max = array.reduce(function(a,b){return Math.max(a,b)})
    const sum = array.reduce(function(a,b){return a+b})

    console.log(min + ' ' + max + ' ' + sum)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 18184
#include <bits/stdc++.h>
using namespace std;
#define MOD1 1000000007
#define MOD2 1000000009
#define ll long long int
#define li long int
#define fi first
#define se second
#define ffl fflush(stdout);
#define all(x) (x).begin,(x).end()
#define whT int t; cin>>t; while(t--)
typedef pair<long long, long long> pi;
int main() 
{
	#ifndef ONLINE_JUDGE
	freopen("G:/coding/CPP/input.txt", "r", stdin);
	freopen("G:/coding/CPP/output.txt", "w", stdout);
	#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	string s,t;
	cin>>s>>t;
	int count = 0 ;
	for(int i=0;i<s.length();i++) {
		if(s[i]!=t[i]) count++;
	}
	cout<<count<<endl;
	

}


Measured memory_bytes: 3776
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        xys: [(usize, usize); m],
    }
    let mut v = vec![(false, 1); n];
    v[0] = (true, 1);
    for (x, y) in xys {
        v[x - 1].1 -= 1;
        v[y - 1].1 += 1;
        if v[x - 1].0 {
            v[y - 1].0 = true;
        }
        if v[x - 1].1 == 0 {
            v[x - 1].0 = false;
        }
    }
    let ans = v.iter().filter(|x| x.0 && x.1 > 0).count();
    println!("{}", ans);
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int > pii;
typedef pair<int, pii> edge;
const int maxn = 307;

ll dp[maxn][maxn];
ll G[maxn][maxn];
bool ok[maxn][maxn];
int f[maxn];

int gf(int x) {
    return f[x] == x? x :f[x] = gf(f[x]);
}

void GG(int n) {
    for(int k = 0 ; k < n ; k++) {
        for(int i = 0 ; i < n ; i++) {
            for(int j = 0 ; j < n ; j++) {
                if(G[i][k] != 0 && G[k][j] != 0 && i!= j) {
                    G[i][j] = min(G[i][j], G[i][k]+G[k][j]);

                }
            }
        }
    }
}

int main() {
    int n;
    while(cin>>n) {
        for(int i = 0 ; i < n ; i++) {
            f[i] = i;
            for(int j = 0 ; j < n ; j++) {
                scanf("%d",&dp[i][j]);
                G[i][j] = dp[i][j];
            }
        }
        for(int k = 0 ; k < n ; k++) {
            for(int i = 0 ; i < n ; i++) {
                for(int j = 0 ; j < n ; j++) {
                    if(G[i][k] != 0 && G[k][j] != 0 && i!= j) {
                        G[i][j] = min(G[i][j], G[i][k]+G[k][j]);

                    }
                }
            }
        }
        int flag = 1;
        vector<edge> vec;
//        for(int i = 0 ; i < n ; i++){
//            for(int j = 0 ; j < n ; j++){
//                cout<<G[i][j]<<" ";
//            }
//            cout<<endl;
//        }
        ll ans = 0;
        for(int i = 0 ; i < n && flag ; i++) {
            for(int j = 0 ; j < n && flag; j++) {

                if(G[i][j] != dp[i][j]) {
                    flag = 0;
                }
                ans += G[i][j];
//                vec.push_back(edge(G[i][j], pii(i, j)));
//                G[i][j] = 0;
            }

        }
        if(flag == 0) {
            cout<<-1<<endl;
        } else {
            ans/=2;
            ll sum = 0;
            for(int k = 0 ; k < n ; k++) {
                for(int i = 0 ; i < n ; i++) {
                    for(int j = 0 ; j < n ; j++) {
                        if(dp[i][j] == dp[i][k] + dp[k][j] && i != j &&(k!= i && k !=j) && ok[i][j] == 0) {
                            ok[i][j] = 1;
                            sum += dp[i][j];
                            //cout<<dp[i][j]<<" "<<dp[i][k]<<" "<<dp[k][j]<<endl;
                        }
                    }
                }
            }
            cout<<ans - sum/2<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148
using namespace std;
void deviation(double a[],double n);
double a[10000];
int sum=0;
double b[40];//??????????????°???
int main()
{
	double n;
    
	while(cin>>n)
	{
		memset(a,0,10000*sizeof(double));
		
		if(n==0)
			break;
		sum++;
		for(int i=0;i<n;i++)
			cin>>a[i];
		deviation(a,n);
		
	
	
	}
	




	for(int i=1;i<=sum;i++)
	{
		cout<<setiosflags(ios::fixed)<<setprecision(8);
	cout<<b[i]<<endl;
	}

}




	


	








void deviation(double a[],double n)
{
	double q=0,p;
	double i=0;
	for(int j=0;j<n;j++)
		
			q+=a[j];
	
	p=q/n;
	
		for(int j=0;j<n;j++)
		{
			double k=a[j]-p;//???????????????
			i=i+k*k;
		}
		
		b[sum]=sqrt(i/n);







}

Measured memory_bytes: 3356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int X = scan.nextInt();
		int T = scan.nextInt();

		int ans = 0;
		if(X > N || X == N) {
			ans = T;
		}else {
			int ks = 1; //たこ焼き焼く回数
			int nokori = N - X;
			int i = 0;
			while(nokori > 0) {
				ks = ks + 1;
				nokori = nokori - X;
				i++;
			}

			ans = T * ks;
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 35584
#include<bits/stdc++.h> 
using namespace std;
int main(){
  int N,sum=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    string X=to_string(i);
    if(X.size()%2==1)
      sum++;
    }
  cout<<sum<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int lld;
	bool mycomp(pair<lld,lld>&a,pair<lld,lld>&b)
	{
		if(a.first==b.first)
			return a.second<b.second;
		else
			return a.first<b.first;
	}
	int main()
	{
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    lld n,q,i,x,y,j,p=0,l,k=0,k1;
	    cin>>n>>k1;lld a[n];
	    set<lld>s;
	    for(i=0;i<n;i++)
	    	{
	    		cin>>a[i];
	    		s.insert(a[i]);
	    	}
	    lld b[200000]={0};
        for(i=0;i<n;i++)
        {
        	b[a[i]]++;
        }
        lld c[s.size()];
        sort(b,b+200000);
        k=0;p=0;
        for(i=0;i<200000;i++)  
        { 
        	if(b[i]>0)
        	{
              k=k+b[i];
              c[p]=k;
              p++;
            }
        } 
        //cout<<s.size()-k-1;
        if(s.size()<=k1)
        	cout<<0;
        else
        	cout<<c[s.size()-k1-1];
	 }

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

int main() 
{
    FAST;
    ll a,b,h,m;
    cin>>a>>b>>h>>m;
    ll t=(60*h)+m;
    double dh=t/2.0,dm=t*6,fd=fabs(dh-dm);
    //cout<<dh<<' '<<dm<<' '<<fd<<'\n';
    long double ans=(a*a)+(b*b)-(2*a*b*cos(fd*PI/180.0));
    ans=sqrt(ans);
    cout<<fixed<<setprecision(22)<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 4296
#include<stdio.h>

void trace(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int j,i,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];
  
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  trace(A,N);
  insertionSort(A,N);

  return 0;
}

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

int N, K, A[109];

bool dp[100009];

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

    for(int i = 0; i <= K; i++)
        for(int j = 0; j < N; j++)
            if(i >= A[j]) dp[i] |= !dp[i - A[j]];

    cout << (dp[K] ? "First" : "Second") << endl;

    return 0;
}

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


int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;++i) {
		int t=i,c=0;
		while(t) t/=10,c++;
		ans+=(c%2);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm> // sort
#include <iomanip>
#include <queue>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
typedef pair<int,int> pint;

using namespace std;

const int MOD = 1000000007;


//dp[j][k][s]: k枚選んで sにする選び方の総数

int main(){

    ll a,b,c,x;
    ll res = 0;
    cin >> a >> b >> c >> x;

    REP(i,a+1)
    {
        REP(j,b+1)
        {
            if(500*i + 100*j > x)break;
            if(x - 500*i - 100*j <= 50*c)++res;
        }
    }
    cout << res << endl;

    return 0;     
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  char str[11],year[5],month[3],day[3];
  cin >> str;
  for(int i=0;i<5;i++){
    year[i] = str[i];
  }
  for(int i=0;i<3;i++){
    month[i] = str[i+5];
    day[i] = str[i+7];
  }
  
  int yyyy = atoi(year);
  int mm = atoi(month);
  int dd = atoi(day);
  
  if(yyyy ==2019){
    if(mm == 4){
      if(dd <= 30){
        cout <<"Heisei" <<endl;
      }else{
        cout <<"TBD" <<endl;
      }
    }else if(mm < 4){
      cout <<"Heisei" <<endl;
    }else{
      cout <<"TBD" <<endl;
    }
    
  }else if(yyyy <2019){
  	cout <<"Heisei" <<endl;  
  }else{
    cout <<"TBD" <<endl;
  }
}
  
  
  

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$data = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($data);
$half = $sum/2;

$left = 0;
foreach($data as $value){
    $left+= $value;
    if($left == $half) {
        echo 0;
        exit;
    }elseif($left > $half){
            $right = ($sum - $left);
            $ans1 = $left - $right;
            $last = $left - $value;
            $lastright = $sum-$last;
            $ans2 = $lastright - $last;
            $ans = min($ans1, $ans2);
            echo $ans;
            exit;

    }

}

Measured memory_bytes: 23200
while True:
    m, f, r = list(map(int, input().split()))
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65 and m+f < 80:
        print('B')
    elif m + f >= 50 and m + f < 65:
        print('C')
    elif m + f >= 30 and m + f < 50 and r >= 50:
        print('C')
    elif m + f >= 30 and m + f < 50:
        print('D')
    elif m + f < 30:
        print('F')


Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;




int main()
{
	int a, b,num;
	vint high(999);
	high[0] = 0;
	cin >> a >> b;
	for (int i = 1; i < 1000; i++){
		high[i] = high[i - 1] + i;
	}
	num=b - a;
	cout << high[num] - b << endl;
	
	
	
}






Measured memory_bytes: 256
#include <stdio.h>
#define NUM 51

void cut(int n, int p, int c, int cards[]) {
    int array[NUM];
    int i, j;
    for(i = p - 1, j = 0; i < p + c - 1; i++, j++ ) {
        array[j] = cards[i];
        cards[i] = 0;
    }
    for(i = 0; i < n; i++ ) {
        if(cards[i]) {
            array[j] = cards[i];
            j++;
        }
    }
    for(i = 0; i < n; i++ ) {
        cards[i] = array[i];

    }
}


int main(void) {
    int i, j, n, r, p, c;
    int cards[NUM];
    scanf("%d %d",&n,&r);
    while(n){
        for(i = 0; i < n; i++ ) {
            cards[i] = n - i;

        }
        for(i = 0; i < r; i++ ) {
            scanf("%d %d",&p,&c);
            cut(n,p,c,cards);
        }
        printf("%d\n",cards[0]);
        scanf("%d %d",&n,&r);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define end "\n"
#define endl "\n"
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


int main() {
    io;
    string s;
    cin>>s;
    int count = 0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='x'){
            count++;
        }
    }
    if (count>7){
        cout<<"NO"<<endl;
    }
    else
    cout<<"YES";

    return 0;
}


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

int main() {
  int N, next = 1;
  cin >> N;
  vector<int> btn(N);

  loop(i, N) cin >> btn.at(i);

  loop(i, N) {
    next = btn.at(next - 1);
    if (next == 2) {
      cout << (i + 1) << endl;
      break;
    }
    if (i == N - 1) {
      cout << "-1" << endl;
      break;
    }
  }
}


Measured memory_bytes: 640
from operator import itemgetter
N,M = [int(x) for x in input().split()]
P = [0]*M
Y = [0]*M
pref = [[] for _ in range(N)]
city = [0]*M
for i in range(M):
    P[i],Y[i] = [int(x) for x in input().split()]
    pref[P[i]-1].append([i,Y[i]])
for index,i in enumerate(pref):
    pref[index].sort(key=itemgetter(1))
for index,i in enumerate(pref):
    for index2,j in enumerate(i):
        city[j[0]]='{:0=6}'.format(index+1)+'{:0=6}'.format(index2+1)
for i in city:
    print(i)

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)
#define mx 1e17
/*  #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/


ll modpow(ll a,ll b){
 ll res=1;
 while(b>0)
{
    if(b&1)res=(res*a)%mod;
    b=b>>1;
    a=(a*a)%mod;

}
return res;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
ll h,a;
cin>>h>>a;
int co=0;
if(h%a!=0)co++;
cout<<(h/a)+co;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	int ans=0;
	scan(S);
	rep(i,6) if(S[i]=='1') ans++;
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>

int main(void) {
  double x1 = 0;
  double y1 = 0;
  double x2 = 0;
  double y2 = 0;
  
  std::cin >> x1 >> y1 >> x2 >> y2;
  
  double r = std::sqrt(std::pow(x2 - x1, 2.0) + std::pow(y2 - y1, 2.0));

  printf("%.8f\n", r);

  return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define pi 3.1415926535897932384626433832795

int main(){

 long long int N;
  scanf("%lld",&N);

/*
  char A[];
  scanf("%s",A);
  */

  /*
  int A[N];
  int i;
  for(i=0;i<N;i++){
   scanf("%d",&A[i]);
   }
  */
printf("%lf",(double)(N)*2.0*pi);







 return(0);
 }


Measured memory_bytes: 1748
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int[] dy = { -1, -1, -1, 0, 0, 1, 1, 1 };
		int[] dx = { -1, 0, 1, -1, 1, -1, 0, 1 };
		char[][] map = new char[8][8];
		for (int i = 0; i < 8; i++)
			map[i] = scanner.next().toCharArray();
		char my, en;
		int u = 0;
		int flag = 0;
		while (true) {
			if (u == 0) {
				my = 'o';
				en = 'x';
			} else {
				my = 'x';
				en = 'o';
			}
			int cnt = 0, ey = 0, ex = 0, dir = 0;
			for (int y = 0; y < 8; y++)
				for (int x = 0; x < 8; x++) {
					int hy = u == 0 ? y : 7 - y;
					int hx = u == 0 ? x : 7 - x;
					if (map[hy][hx] != '.')
						continue;
					int cc = 0, ndir = 0;
					for (int i = 0; i < 8; i++) {
						int c = 0;
						while (true) {
							int ny = hy + dy[i] * (c + 1);
							int nx = hx + dx[i] * (c + 1);
							if (!isOK(ny, nx))
								break;
							if (map[ny][nx] == en) {
								c++;
								continue;
							} else if (map[ny][nx] == my && c != 0) {
								cc += c;
								ndir |= (1 << i);
							}
							break;
						}
					}
					if (cnt >= cc)
						continue;
					cnt = cc;
					ey = hy;
					ex = hx;
					dir = ndir;
				}
			u = 1 - u;
			if (cnt == 0) {
				flag++;
				if (flag == 2)
					break;
			} else {
				flag = 0;
				map[ey][ex] = my;
				for (int i = 0; i < 8; i++) {
					if (((dir >> i) & 1) == 0)
						continue;
					int k = 1;
					while (true) {
						int ny = ey + dy[i] * k;
						int nx = ex + dx[i] * k;
						if (map[ny][nx] == my)
							break;
						map[ny][nx] = my;
						k++;
					}
				}
			}

		}
		for (char[] ans : map)
			System.out.println(ans);

	}

	private boolean isOK(int ny, int nx) {
		return 0 <= ny && ny < 8 && 0 <= nx && nx < 8;
	}
}

Measured memory_bytes: 18064
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;

//セグ木
ll dat[2560000], sz;

void init(ll n) {
	sz = 1;
	while (sz < n)sz *= 2;
	REP(i, sz * 2 - 1) dat[i] = 0;
}

void update(ll k, ll a) { //場所(0-indexed), 値
	k += sz - 1;
	dat[k] = a;
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] =dat[k * 2 + 1] + dat[k * 2 + 2]; //更新
	}
}

ll query(ll a, ll b, ll k, ll l, ll r) { //[a, b) 呼ぶとき (a, b, 0, 0, sz)
	if (r <= a or b <= l)return 0;
	if (a <= l and r <= b)return dat[k];
	ll v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
	ll v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return v1 + v2; //戻り値
}

ll ans = INF;
int main() {
	cin >> n;
	vector<ll> x(n), y(n);
	REP(i, n)cin >> x[i];
	REP(i, n)cin >> y[i];
	REP(i, 1ll << n) {
		ll c1 = 0, c2 = 0;
		bool ok = true;
		REP(j, n) {
			if (i & (1ll << j)) {
				if (j % 2 == 0)c1++;
				else c2++;
			}
		}
		if (c1 != c2)continue;
		vector<P> a, b, c;
		REP(j, n) {
			if ((i & (1ll << j))) {
				if (j % 2 == 0) b.push_back(P(y[j], j));
				else a.push_back(P(y[j], j));
			}
			else {
				if (j % 2 == 0) a.push_back(P(x[j], j));
				else b.push_back(P(x[j], j));
			}
		}
		sort(ALL(a));
		sort(ALL(b));
		REP(j, n) {
			if (j % 2 == 0)c.push_back(a[j / 2]);
			else c.push_back(b[j / 2]);
		}
		REP(j, n - 1) {
			if (c[j].first > c[j + 1].first)ok = false;
		}
		if (!ok)continue;
		init(60);
		ll now = 0;
		REP(j, n) {
			now += query(c[j].second, 60, 0, 0, sz);
			update(c[j].second, 1);
		}
		ans = min(ans, now);
	}
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  for(int i = 0; i < m; i++){
  	cin >> l.at(i) >> r.at(i);
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  if(r.at(0) - l.at(m-1) >= 0)
    cout << r.at(0) - l.at(m-1) + 1 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
#define ll long long
#define endl '\n'
using namespace std;

int main()
{
    double d,t,s;
    cin>>d>>t>>s;

    double x=d/s;


    if(x<=t)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }







    return 0;
}


Measured memory_bytes: 3708
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;
const int MAX_N = 100000;
ll N, M, A[MAX_N];

void solve() {
    long long res = 0;
    ll dp[MAX_N + 1];
    unordered_map<ll, ll> mp;

    for (int i = 0; i < N; ++i) {
        dp[i + 1] = (dp[i] + A[i]) % M;
        mp[dp[i + 1]]++;
    }

    for (auto val: mp) {
        res += val.second * (val.second - 1) / 2;
        if (val.first == 0) {
            res += val.second;
        }
    }

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

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

Measured memory_bytes: 4492
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

ll p, n;
ll x, y, v, u;

void SternBrocot(ll pl = 0, ll ql = 1, ll pr = 1, ll qr = 0) {
    ll pm = pl+pr, qm = ql+qr;
    if (pm > n || qm > n) return;
    if (p*qm*qm < pm*pm) {
        u = pm, v = qm;
        SternBrocot(pl, ql, pm, qm);
    } else if (p*qm*qm > pm*pm) {
        x = pm, y = qm;
        SternBrocot(pm, qm, pr, qr);
    } else {
        x = u = pm;
        y = v = qm;
    }
}

int main() {
    while (cin >> p >> n) {
        if (p == 0 && n == 0) break;
        SternBrocot();
        printf("%lld/%lld %lld/%lld\n", u, v, x, y);
    }
    return 0;
}

Measured memory_bytes: 1136
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int L=A+B;
  int R=C+D;
  if(L<R){
    cout<<"Right"<<endl;
  }else if(L==R){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Left"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int a[3];
	int i;
	rep(i,3)a[i]=in();
	sort(a,3);
	if(a[0]==5&&a[1]==5&&a[2]==7)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
lis = list(map(int,input().split()))
if not (1 in lis):
  print(-1)
  quit()
ans = 0
c = 1
for i in range(n):
  if lis[i] != c:
    ans += 1
  else: 
    c += 1
print(ans)

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

long long N;

int main() {

    scanf("%lld", &N);

    long long lo = 1, hi = 1e7, mid, ans;
    while (lo <= hi) {
        mid = (lo + hi) / 2;

        if (mid * (mid + 1) / 2 >= N) {
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }

    while (N > ans) {
        printf("%lld\n", ans);
        N -= ans;
        ans--;
    }

    if (N) {
        printf("%lld\n", N);
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  int x = 0, y = 0, z = 0;
  rep(i, n) {
    int p;
    cin >> p;
    if (p <= a)
      x++;
    else if (p <= b)
      y++;
    else
      z++;
  }
  cout << min(x, min(y, z)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
void bubbleSort(int* ,int);
int count=0;
int main(){
  int n,a[100],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  bubbleSort(a,n);
  for(i=0;i<n;i++) {
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}
void bubbleSort(int *A, int N){ // N 個の要素を含む 0-オリジンの配列 A
    int flag = 1,j,x; // 逆の隣接要素が存在する
  while (flag){
    flag = 0;
    for(j=N-1;j>=1;j--){
      if(A[j] < A[j-1]){
	x=A[j];
	A[j]=A[j-1];
	A[j-1]=x;
	count++;
	flag=1;
      } 
    }
  }
}



Measured memory_bytes: 2128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	double D, T, S;
	cin >> D >> T >> S;

	if (D / S <= T) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

Measured memory_bytes: 3708
import scala.io.StdIn.readLine
object Main extends App{
    val a = readLine().split(" ").map(_.toInt)
    val (w, h, x, y, r) = (a(0), a(1), a(2), a(3), a(4))
    if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h)
    {
        println("Yes")
    }
    else
    {
        println("No")
    }
}



Measured memory_bytes: 43940
N = int(input())
A = list(map(int, input().split()))
A.sort()
t = max(A)
K = [1]*(t+1)
before = -1
for i in A:
    if K[i] == 1:
        c = 2
        while(True):
            if i*c > t:
                break
            K[i*c] = 0
            c += 1
    if i == before:
        K[i] = 0
    before = i

ans = 0
for i in A:
    ans += K[i]
print(ans)

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

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

    int n;
    cin >> n;
    vector<int> p(n + 1), q(n + 1);
    forx(i, 1, n + 1)
    {
        cin >> p[i];
        q[p[i]] += q[p[i] - 1] + 1;
    }
    int m = 0;
    rep(i, n + 1)
        m = max(m, q[i]);

    cout << n - m << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];

  vector<int> ball(n + 1);
  for (int i = n; i >= 1; i--) {
    //printf("i = %d\n", i);
    int tmp = i;
    int cnt = 0;
    while (tmp + i <= n) {
      cnt += ball[tmp + i];
      
      tmp += i;
    }

    if (a[i] == 0 && cnt % 2 != 0) {
      ball[i] = 1;
    } else if (a[i] == 1 && cnt % 2 != 1) {
      ball[i] = 1;
    }
  }

  ll sum = accumulate(a.begin(), a.end(), 0);
  if (sum == 0) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (ball[i] == 1) {
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;
  for (auto v : ans) cout << v << " ";
  if (ans.size() != 0) cout << endl;
  
  return 0;
}


Measured memory_bytes: 5420
#include <bits/stdc++.h>
using namespace std;
 bool visited[100001];
 long long int p=1000000007;
 vector<long long int> v[100001];
 long long int dp[2][100001];
void dfs(int u){
    visited[u]=true;
    for(int i=0;i<v[u].size();i++){
        if(!visited[v[u][i]]){
            dfs(v[u][i]);
            dp[0][u]=(dp[0][u]%p*(dp[0][v[u][i]]%p+dp[1][v[u][i]]%p)%p)%p;
            dp[1][u]=(dp[1][u]%p*dp[0][v[u][i]]%p)%p;
        }
    }
    //cout<<u<<" "<<dp[0][u]<<" "<<dp[1][u]<<endl;
           if(u==1) dp[0][u]=(dp[0][u]%p+dp[1][u]%p)%p;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
        dp[0][i+1]=1;dp[1][i+1]=1;
      if(i==n-2){dp[0][n]=1;dp[1][n]=1;}
    }
   if(n==1){
       cout<<2;return 0;
   }
    dfs(1);
    cout<<dp[0][1];
}

Measured memory_bytes: 12928
import math

def calc(H, T, a, b):
    cnt = 0
    for h in H:
        if (h -b*T) >= 0:
            cnt += math.ceil((h - b * T) / (a - b))
    if cnt <= T:
        return True
    else:
        return False

tmp = [int(n) for n in input().split()]
a = tmp[1]
b = tmp[2]
H = []

H = sorted([int(input()) for i in range(tmp[0])])[::-1]
minT = 0
maxT = math.ceil(H[0] / b)
T = int((maxT + minT) / 2)

while True:
    T = math.ceil((maxT + minT) / 2)
    if calc(H, T, a, b):
        maxT = T
    else:
        minT = T
    if maxT - minT <= 1:
        break
print(maxT)

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}
template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}
void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  bool d[120][120] = {false};
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      rep(j, x) {
        rep(k, h) {
          d[j][k] = true;
        }
      }
    } else if (a == 2) {
      for (int j = x; j < w; ++j) {
        rep(k, h) {
          d[j][k] = true;
        }
      }
    } else if (a == 3) {
      rep(j, w) {
        rep(k, y) {
          d[j][k] = true;
        }
      }
    } else if (a == 4) {
      rep(j, w) {
        for (int k = y; k < h; ++k) {
          d[j][k] = true;
        }
      }
    }
  }

  int c = 0;
  rep(i, w) {
    rep(j, h) {
      if (!d[i][j]) {
        c++;
      }
    }
  }
  p(c);
}

Measured memory_bytes: 256
#include <iostream>
#define MAX 1000001
using namespace std;

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

  int a[MAX];
  int i=0;
  int flag = 0;
  while(!flag){
    if(i == 0) a[i] = s;
    else{
      if(a[i-1] % 2){
        a[i] = 3*a[i-1]+1;
      }
      else{
        a[i] = a[i-1]/2;
      }
    }
    for(int j = 0;j < i;j++){
      if(a[j]==a[i]){
        flag=1;
        break;
      }
    }
    i++;
  }

  cout << i << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << (a + b + c == 17 ? "YES" : "NO") << "\n";

	return 0;
}

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

void solve(int TestCase) {
    long long n, m, x;
    cin >> n >> m >> x;

    auto A = vector<long long>(n);
    for(auto& x : A)
        cin >> x;
    auto B = vector<long long>(m);
    for(auto& x : B)
        cin >> x;
    
    auto AA = vector<long long>(A.size() + 1);
    for(auto i = 1; i < AA.size(); ++i)
        AA[i] = AA[i-1] + A[i-1];
    auto BB = vector<long long>(B.size() + 1);
    for(auto i = 1; i < BB.size(); ++i)
        BB[i] = BB[i-1] + B[i-1];
    
    long long ret = 0;
    for(auto i = 0; i <= n; ++i) {
        if(AA[i] > x) break;
        int p = upper_bound(BB.begin(), BB.end(), x - AA[i]) - BB.begin();
        ret = max(ret, (long long)i + p - 1);
    }
    cout << ret << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}

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

const int maxn = 2e6 + 10;
int cnt[maxn];

inline void Init(int a, int b) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= a; ++ i) {
        cnt[i % b] ++;
    }
}

inline void work(int a, int b) {
    Init(a,b);
    long long ans = 0;
    ans = 1ll * cnt[0] * cnt[0] * cnt[0];
    if (!(b&1)) ans = ans + (long long)(1ll * cnt[b / 2] * cnt[b / 2] * cnt[b / 2]);
    cout << ans << endl;
}

int main() {
    int a, b;
    cin >> a >> b; work(a, b);
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n,a;
    cin >> n >> a;
    if(n%500 - a <= 0)cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define for(i,a,b) for(ll i=(a);i<=(b);i++)
#define ford(i,a,b) for(ll i=(a);i>=(b);i--)
#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 INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main(void) {
    long int A,B,C,D,ans;
    cin >> A >> B >> C >> D;    
while(A > 0){
    C = C - B;
    if(C<=0){
        cout << "Yes" << "\n"; 
        return 0;
    }
    A = A - D; 
}
cout << "No" << "\n"; 
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int a[1010];
int t[1010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	int q;
	scanf("%d",&q);
	while(q--){
		//[b,e)をe-m個右へrotate
		int b,m,e;
		scanf("%d%d%d",&b,&m,&e);
		m=e-m;
		for(int i=0;i<e-b;i++)t[i]=a[b+i];
		for(int i=0;i<e-b;i++)a[b+(i+m)%(e-b)]=t[i];
	}
	for(int i=0;i<n;i++)printf("%d%c",a[i],i==n-1?10:32);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s;
    cin >> s;
    ll N = s.size();
    ll sum = 0;
    rep(i, 1<<(N-1)){
        ll now = s[0]-'0';
        rep(j, N-1){
            if(i & (1<<j)){
                sum += now;
                now = s[j+1]-'0';
            }
            else{
                now = 10*now + (s[j+1]-'0');
            }
        }
        sum += now;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256