akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    map<char, int> cnt;
    REP(i, H) {
        REP(j, W) {
            cin >> a[i][j];
            cnt[a[i][j]]++;
        }
    }
    // A'のどの行およびどの列もそれぞれ回文になっている。
    if(H % 2 == 0 and W % 2 == 0) {
        for(auto hoge : cnt) {
            if(hoge.second % 4) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    if(H % 2 && W % 2) {
        //両方奇数
        map<int, int> c;
        for(auto p : cnt) {
            c[p.second % 4]++;
        }
        if(c[3]) {
            cout << "No" << endl;
            return 0;
        }
        if(c[1] != 1) {
            cout << "No" << endl;
            return 0;
        }
        if(c[2] > (H - 1) / 2 + (W - 1) / 2) {
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        return 0;
    }
    if(W % 2) {
        swap(H, W);
    }
    map<int, int> c;
    for(auto p : cnt) {
        c[p.second % 4]++;
    }
    if(c[1] || c[3]) {
        cout << "No" << endl;
        return 0;
    }
    if(c[2] > W / 2) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
      ll n; cin >> n;
      vector<string> s(n) ;
      set<string> se;
	  vll p(n);
      map<string , ll > mp;
      rep(i,n){
      	cin >> s[i] >> p[i];
//      	mp[s[i]]
		se.insert(s[i]);
	  }
	  for(auto it=se.begin();it!=se.end();it++){
	  	 vll temp;
	  	 rep(j,n){
	  	 	if(s[j]==*it)temp.pb(p[j]);
		   }
		   sort(all(temp));
		   reverse(all(temp));
		   trav(k,temp){
		   	    rep(j,n){
		   	        if(p[j]==k){
		   	            cout << j+1 << endl;
		   	            break;
		   	        }
		   	    }
		   }
	  }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int h,w;cin>>h>>w;
	vector<string> v(h+1);
	for(int i=1;i<=h;i++) cin>>v[i],cout<<v[i]<<"\n"<<v[i]<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> x = {a, b, c};
    cout << x.size(); 
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string t;
    cin >> t;
    for(int mask = 0; mask < (1LL << 3); mask++){
        int now = t[0] - '0';
        string s = "";
        s += t[0];
        rep(i, 0, 3){
            if(mask & (1LL << i)){
                now += t[i + 1] - '0';
                s += "+";
                s += t[i + 1];
            }else{
                now -= t[i + 1] - '0';
                s += "-";
                s += t[i + 1];
            }
        }
        if(now == 7){
            s += "=7";
            cout << s << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<map>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,vis[15],vis2[15];
string st[15],st2[15],st3[15];
void check()
{
//	for (i=1;i<=n;i++) cerr<<st2[i]<<endl;
//	cerr<<endl;
	int i,j;
	for (i=1;i<=m;i++) st3[i]="";
	for (i=1;i<=m;i++)
	{
		for (j=1;j<=n;j++)
		{
			st3[i].push_back(st2[j][i-1]);
		}
	}
	memset(vis2,0,sizeof(vis2));
	for (i=1;i<=m;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (vis2[j]) continue;
			if (i==j) continue;
			string t=st3[j];
			reverse(t.begin(),t.end());
			/*cerr<<st[i]<<endl;
			cerr<<t<<endl;*/
			if (st3[i]==t)
			{
				vis2[j]=1;
				break;
			}
		}
	}
	int cnt=0;
	for (i=1;i<=m;i++)
	{
		if (!vis2[i])
		{
			cnt++;
			string t=st3[i];
			reverse(t.begin(),t.end());
			if (st3[i]!=t) return;
		}
	}
	if (cnt>1) return;
	cout<<"YES";
	exit(0);
}
void dfs(int x,int y)
{
	if (x<=n) dfs(x+1,y);
	if (vis[x])
	{
		return;
	}
	if (x>n)
	{
		if (n%2==1&&y==(n+1)/2)
		{
			int cnt=0;
			for (i=1;i<=n;i++)
			{
				if (!vis[i])
				{
					cnt++;
					st2[y]=st[i];
				}
			}
			if (cnt<2) check();
		}
		if (y==(n+1)/2+1) check();
		return;
	}
	int i;
	for (i=x+1;i<=n;i++)
	{
		if (vis[i]) continue;
		st2[y]=st[x];
		st2[n-y+1]=st[i];
		vis[x]=1;
		vis[i]=1;
		dfs(x+1,y+1);
		vis[i]=0;
		vis[x]=0;
	}
	if (n%2==1&&y==(n+1)/2)
	{
		int cnt=0;
		for (i=1;i<=n;i++)
		{
			if (!vis[i])
			{
				cnt++;
				st2[y]=st[i];
			}
		}
		if (cnt<2) check();
	}
	vis[x]=0;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++) cin>>st[i];
	dfs(1,1);
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int num;
	int x[10];
	int y[10];
} oresen_t;

void oresen_seikika(oresen_t* oresen) {
	int xx=oresen->x[0];
	int yy=oresen->y[0];
	int i;
	for(i=0;i<oresen->num;i++) {
		oresen->x[i]-=xx;
		oresen->y[i]-=yy;
	}
}

void oresen_reverse(oresen_t* oresen) {
	int i;
	for(i=0;i+i+1<oresen->num;i++) {
		int temp;
		temp=oresen->x[i];
		oresen->x[i]=oresen->x[oresen->num-i-1];
		oresen->x[oresen->num-i-1]=temp;
		temp=oresen->y[i];
		oresen->y[i]=oresen->y[oresen->num-i-1];
		oresen->y[oresen->num-i-1]=temp;
	}
}

void oresen_rotate(oresen_t* oresen) {
	int i;
	for(i=1;i<oresen->num;i++) {
		int temp;
		temp=oresen->x[i];
		oresen->x[i]=-oresen->y[i];
		oresen->y[i]=temp;
	}
}

int oresen_ismatch(const oresen_t* oresen1,const oresen_t* oresen2) {
	int i;
	if(oresen1->num!=oresen2->num)return 0;
	for(i=0;i<oresen1->num;i++) {
		if(oresen1->x[i]!=oresen2->x[i])return 0;
		if(oresen1->y[i]!=oresen2->y[i])return 0;
	}
	return 1;
}

void oresen_input(oresen_t* oresen) {
	int i;
	scanf("%d",&oresen->num);
	for(i=0;i<oresen->num;i++) {
		scanf("%d%d",&oresen->x[i],&oresen->y[i]);
	}
}

int main(void) {
	int n;
	while(scanf("%d",&n)==1 && n!=0) {
		oresen_t kizyun;
		oresen_t now;
		int i,j,match;
		oresen_input(&kizyun);
		oresen_seikika(&kizyun);
		for(i=1;i<=n;i++) {
			oresen_input(&now);
			oresen_seikika(&now);
			match=0;
			for(j=0;j<4;j++) {
				if(oresen_ismatch(&kizyun,&now))match=1;
				oresen_rotate(&now);
			}
			oresen_reverse(&now);
			oresen_seikika(&now);
			for(j=0;j<4;j++) {
				if(oresen_ismatch(&kizyun,&now))match=1;
				oresen_rotate(&now);
			}
			if(match)printf("%d\n",i);
		}
		puts("+++++");
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vec vector

typedef long long ll;

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

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

template<class T> T gcd(T m, T n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}

template<class T> T lcm(T m, T n) {
  return m * n / gcd(m, n);
}

const ll inf = 1LL << 60;
const int mod = 1e9 + 7;

using namespace std;

/* Input variables. */
int n;
vec<int> p;
vec<int> q;

/* Solve! */
void solve() {
  vec<int> qp(n);
  rep(i, n) {
    qp[i] = i + 1;
  }
  int a = 1, b = 1;
  do {
    if (q < qp) a++;
    if (p < qp) b++;
  } while (next_permutation(qp.begin(), qp.end()));
  cout << abs(a - b) << endl;
}

int main() {
  /* Input handling. */
  cin >> n;
  p = vec<int>(n); q = vec<int>(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

  solve();
  return 0;
}

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') bo = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { res = (res << 1) + (res << 3) + ch - '0'; ch = getchar(); }
	return bo * res;
}

template<typename T> void read(T &x) { x = read(); }
template<typename T, typename ...Argv> void read(T &a, Argv &...argv) { read(a); read(argv...); }

const int mod = 998244353;

inline int add(int a, int b) {
	a += b;
	return a >= mod ? a - mod : a;
}

inline int sub(int a, int b) {
	a -= b;
	return a < 0 ? a + mod : a;
}

inline int mul(int a, int b) { return (LL)a * b % mod; }

inline int ksm(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}	
const int inv2 = ksm(2, mod - 2);

int n, s;

inline void FWT(int *t, int n, int type) {	
	for (int step = 1; step < n; step <<= 1) {
		for (int i = 0; i < n; i += step << 1) {
			for (int j = 0; j < step; ++ j) {
				int x = t[i + j], y = t[i + j + step];
				t[i + j] = add(x, y), t[i + j + step] = sub(x, y);
				if (type == -1) {
					t[i + j] = mul(t[i + j], inv2);
					t[i + j + step] = mul(t[i + j + step], inv2);
				}
			}
		}
	}
}

const int N = 1 << 18;
int p[N], a[N];

int main() {
	read(n);
	for (int i = 0; i < 1 << n; ++ i) read(p[i]), s = add(s, p[i]);
	s = ksm(s, mod - 2);
	for (int i = 0; i < 1 << n; ++ i) p[i] = mul(p[i], s);
	for (int i = 1; i < 1 << n; ++ i) a[i] = mod - 1;
	a[0] = (1 << n) - 1;
	p[0] = sub(p[0], 1); 
	FWT(a, 1 << n, 1), FWT(p, 1 << n, 1);
	for (int i = 0; i < 1 << n; ++ i) a[i] = mul(a[i], ksm(p[i], mod - 2));
	FWT(a, 1 << n, -1);
	for (int i = 0; i < 1 << n; ++ i) {
		printf("%d\n", sub(a[i], a[0]));
	}
}

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

int main() {
  int n, m;
  cin>>n>>m;
  bool edge[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      edge[i][j] = false;
    }
  }
  for (int i=0; i<m; i++) {
    int a, b;
    cin>>a>>b;
    --a;
    --b;
    edge[a][b] = true;
    edge[b][a] = true;
  }
  int order[n-1];
  for (int i=0; i<n-1; i++) order[i] = i+1;
  int cnt = 0;
  do {
    int prev = 0;
    bool ok = true;
    for (int idx: order) {
      if (!edge[prev][idx]) {
        ok = false;
        break;
      }
      prev = idx;
    }
    if (ok) {
      ++cnt;
    }
  } while (next_permutation(order, order + n - 1));
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, e[4];

signed main() {
	rep(i,3) {
		cin >> a >> b;
		a--, b--;
		e[a]++, e[b]++;
	}
	sort(e, e+4);
	if (e[0]==1 && e[1]==1 && e[2]==2 && e[3]==2) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import accumulate, product

def inpl(): return tuple(map(int, input().split()))
N, W = inpl()
I = [inpl() for _ in range(N)]
w1 = I[0][0]
A = {w1 + x: [] for x in range(4)}

for w, v in I:
    A[w].append(v)

for k, v in A.items():
    A[k] = [0] + list(accumulate(sorted(v, reverse=True)))

res = 0

for L in product(enumerate(A[w1]),
                 enumerate(A[w1+1]),
                 enumerate(A[w1+2]),
                 enumerate(A[w1+3])):
    if sum([(w1+i)*l[0] for i, l in enumerate(L)]) <= W:
        res = max(res, sum([l[1] for l in L]))

print(res)


Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to

void main()
{
   string s = chomp(readln());
   for(int i=0; i<18; ++i){
       if(i == 5 || i == 13){
           write(" ");
       } else {
       write(s[i]);
       }
   }
   writeln(s[18]);
}

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

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

    // スタートが 0 か 1 か
    int res = 1<<29;
    for (int start = 0; start <= 1; ++start) {
        int val = start; // それぞれの数値でスタート
        int count = 0;
        for (int i = 0; i < S.size(); ++i) {
            if (S[i] - '0' != val) ++count;

            // 入れ替え
            val = 1 -val;
        }
        res = min(res, count);
    }
    cout << res << endl;
}


Measured memory_bytes: 512
#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct counting_sort_t *counting_sort_t;

struct counting_sort_t {
  uint32_t *counting_arr;
  size_t counting_arr_len;
};

static void free_counting_sort_object(counting_sort_t c)
{
  if (c != NULL) {
    free(c->counting_arr);
  }
  free(c);
}

counting_sort_t counting_sort_create(size_t n)
{
  counting_sort_t c = (counting_sort_t)malloc(sizeof(counting_sort_t));
  if (c == NULL) goto err;

  c->counting_arr_len = n;
  c->counting_arr = (uint32_t *)calloc(sizeof(uint32_t), n);
  if (c->counting_arr == NULL) goto err;

  return c;

err:
  free_counting_sort_object(c);
  perror("malloc error");
  exit(1);
}

void counting_sort_destroy(counting_sort_t c)
{
  free_counting_sort_object(c);
}

static void count_incidence(counting_sort_t c, uint64_t data[], size_t len)
{
  uint32_t i;
  for (i = 0; i < len; i++) {
    c->counting_arr[data[i]]++;
  }
}

static void calc_cumulative_sum(counting_sort_t c)
{
  uint32_t i;
  for (i = 1; i < c->counting_arr_len; i++) {
    c->counting_arr[i] += c->counting_arr[i - 1];
  }
}

static bool copy_array(uint64_t data[], size_t len, uint64_t **p)
{
  *p = (uint64_t *)malloc(sizeof(data[0]) * len);
  if (*p == NULL) return false;

  memcpy(*p, data, sizeof(data[0]) * len);

  return true;
}

void counting_sort(counting_sort_t c, uint64_t data[], size_t len)
{
  count_incidence(c, data, len);

  calc_cumulative_sum(c);

  uint64_t *aux;
  if (!copy_array(data, len, &aux)) goto err;

  int32_t i;
  for (i = len - 1; 0 <= i; i--) {
    uint32_t index = c->counting_arr[aux[i]];
    data[index - 1] = aux[i];
    c->counting_arr[aux[i]]--;
  }

  return;
err:
  counting_sort_destroy(c);
  perror("malloc error");
  exit(1);
}

#if !defined(TEST)
uint64_t data[2000000];
int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  counting_sort_t c = counting_sort_create(10001);

  int32_t i;
  for (i = 0; i < num; i++) {
    uint64_t val;
    scanf("%ld", &val);
    data[i] = val;
  }

  counting_sort(c, data, num);

  for (i = 0; i < num; i++) {
    if (i != 0) printf(" ");
    printf("%lu", data[i]);
  }
  printf("\n");

  counting_sort_destroy(c);

  return 0;
}
#endif



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

int main(){
    int n, cnt=0, max=0; cin >> n;
    for(int i = 0; i < n; i++){
        int h; cin >> h;
        if(h>=max){
            cnt++; max = h;
        }
    }
    cout << cnt << 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)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

// calculates nCr (1 <= r <= n <= 1e7)
const int MAX = 1e7;
long long f[MAX], finv[MAX], inv[MAX];
// initializes nCr
void initnCr() {
	f[0] = f[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		f[i] = f[i-1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
}

ll nCr(int n, int r) {
	if (n < r) return 0;
	if (n < 0 || r < 0) return 0;
	return f[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

int main() {
	initnCr();
	int x, y;
	cin >> x >> y;
	if (2 * x - y < 0 || (2 * x - y) % 3 != 0 || 2 * y - x < 0 || (2 * y - x) % 3 != 0) cout << 0 << endl;
	else cout << nCr((2 * x - y) / 3 + (2 * y - x) / 3, (2 * y - x) / 3) << endl;
}

Measured memory_bytes: 238000
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
double DP[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  DP[0] = 1.0;
  FOR(i, 0, n){
    double p;
    cin >> p;
    FORR(j, n, 1) DP[j] = DP[j] * (double(1.0)-p) + DP[j-1] * p;
    DP[0] *= double(1.0) - p;
  }
  double ans = 0.0;
  FORR(i, n, n/2+1) ans += DP[i];
  dout(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> v[n], c(n);
	rep(i, n) {
		cin >> c[i];
		rep(_, m) {
			int a;
			cin >> a;
			v[i].push_back(a);
		} 
	}
	int ans = INF;
	for (int bit = 0; bit < (1 << n); bit++) {
		int sc = 0;
		vector<int> tmp(m);
		rep(i, n) {
			if (bit >> i & 1) {
				sc += c[i];
				rep(j, m) {
					tmp[j] += v[i][j];
				}
			}
		}
		if (*min_element(all(tmp)) >= x) chmin(ans, sc);
	}
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

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


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var x, y int64
	var s string
	fmt.Scan(&x, &s, &y)
	var ans int64
	if s == "+" {
		ans = x + y
	} else {
		ans = x - y
	}
	fmt.Println(ans)
}

func Min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define N 111111
inline int read(){
	int x=0,f=1;
	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;
}
int n,ans,f[N][33];
int tot,a[N*2],b[N*2],c[N];
void add(int x,int y){
	tot++;a[tot]=y;b[tot]=c[x];c[x]=tot;
}
void dfs(int u,int fa){
	for (int i=c[u];i;i=b[i]){
		int to=a[i];
		if (to==fa){
			continue;
		}
		dfs(to,u);
		for (int i=0;i<=20;++i){
			f[u][i]+=f[to][i];
		}
	}
	int p=0;
	for (int i=20;i>=0;--i){
		if (f[u][i]>1){
			p=i+1;break;
		}
	}
	while (f[u][p]) p++;
	f[u][p]++;
	for (int i=0;i<p;++i){
		f[u][i]=0;
	}
	ans=max(ans,p);
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	int n=read();
	for (int i=1;i<n;++i){
		int u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	cout<<ans<<endl;
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 22144
n=int(input())
s=input()
v=[0 for i in range(n)]

for i in range(n):
    j=0
    if s[i]=="E":
        j=1
    else:
        j=-1
    if i==0:
        v[i]+=j
    else:
        v[i]+=j+v[i-1]

sum=-2
w=0
res=""
for i in range(n):
    if sum<v[i]:
        sum=v[i]
        wmax=w
        emax=i-w
        res=s[i]
    if s[i]=="W":
        w+=1

if res=="W":
    print(wmax+s.count("E")-emax)
else:
    print(wmax+s.count("E")-emax-1)


Measured memory_bytes: 21212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int r,d,x;
    cin>>r>>d>>x;
    rep(i,10){
        x=r*x-d;
        cout<<x<<endl;
    }

    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

set<pii> s;

int main()
{	
	vector<pii> v;
	ll n, i, j;
	ll x, y;
	ll curr, ans = 0;

	cin >> n;
	for(int i = 0; i < n; i++) cin >> x, v.pb(mp(x, 0));
	for(int i = 0; i < n; i++) cin >> y, v[i].second = y;

	set<pii> :: iterator itr, titr;
	set<pii> :: reverse_iterator ritr;

	ans = v[0].second; s.insert(mp(v[0].first, v[0].second));
	for(int i = 1; i < n; i++) {
		itr = s.upper_bound(mp(v[i].first, 0));

		if(itr == s.end()) {
			ritr = s.rbegin();
			curr = ritr->second + v[i].second;
			s.insert(mp(v[i].first, curr));
			ans = max(ans, curr);
			continue;
		}
		if(itr == s.begin()) curr = 0;
		else itr--, curr = itr->second;
		
		curr += v[i].second;
		s.insert(mp(v[i].first, curr));
		itr = s.find(mp(v[i].first, curr));

		for(itr++; itr != s.end();) {
			if(itr->second < curr){
				titr = itr;
				++itr; s.erase(titr);
			} else break;
		} ans = max(ans, curr);
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16876
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d || ( abs(a-b)<=d && abs(b-c)<=d )){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto x = readln.chomp.to!int;
  writeln(x < 1200 ? "ABC" : "ARC");
}


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

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define FOR(n) for(int i = 0;i < n;i++)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define ipow(x,y) LL(pow(x,y))

//Debug
#define TEST cout << "OK\n"

const double PI = M_PI;
const long long INF = int(999999999);
const long long MOD = int(1000000007);

//Settings
const bool DO_BENCHMARK = false;
const int DOUBLE_ACCURACY = 15;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

void solve(){
    LL N;
    cin >> N;
    if(N%2==1){
        cout << 0 << endl;
        ED;
    }
    LL ans = N/10;
    N/=10;
    for(LL i = 1;i < 25;i++){
        ans += N/ipow(5,i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

re = 0
ri = 0
sum = 0
for l in 0..n-1
  while ri < n && ( sum ^ a[ri] == sum + a[ri])
    sum += a[ri]
    ri += 1
  end
  re += ri - l
  if ri == l
    ri += 1
  else
    sum -= a[l]
  end
end

puts re


Measured memory_bytes: 15364
using System;

class Program
{
    static void Main()
    {
        var str = Console.ReadLine();
        var a = int.Parse(str.Split()[0]);
        var b = int.Parse(str.Split()[1]);
        var c = int.Parse(str.Split()[2]);
        
        if(a < b && b < c){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}



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

int main()
{
    ll n;
    cin >> n;
    ll a[n];
    vector<ll> v;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        v.push_back(a[i]);
    }
    ll dp[n][n];
    for (ll i = 0; i < n; i++)
        for (ll j = 0; j < n; j++)
            dp[i][j] = 0;
    ll prefix[n + 1];
    prefix[0] = 0;
    for (ll i = 1; i <= n; i++)
        prefix[i] = prefix[i - 1] + a[i - 1];
    for (ll l = 1; l <= n; l++)
    {
        for (ll i = 0, j = i + l; j < n; i++, j = i + l)
        {
            dp[i][j] = LLONG_MAX;
            for (ll k = i; k < j; k++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + prefix[j + 1] - prefix[i]);
        }
    }
    cout << dp[0][n - 1] << '\n';
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 3e5+5;
const int INF = 0x3f3f3f3f;
typedef long long ll;

int A[N];
int Belong[25];

int main() {
    int n;
    while(~scanf("%d", &n)) {
        memset(Belong, 0, sizeof(Belong));
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &A[i]);
        }
        int st = 0;
        ll ans = 0;

        for(int i = 1; i <= n; ++i) {
            int tmpst = 0;
            int tmp = A[i];
            int cnt = 0;
            while(tmp) {
                if(tmp & 1) tmpst = max(tmpst, Belong[cnt]), Belong[cnt] = i;
                tmp >>= 1;
                cnt ++;
            }
            if(tmpst >= st) {
                st = tmpst + 1;
            }
            ans += i - st + 1;
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
const int  maxn=1e5+10;
int a,b,c;
int cnt[15];
int main(){
    memset(cnt,0,sizeof(cnt));
    scanf("%d%d%d",&a,&b,&c);
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
    if(cnt[5]==2&&cnt[7]==1)    printf("YES\n");
    else printf("NO");
    return 0;
}

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

public class Main {

    /**
     *
     * k = 1
     *
     * 2^17+1  2^17     0
     * 1      2^17+1   1
     *
     * dp[2][2] = max(
     */

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long n = sc.nextLong();
        int m = sc.nextInt();
        long res = 0;
        for (int i = 0; i < m; i++) {
            res += sc.nextLong();
        }
        if (res > n) System.out.println(-1);
        else System.out.println(n-res);

    }

    private static void solve(int[] ans, int n, int[] arr) {

    }

    /**\
     *
     * 4
     * 2 3 4 5
     *
     *
     * 1 2 3 4 5 6 7 8
     * 2 6 3 7 4 8 5 9
     */

    // 1 1 1 0 0 0
    // 0 0 1 1 1 1


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

/**
 * 7 3
 * 3 1 5
 * 9 6 5
 *
 * i = 1: 1
 * i = 2: 2
 * i = 3: 3
 *
 *
 * 1 2 3 3 3 3 3
 */


/**
 *
 *  1+1
 **/

Measured memory_bytes: 33916
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,k;
	cin>>i>>j>>k;
	if(i-j==0)
	{
		if(i-k)
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	else if(i-k==0)
	{
		if(i-j)
		cout<<"Yes\n";
		else
		cout<<"No\n";
	}
	else
	{
		if(j-k==0)
		{
			if(i-j)
			cout<<"Yes\n";
			else
			cout<<"No\n";
		}
		else
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())

t, h = 0, 0

for i in range(n):
    s1, s2 = input().split()
    if s1 > s2:
        t += 3
    elif s1 < s2:
        h += 3
    else:
        t += 1
        h += 1

print(t, h)


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    string s;
    cin >> s;
    ll n = ll(s.length());
    vector<vector<ll>> dp(n+1, vector<ll>(13, 0));
    dp[0][0] = 1;
    REP(i, n){
        ll c;
        if(s[i] == '?') c = -1;
        else c = s[i] - '0';
        REP(j, 10){
            if(c != -1 && c != j) continue;
            REP(k, 13) dp[i+1][(k*10+j)%13] += dp[i][k];
        }
        REP(k, 13) dp[i+1][k] %= MOD;
    }
    cout << dp[n][5];
    return 0;
}

Measured memory_bytes: 16652
N = int(input())
A = list(map(int,input().split()))

if N==1:
    if A[0]==A[1]==A[2]:
        print(1)
    else:
        print(0)
    exit()

INF = float('inf')
ans = 0
dp = [[-INF]*(N+1) for _ in range(N+1)]
dp[A[0]][A[1]] = dp[A[1]][A[0]] = 0
maxdp = [max(row) for row in dp]
use = {A[0], A[1]}

for i in range(N-1):
    a,b,c = A[i*3+2:i*3+5]
    if a==b==c:
        ans += 1
        continue
    update = []
    if a==b:
        for j in use:
            update.append((j,c, max(dp[a][j], dp[j][a]) + 1))
    elif b==c:
        for j in use:
            update.append((j,a, max(dp[b][j], dp[j][b]) + 1))
    elif c==a:
        for j in use:
            update.append((j,b, max(dp[c][j], dp[j][c]) + 1))
    update.append((a,b, dp[c][c] + 1))
    update.append((b,c, dp[a][a] + 1))
    update.append((c,a, dp[b][b] + 1))
    mx = max(maxdp)
    update.append((a,b, mx))
    update.append((b,c, mx))
    update.append((c,a, mx))
    for j in use:
        update.append((j,a, maxdp[j]))
        update.append((j,b, maxdp[j]))
        update.append((j,c, maxdp[j]))
    for l,m,n in update:
        dp[l][m] = dp[m][l] = max(dp[l][m], dp[m][l], n)
        maxdp[l] = max(maxdp[l], n)
        maxdp[m] = max(maxdp[m], n)
    use.add(a)
    use.add(b)
    use.add(c)

tmp = max(maxdp)
tmp = max(tmp, dp[A[-1]][A[-1]] + 1)
ans += tmp
print(ans)

Measured memory_bytes: 182796
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = read(int)
    hs = read(int, n)
    dp = arr(n)
    dp[1] = abs(hs[1] - hs[0])
    for i in range(2, n):
        dp[i] = min(
            dp[i - 1] + abs(hs[i] - hs[i - 1]), dp[i - 2] + abs(hs[i] - hs[i - 2])
        )
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 12380
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([][]int, N)
	b := make([][]int, N)
	for i := 0; i < N; i++ {
		a[i] = make([]int, N)
		b[i] = make([]int, N)
		for j := 0; j < N; j++ {
			a[i][j] = getInt()
			b[i][j] = a[i][j]
		}
	}

	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if b[i][j] > b[i][k]+b[k][j] {
					out(-1)
					return
				}
			}
		}
	}

	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if a[i][j] == a[i][k]+a[k][j] {
					if i != k && j != k {
						b[i][j] = 0
					}
				}
			}
		}
	}
	// out("----")
	// for i := 0; i < N; i++ {
	// 	out(b[i])
	// }

	ans := 0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			ans += b[i][j]
		}
	}
	out(ans / 2)
}


Measured memory_bytes: 3712
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define ass_on_fire          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               a.begin(),a.end()
#define rall(a)              a.rbegin(),a.rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=1;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ass_on_fire
    int n,k,s=0;cin>>n>>k;
    int a[n];read(a);
    sort(a,a+n);
    rep(i,0,k) s+=a[i];
    cout<<s;
}


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

int main(){
  string s,t;
  int a,b;
  string u;
  cin >> s >> t >> a >> b >> u;
  if(u==s) a--;
  if(u==t) b--;
  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 3560
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val sList = readLine()!!.split(" ").map { it.toInt() }
    readLine()!!.toInt()
    val tList = readLine()!!.split(" ").map { it.toInt() }

    var total = 0

    for (number in tList) {
        if (binarySearch(number, n, sList)) total++
    }
    println(total)
}

fun binarySearch(target: Int, n: Int, list: List<Int>): Boolean {
    var left = 0
    var right = n
    while (left < right) {
        val mid = (left + right) / 2
        when {
            list[mid] == target -> return true
            target < list[mid] -> right = mid
            else -> left = mid + 1
        }
    }
    return false
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int dp[100000];

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

    int N;
    cin >> N;

    vs32 h(N);
    rep (i, N) cin >> h[i];

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

    for (int i = 2; i < N; ++i)
    {
        dp[i] = MIN(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[N - 1] << "\n";
    return 0;
}



Measured memory_bytes: 1024
import std.stdio;
import std.conv;
import std.array;

void main()
{
    auto reader = readln.split;
    int A = reader[0].to!int;
    int B = reader[1].to!int;

    if (A == B){
        writeln(A * 2);
    } else {
        int max = A;
        if (B > A) max = B;

        writeln(max + (max - 1));
    }
}



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

int main(){
	int n,a;
	cin>>n>>a;
	int l=a;
	int r=n+l-1;
	int ans;
	if(r<=0)ans=r;
	else if(l>=0)ans=l;
	else ans=0;

	int answ = (r+l)*(r-l+1)/2-ans;
	cout<<answ;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define Rep(i,n) for(int i=0; i<(n); i+=2)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
const int INF = 1e9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    int ans = 0;
    int active = 0;
    rep(i,n){
        if(active>=h[i]){
            active = h[i];
        }
        else{
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int c=0;
  for(int i=0;i<n-2;i++){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C'){
      c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
sub f{$M[$_]=1;$M[$_]||&f for@$_;unshift@s,$_}<>;/ /,push@
$`,$'+0for<>;map$M[$_]||f,1..1e5;map{$\+=$-=($p=$p[$_])-$\;$p[$_]+=$-=$p+1-$p[$_]for@$_}@s;print

Measured memory_bytes: 114432
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;


#define ld long double
#define EPS 0.0000000001
#define INF 10000000000LL
#define rep(i,n) for(i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int i,j;

int main(void) {

  while(1){
    int t,p,r;
    cin>>t>>p>>r;
    if(t==0 && p==0 && r==0)break;
    int i;
    pair<pll,ll> team[50]; //solved_num, time, team_num                         
    int v[50][10]={};//team_num, problem_num, wrong_num                         
    int time,tnum,pnum,j;
    string str;
    rep(i,t)
      team[i].second=-i-1;//reverse                                             
    rep(i,r){
      cin>>tnum>>pnum>>time>>str;
      tnum--;
      pnum--;
     if(str=="WRONG"){//WA                                                     
        v[tnum][pnum]++;
      }else{//AC                                                                
        team[tnum].first.first++;
        team[tnum].first.second-=time+v[tnum][pnum]*1200;//reverse              
      }
    }
    rep(i,t)
      if(team[i].first.second==0)team[i].first.second=-1000000000000LL;

    sort(team,team+t);
    for(i=t-1;i>=0;i--){
      cout<<-team[i].second<<" ";
      cout<<team[i].first.first<<" ";
      if(team[i].first.second<-100000000000)
        cout<<"0"<<endl;
      else
        cout<<-team[i].first.second<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3184
n, a = int(input()), list(map(int, input().split()))
a.sort(reverse = True)
alice = 0
bob = 0
for i in range(n):
  if i % 2 == 0:
    alice += a[i]
  else:
    bob  += a[i]
# print(alice)
# print(bob)
print(alice - bob)

Measured memory_bytes: 9116
#include <stdio.h>
#include <math.h>
struct pnt{double x,y;pnt() {};pnt(double a, double b) {x=a,y=b;}};double h;
struct line{double A,B,C;line() {};line(pnt a, pnt b) {A=a.y-b.y,B=b.x-a.x,C=-A*a.x-B*a.y;}};
pnt kramer(pnt x1, pnt x2, double t) {
    line a=line(x1,x2);
	double g=(x2.x*x2.x-x1.x*x1.x+x2.y*x2.y-x1.y*x1.y),delta;
    delta=t*2.0*(a.A*a.A+a.B*a.B);
    return pnt((2.0*a.A*(h-t*a.C)+t*a.B*g)/delta,(2.0*a.B*(h-t*a.C)-t*a.A*g)/delta);
}
int dist(pnt a, pnt b, double val) {
    return (((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))<=val+1e-6);
}
int main() {
    int N,i,j,k,cnt,f;double a,b;pnt RB[105];
	while (scanf("%d",&N)!=EOF && N) {
        for (i=0;i<N;i++) scanf("%lf,%lf",&a,&b),RB[i]=pnt(a,b);cnt=1;
        for (i=0;i<N;i++) for (j=i+1;j<N;j++) if (dist(RB[i],RB[j],4.0)) {
            line q=line(RB[i],RB[j]);h=q.A*q.A+q.B*q.B,h=cos(0.5*acos((2.0-h)/2.0))*sqrt(h);
            RB[104]=kramer(RB[i],RB[j],1.0);
            for (k=f=0;k<N;k++)
				f+=dist(RB[104],RB[k],1.0);
			if (cnt<f) cnt=f;
			RB[104]=kramer(RB[i],RB[j],-1.0);
            for (k=f=0;k<N;k++)
				f+=dist(RB[104],RB[k],1.0);
			if (cnt<f) cnt=f;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 1144