akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int bB = 9;
const int B = 1 << bB;

int up(int x) {
	return (x + (1 << bB) - 1) >> bB;
}

int down(int x) {
	return x >> bB;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	const int H = up(n);
	vector<int> bv(H, 0), v(n, 0);
	while (q--) {
		int com;
		cin >> com;
		if (com) {
			int x;
			cin >> x; x--;
			printf("%d\n", bv[down(x)] + v[x]);
		}
		else {
			int x, y, val;
			cin >> x >> y >> val; x--;
			for (int i = x; i < y && i < (up(x) << bB); i++) {
				v[i] += val;
			}
			if (up(x) <= down(y)) {
				for (int i = up(x); i < down(y); i++) {
					bv[i] += val;
				}
				for (int i = down(y) << bB; i < y; i++) {
					v[i] += val;
				}
			}
		}
	}
	return 0;
}



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

using namespace std;

typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(3, 0));
    for(auto& x : v)
        for(auto& y : x)
            cin >> y;
    vector<vector<int>> dp(n + 1, vector<int>(3, -1));
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 3; ++j){
            if(dp[i][j] == -1)
                continue;
            for(int k = 0; k < 3; ++k){
                if(j == k)
                    continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + v[i][k]);
            }
        }
    }
    cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

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

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

    int ans = k * power(k - 1, n - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    rep(i, k) {
        if (b <= a) {
            b *= 2;
        }
        else if (c <= b) {
            c *= 2;
        }
        else {
            break;
        }
        //cout << a << " " << b << " " << c << endl;
    }
    if (a < b && b < c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> ans(n+1);
    for(ll x=1;x*x<=n;x++)for(ll y=1;y*y<=n;y++)for(ll z=1;z*z<=n;z++){
        ll now=x*x+y*y+z*z+x*y+y*z+z*x;
        if(now>n) continue;
        ans[now]++;
    }
    FOR(i,1,n+1){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3608
#include<unordered_map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cassert>
#include<vector>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

int main()
{
	int A,B,C;
	cin>>A>>B>>C;
	printf("%d\n",min(C,A+B+1)+B);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <math.h>
#include <vector>
using namespace std;

int main() {
    long int A = 0;
    long int B = 0;
    long int C = 0;
    long int K = 0;
    cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K;
    }else if(K <= (A + B)){
        cout << A;
    }else {
        cout << A + (-1 * (K - A - B));
    }
    return 0;
}

Measured memory_bytes: 3120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var h = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var v = h.Sum();
        var e = h.Zip(h[1..], (h1, h2) => Math.Min(h1, h2)).Sum();

        var ans = v - e;

        WriteLine(ans);
    }
}


Measured memory_bytes: 28292
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] food = new int[m];
        for (int i = 0; i < m; i++) {
            food[i] = 1;
        }

        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            Set<Integer> set = new HashSet();
            for (int j = 0; j < k; j++) {
                set.add(sc.nextInt() - 1);
            }
            for (int j = 0; j < m; j++) {
                if (!set.contains(j)) food[j] = 0;
            }
        }

        int count = 0;
        for (int i = 0; i < m; i++) {
            if (food[i] == 1) count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 22356
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

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

   if(s == "abc") cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<string, int>  cnt;
	int n;
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		cnt[s]++;
	}
	int m;
	cin >> m;
	REP(i, m) {
		string s;
		cin >> s;
		cnt[s]--;
	}
	int ans = 0;
	for (auto a : cnt) {
		ans = max(ans, a.second);
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,k;

int main(){
	cin>>n>>k;
	ll t=n/k,res=t*t*t;
	if(k%2==0){
		ll T=0;
		for(int i=1;i<=n;i++) if(i%k==k/2) T++;
		res+=T*T*T;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, D; cin >> N >> D;
    int X[N][D];
    REP (i, N) {
        REP (j, D) {
            cin >> X[i][j];
        }
    }
    int counter = 0;
    double d = 0;
    REP (i, N) {
        REP (j, N) {
            if (i >= j) continue;
            d = 0;
            REP (k, D) {
                d += pow(X[i][k]-X[j][k], 2);
            }
            d = sqrt(d);
            if (ceil(d) == floor(d)) counter++;

        }
    }
    cout << counter << '\n';
    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
}


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

double dp[3000][3000];
double a[3000];
ll nn;

void solve(ll n, ll m)
{
    // cout << n << m<<"\n";
    if (dp[n][m]!=-1)
    {
        return;
    }
    else
    {
        dp[n][m]=1;
    }
    if (m==0&&n==nn)
    {
        dp[n][m]=1;
        return ;
    }
    if (n+m>nn||n>=nn)
    {
        dp[n][m]=0;
        return;
    }
    if (m==0)
    {
        solve(n+1, m);
        dp[n][m]*=dp[n+1][m]*(1-a[n]);
        // cout << n << " "<< m <<" "<< dp[n][m]<<"\n";
        return;
    }
    solve(n+1, m-1);
    solve(n+1, m);
    dp[n][m]*=dp[n+1][m]*(1-a[n])+dp[n+1][m-1]*a[n];
    // cout << n << " "<< m <<" "<< dp[n][m]<<"\n";
    return;
}

int main()
{
    for (int i = 0; i < 3000; ++i)
    {
        for (int j = 0; j < 3000; j++)
        {
            dp[i][j]=-1;
        }
    }
    cin >> nn;
    for (int i = 0; i < nn; ++i)
    {
        cin >> a[i];
    }
    double ans=0.0;
    for (int i = nn/2+1; i <=nn; ++i)
    {
        solve(0, i);
        ans+=dp[0][i];
    }
    cout <<fixed << setprecision(10)<< ans<<"\n";
    return 0;
}

Measured memory_bytes: 70912
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <complex>
using namespace std;

typedef double D;
typedef complex<D> P;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D cross(P a, P b) {
  return (conj(a)*b).Y;
}

P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;
  return a1 + d1/d2*(a2-a1);
}

P circumcenter(P a, P b, P c) {
  a = (a-c)*0.5;
  b = (b-c)*0.5;
  return c + crosspointLL(a, a*P(1,1), b, b*P(1,1));
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

    P a, b, c;
    a = P(x1, y1);
    b = P(x2, y2);
    c = P(x3, y3);
    P ansxy = circumcenter(a, b, c);
    printf("%.3f %.3f %.3f\n", ansxy.X, ansxy.Y, hypot(ansxy.X-x1, ansxy.Y-y1));
  }

}

Measured memory_bytes: 1264
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=500005;

int bit[N+1];int in[N+1];
int getparent(int i)
{
    return i-(i& -i);
}
int getnext(int i)
{
    return i+(i& -i);
}
int getsum(int i)
{
    int ans=0;
    while(i>0)
    {
        ans+=bit[i];
        i=getparent(i);
    }
    return ans;
}
void update(int i,int v)
{
    while(i<=N)
    {
        bit[i]+=v;
        i=getnext(i);
    }
}



void solve()
{
    int n,q;
    cin>>n>>q;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int l,r;
    vector<pii> qry[n+1];int ans[q];
    for(int i=0;i<q;i++)
    {
        cin>>l>>r;
        qry[r].pb(m1(l,i));
    }
    for(int i=1;i<=n;i++)
    {
        
        if(in[a[i]])
            update(in[a[i]],-1);
        update(i,1);
        for(int j=0;j<qry[i].size();j++)
        {
            ans[qry[i][j].se]=getsum(i)-getsum(qry[i][j].fi-1);
        }
        in[a[i]]=i;
    }
    for(int i=0;i<q;i++)
        cout<<ans[i]<<endl;
    
    
    
}

int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}


Measured memory_bytes: 44184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int>L;
int san(int a,int b,int i){
  int left=-1,right=i;
  while(right-left>1){
    int mid=(left+right)/2;
    if(b-a<L[mid]) right=mid;
    else left=mid;
  }
  if(i-right>0) return i-right;
  else return 0;
}
int main() {
  long long count=0;
  int N;
  cin>>N;
  L.resize(N);
  rep(i,N) cin>>L[i];
  sort(L.begin(),L.end());
  for(int i=1;i<N;i++){
    for(int j=i+1;j<N;j++){
      count+=san(L[i],L[j],i);
    }
  }
  cout<<count;
}

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

int	main()
{
	int64_t	a, b, x;
	cin >> a >> b >> x;
	int64_t	quatient_a, quatient_b;
	quatient_a = a / x;
	quatient_b = b / x;
	int64_t	result;
	result = quatient_b - quatient_a;
	if (a % x == 0)
		++result;
	cout << result << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x = 0,flg = 0;
	scanf("%d", &x);
	for (int i = 0; i < 50000; i++) {
		if (x == (i * 108) / 100) {
			flg = i;
			break;
		}
	}
	if (flg > 0) {
		printf("%d\n",flg);
	}
	else {
		printf(":(\n");
	}

	return 0;
}

Measured memory_bytes: 128
N = int(input())

A = []
for i in range(2):
    *a, = map(int, input().split())
    A.append(a)

def dfs(h, w):
    if h==0 and w==0:
        return A[h][w]
    if h<0 or w<0 or h>=2 or w>=N:
        return 0

    ans = 0
    ans = max(dfs(h-1, w)+A[h][w], dfs(h, w-1)+A[h][w])
    return ans

print(dfs(1, N-1))


Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    int n;
    string s;
    cin >> n >> s;
    
    using PSS = pair<string, string>;
    map<PSS, ll> mp;
    rep(bit, 1 << n) {
        string a;
        rep(i, n) if (bit >> i & 1) a += s[i];
        string b;
        rep(i, n) if (!(bit >> i & 1)) b += s[i];
        mp[PSS(a, b)]++;
    }
    
    ll ans = 0;
    reverse(s.begin(), s.end());
    rep(bit, 1 << n) {
        string a;
        rep(i, n) if (bit >> i & 1) a += s[i];
        string b;
        rep(i, n) if (!(bit >> i & 1)) b += s[i];
        ans += mp[PSS(a, b)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 91904
/*░░░░░░░▄▄▄▀▀▀▄▄███▄
░░░░░▄▀▀░░░░░░░▐░▀██▌
░░░▄▀░░░░▄▄███░▌▀▀░▀█
░░▄█░░▄▀▀▒▒▒▒▒▄▐░░░░█▌
░▐█▀▄▀▄▄▄▄▀▀▀▀▌░░░░░▐█▄
░▌▄▄▀▀░░░░░░░░▌░░░░▄███████▄
░░░░░░░░░░░░░▐░░░░▐███████████▄
░░░░░le░░░░░░░▐░░░░▐█████████████▄
░░░░toucan░░░░░░▀▄░░░▐██████████████▄
░░░░░░has░░░░░░░░▀▄▄████████████████▄
░░░░░arrived░░░░░░░░░░░░█▀██████*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	int s = 0;
	for (int i = 1 ;i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		s ^= (x & 1);
	}
	if (s == 0)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
}



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

int main() {
int N;
  cin>>N;
  vector<int64_t> H(N);
  for(int i=0;i<N;i++){
   cin>>H.at(i);
  }
  int max=0,c=0;
for(int i=0;i<N-1;i++){
  for(int j=0;i+j<N-1;j++){
   if(max>=N-i-1){
     goto l;
   }
    else if(H.at(i+j)>=H.at(i+j+1)){
      c++;
    continue;
    }
    else{
      break;
    }
  }
  if(max<c){
    max=c;
  }
  c=0;
}
 l: cout<<max<<endl;
}


Measured memory_bytes: 1024
s = input()[::-1]
t = input()[::-1]

if len(s) < len(t):
  print('UNRESTORABLE')
  exit(0)

ans = ''
for i in range(len(s) - len(t) + 1):
  for j in range(len(t)):
    if s[i+j] in ('?',t[j]):
      continue
    else:
      break
  else:
    ans = s[:i] + t + s[i+len(t):]
    break
else:
  print('UNRESTORABLE')
  
for c in ans[::-1]:
  print('a' if c=='?' else c,end= '')
print()

Measured memory_bytes: 38384
N = int(input())
S = input()     
all = S.count("R") * S.count("G") * S.count("B")
reigai = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = 2 * j - i
        if k > N-1:
            break
        if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
            reigai += 1
print(all - reigai)            

Measured memory_bytes: 73604
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#define INF 0x7fffffff//1<<31-1
#define IP 3.141592654
#define LINF 9223372036854775807//1<<63-1
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define per(i,a,b) for(long long i=b-1;i>=a;i--)
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
const int maxm=1e8+10;


int main()
{
    char ch[maxn];
    cin>>ch;
    rep(i,0,strlen(ch))
    {
        if(i%2==0)cout<<ch[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 384
import Data.List

type Area = (Int, Int)
type Diagram = [(Int, Char)]

toDiagram :: String -> Diagram
toDiagram = zip [1..]

calcAreas :: Diagram -> Diagram -> [(Area, Int)] -> [(Area, Int)]
calcAreas [] _ zs = zs
calcAreas ((i, c):xs) ys zs
  | c == '_'  = calcAreas xs ys zs
  | c == '\\' = calcAreas xs ((i, c):ys) zs
  | c == '/'  = let prevD = find (\y -> snd y == '\\') ys
                in case prevD of
                  Nothing -> calcAreas xs ys zs
                  Just d -> calcAreas xs (delete d ys) (addArea i d zs)

addArea :: Int -> (Int, Char) -> [(Area, Int)] -> [(Area, Int)]
addArea nEnd (nStart, c) xs = ((nStart, nEnd), nEnd - nStart):xs

summarizeAreas :: [(Area, Int)] -> [(Area, Int)]
summarizeAreas [] = []
summarizeAreas [x] = [x]
summarizeAreas (((s1, e1), v1):((s2, e2), v2):xs)
  | s1 < s2 && e1 > e2 = summarizeAreas (((s1, e1), v1 + v2):xs)
  | otherwise          = ((s1, e1), v1) : summarizeAreas (((s2, e2), v2):xs)

main = do
  input <- getLine
  let result = reverse $ map snd $
                 summarizeAreas $ calcAreas (toDiagram input) [] []
  print $ sum result
  putStrLn $ unwords $ map show ((length result):result)

Measured memory_bytes: 7044
// AOJ 1080: Everything Starts With Your Vote
// 2018.2.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HASHSIZ		150011
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int id)
{
	unsigned i = 0;
	int inc = *s;
	char *p = s;
	HASH *tp;

	while (*p) i = (i<<5) + *p++; i %= HASHSIZ;
	tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	tp->s = s, tp->id = id;
}

int lookup(char *s)
{
	unsigned i = 0;
	int inc = *s;
	char *p = s;
	HASH *tp;

	while (*p) i = (i<<5) + *p++; i %= HASHSIZ;
	tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		tp += inc; if (tp >= hashend) tp -= HASHSIZ;
	}
	return -1;
}

typedef struct { char *nm; int x; char fav; } T;
T tbl[100002], *fav;
char name[100002][22];
int N, M, K, L;

char buf[50], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int cmp(T *a, T *b)
{
	if (a->fav - b->fav) return a->fav - b->fav;
	if (b->x - a->x) return b->x - a->x;
	return strcmp(a->nm, b->nm);
}

int check(int m)
{
	int i, f, x, base, sum;
	char *nm;

	base = K-m;
	if (base < 0) return 0;
	if (base >= N) return 1;
	sum = 0, nm = tbl[base].nm, base = tbl[base].x;
	for (i = 0; i < m; i++) {
		x = base - fav[i].x;
		if (x < 0) continue;
		f = (strcmp(fav[i].nm, nm) <= 0);
		if (!x && f) continue;
		sum += x; if (!f) sum++;
		if (sum > L) return 0;
	}
	return sum <= L;
}

int main()
{
	int i, lo, hi, mi;

	while (fgets(p=buf, 50, stdin) && *p != '0') {
		N = in(), M = in(), K = in(), L = in();
		memset(hash, 0, sizeof(hash));

		for (i = 0; i < N; i++) {
			fgets(name[i], 22, stdin);
			tbl[i].nm = p = name[i];
			while (*p > ' ') p++; *p++ = 0;
			insert(name[i], i);
			tbl[i].x = in(), tbl[i].fav = 0;
		}
		for (i = 0; i < M; i++) {
			fgets(p=buf, 12, stdin);
			while (*p > ' ') p++; *p = 0;
			tbl[lookup(buf)].fav = 1;
		}
		qsort(tbl, N, sizeof(T), cmp);
		N -= M, fav = tbl + N;

		lo = 0;
		hi = M; if (hi > K) hi = K; hi++;
		while (hi-lo > 1) {
			mi = (lo + hi) >> 1;
			if (check(mi)) lo = mi; else hi = mi;
		}
		printf("%d\n", lo);
	}
	return 0;
}


Measured memory_bytes: 9552
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(ins):
    n, k, *h = map(int, ins.split())
    costs = [0]
    for i in range(1, n):
        cost = min([costs[-j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
        costs.append(cost)
    return costs[-1]


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))


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

int main()
{
	int n, i;
	vector<int> stairs;

	while (cin>>n, n) {
		stairs.clear();
		stairs.resize(n+3);
		stairs[0] = 1;
		for (i = 0; i < n; i++) {
			stairs[i+1] += stairs[i];
			stairs[i+2] += stairs[i];
			stairs[i+3] += stairs[i];
		}
		cout<<((stairs[n]+9)/10+364)/365<<endl;
	}
	return 0;
}

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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;

    if((a>c && c>b) || (a<c && c<b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <vector>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L


const int N = 2e5 + 5;

 
int vis[N];


int32_t  main() {

	IOS;

 
	int A, B, C, K;

	cin >> A >> B >> C >> K;

	int sum = min(A, K);

	K -= sum;

	if (K == 0) {
		cout << sum << endl;
	}
	else {
		
		int sum2 = min(B, K);

		K -= sum2;

		if (K == 0) {
			cout << sum << endl;
		}
		else {
			int sum3 = min(C, K);

			sum -= sum3;


			cout << sum << endl;

		}
	}

}

Measured memory_bytes: 3172
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def ccw(a, b, c):
    ax = b[0] - a[0]
    ay = b[1] - a[1]
    bx = c[0] - a[0]
    by = c[1] - a[1]
    t = ax*by - ay*bx;
    if t > 0:
        return 1
    if t < 0:
        return -1
    if ax*bx + ay*by < 0:
        return 2
    if ax*ax + ay*ay < bx*bx + by*by:
        return -2
    return 0

def convex_hull(ps):
    n = len(ps)
    k = 0
    ps.sort()
    ch = [None] * (n*2)
    for i in range(n):
        while k >= 2 and ccw(ch[k-2], ch[k-1], ps[i]) <= 0:
            k -= 1
        ch[k] = ps[i]
        k += 1
    t = k + 1
    for i in range(n-2,-1,-1):
        while k >= t and ccw(ch[k-2], ch[k-1], ps[i]) <= 0:
            k -= 1
        ch[k] = ps[i]
        k += 1

    return ch[:k-1]

def radian(a, b):
    return math.atan2(b[1]-a[1], b[0]-a[0])

def main():
    n = I()
    a = [LI() + [_] for _ in range(n)]
    t = convex_hull(a)
    l = len(t)
    r = [0] * n
    if l == 2:
        r[t[0][2]] = 0.5
        r[t[1][2]] = 0.5
    else:
        for i in range(l):
            r1 = radian(t[i], t[i-1])
            r2 = radian(t[i], t[(i+1) % l])
            k = r2 - r1
            while k < 0:
                k += math.pi * 2
            e = (k-math.pi) / math.pi / 2
            r[t[i][2]] = e

    return '\n'.join(map(str,r))


print(main())


Measured memory_bytes: 66796
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    const long mod = (long)1e9 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        var ts = s.Select(x => (long)x - 'a').ToArray();
        var appearance = new long[26];
        for (int i = 0; i < ts.Length; i++)
        {
            appearance[ts[i]]++;
        }

        var dp = new long[appearance.Length];
        for (int i = 0; i < appearance.Length; i++)
        {
            for (int j = 0; j < dp.Length; j++)
            {
                if (i - j < 1)
                {
                    break;
                }

                dp[i - j] += dp[i - j - 1] * appearance[i] % mod;
                dp[i - j] %= mod;
            }
            dp[0] += appearance[i];
            dp[0] %= mod;
        }
        var k = dp.Aggregate((x, y) => (x + y) % mod);
        Console.WriteLine(k);
    }
}


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

int X;

bool slove() {
    for (int i = 1; i <= 1000000; ++i)
    {
        if(X >= 100*i && X <= 105*i) {
            return true;
        }
    }

    return false;
}


int main() {
    cin >> X;

    cout << slove() << endl;

	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}
using psi = pair<string,int>;
struct Comp{
  bool operator()(psi a, psi b) const{
    if(a.fi.size() == b.fi.size()) return a.fi < b.fi;
    return a.fi.size() < b.fi.size();
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  string s;
  int x;
  map<string,int> m;
  rep(i,n){
    cin >> s >> x;
    m[s] += x;
  }
  vector<pair<string,int>> v(all(m));
  sort(all(v),Comp());
  rep(i,v.size()){
    cout << v[i].fi << ' ' << v[i].se << endl;
  }
  return 0;
}

Measured memory_bytes: 3220
// Problem02.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main()
{
	long long n, a, b;
	cin >> n >> a >> b;

	long ret = n / (a + b) * a +  min(n % (a + b), a);
	cout << ret << endl;

}



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

int main()
{
    int k;
    cin >> k;
    long long int ans = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                ans += gcd(gcd(a,b),c);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3552
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    a = b
    r -= c * pow(f, M - 2, M)
print(r % M)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;
map<char,int>table;
int n;
char c;
int index;
char ans;
int main(){
  while(true){
    cin>>n;
    if(n==0)break;
    index=-1;
    ans='a';//???????????????????????????
    bool f=true;
    table.clear();
    for(int i=0;i<26;i++)table['A'+i]=0;
    for(int i=0;i<n;i++){
      cin>>c;
      if(f==false)continue;
      table[c]++;
      int index1,index2,ma=0;//?????§???????????¨2???????????????
      for(int j=0;j<26;j++){

        //cout<<table['A'+j];
          if(ma<=table['A'+j]){
            index1=j;
            ma=table['A'+j];
          }
      }
      ma=0;
      for(int j=0;j<26;j++){
          if(j!=index1&&ma<=table['A'+j]){
            index2=j;
            ma=table['A'+j];
          }
      }
      //for(int j=0;j<26;j++)cout<<table['A'+j];cout<<endl;
      //cout<<index1<<" "<<index2<<endl;
        if(f&&table['A'+index1]>table['A'+index2]+n-i-1){
          index=i+1;
          //cout<<"I"<<index1<<endl;
          ans='A'+index1;
          f=false;
        }
    }

    if(index==-1)cout<<"TIE"<<endl;


    else cout<<ans<<" "<<index<<endl;
    table.clear();
  }
  return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9)

typedef struct {
	int N;
	int *u;
	int *u_rank;
}union_find;

union_find *make_union_find(int N){
	int i;
	union_find *uf = (union_find *)malloc(sizeof(union_find));
	uf->N = N;
	uf->u = (int *)malloc(sizeof(int) * N);
	uf->u_rank = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		(uf->u)[i] = i;
		(uf->u_rank)[i] = 1;
	}
	return uf;
}

int root_uf(int x, union_find *uf){
	int *u = uf->u;
	if(u[x] == x){
		return x;
	}
	else{
		u[x] = root_uf(u[x], uf);
		return u[x];
	}
}

void combine_uf(int x, int y, union_find *uf){
	int x_root = root_uf(x, uf);
	int y_root = root_uf(y, uf);
	int *u = uf->u;
	int *u_rank = uf->u_rank;
	if(x_root == y_root){
		return;
	}
	else if(u_rank[x_root] < u_rank[y_root]){
		u[x_root] = y_root;
		u_rank[y_root] += u_rank[x_root];
		u_rank[x_root] = 0;
	}
	else{
		u[y_root] = x_root;
		u_rank[x_root] += u_rank[y_root];
		u_rank[y_root] = 0;
	}
}

//xとyが同じ集合に属していれば1を,そうでなければ0を返す
int is_same_union_uf(int x, int y, union_find *uf){
	if(root_uf(x, uf) == root_uf(y, uf)){
		return 1;
	}
	else{
		return 0;
	}
}

//xが属する集合の要素数を返す
int rank_uf(int x, union_find *uf){
	return (uf->u_rank)[root_uf(x, uf)];
}

typedef struct {
	int a;
	int b;
	int w;
}edge;

int min(int a, int b){
	return a <= b ? a : b;
}

edge es[5000];

int compare(const void *a, const void *b){
	edge A = *(edge *)a, B = *(edge *)b;
	return A.w - B.w;
}

int main(){
	int N, M, i, j;
	while(1){
		scanf("%d%d", &N, &M);
		if(N == 0 && M == 0){
			return 0;
		}
		for(i = 0; i < M; i++){
			scanf("%d%d%d", &es[i].a, &es[i].b, &es[i].w);
			es[i].a--;
			es[i].b--;
		}
		qsort(es, M, sizeof(edge), compare);
		int ans = inf;
		for(i = 0; i < M; i++){
			union_find *uf = make_union_find(N);
			for(j = i; j < M; j++){
				combine_uf(es[j].a, es[j].b, uf);
				if(rank_uf(0, uf) == N){
					ans = min(ans, es[j].w - es[i].w);
					break;
				}
			}
		}
		if(ans == inf){
			printf("-1\n");
		}
		else{
			printf("%d\n", ans);
		}
	}
}


Measured memory_bytes: 13144
program abc133d
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n, i
    integer(int32), allocatable:: a(:), ans(:)

    read*, n
    allocate(a(n))
    allocate(ans(n))
    read*, a(:)

    ans(1) = (sum(a(1:n:2)) - sum(a(2:n:2)))
    do i=2,n
        ans(i) = 2*a(i-1) - ans(i-1)
    end do
    print'(*(i0,1x))', ans(:)
end program abc133d

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(all(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

bool f(int x) {
  int res = 0;
  for (int i = 1; i <= x; ++i) {
    if (x%i == 0) res++;
  }
  return res == 8;
}

int main () {
  int n = in();
  int ans = 0;
  for (int i = 1; i <= n; i+=2) {
    if (f(i)) ans++; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
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; }
const long long INF = 1LL << 60;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int n;
ll h[100010];
ll dp[100010];

ll rec(int i){
    if(dp[i]<INF)
        return dp[i];
    if(i==0)
        return 0;

    ll res = INF;
    chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
    if(i>1)
        chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));
    return dp[i] = res;
}
int main()
{
    cin >> n;
    rep(i, n) cin >> h[i];
    rep(i, 100010) dp[i] = INF;
    cout << rec(n - 1) << endl;

    return 0;
    
}

Measured memory_bytes: 6528
from collections import deque

n = int(input())

distance = [-1] * n

edge = [dict() for _ in range(n)]

for _ in range(n-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    edge[u][v] = w
    edge[v][u] = w

D = deque([0])
distance[0] = 0

while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i)

for i in distance:
    print(i)

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

#define int long long
#define rep(i,a,b) for(int i = a; i < b; i++)
const int mod = 1e9 + 7;

int per(int n, int r) {
    int res = 1;
    rep(i,n-r+1,n+1) {
        res *= i;
        res %= mod;
    }
    return res;
}

vector<int> ad[100010];
int ans;
int N,K;
int a,b;

void dfs(int v=0, int pv=-1, int d=0) {
    if (d == 0) {
        ans *= per(K-1, ad[v].size());
    }
    else {
        ans *= per(K-2, ad[v].size() - 1);
    }
    ans %= mod;
    for (int nv: ad[v]) {
        if (nv == pv) continue;
        dfs(nv, v, d+1);
    }
}

signed main() {
    cin >> N >> K;
    rep(i,0,N-1) {
        cin >> a >> b;
        a -= 1;
        b -= 1;
        ad[a].push_back(b);
        ad[b].push_back(a);
    }

    ans = K;
    dfs();
    cout << ans << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <string>
using namespace std;
int min(vector<int>A){
  int min=9999999999;
  for(int i=0;i<(int)A.size();i++){
    if(min>A[i]){
      min=A[i];
    }
  }
  return min;
}

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>W(N-1);
  vector<int>S(N);
  for(int i=0;i<N;i++){
    cin>>S[i];
  }
  for(int i=0;i<N-1;i++){
    int S1=0,S2=0;
    for(int j=0;j<i+1;j++){
      S1+=S[j];
    }
    for(int j=i+1;j<N;j++){
      S2+=S[j];
    }
    W[i]=abs(S1-S2);
  }
  cout<<min(W);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
  int a[3];
  int count1=0;
  int count2=0;
  
  for(int i=0;i<3;i++)
  {
    cin>>a[i];
    if(a[i]==5)
    {
      count1++;
    }
    if(a[i]==7)
    {
      count2++;
    }
  }
  
  if(count1==2)
  {
    if(count2==1)
    {
      cout<<"YES"<<endl;
    }
    else
    {
      cout<<"NO"<<endl;
    }
  }
  else
  {
    cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include<set>
using namespace std;
int main(void){
    set <int> A{1 , 3 , 5 , 7 , 8 , 10 , 12};
    set <int> B{4 , 6 , 9 , 11  };
    int  a ,b ;
    cin >> a >> b;
    if(a == 2 || b == 2){
        cout << "No" << endl;
    }else if(A.count(a)==1&& A.count(b)==1){
        cout <<"Yes" << endl;
    }else if(B.count(a)==1&& B.count(b)==1){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> N >> A;
  cout << N-A+1 << endl;

}


Measured memory_bytes: 256
import heapq
from sys import stdin
n,m = map(int,stdin.readline().split())
*l, = map(lambda x:-int(x),stdin.readline().split())
heapq.heapify(l)
for i in [0]*m:
  a=heapq.heappop(l)
  heapq.heappush(l, -(-a//2))
print(-(sum(l)))

Measured memory_bytes: 14204