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

#define ll long long
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define repr(i,n) for(int (i)=(n); (i)>=0; (i)--)

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

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

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : 3番目にのみビットを立てることを意味する "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

// 過去問第3問ABC113Bまでdone

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

    vector<int> dp(N,INF);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2; i<N; i++){
        chmin(dp[i], dp[i-1] + abs(h[i-1]-h[i]));
        chmin(dp[i], dp[i-2] + abs(h[i-2]-h[i]));
    }
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
  
  int n, k; cin >> n >> k;
  int d = 0;
  while (n > 0) {
    n /= k;
    d++;
  }
  cout << d << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;


int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<vector<ll>> G(N);
	vector<pair<ll, ll>> to;
	for (ll i = 0; i < N-1; ++i)
	{
		ll a, b; cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
		to.emplace_back(a, b);
	}

	vector<bool> reach(N, false);
	map<pair<ll, ll>, ll> to_color;
	vector<ll> cv(N);

	queue<ll> que;
	que.push(0);
	reach[0] = true;
	ll K{0};
	while (!que.empty())
	{
		ll now = que.front(); que.pop();
		K = max(K, (ll)G[now].size());
		ll cur{1};
		for (auto &nv : G[now])
		{
			if (reach[nv]) continue;
			if (cur == cv[now]) ++cur;
			cv[nv] = to_color[make_pair(now, nv)] = to_color[make_pair(nv, now)] = cur++;
			reach[nv] = true;
			que.push(nv);
		}
	}

	std::cout << K << std::endl;
	for (auto &p : to) std::cout << to_color[p] << std::endl;
}


Measured memory_bytes: 21360
#include <bits/stdc++.h>
#define N 400010
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,v,p[N],lgl[N][20],lgr[N][20];
int Fl[N],Fr[N],sc,XD[N];
int main()
{
	n=read(); v=read(); 
	for(int i=1;i<=n;i++)
		p[i]=read();
	for(int t=v,_=0;t;t>>=1,_++)
	{
		for(int i=1;i<=n;i++)
		{
			int j=i;
			while(p[j+1]-p[j]<=t&&j+1<=n) j++;
			for(int x=i;x<=j;x++)
				lgl[x][_]=j,lgr[x][_]=i;
			i=j;
		} sc=max(sc,_);
	} sc++;
	for(int i=1;i<=n;i++) lgl[i][sc]=lgr[i][sc]=i;
	memset(XD,0x3f,sizeof XD);
	memset(Fr,0x3f,sizeof Fr); Fr[0]=n+1;
	for(int i=0;i<(1<<sc);i++) 
	{
		for(int k=1;k<=sc;k++) if(!(i&(1<<(k-1))))
		{
			Fl[i|(1<<(k-1))]=max(Fl[i|(1<<(k-1))],lgl[Fl[i]+1][k]);
			Fr[i|(1<<(k-1))]=min(Fr[i|(1<<(k-1))],lgr[Fr[i]-1][k]);
		}
	}
	for(int i=0;i<(1<<sc);i++) XD[Fl[i]]=min(XD[Fl[i]],Fr[((1<<sc)-1)^i]);
	for(int i=n;i>=1;i--) XD[i]=min(XD[i],XD[i+1]);
	for(int i=1;i<=n;i++)
	{
		if(lgl[i][0]==n&&lgr[i][0]==1) puts("Possible");
		else 
		{
			if(XD[lgr[i][0]-1]<=lgl[i][0]+1) puts("Possible");
			else puts("Impossible");
		}
	}
	return 0;
}

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


int main(){
  int N;
  cin >> N;

  if(N<10){
    cout << N << endl;
  }else if(N<100){
    cout << 9 << endl;
  }else if(N<1000){
    cout << 9 + N - 99 << endl;
  }else if(N<10000){
    cout << 9 + 900 << endl;
  }else if(N<100000){
    cout << 9 + 900 + N - 9999 << endl;
  }else if(N<1000000){
    cout << 9 + 900 + 90000 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
class BIT():
    def __init__(self, number):
        self.n = number
        self.list = [0] * (number + 1)

    def add(self, i, x):  # ith added x  1indexed
        while i <= self.n:
            self.list[i] += x
            i += i & -i

    def search(self, i):  # 1-i sum
        s = 0
        while i > 0:
            s += self.list[i]
            i -= i & -i
        return s

    def suma(self, i, j):  # i,i+1,..j sum
        return self.search(j) - self.search(i - 1)

N=int(input())
A=[int(i) for i in input().split()]
C=sorted(set(A))
ndd=defaultdict(int)
for i in range(len(C)):
    ndd[i+1]=C[i]
dd=defaultdict(int)
for i in range(len(C)):
    dd[C[i]]=i+1
#print(ndd,dd)
visit=[0]*N
visit[0]=1
s=A[0]
H=[]
H.append(s)
for i in range(1,N):
    if s<A[i]:
        s=A[i]
        H.append(s)
        visit[i]=1

BITI=BIT(N+1)
BITI2=BIT(N+1)
j=len(H)-1
l=dd[H[j]]
num=sum(A)
T=[0]*N
ans=0
for i in range(N-1,-1,-1):
    if l==dd[A[0]]:
        break
    BITI.add(dd[A[i]],A[i])
    BITI2.add(dd[A[i]],1)
    if dd[A[i]]==l and visit[i]==1:
        T[i]=BITI.suma(dd[H[j-1]],N+1)-BITI2.suma(dd[H[j-1]],N+1)*H[j-1]-ans
        ans+=T[i]
        #print(i,j,l,T[i],ans)
        j-=1
        l=dd[H[j]]
x=num-sum(T)
T[0]=x
#print(visit,T)
for t in T:
    print(t)






Measured memory_bytes: 85736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

namespace Mylib{

}
int main(void){
    int S,W;
    
    cin >> S >> W;
    
    if(S>W){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
    return 0;


}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct vt{
	int x,y,z;
};

int h,w;
bool dp[111][111][222];
string s[111];

queue<vt> que;

bool check(int i,int j,int k){
	return (0<=i && i<h && 0<=j && j<w && (s[i][j]^(k%2)));
}

int main(void){
	int i,j;
	vt u,v;
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> s[i];
		for(j=0; j<w; ++j){
			s[i][j] = (s[i][j]=='.');
		}
	}
	u.x = 0; u.y = 0; u.z = 0;
	v.x = 0; v.y = 0; v.z = 1;
	if(check(0,0,0)){
		que.push(u);
		dp[0][0][0] = true;
	}else{
		que.push(v);
		dp[0][0][1] = true;
	}
	while(!que.empty()){
		u = que.front();
		que.pop();
		if(check(u.x+1,u.y,u.z)){
			v.x = u.x+1;
			v.y = u.y;
			v.z = u.z;
			if(!dp[v.x][v.y][v.z]){
				dp[v.x][v.y][v.z] = true;
				que.push(v);
			}
		}
		if(check(u.x+1,u.y,u.z+1)){
			v.x = u.x+1;
			v.y = u.y;
			v.z = u.z+1;
			if(!dp[v.x][v.y][v.z]){
				dp[v.x][v.y][v.z] = true;
				que.push(v);
			}
		}
		if(check(u.x,u.y+1,u.z)){
			v.x = u.x;
			v.y = u.y+1;
			v.z = u.z;
			if(!dp[v.x][v.y][v.z]){
				dp[v.x][v.y][v.z] = true;
				que.push(v);
			}
		}
		if(check(u.x,u.y+1,u.z+1)){
			v.x = u.x;
			v.y = u.y+1;
			v.z = u.z+1;
			if(!dp[v.x][v.y][v.z]){
				dp[v.x][v.y][v.z] = true;
				que.push(v);
			}
		}
	}
	for(i=0; i<222; ++i){
		if(dp[h-1][w-1][i]){
			cout << (i+1)/2 << endl;
			return 0;
		}
	}
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int p = 0, g = 0;
  int ans = 0;
  for(int i = 0 ;i < s.size(); ++ i){
    if(s[i] == 'g'){
      if(p == g){
	g++;
      }
      else{
	ans++;
	p++;
      }
    }else{
      if(p == g){
	g++;
	ans--;
      }else{
	p++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <functional>

constexpr int MAX_N=100,INF=(int)1e9;

struct edge {
	int to,cost;
	edge()=default;
	edge(int _t,int _c) : to(_t),cost(_c) {}
};

struct Node{
	int v,num,cost;
	Node()=default;
	Node(int _v,int _n,int _c) : v(_v),num(_n),cost(_c) {}

	bool operator<(const Node& rhs) const{
		return cost==rhs.cost ? v < rhs.v : cost < rhs.cost; 
	}
	bool operator>(const Node& rhs) const{
		return cost==rhs.cost ? v > rhs.v : cost > rhs.cost;
	}
};

int c,n,m,s,g;

std::vector<edge> G[MAX_N];

int d[11][MAX_N];

int dijkstra() {

	for(int i=0;i<=c;++i){
		for(int j=0;j<n;++j)
			d[i][j]=INF;
	}

	std::priority_queue<Node,std::vector<Node>,std::greater<Node>> que;

	d[c][s]=0;
	que.emplace(s,c,0);

	while(!que.empty()){

		Node node=que.top();
		que.pop();

		int v=node.v;

		if(v==g)
			return d[node.num][g];

		if(node.cost>d[node.num][v])
			continue;

		for(int i=0;i<G[v].size();++i){
			edge e=G[v][i];
			if(node.num==0)
				goto a;
			else{
				if(d[node.num-1][e.to]>d[node.num][v]+e.cost/2){
					d[node.num-1][e.to]=d[node.num][v]+e.cost/2;
					que.emplace(e.to,node.num-1,d[node.num-1][e.to]);
				}
				a:;
				if(d[node.num][e.to]>d[node.num][v]+e.cost){
					d[node.num][e.to]=d[node.num][v]+e.cost;
					que.emplace(e.to,node.num,d[node.num][e.to]);
				}
			}
		}
	}
	return -1;
}

int main() {
	while(1){
		std::cin>>c>>n>>m>>s>>g;
		if(c+n+m+s+g==0)
			return 0;
		--s;
		--g;
		int a,b,f;
		for(int i=0;i<m;++i){
			std::cin>>a>>b>>f;
			--a;
			--b;
			G[a].emplace_back(b,f);
			G[b].emplace_back(a,f);
		}
		int ans=dijkstra();
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;++i)
			G[i].clear();
	}
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 1e9;
int n,k;
int h[N];
int dp[N];
int main() {
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &h[i]);
		dp[i] = INF;
	}
	dp[n - 1] = 0;
	for(int i = n - 2; i >= 0; --i) {
		for(int j = 1; j <= k and i + j < n; ++j) {
			dp[i] = min(dp[i], dp[i + j] + abs(h[i] - h[i + j]));
		}
	}
	printf("%d\n", dp[0]);
	return 0;
}


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

int main(){

  for (int x = 0;true;x++){
    int h,w;
    cin >> h >> w;

    if (h == 0 && w ==0) break;

    for (int i = 1; i <=h; i++){
      if (i == 1 || i == h){
        for (int j = 1; j <= w; j++){
          cout << "#";
        }
        cout << endl;
      }
      else{
        for (int j = 1; j <= w; j++){
          if (j == 1 || j == w){
            cout << "#";
          }
          else{
            cout << ".";
          }
        }
        cout << endl;
      }
    }
    cout << endl;
  }

  return 0;

}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,ut> prs;
const int SIZE=2005;
const LL p=7+1e9;
const LL INF=1<<30;
const LL INFLL=1LL<<30;
inline void IN(ut &x){cin >> x;}
inline void INA(ut n,ut x[]){REP(i,n) cin >> x[i];}
inline void INE(ut m,VI edges[]){
	ut a,b;
	REP(i,m){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
}
inline void INEC(ut m,Vpr edges[]){
	ut a,b,c;
	REP(i,m){
		cin >> a >> b >> c;
		edges[a].PB(pr(c,b));
		edges[b].PB(pr(c,a));
	}
}
VI v;
LL solve(LL s,LL t,VI& given,bool izryt){ 
	LL sums=0;
	FOR(i,s,t+1){
		if(izryt)
			sums+=v[i];
		else 
			sums+=v[s+t-i];
		given.PB(sums);
	}
	sort(ALL(given),greater<ut>());
	if(s==t) {
		return v[s]>=0;
	}
	VI lef,rig;
	LL ans=0;
	ans += solve(s,(s+t)/2,lef,false);
	ans += solve((s+t)/2+1,t,rig,true);
	int now=rig.size()-1;
	REP(i,lef.size()){
		while(now!=-1 && rig[now]+lef[i]<0) now--;
		ans+=now+1;
	}
	return ans;
}
int main(){
	LL N,K,x;
	cin >> N >> K;
	REP(i,N){
		cin >> x;
		v.PB(x-K);
	}
	VI c;
	cout << solve(0,N-1,c,0) << endl;
	return 0;
}

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

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  
  ll ans;
  if (K % 2 == 0) {
    ans = A - B;
  }
  else {
    ans = B - A;
  }
  if (ans > 1000000000000000000 || ans < -1000000000000000000) {
    cout << "Unfair" << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int sq(int a) { return a*a; }

int bitcount(int a) {
    int c = 0;
    while (a) c++, a&=a-1;
    return c;
}

int n, x[30], y[30], r[30], c[30];

bool conf(int i, int j) {
    return sq(r[i]+r[j]) > sq(x[i]-x[j])+sq(y[i]-y[j]);
}

map<int, int> memo;

int rec(int b) {
    if (memo.count(b)) return memo[b];
    bool f[30];
    rep (i, n) if ((b&(1<<i)) == 0) {
        f[i] = true;
        rep (j, i) if ((b&(1<<j)) == 0 && conf(i, j)) f[i] = false;
    }
    int ans = bitcount(b);
    rep (i, n) if ((b&(1<<i)) == 0 && f[i]) {
        rep (j, i) if ((b&(1<<j)) == 0 && f[j] && c[i] == c[j]) {
            ans = max(ans, rec(b|(1<<i)|(1<<j)));
        }
    }
    return memo[b] = ans;
}

int main() {
    for (;;) {
        scanf("%d", &n);
        if (n == 0) return 0;
        rep (i, n) scanf("%d%d%d%d", x+i, y+i, r+i, c+i);
        memo.clear();
        printf("%d\n", rec(0));
    }
}

Measured memory_bytes: 32000
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;

long long int factorial(int n) {
  long long int s = 1;
  for (int i = 2; i <= n; i++) {
    s = (s*i % MOD);
  }
  return s;
}

int main() {
  int N, M; cin >> N >> M;
  
  if (N-M == 0) {
    long long int f = factorial(N);
    cout << (2*f*f) % MOD << endl;
  } else if (N-M == 1 || N-M == -1) {
    int ma = max(N, M);
    int mi = min(N, M);
    cout << (factorial(ma)%MOD) * factorial(mi) % MOD << endl;
  } else {
    cout << 0 << endl;
  }
}


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

using namespace std;

long long A[200005], C[200005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	long long N, K;
	cin >> N >> K;
	for (long long i = 1; i <= N; ++i) {
		cin >> A[i];
	}
	long long curr = 1, move = 1, len, moves;
	if (K <= N) {
		while (K--) curr = A[curr];
		cout << curr << '\n';
		return 0;
	}
	vector<long long> cycle;
	C[curr] = move;
	while (1) {
		move++;
		curr = A[curr];
		if (C[curr] > 0) {
			len = move - C[curr];
			break;
		}
		C[curr] = move;
	}
	long long shift = C[curr] - C[1];
	for (long long i = 0; i < len; ++i) {
		cycle.push_back(curr);
		curr = A[curr];
	}
	moves = (K - shift) % len;
	long long town = cycle[moves];
	cout << town << '\n';
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool a=false;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    a=true;
  }
  if(a){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3552
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,pri[10010],tot=0;
bool nopri[10010];
ll ans[510][510];

ll lcm(ll x,ll y) {return x/__gcd(x,y)*y;}

void sieve(int n)
{
    rep(i,2,n)
    {
        if (!nopri[i]) pri[++tot]=i;
        for (int j=1;j<=tot && i*pri[j]<=n;j++)
        {
            nopri[i*pri[j]]=1;
            if (i%pri[j]==0) break;
        }
    }
}

int main()
{
    sieve(10000);
    n=read();
    if (n==2)
    {
        puts("4 7\n23 10");return 0;
    }
    //rep(i,1,20) cout << pri[i] << " ";cout << endl;
    rep(i,0,n+1) ans[0][i]=ans[n+1][i]=ans[i][0]=ans[i][n+1]=1;
    int now=0;
    rep(i,1,n)
    {
        int st;
        if (i&1) st=1;else st=2;
        for (int j=st;j<=n;j+=2)
        {
            ans[i][j]=pri[(i+j)>>1]*pri[(i-j+n+1)/2+n];
        }
    }
    rep(i,1,n) 
    {
        int st;
        if (i&1) st=2;else st=1;
        for (int j=st;j<=n;j+=2)
        {
            ans[i][j]=lcm(lcm(ans[i-1][j],ans[i+1][j]),lcm(ans[i][j-1],ans[i][j+1]))+1;
        }
    }
    rep(i,1,n)
    {
        rep(j,1,n) printf("%lld ",ans[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itii;
int main()
{
	string s;
	cin>>s;
	if(s == "ABC")
		cout<<"ARC\n";
	else
		cout<<"ABC\n";
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    int f[n][10], p[n][11];
    for (int i = 0; i < n; i++) for (int j = 0; j < 10; j++) cin >> f[i][j];
    for (int i = 0; i < n; i++) for (int j = 0; j < 11; j++) cin >> p[i][j];
    ll ans = -INF;
    for (int bit = 1; bit < (1 << 10); bit++) {
        ll t = 0;
        for (int i = 0; i < n; i++) {
            int c = 0;
            for (int j = 0; j < 10; j++) {
                if ((bit & (1 << j)) && f[i][j]) c++;
            }
            t += p[i][c];
        }
        ans = max(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

ans = 0
pi = 1

for i in range(N):
    pi *= a[i]

for i in range(N):
    ans += (pi-1)%a[i]
    
print(ans)

Measured memory_bytes: 3316
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
    return 0;
}

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

bitset <1000001> primeArr;
void sieve()
{
	int num_sqrt = sqrt(1000000);
	primeArr[1] = 1;
	for (int i = 4; i <= 1000000; i += 2)
		primeArr[i] = 1;

	for (int i = 3; i <= num_sqrt; i += 2) {
		for (int j = 2; i*j <= 1000000; j++)
			primeArr[i*j] = 1;
	}
}

int primeFactor(int n, vector<int> &arr){
    int c = 0;
    while(n%2 == 0){
        arr[c++] = 2;
        n = n/2;
    }
    for(int i=3;i<=sqrt(n);i+=2){
        while(n%i == 0){
            arr[c++] = i;
            n = n/i;
        }
    }
    if(n >2)
        arr[c++] = n;
    return c;
}


int main()
{
    double n, t, a, mini = 1000000;
    int index;
    cin >> n;
    cin >> t >> a;
    for(int i=0;i<n;i++){
        double h;
        cin >> h;
        if(abs(a - (t-(h*0.006))) < mini){
            //cout << abs(a - (t-(h*0.006))) << endl;
            mini = abs(a - (t-(h*0.006)));
            index = i+1;
        }
    }

    cout << index << endl;
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  temp
//
//  Created by tolemy on 2019/08/04.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(int argc, const char * argv[]) {
    
    
    int a = 0;
    cin >> a;
    
    string s;
    cin >> s;
    
    if(a>=3200)
    {
        cout << s << endl;
    }
    else
    {
        cout << "red" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().strip().split()))

def min_energy(N,X):
    min_e=100000000
    for l in range(max(X)+1):
        e=0
        for n in range(N):
            e+=(X[n]-l)**2
        if min_e>=e:
            min_e=e
    return min_e

print(min_energy(N,X))

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main (){
    int a,b;
    char aa[11];
    char j;
    cin >> a;
    cin >> aa;
    cin >> b;
    j=aa[b-1];
    for (int i=0;i<=a-1;i++){
        if (aa[i]!=j){
            aa[i]= '*';
        }
    }
    cout << aa;


}

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

static const int N = 100 + 1;

void trace(int* a, int n);
void swapInt(int& t1, int& t2);
int selectionSort(int* a, int n);

int main() {
  int a[N], n;

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

  int c = selectionSort(a, n);
  trace(a, n);
  printf("%d\n", c);

  return 0;
}

int selectionSort(int* a, int n) {
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int minj = i; 
    for (int j = i + 1; j < n; ++j) {
      if (a[j] < a[minj]) { minj = j;  }
    }
    swapInt(a[i], a[minj]);
    if (i != minj) { cnt++; }
  }
  return cnt;
}

void trace(int* a, int n) {
  for (int i = 0; i < n; ++i) {
    if (i) { printf(" "); }
    printf("%d", a[i]);
  }
  printf("\n");
}

void swapInt(int& t1, int& t2) {
  int temp = t1;
  t1 = t2;
  t2 = temp;
}

Measured memory_bytes: 1152
import itertools

s = input()
t_list = ['dreamer', 'dream', 'eraser', 'erase']

flg = False
for t in list(itertools.permutations(t_list)):
    s_tmp = s
    for _t in t:
        s_tmp = s_tmp.replace(_t, '')
    if len(s_tmp) == 0:
        print('YES')
        flg = True
        break

if not flg:
    print('NO')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
string S;
int A[200001];
LL MOD=1e9+7;
int main(){
	cin>>N>>S;
	if(S[0]=='W'){
		cout<<0<<endl;
		return 0;
	}
	A[0]=0;
	int c=1;
	for(int i=1;i<2*N;i++){
		int a=0;
		if(S[i]=='B'){
			a=1;
		}
		if(a==c){
			A[i]=1;
		}else{
			A[i]=0;
		}
		c=1-c;
		//cout<<A[i]<<endl;
	}
	LL temp=0;
	LL ans=1;
	REP(i,2*N){
		if(A[i]==0)temp++;
		if(A[i]==1){
			if(temp==0){
				cout<<0<<endl;
				return 0;
			}
			ans*=temp;
			ans%=MOD;
			temp--;
		}
	}
	if(temp!=0){
		cout<<0<<endl;
		return 0;
	}
	REP(i,N){
		LL x=i+1;
		ans*=x;
		ans%=MOD;
	}	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1412
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int[] n=new int[3];
    int f=3;
    for(int i=0;i<3;i++){
      n[i]=sc.nextInt();
    }
    if(n[0]==n[1]){
      f--;
      if(n[0]==n[2]){
        f--;
      }
    }else if(n[1]==n[2]){
      f--;
    }else if(n[0]==n[2]){
      f--;
    }
    System.out.println(f);
  }
}


Measured memory_bytes: 21588
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        String str = "";

        if (a < b) {
            str = "a < b";
        }
        if (a > b) {
            str = "a > b";
        }

        if (a == b) {
            str = "a == b";
        }

        System.out.println(str);

        sc.close();

    }

}



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

typedef long long LL;
const int M=2e5+5;
int a[M];

int main()
{
	int n;
	scanf("%d",&n);
	LL ans=-1;
	int f=1;
	a[0]=-1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>a[i-1]+1) f=0;
		if(a[i]==a[i-1]+1) ans++;
		else ans+=a[i];
	}
	if(!f) ans=-1;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S,T;
  cin >> S >> T;
  int ans = 100000;
  int N = S.size();
  int M = T.size();
  for (int i = 0; i < N-M+1; i++) {
    int cnt = 0;
    string str = S.substr(i,M);
    for (int j = 0; j < M; j++) {
      if (str[j] != T[j]) {
        cnt++;
      }
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
# a[i]<b[j]<c[k]
# iterate over b and find the lower bound and upper bound in a and c respectively
from bisect import bisect_left , bisect_right
def main():
	n = int(input())
	a = list(map(int , input().split()))
	b = list(map(int, input().split()))
	c = list(map(int ,input().split()))
	a.sort()
	b.sort()
	c.sort()
	ans=0
	for i in b:
		k = bisect_left(a,i)
		l = bisect_right(c,i)
		ans = ans+(k*(n-l))
	print(ans)
if __name__=="__main__":
	main()

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

int main(void){
    int s;
    cin >> s;
    int a, b;
    string ans;
    a = s / 100; //上二桁
    b = s % 100; //下二桁
    if(a > 0 && a < 13){
        if(b > 0 && b < 13){
            ans = "AMBIGUOUS";
        }else{
            ans = "MMYY";
        }
    }else{
        if(b > 0 && b < 13){
            ans = "YYMM";
        }else{
            ans = "NA";
        }        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int count=0;
			String[] s=sc.next().split("");

			int[] a=new int[s.length];
			for(int i=0; i<s.length; i++){
			a[i]=Integer.parseInt(s[i]);
			count+=a[i];
			}
			if(a[0]!=0){

			System.out.println(count);
			}
		}

	}

}


Measured memory_bytes: 27176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
const int size = 1e5+10;
ll n,m;
ll x[size];
ll sa[size];

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++)  cin >> x[i];
     
    sort(x,x+m);

    for(int i = 0; i < m-1; i++) sa[i] = x[i+1] - x[i];

    sort(sa,sa+m);

    ll ans = 0;
    for(int i = 0; i < m-n+1; i++)   ans += sa[i];

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  double a, b, h, m; cin >> a >> b >> h >> m;
  double r = M_PI * 2 * (h/12 + (m/60)/12 - m/60);
  double cc = a * a + b * b - 2 * a * b * cos(r);
  printf("%.10f\n", sqrt(cc));

  return 0;
}

// EOF

Measured memory_bytes: 4152
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i, s, e) for(int i=s; i<e; i++)
#define REF(i, s, e) for(int i=s; i>e; i--)
static const long long INF = 9999999999999999;

long long distance_simple(long long ax, long long bx, long long x) {
	return abs(x -  ax) + abs(bx - ax);
}

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

	int a, b, q;
	
	cin >> a >> b >> q;
	
	long long input;
	vector<long long> shrines, temples;
	
	shrines.push_back(-INF);
	FOR(i, 0, a) {
		cin >> input;
		shrines.push_back(input);
	}
	shrines.push_back(INF);

	temples.push_back(-INF);
	FOR(i, 0, b) {
		cin >> input;
		temples.push_back(input);
	}
	temples.push_back(INF);

	//cout << a << ", " << b << ", " << q << endl;
	//cout << "shrines" << endl;
	//FOR(i, 0, a+2) cout << shrines[i] << endl;
	//cout << "temples" << endl;
	//FOR(i, 0, b+2) cout << temples[i] << endl;

	long long min1 = INF;
	long long x;

	FOR(i, 0, q) {
		min1 = INF;
		cin >> x;

		//二分探索
		auto it1 = lower_bound(shrines.begin(), shrines.end(), x);
		int index_s = it1 - shrines.begin() -1; //左側インデックス
		auto it2 = lower_bound(temples.begin(), temples.end(), x);
		int index_t = it2 - temples.begin() - 1; //左側インデックス

		//分岐1：神社探索は左か右か
		FOR(s_lr, 0, 2) {
			//分岐2：寺探索は左か右か
			FOR(t_lr, 0, 2) {
				//神社が先
				long long d_s = distance_simple(shrines[index_s + s_lr], temples[index_t + t_lr], x);
				
				//寺が先
				long long d_t = distance_simple(temples[index_t + t_lr], shrines[index_s + s_lr], x);

				min1 = min({ min1, d_s, d_t });
				//cout << "d_s: " << d_s << endl;
				//cout << "d_t: " << d_t << endl;
				//cout << "min: " << min1 << endl;
			}
		}
		cout << min1 << endl;

		
		
	}

}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long

int main(void)
{
    ll int n, k;
    cin >> n >> k;
    ll int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h, h+n);
    ll int minj = 1000000000;
    for (int i = 0; i <= n-k; i++) {
        minj = min(minj, (h[k-1+i] - h[i]));
    }
    cout << minj << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

// -------------------------------------------------------------------------------------


int main() {
  int N;
  cin >> N;
  vector<int> a(N+1), b(N+1);
  for(int i = 1; i <= N; i++) cin >> a[i];

  int cnt = 0;
  for(int i = N; i > N/2; i--) {
    b[i] = a[i];
    if(b[i] == 1) cnt++;
  }
  for(int i = N/2; i > 0; i--) {
    int _sum = 0;
    for(int j = 2*i; j <= N; j += i) {
      _sum += b[j];
    }

    if((_sum + 1) % 2 == a[i]) {
      b[i] = 1;
      cnt++;
    } else if(_sum % 2 == a[i]) {
      b[i] = 0;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << cnt << endl;
  for(int i = 1; i <= N; i++) {
    if(b[i] == 1) {
      cout << i << endl;
    }
  }

  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 ll MRINF = 5000000000000000;
int main() {


    int N;
    cin >> N;
    int four = 0;

    while(four <= N){
        if((N - four)%7==0){
            cout << "Yes" << endl;
            return 0;
        }
        four += 4;
    }
    cout << "No" << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int MOD = 1000000007;
pair<ll,ll> num[100000];
main(){
    ll N,K;
    cin >> N >> K;
    for(int i = 0;i < N;i++){
        ll a,b;
        cin >> a >> b;
        num[i] = make_pair(a,b);
    }
    sort(num,num+N);
    for(int i = 0;i < N;i++){
        K -= num[i].second;
        if(K <= 0){
            cout << num[i].first << endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int island[52][52];
void func(int,int);

int main(){
  int w,h;
  int ans;
  
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    ans=0;
    fill(island[0],island[52],0);
    
    for(int i=1;i<=h;i++){
      for(int l=1;l<=w;l++){
        cin>>island[i][l];
      }
    }
    
    for(int i=1;i<=h;i++){
      for(int l=1;l<=w;l++){
        if(island[i][l]==1){
          func(i,l);
          ans++;
        }
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

void func(int x,int y){
  island[x][y]=0;
  for(int i=x-1;i<x+2;i++){
    for(int l=y-1;l<y+2;l++){
      if(island[i][l]==1)
        func(i,l);
    }
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


typedef int (*cmp_t)(const void *, const void *);


#define N_MAX 100000


int cmp(const int *a, const int *b)
{
	return *a-*b;
}


int main(void)
{
	int N, i;
	static int A[N_MAX];
	static double B[N_MAX];
	int count;

	while(scanf("%d", &N)==1)
	{
		for(i=0;i<N;i++)
		{
			scanf("%d", &A[i]);
		}
		qsort(A, N, sizeof(A[0]), (cmp_t)cmp);

		B[0]=A[0];
		for(i=1;i<N;i++)
		{
			B[i]=B[i-1]+A[i];
		}

		count=1;
		for(i=1;i<N;i++)
		{
			if(A[i]<=2*B[i-1])
			{
				count++;
			}
			else
			{
				count=1;
			}
		}
/*
for(i=0;i<N;i++) printf(" %d[%d]", A[i], B[i]);
printf("\n");
*/
		printf("%d\n", count);
	}
	return 0;
}


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

int main()
{
	int N, D;

	cin >> N >> D;
	vector<vector<int>> X( N, vector<int>( D ) );
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < D; j++ ) {
			cin >> X[i][j];
		}
	}

	int ans = 0;
	for( int i = 0; i < N - 1; i++ ) {
		for( int j = i + 1; j < N; j++ ) {
			double dist = 0;
			for( int k = 0; k < D; k++ ) {
				int d = X[j][k] - X[i][k];
				dist += d * d;
			}
			if( sqrt( dist ) == floor( sqrt( dist ) ) ) {
				ans++;
			}
		}
	}

	cout << ans << endl;
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

map<int,int> mp1, mp2;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n; cin>>n;

  int a1=0,a2=0,b1=0,b2=0;

  for(int i=0;i<n;i++){
    int t;cin>>t;
    if(i%2==0)mp1[t]++;
    else mp2[t]++;

    if(i==0)a1=t;
    if(i==1)b1=t;

    if(mp1[t]>=mp1[a1]&&a1!=t)a2=a1,a1=t;
    if(mp2[t]>=mp2[b1]&&b1!=t)b2=b1,b1=t;
  }

  if(a1!=b1&&mp1[a1]+mp2[b1]==n){
    cout<<0<<endl;
  }else if (a1!=b1){
    cout<<n-(mp1[a1]+mp2[b1])<<endl;
  } else if(a1==b1){
    cout<<min(n-(mp1[a1]+mp2[b2]), n-(mp1[a2]+mp2[b1]))<<endl;
  }

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;


int main() {
	ll A, B, C, K;
  	cin >> A >> B >> C >> K;
  
	ll nA, nB, nC;//A,B,Cの取る枚数
	nA = nB = nC = 0;

	nA = min(K, A);
	K -= min(K, A);

	nB = min(K, B);
	K -= min(K, B);

	nC = min(K, C);

	cout << nA - nC << endl;
	
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
   set<string> s;
   int n;cin>>n;
   FOR(i,0,n){
       string x;
       cin>>x;
       s.insert(x);
   }
   cout<<s.size();
    
}





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


Measured memory_bytes: 19196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		String[] cut = x.split(" ");
		int a = Integer.parseInt(cut[0]);
		int b = Integer.parseInt(cut[1]);
		int c = Integer.parseInt(cut[2]);
		int d = Integer.parseInt(cut[3]);

		System.out.println(a * b > c * d ? a * b : c * d);

	}
}

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

int n,ans;
string A,B;

string cal(string a,int x,int l,int r){
  for(int i=l;i<r;i++){
    int p=a[i]-'0';
    p=(p+x)%10;
    a[i]='0'+p;
  }
  return a;
}

void dfs(string a,string b,int d,int sum){

  //cout<<a<<' '<<b<<' '<<d<<endl;

  if(ans<=sum) return;

  if(a==b){
    ans=min(ans,sum);
    return ;
  }

  if(a[d]!=b[d]){
    for(int i=1;i<=9;i++){
      string nex=cal(a,i,d,d+1);
      if(nex[d]!=b[d])continue;
      for(int r=d+1;r<=n;r++){
        nex = cal(a,i,d,r);
        dfs(nex,b,d+1,sum+1);
      }
    }
  }
  else{
    dfs(a,b,d+1,sum);
  }
}

signed main(){
  while(cin>>n,n){
    cin>>A>>B;
    ans=1e9;
    dfs(A,B,0,0);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t,a[100001]={0};
    cin>>n;
    ll s=0;
    for(i=1;i<=n;i++)
    {
        cin>>j;
        s+=j;
        a[j]++;
    }
    cin>>q;
    while(q--)
    {
        cin>>p>>r;
       // cout<<a[p]<<" "<<p<<endl;
        s-=a[p]*p;
        k=a[p];
        a[p]=0;
        s-=a[r]*r;
        a[r]+=k;
        s+=a[r]*r;
        //cout<<a[r]<<" "<<r<<endl;
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 4412
#include<stdio.h>
#include<string.h>
 
int main(){
    int n,m,flag=0,i,j;
    char s[256][16],t[16];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%s",s[i]);
    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%s",t);
        for(j=0;j<n;j++){
            if(!strcmp(t,s[j])){
                if(!flag){
                    printf("Opened by %s\n",t);
                    flag=1;
                    break;
                }else{
                    printf("Closed by %s\n",t);
                    flag=0;
                    break;
                }
            }
        }
        if(j==n)printf("Unknown %s\n",t);
    }
    return 0;
}

Measured memory_bytes: 1032
n = gets.to_i
cards = gets.split

value = ->(card) {
  card[1].to_i
}

bubble_sort = ->(ar) {
  n.times do |i|
    (n - 1).downto(i + 1) do |j|
      ar[j], ar[j - 1] = ar[j - 1], ar[j] if value.(ar[j]) < value.(ar[j - 1])
    end
  end
  ar
}

selection_sort = ->(ar) {
  result = "Stable"
  n.times do |i|
    minj = i
    f = false
    (i + 1).upto(n - 1) do |j|
      f = true if value.(ar[i]) == value.(ar[j])
      if value.(ar[j]) < value.(ar[minj])
        minj = j
        result = "Not stable" if f
      end
    end
    ar[i], ar[minj] = ar[minj], ar[i]
  end
  return ar, result
}

puts bubble_sort.(cards.dup).join(" ")
puts "Stable"
ar, result = selection_sort.(cards)
puts ar.join(" ")
puts result


Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    scanf(" %d", &n);

    queue<int> que;
    rep(i,1<<n)
    {
        int a;
        scanf(" %d", &a);
        que.push(a);
    }

    while(que.size()>1)
    {
        int x = que.front(); que.pop();
        int y = que.front(); que.pop();

        if(x==y) que.push(x);
        else que.push(abs(x-y));
    }

    printf("%d\n", que.front());
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int sumdig(int N){
    int sum = 0;
    while(N>0){
        sum += N%10;
        N /= 10;
    }
    return sum;
};

int main(){
    int N,res = 1000;
    cin>>N;
    for(int i=1;i<N;i++){
        int j = N - i;
        int sum = sumdig(i) + sumdig(j);
        if(res>sum) res = sum;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3568
MODULO = 998244353
n, m, k = map(int, input().split())

facts = [1 for i in range(n+1)]
for i in range(1, n+1):
	facts[i] = (i * facts[i-1]) % MODULO

facts_1 = [pow(facts[i], MODULO-2, MODULO) for i in range(n+1)]

def C(n, k):
	if k > n:
		print("C is 0")
		return 0
	else:
		to_ret = (facts[n] * facts_1[k] * facts_1[n-k]) % MODULO
			# print("C(", n, ", ", k, "): ", to_ret)
		return to_ret

pow_m1 = [pow(m-1, n-i-1,  MODULO) for i in range(0, k+1)]

ans = 0
for pair in range(0, k+1):
	# print("pair", pair)
	choose_pairs = C(n-1, pair)
	# print("choose_pairs", choose_pairs)

	color_blocks = m
	color_blocks *= pow_m1[pair]
	color_blocks %= MODULO
	# print("color_blocks", color_blocks)
	ans += (choose_pairs * color_blocks) % MODULO
	ans %= MODULO
	# print()
print(ans) 

Measured memory_bytes: 99852
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B;
    cin >> A >> B;
    rep(n, 1, 1e5) {
        if ((int)(n * 1.08) - n == A && (int)(n * 1.10) - n == B) {
            write(n);
            return 0;
        }
    }
    write(-1);
}

Measured memory_bytes: 256
// 2020-07-18 10:15:15
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 0;
  {
    ll c[3];
    memset(c, 0, sizeof c);
    map<char, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    rep(i, n) {
      c[mp[s[i]]]++;
    }
    ans = c[0] * c[1] * c[2];
  }
  rep(i, n-2) REP(j, i+1, n-1) {
    int k = j + j - i;
    if(n <= k) continue;
    ans -= (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]);
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int s, w;
    cin >> s >> w;

    if(w>=s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3636