akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const long long INF = 1e9;
const long long MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n) for(long long i=0;i<(n);++i)
#define REPR(i,n) for(long long i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

class union_find {
private:
    vector<long long> par;
    vector<long long> ran;
    vector<ll> size;
public:
    union_find(long long n);
    long long find(long long x);
    void unite(long long x, long long y);
    bool same(long long x, long long y);
    ll show_size(long long x);
};

union_find::union_find(long long n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    REP(i,n) par[i] = i;
    REP(i,n) ran[i] = 0;
    REP(i,n) size[i] = 1;
};

long long union_find::find(long long x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::show_size(long long x) {
    if (par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(long long x, long long y) {
    return (find(x) == find(y));
};

int main(long long argc, char const *argv[]) {
    long long n, m;
    cin >> n >> m;
    vector<long long> a(m);
    vector<long long> b(m);
    REP(i,m) {
        long long A, B;
        cin >> A >> B;
        a[i] = --A; b[i] = --B;
    }
    vector<ll> ans(m);
    union_find uf(n);
    ll fai = n*(n-1)/2;
    ans[m-1] = 0;
    for (long long i = m-2; i >= 0; --i) {
        if(!uf.same(a[i+1], b[i+1])) {
            ans[i] = ans[i+1]+(uf.show_size(a[i+1])*uf.show_size(b[i+1]));
            uf.unite(a[i+1], b[i+1]);
        }
        else ans[i] = ans[i+1];
    }
    REP(i,m) cout << fai-ans[i] << endl;
    return 0;
}

Measured memory_bytes: 6016
#include<iostream>
using namespace std;
int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  int point[N+1]={};
  int a=0;
  for(int i=1;i<Q+1;i++){
    cin>>a;
    point[a]++;
  }
  for(int i=1;i<N+1;i++){
    if(point[i]>Q-K)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    for (ll h=1; h<=3500; h++) {
        for (ll n=1; n<=3500; n++) {
            if (4 * h * n > N * (h + n) && (N * h * n) % (4 * h * n - N * (h + n)) == 0) {
                ll w = (N * h * n) / (4 * h * n - N * (h + n));
                cout << h << " " << n << " " << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (i = 0; i < n; ++i)
using namespace std;
void print(vector<long long> v) {
    int i;
    rep(i,v.size()) {
        if (i!=v.size()-1) cout<<v[i]<<" ";
        else    cout<<v[i]<<endl;
    }
}
void input(vector<long long> &v,int n) {
    long long m;
    int i;
    rep (i,n){
        cin>>m;
        v.push_back(m);
    }
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<long long> v;
    int n,i;
    long long ans=1;
    cin>>n;
    input(v,n);
    sort(v.begin(),v.end());
    rep (i,n) {
        if (v[i]<=1000000000000000000/ans) {
            ans*=v[i];
        }
        else {
            ans=-1;
            break;
        }
        if (ans==0) {
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4292
hms :: Int -> [Int]
hms s = [div s (60 * 60), div (mod s (60 * 60)) 60, mod (mod s (60 * 60)) 60]

ft [] = []
ft [x] = show(x)
ft (x:xs) = show (x) ++ ":" ++ ft xs

main = do
  s <- readLn :: IO Int
  putStrLn $ ft $ hms s

Measured memory_bytes: 3608
#include <stdio.h>
int bubbleSort(int A[],int N);



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

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



int bubbleSort( int A[],int N)
{
  int flag = 1;
  int i=0;
  int j;
  int c;
  while(flag == 1){
    flag = 0;
    for( j = N-1; j >= 1; j--){
      if( A[j] < A[j-1]){
	
	c = A[j];
	A[j] = A[j-1];
	A[j-1] = c;
	flag = 1;
	i++;
	
      }
    }
  }

  return i;
}



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


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  string s1, s2;
  cin >> n;

  ans = inf;
  FOR(i, 1, 100001) {
	if ((double)n / i != n / i) continue;
	tmp = n / i;
	s1 = to_string(i);
	s2 = to_string(tmp);
	ma = max(s1.length(), s2.length());
	ans = min(ans, ma);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b/gcd(a,b)
for i in sys.stdin.readlines():
    a,b=map(int,i.split())
    print "{} {}".format(gcd(a,b),lcm(a,b))

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

int main() {
    bool used[1000001];
    ll s;
    std::cin >> s;
    ll result = 1;
    used[s] = true;
    while(true){
        result++;
        if(s%2==0){
            s = s/2;
        }else{
            s = 3*s+1;
        }
        if(used[s]){
            std::cout << result << std::endl;
            return 0;
        }else{
            used[s] = true;
        }
    }
    
}



Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstdio>
#include<string.h>
#include<vector>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=11000;
//vector <vector<int> > a(1,vector<int >(1));

bool pdfh(ll a,ll b,ll c){
    if(a!=b&&b!=c&&a!=c){
        if(a+b>c&&b+c>a&&a+c>b){
            return true;
        }
    }
    return false;
}

int main ()
{
    //std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[N];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int t=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(pdfh(a[i],a[j],a[k]))
                {
                    t++;
                }
            }
        }
    }
    cout<<t<<endl;
    return 0;
}

/*

*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x,val) memset(x, val, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> ;
#define pal pair < ll, ll> ;
#define vi vector <int> ;
#define vl vector < ll > ;
#define vpai vector < pii > ;
#define prec(val,x) cout<<fixed<<setprecision(x)<<val;

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 305;
int n;

ll dp[sze][sze][sze];

ll calc(int one,int two,int three){
    if(one<0||two<0||three<0) return 0;
    if(one==0&&two==0&&three==0) return 0;
    if(dp[one][two][three]>0) return dp[one][two][three];
    int rem=one+two+three;
    ll exp=n+one*calc(one-1,two,three)+two*calc(one+1,two-1,three)+
            three*calc(one,two+1,three-1);
    return dp[one][two][three]=exp/rem;
}

void solve() {
    //int n;
    cin>>n;
    int arr[n];
    int x=0,y=0,z=0;
    rep(i,n) {
        cin>>arr[i];
        if(arr[i]==1) x++;
        if(arr[i]==2) y++;
        if(arr[i]==3) z++; 
    }
    prec(calc(x,y,z),14);
    cout<<endl;

}

int main() {
    IOS;

    int t = 1;
    //cin >> t;
    while (t--) {
        mem(dp,-1);
        solve();
    }

  return 0;
}

Measured memory_bytes: 447188
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD 1000000007
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

ll modpow(ll a,ll n){
    ll res=1;
    while(n>0){
        if(n&1){res*=a;res%=MOD;}
        a*=a;a%=MOD;
        n>>=1;
    }
    return res;
}   
ll nCr(ll n,ll r){
    ll res,x,y;
    res=x=y=1;
    for(int i=0;i<r;i++){
        x*=(n-i);x%=MOD;
        y*=(r-i);y%=MOD;
    }
    res=modpow(y,MOD-2)%MOD;
    res=(res*x)%MOD;
    return res;
}


int main(){
    ll n,a,b;scanf("%lld %lld %lld",&n,&a,&b);

    ll x=modpow(2,n)-1;
    ll y=nCr(n,a)+nCr(n,b);
    y%=MOD;
    printf("%lld\n",(modpow(2,n)-1-y+MOD)%MOD);
    
      
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;
#define MOD 1000000007LL

ll pow(ll a, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

ll fact(int n) {
  ll res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i % MOD;
  return res;
}

ll comb(ll n, ll r) {
  ll tmp = 1;
  for (int i = 0; i < r; i++) {
    tmp = tmp * n % MOD;
    n--;
  }
  ll inv_r = pow(fact(r), MOD-2);
  return tmp * inv_r % MOD;
}

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

  ll n, a, b; cin >> n >> a >> b;
  ll tmp = (comb(n, a) + comb(n, b)) % MOD;
  ll ans = pow(2, n) - 1 - tmp;
  cout << (ans < 0 ? ans + MOD : ans) << "\n";
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  ll n, k;
  cin >> n >> k;
  vector<double> p(2e5 + 10);
  rep(i, n) {
    cin >> p[i];
    p[i] = (p[i]+1)/2;
  }
  vector<double> dp(2e5+10, 0);
  rep(i, k) {
    dp[0] += p[i];
  }
  double mx = dp[0];
  for (int i = 0; i+1 <= n-k; i++) {
    dp[i+1] = dp[i] - p[i] + p[i+k];
    mx = max(mx, dp[i+1]);
  }
  
  printf("%.10lf\n", mx);
  return 0;
}

Measured memory_bytes: 3328
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,W;cin>>n>>W;
  vl w(n),v(n);
  rep(i,n)cin>>w[i]>>v[i];
  ll dp[n+1][n+1][310];
  rep(i,n+1){
    rep(j,n+1){
      rep(k,310)dp[i][j][k]=0;
    }
  }
  rep(i,n){
    rep(j,n+1){
      rep(k,310){
        if(j!=0&&k-(w[i]-w[0])>=0)dp[i+1][j][k]=max(dp[i][j-1][k-(w[i]-w[0])]+v[i],dp[i][j][k]);
        else dp[i+1][j][k]=dp[i][j][k];
      }
    }
  }
  ll MAX=0;
  rep(j,n+1){
    rep(k,310){
      if(j*w[0]+k<=W)MAX=max(MAX,dp[n][j][k]);
    }
  }
  //rep(i,n+1){
    //rep(j,n+1){
      //rep(k,12)cout<<dp[i][j][k]<<" ";
      //cout<<endl;
    //}
    //cout<<endl;
  //}
  cout<<MAX<<endl;
}

Measured memory_bytes: 24960
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll x;
  cin>>x;
  if(x>=30)cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
#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>;

const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int N; cin >> N;
    vector<ll> dp(N,INF);
    vector<ll> H(N);
    rep(i,N) cin >> H.at(i);
    dp.at(0) = 0;
    for(int i = 1; i < N; i++) {
        chmin(dp[i],dp[i-1]+abs(H[i]-H[i-1]));
        if(i > 1) chmin(dp[i],dp[i-2]+abs(H[i]-H[i-2]));
    }
    cout << dp[N-1] << endl;
}

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

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

	long long sum=0;

	for (int i=1; i<n+1;i++)
	{
		if (i%15 == 0) continue;
		else if ( i%3 == 0) continue;
		else if ( i%5 == 0) continue;
		else
		{
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>

int n, m;
std::vector<std::vector<char>> N, M;

bool check(int a, int b) {
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < m; ++j) {
            //std::cout << i << " " << j << std::endl;
            if(N[i + a][j + b] != M[i][j])
                return false;
        }
    }
    
    return true;
}

int main() {
    std::cin >> n >> m;
    
    N.resize(n, std::vector<char>(n));
    M.resize(m, std::vector<char>(m));
    
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            std::cin >> N[i][j];
        }
    }
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < m; ++j) {
            std::cin >> M[i][j];
        }
    }
    
    for(int i = 0; i <= n - m; ++i) {
        for(int j = 0; j <= n - m; ++j) {
            //std::cout << i << " " << j << std::endl;
            if(check(i, j)) {
                std::cout << "Yes" << std::endl;
                
                return 0;
            }
        }
    }
    
    std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>
#define e 1000000007
#define PI 3.141592653589793

typedef  long long ll;

int int_cmp(const void *a, const void *b){ 
    const int *ia = (const int *)a;
    const int *ib = (const int *)b;
    return *ia  - *ib; 
} 


ll int_cmp1(const void *a, const void *b){ 
    const int *ia = (const int *)a;
    const int *ib = (const int *)b;
    return *ia  - *ib; 
} 



int max(int a,int b){
	if(a<b)
		a=b;
	return a;	
}

int min(int a,int b){
	if(a>b)
		a=b;
	return a;	
}

int absolu(int n){
	if(n<0)
		n*=-1;
	
	return n;	
}


void solve(){ 
	int x;
	scanf("%d",&x);
	if(x==1)
		printf("0\n");
	else
		printf("1\n");	
}

int main(){
 /* int t;
	scanf("%d",&t);
	
	while(t--)*/
		solve();
	
	return 0;
}	
	

Measured memory_bytes: 1628
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>
#include <typeinfo>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {

	string str;
	cin >> str;
	int keta = str.length();
	int result = 0;
	int memo = keta - 1;
	int memo2 = 0;

	bool shouldChange = false;
	for (int i = keta - 1; i > 0; --i) {
		if (ctoi(str[i]) <= 7 && ctoi(str[i-1]) >0) {
			shouldChange = true;
			memo = i;
		}
	}
	if (shouldChange) {
		str[memo - 1]--;

		for (int i = memo; i < keta; ++i) {
			str[i] = '9';
		}
	}
	for (int i = 0; i < keta; ++i) {
		result += ctoi(str[i]);
	}
	cout << result;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
using namespace std;
#define M 200000

long long cnt = 0;
int A[M], L[M / 2 + 1], R[M / 2 + 1], n;
 
void merge(int l, int m, int r){
    int n1 = m - l, n2 = r - m, i, j;
    for(i = 0;i < n1;i++)L[i] = A[i + l];
    for(i = 0;i < n2;i++)R[i] = A[i + m];
    i = j = 0;
    for(int k = 0;k < r - l;k++){
        if(j == n2 || (i < n1 && L[i] <= R[j]))A[k + l] = L[i++];
        else A[k + l] = R[j++], cnt += n1 - i;
    }
}

void mergeSort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}
 
main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
	mergeSort(0, n);
	printf("%lld\n", cnt);
}

Measured memory_bytes: 4752
N = int(input())
S = list(input())


A = []
for i in range(N):
  if S[i] == "W":
    A.append(1)
  elif S[i] == "E":
    A.append(-1)
    
R = [A[0]]
for i in range(1,N):
  R.append(R[-1] + A[i])


saidai = 0
for i in range(N):
  if i == 0:
    if saidai < R[N-1] - R[0]:
      saidai = R[N-1] - R[0]
      flag = i
  elif i == N-1:
    if saidai < -R[N-2]:
        saidai = -R[N-2]
        flag = i
  else:
    if saidai < (R[N-1] - R[i]) - R[i-1]:
        saidai = (R[N-1] - R[i]) - R[i-1]
        flag = i  
    
ans = A[:flag].count(1) + A[flag+1:].count(-1)

print(ans)




Measured memory_bytes: 22400
//2019/3/14
import java.util.ArrayList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		String s = sc.next();

		int max = 0;

		int a, j;

		ArrayList<Integer> c = new ArrayList<>();

		ArrayList<Integer> cc = new ArrayList<>();

		for(int i=0;i<N;i++) {

			j = 0;

			a = 0;

			while(j<=i) {

				int b = s.charAt(j);

				c.add(b);

				j++;
			}

			while(j<N) {

				int  d = s.charAt(j);

				//System.out.println((char)cc);

				if(c.contains(d) && !cc.contains(d)) {

					a++;

					cc.add(d);
				}

				j++;

			}

			if(a>max) max = a;

			c.clear();

			cc.clear();
		}

		System.out.println(max);
	}

}


Measured memory_bytes: 25300
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

typedef pair<int, int> P;
typedef long long ll;

int sz[4] = {1, 2, 4, 8}, cij[4];

int main()
{
  REP(i, 4) scanf("%d", &cij[i]);
  ll kol;
  scanf("%lld", &kol);

  kol *= 4;

  ll mn[4];
  
  REP(i, 4) {
    ll tmp = -1;
    REP(j, i+1) {
      ll ncij = cij[j] << (i-j);
      if (ncij < tmp || tmp == -1)
	tmp = ncij;
    }
    mn[i] = tmp;
  }

  ll rje = kol / 8 * mn[3];
  kol %= 8;
  
  REP(i, 4)
    if (kol >> i & 1)
      rje += mn[i];

  printf("%lld\n", rje);
    
  return 0;
}


Measured memory_bytes: 256
from collections import deque
s = list(input())
q = int(input())
rv = False
fr = deque()
re = []
for i in range(q):
    t = input().split(' ')
    if t[0] == '1':
        rv = True if not rv else False
    else:
        if t[1] == '1' and not rv or t[1] == '2' and rv:
            fr.appendleft(t[2])
        else:
            if t[1] == '1' and rv or t[1] == '2' and not rv:
                re.append(t[2])
if rv:
    re.reverse()
    s.reverse()
    fr.reverse()
    print(''.join(re + s) + ''.join(fr))
else:
    print(''.join(fr) + ''.join(s + re))

Measured memory_bytes: 7564
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える定数
#define N_MAX 200


//変数
int Q;
vector<pair<int, int>> lr;
vector<bool> isPrime(100001, true);
vector<int> sumPrime(100001, 0);

//サブ関数
//入力
void input() {
	cin >> Q;
	int tmp1, tmp2;
	REP(i, Q) {
		cin >> tmp1 >> tmp2;
		lr.push_back(make_pair(tmp1, tmp2));
	}
}


//計算
void calc() {
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, 100001) {
		if (isPrime[i]) {
			int num = i * 2;
			while (num < 100001) {
				isPrime[num] = false;
				num += i;
			}
		}
	}
	for (int i = 3; i < 100001; i += 2) {
		sumPrime[i] = sumPrime[i - 2] + (isPrime[i] && isPrime[(i + 1) / 2] ? 1 : 0);
	}
}


//出力
void output() {
	REP(i, Q) {
		int l = lr[i].first;
		int r = lr[i].second;
		DEBUGING(sumPrime[r] - sumPrime[l] + (isPrime[l] && isPrime[(l + 1) / 2] ? 1 : 0));
	}
}

//デバッグ
void debug() {
	//REP(i, 20)DEBUGING(i<<" "<<isPrime[i]);
	int N;
	cin >> N;

	
}


//メイン関数
int main() {

	input();
	calc();
	output();
	debug();

	return 0;
}


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

class Pond {
    
public:
    
    Pond(int begin_pos, int area){
        this->begin_pos = begin_pos;
        this->area = area;
    }
    
    int begin_pos;
    int area;
    
};

int main() {
    
    string s;
    cin >> s;
    
    stack<int> S1;
    stack<Pond> S2;
    
    unsigned long sn = s.length();
    for(int i=0; i<sn; i++){
        char c = s[i];
        if(c=='\\'){
            
            S1.push(i);
            
        }else if(c=='/'){
            
            if(S1.empty()) continue;
            
            int p = S1.top();
            S1.pop();
            
            int area = i - p;
            while( !S2.empty() ){
                Pond p2 = S2.top();
                if( p2.begin_pos < p ) break;
                area += p2.area;
                S2.pop();
            }
            
            S2.push(Pond(p,area));
            
        }
    }
    
    int sn2 = S2.size();
    int sum_area = 0;
    int r[sn2];
    for(int i=sn2-1; i>=0; i--){
        r[i] = S2.top().area;
        sum_area += S2.top().area;
        S2.pop();
    }
    
    cout << sum_area << endl;
    cout << sn2;
    for(int i=0; i<sn2; i++){
        cout << " " << r[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3220
// mitsui_sumitomo_2019_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2){
        print("1");
    } else {
        print("0");
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353                                                                          
#define vi vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end() 
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll>,greater<ll>>
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce               \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                    \
    cout.tie(0);

using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

const int maxN=8*1e6;
bool prime[maxN+1];
ll mpow(ll base,ll exp);
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);
ll modInverse(ll n);
ll nCr(ll n, ll r);
void sieve();
ll myxor(ll a,ll b);

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

void solve(){
    ll n;
    cin >> n;
    vi a(n);
    loop(i,0,n) cin >> a[i];

    vi p(n);
    p[0]=a[0];
    loop(i,1,n){
        p[i]=p[i-1]+a[i];
        p[i]%=mod;
    }
    ll ans=0;
    for(int i=n-1;i>=1;i--){
        p[i-1]%=mod;
        ans+=a[i]*p[i-1];
        ans%=mod;
    }

    cout << ans << endl;

}

int32_t main(){
    SpeedForce


    int t;
    t=1;
    //cin >> t;
    cerr << endl;
    while (t--){
        //cout << fixed << setprecision(10);
        solve();
    }
    cerr << "Time : " << 1000*((double)clock())/ (double)CLOCKS_PER_SEC << "ms" << endl;
}   

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

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

ll modInverse(ll n) { 
    return mpow(n, mod-2); 
}
 
ll nCr(ll n, ll r){ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
    return ((fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod)%mod)%mod; 
}

ll myxor(ll a,ll b){
    return (a|b)&(~a|~b);
}

void sieve(){
    memset(prime,true,sizeof(prime));
    for(int p=2;p*p<maxN;p++){
        if(prime[p]){
            for(int i=2*p;i<maxN;i+=p){
                prime[i]=false;
            }
        }
    }
}

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int n,s,j,tmp,sum;
long long ans;
int a[N];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++){
		sum-=a[i-1];
		tmp=tmp^a[i-1];
		while(j+1<=n&&tmp^a[j+1]==sum+a[j+1]){
			sum+=a[++j];
			tmp=tmp^a[j];
			if (sum!=tmp){
				sum-=a[j];
				tmp=tmp^a[j];
				j--;
				break;
			}
		}	
		ans+=j-i+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void){
    ll a,b;
    string s,num;
    num = "0123456789";
    cin >> a >> b >> s;
    if ((a + b + 1 == s.size()) && s[a] == '-'){
        s[a] = '0';
        for(ll i = 0;i < s.size();i++){
            bool f = false;
            for(ll j = 0;j < 10; j++){
                if(s[i] == num[j]){
                    f = true;
                    break;
                }
            }
            if(f){
                continue;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
    }else{
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.List

main = do
       t1<-getLine
       t2<-getLine
       let (n:x:[])=map read (words t1)::[Int]
           xs=map read (words t2)::[Int]
           ys=scanl1 (+) $ sort xs
       putStrLn $ show $ if (maximum ys)<x then (n-1) else length $ filter (<=x) $ ys

Measured memory_bytes: 1020
def nCk(_n,_k):
  return fact[_n]*pow(fact[_k],m-2,m)*pow(fact[_n-_k],m-2,m)%m

fact=[1]*2005
for i in range(1,2004):
  fact[i]=fact[i-1]*i

n,k=map(int,input().split())
m=10**9+7

for i in range(1,k+1):
  print(nCk(n-k+1,i)*nCk(k-1,i-1)%m if n-k>=i-1 else 0)


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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    sum += abs(A[i]);
  }

  sort(A.begin(), A.end());
  if (A[0] >= 0) {
    cout << sum - A[0] * 2 << endl;

    int x = A[0];
    for (int i = 1; i < n; i++) {
      if (i == n - 1) {
        cout << A[i] << " " << x << endl;
      }
      else {
        cout << x << " " << A[i] << endl;
      }
      x -= A[i];
    }
  }
  else if (A[n - 1] <= 0) {
    cout << sum + A[n - 1] * 2 << endl;

    int x = A[n - 1];
    for (int i = 0; i < n - 1; i++) {
      cout << x << " " << A[i] << endl;
      x -= A[i];
    }
  }
  else {
    cout << sum << endl;

    int x = A[0];
    bool change = false;
    for (int i = n - 1; i > 0; i--) {
      if (A[i - 1] >= 0) {
        cout << x << " " << A[i] << endl;
        x -= A[i];
      }
      else {
        if (change) {
          cout << x << " " << A[i] << endl;
          x -= A[i];
        }
        else {
          cout << A[i] << " " << x << endl;
          x = A[i] - x;
          change = true;
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll x;
  cin >> x;
  
  ll res = 0;
  res += x / 500 * 1000;
  x = x - (x / 500) * 500;

  cout << res + x / 5 * 5 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
typedef long long LL;
const int N=100+5;
const int INF=0x3f3f3f3f;
const double eps=1e-6;
struct Node
{
    double w;
    double cnt;
    bool operator < (const Node&m)const
    {
        return w-m.w<eps;
    }
} a[4];
int main()
{
    LL q,h,s,d;
    LL n;
    while(cin>>q>>h>>s>>d>>n)
    {
        if(h>2*q) h=2*q;
        if(s>2*h) s=2*h;
        if(d>2*s) d=2*s;
        printf("%lld\n",(LL)(n/2*d+n%2*s));
    }
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;
VL x;

int main() {
    cin >> N >> K;
    REP(i, N) x.emplace_back(IN());
    ll ans = LINF;
    REP(i, N - K + 1) {
        ll tmp = min(abs(x[i] - x[i + K - 1]) + abs(x[i]), abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]));
        ans = min(ans, tmp);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1400
#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 n, m;
  bool prime = true;
  cin >> n;
  
  if ( n== 1 ){
    cout << 0 << endl;
    return 0;
  }
  
  ll ans = 0;
  for (ll i=2; i*i <= n; i++){
    if (n % i != 0) continue;
    
    prime = false;
    ll expo = 0;
    while (n % i == 0){
      n /= i;
      expo ++;
    }
    ll j = 1;
    while ( expo >= j*(j+1)/2 ) j++;
    ans += j-1;
  }
  if (n!=1) ans += 1;
  if (prime) ans = 1;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        long A = scan.nextLong();
        long B = scan.nextLong();

        if(A > B) {
            long tmp = A;
            A = B;
            B = tmp;
        }
        long gcd = gcd(A, B);
        if(gcd == 1) {
            os.println("1");
        } else {
            long x = gcd;
            long previ = 0;
            long answer = 1;

            if(x%2 == 0)
                answer++;

            while(x%2 == 0) {
                x /= 2;
            }

            for (long i = 3 ; i <= Math.sqrt(x); i += 2) {
                if (x % i == 0)
                    answer++;
                while(x%i == 0) {
                    x /= i;
                }
            }

            if(x > 2)
                answer++;

            os.println(answer);

        }

    }



    static public long gcd(long a, long b) {
        while(a > 0) {
            long tmpa = a;
            a = b % a;
            b = tmpa;
        }
        return b;
    }

}

Measured memory_bytes: 22612
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int A, B;
	cin >> A >> B;
	if (A <= 9 && B <= 9) {
		cout << A*B << endl;
	}
	else {
		cout << -1 << endl;
	}
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	y /= 1000
	if y < n {
		fmt.Println("-1 -1 -1")
		return
	}
	sub := y - n
	for a := 0; a <= sub/9; a++ {
		tmp := sub - 9*a
		if tmp%4 == 0 {
			b := tmp / 4
			c := n - a - b
			if c >= 0 {
				fmt.Printf("%d %d %d\n", a, b, n-a-b)
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}

Measured memory_bytes: 512
import bisect
n,m,k = map(int,input().split())

a = [0 for _ in range(n)]
b = [0 for _ in range(m)]

a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]

mx = sum(a)+sum(b)

a_sum = [0 for _ in range(n)]
b_sum = [0 for _ in range(m)]

sm = 0
for i in range(n):
    sm += a[i]
    a_sum[i] = sm

sm = 0
for i in range(m):
    sm += b[i]
    b_sum[i] = sm


#print(a_sum)
def solve():
    if(k >= mx):
        print(n+m)
        return
    
    
    caca = bisect.bisect_right(b_sum,k)
    
    for i in range(n):
        a_a = a_sum[i]
        rd = k - a_a
        if(rd < 0):
            continue

        b_b = bisect.bisect_right(b_sum,rd)
        caca_tmp = i + 1 + b_b
        caca = max(caca,caca_tmp)
        #print(i,b_b,rd)
    
    print(caca)



solve()


Measured memory_bytes: 47488
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
#pragma endregion Macros

int N, M, Q;
vector<vector<int>> abcd;

ll score(vector<int> &A){
    ll res = 0;
    rep(i, Q)
    {
        if(A[abcd[i][1]-1] - A[abcd[i][0]-1] == abcd[i][2]){
            res += abcd[i][3];
        }
    }
    return res;
}

ll dfs(vector<int> &A, int i){
    if(i==N){
        return score(A);
    }

    ll res = 0;
    FOR(j, i==0?1:A[i-1], M+1){
        A[i] = j;
        chmax(res, dfs(A, i + 1));
    }

    return res;
}


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

    abcd = vector<vector<int>>(Q, vector<int>(4));

    rep(i, Q) cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];

    vector<int> A(N,1);

    cout << dfs(A, 0);

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 10 ;
int a[N] ;
vector<int> v[N] ;
int n , vis[N] , dep[N] , b[N] ;
int d[4] = {0 , 1 , 2 , 3} ;
void dfs(int u , int fa , int d)
{
	dep[u] = d ;
	vis[u] = 1 ;
	for(auto x : v[u])
	 {
		 if(x == fa || vis[x]) continue ;
		 dfs(x , u , d + 1) ;
	 }
}
int main()
{
	scanf("%d" , &n) ;
	for(int i = 1 , x , y ; i < n ;i ++)
	 scanf("%d%d" , &x , &y) , v[x].push_back(y) , v[y].push_back(x) ;
  dep[1] = 1;
	dfs(1 , -1 , 1) ;
  int c = 0 ;
	for(int i = 1; i <= n ;i ++)
	 c += dep[i] % 2 ;
  b[3] = n / 3 , b[1] = n / 3 + (n % 3 >= 1) , b[2] = n / 3 + (n % 3 >= 2) ;
	if(c <= n / 3 || (n - c) <= n / 3)
	 {
		 int y = 1 ;
		 if(c > n / 3) y = 0 ;
		 for(int i = 1 ; i <= n ;i ++)
		  if(dep[i] % 2 == y) a[i] = 3 ;
			else
			{
				if(b[1]) a[i] = 1 , b[1] -- ;
				else if(b[2]) a[i] = 2 , b[2] -- ;
				else if(b[3]) a[i] = 3 , b[3] -- ;
			}
	 }
	 else
	 {
		 for(int i = 1 ;i <= n ;i ++)
		  {
				if(dep[i] % 2)
				 {
					 if(b[1]) a[i] = 1 , b[1] -- ;
					 else if(b[3] ) a[i] = 3 , b[3] -- ;
				 }
				else
				 {
					 if(b[2]) a[i] = 2 , b[2] -- ;
					 else if(b[3]) a[i] = 3 , b[3] -- ;
				 }
			}
	 }
	 b[1] = 0 , b[2] = 0 , b[3] = 0 ;

	 for(int i = 1; i <= n ;i ++)
			 a[i] = d[a[i]] + ((b[a[i]] ++ ) * 3 ) , cout << a[i] << " " ;
	puts("") ;
	return 0 ;
}


Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S,T;
  cin>>S;
  cin>>T;
  int ans=0;
  for(int i=0;i<3;i++) {
    if(S.at(i)==T.at(i)) {
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<string> vec(N);
  
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  int count=1;
  
  for (int i=0; i<N-1; i++){
    if (vec.at(i) < vec.at(i+1)){
      count++;
    }
  }
  
  cout << count << endl;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    //int f=0;
    int ans=0;
    int l=s.length();
    vector<string>sa;
    for(int i=0;i<l;i++)
    {
        int cnt=0;
        string temp;
        int jj=i;
        while(cnt<l)
        {
            temp.push_back(s[jj]);
            cnt++;
            jj=(jj+1)%l;
        }
        sa.push_back(temp);
    }
    int f=0;
    for(int i=0;i<sa.size();i++)
    {
        string p=sa[i];
        if(p==t)
        {
            f=1;
            break;
        }

    }
    if(f)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt int Q[100005]={0}
#define mp make_pair
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<int>()) 
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(int i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(int i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=mpowe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
bool check(string s)
{
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=s[n-1-i])
            return false;
    }
    return true;
}
int main()
{
    fastio();
   
    double n;
    cin>>n;
    n=n/3;
    n = n*n*n;
    cout<<fixed<<setprecision(10)<<n<<endl;
}

Measured memory_bytes: 256
<?php
/*
	AOJ 0159
	@kankichi573
*/
while(fscanf(STDIN,"%d",$n) && $n)
{
  $riso_bmi=10000;
	
  for($i=0;$i<$n;$i++)
    {
      fscanf(STDIN,"%d %d %d",$bango,$height,$weight);
      $height /= 100.0;
      $bmi = $weight*1.0/$height/$height;
      //fprintf(STDOUT,"%f %f %f\n",$bmi,$height,abs($bmi-22));
      if(abs($bmi-22) < abs($riso_bmi-22))
	{
	  $riso_bmi=$bmi;
	  $riso_no =$bango;
	}
    }
  fprintf(STDOUT,"%d\n",$riso_no);
 }
  return(0);
?>

Measured memory_bytes: 6592
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;

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

  cout << x/3 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=3e3+10;
const int mod=1e9+7;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
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; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,f[N][N][2];
int main() {
    cin>>n>>m;
    f[0][0][1]=1;
    for(int i=1;i<=n;i++) f[0][i][0]=1;
    for(int i=0;i<m;i++)
        for(int j=0;j<=n;j++)
            for(int k=0;k<2;k++)
                if(f[i][j][k]) {
                    if(j) inc(f[i+1][j-1][k|(j==1)],f[i][j][k]);
                    if(j) inc(f[i+1][j][k|(j==1)],f[i][j][k]);
                    if(n-j) inc(f[i+1][j][k],f[i][j][k]);
                    if(n-j) inc(f[i+1][j+1][k],f[i][j][k]);
                }
    int ans=0;
    for(int i=0;i<=n;i++) inc(ans,f[m][i][1]);
    printf("%d\n",ans);
    return 0;
}


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

int N;
double P;

struct edge {
	int to;
	double cost;
};
vector<edge> G[100000];

double s;

double dfs(int v, int par) {
	double sum = s;
	for(auto e : G[v]) {
		if(e.to == par) continue;
		sum += P * (e.cost + dfs(e.to, v));
	}
	return sum;
}

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

	cin >> P >> N;
	for(int i = 0; i < N - 1; i++) {
		int x, y;
		double c;
		cin >> x >> y >> c;
		x--, y--;
		G[x].push_back({ y, c });
		G[y].push_back({ x, c });
	}

	s = dfs(0, -1);
	cout << fixed << setprecision(15) << dfs(0, -1) << endl;
}

Measured memory_bytes: 16560