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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    ll x = 0, k = 0, d = 0;
    cin >> x >> k >> d;

    if(x < 0){
        x = abs(x);
    }

    if(x/d > k) cout << x - k*d << "\n";
    else{
        ll cnt = k - x/d;
        ll a = x%d, b = d - x%d;
        if(cnt%2) cout << b << "\n";
        else cout << a << "\n";
    }

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e9+7;
int main() {
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i, t) cin >> a[i];
    sort(a.begin(), a.end());
    rep(j, k) {
        if ( j % 2 == 0 ) {
            sort(a.begin(), a.end());
            --a[a.size()-1];
        }
        else {
            if ( a[a.size()-2] == 0 ) break;
            --a[a.size()-2];
        }
    }
    cout << a[a.size()-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long int min(long long int a, long long int b){return a<b? a: b;}

int main(void){
    long long int n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);
    printf("%lld\n", a*(n/(a+b))+min(a, n%(a+b)));
    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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;}

int main(){
  ll N,K; cin >> N >> K;
  ll mul = N/K;
  ll ans = 1e18;
  ans = min(abs(N-K*mul), abs(N-K*(mul+1)));
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int MOD;

int add(int x, int y) {
   return (x += y) >= MOD ? x - MOD : x;
}

int mul(int x, int y) {
   return (long long) x * y % MOD;
}

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N >> MOD;
   vector<int> dp(N);
   dp[0] = 1;
   for (int p = 2; p <= N; ++p) {
      int z = min(p - 1, N + 2 - p);
      for (int i = z; i < N; ++i) {
         dp[i] = add(dp[i], dp[i - z]);
      }
   }
   int ans = 0;
   for (int i = 0; i < N; ++i) {
      ans = add(ans, mul(N - i, dp[i]));
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 2020
#define M 20200
using namespace std;

int n,to[M],hd[M],lk[N],ln[M],cst[M],u,v,tc,cnt=1,S,T,tp,q[N],h,t,pre[N];
long long dis[N],ans;
bool inq[N];

inline void add(int u,int v,int w,int c){to[++cnt]=v,hd[cnt]=lk[u],ln[cnt]=w,cst[cnt]=c,lk[u]=cnt;}

inline void Add(int u,int v,int w,int c){add(u,v,w,c),add(v,u,0,-c);}

int main()
{
	scanf("%d",&n);
	S=n*2,T=S+1;
	for(int i=0;i<S;i++)
	{
		scanf("%d%d%d",&u,&v,&tc);
		if(i<n)Add(S,i,tc,0);
		else Add(i,T+4,tc,0);
		for(int s=0;s<4;s++)
		{
			tp=(s&1?u:-u)+(s>>1&1?v:-v);
			if(i<n)Add(i,T+s,tc,tp);
			else Add(T+s,i,tc,-tp);
		}
	}T+=4;
	while(1)
	{
		for(int i=0;i<=T;i++)
		dis[i]=-1e17;
		dis[q[h=0]=S]=0,t=1;
		while(h^t)
		{
			inq[u=q[h++]]=0,h==N?h=0:0;
			for(int i=lk[u];i;i=hd[i])
				if(ln[i]&&dis[v=to[i]]<dis[u]+cst[i])
					dis[v]=dis[u]+cst[i],pre[v]=i,inq[v]?0:(inq[q[t++]=v]=1,t==N?t=0:0);
		}
		if(dis[T]==-1e17)break;
		tp=1e9;
		for(u=T;u^S;u=to[pre[u]^1])tp=min(tp,ln[pre[u]]);
		ans+=dis[T]*tp;
		for(u=pre[T];u;u=pre[to[u^1]])ln[u]-=tp,ln[u^1]+=tp;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int ans[220000];
int cnt[220000];
int a[220000];

vector<int> enum_div(int n) {
  vector<int> ret;
  for(int i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      ret.push_back(i);
      if(i*i != n) {
        ret.push_back(n/i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  int n;
  cin >> n;
  rep(i,n) cin >> a[i+1];
  for(int i = n; i>=1; i--) {
    if(cnt[i]%2==a[i]) continue;
    else {
      ans[i]++;
      vi v = enum_div(i);
      rep(j,v.size()) cnt[v[j]]++;
    }
  }
  int m = 0;
  for(int i = 1; i<=n; i++) m += ans[i];
  cout << m << endl;
  vi ret;
  for(int i = 1; i<=n; i++) {
    if(ans[i]) ret.push_back(i);
  }
  rep(i,ret.size()) {
    cout << ret[i];
    if(i!=ret.size()-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

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

int main(){
    long long n; cin >> n;
    long long m = (long long)1e16;
    for(int i = 0; i < 5; i++){
        long long a; cin >> a;
        m = min(m, a);
    }
    long long ans = 4;
    ans += (n + m - 1)/m;
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s1,s2,s3;cin>>s1>>s2>>s3;
    string res=""; res+=('A'+s1[0]-'a');res+=('A'+s2[0]-'a');res+=('A'+s3[0]-'a');
  cout<<res<<endl;
}


Measured memory_bytes: 256
/*
 * 2321.cc: Butterfly
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_T = 16;
const int TBITS = 1 << MAX_T;

typedef long long ll;

/* typedef */

/* global variables */

ll dp[TBITS];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
      int m;
      ll l;
      cin >> m >> l;
      int mask = 0;
      for (int j = 0; j < m; j++) {
	int sj, ej;
	cin >> sj >> ej;
	sj -= 6, ej -= 6;
	for (int t = sj; t < ej; t++)
	  mask |= (1 << t);
      }

      for (int bits = TBITS - 1; bits >= 0; bits--)
	if (dp[bits] >= 0 && ! (bits & mask)) {
	  int bits0 = bits | mask;
	  ll dp0 = dp[bits] + l;
	  if (dp[bits0] < dp0) dp[bits0] = dp0;
	}
    }

    ll maxdp = 0;
    for (int bits = 0; bits < TBITS; bits++)
      if (maxdp < dp[bits]) maxdp = dp[bits];
    printf("%lld\n", maxdp);
  }

  return 0;
}

Measured memory_bytes: 1676
void count(){
  int mas[3];
  int count = 0;
  scanf("%1d%1d%1d", &mas[0], &mas[1], &mas[2]);

  for(int i=0; i<sizeof(mas)/sizeof(mas[0]); i++){
    if(mas[i] != 0){
      count++;
    }
  }
  printf("%d", count); 
}

int main(){
  count();
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define N 100

int main(){
  int i,j,n,A[N],tmp,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>=1+i;j--){
      if(A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	count++;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n%d\n",count);
 return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

struct UF {
	vector<int> data;
	UF(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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

    int x,y;cin>>x>>y;
    UF uf(13);
    uf.unite(1,3);uf.unite(5,3);uf.unite(5,7);uf.unite(7,8);uf.unite(8,10);uf.unite(10,12);
    uf.unite(4,6);uf.unite(6,9);uf.unite(9,11);
    if(uf.find(x,y)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int i=1;
		while(true){
        	String x=br.readLine();
        	if(x.equals("0")) break;
        	sb.append("Case "+i+": "+x+"\n");
    		i++;
        }
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 27032
#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() {
  string s; cin >> s;
  int cnt1 = 0, cnt2 = 0;
  rep(i, (int)s.size()) {
    if (s[i] == '0') cnt1++;
    else cnt2++;
  }
  cout << min(cnt1, cnt2) * 2 << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl();
        v<P> ba;
        rep(i, n) {
            ll a, b;
            cin >> a >> b;
            ba.eb(P(b, a));
        }
        sort(all(ba));
        ll now = 0;
        rep(i, n) {
            if (ba[i].S + now <= ba[i].F) {
                now += ba[i].S;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 6512
// https://atcoder.jp/contests/abl/tasks/abl_d

#include <atcoder/all>

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

ll op(ll a, ll b) { return max(a, b); }
ll e() { return 0; }

void solve() {
  ll N, K;
  cin >> N >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll max_a = *max_element(all(as));

  segtree<ll, op, e> dp(max_a + 1);

  ll res = 0;

  rep(i, N) {
    ll a = as[i];
    ll prev_max = dp.prod(max(0ll, a - K), min(max_a, a + K) + 1);
    dp.set(a, prev_max + 1);
    chmax(res, prev_max + 1);
  }

  cout << res << "\n";
}


Measured memory_bytes: 16140
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

ll sign(ll A){
    if(A>=0) return 1;
    else return 0;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    REP(i, N) cin >> x[i] >> y[i] >> z[i];

    ll ans = 0;
    for(int s=0; s<(1<<3); s++) {
        bitset<3> b = bitset<3>(s);
        vector<ll> candidates(N);
        REP(i, N) {
            candidates[i] = ll(2*b[0]-1) * x[i] + ll(2*b[1]-1) * y[i] + ll(2*b[2]-1) * z[i];
        }
        sort(ALL(candidates));
        ll cand = 0;
        REP(j, M) cand += candidates[N-1-j];
        if(ans < cand) ans = cand;
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
s = [str(i) for i in input()]
n = len(s)

sa = s[0:(n-1)//2]
sb = s[(n+1)//2:n]

def palindrome(string):
    for i in range(len(string)//2):
        if string[i] != string[-i-1]:
            return False
    return True

if palindrome(s) and palindrome(sa) and palindrome(sb):
    print("Yes")
else:
    print("No")


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

int main() {
	
	int c = 0,f = 0;
	string str;
	cin >> str;
	
	for(auto a:str)
		if(a == 'C')
			c++;
		else if(c&&a=='F')
			f++;
			
	cout << (f ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	int a;
	rep(i, n) { cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3416
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll a,b,m,min=inf;
  cin >> a >> b >> m;
  vint aa(a),bb(b),x(m),y(m),c(m);
  rep(i,a){
    cin >> aa[i];
  }
  rep(i,b){
    cin >> bb[i];
  }
  rep(i,m){
    cin >> x[i] >> y[i] >> c[i];
  }

  rep(i,m){
    if(min>aa[x[i]-1]+bb[y[i]-1]-c[i]){
      min = aa[x[i]-1]+bb[y[i]-1]-c[i];
    }
  }

  std::sort(aa.begin(),aa.end());
  std::sort(bb.begin(),bb.end());

  if(aa[0]+bb[0]<min){
    min = aa[0]+bb[0];
  }

  pri(min);

}


Measured memory_bytes: 2176
//C - Tax Increase 

#include <iostream>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    int xa_min = a / 0.08 + (a % 2);
    int xa_max = (a + 1) / 0.08 + ((a+1) % 2);
    int xb_min = b / 0.10;
    int xb_max = (b + 1) / 0.10;

    if ((xa_min < xb_max) && (xb_min < xa_max)) {
        if (xa_min > xb_min)
            cout << xa_min << endl;
        else 
            cout << xb_min << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int n,x,y,a,b,c,ans;
    cin>>n>>x>>y;x--;y--;
    int cut=y-x-1;
    vector<int>cnt(n);
    rep(i,n){
        rep(j,n){
            if(i<j){//全探索
                if(i<=x){//i in zoneA
                    if(j<=x)cnt[j-i]++;
                    else if(j<y)cnt[min(j-i,x-i+1+y-j)]++;//(A,B)
                    else cnt[j-i-cut]++;
                }
                else if(i<y){//i in zoneB
                    if(j<y)cnt[min(j-i,i-x+1+y-j)]++;//(B,B)
                    else cnt[min(j-i,i-x+1+j-y)]++;//(B,C)
                }
                else{//i in zoneC
                    cnt[j-i]++;
                }
            }
        }
    }
    for(int i=1;i<n;i++)cout<<cnt[i]<<endl;
    return 0;
}



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

const int N = 310;
typedef long long ll;

ll dis[N][N],book[N][N];
ll n,ans;

ll Floyd()
{
	ll ans=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if((i!=j)&&(i!=k)&&(j!=k))
				{
					if(dis[i][j]>dis[i][k]+dis[k][j]) return -1;
					if(dis[i][j]==dis[i][k]+dis[k][j]) book[i][j]=1;
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(!book[i][j])
				ans+=dis[i][j];
	return ans/2;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>dis[i][j];
	ans = Floyd();
	cout<<ans<<"\n";
}

Measured memory_bytes: 1664
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int a, b;
  cin >> a >> b;
  cout << CEIL(b - 1, a - 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
#define H 500000
 
void maxHeapify(int *, int);
void buildMaxHeap(int *);
 
int h;
 
int main() {
 
  int A[H];
  int i;
 
  scanf("%d",&h);
  if(h>H) exit(0);
 
   
  for(i=1; i<=h ; i++) scanf("%d",&A[i]);
 
 buildMaxHeap(A);
   
 for(i=1; i<=h ; i++) printf(" %d",A[i]);
 
 printf("\n");
 
  return 0;
}

 
void maxHeapify(int *A, int i) {
  int l,r,largest,temp;
 
  l=i*2;
  r=i*2+1;
 
  if(l<=h && A[l]>A[i])largest = l;
  else largest = i;
 
  if(r<=h && A[r]>A[largest]) largest=r;
 
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
 
    maxHeapify(A, largest);  
  }
 
}
 
void buildMaxHeap(int *A) {
  int i;
 
  for(i=h/2 ; i>=1 ; i--){
    maxHeapify(A, i);
  }
}

Measured memory_bytes: 2552
#include <stdio.h>
#include <ctype.h>

int main(){
    int c;
    int i=0,cnt[128]={0};//ASCII????????????0~127
    while((c=getchar())!=EOF){
        cnt[c]++;
        i++;
    }
    for(i=0;i<26;i++){
        cnt[i+97]+=cnt[i+65];
        printf("%c : %d\n",i+97,cnt[i+97]);
    }
    return 0;
}

Measured memory_bytes: 1768
//dfs
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>

using namespace std;
typedef long long ll;
#define cls(x) memset(x,0,sizeof(x))


const int INF = 0x3f3f3f3f;
const int SZ = 100;

int main() {
  int total = 1 << 10;
  int n;
  cin >> n;
  int a[10];
  while(n-- > 0) {
    for(int i = 0; i < 10; ++i) {
      cin >> a[i];
    }
    bool flag;
    for(int p = 0; p < total; ++p) {
      int cur = p;
      int pre_left = -1, pre_right = -1;
      flag = true;
      for(int i = 0; i < 10; ++i) {
        if((cur >> i) & 1) {
          //left
          //cout << a[i] << endl;
          if(a[i] > pre_left) {
            pre_left = a[i];
          } else {
            flag = false;
            break;
          }
        } else {
          // right
          if(a[i] > pre_right) {
            pre_right = a[i];
          } else {
            flag = false;
            break;
          }
        }
      }
      if(flag) break;
    }
    if(flag)  {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
	return 0;
}


Measured memory_bytes: 3072
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var c = 0;
        var ok = false;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (ok) continue;
            if (line[0] == line[1])
            {
                c++;
                if (c == 3) ok = true;
            }
            else c = 0;
        }
        Console.WriteLine(ok? "Yes":"No");
    }
}


Measured memory_bytes: 27524
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;


#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
//


//
//end   global variable

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

  int k,t;
  vector<int> a;
  cin >> k >> t;
  rep(i,t){
    a.pb(0);
    cin >> a[i];
  }
  sort(all(a));

  rep(i,t-1){
    a[t-1] -= a[i];
  }
  cout << max(0,a[t-1]-1) << endl;
  //
  //end   main()
  return 0;
}


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


int main(){
  int n,m,i,co;
  cin >> n >> m;
  co=0;
  vector<int> x(m);
  for(i=0;i<m;++i){
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  vector<int>di(m-1);
  for(i=0;i<m-1;++i){
    di[i]=x[i+1]-x[i];
  }
  sort(di.begin(),di.end());
  int sum=0;
  for(i=0;i<m-n;++i){
    sum+=di[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main ()
{
    int a,b,c,d,s1,s2;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    s1=a+b;
    s2=c+d;
    if(s1>s2)
        printf("Left\n");
    else if(s2>s1)
        printf("Right\n");
    else
        printf("Balanced\n");
    return 0;
}

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

namespace ConsoleApp22
{
    class Program
    {
        static void Main(string[] args)
        {


            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var a = line[0];
            var b = line[1];

            var ans = new List<int>{ a + b, a - b, a * b }.OrderByDescending(x => x).First();

            Console.WriteLine(ans);

        }

    }


}


Measured memory_bytes: 13396
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;

const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
const ll INF=1<<30;
int n, m, p;
class BellmanFord{
    public:
        typedef struct Edge{
            int from;
            int to;
            int cost;
            Edge(int f,int t,int c):from(f),to(t),cost(c){}
        } Edge;
        int edge_num, vertex_num, start, goal;
        vector<Edge> edges;
        vector<ll> dist;
        vector<int> afby_nc;
 
    BellmanFord(int e,int v,int s,int g) : edge_num(e),vertex_num(v),start(s),goal(g){
        dist=vector<ll>(vertex_num,INF);
        dist[start]=0;
        afby_nc=vector<int>(vertex_num,false);
    }
 
    void connect(int from, int to, int cost) {
        edges.push_back(Edge(from,to,cost));
    }
 
    void relax(){
        REP(i,vertex_num){
            for(auto edge : edges){
                if(dist[edge.from]!=INF && dist[edge.to]>dist[edge.from]+edge.cost)
                   dist[edge.to]=dist[edge.from]+edge.cost;
            }
        }
    }
 
    void check_negative_cycle(){
        REP(i,vertex_num){
            for(auto edge : edges){
                if(dist[edge.from]==INF)continue;
                if(dist[edge.to]>dist[edge.from]+edge.cost){
                    afby_nc[edge.to]=true;
                    dist[edge.to]=dist[edge.from]+edge.cost;
                }
                if(afby_nc[edge.from]==true)afby_nc[edge.to]=true;
            }
        }
    }
 
    ll distance(){
        this->relax();
        ll ans_dist=dist[goal];
        //for(auto vv:dist)printf("###%lld\n",vv);
        this->check_negative_cycle();
        //for(auto vv:dist)printf("######%lld\n",vv);
        if(ans_dist>dist[goal] || afby_nc[goal]==true)return -INF;
        else return ans_dist;
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m>> p;
    int a, b, c;
    BellmanFord bf(m,n,0,n-1);
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        bf.connect(a-1,b-1,p-c);
    }
    ll dist=bf.distance();
    if(dist==-INF)
    cout << -1 << "\n";
    else if(dist>0) cout<<0<<"\n";
    else cout<<-dist<<"\n";
}

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

typedef pair<int,int> P;
const int INF = 500000000;

int main(){
    int n;
    cin >> n;
    n = n%10;
    string s;
    if (n == 3) s = "bon";
    else if (n == 0 || n == 1 || n == 6 || n == 8) s = "pon";
    else s = "hon";
    cout << s << "\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ll n;
    cin >> n;
    vll a(n);
    set<ll> syu;
    map<ll, ll> cnt;
    rep(i, n)
    {
        cin >> a[i];
        syu.insert(a[i]);
        cnt[a[i]]++;
    }
    if (syu.size() == 1)
    {
        if (a[0] == 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (n % 3 != 0 || syu.size() > 3)
        cout << "No" << endl;
    else
    {
        vll x;
        vll y;
        for (auto p : syu)
        {
            x.push_back(cnt[p]);
            y.push_back(p);
        }
        if (syu.size() == 3)
        {
            if (x[0] == x[1] && x[1] == x[2] &&
           ( ( y[0] ^ y[1]) == y[2])
            && ((y[1] ^ y[2]) == y[0])
             && ((y[2] ^ y[0]) == y[1]))
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
        }
        else if (syu.size() == 2)
        {
            if (x[0] * 2 == x[1])
            {
                if (y[0] == 0)
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
            }
            else if (x[1] * 2 == x[0])
            {
                if (y[1] == 0)
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
            }
            else
                cout << "No" << endl;
        }
        else
            cout << "No" << endl;
    }
}


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

using namespace std;

int N, L, ans = 0;
int a[210];

bool cmp(int x, int y)
{
	return abs(x) < abs(y);
}
int main()
{
	cin >> N >> L;
	for(int i = 1; i <= N; i++)
		a[i] = L + i - 1;
	sort(a + 1, a + N + 1, cmp);
	for(int i = 2; i <= N; i++)
		ans += a[i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

bool sosuu(int n)
{
  int i=3;
  if(n==1){return false;}
  if(n==2){return true;}
  if(n%2==0){return false;}
  while(true)
  {
    if(n%i==0&&n!=i){return false;}
    if(i>sqrt(n)+1){break;}
    i+=2;
  }
  return true;

}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n;
  n=s.length();
  int i=0;
  int res=0;
  while(s.length()>1)
  {
    if(all_of(s.begin(),s.end(),[](char a){return a=='0';}) or all_of(s.begin(),s.end(),[](char a){return a=='1';}))
    {
      res=n-i;
      break;
    }
    s=s.substr(1,s.length()-2);
    i++;
  }
  if(res==0){res=n-n/2;}
  cout <<res;

}

Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/21
Solved on 2019/3/
@author: shinjisu
"""


# ABC 086 C Traveling
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp(N)
    prevT, prevX, prevY = 0, 0, 0
    for i in range(N):
        T, X, Y = getIntList()
        d.dmp((T, X, Y), 'T, X, Y')
        dt, dx, dy = T-prevT, abs(X-prevX), abs(Y-prevY)
        d.dmp((dt, dx, dy), 'dt, dx, dy')
        if dt < dx+dy:
            return 'No'
        if (dt-dx-dy) % 2 == 1:
            return 'No'
        prevT, prevX, prevY = T, X, Y
    return 'Yes'


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)


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

using namespace std;
#define ll long long

int main (void) {
    int n;

    int a[3][3];
    int col[3][3];
    int row[3][3];
    int acr[2][3];
    for (int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            col[i][j] = a[j][i];
            row[i][j] = a[i][j];
            if(i == j){
                acr[0][j] = a[i][j];
            }
            if(i + j == 2){
                acr[1][j] = a[i][j];
            }
        }
    }

    scanf("%d", &n);
    int b[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &b[i]);
    }

    int cnt = 0;
    for (int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
            for (int i = 0; i < n; i++){
                if(b[i] == col[j][k]){
                    cnt++;
                }
            }
        }
        if(cnt == 3){
            puts("Yes");
            return 0;
        }else{
            cnt = 0;
        }
    }

    for (int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
            for (int i = 0; i < n; i++){
                if(b[i] == row[j][k]){
                    cnt++;
                }
            }
        }
        if(cnt == 3){
            puts("Yes");
            return 0;
        }else{
            cnt = 0;
        }
    }

    for (int j = 0; j < 2; j++){
        for(int k = 0; k < 3; k++){
            for (int i = 0; i < n; i++){
                if(b[i] == acr[j][k]){
                    cnt++;
                }
            }
        }
        if(cnt == 3){
            puts("Yes");
            return 0;
        }else{
            cnt = 0;
        }
    }

    puts("No");
    return 0;
}

Measured memory_bytes: 256
import sys

input=sys.stdin.readline

n,m=map(int,input().split())
edge=[[] for i in range(n)]
for i in range(m):
    u,v,s=map(int,input().split())
    edge[u-1].append((v-1,s))
    edge[v-1].append((u-1,s))

ans=[1 for i in range(n)]
pm=[True]*n

used=[False]*n
used[0]=True

que=[0]
while que:
    u=que.pop()
    for v,s in edge[u]:
        if not used[v]:
            pm[v]=(not pm[u])
            ans[v]=s-ans[u]
            used[v]=True
            que.append(v)

flag=True
bipart=True
for u in range(n):
    for v,s in edge[u]:
        if ans[u]+ans[v]!=s:
            flag=False
        if pm[u]==pm[v]:
            bipart=False
            check=(u,v,s)

if bipart:
    upper=float("inf")
    lower=1

    for v in range(1,n):
        if pm[v]:
            lower=max(lower,2-ans[v])
        else:
            upper=min(upper,ans[v])

    if flag:
        if upper<lower:
            print(0)
        else:
            print(upper-lower+1)
    else:
        print(0)
else:
    u,v,s=check
    a,b=ans[u],ans[v]
    if pm[u]:
        diff=s-(ans[u]+ans[v])
        if diff%2==1:
            print(0)
            exit()
        else:
            for i in range(n):
                if pm[i]:
                    ans[i]+=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
                else:
                    ans[i]-=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
            flag=True
            for u in range(n):
                for v,s in edge[u]:
                    if ans[u]+ans[v]!=s:
                        flag=False
            print(int(flag))

    else:
        diff=(ans[u]+ans[v])-s
        if diff%2==1:
            print(0)
            exit()
        else:
            for i in range(n):
                if pm[i]:
                    ans[i]+=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
                else:
                    ans[i]-=diff//2
                    if ans[i]<1:
                        print(0)
                        exit()
            flag=True
            for u in range(n):
                for v,s in edge[u]:
                    if ans[u]+ans[v]!=s:
                        flag=False
            print(int(flag))


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

int par[55];

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

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

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

void unite(int x,int y)
{
	x=root(x);
	y=root(y);
	if(x==y)return;
	else par[x]=y;
}

int main()
{
	int n,m,a[55],b[55],sum=0;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<m;i++)
	{
		init(n);
		for(int j=0;j<m;j++)
		{
			if(j!=i)
			{
				unite(a[j],b[j]);
			}
		}
		if(!same(a[i],b[i]))sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,a,b;

void wi107(ll &nq){
    nq=nq%1000000007;
}

int main(){
    cin>>a>>b;
    n=1;
    if(abs(a-b)>1){
        C 0 E;
        return 0;
    }
    else{
        for(int i=1;i<=a;i++){n*=i;wi107(n); }
        for(int i=1;i<=b;i++){n*=i;wi107(n); }
        
        if(abs(a-b)==0){
            n*=2;
            wi107(n); 
        }
        C n E;
    }
    //C n%530123477 E;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] spl = s.split(" ");
		int N = Integer.parseInt(spl[0]);
		int K = Integer.parseInt(spl[1]);
		sc.close();
		System.out.println(N - K + 1);
	}
}


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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,ans=0; cin >> n;
    vector<ll> a(n);
    for(ll &i: a) cin >> i;
    sort(a.begin(), a.end());
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]==a[j]) continue;
            for(int k=j+1;k<n;k++){
                if(a[i]==a[k] || a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i])++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  int find[n * m + 1][2];
  REP1(i, n * m) REP(j, 2) find[i][j] = 0;
  REP(i, n) {
    cin >> a[i];
    find[a[i]][0]++;
  }
  REP(i, m) {
    cin >> b[i];
    find[b[i]][1]++;
  }
  REP1(i, n * m) REP(j, 2) {
    if (1 < find[i][j]) {
      cout << 0 << endl;
      return 0;
    }
  }
  int sum[n * m + 1][2];
  for (int i = 0; i <= n * m; ++i) REP(j, 2) sum[i][j] = 0;
  REP(i, n) sum[a[i]][0]--;
  REP(i, m) sum[b[i]][1]--;
  sum[0][0] = n, sum[0][1] = m;
  REP(i, n * m) REP(j, 2) sum[i + 1][j] += sum[i][j];
  ll ans = 1;
  for (int x = n * m; x >= 1; --x) {
    if (find[x][0] && find[x][1]) {
      ans *= 1;
    } else if (find[x][0]) {
      ans *= sum[x][1];
    } else if (find[x][1]) {
      ans *= sum[x][0];
    } else {
      ans *= (sum[x][1] * sum[x][0] % MOD - (n * m % MOD - x));
    }
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15872
import numpy as np
import math
import sys

sys.setrecursionlimit(1000000)

def contrary_bit(bit):
    if (bit == 1):
        return 0
    elif (bit == 0):
        return 1
    else:
        print("error")

def dfs(adj_lists, nodes, node):
    # nodeから出発して，深さ優先探索
    neighbors = adj_lists[node]
    for neighbor in neighbors:
        if (nodes[neighbor[0]] != -1):
            #訪問済み
            continue
        else:
            if neighbor[1] % 2 == 0:
                # 同じbit  
                nodes[neighbor[0]] = nodes[node]
                nodes = dfs(adj_lists, nodes, neighbor[0])
            else:
                nodes[neighbor[0]] = contrary_bit(nodes[node])
                nodes = dfs(adj_lists, nodes, neighbor[0])
    return nodes

def main():
    N = int(input())
    adj_lists = {}
    for i in range(1, N + 1):
        adj_lists[i] = []
    nodes = [-1] * (N + 1)
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        adj_lists[u].append((v, w))
        adj_lists[v].append((u, w))
    nodes[1] = 1
    nodes = dfs(adj_lists, nodes, 1)
    ans = nodes[1:]
    for color in ans:
        print(color)

if __name__ == '__main__':
    main()

Measured memory_bytes: 96644
main(){
  long long n,i,s,A=0;
  scanf("%lld",&n);
  s=sqrt(n);
  for(i=1;i<s+1;i++){
    if(n%i)continue;
    if(i>1&&n/(i-1)==n%(i-1))A+=i-1;
    if(i*i!=n&&n/(n/i-1)==n%(n/i-1))A+=n/i-1;
  }
  printf("%lld",A);
  return 0;
}

Measured memory_bytes: 2072
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def solve(n,m):
    H = [int(input()) for _ in range(n)]
    W = [int(input()) for _ in range(m)]

    H_length = [0] * 1500000
    W_length = [0] * 1500000
    for i in range(n):
        height = 0
        for j in range(i,n):
            height += H[j]
            H_length[height] += 1
    
    for i in range(m):
        width = 0
        for j in range(i,m):
            width += W[j]
            W_length[width] += 1
    
    ans = sum(h*w for h,w in zip(H_length,W_length))
    print(ans)

def main():
    while True:
        n,m = map(int,input().split())
        if n == 0:
            return
        solve(n,m)
if __name__ == '__main__':
    main()


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

string r,a = "AKIHABARA";
set<string> v;

int main() {
    string s,t;
    cin >> s;
    for(int i=0; i<(1<<9); i++) {
        t = "";
        for(int j=0; j<9; j++) {
            if(a[j]=='A' && (i&(1<<j))) t += a[j];
            else if(a[j]!='A') t += a[j];
        }
        v.insert(t);
    }
    int ok = 0;
    for(string p: v) {

        ok |= (p==s);

    }
    if(ok) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
}



Measured memory_bytes: 256