akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    long X, Y, A, B, C;
    std::cin >> X >> Y >> A >> B >> C;
    std::vector<int> p(A), q(B), r(C), a;
    for (int i = 0; i < A; i++) std::cin >> p[i];
    for (int i = 0; i < B; i++) std::cin >> q[i];
    for (int i = 0; i < C; i++) std::cin >> r[i];
    std::sort(p.begin(), p.end(), std::greater<>());
    std::sort(q.begin(), q.end(), std::greater<>());
    std::sort(r.begin(), r.end(), std::greater<>());
    for (int i = 0; i < X; i++) a.push_back(p[i]);
    for (int i = 0; i < Y; i++) a.push_back(q[i]);
    for (int i = 0; i < C; i++) a.push_back(r[i]);
    std::sort(a.begin(), a.end(), std::greater<>());
    long ans = 0;
    for (int i = 0; i < X + Y; i++) ans += a[i];
    std::cout << ans << std::endl;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;

array<int, 3> edge[maxn];
int N, lab[maxn]; ll res[maxn];
int info[maxn], par[maxn], sz[maxn];

int finds(int u)
{
  if (lab[u] == u) return u;
  return lab[u] = finds(lab[u]);
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N;
  for (int i = 1; i < N; ++i){
    cin >> edge[i][1] >> edge[i][2] >> edge[i][0];
  }
  sort(edge + 1, edge + N);
  for (int i = 1; i <= N; ++i){
    lab[i] = info[i] = i; sz[i] = 1;
  }
  int cnt = N + 1;
  for (int i = N - 1; i >= 1; --i){
    int u = edge[i][1], v = edge[i][2], w = edge[i][0];
    u = finds(u); v = finds(v);
    par[info[u]] = cnt;
    par[info[v]] = cnt;
    res[info[u]] = 1ll * sz[v] * w;
    res[info[v]] = 1ll * sz[u] * w;
    info[v] = cnt;
    sz[v] += sz[u];
    lab[u] = v;
    ++cnt;
  }
  for (int i = cnt; i >= 1; --i){
    res[i] += res[par[i]];
  }
  for (int i = 1; i <= N; ++i){
    cout << res[i] << '\n';
  }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, q;
    cin >> n >> q;
    string t;
    cin >> t;

    int s[SIZE] = {};
    for(int i = 1; i < t.size(); ++i) {
        if(t[i - 1] == 'A' && t[i] == 'C') ++s[i];
        s[i] += s[i - 1];

    }
    while(q--) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}



Measured memory_bytes: 1872
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
bool ist(int a,int b,int c)
{
  if(a+b<=c)return false;
  if(c+b<=a)return false;
  if(a+c<=b)return false;
 
  if(abs(a-b)>=c)return false;
  if(abs(b-c)>=a)return false;
  if(abs(c-a)>=b)return false;
  
  if(a==b||b==c||c==a)return false;


  return true;

} 

int main(int argc, char const *argv[])
{ 
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);


 int n;
 cin>>n;
 int l[n];

 for(int i=0;i<n;i++)
 cin>>l[i];
 int ans=0;
 for(int i=0;i<n;i++)
 {
  for(int j=i+1;j<n;j++)
  {
    for(int k=j+1;k<n;k++)
    if(ist(l[i],l[j],l[k]))
    ans++;
  }
 }
cout<<ans<<endl;
}
 
 

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


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size; // size[i]:iがrootの時のメンバ数

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

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

    int get_size(int x) {
        return size[root(par[x])];
    }

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

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

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  vector< vector<int> > blk(N);
  REP(i,M) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a,b);
    blk[a].push_back(b);
    blk[b].push_back(a);
  }
  REP(i,K) {
    int c,d;
    cin >> c >> d;
    c--;d--;
    blk[c].push_back(d);
    blk[d].push_back(c);
  }

  REP(i,N) {
    int bcnt = 0;
    for ( auto bk : blk[i] )
      if( uf.same(i,bk) ) bcnt++;
//    cout << i << " : " << uf.get_size(i) << " - " << bcnt << endl;
    int cnt = uf.get_size(i) - 1 - bcnt;
    cout << cnt << " ";
  }
    
/*  
  REP(i,N) {
    int cnt = 0;
    REP(j,N) {
      if (i==j) continue;
      bool flg =false;
      for ( auto bk : blk[i] )
        if (bk == j) flg = true;
      if ( flg ) continue;
      if (uf.same(i,j)) cnt++;
//      cout << i << " - " << j << " : " << cnt << endl;
    }
    cout << cnt << " ";
  }
  */
  cout << endl;
}

  


Measured memory_bytes: 8440
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}
typedef vector<vector<pii>> Graph;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
	bool operator<(const Edge& e)const{return weight<e.weight;}
	bool operator>(const Edge& e)const{return weight>e.weight;}
};

struct UnionFind{
	vi data;
	UnionFind(int size):data(size,-1){}
	int Find(int n){
		return data[n]<0?n:(data[n]=Find(data[n]));
	}
	void Unite(int a,int b){
		int ra=Find(a),rb=Find(b);
		if(ra!=rb){
			if(-data[ra]<-data[rb])
				swap(ra,rb);
			data[ra]+=data[rb];
			data[rb]=ra;
		}
	}
	int Size(int n){
		return -data[Find(n)];
	}
};

int main()
{
	for(int r;~scanf("%d",&r) && r;){
		int n[2],p[2],l[2];
		vector<Edge> es[2];
		rep(k,2){
			int w,h,x,y; scanf("%d%d%d%d",&w,&h,&x,&y);
			n[k]=w*h; p[k]=(y-1)*w+(x-1);
			vi level(n[k]);
			rep(i,n[k]) scanf("%d",&level[i]);
			l[k]=level[p[k]];
			
			rep(i,h) rep(j,w) rep(_,4){
				int ni=i+"\xff\x1\0\0"[_],nj=j+"\0\0\xff\x1"[_];
				if(ni<0 || h<=ni || nj<0 || w<=nj) continue;
				es[k].emplace_back(i*w+j,ni*w+nj,max(level[i*w+j],level[ni*w+nj]));
			}
			sort(all(es[k]));
		}
		
		vector<pii> mn[2]; // (#rooms,level)
		rep(k,2){
			mn[k].emplace_back(0,0);
			UnionFind uf(n[k]);
			for(Edge e:es[k]){
				uf.Unite(e.src,e.dst);
				if(e.weight<l[k])
					continue;
				else if(e.weight>mn[k].back().second)
					mn[k].emplace_back(uf.Size(p[k]),e.weight);
				else
					mn[k].back().first=uf.Size(p[k]);
			}
		}
		
		int res=INFTY;
		rep(i,mn[0].size()){
			int j=lower_bound(all(mn[1]),mp(r-mn[0][i].first,0))-mn[1].begin();
			if(j==mn[1].size()) continue;
			res=min(res,mn[0][i].second+mn[1][j].second);
		}
		
		printf("%d\n",res);
	}
	
	return 0;
}

Measured memory_bytes: 32228
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;
bool P(string t) {
	int n = (int) t.size();
	for (int i = 0; i <= n / 2; ++i) {
		if (t[i] != t[n - i - 1]) {
			return false;
		}
	}
	return true;
}
int main() {
	INIT
	string s;
	cin >> s;
	int n = s.size();
	
	string a = s.substr(0, (n - 1) / 2);
	string b = s.substr(n + 3/ 2 - 1);
	if (P(s) && P(a) && P(b)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	
	return 0;
}
/*
rep (i, 0, n) {
		if (i) cout << ' ';
		cout << A[i];
	}
*/

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

int main(){
    int n,m,x; cin >> n >> m >> x;
    int ans = 1e9;
    vector<int> c(n);
    vector<vector<int>> a(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m) {
            int A; cin >> A;
            a[i].push_back(A);
        }
    }
    for(int bit = 0;bit < (1<<n);++bit){
        vector<int> suma(m,0);
        int sum = 0;
        for(int i = 0;i < n;++i){
            if(1&(bit>>i)) {
                sum += c[i];
                for(int j = 0;j < m;++j){
                    suma[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for(int i = 0;i < m;++i){
            if(suma[i] < x) flag = false;
        }
        if(flag) ans = min(ans,sum);
    }
    if(ans == 1e9) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main(){
    int n,l;
    cin>>n>>l;
    int ans=0,mn=1e9,x;
    rep(i,n){
        ans+=l+i;
        if(mn>abs(l+i)){
            mn=abs(l+i);
            x=l+i;
        }
    }
    cout<<ans-x<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	string t;
	cin>>t;
	bool n=false,w=false,s=false,e=false;
	for(auto i:t){
		if(i=='N')
			n=true;
		if(i=='W')
			w=true;
		if(i=='S')
			s=true;
		if(i=='E')
			e=true;
	}
	if(n^s || e^w)
		cout<<"No";
	else
		cout<<"Yes";
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll x,n;cin >>x>>n;
    map<ll,int>mp;
    for (int i = 0; i < n; ++i) {
        ll p;cin >>p;
        mp[p]++;
    }
    ll d=0;
    ll ans;
    while (1){
        if(mp[x-d]==0){
            ans=x-d;
            break;
        }
        if(mp[x+d]==0){
            ans=x+d;
            break;
        }
        d++;
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

bool dfs(int N, int M, vector< vector<bool> >& adj, vector<int>& a, vector<int>& b, int i, vector<bool>& vis) {
	vis[i] = true;
	for (int j = 0; j < M; j++) {
		if (!adj[i][j] || a[i] == j) continue;
		if (b[j] == -1) {
			b[j] = i;
			a[i] = j;
			return true;
		}
		int _i = b[j];
		if (!vis[_i] && dfs(N, M, adj, a, b, _i, vis)) {
			b[j] = i;
			a[i] = j;
			return true;
		}
	}
	return false;
}

int match(int N, int M, vector< vector<bool> >& adj) {
	vector<int> a(N, -1), b(M, -1);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] != -1) continue;
		vector<bool> vis(N);
		if (dfs(N, M, adj, a, b, i, vis))
			cnt++;
	}
	return cnt;
}

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0) break;
		vector<int> x(N), y(N), v(N);
		for (int i = 0; i < N; i++)
			cin >> x[i] >> y[i] >> v[i];
		vector<int> X(M), Y(M);
		for (int j = 0; j < M; j++)
			cin >> X[j] >> Y[j];
		double lb = 0, ub = 20000;
		for (int t = 0; t < 50; t++) {
			double mid = (lb + ub) / 2;
			vector< vector<bool> > adj(N, vector<bool>(M));
			for (int i = 0; i < N; i++)
				for (int j = 0; j < M; j++) {
					double dx = X[j] - x[i], dy = Y[j] - y[i];
					adj[i][j] = (sqrt(dx * dx + dy * dy) <= mid * v[i]);
				}
			if (match(N, M, adj) == M) ub = mid;
			else lb = mid;
		}
		printf("%.10f\n", lb);
	}
}

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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

ll calc(ll d, ll s, ll c, ll f) {
    if (d < s) {
        return d + (s - d) + c;
    }
    if (d % f == 0) {
        return d + c;
    }
    ll tmp = d % f;
    return d + c - tmp + f;
}
int main() {
    ll N;
    cin >> N;
    vector<ll> C(N);
    vector<ll> S(N);
    vector<ll> F(N);
    rep(i, N - 1) { cin >> C[i] >> S[i] >> F[i]; }
    rep(i, N - 1) {
        ll d = S[i] + C[i];
        for (ll j = i + 1; j < N - 1; j++) {
            d = calc(d, S[j], C[j], F[j]);
        }
        cout << d << endl;
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
t = s[-1:-n-1:-1]
def sub(r,b):
    # tを分割してr,bを作る通り数
    dp = [[0]*(len(b)+1) for _ in range(len(r)+1)]
    dp[0][0] = 1
    for i in range(len(r)+1):
        for j in range(len(b)+1):
#             if i+j>=n:
#                 continue
            if i<len(r) and t[i+j]==r[i]:
                dp[i+1][j] += dp[i][j]
            if j<len(b) and t[i+j]==b[j]:
                dp[i][j+1] += dp[i][j]
    return dp[len(r)][len(b)]


ans = 0
for bit in range(1<<n):
    r = []
    b = []
    for i in range(n):
        if bit>>i&1:
            r.append(s[i])
        else:
            b.append(s[i])
    ans += sub(r,b)
print(ans)

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

using namespace std;

#define PB push_back
#define MEM(n, val) memset(n, val, sizeof(n))
#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define ROF(i, j, k) for(int i = j; i >= k; i--)
#define LL long long
#define F first
#define S second
#define PII pair<int, int>
#define INF 1999999999
#define MP make_pair
#define LN (node * 2)
#define RN ((node * 2) + 1)
#define MX 1000010
#define SF(a) scanf("%d", &a)

int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};

int n;
int ara[3][110];
int dp[3][110];

int func(int x, int y)  {
    if(x == 1 && y == n - 1)    {
        return ara[x][y];
    }
    if(x > 1 || y > n)    {
        return -100000;
    }
    if(dp[x][y] != -1)    {
        return dp[x][y];
    }
    int ans = 0;
    ///down
    ans = max(ans, ara[x][y] + func(x + 1, y));
    ///right
    ans = max(ans, ara[x][y] + func(x, y + 1));
    return dp[x][y] = ans;
}

int main()  {
    std::ios_base::sync_with_stdio(false);
    //freopen("in.txt", "r", stdin);

    cin >> n;
    FOR(i, 0, 1)   {
        FOR(j, 0, n - 1)   {
            cin >> ara[i][j];
        }
    }
    MEM(dp, -1);
    cout << func(0, 0);
    return 0;
}
/**
*/


Measured memory_bytes: 256
#!/usr/bin/env ruby
n = gets.to_i

hash = { 'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 }

n.times do
  s = gets.chomp.to_s
  hash[s] += 1
end

puts "AC x #{hash['AC']}"
puts "WA x #{hash['WA']}"
puts "TLE x #{hash['TLE']}"
puts "RE x #{hash['RE']}"


Measured memory_bytes: 14312
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
int d1[8] = { 1,1,1,0,0,-1,-1,-1 };
int d2[8] = { 1,0,-1,1,-1,1,0,-1 };
int h, w;
int fh(int x) {
	return (x% h+h)%h;
}
int fw(int x) {
	return (x%w + w) % w;
}
int main() {
	while (cin >> h >> w, h) {
		char t[20][20];
		string s;
		rep(i, h) {
			cin >> s;
			rep(j, w) {
				t[i][j] = s[j];
			}
		}
		vector<string>v;
		rep(i, h) {
			rep(j, w) {
				rep(k, 8) {
				    string u;
				    u = t[i][j];
					int now = 1;
					while (!(fh(i + now*d1[k]) == i && fw(j + now*d2[k]) == j)) {
						u += t[fh(i + now * d1[k])][fw(j + now * d2[k])];
						v.push_back(u);
						now++;
					}
				}
			}
		}
		sort(v.begin(), v.end());
		int len = v.size();
		ui ma = 0; string out = "0";
		rep(i, len-1) {
			if (v[i] == v[i + 1] && ma < v[i].length()) {
				ma = v[i].length(); out = v[i];
			}
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 31144
#include <stdio.h>
int main(void){
	int i,n,x;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			printf(" %d",i);
		}else if(x%10==3){
			printf(" %d",i);
		}else{
			while(1){
				x/=10;
				if(x==0) break;
				if(x%10==3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	printf("\n");
	return 0;
}

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

int main() {
  string a;
  cin >> a;
  
  if(a.at(0) == 'A'){
    cout << 'T' << endl;
  }
  
  else if(a.at(0) == 'T'){
    cout << 'A' << endl;
  }
  
  else if(a.at(0) == 'C'){
    cout << 'G' << endl;
  }
  
  else{
    cout << 'C' << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <functional>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
int dp[100200];

int main(){
    dp[1]=0;
    int N,K;
    cin>>N>>K;
    vector<int>h(N+1);
    rep(i,N) cin>>h[i+1];
    for(int i=2;i<=N;i++){
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for(int k=1;k<=K;k++){
            if(i-k>=1){
                dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
            }
        }
    } 
    cout<<dp[N];
}

Measured memory_bytes: 1024
N, K = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ans = Float::INFINITY
(0..N-K).each{|x|
    l = xs[x]
    r = xs[x+K-1]
    l2r = l.abs + (r-l).abs
    r2l = r.abs + (l-r).abs
    ans = [ans,l2r,r2l].min
}

puts ans


Measured memory_bytes: 11012
#include<stdio.h>

int main(){
  int a,i,max=0,kotae=0;
  scanf("%d\n",&a);
  int b[a];
  for(i=0;i<a;i++){
    scanf("%d ",&b[i]);
    if(max<=b[i]){
      max=b[i];
      kotae++;
    }
  }
  printf("%d",kotae);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int inf = 999;

int calc(string s, char c) {
	if (s.find(c) == string::npos) {
		return inf;
	}

	int count = 0;
	while (s.size() > 0) {
		if (s.find_first_not_of(c) == string::npos) {
			return count;
		}

		string t;
		for (int i = 0; i < s.size() - 1; i++) {
			if (s[i] == c || s[i + 1] == c) {
				t += c;
			} else {
				t += s[i];
			}
		}
		count++;
		// cout << t << endl;
		s = t;
	}

	return 0;
}

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

	int ans = inf;
	for (char c = 'a'; c <= 'z'; c++) {
		ans = min(ans, calc(s, c));
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

#define ll long long 
#define read(x) scanf("%d",&x)

struct node
{
	int id,val;
}a[2005];
ll dp[2005][2005];
int n;

bool cmp(node n,node m){return n.val<m.val;}

int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i].val),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) dp[i][i]=1ll*a[1].val*abs(a[1].id-i);
	for(int i=2;i<=n;i++)
	{
		for(int l=1;l+i-1<=n;l++)
		{
			int r=l+i-1;
			dp[l][r]=0;
			dp[l][r]=max(dp[l][r],max(dp[l+1][r]+1ll*a[i].val*abs(a[i].id-l),dp[l][r-1]+1ll*a[i].val*abs(a[i].id-r)));
		}
	}
	printf("%lld\n",dp[1][n]);
}

Measured memory_bytes: 26452
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def fact_table(N, mod):
    inv = np.empty(N, np.int64)
    inv[0] = 0
    inv[1] = 1

    for n in range(2,N):
        q, r = divmod(mod, n)
        inv[n] = inv[r] * (-q) % mod

    fact = np.empty(N, np.int64)
    fact[0] = 1
    for n in range(1,N):
        fact[n] = n * fact[n-1] % mod
    fact_inv = np.empty(N, np.int64)
    fact_inv[0] = 1
    for n in range(1,N):
        fact_inv[n] = fact_inv[n-1] * inv[n] % mod
    return fact, fact_inv, inv

def main():
    n, m = map(int, readline().split())
    mod = 10**9 + 7
    fact, fact_inv, inv = fact_table(n+1, mod)
    comb = fact[n] * fact_inv % mod * fact_inv[::-1] % mod
    comb[1::2] *= (-1)
    comb = comb[::-1]

    p = 1
    ans = 0
    for k in range(n+1):
        ans += comb[k] * p % mod
        if k != n:
            p = p * (m-n+1+k)%mod
    ans %= mod
    print( p * ans % mod )
    return

main()



Measured memory_bytes: 46660
#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 ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test int t; cin>>t; while(t--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define f0(i,n) for( ll i = 0; i < ( n ); i ++)
#define f1(i,n) for(i = 1; i <= ( n ); i ++)
#define f(i,m,n) for(auto i = ( m ); i <= ( n ); i ++)
#define nl cout<<"\n"
#define  mod 1000000007
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(x) ((ll)x.size())
#define mem(a, b) memset(a, b, sizeof(a));
#define make_graph(k) int x,y; f0(i,k){cin>>x>>y; adj[x].pb(y); /*adj[y].pb(x);*/}
#define dekh cout<<"dekh"

#define o_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setpll tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update>
typedef vector<ll> vl;




/*ll Pow(ll a, ll b, ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll x = a*a;
        x%=m;
        return Pow(x,b/2,m);
    }
    return (a*Pow(a,b-1,m))%m;
}
*/
/*vector<ll>adj[200005];
 ll vis[200005]={0};
 ll depth[200005]={0};*/

//ll p;ll arr[200005];
/*
void dfs(ll x)
{

    vis[x]=1;

    for(auto child : adj[x])
    {   if(!vis[child])
         {
             dfs(child);
         }
         depth[x]= max(depth[x],depth[child]+1);

    }

}

*/



int main()
{
    fast
    ll n,i,j,m;
    cin>>n>>m;
    char arr[n][m];
    ll dp[n][m]={{0}};
    f0(i,n){
        f0(j,m){
                 cin>>arr[i][j];
                 if(arr[i][j]=='#'){dp[i][j]=0;}
            }
        }

    dp[0][0]=1;
          f1(i,m-1){
        if(arr[0][i]=='#')dp[0][i]=0;
       else{ dp[0][i]=dp[0][i-1];}//cout<<dp[0][i];

        }

        f1(i,n-1){
        if(arr[i][0]=='#')dp[i][0]=0;
     else{   dp[i][0]=dp[i-1][0];}//cout<<dp[i][0];

        }
        for(i=1;i<n;i++)
        {
            for(j=1;j<m;j++)
            {
              if(arr[i][j]=='#')continue;
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
              
            }
        }
  //f0(i,n)f0(j,m)cout<<dp[i][j]<<" ";
     cout<<dp[n-1][m-1];

}





Measured memory_bytes: 12368
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef double long db;
ll a[200005],b[200005];
int main(){
    ll n,d,num=0;cin>>n>>d;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }  
    for(int i=1;i<=n;i++){
        if(a[i]*a[i]+b[i]*b[i]<=d*d){
            num++;
        }
    }
    cout<<num<<endl;
}

Measured memory_bytes: 6756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var stringList = new List<string>();

			for (int i = 0; i < N; i++) {
				var inputstr = retreiveStringArray()[0];
				stringList.Add(inputstr);
			}

			var a_zList = Enumerable.Range('a', 26).Select(x => (char)x).ToList();

			var minCountDic = new Dictionary<char, int>();

			//すべてのアルファベットの要素を作っておく
			foreach (var alpabet in a_zList) {
				minCountDic.Add(alpabet, 100);
			}


			foreach (var str in stringList) {

				var currentCountDic = new Dictionary<char, int>();
				//この文字列は、どの文字を何回使っているか?
				foreach (var ch in str) {
					if (!currentCountDic.ContainsKey(ch)) {
						currentCountDic.Add(ch, 1);
					}
					else {
						currentCountDic[ch]++;
					}
				}

				foreach (var alpabet in a_zList) {
					//各文字の使用回数の最小は?
					var current = 0;
					if (currentCountDic.ContainsKey(alpabet)) {
						current = currentCountDic[alpabet];
					}
					var min = minCountDic[alpabet];
					minCountDic[alpabet] = Math.Min(current, min);
				}
			}

			var ans = string.Empty;

			foreach (var alpabet in a_zList) {
				var addString = Enumerable.Repeat(alpabet, minCountDic[alpabet]);
				ans = ans + string.Join("", addString);
			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  
  if(S.at(0)!='a'){
cout<<'a'<<endl;
  }
  else if(S.at(S.size()-1)=='a'){
    cout<<'b'<<endl;
  }


  else {
  
  for(int i=1;i<S.size();i++){
  if(S.at(i)-S.at(i-1)>1){
    char ans2=S.at(i-1)+1;
    cout<<ans2<<endl;
    break;
  }
    if(i==S.size()-1&&S.at(S.size()-1)!='z'){
      char ans=S.at(i)+1;
        cout<<ans<<endl;
    }
    if(i==S.size()-1&&S.at(S.size()-1)=='z'){
      cout<<"None"<<endl;
  }
    
  }
  }


}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;

int main() {
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double ans;
  double omegaH = 2.0 * PI / (12*60);
  double omegaM = 2.0 * PI / 60;

  double theta = omegaH * (h*60 + m) - omegaM * m;

  ans = sqrt( a*a + b*b - 2.0 * a*b* cos(theta) );

  printf("%.16f\n", ans);
}

Measured memory_bytes: 4192
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (n % i != 0) {
			ans += n / i;
		} else {
			ans += n / i - 1;
		}
	}
	cout << ans << '\n';

}
int  main()
{

	fastio;
	int t = 1;
	if (takeTestCases) { cin >> t; }
	int t_t = 1;
	while (t--) {
		if (printCaseNo)
		case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0;
}


Measured memory_bytes: 3804
#include<iostream>
#include<stdio.h>
using namespace std;

int main() {
	int n;
	while (1) {
		cin >> n;
		if (n == 0)break;
		int matrix[11][11];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> matrix[i][j];
			}
		}
		int num1, num2;
		for (int i = 0; i < n; i++) {
			num1 = 0; num2 = 0;
			for (int j = 0; j < n; j++) {
				num1 += matrix[i][j];
				num2 += matrix[j][i];
			}
			matrix[i][n] = num1;
			matrix[n][i] = num2;
		}
		num1 = 0;
		for (int i = 0; i < n; i++) {
			num1 += matrix[n][i];
		}
		matrix[n][n] = num1;
		for (int i = 0; i < n + 1; i++) {
			for (int j = 0; j < n + 1; j++) {
				printf("%5d", matrix[i][j]);
			}
			printf("\n");
		}
	}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
#define rll register ll
const int N=1e4+5;
int p[N],a[N],tot;
inline void prime(ri n){
	ri i,j,x;
	for(i=2;i<=n;++i){
		if(!p[i]) a[++tot]=i;
		for(j=1;(x=a[j]*i)<=n;++j){
			p[x]=1;
			if(i%a[j]==0)
				break;
		}
	}
}
inline ll calc(ri i,ri j){
	return (ll)a[(i+j+1)/2]*a[(j-i+500+1)/2+505];
}
inline ll gcd(rll x,rll y){
	return !y?x:gcd(y,x%y);
}
inline ll lcm(rll x,rll y){
	return x/gcd(x,y)*y;
}
int main(){
	ri n,i,j;
	scanf("%d",&n);
	prime(1e4);
//	printf("tot = %d\n",tot);
//	for(i=2;i<=n+1;++i){
//		for(j=2;j<=n+1;++j)
//			printf("%d ",i+j&1);
//		puts("");
//	}
	for(i=2;i<=n+1;++i){
		for(j=2;j<=n+1;++j)
			if(i+j&1)
				printf("%lld ",calc(i,j)); 
			else
				printf("%lld ",lcm(lcm(calc(i-1,j),calc(i+1,j)),lcm(calc(i,j-1),calc(i,j+1)))+1);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3200
import sys
#input = sys.stdin.readline

def main():
    n=int(input())
    h=list(map(int,input().split()))
    cnt,ans=0,0
    bh=h[0]
    for i in range(1,n):
        if h[i]<=bh:
            cnt+=1
        else:
            cnt=0
        bh=h[i]
        ans=max(ans,cnt)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 15020
#include <stdio.h>
int main(){
    int H,W,i,j;
    
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if((i+j)%2==0) printf("#");
            else if((i+j)%2==1) printf(".");
        }
    printf("\n");    
    }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2040
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 1000020;
const int maxm = 1000020;
const int MOd = 998244353;

int a, q, fir[maxn];
vector<int> w[maxn];

int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);

    string s, t;
    cin >> s >> t;

    for(int i=0;i<s.size();i++)
    	w[ s[i]-'a' ].pb(i);

    Lint loc = -1;
    Lint num = 0;
    for(int i=0;i<t.size();i++) {
    	int h = t[i]-'a';
    	if( w[h].size() == 0 ) {
    		printf("-1\n");
    		return 0;
    	}
    	int j = upper_bound( all( w[h] ), loc ) - w[h].begin();
    	if( j >= w[h].size() ) {
    		loc = w[h][0];
    		num++;
    	} else {
    		loc = w[h][j];
    	}
    }

    cout << (Lint)num*s.size() + loc + 1 << endl;
	return 0;
}

Measured memory_bytes: 25792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
//↓Binary Indexed Tree
struct BIT{
private:
	int n;
	vector<int> node;
public:
	//N要素のBITを作り、すべて0で初期化する
	//1-indexedであることに注意！！
	BIT(int N){
		node.resize(N+1,0);
		n=N;
	}
	//ノードiまでの和を計算する
	int sum(int i){
		if(!i)
			return 0;
		return node[i]+sum(i-(i&-i));
	}
	//ノードiにxを足す
	void add(int i,int x){
		if(i>n)
			return;
		node[i]+=x;
		add(i+(i&-i),x);
	}
};
//↑Binary Indexed Tree
//↓座標圧縮：vectorを入れると新座標をvectorで返す
vector<ll> comp(vector<ll> v){
	map<ll,int> pam;
	int sz=v.size();
	for(int i=0;i<sz;i++){
		pam[v[i]]=0;
	}
	//新座標が1からほしいときはnc=1にする
	int nc=0;
	for(pair<ll,int> i:pam){
		pam[i.first]=nc;
		nc++;
	}
	vector<ll> w;
	for(int i=0;i<sz;i++){
		w.push_back(pam[v[i]]);
	}
	return w;
}
//↑座標圧縮
int main(){
	int N,K;
	cin>>N>>K;
	vll A;
	A.pb(0);
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		a-=K;
		A.pb(a);
	}
	for(int i=1;i<=N;i++)
		A[i]+=A[i-1];
	vll B=comp(A);
	BIT T(N+SIZE+100);
	ll ans=0;
	for(int i=0;i<=N;i++){
		ans+=T.sum(B[i]+SIZE);
		T.add(B[i]+SIZE,1);
	}
	cout<<ans<<endl;
	return 0;
}

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

string w;
char chs[26];

int main(){
    cin >> w;
    for(int i = 0; i < w.size(); i++){
        chs[w[i]-'a']++;
    }

    for(int i = 0; i < 26; i++){
        if(chs[i] % 2 != 0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

void solve(ll N,vector<ll> &ans,vector<ll> &A){
  for(int i=0;i<N;i++){ans[i]=i;}
  do{
    bool jd=true;
    for(int i=0;i+1<N;i++){
      jd&=A[ans[i]]!=ans[i+1];
    }
    if(jd){break;}
  }while(next_permutation(ans.begin(),ans.end()));
}

void output(ll N,vector<ll> ans,vector<ll> A){
  bool jd=true;
  for(int i=0;i+1<N;i++){
    jd&=A[ans[i]]!=ans[i+1];
  }
  assert(jd);
  for(auto &I:ans){I++;}
  cout<<ans<<endl;
  sort(ans.begin(),ans.end());
  //for(int i=0;i<N;i++){assert(ans[i]==i+1);}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<ll> A(N),ans(N,-1),cnt(N,0);
  set<ll> S;
  priority_queue<pll> Q;
  cin>>A;
  for(auto &I:A){I--; cnt[I]++; Q.push({cnt[I],I});}
  for(int i=0;i<N;i++){S.insert(i);}
  auto answer=[&](int i,int a){ans[i]=a; cnt[A[a]]--; S.erase(a);};
  if(N<=8){
    solve(N,ans,A);
    bool jd=true;
    for(int i=0;i+1<N;i++){
      jd&=A[ans[i]]!=ans[i+1];
    }
    for(auto &I:ans){I++;}
    if(jd){cout<<ans<<endl;}
    else{cout<<-1<<endl;}
    return 0;
  }

  
  for(int i=0;i+5<N;i++){
    while(!Q.empty()){
      pll u=Q.top();
      if(cnt[u.S]!=u.F || S.count(u.S)==0){Q.pop(); continue;}
      break;
    }
    if(!Q.empty() && cnt[Q.top().S]>=N-i-1){
      assert(A[Q.top().S]!=Q.top().S);
      answer(i,Q.top().S);
      for(int j=i+1;j<N;j++){
        ll k=*S.lower_bound(-1LL);
        if(j==0 || k!=A[ans[j-1]]){
          answer(j,k);
        }
        else{
          S.erase(k);
          ll k2=*S.lower_bound(-1LL);
          answer(j,k2);
          S.insert(k);
        }
      }
      for(auto &I:ans){I++;}
      cout<<ans<<endl;
      return 0;
    }
    ll k=*S.lower_bound(-1LL);
    if(i==0 || k!=A[ans[i-1]]){
      answer(i,k);
    }
    else{
      S.erase(k);
      ll k2=*S.lower_bound(-1LL);
      answer(i,k2);
      S.insert(k);
    }
  }
  
  vector<ll> rem;
  for(auto &I:S){rem.push_back(I);}
  assert(rem.size()==5);
  ll C=N-5;
  do{
    for(int i=0;i<5;i++){
      ans[C+i]=rem[i];
    }
    bool jd=true;
    for(int i=max(0LL,N-10);i+1<N;i++){
      jd&=A[ans[i]]!=ans[i+1];
    }
    if(jd){break;}
  }while(next_permutation(rem.begin(),rem.end()));
  bool jd=true;
  for(int i=0;i+1<N;i++){
    jd&=A[ans[i]]!=ans[i+1];
  }
  assert(jd);
  for(auto &I:ans){I++;}
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9456
#include <iostream>

using namespace std;

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	
	long long result = b, ab = a + b;
	
	if (ab == c) {
		result += ab;
	} else if (ab > c) {
		result += c;
	} else {
		result += ab + 1;
	}
	
	cout << result << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iomanip>
#include <iostream>
#include <vector>    
#include <cstdlib>
#include <set>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

struct apples
{
    int num;
    int kind;
}app[300003];

int cmp(apples f,apples a)
{
    return f.num > a.num;
}
int main()
{
    fast_io();
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++)
    {
        cin >> app[i].num;
        app[i].kind = 1;
    }
    for (int i = a; i < (a+b); i++)
    {
        cin >> app[i].num;
        app[i].kind = 2;
    }
    for (int i = (a+b); i < (a+b+c); i++)
    {
        cin >> app[i].num;
        app[i].kind = 3;
    }
    sort(app, app + (a + b + c), cmp);
    ll ans = 0, num = 0;
    int xx = 0, yy = 0;
    for (int i = 0;i<(a+b+c);i++)
    {
        if(app[i].kind==3)
        {
            if((xx+yy+num)>=(x+y))
                break;
            else
            {
                ans+=app[i].num;
                num++;
            }
        }
        else if(app[i].kind==1)
        {
            if(xx<x)
            {
                ans += app[i].num;
                xx++;
            }    
        }
        else if(app[i].kind==2)
        {
            if(yy<y)
            {
                ans+=app[i].num;
                yy++;
            }
        }
        if((xx+yy+num)>=(x+y))
            break;
    }
    cout << ans;
    return 0;
}

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

int combination[2001]; // 0 ~ 2000

inline void init();
inline int solve(int n);

int main() {
  init();

  int n;
  while (cin >> n)
    cout << solve(n) << endl;

  return 0;
}

inline void init() {
  for (auto i = 0; i <= 1000; i++)
    for (auto j = 0; j <= 1000; j++)
      combination[i+j]++;
}

inline int solve(int n) {
  auto cnt = 0;
  auto last = std::min(n, 2000);
  
  for (auto ab = 0; ab <= last; ab++) {
    auto cd = n - ab;
    if (cd <= 2000)
      cnt += combination[ab] * combination[cd];
  }

  return cnt;
}


Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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 (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    map<int,int> mp;
    int n;
    cin >> n;
    ll s = 0;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
        s+=a;
    }
    int q;
    cin >> q;
    rep(_,q){
        int b,c;
        cin >> b >> c;
        mp[c]+=mp[b];
        s += (c-b)*mp[b];
        mp.erase(b);
        cout << s << endl;
    }
}

Measured memory_bytes: 6124
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start_tmp = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start_tmp = None
                    break
                sj += 1
            start = start_tmp if start_tmp is not None else start

    if start is None:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 38384
use std::cmp::max;
use std::io::{stdin, Read};

macro_rules! parse {
    ($iter: ident) => {
        $iter.next().unwrap().parse().unwrap()
    };
    ($iter: ident,2) => {
        (parse!($iter), parse!($iter))
    };
    ($iter: ident,3) => {
        (parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident,4) => {
        (parse!($iter), parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident, $n: ident) => {
        $iter.take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let (n, x): (i64, i64) = parse!(iter, 2);
    let a = iter.fold((0, 0), |(sum, prev), s| {
        let ai: i64 = s.parse().unwrap();
        let d: i64 = max(prev + ai - x, 0);
        (sum + d, ai - d)
    });
    println!("{}", a.0);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  char D;
  D = N[0];
  char E,F;
  E = N[1];
  F = N[2];
  if ( E < D ) {
    cout << (D-'0')*111 << endl;
  }
  else if ( E == D ) {
    if ( F <= D ) {
      cout << (D-'0')*111 << endl;
    }
    else {
      cout << (D-'0')*111 + 111 << endl;
    }
  }
  else {
    cout << (D-'0')*111 + 111 << endl;
  }
}

Measured memory_bytes: 256