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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

struct UnionFind{
    vector<int> par; // par[i]:iの親の番号
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) par[i] = i;
    }
    
    int root(int 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);
        int ry = root(y);
        if(rx == ry) return;
        par[min(rx,ry)] = max(rx,ry);
    }
    
    bool same(int x, int y){ // xとyが同じ木に属するかどうか
        return root(x) == root(y);
    }
};

int main(void){
    int N,M,K; cin >> N >> M >> K;
    VI edge[N];
    UnionFind uf(N);
    REP(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
        uf.unite(a,b);
    }

    map<int,int> m;
    VI v(N);
    REP(i,N){
        v[i] = uf.root(i);
    }
    REP(i,N){
        int root = v[i];
        if(m.find(root) == m.end()) m[root] = 1;
        else m[root]++;
    }
    VI ans(N);
    REP(i,N){
        ans[i] = m[v[i]]-1-edge[i].size();
    }
    REP(i,K){
        int c,d; cin >> c >> d;
        c--; d--;
        if(uf.same(c,d)){
            ans[c]--;
            ans[d]--;
        }
    }
    REP(i,N) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

    ll n;
    cin >> n;
    ll nn = 1ll<<n;

    vector<ll> a(nn);
    for(auto &e: a) cin >> e;

    using P = pair<ll, ll>;
    P z = P(-1, -1);

    vector<ll> r(nn, 0);
    r[0] = a[0];

    vector<P> m1(nn, z), m2(nn, z);
    m1[0] = P(a[0], 0);
    for(ll k=1; k<nn; k++) {
        P mm1 = z, mm2 = z;
        for(ll i=0; i<20; i++) {
            ll j = k & ~(1ll<<i);
            if(k == j) continue;

            for(auto &t: {m1[j], m2[j]}) {
                if(t.second == mm1.second || t.second == mm2.second) continue;
                if(t.first > mm1.first)
                    mm2 = mm1, mm1 = t;
                else if(t.first > mm2.first)
                    mm2 = t;
            }
        }
        if(a[k] > mm1.first)
            mm2 = mm1, mm1 = P(a[k], k);
        else if(a[k] > mm2.first)
            mm2 = P(a[k], k);
        m1[k] = mm1;
        m2[k] = mm2;
        r[k] = max(r[k-1], mm1.first + mm2.first);
    }

    for(ll k=1; k<nn; k++)
        cout << r[k] << endl;
}


Measured memory_bytes: 15360
#include<stdio.h>

int main()
{
    int a,b,sum;
    scanf("%d%d",&a,&b);
    if(b%a==0){
        sum=a+b;
        printf("%d",sum);
    }
    else{
        sum=b-a;
        printf("%d",sum);
    }


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
#include <map>
using namespace std;

map<string, int> M;
set<string> ans;
string s[222222];

int main(void)
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);

	int n, i;

	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> s[i];
		M[s[i]]++;
	}

	int maxi = -1;
	for (i = 1; i <= n; i++)
		if (maxi < M[s[i]])
			maxi = M[s[i]];

	for (i = 1; i <= n; i++)
		if (maxi == M[s[i]])
			ans.insert(s[i]);

	set<string>::iterator it;
	for (it = ans.begin(); it != ans.end(); ++it)
		cout << *it << endl;
	return 0;
}

Measured memory_bytes: 34944
import java.util.*;

import static java.lang.System.*;

class Main {
    public static Scanner sc = new Scanner(in);
    public static Random rand=new Random();


    public void run() {
    	while(true){
    	int n=sc.nextInt();
    	int w=sc.nextInt();
    	if(n==0)return;
    	int[] v=nextIntArray(n);

    	int[] dat=new int[100/w+1];

    	for(int i=0;i<v.length;i++){
    		dat[v[i]/w]++;
    	}

    	int max=0,l=0;
    	for(int i=0;i<dat.length;i++){
    		if(dat[i]>max)max=dat[i];
    		if(dat[i]!=0)l=i;
    	}

    	double res=0;
    	for(int i=0;i<l;i++){
    		res+=(double)dat[i]/max*(l-i)/(l);
    	}
    	res+=0.01;

    	ln(res);
    	}
    }
    public static void main(String[] args) {
        new Main().run();
    }

    public int[] nextIntArray(int n){
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[i]=sc.nextInt();
        }
        return res;
    }
    public static void pr(Object o) {
        out.print(o);
    }
    public static void ln(Object o) {
        out.println(o);
    }
    public static void ln() {
        out.println();
    }
}

Measured memory_bytes: 23548
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n;
    cin >> n;
    while(true){
        if(n < 1000){
            break;
        }
        n -= 1000;
    }
    if(n == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
main(n){float a,b,c,d,e,f,g,h;scanf("%d",&n);while(n--){scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h);puts((c-a)*(h-f)-(d-b)*(g-e)?"NO":"YES");}}

Measured memory_bytes: 616
import java.util.Scanner;
class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int A = scanner.nextInt();//一つ目の数字を取り出す
            int B = scanner.nextInt();//スペース後の２つ目の数字を取り出す
            int ans = A + B;
            int dig = String.valueOf(ans).length();

            System.out.println(dig);
        }
    }
}



Measured memory_bytes: 26404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m;
    cin >> m;
    vll d(m), c(m);
    rep(i, m){
        cin >> d[i] >> c[i];
    }
    ll s = 0;
    rep(i, m){
        s += d[i]*c[i];
    }
    ll x = s/10;
    ll y = s%10;
    if(x == 0){
        cout << accumulate(ALL(c), 0ll)-1 << endl;
        return 0;
    }
    ll ans = accumulate(ALL(c), 0ll)-1;
    ans += x/9*10;
    x %= 9;
    if(x == 0){
        if(y == 0) ans--;
    }else{
        ans += x;
        if(x+y>=10) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

signed main()
{
	
 	FLASH

 	int n, m;

 	cin>>n>>m;

 	bool b[n+ 1][m + 1] = {{0}};
 	fr(i,1,m + 1) b[0][i] = 1;

  	fr(i,1,n + 1)
 	{
 		int k;
 		cin>>k;
 		fr(j,1,k +  1)
 		{
 			int a;
 			cin>>a;
 			b[i][a] = b[i-1][a];
 		}
 	}

 	int cnt = 0;

 	fr(i,1,m + 1)
 	{
 		cnt += b[n][i];
 	}
 	cout<<cnt<<'\n';


}

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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;



const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
 
     



int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';
    cout.precision(16);
    
    int N, A;
    cin >> N >> A;
    vector<int> xs(N);
    ii (N)
        cin >> xs[i];

    vector<vector<LL> > sum_ntaken_2_nways(    2505, vector<LL>(55, 0));
    sum_ntaken_2_nways[0][0] = 1;
    ii (N) {
        vector<vector<LL> > next = sum_ntaken_2_nways;
        xx (2501) {
            yy (51) {
                if (sum_ntaken_2_nways[x][y] == 0) continue;
                next[x + xs[i]][y + 1] += sum_ntaken_2_nways[x][y];
            }
        }
        swap(sum_ntaken_2_nways, next);
    }

    LL rr = 0;
    iii (1, N+1) {
        rr += sum_ntaken_2_nways[A*i][i];
    }

    cout << rr << '\n';


    return 0;
}



Measured memory_bytes: 2608
#include <iostream>
#include <string>

using namespace std;

int strtoint(string str) {
	int res = 0;
	int i = 0;
	while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
		res *= 10;
		res += str[i]-48;
		i++;
	}
	
	return res;
}

int main()
{
	string str;
	cin >> str;
	int former = strtoint(str.substr(0, 2));
	int	latter = strtoint(str.substr(2, 4));
	if (former >= 1 && former <= 12) {
		if (latter >= 1 && latter <= 12) {
			cout << "AMBIGUOUS";
		}
		else {
			cout << "MMYY";
		}
	}
	else {
		if (latter >= 1 && latter <= 12) {
			cout << "YYMM";
		}
		else {
			cout << "NA";
		}
	}
}

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


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    cnt = 0
    for a in range(n):
        if ((a + 1) * A[a]) % 2 == 1:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize "trapv"
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  string s; cin >> s;
  int sum = 0;

  for(char c : s){
    sum = sum + (c - '0');
    sum%=9;
  }

  if(sum==0) cout << "Yes\n";
  else cout << "No\n";

  return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

typedef complex<double> P;

const double PI = acos(-1.0);

int main(){
	int N, D;
	while(cin >> N >> D, N){
		P p = P(0,0); double dir = PI/2;
		for(int i=0;i<N;i++){
			int L, R, T; cin >> L >> R >> T;
			if(L==R){
				p = p + T*L/180.0*PI*P(cos(dir), sin(dir));
			}
			else {
				double r = ((double)L+R)/(L-R)*D;
				P c = p + P(cos(dir), sin(dir))*P(0,-1)*r;
				double agl = (r > 0 ? -L/abs(r+D) : R/abs(r-D))*T*PI/180.0;
				dir += agl;
				p = (p-c)*P(cos(agl), sin(agl))+c;
			}
		}
		printf("%.8lf\n%.8lf\n", real(p), imag(p));
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 2333
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m;
int main() {
	n = read(), m = read();
	cout << ceil((D)n / (D)m);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<int> c(n);
  rep(i, n) cin >> c[i];
  int ans = 0;
  rep(i, n) if(v[i] > c[i]) ans += (v[i] - c[i]);
  cout << ans << endl;
  return 0;
}

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<int> v(N + M);
        for (auto& i : v) cin >> i;
        v.push_back(0);
        sort(v.begin(), v.end());
        int ans = 0;
        for (int i = 0; i < v.size()-1; i++)
            ans = max(ans, v[i+1]-v[i]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========


int main(int argc, char** argv) {
  string S;
  cin >> S;
  int N = S.size();

  // check 2
  REP(i, N-1) {
    if (S[i] == S[i+1]) {
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }

  // check 3
  REP(i, N-2) {
    if (S[i] == S[i+2]) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;

  return 0;
}


Measured memory_bytes: 512
if __name__ == '__main__':
    n = int(input())
    numbers = list(map(int, input().split()))
    numbers.sort()
    sol = 0
    counter = 0
    for i in range(n):
        for j in range(i+ 1, n):
            x= numbers[i] + numbers[j]
            left = j + 1
            right = n - 1
            ok = -1
            while left <= right:
                mid = (left + right) // 2
                if numbers[mid] < x:
                    ok = mid
                    left = mid + 1
                else:
                    right = mid - 1
            sol = ok
            if sol != -1:
                counter = counter - j + sol
    print(counter)

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

const int MAX=105;
int state[MAX],N,S[MAX][MAX];
priority_queue<pair<int,int>> Q;

int prim(){
    int sum=0,cnt=1;
    for(int i=0;i<N;i++){
        state[i]=0;
    }
    state[0]=1;
    for(int i=0;i<N;i++){
        if(S[0][i]!=10000) Q.push(make_pair(-S[0][i],i));
    }
    while(1){
        int a=Q.top().second;
        if(state[a]==0){
        sum+=(-Q.top().first);
        Q.pop();
        state[a]=1;
        cnt++;
        for(int i=0;i<N;i++){
            if(S[a][i]!=10000000&&state[i]==0) Q.push(make_pair(-S[a][i],i));
        }
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return sum;
}


int main(){

    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int a;cin>>a;
            if(a==-1) S[i][j]=10000000;
            else S[i][j]=a;
        }
    }
    cout<<prim()<<endl;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void chmin(int* a, int b){
  if( *a > b ) *a = b;
}

int main(){
  int n, k;
  vector<int> hi;
  vector<int> dp;

  cin >> n >> k;
  hi.resize(n,0);
  dp.resize(n,999999999);
  dp[0] = 0;
  for(int i=0; i<n; i++){
    cin >> hi[i];
  }

  for(int i=0; i<n; i++){
    for(int j=1; j<=k; j++){
      if(n <= j+i) continue;
      chmin(&dp[i+j], dp[i] + abs( hi[i] - hi[i+j] ) );
    }
  }
  cout << dp[n-1];

  return 0;
}


Measured memory_bytes: 1152
require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(function(i){z=i.split(' '),a=z[0]-z[3],b=z[1]-z[4],c=z[2],f=z[5],r=Math.sqrt(a*a+b*b);c?console.log(r-c>f?0:f<c-r?2:r<f-c?-2:1):0})

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

long long sum1(long long i)
{
    int sum=i;
    return sum;
}

long long sum2(long long i)
{
    long long d,rem,sum;
    sum=i/10+i%10;
    return sum;
}

long long sum3(long long i)
{
    long long rem,sum;
    rem=i%10;
    i=i-rem;
    sum=rem;
    i=i/10;
    rem=i%10;
    sum=sum+rem+i/10;
    return sum;
}

long long sum4(long long i)
{
    long long  rem,sum;
    rem=i%10;
    i=i/10;
    sum=rem;
    rem=i%10;
    sum+=rem;
    i=i/10;
    rem=i%10;
    sum=sum+rem+i/10;
    return sum;
}

int main()
{
    long long n,a,b,i,ans=0,sum;
    scanf("%lld %lld %lld",&n,&a,&b);

    for(i=1; i<=n; i++)
    {
        if(i<10)
        {
            sum=sum1(i);
        }

        else if(i<100)
        {
            sum=sum2(i);
        }

        else if(i<1000)
        {
            sum=sum3(i);
        }

        else if(i<10000)
        {
            sum=sum4(i);
        }

        else sum=1;

        if(sum>=a && sum<=b)
        {
            ans+=i;
        }
    }

    printf("%lld",ans);

    return 0;

}






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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

int main(void)
{
	li a, b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

const int N=5e5+50; 

int n,k,a[N];
char s[N]; 
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	scanf("%d%d%s",&n,&k,s); 
	lop(i,0,n)a[i]=s[i]=='B';
	//maintaining [p,p+n)^flag
	int p=0,q=p+n;//[p,p+n)
	bool flag=0;
	while(k--){
		if(a[p]^flag==0)a[p]=1^flag; 
		else{
			flag^=1;
			a[q]=0^flag;
			if(++p>=N)p=0; 
			if(++q>=N)q=0; 
		}
	}
	lop(i,0,n)printf("%c",(a[(p+i)%N]^flag)?'B':'A'); 
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <assert.h>
 
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 2e18 + 7;
const int maxN = 2e6 + 5;
const ll MOD = 1e9 + 7;
 
int n, k, arr[maxN][4], dp[maxN][4];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	RI(i, n) {
		REP(j, 3) {
			cin >> arr[i][j];
		}
	}
	dp[0][0] = dp[0][1] = dp[0][2] = 0;
	RI(i, n) {
		REP(j, 3) {
			REP(k, 3) {
				if (k != j) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + arr[i][j]);
				}
			}
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
	return 0;
}


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

int main()
{
	
	ll peri;
	ll n;
	cin>>peri>>n;
	vector<ll> arr;
	for(int i = 0 ; i  < n ; i++)
	{
		ll temp;
		cin>>temp;
		arr.push_back(temp);
	}
	arr.push_back(peri + arr[0]);
	// cout<<peri<<endl;
	ll diff = 0;
	ll sumans = 0;
	for(int i = 1 ; i < n+1 ; i++)
	{
		diff = max(diff, arr[i] - arr[i-1]);
		sumans  += (arr[i] - arr[i-1]);
		// cout<<sumans<<endl;
	}
	sumans -= diff;
	cout<<sumans<<endl;
	
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

#define rep(i, n) for(lli i = 0; i < (lli)(n); i++)

const lli MOD = 1000000007LL;

lli modpow(lli a, lli n){
    lli res = 1;

    for(lli ai = a; n; n>>=1){
        if(1&n) res = (res*ai)%MOD;
        ai=(ai*ai)%MOD;
    }
    return res;
}

lli inv(lli n){
    return modpow(n, MOD-2);
}

lli modperm(lli n, lli k){
    lli res = 1;
    rep(i, k){
        res = (res*(n-i))%MOD;
    }
    return res;
}

lli modcomb(lli n, lli k){
    return (modperm(n, k)*inv(modperm(k, k)))%MOD;
}

lli posmod(lli n){
    lli res = n;
    res %= MOD;
    if(res < 0) res += MOD;
    return res;
}
int n, m, x;


int main(void){
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n);
    rep(i, n){
        cin >> c.at(i);
        int aij;
        rep(j, m){
            cin >> aij;
            a.at(i).push_back(aij);
        }
    }
    int b = 0;
    int res = INT_MAX;
    while(b < (2<<n)){
        int ce = 0;
        vector<int> sk(m);
        for(int i = 0; i < n; i++){
            if((1<<i)&b){
                rep(j, m){
                    sk.at(j) += a.at(i).at(j);
                }
                ce += c.at(i);
            }
        }
        b++;
        bool f = true;
        rep(j, m){
            if(sk.at(j) < x) f = false;
        }
        if(f) res = min(res, ce);
    }
    if(res != INT_MAX) cout << res << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    int set[n+1];
    for(int i=0;i<=n;i++)set[i]=0;
    for(int i=0;i<m;i++){
        int tmp;
        scanf("%d",&tmp);
        set[tmp]++;
        scanf("%d",&tmp);
        set[tmp]++;
    }
    for(int i=1;i<=n;i++)if(set[i]%2==1){
        printf("NO");
        return 0;
    }
    printf("YES");
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
main(){
  unsigned int n;
  int p;
  bool f;
  while(cin>>n){
    p=1;
    f=false;
    while(n!=0){
      if(n&1==1){
	if(f){
	  cout<<" ";
	}
	else{
	  f=true;
	}
	cout<<p;
      }
      n=n>>1;
      p*=2;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Arrays;


public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            // int n = 3;
            Map<String, List<List<Integer>>> map = new HashMap<String, List<List<Integer>>>(){{
                put("1", Arrays.asList(Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0)));
                put("2", Arrays.asList(Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0)));
                put("3", Arrays.asList(Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0)));
                put("4", Arrays.asList(Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0), Arrays.asList(0,0,0,0,0,0,0,0,0,0)));
            }};
            for(int i=0; i<n; i++){
                String[] arr = br.readLine().split(" ");
                String b = arr[0];
                int r = Integer.parseInt(arr[1]), f = Integer.parseInt(arr[2]), v = Integer.parseInt(arr[3]);
                map.get(b).get(r-1).set(f-1, map.get(b).get(r-1).get(f-1) + v);
            }
            for (Map.Entry<String, List<List<Integer>>> entry : map.entrySet()) {
                entry.getValue().forEach(row -> {
                    row.forEach(t -> {
                       System.out.printf(" %d", t);
                    });
                    System.out.println();
                });
                if (!entry.getKey().equals("4")) {
                    System.out.println("####################");
                }
            }
        }catch(IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 30780
#include <stdio.h>
#include <string.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;

int main()
{
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  
  sort(v.begin(), v.end());
  
  cout << static_cast<double>(v[0]) * static_cast<double>(v[1]) / 2.0;

  return 0; 
}

Measured memory_bytes: 256
n,m=list(map(int,input().split()))
p=list(map(int,input().split()))
from collections import defaultdict
from collections import deque
c=0
for i in range(n):
    if p[i]==i+1:
        c+=1
vis=[0]*n
def dfs(x):
    vis[x]=1
    a.add(x+1)
    
    di = deque()
    di.append(x)
    while di:
        now = di.popleft()
        for j in d[now]:
            if not vis[j]:
                vis[j] = 1
                a.add(j+1)
                di.append(j)
    
    
    for u in d[x]:
        if vis[u]==0:
            dfs(u)
d=defaultdict(list)
for i in range(m):
    a,b=list(map(int,input().split()))
    d[a-1].append(b-1)
    d[b-1].append(a-1)
ans=0
for i in range(n):
    if vis[i]==0:
        a=set()
        dfs(i)
        l=0
        z=0
        for j in a:
            if p[j-1] in a:
                z+=1
            if p[j-1]==j:
                l+=1
        ans=max(ans,c+z-l)
print(ans)
        
                
                
    
    
    
    

Measured memory_bytes: 115064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int d,t,s;
    cin >> d >> t >> s;

    if(s*t>=d)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
	char mozi[4];
	int i;
	
	for(i=0;i<3;i++){
		scanf("%c",&mozi[i]);
	}
	if(mozi[0]==mozi[1] || mozi[0]==mozi[2] || mozi[2]==mozi[1]){
		printf("No");
	}else{
		printf("Yes");
	}
	
	return 0;}

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

int main()
{   
    string s;
    cin >> s;
    bool flag1 = true, flag2 = true, flag3 = true; 
    int n = s.size();
    for(int i= 0; i<= n/2-1; i++){
        if(s[i]!=s[n-i-1]) flag1 = false;
        // cout << i << " " << n-i-1<<endl;
    }
    // cout << flag1 << endl;
    for(int i= 0; i<= (n-1)/4-1; i++){
        if(s[i]!=s[(n-1)/2-1-i]) flag2 = false;
        // cout << i << " " << (n-1)/2-1-i<<endl;
    }
    // cout << flag1 << endl;
    for(int i= 0; i<= (n-1)/4-1; i++){
        int tmp = (n+3)/2-1;
        if(s[i+tmp]!=s[n-i-1]) flag3 = false;
        // cout << i+tmp << " " << n-i-1<<endl;
    }
    // cout << n*(n-1)/2 + m*(m-1)/2 << endl;
    // cout << flag1 << flag2 << flag3<<endl;
    if(flag1 && flag2 && flag3) cout<<"Yes"<< endl;
    else cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    
    long a, b, r, tmp,a1,b1,bai;
    while(scan.hasNextLong()){

    a = scan.nextInt();
    b = scan.nextInt();
    a1 = a;
    b1 = b;
 
    //?????¶??° a > b ????¢?????????\??? 
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
    }
 
  // ?????????????????????????????? 
    r = a % b;
     while(r!=0){
     a = b;
     b = r;
     r = a % b;
  }
    bai = a1 * b1 / b;
  //* ?????§??¬?´???°????????? */
    System.out.println(b + " " + bai);
    }
    }
}

Measured memory_bytes: 26184
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,k;
    cin >> n>>k;
    ll a,b;
    vpl v;
    rp(i,n) {
        cin >> a >> b;
        v.pb(mp(a,b));
    }
    sort(v.begin(),v.end());
    ll cnt = 0;
    while(k > 0){
        if(v[cnt].second < k){
            k -= v[cnt].second;
            cnt++;
        } else {
            cout << v[cnt].first <<endl;
            return 0;
        }
    }


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll 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; }

int n;
vector<int> p, q;
vector<int> v;

bool check(vector<int> a, vector<int> b) {
    rep(i, n) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

int main() {
    cin >> n;
    p.resize(n);
    q.resize(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    for (int i = 1; i <= n; i++) {
        v.push_back(i);
    }

    int cnt = 1;
    int a = 0, b = 0;
    do {
        if (check(v, p)) a = cnt;
        if (check(v, q)) b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a-b) << endl;
}


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

int main() 
{
    int N;
    string S;
    cin >> N >> S;
    
    if (N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    int sum = N / 2;
    string T = S.substr(0,sum);
    string S2 = S.substr(sum,N-1);
    if (T == S2) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

// union by size
class UnionFindTreeBySize { // The range of node number is from 0 to n-1
  public:
    //'size[x]' is a size of the union find tree the root of which is x.
    //'parents[x]' is the parent of x
    vector<int> size, parents;

    // constructor
    UnionFindTreeBySize() {}
    UnionFindTreeBySize(int n) { // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeSet(i);
        }
    }

    // make a union find tree
    void makeSet(int x) {
        parents[x] = x; // the parent of x is x
        size[x] = 1;
    }

    // check whether the root of x is the same as that of y
    bool same(int x, int y) { return findSet(x) == findSet(y); }

    // unite two tree
    void unite(int x, int y) { link(findSet(x), findSet(y)); }
    void link(int x, int y) { // ignoring size except for root
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
    }

    // travel the parents of tree recursivily to find root
    int findSet(int x) {
        if (x != parents[x]) {
            parents[x] = findSet(parents[x]); // change the x's parent to the root of tree.
        }
        return parents[x];
    }

    int treeSize(int x) { return size[findSet(x)]; }
};

int main() {
    ll N, M;
    cin >> N >> M;
    auto A = make_vec<ll>(M);
    auto B = make_vec<ll>(M);
    REP(i, M) {
        cin >> A.at(i) >> B.at(i);
        A[i]--;
        B[i]--;
    }

    UnionFindTreeBySize uft = UnionFindTreeBySize(N); // make trees

    auto ans = make_vec<ll>(M);
    ans[M - 1] = (N - 1) * N / 2;
    RREP(i, M - 2) {
        if (uft.same(A[i + 1], B[i + 1])) {
            ans[i] = ans[i + 1];
        } else {
            ans[i] = ans[i + 1] - ll(uft.treeSize(A[i + 1])) * ll(uft.treeSize(B[i + 1]));
            uft.unite(A[i + 1], B[i + 1]);
        }
    }
    for (auto i : ans) {
        cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 4480
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair < short , short > Pi;
#define y first
#define x second
#define INF ( 1 << 30 )
#define SQR(x) ((x)*(x))
Pi p[500000];
int main(){
  int n;
  scanf("%d", &n);
  for(int i = 0 ; i < n ; i++ ){
    scanf("%hd %hd", &p[i].y, &p[i].x);
  }
  sort( p, p + n);
  int ret = INF;
  for(int i = 0 ; i < n ; i++ ){
    for(int j = i + 1 ; j < n ; j++ ){
      if( SQR(p[i].y - p[j].y) >= ret) break;
      ret = min( ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
    }
  }
  printf("%d\n", ret);
}

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

int main() {

    int N;
    vector<int> a(100010, 0);

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

    int pairs = 0;
    for (int i=1; i<=N; i++) {
        if (i == a[a[i]]) {
            pairs++;
        }
    }

    cout << pairs/2 << endl;

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair < int , int > Pt;
bool dp[1 << 24];
Pt pts[24];
int n, r[24], c[24];
int hoge[24];
const int INF = 1 << 28;
bool intersect( Pt a, Pt b, int r1, int r2){
  return pow( a.first - b.first, 2) + pow( a.second - b.second, 2) < pow( r1 + r2, 2);
}

int rec( int bit){
  if(dp[bit]++) return -INF;
  int ret = 0;

  for(int i = 0 ; i < n ; i++ ){
    if((bit >> i) & 1){
      for(int j = i + 1 ; j < n ; j++ ){
        if( (bit >> j) & 1 && c[i] == c[j] && !(bit & hoge[i]) && !(bit & hoge[j])){
          ret = max( ret, rec( bit & ~(1 << i) & ~(1 << j)) + 2);
        }
      }
    }
  }
  return ret;
}
int main()
{
  while(cin >> n, n){
    fill_n( dp, 1 << 24 , false);
    fill_n( hoge, 24 , 0);

    for(int i = 0 ; i < n ; i++ ){
      cin >> pts[i].first >> pts[i].second >> r[i] >> c[i];
      for(int j = 0 ; j < i ; j++ ){
        if(intersect(pts[i],pts[j],r[i],r[j])) hoge[i] |= 1 << j;
      }
    }
    cout << rec((1 << n) - 1) << endl;
  }
}

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

long long N, Q;
static long long X[200000] = {};
static bool visited[200000] = {};
vector<long long> V[200000];

void DFS(long long P, long long COUNT) {
	visited[P] = true;
	X[P] += COUNT;
	for (long long NP : V[P]) {
		if (!visited[NP]) {
			DFS(NP, X[P]);
		}
	}
}

int main() {
	cin >> N >> Q;
	for (int i = 0; i < N - 1; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	for (int i = 0; i < Q; i++) {
		long long p, x;
		cin >> p >> x;
		p--;
		X[p] += x;
	}
	DFS(0, 0);
	for (int i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << X[i];
	}
	cout << endl;
}

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

#define REP(i,n) for(ll i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;

/* XOR A to B Template */
long long xorAtoBs(long long a) {
     long long res[] = {a,1,a+1,0};
     return res[a%4];
}

long long xorAtoB(long long a, long long b) {
     return xorAtoBs(b)^xorAtoBs(a-1);
}
/* END */

int main(){
	ll A,B;
	cin >> A >> B;
	if(A==0)A++;
	cout << xorAtoB(A,B) << endl;
}


Measured memory_bytes: 256
n=int(input())
b=list(map(int,input().split()))
a=[]
a.append(b[0])
a.append(b[0])
for i in range(1,n-1):
    if b[i]<b[i-1]:
        a[i]=b[i]
    a.append(b[i])
print(sum(a))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
using llong = long long;

llong n;
llong a[200005];

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

    llong sum = 0;
    for (int i = 0; i < n; i++) {
        sum ^= a[i];
    }

    for (int i = 0; i < n; i++) {
        cout << (sum ^ a[i]) << ' ';
    }
    cout << endl;
}

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

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,k=LI()

  if a<=k:
    if b<=k-a:
      print(0,0)
    else:
      print(0,b-(k-a))
  else:
    print(a-k,b)

main()
# print(main())


Measured memory_bytes: 7752
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int a = scn.nextInt();
		int b = scn.nextInt();
      	int k = scn.nextInt();
      	if(k>(a+b)/2-a){
        	for(int i=0; i<b-a+1; ++i){
				System.out.println(a+i);
			}
        }else if(a==b){
          System.out.println(a);
        }else{
         	for(int i=a; i<=a+k-1; ++i){
				System.out.println(i);
			}
          	for(int i=b-k+1; i<=b; ++i){
				System.out.println(i);
			}
        }
	}
}


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


using namespace std;
int main()
{

int a,b,x;
    
    cin >> a >> b >> x;
    if(x >= a && x <= a + b){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> map = new TreeMap<>();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if (map.containsKey(tmp)) {
                map.put(tmp, map.get(tmp) + 1);
            } else {
                map.put(tmp, 1);
                list.add(tmp);
            }
        }
        long count = 0;
        for (int i = 0; i < list.size(); i++) {
            if (map.get(list.get(i)) < list.get(i)) {
                count += map.get(list.get(i));
            } else {
                count += map.get(list.get(i)) - list.get(i);
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 65016
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;


int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a;
    }

    if(h - sum > 0){
        cout  << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }


}

Measured memory_bytes: 640
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    X = list(map(int, readline().rstrip().split()))
    len_m = len([x for x in X if x < 0])
    len_p = len([x for x in X if x > 0])
    ans = 10**10
    idx = max(0, len_m-K)
    s = [0] + X[idx:idx+K-1]
    for i in range(max(0, len_m-K), min(len_m+K, N-K+1)):
        s.pop(0)
        s.append(X[i+K-1])
        if len(s) != K:
            continue
        if s[0] < 0 and s[-1] > 0:
            c = min(abs(s[0]) * 2 + s[-1], abs(s[0]) + s[-1] * 2)
        else:
            c = max(abs(s[0]), abs(s[-1]))
        ans = min(ans, c)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14480