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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
const ll mod = mods[0];
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll powl(ll x,ll r,ll mod = mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

class bit {
private:
	vl* v;
	ll n;
public:
	bit (ll n) {
		this->v = new vl(n+1);
		this->n = n;
	}
	void add(ll i,ll val){
		for(;i <= n;i += i&-i) this->v->at(i) += val;
	}
	ll sum(ll i){
		ll ret = 0;
		for(;i > 0;i -= i&-i) ret += this->v->at(i);
		return ret;
	}
};

ll n;
vl x,y;
vl y_sorted;
vl idx;
vl reg1,reg2,reg3,reg4;
set<ll> s;
bit b(0);
unordered_map<ll,ll> y_zip;

ll ans;

int main(){
  cin >> n;
  x = y = vl(n);
  for(ll i = 0;i < n;i++) cin >> x[i] >> y[i];
  reg1 = reg2 = reg3 = reg4 = vl(n);
  idx = vl(n);
  iota(idx.begin(),idx.end(),0ll);
  y_sorted = y;
  sort(y_sorted.begin(),y_sorted.end());

  for(ll i = 0;i < n;i++){
    y_zip[y_sorted[i]] = i+1;
  }
  // calc reg1
  sort(idx.begin(),idx.end(),[](ll a,ll b){
    return x[a] < x[b];
  });
  b = bit(n);
  for(ll i : idx){
    reg1[i] = b.sum(y_zip[y[i]]);
    b.add(y_zip[y[i]], 1);
  }
  // calc reg2
  b = bit(n);
  for(ll i : idx){
    reg2[i] = b.sum(n)-b.sum(y_zip[y[i]]);
    b.add(y_zip[y[i]], 1);
  }
  // calc reg3
  sort(idx.rbegin(),idx.rend(),[](ll a,ll b){
    return x[a] < x[b];
  });
  b = bit(n);
  for(ll i : idx){
    reg3[i] = b.sum(y_zip[y[i]]);
    b.add(y_zip[y[i]], 1);
  }
  // calc reg4
  b = bit(n);
  for(ll i : idx){
    reg4[i] = b.sum(n)-b.sum(y_zip[y[i]]);
    b.add(y_zip[y[i]], 1);
  }

  // for(ll i = 0;i < n;i++){
  //   cerr << reg1[i] << " " << reg2[i] << " " << reg3[i] << " " << reg4[i] << endl;
  // }
  // return 0;

  for(ll i = 0;i < n;i++){
    ll mem = 0;
    mem += (powl(2, reg1[i]+reg2[i])-1+mod)%mod;
    mem += (powl(2, reg1[i]+reg3[i])-1+mod)%mod;
    mem += (powl(2, reg2[i]+reg4[i])-1+mod)%mod;
    mem += (powl(2, reg3[i]+reg4[i])-1+mod)%mod;
    mem %= mod;
    mem -= (powl(2, reg1[i])-1+mod)%mod;
    mem = (mem+mod)%mod;
    mem -= (powl(2, reg2[i])-1+mod)%mod;
    mem = (mem+mod)%mod;
    mem -= (powl(2, reg3[i])-1+mod)%mod;
    mem = (mem+mod)%mod;
    mem -= (powl(2, reg4[i])-1+mod)%mod;
    mem = (mem+mod)%mod;
    ans += (powl(2, n)-1+mod-mem+mod)%mod;
    ans %= mod;
  }
  cout << ans << endl;




}


Measured memory_bytes: 27208
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n;
  std::string s;
  Solver() {
    S002 r;
    r >= n >= s;
  }
  void solve() {
    long x = 0;
    long res = 0;
    for(char c : s) {
      if( c == 'I' ) {
        x += 1;
      }
      else if( c == 'D' ) {
        x -= 1;
      }
      res = std::max(res, x);
    }
    printf("%ld\n", res);
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}

for i in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

ans_buf = []
max_c =0
for key in d.keys():
    if d[key] > max_c:
        ans_buf = []
        ans_buf.append(key)
        max_c = d[key]
    elif d[key] == max_c:
        ans_buf.append(key)
    else:
        continue

ans_buf.sort()
for a in ans_buf:
    print(a)

Measured memory_bytes: 32096
#include <iostream>
#include <cmath>

int main()
{
	int a, b;
	std::cin >> a >> b;

	double d;
	if (b < 10)
	{
		d = a * 10 + b;
	}
	else if (b < 100)
	{
		d = a * 100 + b;
	}
	else
	{
		d = a * 1000 + b;
	}

	if (sqrt(d) == (int)sqrt(d))
	{
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}

	return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll X, A, B;
  cin >> X >> A >> B;
  if (B <= A) {
    cout << "delicious" << endl;
  } else if (B - A > X) {
    cout << "dangerous" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;
const ll MOD = 998244353;

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

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> minv(N + 1);
    minv[1] = 1;
    for (ll i = 2; i <= N; i++) {
        minv[i] = MOD - MOD / i * minv[MOD % i] % MOD;
    }
    vector<ll> fac(N + 1), ifac(N + 1);
    fac[0] = ifac[0] = 1;
    for (ll i = 1; i <= N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        ifac[i] = ifac[i - 1] * minv[i] % MOD;
    }
    ll ans = 0;
    for (ll i = 0; i <= K; i++) {
        ll cnt = M * pow(M - 1, N - 1 - i) % MOD;
        (cnt *= fac[N - 1] * ifac[N - 1 - i] % MOD * ifac[i] % MOD) %= MOD;
        (ans += cnt) %= MOD;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, a, b; cin >> n >> a >> b;

    if (b - a == 1) {
        puts("Borys");
        return 0;
    }

    while (b - a > 1) {
        a++;
        if (b - a == 1) {
            puts("Alice");
            return 0;
        }

        b--;
        if (b - a == 1) {
            puts("Borys");
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int X,A,B;

	cin >> X >> A >> B;

	cout << (X-A) % B << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
//AKIHABARA
int main(){
  string s;
  cin >> s;
  map<string,bool>ok;
  rep(i,2)rep(j,2)rep(k,2)rep(l,2){
    string tmp;
    if(i)tmp += 'A';
    tmp += "KIH";
    if(j)tmp += 'A';
    tmp += "B";
    if(k)tmp += 'A';
    tmp += 'R';
    if(l)tmp += "A";
    ok[tmp] = true;
  }
  if(ok[s])cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

#define FOR(s, i, n) for(int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if (k <= a){
		cout<<k<<'\n';
	}else if(k <= a+b){
		cout<<a<<'\n';
	}else{
		cout<<a-(k-a-b)<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3648
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll N, v;
	while(cin>>N) {
		ll n0=0, n1=0, n2=0;
		REP(i, N) {
			cin>>v;
			if(v%4==0) n2++;
			else if(v%2==0) n1++;
			else n0++;
		}
		bool ans=1;
		if(n1==0) ans = n2>=n0-1;
		else ans = n2>=n0;
		
		cout<<(ans?"Yes":"No")<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef unsigned long long ll;

int main()
{
  int h, w;
  cin >> h >> w;
  string s[h + 2], str;
  s[0] = "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
  s[h + 1] = "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
  for (int i = 1; i <= h; i++) {
    s[i] = 'a';
    cin >> str;
    s[i] += str + 'a';
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int cnt = 0;
      if (s[i][j] == '#') {
        cout << '#';
        continue;
      }
      if (s[i - 1][j - 1] == '#') cnt++;
      if (s[i - 1][j] == '#') cnt++;
      if (s[i - 1][j + 1] == '#') cnt++;
      if (s[i][j - 1] == '#') cnt++;
      if (s[i][j + 1] == '#') cnt++;
      if (s[i + 1][j - 1] == '#') cnt++;
      if (s[i + 1][j] == '#') cnt++;
      if (s[i + 1][j + 1] == '#') cnt++;
      cout << cnt;
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
// AOJ Volume 0 Problem 0025

#include <stdio.h>

int main(void)
{
    int a[4], b[4];
	int hit, blow;
	int i, j;
	
    while (scanf("%d%d%d%d%d%d%d%d",
				&a[0], &a[1], &a[2], &a[3],
				&b[0], &b[1], &b[2], &b[3]) != EOF){

		hit = blow = 0;
		for (i = 0; i < 4;i++){
			for (j = 0; j < 4; j++){
//				printf("(%d-%d)", a[i], b[j]);
				if (a[i] == b[j]){
					if (i == j){
						hit++;
					}
					else {
						blow++;
					}
				}
			}
		}
		
		printf("%d %d\n", hit, blow);
		
	}
    
    return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int calc_area(int x, int y){
    return x * y;
}

int calc_around(int x, int y){
    return x * 2 + y * 2;
}

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

    int ans1 = calc_area(a,b);
    int ans2 = calc_around(a,b);

    cout << ans1 << ' ' << ans2 << endl;
    return 0;
}
 
 



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll cnt[5]={},ans=0;
  int n;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    switch(s[0]){
      case 'M':cnt[0]++;break;
      case 'A':cnt[1]++;break;
      case 'R':cnt[2]++;break;
      case 'C':cnt[3]++;break;
      case 'H':cnt[4]++;break;
    }    
  }
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(i==j) continue;
      for(int k=0;k<5;k++){
        if(i==k||j==k) continue;
        ans+=cnt[i]*cnt[j]*cnt[k];
      }
    }
  }
  cout<<(ans/6)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;


int sum(int n){
    if(n==0) return 0;
    else return n+sum(n-1);
    
}



int main()
{
    int a,b;
    cin >> a >> b;
    int c = sum(b-a);
    cout << c-b << endl;
    
    
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
    ll N, A, B, C, D, E;
    cin >> N;
    vector<ll> gate(5);

    ll min_gate = INF;
    rep(i, 5) {
        cin >> gate.at(i);
        min_gate = min(min_gate, gate.at(i));
    }

    if(N%min_gate == 0) {
        ll ans = N/min_gate + 4;
        cout << ans << endl;
    }
    else{
        ll ans = N/min_gate + 5;
        cout << ans << endl;        
    }
    
}

Measured memory_bytes: 256
import sys
import fractions
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    print(A*B//fractions.gcd(A,B))

if __name__ == '__main__':
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

struct UnionFindSize {
    vector<int> par;
    
    UnionFindSize(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

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

    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    UnionFindSize uf(N);

    REP(i, M){
    	ll x, y;
    	cin >> x >> y;
    	uf.merge(x, y);
    }

    //REP(i, N) dump(uf.root(i))

    vector<ll> rs;
    REP(i, N) rs.push_back(uf.root(i));
    sort(rs.begin(), rs.end());
    rs.erase(unique(rs.begin(), rs.end()), rs.end());
    ll K = rs.size();
    map<ll, ll> mp;
    REP(i, rs.size()) mp[rs[i]] = i;

    vector<vector<ll>> com(K);
    REP(i, N){
    	com[mp[uf.root(i)]].push_back(a[i]);
    }
    REP(i, K) sort(com[i].begin(), com[i].end());

    ll res = 0;
    vector<ll> cand;

    REP(i, K){
    	REP(j, com[i].size()){
    		if(j==0) res += com[i][j];
    		else{
    			cand.push_back(com[i][j]);
    		}
    	}
    }

    if(K==1){
    	cout << 0 << endl;
    	return 0;
    }

    sort(cand.begin(), cand.end());
    if((int)cand.size()<K-2){
    	cout << "Impossible" << endl;
    }else{
    	REP(i, K-2) res += cand[i];
    	cout << res << endl;
    }

    //cout << com << endl;
    return 0;
}

Measured memory_bytes: 13940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n;
vector<vector<int>> g;
vector<bool> chk;

int dfs(int p = 0, int c = 0)
{
  if (chk[p])
    return 0;
  c++;
  if (c == n)
    return 1;
  chk[p] = true;
  int ret = 0;
  for (auto& nxt : g[p])
    ret += dfs(nxt, c);
  chk[p] = false;
  return ret;
}

int main()
{
  int m;
  cin >> n >> m;
  g.resize(n);
  rep(i, m)
  {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  chk.resize(n);
  fill(chk.begin(), chk.end(), false);
  cout << dfs() << endl;
  return 0;
}

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

const int MOD = 1000000007;
struct modint {
  long long val;
  modint(long long val=0) : val((val % MOD + MOD) % MOD){}
  modint operator-() const { return modint(-val); }
  modint& operator+=(const modint a) { if ((val += a.val)     >= MOD) val -= MOD; return *this; }
  modint& operator-=(const modint a) { if ((val += MOD-a.val) >= MOD) val -= MOD; return *this; }
  modint& operator*=(const modint a) { (val *= a.val) %= MOD; return *this; }
  modint operator+(const modint a) const { return (modint)*this += a; }
  modint operator-(const modint a) const { return (modint)*this -= a; }
  modint operator*(const modint a) const { return (modint)*this *= a; }
  modint pow(long long n) const { modint r(1), m(val); while (n > 0) { if (n & 1) {r *= m;} m *= m; n >>= 1; } return r; }
  modint inv() const { return pow(MOD-2); }
  modint& operator/=(const modint a) { return (*this) *= a.inv(); }
  modint operator/(const modint a) const { return (modint)*this /= a; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  friend ostream &operator<<(ostream &os, const modint &p) { return os << p.val; }
  friend istream &operator>>(istream &is, modint &a) { long long t; is >> t; a = modint(t); return (is); }
};

struct mod_combination {
  /* initialize: O(n) */
  /* choose    : O(1) */
  vector<modint> fact, fact_inv, inv;
  mod_combination(int n) : fact(n+1, 1), fact_inv(n+1, 1), inv(n+1, 1) {
    for (int i = 2; i <= n; i++) {
      fact[i] = fact[i - 1] * i;
      inv[i] = -inv[MOD % i] * (MOD / i);
      fact_inv[i] = fact_inv[i - 1] * inv[i];
    }
  }
  modint choose(int n, int k) { return fact[n] * fact_inv[k] * fact_inv[n - k]; }
};

int n,k; 

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

  mod_combination mc(n);

  modint ans = 0;
  for(int i=0; i<=min(n-1,k); i++) {
    ans += mc.choose(n,i) * mc.choose(n-1, i);
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 100100;
int choco[10][1000];

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(W);
    rep(i,H) cin >> s[i];
    int ans = INF, num_div;
    rep(div, 1<<(H-1)) {
        int g = 0;
        vector<int> group(H);
        rep(i,H) {
            group[i] = g;
            if (div>>i&1) g++;
        }
        num_div = g;
        g++;
        rep(i,g) rep(j,W) choco[i][j] = 0;
        rep(i,H) rep(j,W) choco[group[i]][j] += (s[i][j] - '0');
        vector<int> now(g);
        auto add = [&](int j) {
            rep(i,g) now[i] += choco[i][j];
            rep(i,g) if (now[i] > K) return false;
            return true;
        };
        rep(j, W) {
            if (!add(j)) {
                num_div++;
                now = vector<int>(g);
                if (!add(j)) {
                    num_div = INF;
                    break;
                }
            }
        }
        ans = min(ans, num_div);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def checkmine(i,j):
    count=0
    for a in range(-1,2):
        for b in range(-1,2):
            if 0<=a+i<n and 0<=b+j<m:
                if field[a+i][b+j]=="#":count+=1
    return count

n,m=map(int,input().split())
field=[]
for i in range(n):field.append(list(input()))
for i in range(n):
    for j in range(m):
        if field[i][j]==".":field[i][j]=checkmine(i,j)
for i in field:print(''.join(map(str,i)))

Measured memory_bytes: 3064
import numpy as np
from numba import njit
N,K=[int(_) for _ in input().split()]
A = np.array([int(_) for _ in input().split()],dtype=int)
A.sort()


@njit
def main(N,K,A):
    lb = -10**18-1
    rb = 10 ** 18 + 1
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                elif a < 0:
                    il = np.searchsorted(A,0- (-target)//a,side='left')
                    d = max(i - il, 0)
                else:
                    ir = np.searchsorted(A,target//a,side='right')
                    d = min(ir, i)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

print(main(N,K,A))


Measured memory_bytes: 113736
h, w = [int(i) for i in input().split()]
adj = [["" for _ in range(w)] for j in range(h)]
for i in range(h):
    _tmp = input()
    for j in range(w):
        adj[i][j] = _tmp[j]
# for i in range(h):
    # print(adj[i])
for i in range(h):
    for j in range(w):
        if (i > 0 or j > 0) and adj[i][j] == "#":
            okFlag = False
            if i > 0 and adj[i - 1][j] == "#":
                okFlag = True
                adj[i - 1][j] = "."
            elif j > 0 and adj[i][j - 1] == "#":
                okFlag = True
                adj[i][j - 1] = "."
            if not okFlag:
                print("Impossible")
                # print("[{},{}]".format(i, j))
                exit()
print("Possible")
# for i in range(len(adj)):
    # print(adj[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int solve(int n, int m, vector<vector<bool> > g) {
    // check whether the complement graph is a bipartite graph or not
    vector<pair<int, int> > bipartite;
    vector<int> used(n);
    function<void (int)> go = [&](int i) {
        (used[i] == 1 ? bipartite.back().first : bipartite.back().second) += 1;
        REP (j, n) if (i != j and not g[i][j]) {
            if (used[j]) {
                if (used[j] != - used[i]) {
                    throw -1;  // not a bipartite graph
                }
            } else {
                used[j] = - used[i];
                go(j);
            }
        }
    };
    REP (i, n) if (not used[i]) {
        bipartite.emplace_back(0, 0);
        used[i] = 1;
        try {
            go(i);
        } catch (int) {
            return -1;
        }
    }

    // knapsack
    vector<bool> cur(n + 1), prv;
    cur[0] = true;
    for (auto it : bipartite) {
        int a, b; tie(a, b) = it;
        cur.swap(prv);
        cur.assign(n + 1, false);
        REP_R (i, n + 1) {
            if (i - a >= 0 and prv[i - a]) cur[i] = true;
            if (i - b >= 0 and prv[i - b]) cur[i] = true;
        }
    }
    int a = n / 2;
    while (not cur[a]) -- a;
    int b = n - a;
    return a * (a - 1) / 2 + b * (b - 1) / 2;
}

int main() {
    int n, m; cin >> n >> m;
    auto g = vectors(n, n, bool());
    REP (i, m) {
        int a, b; cin >> a >> b;
        -- a; -- b;
        g[a][b] = true;
        g[b][a] = true;
    }
    cout << solve(n, m, g) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 89184
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int64_t,int64_t>
#define mp make_pair
#define whole(v) begin(v),end(v)
#define print(c,n) for(int64_t i=0;i<n;i++) cout << c[i] << " ";
#define MOD 1000000007
int dp[1006][1006];
void solve(){
	int n,m;
	cin >> n >> m;
	char arr[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> arr[i][j];
		}
	}

	for(int i=0;i<m;i++){
		if(arr[0][i]=='#'){
			for(int j=i;j<m;j++){
				dp[0][i]=0;
			}
			break;
		}
		else{
			dp[0][i]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(arr[i][0]=='#'){
			for(int j=i;j<n;j++){
				dp[i][0]=0;
			}
			break;
		}
		else{
			dp[i][0]=1;
		}
	}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(arr[i][j]=='#') continue;
			dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
		}
	}
	// for(int i=0;i<n;i++){
	// 	for(int j=0;j<m;j++){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	cout << dp[n-1][m-1] << "\n";
}
int main(){
	
	solve();
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,h[100000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int dp[100100];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 54;
int n, m;
vector<int> adj[N];
map<pair<int, int>, int> ite;
long long int mask[N];
int u[N], v[N];
bool dfs(int v, int p, int f, long long int ta)
{
    if (v == f)
        return true;
    // cout<<ta<<" "<<endl;
    for (auto it : adj[v])
    {
        if (it != p)
        {
            if (dfs(it, v, f, ta))
            {
                // cout<<it<<"*\n";
                mask[ite[make_pair(v, it)]] |= ta;
                return true;
                // mask[ite[make_pair(it, v)]] += ta;
            }
        }
    }
    return false;
}
long long int dp[50][(1<<20)];
bool vis[50][1<<20];
long long int solve(int i, long long int j)
{
    if (i == n)
    {
        return (j == ((1 << m) - 1));
    }
    if(!vis[i][j])
    {
        dp[i][j]=solve(i + 1, j | mask[i]) + solve(i + 1, j);
        vis[i][j]=true;
    }
    return dp[i][j];
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        ite[make_pair(a, b)] = i;
        ite[make_pair(b, a)] = i;
    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> u[i] >> v[i];
        dfs(u[i], u[i], v[i], 1 << (i - 1));
    }
    // for(int i=1;i<=n-1;i++)
    //     cout<<mask[i]<<" ";
    cout << solve(1, 0);
}

Measured memory_bytes: 405760
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		 long double   ld;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;


int main()
{

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll f=1;
    ll ans=a*d;
    ans=max(ans,a*c);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<nn;






}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

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

int N;
set<pii> st;
set<pii>::iterator ite;
ll A, B = 0;

int main()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
    {
        int k;
        cin >> k;
        if(k == 1)
        {
            int a, b;
            cin >> a >> b;
            B += b;
            if(st.empty())
            {
                st.insert(mk(a, i));
                st.insert(mk(a, -i));
                A = 0;
                ite = st.begin();
            }
            else
            {
                if(ite->fi == a)
                {
                    st.insert(mk(a, i));
                    st.insert(mk(a, -i));
                }
                else if(a < ite->fi)
                {
                    st.insert(mk(a, i));
                    st.insert(mk(a, -i));
                    ll tmp = ite->fi;
                    ite--;
                    A += labs(tmp - a);
                }
                else
                {
                    st.insert(mk(a, i));
                    st.insert(mk(a, -i));
                    ll tmp = ite->fi;
                    ite++;
                    A += labs(tmp - a);
                    A -= labs(ite->fi - tmp);
                }
            }
        }
        else cout << ite->fi << " " << A + B << endl;
    }

    return 0;
}


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

long long int getSub(long long int a, long long int b, long long int c){
    long long int red, blue;
    red = ((a/2)+(a%2)) * b * c;
    blue = a/2 * b * c;
    return abs(red-blue);
}

int main(){
    long long int a, b, c;
    cin >> a >> b >> c;
    long long int min  = getSub(a,b,c);
    min = getSub(a,c,b) < min ? getSub(a,c,b) : min;
    min = getSub(b,a,c) < min ? getSub(b,a,c) : min;
    min = getSub(b,c,a) < min ? getSub(b,c,a) : min;
    min = getSub(c,a,b) < min ? getSub(c,a,b) : min;
    min = getSub(c,b,a) < min ? getSub(c,b,a) : min;

    cout << min << endl;
}

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

using namespace std;

int main()
{
    long long x1, y1, x2, y2, s;
    cin >> s;

    long long x = ceil(sqrt(s));
    x2 = 1;
    y1 = x * x - s;
    x1 = y2 = x;

    cout << 0 << ' ' << 0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2;

    return 0;
}

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

using namespace std;

const int N = 1e5;
int h[N], min_cost[N], n;

int main(){
    cin >> n;

    for(int i = 0; i < n; ++i)
        cin >> h[i];

    min_cost[1] = abs(h[1] - h[0]);

    for(int i = 0, j = 1, k = 2; k < n; i = j, j = k++)
        min_cost[k] = min(min_cost[i]+abs(h[k]-h[i]),min_cost[j]+abs(h[k]-h[j]));

    cout << min_cost[n-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.List

main=do
    [n,m]<-map read.words<$>getLine::IO[Int]
    abs<-replicateM n $ map read.words<$>getLine::IO[[Int]]
    cds<-zip [1..] <$> replicateM m (map read.words<$>getLine)::IO[(Int,[Int])]
    mapM_ print $ map (search cds) abs

search cds [a,b] = snd $ minimum $ map (\(i,[c,d])-> (abs (a-c) + abs (b-d), i)) cds


Measured memory_bytes: 1020
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])

Measured memory_bytes: 3064
var n,a,b,i,ans  :int32;

function gcd(x,y:integer):integer;
begin
  if x mod y = 0 then gcd:=y
  else gcd:=gcd(y,x mod y)
end;

begin
  readln(n);
  read(a);
  for i:=2 to n do begin
    if a=1 then break;
    read(b);
    a:=gcd(a,b)
  end;
  write(a)
end.
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    vector< vector<int>> a(3,vector<int>(3,0));
    rep(i,3)rep(j,3)cin >> a.at(i).at(j);
    int n;
    cin >> n;
    vector<int> b(n,0);
    rep(i,n)cin >> b.at(i);
    rep(k,n){
        rep(i,3)rep(j,3){
            if(a[i][j] == b[k]){
                a[i][j] = 0;
            }
        }
    }
    rep(i,3){//横
        if(a[i][0]+a[i][1] + a[i][2] == 0){cout << "Yes" << endl;return 0;}
    }
    //縦
    rep(i,3){
        if(a[0][i]+a[1][i] + a[2][i] == 0){cout << "Yes" << endl;return 0;}
    }
    if(a[0][0] + a[1][1] + a[2][2] == 0){cout << "Yes" << endl;return 0;}
    if(a[0][2] + a[1][1] + a[2][0] == 0){cout << "Yes" << endl;return 0;}

    cout << "No" << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n;
	cin>>n;
	ll ans=1,mod=1e9+7;
	ll cnt[3]={};
	for(int i=1;i<=n;i++){
		ll x;
		cin>>x;
		ll num=0;
		for(int j=0;j<3;j++)if(cnt[j]==x)num++;
		for(int j=0;j<3;j++){
			if(cnt[j]==x){
				cnt[j]++;
				break;
			}
		}
		ans*=num;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long int N, denominator = 10, total = 0;
    cin >> N;
    if(N%2 == 1)
        cout << 0 << endl;
    else{
        while(denominator <= N){
            total += N/denominator;
            denominator *= 5;
        }
        cout << total;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	 
	Scanner sc= new Scanner (System.in);
	int n = sc.nextInt();
	int i[];
	i = new int[3];
for(int count=0;count<n;count++){	
		for(int d=0;d<3;d++ ){
			i[d]=sc.nextInt();
		}
		Arrays.sort(i);
		if((i[2]*i[2])==(i[0]*i[0])+(i[1]*i[1])){
			System.out.println("YES");
		}
		else System.out.println("NO");
		}
	 
	
	}

}

Measured memory_bytes: 23376
/**
 *      ABC 48 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-20 07:17:18
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string A, s; cin >> A >> s;
    cout << 'A' << s[0] << 'C' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;

int main()
{
	int n;
	cin >> n;
	priority_queue<double, vector<double>, greater<double>> v;
	double tmp;
	for (int i = 0; i < n; ++i)
	{
		cin >> tmp;
		v.push(tmp);
	}

	while (v.size() > 1)
	{
		double x = v.top();
		v.pop();
		double y = v.top();
		v.pop();
		v.push((x + y) / 2);
	}
	cout << setprecision(10) << v.top() << endl;

	return 0;
}


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

#define ld long double
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)

const int N=1e5;
int A[N],B[N],C[N],D[N];

struct hash_pair{
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};

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

ll power(ll x,ll y,ll p){
	ll res = 1;
	x = x%p;
	while(y > 0){
		if(y&1)
			res = (res*x)%p;
		y = y>>1;
		x = (x*x)%p;
	}
	return res;
}

int root(int i){
	while(A[i] != i){
		A[i] = A[A[i]];
		i = A[i];
	}
	return i;
}

void unite(int a,int b){
	int c = root(a);
	int d = root(b);
	if(c == d)
		return;
	if(B[c] < B[d]){
		A[c] = d;
		B[d] += B[c];
	}
	else{
		A[d] = c;
		B[c] += B[d];
	}
}

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	int n,m,k,a,b;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		A[i] = i;
		B[i] = 1;
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		a--,b--;
		D[a]++;
		D[b]++;
		// cout<<a<<" "<<b<<"\n";
		unite(a,b);
	}
	for(int i=0;i<n;i++)
		C[i] = B[root(i)]-D[i];
	for(int i=0;i<k;i++){
		cin>>a>>b;
		a--,b--;
		if(root(a) == root(b)){
			C[a]--;
			C[b]--;
		}
	}
	for(int i=0;i<n;i++)
		cout<<C[i]-1<<" ";

	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
    int i,a,b,c,k,ans;

    ans = 0;

    cin >> a >> b >> c >> k;

    if(a <= k){
        ans += a;
        k -= a;
        if(b <= k){
            ans -= (k - b);
        }
    }else{
        ans = k;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a,b; cin >> a >> b;
    if(a+b >= 10) cout << "error" << endl;
    else cout << a+b << endl;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	int A[N+2];
	A[N + 1] = 0;
	A[0] = 0;
	for (int i = 1; i < N+1; i++) {
		cin >> A[i];
	}
	long long def=0;
	for (int i = 1; i < N+2; i++) {
		def += abs(A[i] - A[i - 1]);
	}
	for (int i = 1; i <= N; i++) {
		if ((A[i + 1] - A[i])*(A[i - 1] - A[i]) < 0) cout << def << endl;
		else {
			cout << def - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main()
{
    string s,t;
    long long c=0;
    cin>>s>>t;
    int len=s.length();
    for (int i=0;i<len;i++)
    {
        if (s[i]==t[i])continue;
        else c++;
    }
    cout<<c;
}


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

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

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n;
    cin >> n;

    int ans1 = 0, ans2 = 0;

    loop(i, n){
        string str1, str2;
        cin >> str1 >> str2;

        if(str1 < str2) ans2 += 3;
        else if(str1 > str2) ans1 += 3;
        else {ans1++; ans2++;}
    }

    cout << ans1 << " " << ans2 << endl;

    return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    ll ans = 0;
    rep(i,n){
        ll cnt1 = n - (upper_bound(ALL(c),b[i]) - c.begin());
        ll cnt2 = lower_bound(ALL(a), b[i]) - a.begin();
        ans += cnt1 * cnt2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;


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


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

using namespace std;
const int maxn = 1e5+7;
const int INF = 1e9 + 7;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,w,taka[maxn][2];
	cin >> n >> w;
	int weight[n],value[n],nax = 0;
	for(int i = 0;i<maxn;i++) taka[i][0] = taka[i][1] = INF;
	for(int i = 0;i<n;i++) cin >> weight[i] >> value[i];
	taka[0][0] = taka[0][1] = 0;
	for(int i = 0 ;i<n;i++) {
		int curr  = i&1,next = 1 - curr;
		for(int j = 0;j<maxn;j++) {
			if((taka[j][curr]<INF||j == 0)&&taka[j][curr]<=w-weight[i]) {
				taka[j+value[i]][next] = min(taka[j+value[i]][next],taka[j][curr]+weight[i]);
				nax = max(nax,j+value[i]);
				
			}
			taka[j][next] = min(taka[j][curr],taka[j][next]);
		}
	}
	cout <<nax;
	return 0;
}

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

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb(i) push_back(i)
#define fs first
#define sc second

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

int main(){
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int cnt = 0;
	rep(i,s.length()){
		cnt += s[i]!=t[i];
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>

#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef vector<int> vi;
typedef vector<vi>  vvi;

vvi adj;
int ans,cnt;
bool visited[100];

void dfs(int u){
	if(ans<cnt) ans=cnt;

	cnt++;
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(!visited[v]){
			visited[v]=true;
			dfs(v);
			visited[v]=false;
		}
	}
	cnt--;
}

int main(){
	for(int m;scanf("%d",&m),m;){
		bool adjm[100][100]={},flg[100]={};
		rep(i,m){
			int a,b; scanf("%d%d",&a,&b);
			a--, b--;
			adjm[a][b]=adjm[b][a]=flg[a]=flg[b]=true;
		}

		int f[100],n=0;
		rep(i,100) if(flg[i]) f[i]=n++;

		adj=vvi(n);
		rep(i,100) rep(j,100) if(adjm[i][j]) adj[f[i]].pb(f[j]);

		ans=0,cnt=1;
		rep(u,n-1){
			visited[u]=true;
			dfs(u);
			visited[u]=false;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 832
def main():
    n, a, b = map(int, input().split())
    if abs(a - b) % 2 == 0:
        print(abs(a - b) // 2)
    else:
        mi = min(a, b) - 1
        ma = n - max(a, b)
        print(min(mi, ma) + (abs(a - b) + 1) // 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0 ; i < n ; i++)
		cin >> a[i] >> b[i] >> c[i];

	vector<vector<int> > dp(3, vector<int>(n+1 , 0));

	for(int i = 1 ; i <= n ; i++){
		dp[0][i] = a[i-1] + max(dp[1][i-1], dp[2][i-1]);
		dp[1][i] = b[i-1] + max(dp[0][i-1], dp[2][i-1]);
		dp[2][i] = c[i-1] + max(dp[1][i-1], dp[0][i-1]);
	}
	cout << max(max(dp[0][n], dp[1][n]), dp[2][n]);
	
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 2944