akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;

#define REP(i,p,n) for(int i=p;i<n;i++)
#define rep(i,n) REP(i,0,n)

#define EPS (1e-10)
#define INF (1e+4)
#define EQ(a,b) (abs(a-b)<EPS)
#define PI (acos(-1))

typedef complex<double> P;
#define X real()
#define Y imag()
double dot(const P& a,const P& b){ return (a.X*b.X)+(a.Y*b.Y); }
double cross(const P& a,const P& b){ return (a.X*b.Y)-(a.Y*b.X); }
double rad(double theta){ return (theta/180.0)*PI; }

double distance_lp2(const P& a,const P& b,const P& c)
{
	if(dot(b-a,c-a)<EPS) return abs(c-a);
	if(dot(a-b,c-b)<EPS) return abs(c-b);
	return abs(cross(b-a,c-a)/abs(b-a));
}

bool is_intersected_ll2(const P& a1,const P& a2,const P& b1,const P& b2)
{
	if(abs(cross(a2-a1,b2-b1))<EPS) return false;
	return (cross(a2-a1,b1-a1)*cross(a2-a1,b2-a1)<EPS) && (cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1)<EPS);
}

bool is_include4(const P& p,const P& lhs,const P& rhs)
{
	return min(lhs.X,rhs.X)<=p.X && p.X<=max(lhs.X,rhs.X) &&
		   min(lhs.Y,rhs.Y)<=p.Y && p.Y<=max(lhs.Y,rhs.Y);
}

bool len3(double d,double r,double h){ return d*d+(r-h)*(r-h)<(r*r); }

bool check(double d1,double d2,double d3,double d4,double h,double r)
{
	if(r<=h){ if(d1<r||d2<r||d3<r||d4<r){ return false; } }
	else    { if(len3(d1,r,h)||len3(d2,r,h)||len3(d3,r,h)||len3(d4,r,h)){ return false; } }

	return true;
}


P S,G;

int main()
{
	int n;
	while(cin>>n&&n)
	{
		cin>>S.X>>S.Y>>G.X>>G.Y;

		double ans = INF;

		rep(i,n)
		{
			double h;
			P p1,p2;

			cin>>p1.X>>p1.Y>>p2.X>>p2.Y>>h;
			if(ans<EPS){ ans=0; continue; }
			
			bool a = is_intersected_ll2(S,G,p1,P(p1.X,p2.Y));
			bool b = is_intersected_ll2(S,G,p1,P(p2.X,p1.Y));
			bool c = is_intersected_ll2(S,G,p2,P(p1.X,p2.Y));
			bool d = is_intersected_ll2(S,G,p2,P(p2.X,p1.Y));
			bool e = is_include4(S,p1,p2);
			bool f = is_include4(G,p1,p2);

			if(a||b||c||c||d||e||f){ ans=0; continue; }

			double d1 = distance_lp2(S,G,p1);
			double d2 = distance_lp2(S,G,p2);
			double d3 = distance_lp2(S,G,P(p1.X,p2.Y));
			double d4 = distance_lp2(S,G,P(p2.X,p1.Y));

			double s1 = distance_lp2(p1,P(p1.X,p2.Y),S);
			double s2 = distance_lp2(p1,P(p2.X,p1.Y),S);
			double s3 = distance_lp2(p2,P(p1.X,p2.Y),S);
			double s4 = distance_lp2(p2,P(p2.X,p1.Y),S);

			double g1 = distance_lp2(p1,P(p1.X,p2.Y),G);
			double g2 = distance_lp2(p1,P(p2.X,p1.Y),G);
			double g3 = distance_lp2(p2,P(p1.X,p2.Y),G);
			double g4 = distance_lp2(p2,P(p2.X,p1.Y),G);

			double lhs=0,rhs=INF;

			while(abs(rhs-lhs)>EPS)
			{
				double med = (lhs+rhs)/2.0;
				double dd = check(d1,d2,d3,d4,h,med);
				double ss = check(s1,s2,s3,s4,h,med);
				double gg = check(g1,g2,g3,g4,h,med);

				if(dd&&ss&&gg){ lhs=med; } else { rhs=med; }
			}

			if(rhs<ans) ans=rhs;
		}

		printf("%0.10lf\n",ans);
	}

    return 0;
}

Measured memory_bytes: 1268
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int64_t H, W;
  cin >> H >> W;

  cout << (H == 1 || W == 1 ? 1
                            : (H + 1) / 2 * ((W + 1) / 2) + (H / 2) * (W / 2))
       << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int N,hoge[10000]={0},i;
    while(cin>>N){
        if(N==-1)break;
        for(i=0;i<10000;i++){
            if(N<4){
                hoge[i]=N;
                break;
            }
            hoge[i]=N%4;
            N/=4;
        }
        for(int j=i;j>=0;j--){
            cout<<hoge[j];
        }
        puts("");

    }
    return 0;
}

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

int main() {

  int N;
  cin >> N;

  vector<long long> T(N);
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i] >> A[i];
  }

  vector<long long> t(N);
  vector<long long> a(N);

  t[0] = T[0];
  a[0] = A[0];

  for (int i = 1; i < N; i++) {
    long long t_ = ceil((double long) t[i - 1] / T[i]);
    long long a_ = ceil((double long) a[i - 1] / A[i]);
    long long n = max(t_, a_);
    t[i] = n * T[i];
    a[i] = n * A[i];
  }

  cout << t[N - 1] + a[N - 1] << endl;
  
  return 0;

}


Measured memory_bytes: 256
N = int(input())
import math
n = 10*N
for i in range(1,math.ceil(N/2)+1):
    m = 0
    j = str(N-i)
    i = str(i)
    for k in range(len(i)):
        m += int(i[k])
    for k in range(len(j)):
        m += int(j[k])
    if m < n:
        n = m
print(n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 3000;
const int mo = 1e9 + 7;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n, m;
int f[N + 5][N + 5][2];

inline void add(int &a, int b) {
    if((a += b) >= mo) a -= mo;
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif 

    scanf("%d%d", &n, &m);

    for(int i = 0; i <= n; ++i) f[0][i][!i] = 1;
    for(int i = 1; i <= m; ++i) {
        for(int j = 0; j <= n; ++j) {
            if(j > 0) {
                add(f[i][j][(j == 1)], f[i-1][j][0]);
                add(f[i][j][1], f[i-1][j][1]);

                add(f[i][j-1][(j == 1)], f[i-1][j][0]);
                add(f[i][j-1][1], f[i-1][j][1]);
            }

            if(j < n) {
                add(f[i][j][0], f[i-1][j][0]);
                add(f[i][j][1], f[i-1][j][1]);

                add(f[i][j+1][0], f[i-1][j][0]);
                add(f[i][j+1][1], f[i-1][j][1]);
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= n; ++j) {
        add(ans, f[m][j][1]);
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 70656
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <cctype>

using namespace std;

const int64_t INF=10000000000000000;

class order{
public:
    int64_t card_num;
    int64_t size;
};
bool cmp(const order* left,const order* right){
    return (left->card_num)>(right->card_num);
}
int main(){
    int32_t n,m;
    cin>>n>>m;
    vector<order*> order_list;
    order_list.reserve(n+m);
    for(int32_t i1=0;i1<n;i1++){
        int64_t temp;
        cin>>temp;
        order *temp2=new order();
        temp2->card_num=temp;
        temp2->size=1;
        order_list.push_back(temp2);
    }
    for(int32_t i1=0;i1<m;i1++){
        int64_t card,size;
        cin>>size>>card;
        order *temp2=new order();
        temp2->card_num=card;
        temp2->size=size;
        order_list.push_back(temp2);
    }
    sort(order_list.begin(),order_list.end(),cmp);
    int64_t ans=0;
    int64_t sum_num=0;
    for(auto i1=order_list.begin();i1!=order_list.end();i1++){
        order *t = (*i1);
        if(sum_num+(t->size)<=n){
            sum_num+=t->size;
            ans+=(t->card_num)*(t->size);
        }else{
            ans+=(n-sum_num)*(t->card_num);
            break;
        }
    }
    cout<<ans<<endl;


   return 0;
}


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

int main() {
  string n;
  cin>>n;
  
  int p=n.size();
  int j=0;
  
  for(int i=0;i<p;i++){
    if(n.at(i)=='o'){
      j++;
    }
  }
  
  if(j+15-p>=8){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

}

Measured memory_bytes: 256
#include<cstdlib>
#include<map>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main()
{
    int a[5];
    int m=0;
    for(int i=0; i<3; i++)
        cin>>a[i];
    while(a[0]!=a[1] || a[0]!=a[2])
    {
        m++;
        sort(a,a+3);
        if(a[0]==a[1])
        {
            a[0]+=1;
            a[1]+=1;
        }
        else if(a[1]==a[2])
            a[0]+=2;
        else
        {
            if(m%2)
            {
                a[0]+=1;
                a[1]+=1;
            }
            else
                a[0]+=2;
        }
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;


int main()
{
    // read input
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    rep(i, 0, H) cin >> grid[i];

    int cnt = 0;
    rep(i, 0, 1<<H)
        rep(j, 0, 1<<W)
        {
            int num_black = 0;
            rep(h, 0, H)
                rep(w, 0, W)
                {
                    if ((i>>h)&1) continue;
                    if ((j>>w)&1) continue;
                    if (grid[h][w] == '.') continue;
                    ++num_black;
                }
            if (num_black == K)
                ++cnt;
        }
    cout << cnt << endl;
    return 0;
}

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

#define ll long long 

using namespace std;

int n,m,c,r;
int aux;
vector <int> B;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>c;
    for (int i=0; i<m; i++){
        cin>>aux;
        B.push_back(aux);
    }
    for (int i=0; i<n; i++){
        int s=0;
        for (int j=0; j<m; j++){
            cin>>aux;
            s+=B[j]*aux;
        }
        s+=c;
        if(s>0) r++;
    }
    
    cout<<r;
    return 0;
}

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

int main(){
	int xp[]={-1,0,1,0};
	int yp[]={0,-1,0,1};
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<pair<int,int> > a(n);
		a[0].first=0;
		a[0].second=0;
		int x1=0;
		int x2=0;
		int y1=0;
		int y2=0;
		for(int i=0;i<n-1;i++){
			int q,b;
			cin>>q>>b;
			a[i+1].first=a[q].first+xp[b];
			a[i+1].second=a[q].second+yp[b];
			x1=min(x1,a[i+1].first);
			x2=max(x2,a[i+1].first);
			y1=min(y1,a[i+1].second);
			y2=max(y2,a[i+1].second);
		}
		cout<<x2-x1+1<<" "<<y2-y1+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
use proconio::{fastout, input};
use std::cmp;

#[fastout]
fn main() {
    input! {
        l: u64,
        r: u64,
    }
    let r = cmp::min(r, l + 2019 * 2);
    let mut min = 2019;
    for i in l..r {
        for j in i + 1..=r {
            min = cmp::min(min, (i * j) % 2019);
        }
    }

    println!("{}", min);
}


Measured memory_bytes: 2084
// Date: 2020-02-28

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int k;
string s;
vector<pii> v;
set<string> ans;

int main() {
    FIO;
    cin >> s >> k;
    int n = s.size();
    rep(i, 0, n-1) v.pb(mk(s[i]-'a', i));
    v.pb(mk(26, n));
    sort(all(v));
    int pre = v[0].fi;
    rep(i, 0, n) {
        if(v[i].fi == pre) {
            rep(j, 1, k) if(v[i].se+j-1 < n) ans.insert(s.substr(v[i].se, j));
        } else {
            if(ans.size() >= k) break;
            pre = v[i].fi;
            --i;
        }
    }
    int cnt = 0;
    for(auto it = ans.begin(); it != ans.end(); ++it) {
        ++cnt;
        if(cnt == k) {
            cout << *it;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 384
//PseudoName

	#pragma GCC optimize("O3")
	#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	using namespace std;
	using namespace __gnu_pbds;
	template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


	#define FOR(i,n) for(i=0;i<n;i++)
	#define FOR1(i,n) for(i=1;i<=n;i++)
	#define FOR2(I, A, B) for (int I = (A); I <= (B); ++I)
	#define pb push_back
	#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
	#define print(v) for(auto it:v)cout<<it<<" ";cout<<endl
	#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	#define endl "\n"
	#define min3(a,b,c) min(a,min(b,c))
	#define forr(n) for(int i=0;i<n;i++)
	#define frr(n) for(int i=1;i<=n;i++)
	#define rep(i,a,b) for(int i=a;i<=b;i++)



	typedef long long ll;
	typedef long li;
	typedef vector<int> vi;
	typedef vector<ll> vli;
	typedef vector<vi> vvi;
	typedef vector<vli> vvli;
	typedef pair<int,int> pi;
	typedef pair<ll,ll> pli;
	typedef vector<pi> vpi;
	typedef vector<pli> vpli;



	//const ll MOD=1e9+7;

	/*
	ll fast_exp(ll base, ll exp) {
	    ll res=1;
	    while(exp>0) {
	       if(exp%2==1) res=(res*base)%MOD;
	       base=(base*base)%MOD;
	       exp/=2;
	    }
	    return res%MOD;
	}
	ll imod(ll a)
	{
		return fast_exp(a, MOD-2);
	}
	*/

	int main() {
	    fast();
	    int n;
	    cin>>n;
	    map<int,int> mp;
	    int a;

	    forr(n-1)
	    {
	        cin>>a;
	        mp[a]++;
	    }
        frr(n)cout<<mp[i]<<endl;


	}


Measured memory_bytes: 13028
/*2020/03/14 PanasonicProgrammingContest2020*/

#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() {
    ll h, w;
    cin >> h >> w;
    if(h==1 || w==1) {
        cout << 1 << endl;
        return 0;
    }
    if(h%2!=0) cout << h/2*w + (w+1)/2 << endl;
    else cout << h*w/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int INF = 1<<30;

int main(){
  int n,m; cin >> n >> m;
  vector<pair<int,int>> key(m);
  vector<int> dp((1<<n),INF);
  rep(i,m){
    int a,b; cin >> a >> b;
    int s = 0;
    rep(j,b){
      int c; cin >> c;
      c--;
      s |= 1 << c;
    }
    key[i] = {s,a};
  }
  
  dp[0] = 0;
  
  rep(i,m){
    rep(j,(1<<n)){
      if(dp[j] != INF){
        int s = j | key[i].first;
        chmin(dp[s],dp[j] + key[i].second);
      }
    }
  }
  
  int ans = dp[(1<<n)-1];
  if(ans == INF) ans = -1;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main(){
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}


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

int main() {
	string N, s;
	cin >> N;
	s = N.at(0);
	for (int i = 0; i < (int)N.size() - 1; i++) {
		s += '9';
	}
	int ans = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		ans += s.at(i) - '0';
	}
	if (s <= N) {
		cout << ans << endl;
	} else {
		cout << ans - 1 << endl;
	}
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

int main() {
	ll n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	ll cnt = n;
	REP(i, 0, n-1) {
		bool flag = 1;
		REP(j, i, n - 1) {
			if (s[j] != t[j-i]) {
				flag = 0;
				break;
			}
		}
		if (flag) {
			cnt = i;
			break;
		}
	}
	if (n == 0) {
		cout << 2 * n << endl;
	}
	else {
		cout << n + cnt << endl;
	}
}

Measured memory_bytes: 256
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],vis[N],pre[N],f[N],sum[N];
signed main(){
	n=read();sum[0]=1;
	F(i,1,n){
		a[i]=read();
		pre[i]=vis[a[i]];
		vis[a[i]]=i;
		if (pre[i]&&pre[i]<i-1) f[i]=sum[pre[i]];
		sum[i]=(sum[i-1]+f[i])%mod;
	} 
	wrn(sum[n]);
	return 0;
}

Measured memory_bytes: 18176
N, M = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N)
for _ in range(M):
    A, B = map(lambda x:int(x)-1, input().split())
    uf.union(A, B)

ans = 0
for r in uf.roots():
    ans = max(uf.size(r), ans)

print(ans)

Measured memory_bytes: 83028
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  map<char,int> cnt;
  string w;
  cin>>w;
  int n=w.size();
  rep(i,0,n){
   cnt[w[i]]++; 
  }
  bool ans=true;
  for(auto v:cnt){
   if(v.second%2)ans=false; 
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
  int g[101][101] = {0};
  int n, i, j, u, k, v;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &v);
      g[u - 1][v - 1] = 1;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (j != n - 1) {
        printf("%d ", g[i][j]);
      } else {
        printf("%d", g[i][j]);
      }
    }
    putchar('\n');
  }

  return 0;
}



Measured memory_bytes: 2044
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 

// Function to find the number of divisors 
// of all numbers in the range [1, n] 
void findDivisors(int n) 
{ 

	// Array to store the count 
	// of divisors 
	int div[n + 1]; 
	memset(div, 0, sizeof div); 

	// For every number from 1 to n 
	for (int i = 1; i <= n; i++) { 

		// Increase divisors count for 
		// every number divisible by i 
		for (int j = 1; j * i <= n; j++) 
			div[i * j]++; 
	} 

	// Print the divisors
	int sum=0;
	for (int i = 1; i < n; i++) 
	    sum+=div[i];
	cout<<sum;
} 

// Driver code a
int main() 
{ 
	int x;
	cin>>x;
	findDivisors(x);
	return 0; 
} 


Measured memory_bytes: 7428
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

constexpr static int MAXN = 2e5;

int n;
int x[MAXN], y[MAXN];

int64_t total = 0;
int p[MAXN], r[MAXN];

int f(int a) {
    if (p[a] != a)
        p[a] = f(p[a]);
    return p[a];
}

void merge(int a, int b) {
    int ar = f(a);
    int br = f(b);
    if (ar == br)
        return;
    if (r[ar] < r[br])
        p[ar] = br;
    else if (r[ar] > r[br])
        p[br] = ar;
    else {
        p[br] = ar;
        r[ar] = r[ar] + 1;
    }
    total += min(abs(x[a] - x[b]), abs(y[a] - y[b]));
}

int main() {
    cin >> n;
    vector <pair <int, int>> xv, yv;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        xv.push_back({x[i], i});
        yv.push_back({y[i], i});
    }
    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());
    vector <pair <int, pair <int, int>>> edges;
    for (int i = 0; i + 1 < n; i++) {
        edges.push_back({xv[i + 1].first - xv[i].first, {xv[i].second, xv[i + 1].second}});
        edges.push_back({yv[i + 1].first - yv[i].first, {yv[i].second, yv[i + 1].second}});
    }
    sort(edges.begin(), edges.end());

    for (int i = 0; i < n; i++)
        p[i] = i;
    for (auto& e : edges)
        merge(e.second.first, e.second.second);
    cout << total << endl;
}


Measured memory_bytes: 7912
#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second

#define mp make_pair
signed main()
{

	int n,r;cin>>n>>r;
	if(n<10){cout<<r+100*(10-n);}
	else cout<<r<<endl;

		getchar();
	getchar();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

char x,y;
char A,B,C,D,E,F;
int main()
{
	A=10;
	B=11;
	C=12;
	D=13;
	E=14;
	F=15;
	while(~scanf("%c %c",&x,&y))
	{

	if(x > y)
	{
		printf(">");
		break;
	}
	else if(x < y)
	{
		printf("<");
			break;

	}
	else if(x = y)
	{
		printf("=");
			break;

	}
	}
	return 0;

}

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

signed main(){
	string s;cin>>s;
	int k;cin>>k;
	int n=s.size();
	vector<int> v(n);
	for(int i=0;i<n;i++)v[i]=('z'-s[i])+1;
	int r=k;string ans=s;
	for(int i=0;i<n;i++){
		if(r>=v[i] && s[i]!='a'){r-=v[i];ans[i]='a';}
	}	
	ans[n-1]+=(r%26);
	cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

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

ll lcm(ll a, ll b){
    return (a/gcd(a, b))*(b/gcd(a, b))*gcd(a, b);
}

int main(void){
    ll A, B;
    cin>>A>>B;
    cout<<lcm(A, B)<<endl;
    return 0;
}


Measured memory_bytes: 256
//http://arc061.contest.atcoder.jp/tasks/arc061_c
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <queue>
#include <tuple>

using namespace std;

typedef pair<int, int> edge;	//(to, cost)
typedef pair<int, int> P;	//(dist, v)

const int INF = 1000000000;

int N;
vector<edge> G[600000];
int d[600000];

void add_edge(int p, int q, int cost1, int cost2)
{
	G[p].push_back({ q, cost1 });
	G[q].push_back({ p, cost2 });
}

map<pair<int, int>, int> memo;	//key=(v, color), value=id

int getid(int v, int c, int& lastid)
{
	auto it = memo.find(make_pair(v, c));
	if (it!=memo.end()) {
		return it->second;
	}
	int ret = lastid++;
	add_edge(v, ret, 1, 0);
	return memo[make_pair(v,c)] = ret;
};

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

	int lastid = N;
	for (int i = 0; i < M; i++) {
		int p, q, c;
		cin >> p >> q >> c;
		p--, q--;
		int a = getid(p, c, lastid);
		int b = getid(q, c, lastid);
		add_edge(a, b, 0, 0);
	}
	fill(d, d + lastid, INF);
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, 0));
	while (!q.empty()) {
		P p = q.top(); q.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (const auto& e : G[v]) {
			if (d[e.first] > d[v] + e.second) {
				d[e.first] = d[v] + e.second;
				q.push(P(d[e.first], e.first));
			}
		}
	}
	if (d[N - 1] == INF)
		cout << -1 << endl;
	else
		cout << d[N - 1] << endl;
	return 0;
}

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


int main() {
	int n;
	cin >> n;
	double isum = 0.0;
	for (int i = 0; i < n; ++i) {
		double a;
		cin >> a;
		isum += 1.0 / a;
	}

	cout << setprecision(16) << 1.0 / isum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;

  cin >> n;
  cout << ((n - 1) / 111 + 1) * 111 << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func pow(a, b int) int {
	ans := 1
	for i := 0; i < b; i++ {
		ans *= a
	}
	return ans
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	fmt.Println(k * pow(k-1, n-1))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
ll dp[2][100005];
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string l;
	cin >> l;
	int n = l.size();
	dp[0][0] = 2;
	dp[1][0] = 1;
	rep(i, n - 1) {
		if (l[i + 1] == '1') {
			dp[0][i + 1] = dp[0][i] * 2 % MOD;
			dp[1][i + 1] = (dp[1][i] * 3 + dp[0][i]) % MOD;
		} else {
			dp[0][i + 1] = dp[0][i];
			dp[1][i + 1] = dp[1][i] * 3 % MOD;
		}
	}
	cout << (dp[0][n - 1] + dp[1][n - 1]) % MOD << endl;
	return 0;
}

Measured memory_bytes: 2000
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String A = sc.next();
    String B = sc.next();

    sc.close();

    String result = "";

    if (A.equals(B)) {
      result = "EQUAL";
    } else {
      if (A.length() < B.length()){
        result = "LESS";
      } else if (B.length() < A.length()) {
        result = "GREATER";
      } else {
        for (int i = 0; i < A.length(); i++) {
          int a = Integer.valueOf(A.substring(i, i+1));
          int b = Integer.valueOf(B.substring(i, i+1));
          if (a < b) {
            result = "LESS";
            break;
          } else {
            result = "GREATER";
            break;
          }
        }
      }
    }

    System.out.println(result);

  }

}

Measured memory_bytes: 23124
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long count = 0;
        String[] data = new String[100011];
        for(int i=0; i<n; i++){
            String s = sc.next();
            char[] c = s.toCharArray();
            Arrays.sort(c);
            data[i] =  new String(c);
        }
        Arrays.sort(data, 0, n);
        for(int i=0; i<n; i++){
            for(int j=i+1; j<=n; j++){
                if(!(data[i].equals(data[j]))){
                    long aaa= (long) (j-i-1)*(j-i)/2;
                    count += aaa;
                    i=j-1;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 52192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
const int MOD = 1000000007;
//a+b<=l a^b==a+b なるa,bの組
ll dp[100100][2];
int main(){
    string l;
    cin >> l;
    int n = l.size();
    ll dp[n][2];
    dp[0][0]=1;
    dp[0][1]=0;
    rep(i,n){
        if(l[i]=='1'){
            dp[i+1][0]=dp[i][0]*2%MOD;
            dp[i+1][1]=(dp[i][1]*3+dp[i][0])%MOD;
        }else{
            dp[i+1][0]=dp[i][0] %MOD;
            dp[i+1][1]=dp[i][1]*3 %MOD;
        }
    }
    ll ans = (dp[n][0]+dp[n][1]) %MOD;
    cout << ans << endl;
}


Measured memory_bytes: 2048
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	if (ci - cn + 16 > cm) {
		int A = getcha() - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
		return A;
	}
	else {
		int A = *ci++ - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
		return A;
	}
}

int P[100001];
int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

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


	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	for (int i = 1; i < 2 * M; i += 2) {
		int a = Find(getint());
		int b = Find(getint());
		getint();
		if (a == b) continue;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
	}

	int kotae = 0;
	rep1(i, N) {
		if (P[i] < 0) kotae++;
	}
	printf("%d", kotae);

	Would you please return 0;
}

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


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    ll maxn = 0;
    maxn = max(maxn,A*10 + B + C);
    maxn = max(maxn,A + B*10 + C);
    maxn = max(maxn,A + B + C*10);

    cout<<maxn;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N-1);
  for (int i = 0 ; i < N-1; i++) {
    cin >> B.at(i);
  }
  A.at(0) = B.at(0);
  for (int i = 1 ; i < N-1; i++) {
    A.at(i) = min(B.at(i-1), B.at(i));
  }
  A.at(N-1) = B.at(N-2);
  int sum = 0;
  for (int i = 0 ; i < N; i++) {
    sum += A.at(i);
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b="CODEFESTIVAL2016";
int main()
{
	double ans;
	ans=16;
	getline(cin,a);
	for(int i=0;i<=15;i++)
	{
		if(a[i]==b[i]) ans--;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define fi(a,b) for(int i=a;i<=b;++i)
#define fj(a,b) for(int j=a;j<=b;++j)
#define all(x) x.begin(),x.end()
// #define int long long

// ---------------------------------------------------------------------------
// Global Variables
const int mod = 1e9+7;
const int maxn = 2e5 + 9;

// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
void test_case(int tc)
{
	// cout<<"Case #"<<tc<<": ";
	int k;cin>>k;
	string s = "ACL";
	fi(1,k)cout<<s;
}

int32_t main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
		freopen("/home/suryakant/input.txt","r",stdin);
		freopen("/home/suryakant/output.txt","w",stdout);
	#endif
	
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;++tc)test_case(tc);
}

Measured memory_bytes: 3620
// 2014/07/28 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int sum = 0;

	int p1;
	cin >> p1;
	if(p1<40){
		p1 = 40;
	}
	sum += p1;

	int p2;
	cin >> p2;
	if(p2<40){
		p2 = 40;
	}
	sum += p2;

	int p3;
	cin >> p3;
	if(p3<40){
		p3 = 40;
	}
	sum += p3;

	int p4;
	cin >> p4;
	if(p4<40){
		p4 = 40;
	}
	sum += p4;

	int p5;
	cin >> p5;
	if(p5<40){
		p5 = 40;
	}
	sum += p5;

	cout << sum/5 << '\n';

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a, b, c, d, e, f, g, h, i, p;
	int z[100005];
	scanf("%d", &a);
	for (i = 0; i < a; i++)scanf("%d", &z[i]);
	sort(z, z + a);
	b = z[a / 2-1 ]; c = z[a / 2];
	printf("%d\n", c - b);
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)


using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cout << fixed << setprecision(12);

    int n, m;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    cin >> m;
    vint b(m);
    vint c;
    rep(i, m) cin >> b[i];
    set_intersection(all(a), all(b), inserter(c, c.end()));
    for (int i :c) cout << i << endl;
    return 0;
}


Measured memory_bytes: 6440
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    a = [int(input()) - 1 for _ in range(N)]

    cur = 0
    cnt = [-1] * N
    cnt[0] = 0
    while cur != 1:
        c = cnt[cur]

        cur = a[cur]
        if ~cnt[cur]: break
        cnt[cur] = c + 1

    print(cnt[1] if ~cnt[1] else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11048
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1e9
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int n,a,b,c;
int l[10];
int ans;
int cal(int num, int x, int y, int z){
    if(num == n){
        if(min(x,min(y,z)) == 0) return MM;
        else return abs(x-a)+abs(y-b)+abs(z-c);
    }
    int mn = MM;
    mn = min(mn, cal(num+1,x,y,z));
    mn = min(mn, cal(num+1,x+l[num],y,z) + (x > 0 ? 10:0));
    mn = min(mn, cal(num+1,x,y+l[num],z) + (y > 0 ? 10:0));
    mn = min(mn, cal(num+1,x,y,z+l[num]) + (z > 0 ? 10:0));
    return mn;
}
int main(){
    cin >> n >> a >> b >> c;
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    cout << cal(0,0,0,0) << 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;

int main(){
  int n; cin >>n;
  vector<ll> a(n);
  ll total=0, sum=0, ans=1000000000000000000LL;
  rep(i,n) {
    cin >>a[i];
    total+=a[i];
  }
  rep(i,n){
    sum+=a[i];
    if(i+1<n) ans=min(ans,abs(total-2*sum));
  }
  cout << ans << endl;
  return 0;
}

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


int main()
{
	int m, f, r, s;
	int test[50][3];
	int rank[50];

	for (int i = 0; i < 50; i++){
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1){
			s = i;
			break;
		}
		else{
			test[i][0] = m;
			test[i][1] = f;
			test[i][2] = r;

			if (test[i][0] == -1 || test[i][1] == -1){
				rank[i] = -1;
			}
			else{
				rank[i] = test[i][0] + test[i][1];
			}
		}
	}

	for (int i = 0; i < s; i++){
		if (rank[i] == -1){
			cout << "F" << endl;
		}
		else if (80 <= rank[i]){
			cout << "A" << endl;
		}
		else if (65 <= rank[i] && rank[i] < 80){
			cout << "B" << endl;
		}
		else if (50 <= rank[i] && rank[i] < 65){
			cout << "C" << endl;
		}
		else if (30 <= rank[i] && rank[i] < 50){
			if (50 <= test[i][2]){
				cout << "C" << endl;
			}
			else{
				cout << "D" << endl;
			}
		}
		else if (rank[i] < 30){
			cout << "F" << endl;
		}
	}
	
	return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    ll X, Y;
    cin >> X >> Y;

    int ans = 1;
    while ((X *= 2) <= Y)
        ans++;

    cout << ans << endl;

    return 0;
}



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

int main(void){
  string s1, s2;
  cin >> s1 >> s2;
  reverse(s2.begin(), s2.end());
  if(s1 == s2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

void D(vector<vector<pair<int,long long>>> &G, int s, int n, vector<long long> &C){
  vector<bool> state(n,false);
  C[s] = 0;
  priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
  Q.push(make_pair(0,s));
  
  while(!Q.empty()){
    pair<long long,int> p = Q.top();
    Q.pop();
    long long c = p.first;
    int u = p.second;
    state[u] = true;
    if(C[u]<c) continue;
    for(int i=0;i<G[u].size();i++){
      int v = G[u][i].first;
      if(state[v]==true) continue;
      if(C[u]+G[u][i].second<C[v]){
        C[v] = C[u] + G[u][i].second;
        Q.push(make_pair(C[v],v));
      }
    }
  }
  return;
}

int main(){
  int n,m,s,t;
  long long inf = 1000000000000000;
  long long yen = inf;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<pair<int,long long>>> A(n,vector<pair<int,long long>>(0)), B(n,vector<pair<int,long long>>(0));
  for(int i=0;i<m;i++){
    long long u,v,a,b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    A[u].push_back(make_pair(v,a));
    A[v].push_back(make_pair(u,a));
    B[u].push_back(make_pair(v,b));
    B[v].push_back(make_pair(u,b));
  }
  
  vector<long long> Ca(n,inf), Cb(n,inf);
  D(A,s,n,Ca);
  D(B,t,n,Cb);
  
  vector<long long> C(n);
  priority_queue<long long,vector<long long>,greater<long long>> Q;
  for(int i=n-1;i>=0;i--){
    Q.push(Ca[i]+Cb[i]);
    C[i] = Q.top();
  }
  
  for(int i=0;i<n;i++) cout << yen-C[i] << endl;
  return 0;
}


Measured memory_bytes: 20732
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=int(1e6+5);
typedef long long LL;
int n,k;
LL m;
int fa[MAXN];
struct edge {
    int u,v;
    edge() {};
    edge(int U,int V) {u=U,v=V;}
};
vector<edge>G;
int Find(int u) {
    if(u==fa[u])
        return u;
    return fa[u]=Find(fa[u]);
}
void Union(int u,int v) {
    int fu=Find(u),fv=Find(v);
    if(fu!=fv)
        fa[fu]=fv;
    return;
}
int main()
{
    //freopen("tour.in","r",stdin);
    //freopen("tour.out","w",stdout);
    int u,v,op;
    scanf("%d%lld%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=k;i++) {
        scanf("%d%d%d",&u,&v,&op);
        u++,v++;
        if(op==0)
            Union(u,v);
        else
            G.push_back(edge(u,v));
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        if(Find(i)==i)
            cnt++;
    LL mx=(LL)(cnt-1)*cnt/2+n-cnt;
    LL mi=(LL)(G.size()?n:n-1);
    if(mx<m||mi>m) {
        puts("No");
        return 0;
    }
    for(int i=0;i<G.size();i++)
        if(Find(G[i].u)==Find(G[i].v)) {
            puts("No");
            return 0;
        }
    puts("Yes");
}


Measured memory_bytes: 1784
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))
int n;
int a[] = { 3,5,7 };
int func(int a) {
	string s;
	while (a) {
		s = to_string(a % 4) + s;
		a /= 4;
	}
	rep(i, s.size()) {
		if (s[i] == '0')return INF;
		if (s[i] == '1') {
			s[i] = '3';
			continue;
		}
		if (s[i] == '2')s[i] = '5';
		if (s[i] == '3')s[i] = '7';
	}
	if (s != "")return stoll(s);
	else return 3;
}
bool check(int a) {
	string s = to_string(a);
	bool d = false, b = false, c = false;
	rep(i,s.size()) {
		if (s[i] == '3')d = true;
		if (s[i] == '5')b = true;
		if (s[i] == '7')c = true;
	}
	return d&b&c;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	int ans = 0;
	for (int i = 1; ; i++) {
		if (func(i) == INF)continue;
		if (n < func(i)) {
			cout << ans << endl;
			break;
		}
		if (check(func(i)))ans++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

int main() {
    long long a, b, c;
    cin >> a >> b;
    for (int i = 1; i < 4; i++){
        if (a != i && b != i){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256