akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main(){
	int n, m, s, c;
	int s1, s2, s3;
	s1 = s2 = s3 = -1;
	cin >> n >> m;
	rep(i, m){
		cin >> s >> c;
		if(s == 1 && (s1 == -1 || s1 == c)){
			s1 = c;
		}else if(s == 2 && (s2 == -1 || s2 == c)){
			s2 = c;
		}else if(s == 3 && (s3 == -1 || s3 == c)){
			s3 = c;
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	
	int ans = 0;
	if(m == 0){
		if(n == 3) ans = 100;
		else if(n == 2) ans = 10;
		else ans = 0;
	}else if(n == 3){
		if(s1 == 0){
			cout << -1 << endl;
			return 0;
		}
		if(s1 == -1) s1 = 1;
		if(s2 == -1) s2 = 0;
		if(s3 == -1) s3 = 0;
		for(int i = 100; i < 1000; i++){
			int a1, a2, a3;
			string str = to_string(i);
			a1 = str[0] - '0';
			a2 = str[1] - '0';
			a3 = str[2] - '0';
			if(a3 == s3 && a2 == s2 && a1 == s1){
				ans = i;
				break;
			}
		}
	}else if(n == 2){
		if(s1 == 0){
			cout << -1 << endl;
			return 0;
		}
		if(s1 == -1) s1 = 1;
		if(s2 == -1) s2 = 0;
		for(int i = 10; i < 100; i++){
			int a1, a2;
			string str = to_string(i);
			a1 = str[0] - '0';
			a2 = str[1] - '0';
			if(a2 == s2 && a1 == s1){
				ans = i;
				break;
			}
		}
	}else if(n == 1){
		ans = s1;
	}
	
	cout << ans << endl;
	
	return 0;
}

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<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
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=(ll)1e+18+1;
int INF=1e+9+1;
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll p[]={a,1,0},q[]={b,0,1};
		while(*q){
			ll t=*p/ *q;
			rep(i,3) swap(p[i]-=t*q[i],q[i]);
		}
		if(p[0]<0) rep(i,3) p[i]=-p[i];
		x=p[1],y=p[2];
		return p[0];
	}
	ModInt inv() const {
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
int main(){
	int N;
	ll C[200001];
	scan(N);
	rep(i,N) scan(C[i]);
	sort(C,C+N);
	mint ans=0;
	mint twoth=1;
	rep(i,2*N-2) twoth*=2;
	rep(i,N){
		ans+=C[i]*(N+1-i);
	}
	ans*=twoth;
	prin(ans);
	return 0;
}


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

using namespace std;

using ll = long long;

struct Edge {
    int u, v, col = -1;
};

vector<vector<pair<int, int> > > adj;
vector<Edge> edges;
int max_col = -1;
void dfs(const int u = 0, const int par = -1, const int prev = 0) {
    int cur = 0;
    for (auto p : adj[u]) {
        const int v = p.first, id = p.second;
        if (v == par) continue;
        do
            cur++;
        while (cur == prev);
        max_col = max(max_col, cur);
        edges[id].col = cur;
        dfs(v, u, cur);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;

    adj.resize(n);
    edges.resize(n - 1);
    for (int i = 0; i < n - 1; i++) {
        auto &e = edges[i];
        cin >> e.u >> e.v;
        e.u--, e.v--;
        adj[e.u].emplace_back(e.v, i);
        adj[e.v].emplace_back(e.u, i);
    }
    dfs();
    cout << max_col << '\n';
    for (auto e : edges) cout << e.col << '\n';
}

Measured memory_bytes: 7936
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static PrintWriter out;
    static Scanner sc;

    static void solve() {
        int[][] c = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = nextInt();
            }
        }

        int[] a = new int[3];
        int[] b = new int[3];

        // a[0]は固定値と想定して問題ない
        a[0] = 0;

        for (int j = 0; j <= 2; j++) {
            b[j] = c[0][j] - a[0];
        }
        for (int i = 1; i <= 2; i++) {
            a[i] = c[i][0] - b[0];
        }

        boolean ok = true;
        for (int i = 1; i <= 2; i++) {
            for (int j = 1; j <= 2; j++) {
                if (c[i][j] != a[i] + b[j]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                break;
            }
        }

        if (ok) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }

    static int nextInt() {
        return Integer.parseInt(sc.next());
    }

    static long nextLong() {
        return Long.parseLong(sc.next());
    }

    static String nextString() {
        return sc.next();
    }

    static int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    static List<Integer> nextIntList(int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        return list;
    }

    static List<Long> nextLongList(int n) {
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextLong());
        }
        return list;
    }

    static <T extends Comparable<? super T>> void sort(List<T> list) {
        Collections.sort(list);
    }

    // greatest common divisor
    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        sc = new Scanner(System.in);

        solve();

        out.flush();
        sc.close();
    }

}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int line = sc.nextInt();
		int spotCount = sc.nextInt();
		int firstSpot = sc.nextInt();
		int[] dangerousZone = new int[spotCount];
		int leftSpot = 0;
		int rightSpot = 0;
		for (int i = 0; i < spotCount; i++) {
			dangerousZone[i] = sc.nextInt();
			if (0 < dangerousZone[i] && dangerousZone[i] < firstSpot) {
				leftSpot++;
			} else {
				rightSpot++;
			}
		}
		if (leftSpot > rightSpot) {
			System.out.println(rightSpot);
		} else {
			System.out.println(leftSpot);
		}
		
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main() 
{
    IOS;
    int n;
    cin>>n;
    int arr[n];
    int ans=0;
    map<int,int>mp;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        ans+=mp[i-arr[i]];
        mp[arr[i]+i]++;
    }
    print(ans);
}   


Measured memory_bytes: 27888
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) { return m / gcd(n, m) * n; }

int main(void) {
	int x;
	cin >> x;
	cout << x * x * x << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main(){
  int N; cin >> N;
  int ans; ans = 0;
  bool jud; jud = false;
  int A[200];
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  
  while(jud == false){
    
     //2で割り切れないものがあればjudをtrueに変更
     for (int i=0; i<N; i++){
       if (A[i]%2 == 1){
         jud = true;
       }
     }
    
     if (jud == false){
       ans = ans + 1;
       for (int i=0; i<N; i++){
         A[i] = A[i]/2;
       }
     }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int f(int n){
    if(n == 1) return 1;
    if(n == 2) return 2;
    if(n == 3) return 4;
    return f(n-1) + f(n-2) + f(n-3);
    
    
}

int main(void){
    while(true) {
        int n;
        cin >> n;
        if(n==0) break;
        cout << (f(n) / 3650)+1 << endl;
    }
}
   




Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int max3(int a,int b,int c)
{
    if (a >= b && a >= c){
        return a;
    }
    else if (b >= a && b >= c){
        return b;
    }
    else {
        return c;
    }
}

int main()
{
    int N,W;
    int v[105];
    int w[105];
    
    cin >> N >> W;
    for (int i = 1;i <= N;i++){
        cin >> v[i] >> w[i];
    }
    
    int dp[105][100005];
    
    for (int i = 0;i <= N;i++){
        dp[i][0] = 0;
    }
    for (int i = 0;i <= W;i++){
        dp[0][i] = 0;
    }
    
    for (int i = 1;i <= N;i++){
        for (int j = 0;j <= W;j++){
            if (j >= w[i]){
                dp[i][j] = max3(dp[i-1][j],dp[i][j-w[i]]+v[i],dp[i-1][j-w[i]]+v[i]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}



Measured memory_bytes: 7468
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main() {
	string str;
	int N = 0,maxx=0;
	cin >> str;
	
	for (char c:str) {
		if (c == 'A' || c == 'T' || c == 'G' || c == 'C') {
			N++;
		}
		else {
			N = 0;
		}
		maxx=max(maxx,N);
	}

	cout << maxx << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    string str;

    cin >> str;

    cout << str[0] << str.size() - 2 << str[str.size() - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
S = list(input())
n = len(S)
ans = [0] * n
right_flag = False
for i, s in enumerate(S):
  if s == 'R' and right_flag is False:
    right_index = i
    right_flag = True
  elif s == 'L' and right_flag:
    right_flag = False
    cnt = i - right_index
    odd = cnt // 2
    even = cnt - odd
    ans[i-1] += even
    ans[i] += odd
left_flag = False
for i, s in enumerate(S[::-1], 1):
  if s == 'L' and left_flag is False:
    left_index = i
    left_flag = True
  elif s == 'R' and left_flag:
    left_flag = False
    cnt = i - left_index
    odd = cnt // 2
    even = cnt - odd
    ans[-i+1] += even
    ans[-i] += odd
print(*ans)

Measured memory_bytes: 28920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<deque>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef deque<int> di;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

signed main(void) {
    int i,j;
    int n,m;
    cin >> n >> m;
    vi t(m);
    rep(i,m) cin >> t[i];
    vi ans(n,0);
    rep(i,m){
        vi a(n);
        rep(j,n)cin >> a[j];
        int cnt = 0;
        rep(j,n){
            if(a[j] == t[i]){
                ans[j]++;
            }else{
                cnt++;
            }
        }
        ans[t[i]-1] += cnt;
    }
    rep(i,n)cout << ans[i] << endl;

}



Measured memory_bytes: 3128
import itertools

a,b = map(int,input().split())

N = int(input())
reserved = [0]*1001
for _ in range(N):
    s, f = map(int,input().split())
    reserved[s] += 1
    reserved[f] -= 1

cumsum = list(itertools.accumulate(reserved))

#print(cumsum)

if sum(cumsum[a:b]):
    print(1)
else:
    print(0)


Measured memory_bytes: 5656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[105],sum;
int main(){
	cin>>n;
	rep(i,n)
	{
		cin>>a[i]; sum+=a[i];
	}
	P p = mp(INF,INF);
	rep(i,n){
		int x = abs(sum-a[i]*n);
		p = min(p,mp(x,i));
	}
	cout << p.sc << endl;
}

Measured memory_bytes: 768
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
vi v[N];
ll ans,k;
void solve(){
    ll n,a,b;
    cin>>n>>k;
    rep(i,1,n-1){
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    // rep(i,1,n) cout<<sz(v[i])<<" ";
    ans=k;
    queue <ll> q;
    bool vis[N]={0};
    vis[1]=1;
    ll kk=0;
    rep(i,0,sz(v[1])-1){
        if(vis[v[1][i]]) {kk=1;continue;}
        if((k-1-i+kk)<0) {cout<<0;return;}
        ans=(ans*(k-1-i+kk))%hell;
        q.push(v[1][i]);
        vis[v[1][i]]=1;
    }
    while(!q.empty()){
        ll curr=q.front();
        q.pop();
        kk=0;
        rep(i,0,sz(v[curr])-1){
            if(vis[v[curr][i]]) {kk=1;continue;}
            q.push(v[curr][i]);
            if((k-2-i+kk)<0) {cout<<0;return;}
            ans=(ans*(k-2-i+kk))%hell;
            vis[v[curr][i]]=1;
        }
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 7412
def enq(a,x)
  b=a[i=-1] and b=a and until b.frozen?
    x < (a=b)[-1] or return a << x
    x > a[0] or return a.unshift x
    b = a[i = a.bsearch_index{|y| x < (y.frozen? ? y: y[0])}-1]
  end
  a[i+9] or return a.insert i+1, x
  i>0 ? a[i]=[b,x] : enq(a[i+=1].to_a,x)  rescue a[i]=[x,a[i]]
end
def deq(a) r=a.shift; a[0].frozen? or a.unshift *a.shift; r end
Q,E,N = [],{},{}
F =->(e,n) { N[n] ? next : enq(Q,e); (E[e]||={})[n] = 0 }
gets.to_i.times {
  n,a,b,c,d = gets.split.map &:to_i
  Q.replace [0]
  E.replace({0=>{n=>0}})
  N.clear
  p (catch(:e) { while 1
    E[e=deq(Q)].keys.each {|n|
      N[n] ? next : N[n]=e
      throw :e,e  if n == 0
      [[a,2],[b,3],[c,5]].each {|p,m|
        q,r = n.divmod m
        if r == 0
          p > (x=q*d*(m-1)) and p = x
          F[e+p,q]
        else
          F[e+d*r,n-r]
          F[e+d*(m-r),n-r+m]
        end
      }
    }
    E.delete e
    deq Q  while Q[0] == e
  end })
}

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

typedef long long int lli;

int main() {
	lli N, M;
	cin >> N >> M;

	vector<pair<lli,lli>> P(N);
	for (lli i = 0; i < N; i++) {
		cin >> P[i].first >> P[i].second;
	}

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

	lli sum = 0;
	lli tmp = 0;
	lli i = 0;
	while (tmp < M) {
		sum += P[i].first * min(P[i].second, max(0LL, M - tmp));
		tmp += P[i].second;
		i++;
	}

	cout << sum << endl;

	return 0;
}


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

int main() {
    int n, a, b, a1, a2;

    cin >> n >> a >> b;

    a1 = abs(a - b);
    a2 = abs(max(a, b) - a1);
    
    a1 = a + b - n;

    if (a1 < 0) a1 = 0;

    printf("%d %d\n", a2, a1);

    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env ruby

N = STDIN.read.to_i
SU = [357, 375, 537, 573, 735, 753]
NS = [3, 5, 7]


def sgs_fac(i, m)
  cnt = 0
  NS.repeated_permutation(i) {|arr| 
    j = arr.join('').to_i
    if j <= m && arr.uniq.length == 3
      cnt = cnt + 1
    end
  }
  return cnt
end

def sgs()
  l = N.to_s.length
  cnt = 0
  i = l
  while i > 0
    cnt = cnt + sgs_fac(i, N)
    i = i - 1
  end

  return cnt
end

puts sgs()


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

int main(){
    int n;
    cin >> n;
    vector<int> ns(n);
    rep(i, n) cin >> ns.at(i);
    ll min = 100000000000;
    for(int i=-100; i<=100; i++){
        ll cos = 0;
        rep(j, n) cos += pow((ns.at(j) - i), 2);
        if(min > cos) min = cos;
    }
	cout << min << endl;
}


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

int a, b, c, ans;

int main() {
  ans = 0;
  cin >> a >> b >> c;
  if (a%2 + b%2 + c%2 == 1) {
    if (a % 2 == 0) a++;
    if (b % 2 == 0) b++;
    if (c % 2 == 0) c++;
    ans = 1;
  } else if (a%2 + b%2 + c%2 == 2) {
    if (a % 2 == 1) a++;
    if (b % 2 == 1) b++;
    if (c % 2 == 1) c++;
    ans = 1;
  }
  ans += (3*max({a, b, c}) - (a+b+c)) / 2;
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll, ll>> work;
    REP(i, N)
    {
        ll a, b;
        cin >> a >> b;
        work.push_back(make_pair(b, a));
    }
    sort(ALL(work));
    bool flag = true;
    ll total = 0;
    REP(i, N)
    {
        total += work[i].second;
        if (total > work[i].first)
        {
            flag = false;
            break;
        }
    }

    string ans;
    if (flag) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 6256
#include <iostream>

using namespace std;

int main()
{
	int n = 0;

	cin >> n;

	int a[n];

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = n - 1; i >= 0; i--)
	{
		cout << a[i];
		if (i != 0)
			cout << " ";
	}

	cout << endl;

	return 0;
}

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

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

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

//.data

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

    int n;
    cin >> n;
    vector<int> arr(n);
    int tot = 0;
    loop(n) {
        cin >> arr[i];
        tot ^= arr[i];
    }
    loop(n) {
        cout << (tot ^ arr[i]) << ' ';
    }
    cout << endl;

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

Measured memory_bytes: 3944
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin>>n;
    vector<long long> a(n),chk(n+10,0);
    long long i;
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        ++chk[a[i]];
    }
    long long ans = 0;
    for(i=1;i<=n;++i)
    {
        ans += ((chk[i]*(chk[i]-1))/2);
    }
    for(i=0;i<n;++i)
    {
        if(chk[a[i]] == 1)
            cout<<ans<<"\n";
        else
            cout<<ans-chk[a[i]]+1<<"\n";
    }
}


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

int main()
{
    int a, b;
    cin >> a >> b;
  
    bool flag = true;
    int value = 0;
    while (flag)
    {
      if (a == int(value * 0.08) && b == int(value * 0.1))
      {
        flag = false;
        cout << value << endl;
      }
      else
      {
        value++;
      }
      
      if (value > 1000)
      {
        flag = false;
        cout << -1 << endl;
      }
    }

    return 0;
}

Measured memory_bytes: 256
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include<stdio.h>

using namespace std;

int main(void) {
	int n, k, q; cin >> n >> k >> q;
	int a,count=0;
	vector<int> v(n,k);//a(q),
	for (int i = 0; i < q; ++i) {
		cin >> a;
		v[a - 1] += 1;
	}
	for (int i = 0; i < n; ++i) {
		if (v[i] - q > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	/*for (int i = 0; i < q; ++i) {
		cin >> a;
		for (int j = 0; j < n; j++) {
			//if(v[j]<=0)
			if (j == a - 1) continue;
			v[j] -= 1;
		}
	}
	for (int j = 0; j < n; j++) {
		//cout << v[j];
		if (v[j] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}*/

	return 0;
}


Measured memory_bytes: 1024
def Result(original, digit):
    history = [original]
    while True:
        history.append(next(history[-1], digit))
        if history[-1] in history[:-1]:
            return history.index(history[-1]), history[-1], len(history) - history.index(history[-1]) - 1


def next(decimal, digit):
    tmp = decimal
    numbers = []
    for i in range(digit):
        numbers.append(tmp / 10 ** (digit - i - 1))
        tmp -= numbers[-1] * 10 ** (digit - i - 1)
    maxnum = ""
    for i in sorted(numbers, reverse=True):
        maxnum += str(i)
    maxnum = int(maxnum)
    minnum = ""
    for i in sorted(numbers):
        minnum += str(i)
    minnum = int(minnum)
    return maxnum - minnum


if __name__ == "__main__":
    import sys
    import fileinput

    fin = fileinput.input()
    while True:
        line = fin.next()
        originalnumber, digit = [int(i) for i in line.strip().split()]
        if originalnumber == 0 and digit == 0:
            break
        first, result, sub = Result(originalnumber, digit)
        print first, result, sub

    sys.exit(0)

Measured memory_bytes: 4296
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Foldable
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  as <- getIntList

  let cost y = sum $ map (\x -> (x - y)^2) as
      solve y m | y > 100   = m
                | otherwise = solve (y+1) (min (cost y) m)
      inf = 10^9 :: Int

  print $ solve (-100) inf

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define reset(X) memset(X, 0, sizeof(X))
#define int long long
typedef long long ll;
#define pb push_back
#define se second
#define fi first
#define endl '\n'
#define all(X) X.begin(),X.end()

const int INF=1e18;
const int mod=1e9+7;
const int mod2=998244353;



#define REDN(a) int a;cin>>a;
#define REDL(a,n) int a[n];for(int i=0;i<n;i++) cin>>a[i];
#define REDA(a,n,m) int a[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++) cin>>a[i][j];





int pow(int a, int b)
{
    int prod=1;
    int mult=a;
    while(b!=0)
    {
        if(b%2)
        {
            prod*=mult;
            prod%=mod2;
        }
        mult*=mult;
        mult%=mod2;
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int mod)
{
    return pow(q, mod-2);
}






struct deta
{
    int sa, ea, sb, eb;
    deta()
    {
        sa=0, ea=0, sb=0, eb=0;
    }
    deta(int a, int b, int c, int d)
    {
        sa=a, ea=b, sb=c, eb=d;
    }

    bool operator<(deta other)
    {
        if(sa<other.sa)
            return true;
        if(sa>other.sa)
            return false;
        return false;
    }
};





struct cmp_se
{
bool operator()(deta a, deta b)
{
    if(a.ea<b.ea)
        return true;
    if(a.ea>b.ea)
        return false;
    return a.sa<b.sa;
}
};

const int MAXN=4e5+10;
 int t[4*MAXN];
int lazy[4*MAXN];

void push(int v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return -INF;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return max(query(v*2, tl, tm, l, min(r, tm)), 
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
signed main()

{
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r")) {
        freopen ("INPUT.txt" , "r" , stdin);
         freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
//----------------------------------
    int n;
    cin>>n;
    map<string ,int > lis;
    int a[n+1];
    for(int i=0;i<n;i++)
    {
        string k;
        cin>>k;
        lis[k]=i;
        cin>>a[i];

    }
    a[n]=0;
    for(int i=n-1;i>=0;i--)
    {
        a[i]=a[i]+a[i+1];
    }
    string l;
    cin>>l;
    cout<<a[lis[l]+1]<<endl;
    
}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int N, T;
            cin >> N >> T;
        int min = 1001;
        vector<int> c(N);
        vector<int> t(N);
            for(int i = 0; i < N; i++){
                cin >> c.at(i) >> t.at(i);
                    if(t.at(i) <= T){
                        if(c.at(i) <= min){
                            min = c.at(i);
                        }
                    }
            }
                if(min == 1001){
                    cout << "TLE" << endl;
                }else{
                    cout << min << endl;
                }
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R'){
      count++;
    }
  }
  if (count > N-count){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  
    

Measured memory_bytes: 3592
S = input()

ans = 0

if len(S) == 1:
    ans = int(S)
else:
    for i in range(2 ** (len(S) - 1)):
        tmp = S[0]
        for j in range(0, len(S) - 1):
            if i >> j & 1 == 0:
                tmp += S[j + 1]
            else:
                ans += int(tmp)
                tmp = S[j + 1]
        ans += int(tmp)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h> 
#include<queue>
#include<string.h>
#include<stack>


using namespace std;

#define INF 1000000000
#define BL 1
#define WH 0
#define GL 2

int par[100001];
int r[100001];

void init(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		r[i]=0;
	}
}


int root(int x){
	if(par[x]==x){
		return x;
	}
	else {
		return par[x]=root(par[x]);
	}
}

bool same(int x,int y){
	return root(x)==root(y);
}


void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y)return;

	if(r[x]<r[y]){
		par[x]=y;
	}
	else{
		par[y]=x;
		if(r[x]==r[y])r[x]++;
	}
}

struct edge{
	int s1,t1,w1;
};


bool comp(const edge g1,const edge g2){
	return g1.w1 < g2.w1;
}

edge g[100001];

int kruskal(int V,int E){
	sort(g,g+E,comp);
	init(V);
	int ans=0;
	for(int i=0;i<E;i++){
		edge new_g=g[i];
		if(!same(new_g.s1,new_g.t1)){
			unite(new_g.s1,new_g.t1);
			ans=ans+new_g.w1;
		}
	}
	return ans;
}


int main(){
	int V;
	int E;
	

	cin>>V>>E;
	int s,t,w;
	for(int i=0;i<E;i++){
		cin>>s>>t>>w;
		g[i]=(edge){s,t,w};
	}
	int ans=0;
	ans=kruskal(V,E);
	cout<<ans<<endl;
	return 0;
}























Measured memory_bytes: 4372
def test(s):

	res = 0
	aAdd = 0
	last = ''
	tmp = ''
	for i in xrange(len(s)):
		if tmp and tmp > i:
			continue
		if s[i] == 'A':
			aAdd += 1
		elif s[i:i+2] == 'BC':
			# print aAdd
			res = res + aAdd
			tmp = i + 2
		else:
			aAdd = 0
			last = s[i]


	return res
s=raw_input()
print test(s)

Measured memory_bytes: 85044
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
	
using namespace std;
int main()
{
	
	std::ios::sync_with_stdio(false);

		int a,b,c;
		cin>>a>>b>>c;
		cout<<c<<" "<<a<<" "<<b;
	
	return 0;
}

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

const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n,m,a[300000],res=0,cou=0;
string str;
int main() {
	cout << fixed << setprecision(10);
	cin>>n;
	cout<<n*n*n<<endl;
	
} 


Measured memory_bytes: 256
//C

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
//#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};



//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!

int W[1000];
signed main() {
	int N;
	cin >> N;
	int ans = LL_HALFMAX;
	rep(i, N) {
		cin >> W[i];
	}
	rep(i, N) {
		int one = 0, two = 0;
		rep(j, i) {
			one += W[j];
		}
		for (int j = i; j < N; j++) {
			two += W[j];
		}
		ans = min(abs(one - two), ans);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
e_out = [[] for _ in range(N + 1)]
e_in = [[] for _ in range(N + 1)]
for _ in range(N + M - 1):
    a, b = map(int, input().split())
    e_out[a].append(b)
    e_in[b].append(a)


# 1. 入次数が0のやつが親
# 2. 親が決まれば、そのこの入次数を減らす,1に戻る

# 親を決めるよ
for i, e in enumerate(e_in[1:], start=1):
    if len(e) == 0:
        root = i
        break

node = [root]
parent = [-1] * (N + 1)
parent[root] = 0
diff = [0] * (N + 1)  # 入次数をどれだけ減らすか

while node:
    s = node.pop()
    for t in e_out[s]:
        diff[t] += 1
        if len(e_in[t]) - diff[t] == 0:
            parent[t] = s
            node.append(t)

print(*parent[1:], sep="\n")


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}

	int max1 = 0;
	int max2 = 1;
	for(int i = 1; i < n; ++i)
	{
		if (a[max1] < a[i])
		{
			max2 = max1;
			max1 = i;
		}
		else if (a[max2] < a[i])
		{
			max2 = i;
		}
	}
	for(int i = 0; i < n; ++i)
	{
		cout << (i == max1 ? a[max2] : a[max1]) << endl;
	}
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3984
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public class Node {
		int score;
		int x;
		int y;
		public Node(int score, int x, int y) {
			super();
			this.score = score;
			this.x = x;
			this.y = y;
		}
		
		
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		char[][] s = new char[h][];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().toCharArray();
		}
    	Deque<Node> queue = new ArrayDeque<>();
        queue.add(new Node(1,0,0));
        
        int b = 0;
        Node node; 
        while( (node = queue.poll()) != null ) {
        	int score = node.score;
        	int x = node.x;
        	int y = node.y;
        	if( x<0 || w<=x || y<0 || h<=y )
        		continue;
        	if( s[y][x]!='.')
        		continue;
        	s[y][x] = '/';
        	
            boolean isGoal = x == w-1 && y == h-1;
			if( isGoal ) {
				for (int i = 0; i < h ; i++) {
					for (int j = 0; j < w ; j++) {
						if( s[i][j] != '#' )
							b++;
					}
				}
				System.out.println( b - node.score );
				return ;
            }
			
			// 
	        queue.add(new Node(score+1, x+1, y ));
	        queue.add(new Node(score+1, x-1, y ));
	        queue.add(new Node(score+1, x, y+1 ));
	        queue.add(new Node(score+1, x, y-1 ));

        }

		System.out.println(-1);
	}
	
    
}


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

int waruni(int n) {
  int cnt = 0;
  while(n%2 != 1) {
    cnt++;
    n = n/2;
  }
  return cnt;
}

int main() {
  int N;
  cin >> N;
  int ans = 1000000;
  for (int i = 0;i<N;i++) {
    int a;
    cin >> a;
    ans = min(ans,waruni(a));
    
  }
  cout << ans << endl;
    
  
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 305;
ld dp[N][N][N];
bool mark[N][N][N];
int n;

ld solve(int t1, int t2, int t3) {
	int t0 = n - (t1 + t2 + t3);
	if (t0 == n)
		return 0;
	ld &ans = dp[t1][t2][t3];
	if (mark[t1][t2][t3])
		return ans;
	mark[t1][t2][t3] = 1;
	ans = 1;
	if (t1)
		ans += solve(t1 - 1, t2, t3) * ((ld) t1 / n);
	if (t2)
		ans += solve(t1 + 1, t2 - 1, t3) * ((ld) t2 / n);
	if (t3)
		ans += solve(t1, t2 + 1, t3 - 1) * ((ld) t3 / n);
	ans /= (1 - ((ld)t0 / n));
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t[4] = {};
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		t[a]++;
	}
	cout << fixed << setprecision(12) << solve(t[1], t[2], t[3]);
	return 0;
}


Measured memory_bytes: 228156
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vii;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int n, k; cin>>n>>k;
  vector<LL> v(n);
  forn(i,n) cin>>v[i];
  for(int i = k; i < n; i++){
  	cout<<(v[i] > v[i-k]?"Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
int a[2001],s,n,i;
std::bitset<4000001> d;     
int main(){
    std::cin>>n;d[0]=1;
    for(;i<n;i++)std::cin>>a[i],s+=a[i],d|=(d<<a[i]);
    while(!d[++s/2]){} std::cout<<s/2;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 ll pow_mod(ll x, ll n) {
   x %= MOD;
   if (n == 0) return 1;
   else if (n % 2 == 1) return (x * pow_mod(x, n - 1)) % MOD;
   else return pow_mod((x * x) % MOD, n / 2) % MOD;
 }

 ll SUM(ll a, ll b) {
   return (b * (b + 1) % MOD * pow_mod(2, MOD - 2) % MOD - a * (a - 1) % MOD * pow_mod(2, MOD - 2) % MOD + MOD) % MOD;
 }

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

   ll ten = 10000000000 - MOD;
   ten = pow_mod(ten, 10);

   ll ans = 0;

   for (ll i = K; i <= N + 1; i++) {
     ll tmp = -i * (i - 1) / 2 + i * (2 * N - i + 1) / 2 + 1;
     ans += tmp % MOD;
     ans %= MOD;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//解説を見て修正AC
//参考:https://qiita.com/drken/items/fd4e5e3630d0f5859067#5-%E9%81%8E%E5%8E%BB%E5%95%8F%E7%B2%BE%E9%81%B8-10-%E5%95%8F
 int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
int n,a,b;

cin>>n>>a>>b;
int ans=0;
for (size_t i = 0; i <= n; i++)
{   int m=i;int sum=0;
    //int sum=findSumOfDigits(i);
   while(m>0)
    {
        sum+=m%10;
        m/=10;

    }
    if(a<=sum&&sum<=b)
    {
        ans+=i;
    }
    
    
}
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int m;
vector<bool> b(16,false);
vector<P> f;

int dfs(int k,vector<int> v){
    int ret=0;
    if(k==m){
        map<P,int> ma;
        for(int i=0;i<m;i++){
            if(i%2){
                int x=f[v[i]].fs-f[v[i-1]].fs;
                int y=f[v[i]].sc-f[v[i-1]].sc;
                int g=__gcd(abs(x),abs(y));
                x/=g;
                y/=g;
                if(x*y<0) ma[{-abs(x),abs(y)}]++;
                else ma[{abs(x),abs(y)}]++;
            }
        }
        for(auto p:ma) ret+=p.sc*(p.sc-1)/2;
        return ret;
    }
    for(int i=0;i<m;i++){
        if(!b[i]){
            v.pb(i);
            b[i]=true;
            ret=max(ret,dfs(k+1,v));
            b[i]=false;
            if(k%2==0) return ret;
            v.pop_back();
        }
    }
    return ret;
}
int main(){
    cin >> m;
    for (int i = 0; i < m; i++) {
        int x,y;
        cin >> x >> y;
        f.pb({x,y});
    }
    cout << dfs(0,vector<int> ()) << endl;
    return 0;
}



Measured memory_bytes: 3172
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let a:i64 = read();
    let b:i64 = read();
    let k:i64 = read();

    let mut set = HashSet::new();

    for i in a..a+k {
        if a <= i && i <= b {
            set.insert(i);
        }
    }
    for i in b-k+1..b+1 {
        if a <= i && i <= b {
            set.insert(i);
        }
    }

    //debug!(set);
    let mut v:Vec<i64> = set.into_iter().collect();
    v.sort();
    for num in v.iter() { println!("{}", num); }


}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int A, B, K;
  cin >> A >> B >> K;
  int ans = gcd(A, B);
  int c = 0;
  for (int i = 1; i < A * B; i++) {
    if (ans % i == 0) {
      c++;
    }
    if (c == K) {
      ans /= i;
      break;
    }
  }  
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'
#define PI 3.1415926535897932385
#define MOD 1000000007
typedef vector<ll> ve;




int main()
{ll n;
cin>>n;
map<ll,ll>m;
for(ll i=0;i<n-1;i++)
{ll t;
     cin>>t;
     m[t]++;
} 
for(ll i=1;i<=n;i++)
{
	cout<<m[i]<<endl;
}

 return 0;
    }

    
	 		
	    

Measured memory_bytes: 16132