akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
int q[1000000],dp[1000000];
main(){
	int n,w,i,j,a,b,mx=-1;
	cin>>n>>w;
	dp[0]=1;
	for (i=0;i<n;++i){
		cin>>a>>b;
		for (j=w;j>=a;j--){
			if (dp[j-a]!=0){
				dp[j]=max(dp[j],dp[j-a]+b);
				mx=max(mx,dp[j]);
			}
		}
	}
	cout <<mx-1;
}

Measured memory_bytes: 1024
N,W = map(int,input().split())
WV = [list(map(int,input().split())) for _ in [0]*N]

#dp[i][n:入れた数][dW:w1からの差分の合計]
dp = [[[0]*(3*N+1) for _ in [0]*(N+1)] for _ in [0]*(N+1)]
w0 = WV[0][0]
for i,wv in enumerate(WV,1):
    w,v = wv
    w -= w0
    for n in range(1,i+1):
        for dW in range(3*N+1):
            if n*w0 + dW > W:break
            if w>dW:
                dp[i][n][dW] = dp[i-1][n][dW]
                continue
            dp[i][n][dW] = max(dp[i-1][n][dW],dp[i-1][n-1][dW-w]+v)
print(max(max(row) for row in dp[-1]))

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

#include<algorithm>
#include<functional>
#include<vector>

using Size = int;
using Vertex = int;
using Weight = long long;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

class CentroidDecomposition {
 public:
  CentroidDecomposition(const Graph& G, Vertex root) : parent(G.size(), NIL), depth(G.size(), 0), subsize(G.size(), 1), head(G.size()), d(G.size(), 0) {
    std::function<Size(Vertex)> dfs = [&](Vertex cur) {
      for(const auto& e: G[cur]) if(e.to != parent[cur]) {
        d[e.to] += d[e.from] + e.weight;
        depth[e.to] = depth[cur] + 1;
        parent[e.to] = cur;
        subsize[cur] += dfs(e.to);
      }
      return subsize[cur];
    };
    std::function<void(Vertex)> build = [&](Vertex cur) {
      Vertex nex = NIL;
      Size size = 0;
      for(const auto& e: G[cur]) if(e.to != parent[cur]) if(chmax(size, subsize[e.to]) == subsize[e.to]) nex = e.to;
      for(const auto& e: G[cur]) if(e.to != parent[cur]) {
        if(e.to == nex) head[e.to] = head[cur];
        else            head[e.to] = e.to;
        build(e.to);
      }
    };
    dfs(root);
    build(head[root] = root);
  }
  Vertex lca(Vertex u, Vertex v) const {
    while(head[u] != head[v]) {
      if(depth[head[u]] > depth[head[v]]) std::swap(u, v);
      v = parent[head[v]];
    }
    return depth[u] < depth[v] ? u : v;
  }
  Weight distance(auto v) {return d[v];}
 private:
  inline Size position(Vertex v) {return depth[v] - depth[head[v]];}
  template<typename T> inline T chmax(T& l, const T& r) {return l = std::max(l, r);};
  const Size NIL = -1;
  std::vector<Vertex> head, parent;
  std::vector<Size> depth, subsize;
  vector<Weight> d;
};

int main() {
  int N;
  cin >> N;
  Graph G(N);
  for(auto i=1; i<N; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    G[a].push_back({a,b,c});
    G[b].push_back({b,a,c});
  }

  int Q, K;
  cin >> Q >> K;
  CentroidDecomposition T(G, K-1);
  for(auto i=0; i<Q; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    cout << T.distance(x) + T.distance(y) << endl;
  }
}


Measured memory_bytes: 18944
#include<iostream>

using namespace std;

int main()
{
	int A, B, sum;
	
	cin >> A >> B;
	
	sum = A - (2 * B);
	
	if(sum > 0){
		cout << sum << endl;
	}
	else{
		cout << 0 << endl;
	}
	
	return 0;
}

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

int main(void){
  int n,count = 0;
  char a[101],b[101],c[101];
  cin >> n >> a >> b >> c;

  for(int i = 0; i < n; i++){
    char temp[3];
    temp[0] = a[i]; temp[1] = b[i]; temp[2] = c[i];
    sort(temp,temp + 3);
    if(temp[0] == temp[1] && temp[1] == temp[2]);
    else if(temp[0] == temp[1] || temp[1] == temp[2])count++;
    else count += 2;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
t=input()
n=len(s)
m=len(t)

ans=m
for i in range(n-m+1):
  res=0
  for j in range(m):
    if s[i+j]==t[j]:
      continue
    else:
      res+=1
  ans=min(ans,res)
print(ans)

Measured memory_bytes: 9116
using System;
class Program{
  static void Main(string[] args){
    string[] tmp = Console.ReadLine().Split(' ');
    int a=int.Parse(tmp[0]), b=int.Parse(tmp[1]), k=int.Parse(tmp[2]);
    int g = Gcd(a,b);
    int p=g;
    int i=1;
    while(i<k){
      if(g % (--p)==0){i++;}
    }
    Console.WriteLine(p);
  }
  public static int Gcd(int a, int b) {
         if (a < b)
             return Gcd(b, a);
         while (b != 0) {
             var remainder = a % b;
             a = b;
             b = remainder;
         }
         return a;
     }
}

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

int main(){
  int n;
  cin>>n;
  int64_t d,a;
  cin>>d>>a;
  vector<pair<int64_t,int64_t>> p(n);
  for(int i=0;i<n;++i) cin>>p[i].first>>p[i].second;
  sort(p.begin(),p.end());

  vector<int64_t> x(n),h(n);
  for(int i=0;i<n;++i) x[i]=p[i].first,h[i]=p[i].second;

  vector<int64_t> dam(n+1,0);
  int64_t ans=0;

  for(int i=0;i<n;++i){
    if(i>0) dam[i] += dam[i-1];

    if(h[i]<=dam[i]) continue;
    else{
      int64_t q=(h[i]-dam[i]+a-1)/a;
      ans += q;
      if(x[i]+2*d>=x[n-1]){
        dam[n] -= q*a;
        dam[i] += q*a;
      }
      else{
      int j=upper_bound(x.begin(),x.end(),x[i]+2*d)-x.begin();
      dam[j] -= q*a;
      dam[i] += q*a;
    }
    }
  }

  cout<<ans<<endl;
}



Measured memory_bytes: 8064
inStr = input()
splitStr = inStr.split()
N = int(splitStr[0])
#L = int(splitStr[1])

S = list(range(N))

for i in range(N):
    S[i] = input()

S.sort()

for i in range(N):
    print("%s" %S[i], end="")
print("")


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   string s;
   cin>>s;
   int n=s.length();
   int f=1;
   int left=(n/2 - 1);
   string temp=s;
   reverse(temp.begin(),temp.end());
   if(temp!=s)
    f=0;
   string s1=s.substr(0,left + 1);
   temp=s1;
   reverse(temp.begin(),temp.end());
    if(temp!=s1)
    f=0;
   string s2=s.substr(n/2 + 1 , n/2);
   temp=s2;
   reverse(temp.begin(),temp.end());
    if(temp!=s2)
    f=0;
   if(!f)
        cout<<"No"<<endl;
   else
    cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
class Main{
    public static void main(String[] a){
    int b=0;
    int c=0;
    int d=0;
     for(b=1;b<=9;b++){
      for(c=1;c<=9;c++){
       d=b*c;
        System.out.println(b+"x"+c+"="+d);
      }
     c=0;
     }
    }
}

Measured memory_bytes: 24196
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
edge = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if s[i][j] =="#":
            for x,y in edge:
                if 0<= i+y <h and 0<= j+x < w and s[i+y][j+x] =="#":break #三番目のforから抜け出す
            else:
                print("No")
                break #二番目
    else:continue
    break
else:print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n;
	cin >> n;
	vi c(8, 0);
	int col = 0;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (1 <= a and a <= 399) {
			c.at(0)++;
		}
		else if (400 <= a and a <= 799) {
			c.at(1)++;
		}
		else if (800 <= a and a <= 1199) {
			c.at(2)++;
		}
		else if (1200 <= a and a <= 1599) {
			c.at(3)++;
		}
		else if (1600 <= a and a <= 1999) {
			c.at(4)++;
		}
		else if (2000 <= a and a <= 2399) {
			c.at(5)++;
		}
		else if (2400 <= a and a <= 2799) {
			c.at(6)++;
		}
		else if (2800 <= a and a <= 3199) {
			c.at(7)++;
		}
		else {
			col++;
		}
	}
	rep(i, 8) {
		if (c.at(i) > 0) {
			ans++;
		}
	}
	int m = 0, M = 0;
	if (col > 0) {
		m = 0;
		M = col;
	}
	if (ans == 0) {
		m = 1;
	}
	cout << ans + m << " " << ans + M << endl;
	return 0;
}


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

int main(){
    string moji;
    cin >> moji;
    int len=0;
    for(int i=moji.length()-2;i>0;i-=2){
        len=i/2;
      if(moji.substr(0,len)==moji.substr(len,len)){
            break;
        }
    }
    cout << to_string(len*2) <<endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input: string) {
    let lines = input.split('\n');
    let bricks = lines[1].split(' ').map(v => parseInt(v));

    let targetIndex = 0;
    let count = 0;
    bricks.forEach((value) => {
        if (value === targetIndex + 1) {
            targetIndex++;
        } else {
            count++;
        }
    })
    console.log(targetIndex === 0 ? -1 : count);

}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 26436
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
const int maxN = 1e5;
const ll maxV = 1e14;
const int NIL = -1;
const int white = 0, gray = 1;
ll TRAV[maxN];
int COLOR[maxN];


struct Edge{
    int from, to;
    ll length;
};


struct Node{
    vector<Edge> e;
};
Node T[maxN];

void dfs(int k){
    rep(i,T[k].e.size()){
        Edge e = T[k].e[i];
        if (COLOR[e.to] == gray) continue;
        else{
            TRAV[e.to] = TRAV[k]+e.length;
            COLOR[e.to] = gray;
            dfs(e.to);
        }
    }
}


int main() {
    int n;
    cin >> n;
    rep(i,n){
        COLOR[i] = white;
    }
    int a,b; ll c;
    Edge e;
    rep(i,n-1){
        cin >> a >> b >> c;
        --a; --b;
        e.from = a; e.to = b; e.length = c;
        T[a].e.push_back(e);
        e.from = b; e.to = a;
        T[b].e.push_back(e);
    }
    int q,k;
    cin >> q >> k;
    --k;
    TRAV[k] = 0;
    COLOR[k] = gray;
    dfs(k);
    int x[q],y[q];
    rep(i,q){
        cin >> x[i] >> y[i];
    }
    rep(i,q){
        cout << TRAV[x[i]-1]+TRAV[y[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
const int N=1e6+10;
int n,ans=0,t=1;
int a[N];
int q=0;

int main(){
    cin>>n;
    vector<int>s;
    for(int i=1;i<=n;i++) {
            cin>>a[i];
            s.push_back(a[i]);}
            int j=0;
    for(int i=1;i<=n;i++){
        if(i!=s[j])
        {s.erase(s.begin()+i-1,s.begin()+i-1);
            i--;
            ans++;
             }
             if(i==s[j]){
                q++;
             }

            j++;
            if(t==n)
                break;
                t++;
    }
    if(q==0)
        cout<<"-1"<<endl;
    else
 cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define MAX 500008

ll modpow(ll a,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n&1){       //nのbitと...00001を比較  nが2で割り切れるならtrue
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a,ll mod){
  return modpow(a,mod-2,mod);
}

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

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2;i<MAX;i++){
    fac[i]=(fac[i-1]*i)%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(ll n,ll k){
  if(n<k){
    return 0;
  }
  if(n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


int main(){
  ll N,M;
  cin>>N>>M;
  COMinit();
  ll ans=0;

  for(ll i=0;i<=N;i++){
    ll x=COM(N,i);
    ll y;
    y=fac[M]*finv[M-i]%MOD;
    x=x*y%MOD;
    y=fac[M-i]*fac[M-i]%MOD;
    x=x*y%MOD;
    y=finv[M-N]*finv[M-N]%MOD;
    x=x*y%MOD;
    if(i%2==0){
      ans+=x;
      ans%=MOD;
    }else{
      ans-=x;
      if(ans<0){
        ans+=MOD;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 15328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll P=1e9+7;

ll ksm(ll x,ll p)
{
    if(p==1)
        return x;
    ll ans=ksm(x,p/2);
    if(p&1)
        return (((ans*ans)%P)*x)%P;
    return (ans*ans)%P;
}

ll n,k,inv[200010],fac[200010],sum=1;

ll F(int x,int y) 
{
	if(y>x) 
        return 0 ;
	return ((fac[x]*inv[y])%P)*inv[x-y]%P; 
}


int main() 
{   cin>>n>>k;
	inv[0]=1;fac[0]=1;
    for(int i=1;i<=n;++i)
        fac[i]=(ll)(fac[i-1]*i)%P,inv[i]=ksm(fac[i],P-2);
    for(ll i=1;i<=min(n-1,k);++i)
    {
        ll ssum=F(n,i);
        ll t=n-i,u=F(n-1,n-t);
        sum=(sum+ssum*u%P)%P;
    }
    cout<<sum<<endl;
	return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

const double PI = acos(-1);



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<pii> ps(n);
  REP(i,n)cin >> ps[i].fi >> ps[i].se;

  int32 ans = 0;

  sort(all(ps), [](auto const& lhs, auto const& rhs) {
    if(lhs.fi + lhs.se == rhs.fi + rhs.se)return lhs.fi < rhs.fi;
    return lhs.fi + lhs.se < rhs.fi + rhs.se;
  });
  chmax(ans, abs(ps[0].fi - ps[n-1].fi) + abs(ps[0].se - ps[n-1].se));

  sort(all(ps), [](auto const& lhs, auto const& rhs) {
    if(lhs.fi - lhs.se == rhs.fi - rhs.se)return lhs.fi < rhs.fi;
    return lhs.fi - lhs.se < rhs.fi - rhs.se;
  });
  chmax(ans, abs(ps[0].fi - ps[n-1].fi) + abs(ps[0].se - ps[n-1].se));

  ANS(ans);
  return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <iomanip>

int main(){
	double a, b, c, d, e, f, x, y;
	
	while(std::cin>>a>>b>>c>>d>>e>>f){
	
		y = (d*c-a*f) / (b*d-a*e); // 連立方程式のyの解
		x = (c-b*y) / a; // xの解
		
		std::cout << std::fixed << std::setprecision(3) << x << " " << y << "\n"; // 桁数の調整
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner scan = new Scanner(System.in);
        int w = scan.nextInt();
        int h = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();

        if(r <= x && x <= w-r) {
            if(r <= y && y <= h-r) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
        scan.close();
    }
}


Measured memory_bytes: 26412
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000
#define NIL -1

int A[500000][3];//x,y,id

void sort_ck(int l,int r,int c){
    priority_queue<pair<int,pair<int,int> > > PQ;
    int c_ = (c+1)%2;
    REP1(i,r-l) PQ.push(make_pair(-A[l+i][c],make_pair(A[l+i][c_],A[l+i][2])));
    REP1(i,r-l){
        A[i+l][c] = -PQ.top().first;
        A[i+l][c_] = PQ.top().second.first;
        A[i+l][2] = PQ.top().second.second;
        PQ.pop();
    }
}

struct Node{
    int id,l,r,p,x,y;
};

Node T[500000];
int np = 0;

int make2Dtree(int l,int r,int d){
    if (r-l <= 0) return NIL;
    int mid = (l+r)/2;
    sort_ck(l,r,d);
    int t = np++;
    T[t].id = A[mid][2];
    T[t].x = A[mid][0];
    T[t].y = A[mid][1];
    int d_ = (d+1)%2;
    T[t].l = make2Dtree(l,mid,d_);
    T[t].r = make2Dtree(mid+1,r,d_);
    
    return t;
}

vector<int> ans;

void findTree(int i,int xs,int xt,int ys,int yt,int d){
    if (d == 0) {
        if(xs <= T[i].x && T[i].l != NIL) findTree(T[i].l,xs,xt,ys,yt,1);
        if (xs <= T[i].x && T[i].x <= xt && ys <= T[i].y && T[i].y <= yt) ans.push_back(T[i].id);
        if(T[i].x <= xt && T[i].r != NIL) findTree(T[i].r,xs,xt,ys,yt,1);
    }else{
        if(ys <= T[i].y && T[i].l != NIL) findTree(T[i].l,xs,xt,ys,yt,0);
        if (xs <= T[i].x && T[i].x <= xt && ys <= T[i].y && T[i].y <= yt) ans.push_back(T[i].id);
        if(T[i].y <= yt && T[i].r != NIL) findTree(T[i].r,xs,xt,ys,yt,0);
    }
}

void in_order(Node T[],int i){
    if (T[i].l != NIL) in_order(T,T[i].l);
    printf("%d\n",T[i].id);
    if (T[i].r != NIL) in_order(T,T[i].r);
}

int main(){
    INT(n);
    REP1(i,n){
        INT(x);INT(y);
        A[i][0] = x;
        A[i][1] = y;
        A[i][2] = i;
    }
    make2Dtree(0,n,0);
    INT(q);
    REP1(i,q){
        INT(xs);INT(xt);INT(ys);INT(yt);
        findTree(0,xs,xt,ys,yt,0);
        sort(ans.begin(),ans.end());
        REP1(j,ans.size()) printf("%d\n",ans[j]);
        BR;
        ans.clear();
    }
    return 0;
}

Measured memory_bytes: 24676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int lli;

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

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int ans = 0;
	int sgn = 1;
	for (int i = 0;i<N;i++) {
		ans = ans + sgn * a[i];
		sgn = sgn * (-1);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int sum=a+b;
    string s;
    cin>>s;
    int cnt=0;
    int overseas=1;
    for(int i=0;i<n;i++){
       if(s[i]=='a'){
            if(cnt<sum){
                cout<<"Yes"<<endl;
                cnt++;
            }
            else cout<<"No"<<endl;
       }
       else if(s[i]=='b'){
            if(cnt<sum && overseas<=b){
                cout<<"Yes"<<endl;
                cnt++;
                overseas++;
            }
            else cout<<"No"<<endl;
       }
       else {
        cout<<"No"<<endl;
       }
    }
    return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		var S = GetString();
		var T = GetString();
		long cnt = 0;
		for(int i = 0; i < S.Length; i++)
		{
			if(S[i] != T[i])
				cnt++;
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 27528
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			Map<Integer, Integer> map = new HashMap<>();
			for(int i = 1 ; i <= n ; i++) {
				String tmp = String.valueOf(i);
				String start = tmp.substring(0, 1);
				String end = tmp.substring(tmp.length() - 1);
				Integer pair = Integer.valueOf(start + end);
				Integer count = map.getOrDefault(pair, 0);
				map.put(pair, count + 1);
			}
			long ans = 0;
			for(Map.Entry<Integer, Integer> entry : map.entrySet()) {
				String tmp = String.valueOf(entry.getKey());
				String start = tmp.substring(0, 1);
				String end = tmp.substring(tmp.length() - 1);
				Integer pair = Integer.valueOf(end + start);
				ans += entry.getValue() * map.getOrDefault(pair, 0);
			}
			System.out.println(ans);
		}

	}

}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n, x, m, cnt = 0, tot = 0, ans = 0, stot = 0;
  cin >> n >> x >> m;
  unordered_map<ll, ll> mp;
  vector<ll> v;
  while (mp.count(x) == 0) {
    mp[x] = cnt++;
    v.push_back(x);
    tot += x;
    x = x * x % m;
  }

  if (n <= cnt) {
    rep(i, n) ans += v[i];
    cout << ans << endl;
    return 0;
  }

  for (auto t : v) {
    if (t == x) break;
    stot += t;
  }

  ll c = 0;
  ll s = cnt - mp[x];
  for (int i = mp[x]; i < cnt; ++i) c += v[i];
  ans = tot;
  n -= cnt;
  ans += n / s * c;
  n %= s;
  rep(i, n) ans += v[mp[x] + i];
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int N, Y;
    cin >> N >> Y;
    int x = -1;
    int y = -1;
    int z = -1;
    for (int i = 0; i <= Y / 10000; i++)
    {
        bool f = false;
        for (int j = 0; j <= Y / 5000; j++)
        {
            z = N - i - j;
            if (0 <= z && z <= N && 9000 * i + 4000 * j == Y - 1000 * N)
            {
                x = i;
                y = j;
                f = true;
                break;
            }
            z = -1;
        }
        if (f)
        {
            break;
        }
    }
    cout << x << ' ' << y << ' ' << z << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

a = input()
b = input()
c = input()
d = input()
e = input()
k = input()
print "Yay!" if e - a <= k else ":("

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct City{
    int num;
    int P;
    int Y;
    int x;
};

// 比較関数を定義
bool sort1(const City& left, const City& right){
    return left.P == right.P ? left.Y < right.Y : left.P < right.P;
}

bool sort2(const City& left, const City& right){
    return left.num == right.num ? left.Y < right.Y : left.num < right.num;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<City> c;
    c.resize(M);
    for(int i=0;i<M;i++){
        c[i].num = i;
        cin >> c[i].P >> c[i].Y;
    }

    //P,Yソート
    sort(c.begin(), c.end(), sort1);

    //xを求める
    int count = 1;
    for(int i=0;i<M;i++){
        if(i==0){
            c[i].x = 1;
            count++;
        }else if(c[i].P == c[i-1].P){
            c[i].x = count;
            count++;
        }else{
            count = 1;
            c[i].x = count;
            count++;
        }
    }

    //numでソート
    sort(c.begin(), c.end(), sort2);
        
    for(int i=0;i<M;i++){
        printf("%06d%06d\n",c[i].P,c[i].x);
    }

    return 0;
}

Measured memory_bytes: 3072
n=tonumber(io.read())
str=io.read()
h={}
for w in string.gmatch(str,"[^ ]+")do
	table.insert(h,w)
end
memo={}
function cal(i)
	if(memo[i]~=nil) then
		return memo[i]
	end
	local way1=cal(i-1)+math.abs(h[i]-h[i-1])
	local way2=99999999
	if(i>2) then
		way2=cal(i-2)+math.abs(h[i]-h[i-2])
	end
	if(way1<way2) then
		memo[i]=way1
	else
		memo[i]=way2
	end
	return memo[i]
end
memo[1]=0
memo[2]=math.abs(h[2]-h[1])
print(math.floor(cal(n)))

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

struct NodeC
{
	int id;
	int left, right;
};
void preOrder(NodeC nodes[],int rootId,int n)
{
	cout << " " << rootId;
	if (nodes[rootId].left != -1)
	{
		preOrder(nodes, nodes[rootId].left, n);
	}

	if (nodes[rootId].right != -1)
	{
		preOrder(nodes, nodes[rootId].right, n);
	}
}
void inOrder(NodeC nodes[], int rootId, int n)
{
	if (nodes[rootId].left != -1)
	{
		inOrder(nodes, nodes[rootId].left, n);
	}

	cout << " " << rootId;

	if (nodes[rootId].right != -1)
	{
		inOrder(nodes, nodes[rootId].right, n);
	}
}
void postOrder(NodeC nodes[], int rootId, int n)
{
	if (nodes[rootId].left != -1)
	{
		postOrder(nodes, nodes[rootId].left, n);
	}

	if (nodes[rootId].right != -1)
	{
		postOrder(nodes, nodes[rootId].right, n);
	}

	cout << " " << rootId;
}
void C()
{
	NodeC nodes[30];
	bool isRoot[30];
	int n;
	cin >> n;
	fill(isRoot, isRoot + n,true);
	for (int i = 0; i < n; i++)
	{
		int id, left, right;
		cin >> id >> left >> right;
		if (left != -1)isRoot[left] = false;
		if (right != -1)isRoot[right] = false;
		nodes[id].id = id;
		nodes[id].left = left;
		nodes[id].right = right;
	}

	int rootId = -1;
	for (int i = 0; i < n; i++)
	{
		if (isRoot[i])rootId = i;
	}
	cout << "Preorder" << endl;
	preOrder(nodes,rootId,n);
	cout << endl;
	cout << "Inorder" << endl;
	inOrder(nodes, rootId, n);
	cout << endl;
	cout << "Postorder" << endl;
	postOrder(nodes, rootId, n);
	cout << endl;
}
int main()
{
	C();
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}
int main() {
	int n; cin >> n;
	cout << 180*(n-2) << endl;
}

Measured memory_bytes: 256
a=[[] for _ in range(3)]
for i in range(3):
  a[i]=list(map(int,input().split()))
l=[]
N=int(input())
for i in range(N):
  n=int(input())
  for i in range(3):
    for j in range(3):
      if a[i][j]==n:
        l.append([i,j])

def judge(l):
  if len(l)<=2:
    return 'No'
  else:
    if [0,0] in l and [1,1] in l and [2,2] in l:
      return 'Yes'
    elif [0,2] in l and [1,1] in l and [2,0] in l:
      return 'Yes'
    else:
      dic1={}
      dic2={}
      for ij in l:
        i,j=ij[0],ij[1]
        if i not in dic1.keys():
          dic1[i]=1
        else:
          dic1[i]+=1
          if dic1[i]==3:
            return 'Yes'
        if j not in dic2.keys():
          dic2[j]=1
        else:
          dic2[j]+=1
          if dic2[j]==3:
            return 'Yes'
      return 'No'
print(judge(l))

Measured memory_bytes: 3064
#include <cstdio>
int factor[1001];
const int MOD = 1e9 + 7;

void factorize(int N) {
  for (int i = 2; i * i <= N; ++i) {
    while (N % i == 0) {
      factor[i]++;
      N /= i;
    }
  }
  if (N != 1)
    factor[N]++;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    factorize(i);
  int ans = 1;
  for (int i = 2; i <= N; ++i)
    ans = 1LL * ans * (1 + factor[i]) % MOD;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn=2e5+23;
#define hash iewrmf
mt19937 rnd(time(0));
ull hash[30],base;
string s[maxn];
unordered_map<ull,vector<int>> m;
int cnt[30];

int main(){
	for(int i=0;i<=26;i++) hash[i]=rnd();
	base=rnd();
	ios::sync_with_stdio(0);
	cin.tie(0);
	if(base%2==0) base++;
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	sort(s+1,s+n+1,[&](auto i,auto j){
		return i.length()>j.length();
	});


	ll ans=0;

	for(int i=1;i<=n;i++){
		if(s[i].length()==1){
			ans+=cnt[s[i][0]-'a'];
			cnt[s[i][0]-'a']++;
			continue;
		}
		ull now=0;
		vector<int> vis(27);
		for(auto c:s[i]) vis[c-'a']++;
		for(int i=0;i<26;i++) if(vis[i]) cnt[i]++;
		for(int j=max((int)s[i].length()-1,1);j>=0;j--){
			if(j<(int)s[i].length()){
				int c=s[i][j]-'a';
				now=now*base+hash[c];
				vis[c]--;
			}
			auto &t=m[now];
			if(!t.size()) t.resize(27);
			if(j==1){
				int c=s[i][j-1]-'a';
				ans+=t[c];
			}
			for(int i=0;i<26;i++) if(vis[i]) t[i]++;
			t[26]++;
		}
		// printf("%s %lld\n",s[i].c_str(),ans);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 190440
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2010


int N;
int ball[SIZE];
vector<int> tree[SIZE];

struct Data {
  int max = 0;
  int min = 0;
  int size = 0;
  int ans = 0;
};

Data dfs1(int now, int back = -1){
  Data res = {0, 0, 0, 0};

  for(int to : tree[now]){
    if (back == to) continue;
    auto p = dfs1(to, now);
    p.max += p.size;
    p.min += p.size;

    debug(res.min - p.max);
    debug(p.min - res.max);

    if (min(p.max, res.max) - max(p.min, res.min) >= 0) {
      res.min = (p.max%2) ^ (res.max%2);
    }else{
      res.min = max(res.min - p.max, p.min - res.max);
    }

    res.max += p.max;

    res.ans += p.ans + p.size;

    res.size += p.size;
  }

  res.size += ball[now];

  debug(now);
  debug(res.min);
  debug(res.max);
  debug(res.size);

  return res;
}

int main(){

  scanf("%d", &N);
  for(int i=0;i<N;i++)
    scanf("%1d", ball+i);

  for(int i=0;i<N-1;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }


  int ans = INF;

  for(int i=0;i<N;i++){
    auto res = dfs1(i);
    if (res.min == 0){
      debug("Yes");
      ans = min(ans, res.ans / 2);
    }
  }

  if (ans == INF){
    puts("-1");
  } else {
    printf("%d\n", ans);
  }


  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int N=2e5+9;
	int X,Y,A,B,C,a[N],b[N],c[N],ans;
	int main(){
		X=read<int>(),Y=read<int>(),A=read<int>(),B=read<int>(),C=read<int>();
		for(int i=1;i<=A;i++) a[i]=-read<int>();
		for(int i=1;i<=B;i++) b[i]=-read<int>();
		for(int i=1;i<=C;i++) c[i]=-read<int>();

		sort(a+1,a+A+1),sort(b+1,b+B+1),sort(c+1,c+C+1);
		for(int i=1;i<=X;i++) ans+=-a[i];
		for(int i=1;i<=Y;i++) ans+=-b[i];

		for(int i=1,l=X,r=Y;i<=C;i++){
			int mn=-c[i],pos=-1;
			if(l>=1 && -a[l]<=mn) mn=-a[l],pos=0;
			if(r>=1 && -b[r]<=mn) mn=-b[r],pos=1;

			if(pos==-1) break;
			ans+=-c[i]-mn;
			if(pos==0) l--;
			else r--;
		}
		printf("%lld\n",ans);
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define speed  ios_base::sync_with_stdio(0);cin.tie(0) ; cout.tie(0);   
#define ll long long
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define mod 1000000007
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
int main()
{
  speed;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  {
      string s,t;
        cin>>s>>t;
        int i;
        for(i=0;i<s.length();i++)
        {
          if(s[i]!=t[i])
          {
            break;
          }
        }
        if((i==s.length())&&(t.length()==(s.length()+1)))
        {
          cout<<"Yes"<<endl;
        }
        else
        {
          cout<<"No"<<endl;
        }
        

  }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N, K;
ll h[100000];

void _main() {
  cin >> N >> K;
  rep(i, 0, N) cin >> h[i];
  sort(h, h+N);

  ll ans = infl;
  rep(i, 0, N-K+1) chmin(ans, h[i+K-1] - h[i]);
  cout << ans << "\n";
}

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

int W,H;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct Cor{
	int x,y;
	Cor(int para_x,int para_y){
		x=para_x;
		y=para_y;
	}
};

bool in(int x,int y){
	if(x<0 || y<0 || x>=W || y>=H)
		return false;
	 return true;
}

void next(int x,int y,char c,vector<string> &M,vector<vector<bool> > &visit,vector<Cor> &C){
	if(!in(x,y)) return; //OÅµ½
	if(visit[y][x]) return;  //à¤«½º
	if(M[y][x]!=c) return;  //á¤ubN¾æ
	visit[y][x]=true;
	

	C.push_back(Cor(x,y));//¡ÜÅÊÁ½ubNÉÇÁ·éº

	for(int r=0;r<4;r++){//×Úµ½¯¶íÞÌubNÈ¢H
		int nx=x+dx[r],ny=y+dy[r];
		if(in(nx,ny) && M[ny][nx]==c)
			next(nx,ny,M[ny][nx],M,visit,C);
	}

	if(in(x,y-1) && isdigit(M[y-1][x]) && M[y-1][x]!=c){
		next(x,y-1,M[y-1][x],M,visit,C);
	}
}

void start(int x,int y,char c,vector<string> &M,vector<vector<bool> > &visit,vector<Cor> &C,int &left,int &right,vector<vector<bool> > &checked){
	if(!in(x,y)) return; //OÅµ½
	if(visit[y][x]) return;  //à¤«½º
	if(M[y][x]!=c) return;  //á¤ubN¾æ
	if(checked[y][x]) return;
	visit[y][x]=true;  //«Üµ½æI
	checked[y][x]=true;


	C.push_back(Cor(x,y));//¡ÜÅÊÁ½ubNÉÇÁ·éº
	if(!in(x,y+1)){ //nÊ¾I
		left=min(left,x); //¶ÌlðXV
		right=max(right,x);  //EÌlàËI
	}
	else{
		if(isdigit(M[y+1][x]) && M[y+1][x]!=c){//á¤ubNÅµ½I
			left=min(left,x);// XVI
			right=max(right,x);
		}
	}

	for(int r=0;r<4;r++){
		int nx=x+dx[r],ny=y+dy[r];
		if(!in(nx,ny)) continue;
		if(M[ny][nx]==M[y][x])
			start(nx,ny,M[ny][nx],M,visit,C,left,right,checked);
	}

	if(in(x,y-1) && !visit[y-1][x] && isdigit(M[y-1][x]) && M[y-1][x]!=c){//ãÉá¤ubNª èÜ·©?
		next(x,y-1,M[y-1][x],M,visit,C);
	}

}

void solve(){
	vector<string> M;
	for(int i=0;i<H;i++){
		string s;
		cin>>s;
		M.push_back(s);
	}

	vector<vector<bool> > checked(H,vector<bool>(W,false));
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			if(checked[y][x]) continue;
			if(M[y][x]!='.'){
				vector<Cor> C;
				int left=10000,right=0;
				vector<vector<bool> > visit(H,vector<bool>(W,false));
				start(x,y,M[y][x],M,visit,C,left,right,checked);

				double sum_x=0;
				for(int n=0;n<C.size();n++){
					sum_x+=C[n].x+0.5;
				}


				double g=double(sum_x)/C.size();


				if(!(left < g && g < right+1)){
					cout<<"UNSTABLE\n";
					return;
				}
			}
		}
	}
	cout<<"STABLE\n";
}

int main()
{
	while(cin>>W>>H){
		if(W==0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
int main(){
int n,i,taro=0,hanako=0;
char card1[101],card2[101];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %s",card1,card2);
if(strcmp(card1,card2)==0) taro+=1,hanako+=1;
else if(strcmp(card1,card2)>0) taro+=3;
else if(strcmp(card1,card2)<0) hanako+=3;
}
printf("%d %d\n",taro,hanako);
return 0; }




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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);

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

    map<int, int> data;
    for (int x : a) {
        if (data.count(x)) {
            data.at(x)++;
        }

        else {
            data[x] = 1;
        }
    }
    vector<int> b;
    for (auto x : data) {
        b.push_back(x.second);
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());

    int c = 0;
    if (b.size() < k) {
        cout << 0 << endl;
    }

    else {
        for (int i = 0; i < k; i++) {
            c += b.at(i);
        }

        cout << n - c << endl;
    }
}

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

using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;

#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
 
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////


struct edge{
    ll to;
    ll num;
};
#define N 200005
l_l d[N];
ll revd[N];
bool comp(edge a,edge b){
    return revd[a.to]<revd[b.to];
}
int main(){fastio
    inf=(ll)1E9;
    ll n,m;cin>>n>>m;
    rep(i,0,n-1){cin>>d[i].fi;d[i].se=i+1;}
    vector<edge>v[n+1];
    rep(i,1,m){
        ll a,b;cin>>a>>b;
        edge e={b,i};
        v[a].pb(e);
        e.to=a;
        v[b].pb(e);
    }
    ll ans[m+1];rep(i,1,m)ans[i]=inf;
    sort(d,d+n);
    rep(i,0,n-1){
        revd[d[i].se]=i;
    }
    rep(i,1,n){
        sort(v[i].begin(),v[i].end(),comp);
    }
    ll mini[n+1];rep(i,1,n)mini[i]=inf;
    vector<ll>gra[n+1];
    rep(i,0,n-1){
        ll ver=d[i].se;
        
       /* c[ver]=1;
        c[v[ver][0].to]=2;色の変更*/
        ll nex=v[ver][0].to;
        ans[v[ver][0].num]=d[i].fi;
        if(mini[ver]<d[i].fi){
            
            cout<<-1<<endl;return 0;
        }
        mini[ver]=d[i].fi;
        Min(mini[nex],d[i].fi);
        gra[ver].pb(nex);
        gra[nex].pb(ver);
        //cout<<ver<<" "<<nex<<endl;
    }
    ll col[n+1];memset(col,-1,sizeof(col));
    rep(i,1,n){
        if(col[i]!=-1)continue;
        queue<ll>q;q.push(i);col[i]=1;
        while(!q.empty()){
            ll t=q.front();q.pop();
            for(auto x:gra[t]){
                if(col[x]!=-1)continue;
                col[x]=3-col[t];
                q.push(x);
            }
        }
    }
    
    /*
    rep(i,1,n){
        cout<<i<<":";
        for(auto x:gra[i])cout<<x<<" ";cout<<endl;
    }*/
    rep(i,1,n){
        if(col[i]==1)cout<<"B";
        else cout<<"W";
    }cout<<endl;
    rep(i,1,m){
        cout<<ans[i]<<endl;
    }
    
    return 0;
}

/*
 7 6
 5 2 1 1 3 3 3
 */


Measured memory_bytes: 26752
#include <stdio.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int main() {
	int d,c[27],s[366][27]={0},t[366],last[27]={0},sat=0;
	scanf("%d",&d);
	rep(i,26)scanf("%d",c+i+1);
	rep(i,d)rep(j,26)scanf("%d",&s[i+1][j+1]);
	
	rep(i,d){
		int ms=1,mt=1;
		rep(j,26)if(s[i+1][j]>ms){mt=j;ms=s[i+1][j];}
    	
		t[i+1]=mt;
	}

	int x=250000;
	while(x--){
		int A=rand()%d+1,B=rand()%d+1,U=rand()%d+1,V=rand()%d+1,a=rand()%26+1,b=rand()%26+1,u=rand()%26+1,v=rand()%26+1,satt=0,a1,b1,u1,v1;
		a1=t[A],b1=t[B],u1=t[U],v1=t[V];
		t[A]=a;t[B]=b,t[U]=u,t[V]=v;
		rep(i,26)last[i+1]=0;
		rep(i,d){
			satt+=s[i+1][t[i+1]];
			last[t[i+1]]=i+1;
			rep(j,26)satt-=c[j+1]*(i+1-last[j+1]);
		}
		if(satt>sat)sat=satt;
		else {t[A]=a1;t[B]=b1;t[U]=u1;t[V]=v1;}
	}
	rep(i,d)printf("%d\n",t[i+1]);
}

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

#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back

int32_t main()
{
    int n; cin >> n;
    int vec[n][3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++)
            cin >> vec[i][j];
    }
    int dp[n][3];
    dp[0][0] = vec[0][0];    dp[0][1] = vec[0][1];    dp[0][2] = vec[0][2];
    for (int i = 1; i < n; i++) {
            dp[i][0] = vec[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = vec[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = vec[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
        }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
    }








Measured memory_bytes: 4992
# coding: utf-8
import collections

S = input()
# print(S)
c = collections.Counter(S)
# print(c)

if len(S) == 4 and (c.most_common()[0][1] == 2 and c.most_common()[1][1] == 2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
b = LIST()
s = sum(a)
for i in range(n):
    if a[i] < b[i]:
        b[i] -= a[i]
        a[i] = 0
        a[i + 1] = max(0, a[i + 1] - b[i])
    else:
        a[i] -= b[i]
print(s - sum(a))


Measured memory_bytes: 97660
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool ok = true;
    if (S[2] != S[3] || S[4] != S[5]) {
        ok = false;
    }
    yesno(ok);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    double r,x,y;
	double p=3.14159265358979323846;

    scanf("%lf",&r);

    x=p*r*r;
    y=2*p*r;

    printf("%.6f %.6f\n",x,y);

    return 0;
}


Measured memory_bytes: 2668