akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int main(void){
	double x1,x2,x3,y1,y2,y3;
	double a1,b1,c1,a2,b2,c2;
	double a_x,a_y,r,waru;
	int  kaisu,i;
	
	scanf("%d",&kaisu);
	
	for(i=0;i < kaisu;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		
		a1 = (2*(x2-x1));
		b1 = (2*(y2-y1));
		c1 = (x1*x1 - x2*x2 + y1*y1 - y2*y2);
		a2 = (2*(x3-x1));
		b2 = (2*(y3-y1));
		c2 = (x1*x1 - x3*x3 + y1*y1 - y3*y3);
		
		waru = (a1*b2-a2*b1);
		if(waru <= 0.000001 && waru >= -0.000001) waru += 0.000001;
		
		a_x = (b1*c2-b2*c1)/(waru*1.0);
		a_y = (c1*a2-c2*a1)/(waru*1.0);
		r = sqrt( (x1-a_x)*(x1-a_x) + (y1-a_y)*(y1-a_y) );
		
		/*
		if(((int)(a_x*10000)) % 10 > 4) a_x += 0.001;
		if(((int)(a_y*10000)) % 10 > 4) a_y += 0.001;
		if(((int)(r*10000))   % 10 > 4)   r += 0.001;
		
		if(a_x < 0.0001 && a_x > -0.0001) a_x = 0.00001;
		if(a_y < 0.0001 && a_y > -0.0001) a_y = 0.00001;
		if(  r < 0.0001 &&   r > -0.0001)   r = 0.00001;
		*/
		
		printf("%.3f %.3f %.3f\n",a_x,a_y,r);
	}
	
	return 0;
}

Measured memory_bytes: 664
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.sizes = [1 for _ in range(size)]

    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.sizes[y] += self.sizes[x]
        else:
            self.parent[y] = x
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sizes[self.find(x)]


N,M = map(int, input().split())

AB = []
for m in range(M):
    AB.append([int(i) for i in input().split()] )

u = UnionFind(N)

com = N*(N-1)//2
ans = [com]


for m in reversed(range(M)):
    a = AB[m][0] -1
    b = AB[m][1] -1
    if u.same(a,b):
        ans.append(com)
    else:
        com -= u.size(a)*u.size(b)
        ans.append(com)
        u.unite(a,b)

for m in reversed(range(M)):
    print(ans[m])

Measured memory_bytes: 30380
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v,long long mod){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mod;
		u=u*u%mod;
		v>>=1;
	}
	return o;
}
long long n,i,j,k,x,y,sum[5005],f[5005][5005][2],g[5005][2],h[5005],ans;
long long top,nex[10005],to[10005],fir[5005];
void lj(long long u,long long v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
void ss(long long u,long long v){
	sum[v]=1;
	f[v][1][0]=1;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(to[top1]!=u){
			ss(v,to[top1]);
			x=to[top1];
			for(i=1;i<=sum[v];i++)
				for(j=1;j<=sum[x];j++){
					g[i+j][0]=(g[i+j][0]+f[v][i][0]*f[x][j][0]+f[v][i][1]*f[x][j][1])%mo;
					g[i+j][1]=(g[i+j][1]+f[v][i][0]*f[x][j][1]+f[v][i][1]*f[x][j][0])%mo;
					if((j&1)==0){
						g[i][0]=(g[i][0]+f[v][i][0]*f[x][j][1]%mo*h[j]+f[v][i][1]*f[x][j][0]%mo*h[j])%mo;
						g[i][1]=(g[i][1]+f[v][i][0]*f[x][j][0]%mo*h[j]+f[v][i][1]*f[x][j][1]%mo*h[j])%mo;
					}
				}
			sum[v]+=sum[x];
			for(i=1;i<=sum[v];i++){
				f[v][i][0]=g[i][0];
				f[v][i][1]=g[i][1];
				g[i][0]=0;
				g[i][1]=0;
			}
		}
}
int main(){
	n=read();
	for(i=1;i<n;i++){
		x=read();y=read();
		lj(x,y);
		lj(y,x);
	}
	h[0]=1;
	for(i=2;i<=n;i+=2)
		h[i]=h[i-2]*(i-1)%mo;
	ss(1,1);
	for(i=2;i<=n;i+=2)
		ans=(ans+(f[1][i][0]-f[1][i][1])*h[i])%mo;
	ans=(ans+mo)%mo;
	pus(ans,2);
    return 0;
}

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

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int k, a, b;
    cin >> k >> a >> b;
    bool ok = false;
    rep2(i,a,b+1){
        if (i % k == 0){
            ok = true;
            break;
        }
    }
    if(ok) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

int main() {

	int N, X, Y;
	cin >> N >> X >> Y;
	--X; --Y;

	vector<vector<int>> data(N, vector<int>(N, INF));
	vector<int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int m1 = min(abs(X - i) + 1 + abs(j - Y), abs(Y - i) + 1 + abs(j - X));
			data[i][j] = min(abs(j - i), m1);
			ans[data[i][j]]++;
		}
	}
	for (int i = 1; i < N; ++i) {
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 18304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

umap<ull, int> resultCache;

int main()
{
    int N, K;

    cin >> N >> K;

    double firstWinProb = std::max(0.0, 1.0 * (N - K + 1) / N);

    double firstLoseProb = 1 - firstWinProb;
    double firstLoseFinallyWinProb = 0;

    int firstLosePatternNum = std::min(N, K - 1);
    if (firstLosePatternNum > 0)
    {
        for (int k = 1; k <= firstLosePatternNum; k++)
        {
            double shouldCoinWinCount = std::ceil(std::log2(1.0 * K / k));
            firstLoseFinallyWinProb += std::pow(0.5, shouldCoinWinCount);
        }
        firstLoseFinallyWinProb *= firstLoseProb / firstLosePatternNum;
    }

    printf("%.15lf\n", (firstWinProb + firstLoseFinallyWinProb));

    return 0;
}

Measured memory_bytes: 384
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

int n, k, ans = 1000000;
vector<int> d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

void dfs(int now_price, int depth) {
    if(now_price >= n) {
        ans = min(ans, now_price);
        return;
    }
    rep(i, 10) {
        if(d[i] == 0 && depth == 0) continue;
        if(d[i] == -1) continue;
        dfs(now_price * 10 + d[i], depth + 1);
    }
}

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

    cin >> n >> k;

    rep(i, k) {
        int x; cin >> x;
        d[x] = -1;
    }
    dfs(0, 0);
    cout << ans << endl;
}


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

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

int X, Y, Z;
int V[4];
struct Cell
{
    int N, E, A;
};
Cell cells[51];

float dp[51][50 * 100];

int main() {
    while(true) {
        cin >> X >> Y >> Z;
        if(!X && !Y && !Z) break;

        rep(i, X) cin >> V[i];

        memset(cells, 0, sizeof(int) * 3 * (Y + 1));
        rep(i, Z) {
            Cell cell;
            cin >> cell.N >> cell.E >> cell.A;
            cells[cell.N] = cell;
        }

        rep(i, Y + 1) {
            rep(j, 100 * Y) {
                dp[i][j] = 0.0;
            }
        }
        dp[0][0] = 1.0;

        rep(i, Y) {
            rep(j, 100 * Y) {
                if(dp[i][j] == 0.0) continue;

                rep(k, X) {
                    int money = j, current = i + V[k];
                    if(current > Y) current = Y;
                    Cell &cell = cells[current];
                    switch(cell.E) {
                        case 1:
                            current += cell.A;
                            break;
                        case 2:
                            money += cell.A;
                            break;
                        case 3:
                            money -= cell.A;
                            if(money < 0) money = 0;
                            break;
                    }
                    if(current > Y) current = Y;
                    dp[current][money] += dp[i][j] / X;
                }
            }
        }
        /*
        rep(i, Y + 1) {
            rep(j, 101) {
                cout.width(4);
                cout << dp[i][j];
            }
            cout << endl;
        }
        */

        float ans = 0.0;
        rep(i, 100 * Y) {
            ans += dp[Y][i] * i;
        }
        cout << (int)ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2164
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    if( n == 3 || n == 5 || n == 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
inline int read()
{
    int sum=0,p=1;char ch=getchar();
    while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
    if(ch=='-')p=-1,ch=getchar();
    while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
    return sum*p;
}

const int maxn=2e5+20;
const int inf=0x3f3f3f3f;

int n;
int p[maxn];

struct node {
    int mx[2];
    node(){ mx[0]=0; mx[1]=-inf;}
    inline void Merge(node lc,node rc){
	mx[0]=max(lc.mx[0],rc.mx[0]);
	mx[1]=max(lc.mx[1],rc.mx[1]);
    }
};
node c[(1<<19)+20];

int val[maxn];

int f[maxn][2];

#define lc (o<<1)
#define rc (o<<1|1)
#define left lc,l,mid
#define right rc,mid+1,r

void update(int x,int *d,int o,int l,int r)
{
    if(l==r)return c[o].mx[0]=d[0],c[o].mx[1]=d[1],void();
    int mid=l+r>>1;
    if(x<=mid)update(x,d,left);
    else update(x,d,right);
    c[o].Merge(c[lc],c[rc]);
}

node query(int ql,int qr,int o,int l,int r)
{
    if(ql>qr)return node();
    if(ql<=l && r<=qr)return c[o];
    int mid=l+r>>1;
    if(qr<=mid)return query(ql,qr,left);
    else if(ql>mid)return query(ql,qr,right);
    else {
	node x; x.Merge(query(ql,qr,left),query(ql,qr,right));
	chkmax(x.mx[0],0);
	return x;
    }
}

/*void make_tree(int o,int l,int r)
{
    c[o].mx[0]=f[l][0]; c[o].mx[1]=f[l][1];
    if(l==r)return;
    int mid=l+r>>1;
    make_tree(left);
    make_tree(right);
    }*/

inline void init()
{
    n=read();
    REP(i,1,n)p[i]=read();
    int mx=0;
    REP(i,1,n)
    {
	val[i]=1;
	if(p[i]>mx)mx=p[i],val[i]=2;
    }
    DREP(i,n,1)
    {
	node t=query(p[i],n,1,1,n);
	f[i][0]=t.mx[val[i]&1]+val[i];
	f[i][1]=t.mx[~val[i]&1]+val[i];
	chkmax(f[i][0],0);
	update(p[i],f[i],1,1,n);
    }
}

int ans[maxn];

inline void doing()
{
    
    int A=0,B=0,Q=0,maxA=0,maxB=0;
    REP(i,1,n)Q+=val[i]==2;

    {
	node t=query(1,n,1,1,n);
	if(t.mx[Q&1]<Q)puts("-1"),exit(0);
    }
	    
    REP(i,1,n)
    {
	int mx[2]={0,0};
	update(p[i],mx,1,1,n);
	int flg0=0,nA,nB,nQ;
	//check0
	{
	    nA=A+(p[i]>maxA),nB=B,nQ=Q-(val[i]==2);
	    {
		int ned=nA+nQ-nB;
		node t=query(maxB+1,n,1,1,n);
		if(ned>=0 && t.mx[ned&1]>=ned)flg0=1;
	    }
	    {
		int ned=nB+nQ-nA;
		node t=query(max(maxA,p[i])+1,n,1,1,n);
		if(ned>=0 && t.mx[ned&1]>=ned)flg0=1;
	    }
	}
	if(flg0)
	{
	    A+=p[i]>maxA; Q-=val[i]==2;
	    ans[i]=0;
	    chkmax(maxA,p[i]);
	}else
	{
	    B+=p[i]>maxB; Q-=val[i]==2;
	    ans[i]=1;
	    chkmax(maxB,p[i]);
	}
    }
    REP(i,1,n)printf("%d",ans[i]);
}

int main()
{

    init();
    doing();
    return 0;
}



Measured memory_bytes: 8448
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#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--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int maxbit(ll x) {
	int res = -1;
	while (x) {
		res++; x /= 2;
	}
	return res;
}
int main() {
	ll a, b; cin >> a >> b;
	if (a == b) {
		cout << 1 << endl; return 0;
	}
	int l1 = maxbit(a);
	int l2 = maxbit(b);
	while (l1 == l2) {
		ll key = (ll)1 << l1;
		a %= key; b %= key;
		l1 = maxbit(a);
		l2 = maxbit(b);
	}
	ll out = 0;
	ll c = b % ((ll)1 << l2);
	int t = maxbit(c); t++;
	c = (ll)1 << t;
	out += ((ll)1 << l2) - a;
	out += c;
	per(i, l2) {
		ll key = (ll)1 << i;
		if (a < key && c <= key) {
			out += key;
		}
		else {
			if (a >= key&&c<=key) {
				key *= 2;
				out += key - a;
			}
			break;
		}
	}
	cout << out << endl;
	return 0;
}


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

using namespace std;

#define int long long
#define reg register
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)

inline int Read() {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a,T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a,T const&b) {
	return a<b?a=b,1:0;
}

const int N=2e3+5,mod=1e9+7ll;

int n,k,m,C[N][N];

signed main() {
	n=Read(),k=Read(),m=n-k;
	C[0][0]=1ll;
	rep(i,1,n) {
		C[i][0]=1ll;
		rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}//debug(C[7][7]);
	if(n==k){
		puts("1");
		rep(i,2,n)printf("%d\n",0);
		return 0;
	}
	printf("%lld\n",(C[m-1][1]+2ll)*1%mod);
	rep(i,2,k) {
		int N1=C[m-1][i],N2=(2*C[m-1][i-1])%mod,N3=C[m-1][i-2],K1=C[k-1][i-1];
		int Ans=((N1+N2+N3)%mod*K1)%mod;
		Ans=(Ans+mod)%mod;
		printf("%lld\n",Ans);
	}
}

Measured memory_bytes: 30080
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = [0] + [list(map(lambda x: tuple(sorted((i, int(x)))), input().split())) for i in range(1, N+1)]
Idx = [0]*(N+1)
pool = set()  # 対局待ち
q = deque([a[0] for a in A[1:]])
#day = [set() for _ in range(N*(N-1)//2)]
ans = 1
s = set()
while q:
    #print(pool, q)
    p = q.popleft()
    if p in pool:
        pool.remove(p)
        a, b = p
        Idx[a] += 1
        Idx[b] += 1
        if a in s or b in s:
            ans += 1
            s = {a, b}
        else:
            s.add(a)
            s.add(b)
        if Idx[a]<N-1:
            q.append(A[a][Idx[a]])
        if Idx[b]<N-1:
            q.append(A[b][Idx[b]])
    else:
        pool.add(p)
if pool:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 99056
#include<bits/stdc++.h>
using namespace std;
int main(){string s;
int i,a=0,b=0;
cin>>s;
for(i=0;i<3;i++){
    if(s[i]=='A'){a++;}
    else{b++;}
}if(min(a,b)){cout<<"Yes";}
else{cout<<"No";}
    return 0;}

Measured memory_bytes: 256
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
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;
}
signed main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<=2;i++) if(s[i]=='R') cnt++;
    if(cnt==2){
        if(s=="RSR") cout<<1<<endl;
        else cout<<2<<endl;
    }
    else cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3544
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    long n, k;
    long i;
    long add, sum=0;
    
    cin >> n >> k;
    
    for(i = n+1; i >= k; i--) {
        add = i * (n - i + 1);
        
        add = add % 1000000007;
        
        sum += add + 1;
        
        sum = sum % 1000000007;
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while(n-- != 0)
		{
			int num = stdIn.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			while(num != 0)
			{
				list.add(num % 10);
				num /= 10;
			}
			Collections.sort(list);
			int max = 0, min = 0;
			for(int i = list.size() - 1; i >= 0; --i)
			{
				max *= 10;
				max += list.get(i);
			}
			for(int i = 0; i < list.size(); ++i)
			{
				min *= 10;
				min += list.get(i);
			}
			System.out.println(max - min);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
    #include <string>
    #include <vector>
    #include <math.h>
    using namespace std;
     
    int main() {
        int N;
        cin>>N;
        long long int T,A;
        cin>>T>>A;
        long long int min=600000*1000;
        int count;
        for(int i=0;i<N;i++){
            long long int h;
            cin>>h;
            if(min>abs(A*1000-(T*1000-6*h))){
                min=abs(A*1000-(T*1000-6*h));
                count=i+1;
            }
        }
        cout<<count<<endl;
    }

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

using namespace std;

using ll = long long;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int m, d;
    cin >> m >> d;
    int ans(0);
    for (int i(10); i <= d; ++i)
        for (int j(1); j <= m; ++j)
            if (i % 10 >= 2 and i / 10 >= 2 and i / 10 * (i % 10) == j)
                ++ans;
    cout << ans << endl;
}


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

int main(){
int N; cin >>N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);}
  
  sort(L.begin(),L.end());int sum=0;
  
  for(int i=0; i<N-1;i++){
    sum+=L.at(i);}
  if(sum<=L.at(N-1)){
    cout << "No" << endl;}
     else{cout << "Yes"<<endl;}}
   
    
    

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

int main() {
  int a, b;
  cin >> a >> b; 
  
  if (a * b / 2 * 2 == a * b * 0.5 * 2 ) {
  cout << "Even" << endl;
  }
  if (a * b / 2 * 2 != a * b * 0.5 * 2 ) {
  cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int k = Integer.parseInt(sc.next());
      int x = Integer.parseInt(sc.next());
      int min = x - (k-1);
      int max = x + (k-1);
      for(int n=min; n<=max; n++) {
      	System.out.println(n + " ");
      }
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
constexpr ll MOD = 1000000007;
int main(void){
  int n;
  scanf("%d\n",&n);
  vector<ll> a(n);
  RPT(i,0,n) scanf("%ld ",&a[i]);
  ll ans = 0;
  vector<ll> ones(65,0);
  ll tmp = 1;
  RPT(i,0,62){
    FOR(j,0,n){
      if( ( (a[j]>>i)&1LL)==1 ) ones[i]++;
    }
    ones[i] = ones[i]*((ll)n-ones[i]) % MOD;
    ones[i] *= tmp;
    ones[i] %= MOD;
    ans += ones[i];
    ans %= MOD;
    tmp *= 2;
    tmp %= MOD;
  }
  /*
  FOR(i,0,n){FOR(j,i+1,n){
    ll tmp = (a[i]^a[j]) % MOD;
    ans += tmp;
    ans %= MOD;
  }
  }
  */
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    string L;
    cin >> L;
    int x=L.size();

    vector<vector<ll> > dp(x+1,vector<ll>(2,0));
    dp[0][0]=1;
    for(int i=0; i<x; i++){
        if(L[i]=='1'){
            dp[i+1][1]=(dp[i][0]+dp[i][1]*3)%MOD;
            dp[i+1][0]=dp[i][0]*2%MOD;
        }else{
            dp[i+1][1]=dp[i][1]*3%MOD;
            dp[i+1][0]=dp[i][0]%MOD;
        }
    }

    //cout_mat(dp);

    cout << (dp[x][1]+dp[x][0])%MOD << endl;
}

Measured memory_bytes: 5760
#include <stdio.h>
#define N 10000

void Opt( int map[ 2 ][ N ], int n, int r[ ] ) {
  int i, j, k;
  int count;
  int cf = 0;

  for( i = 0; i < 2; i++ ) {
    count = 0;

    for( j = 0; j < n; j++ ) {
      if( map[ i ][ j ] == 0 ) {
        map[ i ][ j ] = -1;
        count++;
        cf = 1;
      } else if( map[ i ][ j ] == r[ (i+1)%2 ] ) {
        map[ i ][ j ] = -1;
        count++;
        for( k = 0; k < n; k++ )
          map[ (i+1)%2 ][ k ]--;
        cf = 1;
      }
    }

    r[ i ] -= count;
  }

  if( cf == 0 ) return;

  Opt( map, n, r );
  return;
}

int main( void ) {
  int i, j;
  int n;
  int map[ 2 ][ N ];
  int row[ 2 ], r[ 2 ];

  while( 1 ) {
    scanf( "%d", &n );
    if( !n ) break;

    for( i = 0; i < 2; i++ ) {
      row[ i ] = 0;

      for( j = 0; j < n; j++ ) {
        scanf( "%d", &map[ i ][ j ] );
        row[ i ] += map[ i ][ j ];
      }
    }

    if( row[ 0 ] != row[ 1 ] ) {
      printf( "No\n" );
      continue;
    }

    r[ 0 ] = n;
    r[ 1 ] = n;
    Opt( map, n, r );

    if( !r[ 0 ] && !r[ 1 ] )
      printf( "Yes\n" );
    else
      printf( "No\n" );
  }

  return( 0 );
}

Measured memory_bytes: 660
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++)L[i] = A[left + i];
	for (i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i].value <= R[j].value) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right) {
	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[], int n, int p, int r) {
	int i, j;
	struct Card t, x;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j].value <= x.value) {
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
	int q;
	if (p < r) {
		q = partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q + 1, r);
	}
}

int main() {
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s %d", S, &v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}

	mergeSort(A, n, 0, n);
	quickSort(B, n, 0, n - 1);

	for (i = 0; i < n; i++) {
		if (A[i].suit != B[i].suit)stable = 0;
	}

	if (stable == 1)printf("Stable\n");
	else printf("Not stable\n");
	for (i = 0; i < n; i++) {
		printf("%c %d\n", B[i].suit, B[i].value);
	}

	return 0;
}

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

int main(){
    long long n, k;
    cin >> n >> k;

    if(n % k == 0)
        cout << 0;

    else{
        long long l = n % k;

        cout << min(l, abs(l - k));
    }
    return 0;

}


Measured memory_bytes: 384
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
for i in range(min(N,K)+1): # Dequeueからとる宝石の数
    for j in range(i+1):  # 左からとる宝石の数
        Juel = V[:j]+V[N-i+j:]
        Juel.sort()
        sum_v = 0
        for k in range(min(K-i,i)):
            Juel[k] = max(Juel[k],0)
        ans = max(ans,sum(Juel))
print(ans)

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad
 

main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ solve a b

solve :: Int -> Int -> String  
solve a b = if mod (a + b) 2 == 0 then show (div (a + b) 2) else "IMPOSSIBLE"   

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int N; cin >> N;
	vector<int> a;
	for (int i = 0; i < N; i++) {
		int ipt; cin >> ipt;
		a.push_back(ipt);
	}
	int sc = 0;
	for (int i = 1; i < N; i++) {
		if (a[i] == a[i - 1]) {
			sc++;
			a[i] = 10000;
		}
	}
	cout << sc << endl;






	return 0;
}

Measured memory_bytes: 256
n, d = map(int, input().split())

X = []
for i in range(n):
  X.append(list(map(int, input().split())))
from itertools import combinations as cm
total = 0
for pair in cm(X, 2):
  dis2 = 0
  for i in range(d):
    dis2 += (pair[0][i] - pair[1][i])**2
  dis = dis2**0.5
  if int(dis) == dis:
    total += 1
print(total)

Measured memory_bytes: 38512
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

Node GetMinimum(Node x){
  while (x->left != NIL)
    x = x->left;

  return x;
}

Node GetSuccessor(Node x){
  Node y;
  
  if (x->right != NIL)
    return GetMinimum(x->right);

  y = x->parent;

  while (y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void delete(Node z){
  Node y;
  Node x;

  printf("\n%p %p\n",x,y);
  
  if (z->left == NIL || z->right == NIL)
    y = z;

  else
    y = GetSuccessor(z);

  if (y->left != NIL)
    x = y->left;

  else
    x = y->right;

  if (x != NIL)
    x->parent = y->parent;

  if (y->parent == NIL)
    root = x;

  else if (y == y->parent->left)
    y->parent->left = x;

  else
    y->parent->right = x;

  if (y != z)
    z->key = y->key;
}

Node find(Node u,int k){
  while (u != NIL && k != u->key){
    if (k < u->key)
      u = u->left;

    else
      u = u->right;
  }

  return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){
    y = x;

    if (z->key < x->key)
      x = x->left;

    else
      x = x->right;
  }

  z->parent = y;

  if (y == NIL)
    root = z;

  else if (z->key < y->key)
    y->left = z;

  else
    y->right = z;
}

void inorder(Node u){
  if (u == NIL)
    return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if (u == NIL)
    return;

  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  Node z;
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }

    else if (com[0] == 'f'){
      scanf("%d",&x);
      
      if (find(root,x) != NIL)
	printf("yes\n");

      else
	printf("no\n");
    }

    else if(com[0] == 'd'){
      scanf("%d",&x);
      
      delete(z = find(root,x));
    }
    
  }

  return 0;
}



Measured memory_bytes: 25160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskAA solver = new TaskAA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskAA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println(3 + 2 + 1 - a - b);
        }

    }
}



Measured memory_bytes: 21204
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> a{10, 20, 30, 40, 50, 60, 200};
        vector<int> v(n);
        vector<int> cnt(7);
        for (auto &&i : v) {
            scanf("%d", &i);
            for (int j = 0; j < 7; ++j) {
                if(i < a[j]){
                    cnt[j]++;
                    break;
                }
            }
        }
        for (int i = 0; i < 7; ++i) {
            cout << cnt[i] << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 6748
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,q;
    int ans=0;
    cin >>n;
    vector<int> s(n);
    rep(i,n){
        cin>>s[i];
    }
    cin>>q;
    vector<int>t(q);
    sort(all(s));
    rep(i,q){
        cin>>t[i];
        if(*lower_bound(all(s),t[i])==t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  ll cnt=0;
  ll m=a.at(0);
  for(int i=1; i<n; i++) {
    if(a.at(i)<=m) cnt++;
    m=min(m, a.at(i));
  }
  cout << cnt+1 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
const int P=1e5+5;
const int Q=2e5+2;
#define FOR(i,a,b) for (i = (a); i < (b); i++)
#define ROF(i,a,b) for (i = (a); i > (b); i--)
long long n,m,M,i,j,k,a[P],x=0,y=0,s=0;
using namespace std;
int main()
{
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>M) M=a[i];
    }
    for(i=M*0.5;i<=m;i=i+M){
        for(j=0;j<n;j++)
            if(i%a[j]!=0.5*a[j]) break;
        if(j==n)
            if(x==0){x=i;
              s++;}
            else{
                y=i;
                s++;
                for(k=2*y-x;k<=m;k=k+y-x)
                    s++;
                break;
            }
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long cnt[1005] = {0},ans = 1;
    long long n; cin >> n;
    for(int i = 2; i <= n; i++){
        long long now = i;
        for(long long j = 2; j <= now; j++){
            while(now>0 && now % j == 0){
                ++cnt[j];
                now /= j;
            }
        }
    }
    for(long long i = 0; i <= n; i++){
        if(cnt[i] != 0){
            ans *= cnt[i] + 1;
            ans %= 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

// (x1, y1)が最小、(x2, y2)が最大
struct Rect {
    int x1, y1, x2, y2;
};

int h, w;
vector<string> g;
vector<vector<bool>> seen;

bool isRect(int y, int x) {
    Rect rect;
    rect.x1 = rect.x2 = x;
    rect.y1 = rect.y2 = y;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(g[i][j] != g[y][x]) {
                continue;
            }
            chmax(rect.x2, j);
            chmax(rect.y2, i);
            chmin(rect.x1, j);
            chmin(rect.y1, i);
        }
    }
    for(int i = rect.y1; i <= rect.y2; i++) {
        for(int j = rect.x1; j <= rect.x2; j++) {
            if(g[i][j] != g[y][x] && !seen[i][j]) {
                return 0;
            }
        }
    }
    return 1;
}

void dfs(int y, int x, char c) {
    if(seen[y][x]) {
        return;
    }
    seen[y][x] = true;
    for(int d = 0; d < 4; d++) {
        int ny = y + dy[d];
        int nx = x + dx[d];
        if(0 <= nx && nx < w && 0 <= ny && ny < h && g[ny][nx] == c) {
            dfs(ny, nx, c);
        }
    }
}

void solve() {
    g.clear();
    seen.clear();
    cin >> h >> w;
    g.resize(h);
    seen.resize(h, vector<bool>(w, false));
    for(int i = 0; i < h; i++) {
        cin >> g[i];
    }
    while(1) {
        bool ed = true;
        bool update = false;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                if(g[i][j] == '.') {
                    continue;
                }
                ed = false;
                if(seen[i][j]) {
                    continue;
                }
                if(isRect(i, j)) {
                    update = true;
                    dfs(i, j, g[i][j]);
                }
            }
        }
        if(ed || !update) {
            break;
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(g[i][j] != '.' && !seen[i][j]) {
                print("SUSPICIOUS");
                return;
            }
        }
    }
    print("SAFE");
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    int ans;
    for(int i=1;i*i<=N;i++){
        if(N%i==0) ans=N/i;
    }
    cout<<to_string(ans).size()<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll W, H, x, y;

int main() {

  cin >> W >> H >> x >> y;

  printf("%.14lf ", (double)W*(double)H/2.0);
  if (2*x == W && 2*y == H) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

}


Measured memory_bytes: 888
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define Each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int N;
vector<int> in, h1, h2;

/*
bool sorter(const A& x, const A& y){
	return x.a < y.a;
}

int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

int lcm(int a, int b){
	if(a == 0 || b == 0) return 0;
	return a*b/gcd(a,b);
}
*/
bool dfs(int n){
	bool flag = false;
	if(n == 10) return true;
	else{
		if(h1.size() == 0 || h1[h1.size()-1] < in[n]){
			h1.pb(in[n]);
			if(dfs(n+1)) flag = true;
			h1.pop_back();
		}
		if(h2.size() == 0 || h2[h2.size()-1] < in[n]){
			h2.pb(in[n]);
			if(dfs(n+1)) flag = true;
			h2.pop_back();
		}
	}
	return flag;
}

int main(){
	scanf("%d", &N);
	Rep(i,N){
		in.clear();
		Rep(j,10){
			int ball;	
			scanf("%d", &ball);
			in.pb(ball);
		}
		h1.clear();
		h2.clear();
		if(dfs(0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  cout << ((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible"
                                                          : "Impossible")
       << endl;
}


Measured memory_bytes: 256
//                                                  '-.-'
   //                                         ()      __.'.__
   //                                      .-:--:-.  |_______|
   //                               ()      \____/    \=====/
   //                               /\      {====}     )___(
   //                    (\=,      //\\      )__(     /_____\
   //    __    |'-'-'|  //  .\    (    )    /____\     |   |
   //   /  \   |_____| (( \_  \    )__(      |  |      |   |
   //   \__/    |===|   ))  `\_)  /____\     |  |      |   |
   //  /____\   |   |  (/     \    |  |      |  |      |   |
   //   |  |    |   |   | _.-'|    |  |      |  |      |   |
   //   |__|    )___(    )___(    /____\    /____\    /_____\
   //  (====)  (=====)  (=====)  (======)  (======)  (=======)
   //  }===={  }====={  }====={  }======{  }======{  }======={
   // (______)(_______)(_______)(________)(________)(_________)
   //
   // Credits :- Joan G. Stark
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
   //|                      AUTHOR - KASPAROVIAN                                     |
   //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define frr(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fr first
#define sc second
#define mk make_pair
#define endl '\n'
#define MOD 1000000007
#define in insert
#define sz(x) (ll)(x).size()
#define mem(a,b) memset(a,b,sizeof(a))
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef vector<vi> graph;
template<class T> void mxi(T & a, const T & b) { a = max(a, b); }
template<class T> void mni(T & a, const T & b) { a = min(a, b); }
ld EPS=1e-9;
int arr[405];
int n;
int pre[405];
int dp[405][405];
int go(int l,int r)
{
	//cout<<1;
	if(l==r)
	{
		return 0;
	}
	if(dp[l][r]==-1)
	{
		dp[l][r]=(1LL)*MOD*MOD;
		//cout<<dp[l][r]<<endl;
		for(int k=l;k<=r;k++)
		{
			dp[l][r]=min(dp[l][r],pre[r+1]-pre[l]+go(k,r)+go(l,k-1));
		}
	}
	return dp[l][r];
}
void solve()
{
	mem(dp,-1);
	cin>>n;
	pre[0]=0;
	frr(i,n)
	   cin>>arr[i];
	frr(i,n)
	  pre[i+1]=pre[i]+arr[i];
	cout<<go(0,n-1)<<endl;

}
signed main()
{
  //fast;
  int t,tab;
  t=1;
  tab=t;
  while(t--)
  {
    //cout<<"Case #"<<(tab-t)<<": ";
    solve();
  }
}

Measured memory_bytes: 4892