akhauriyash/Code-Regression huggingface dataset:
#2-1-1 #ABC104C
d,g = map(int,input().split())
q={}
comp={}
p={}
minsolve=0
for i in range(d):
    a,b=map(int,input().split())
    q[i]=a
    p[i]=100*(i+1)
    comp[i]=100*(i+1)*a+b
    minsolve+=a
    
solve=[0 for _ in range(d)]
def roop(s,check,point,solved,minsolve):
    solve=s.copy()
    solve2=s.copy()
    if check==d:
        if 0 in solve:
            solverev=solve.copy()
            solverev.reverse()
            idx=d-solverev.index(0)-1
            shold=max(0,1+(g-point-1)//p[idx])
            if q[idx]>shold and shold>=0:
                solved+=shold
                minsolve=min(minsolve,solved)
        return minsolve

    minsolve=roop(solve,check+1,point,solved,minsolve)
    solve2[check]+=1
    minsolve=roop(solve2,check+1,point+comp[check],solved+q[check],minsolve)
    return minsolve

print(roop(solve,0,0,0,minsolve))

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

vector<int> v[100001],sol(100001,-1);


int lpath(int i)
{
    if(sol[i]!=-1)
        return sol[i];
    int ans=0;
    
    for(int j=0;j<v[i].size();j++)
        ans=max(ans,lpath(v[i][j])+1);
    return sol[i]=ans;
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int t1,t2;
        cin>>t1>>t2;
        v[t1].push_back(t2);
    }
    int lp=0;
    for(int i=1;i<=n;i++)
    {
        lp=max(lp,lpath(i));
    }
    cout<<lp;
    return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> x(N);
  vector<int> y(M);
  for(int i=0; i<N;i++){
  	cin>>x[i];
  }
  for(int i=0; i<M;i++){
  	cin>>y[i];
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  if(x.back()<y.front()&&X<y.front()&&x.back()<Y){
    cout<<"No War"<<endl;
    return 0;
  }
  cout<<"War"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int r;

	cin>>r;

	if(r<1200){
		cout<<"ABC"<<endl;
	}else if(r<2800){
		cout<<"ARC"<<endl;
	}else{
		cout<<"AGC"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)

typedef vector<int> Edges;
typedef vector<Edges> Graph;

Graph g;
vector<int> cnt;
vector<bool> visited;

void dfs(const int cur, int sum) {
  //  cout << "DFS " << cur << "," << sum << endl;            
  visited[cur] = true;
  cnt[cur] += sum;
  for(int i = 0; i < g[cur].size(); i++) {
    int nxt = g[cur][i];
    if(visited[nxt]) continue;
    dfs(nxt, cnt[cur]);
  }
}

int main() {
  int N, Q; cin>>N>>Q;
  g = Graph(N);
  cnt = vector<int>(N,0);
  visited = vector<bool>(N, false);
  for(int i = 1; i < N; i++) {
    int a, b; cin>>a>>b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i,Q) {
    int p, x; cin>>p>>x; p--;
    cnt[p] += x;
  }
  dfs(0,0);
  REP(i,N) cout << " " << cnt[i] ;
  cout << endl;
  return 0;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    // 処理
    // 出力
    (e - a > k) ? cout << ":(" << endl : cout << "Yay!" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N>>K;
    cout<<min(N%K, K - (N % K))<<endl;
}

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

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

using namespace std;

typedef long long ll;
ll n,k,w[100001];

bool check(ll P){
  ll cnt = 1, sum = 0;
  rep(i,n) {
    if( w[i] > P ) return false;
    if( sum + w[i] <= P ) sum += w[i];
    else ++cnt, sum = w[i];
  }
  return cnt <= k;
}

int main(){
  cin >> n >> k;
  rep(i,n) cin >> w[i];
  ll L = 0, R = 2000000000000;
  while( L + 1 < R ){
    ll M = ( L + R ) / 2;
    if( check(M) ) R = M;
    else           L = M;
  }
  cout << R << endl;
  return 0;
}

Measured memory_bytes: 1940
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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

long long f(long long x){
    if(x==1)return 1;
    long long a=f(x/2);
    return a*2+1;
}

int main(){
    long long h;
    cin>>h;
    

    cout<<f(h)<<endl;

}

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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
bitset<8002>yo,abr_yo;
 main()

{
    fast
    string s;
    cin>>s;
    int x,y;
    cin>>x>>y;
    int nxt;
    int k=0,sum1=0,sum2=0;
    int sz=s.size();
    nxt=sz;
    yo.set(0);
    abr_yo.set(0);
    f(i,0,sz-1)
    {
        if(s[i]=='T')
        {
            nxt=i+1;
            break;
        }
        else k++;
    }
    int cnt=0,turn=1;
    s=s+"T";
    f(j,nxt,sz)
    {
        if(s[j]=='T')
        {

            if(turn==1)sum2+=cnt,abr_yo|=(abr_yo<<cnt);
            else sum1+=cnt,yo=(yo<<cnt)|yo;
            cnt=0;
            turn=1-turn;
        }
        else
        {
            cnt++;
        }
    }
    //cout<<k<<" "<<sum1<<" "<<sum2<<endl;
    int rgt=(x-k+sum1);
    int up=(y+sum2);
    int down=(sum2-y);
    int lft=(sum1-x+k);
    if(rgt%2 || up%2 || down%2 || lft%2)
    {
        cout<<"No"<<endl;
        return 0;
    }
    int flag=0;
    rgt=rgt/2;up=up/2;lft=lft/2;down=down/2;
    if(lft>=0 && rgt>=0 && up>=0 && down>=0)
    {
        if(lft+rgt==sum1 && up+down==sum2)
        {
            if(lft<=sum1 && rgt<=sum1)
            {
                if(up<=sum2 && down<=sum2)
                {
                    if(yo[lft] && yo[rgt] && abr_yo[up] && abr_yo[down])
                    {
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;

}





































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

//素数判定機
bool isprime(int x){
  if(x<2) return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

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

  vector<int> l(Q);
  vector<int> r(Q);
  rep(i,Q) cin >> l.at(i) >> r.at(i);//入力終了

  vector<int> lk={};
  for(int j=3;j<=99999;j+=2){
      if(isprime(j)&&isprime((j+1)/2)) lk.push_back(j);
    }//先に全パターンの素数を書き出す

  rep(i,Q){
    int ans=0,L=l.at(i),R=r.at(i);
    for(int j=0;j<lk.size();j++){
      if(L<=lk.at(j)&&lk.at(j)<=R) ans++;
    }
    cout<< ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
/*   In The Name Of God   */
// Hunt...
/*
ID: alimora2
LANG: C++11
TASK: PROB
*/
#include <bits/stdc++.h>

#define sqr(A) (A) * (A)
using namespace std;
typedef long long ll;

const int maxn = 2e5;
ll a[maxn], l[maxn + 1], r[maxn + 1];
stack<ll> t;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	ll n, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		while (!t.empty()) {
			if (a[i] < a[t.top()]) {
				l[i] = t.top();
				t.pop();
			}
			else {
				l[i] = t.top();
				break;
			}
		}
		if (t.empty())
			l[i] = -1;
		t.push(i);
	}
	while (!t.empty())
		t.pop();
	for (int i = n - 1; i >= 0; i--) {
		while (!t.empty()) {
			if (a[i] < a[t.top()]) {
				r[i] = t.top();
				t.pop();
			}
			else {
				r[i] = t.top();
				break;
			}
		}
		if (t.empty())
			r[i] = n;
		t.push(i);
	}
	for (ll i = 0; i < n; i++)
		ans += a[i] * (i - l[i]) * (r[i] - i);
	cout << ans << endl;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s; cin >> s;
	deque<char> que(s.begin(), s.end());
	int q; cin >> q;
	bool rev = true;
	for (int i = 0; i < q; i++) {
		int t; cin >> t;
		if (t == 1) {
			rev = (rev ? false : true);
		} else {
			int f; char c; cin >> f >> c;
			if (f == 1) {
				if (rev) {
					que.push_front(c);
				} else {
					que.push_back(c);
				}
			} else {
				if (rev) {
					que.push_back(c);
				} else {
					que.push_front(c);
				}
			}
		}
	}
	if (!rev) reverse(que.begin(), que.end());
	for (char c : que) cout << c;
}

Measured memory_bytes: 896
/*
  AUTHOR:SOURABH
  CREATED:26:10:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    ll n,i,p,q,mi=1e13;
    cin>>n;
    for(i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {p=i,q=n/p;mi=min(mi,p+q-2);}
    }
    cout<<mi;
    return 0;
}














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

int main()
{    
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n)
    {
        int a;
        cin >> a;
        p[i] = q[i] = a;
    }

    sort(q.begin(), q.end());
    int cnt = 0;
    rep(i,n) if(p[i] != q[i]) cnt++;

    cout << (cnt<=2 ? "YES" : "NO") << endl;
    return 0;
}

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

int main(){
	double r;
	cin>>r;
	printf("%.12lf %.12lf\n",r*r*3.141592653589,r*2*3.141592653589);
	//cout<<r*r*3.141592653589<<" "<<r*2*3.141592653589<<endl;
}



Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] classlist = {"heavy", "light heavy", "middle", "light middle", "welter",
						  "light welter", "light", "feather", "bantam", "fly",
						  "light fly"};
		double[] weightlist = {91,81,75,69,64,60,57,54,51,48,0};
		double weight;
		
		while (sc.hasNextDouble()) {
			weight = sc.nextDouble();
			for(int i = 0;;i++){
				if(weightlist[i] < weight){
					System.out.println(classlist[i]);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  while(cin>>n,n){
    vector<int> ps(n);
    for(int i=0;i<n;i++) cin>>ps[i];

    const int MAX = 600;
    const int INF = 1e9;
    vector< vector<int> > dp(n+1,vector<int>(MAX,INF));
    dp[0][0]=0;
    for(int p:ps){
      int q=p%1000;
      for(int i=n-1;i>=0;i--){
        for(int j=MAX-1;j>=0;j--){
          if(dp[i][j]==INF) continue;
          int coin=j*1000-dp[i][j]-i*500;
          assert(coin>=0);

          int k=(p+999)/1000;

          // get 500 yen
          if((q==0&&500<=coin)||(0<q&&q<=500)||(500<q&&q%500<=coin))
            chmin(dp[i+1][j+k],dp[i][j]+p);

          // no 500 yen
          chmin(dp[i][j+k],dp[i][j]+p);
        }
      }
    }

    for(int i=n;i>=0;i--){
      int res=INF;
      for(int j=0;j<MAX;j++)
        chmin(res,dp[i][j]);
      if(res==INF) continue;
      cout<<i<<" "<<res<<endl;
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3248
#include <stdio.h>
#include <math.h>
int main(){
	int n,l;
	int nearNone,sum=0;
	scanf("%d%d", &n,&l);
	nearNone=l;
	for (int i = 0; i < n; i++) {
		sum+=l+i;
		if(abs(nearNone)>abs(l+i)){
			nearNone=l+i;
		}
	}
	printf("%d\n", sum-nearNone);
	return 0;
}


Measured memory_bytes: 128
//If you are reading this then you are at wrong place.
#include<bits/stdc++.h>
#define mod 1000000007
#define lli long long int
using namespace std;
bool prime [1000001];
void debug(lli a){cout<<a<<endl;}
lli sieve(lli a){memset(prime,true,sizeof(prime));lli p,i;for(p=2;p*p<=a;p++){if(prime[p]==true){for(i=p*2;i<=a;i+=p)prime[i]=false;}}return 0;}
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli find_max(lli __a,lli __b){return __a^((__a^__b) & -(__a<__b));}
lli add(lli __a,lli __b,lli MOD){lli x = (__a+__b)%MOD; return x; }
lli mul(lli a,lli b,lli MOD){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b,lli MOD){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b,lli MOD){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}
int main()
{
//	ifstream cin("testcase.txt");
	//ofstream cout("output.txt");	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);	
	cout.precision(20);
	lli t,i,j;
	//cin>>t;
	//memset(dp, -1, sizeof dp);
	t=1;
	lli counter1=0;
	while(t--)
	{
		counter1++;
		int n;
		cin>>n;
		int a[n];
		for(i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);
		cout<<abs(a[0]-a[n-1]);
		cout<<endl;
		//cout<<"Case #"<<counter1<<" ";
		//cout<<endl;	
	}	
}


Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim**/


#include<bits/stdc++.h>
using namespace std;
#define ll long long

#define pb push_back
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define clr(v) v.clear()
vector<ll>v;
pair<ll,ll>p;
map<ll,ll>mp;
set<ll>st;
deque<ll>dq;
priority_queue<ll>pq;
#define f(i,b) for(i=0;i<b;i++)
#define f1(i,b) for(i=1;i<=b;i++)
#define fr(i,b)for(i=b-1;i>=0;i--)
ll mn=INT_MAX,mx=INT_MIN;
ll n,m,tc,i,j,tmp,sum,cn,ans,res,pos,flag,l,x,k,dif;

string s,str;


ll a[200007],b[200007];
int main()
{

   io;
ll a,b,c,d;
cin>>a>>b>>c>>d;
cout<<min(a,b)+min(c,d)<<endl;
return 0;
}





Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] x = new int[n];
        int maxx = 0;
        int minx = 101;
        for(int i = 0; i < n; i++){
            x[i] = scan.nextInt();
            if(x[i] > maxx){
                maxx = x[i];
            }
            if(x[i] < minx){
                minx = x[i];
            }
        }
        int min = 0;
        int out = Integer.MAX_VALUE;
        for(int i = minx; i <= maxx; i++){
            for(int j = 0; j < n; j++){
                min += Math.pow(x[j] - i, 2);
            }
            if(out > min){
                out = min;
            }
            min = 0;
        }
        System.out.println(out);
    }
}

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

using namespace std;

int M,D;
int ans;

int main(){
	scanf("%d%d",&M,&D);
	for(int i=1;i<=M;i++){
		for(int j=10;j<=D;j++){
			if(j%10>=2)
				if(j>=20)
					if((j%10)*((int)(j/10))==i)
						ans++;
		}
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}


int main(){
	int n; cin >> n;
	map<int,int> a;
	Rep(n){
		int k; cin >> k;
		a[k]++;
	}
	int m1 = 0;
	int m2 = 0;
	for(auto [k,v]: a){
		if(v >= 4){
			if(k > m1){
				m1 = k;
				m2 = k;
			}else if(k > m2){
				m2 = k;
			}
		}
		else if(v >= 2){
			if(k > m1){
				m2 = m1;
				m1 = k;
			}else if(k > m2){
				m2 = k;
			}
		}
	}
	cout << (ll)m1 * m2 << endl;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    char a;
    cin >> a;
    if(a <= 'Z') cout << 'A' << endl;
    else cout << 'a' << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
using namespace std;
using ll = long long;

int main(){
    int p,q,r;
    cin >> p >> q >> r;
    if(p>=q&&p>=r)    cout << q+r;
    else if(q>=p&&q>=r)   cout << p+r;
    else    cout << p+q;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			int max = a >= b ? (a >= c ? a : c) : (b >= c ? b : c);

			if ((a + b + c) == max * 2) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21460
#include <stdio.h>
int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p<'a')||(*p>'z'));}

char *decode (char *inbuf, int s) {
  int p = 0;
  while (inbuf[p]){
    if(!a(&inbuf[p])) {
      int t = inbuf[p] + s;

      if (t > 'z')      inbuf[p] = (char)(t - 26);
      else if (t < 'a') inbuf[p] = (char)(t + 26);
      else              inbuf[p] = (char)t;
    }
    p++;
  }
  return (inbuf);
}

int main(s){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    char *p=inbuf;
    while(*p){
      s = 0;
      if((c(p,12))&&((c(p+1,3)&&a(p+3))||(c(p+1,7)&&c(p+2,7)&&a(p+4))||(c(p+1,25)&&c(p+2,16)&&a(p+4)))){
	s = 't' - *p;
	p+=3;
      }
      if (s) break;
      p++;
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 524
package main

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

func main() {
	s := IOInitialize()
	A := Int(s)
	B := Int(s)
	C := Int(s)
	D := Int(s)
	sum := 0
	if A > B {
		sum += B
	} else {
		sum += A
	}

	if C > D {
		sum += D
	} else {
		sum += C
	}
	fmt.Println(sum)
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;


int main() {
    
    int n;
    cin>>n;
    si s;
    rep(i,n){
        int a;
        cin>>a;
        s.insert(a);
    }
    int q;
    cin>>q;
    rep(i,q){
        int b;
        cin>>b;
        fin(s.count(b));
    }
}


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

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


int main(){
    int N,K,sum=0;
    cin >> N >> K;

    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p.at(i);
    }
    sort(p.begin(),p.end());

    for(int i=0;i<K;i++){
        sum +=p.at(i);
    }
    cout << sum << endl;
}



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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> xy(n, vector<pair<int, int>>(0));
    rep(i, n){
        int A;
        cin >> A;
        rep(j, A){
            int x, y;
            cin >> x >> y;
            x--;
            xy[i].push_back(make_pair(x, y));
        }
    }
    int m = 0;
    bool flag = true;
    for(int temp = 0; temp < (1 << n); temp++){
        int ans = 0;
        flag = true;
        rep(i, n){
            if(temp & (1 << i)){
                rep(j, xy[i].size()){
                    int y = xy[i][j].second;
                    int x = xy[i][j].first;
                    if(y == 1){
                        if(!(temp & (1 << x))){
                            flag = false;
                            break;
                        }
                    }else{
                        if(temp & (1 << x)){
                            flag = false;
                            break;
                        }
                    }
                }
                if(!flag) break;
                else{
                    ans++;
                }
            }
        }
        if(flag){
            m = max(m, ans);
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

a, b = getList()

for i in range(b):
    if (a-1)*i + 1 >= b:
        print(i)
        sys.exit()
# print(math.ceil((b-1)/a))

Measured memory_bytes: 39924
# don't know good 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2954794#1

table = [''] * 1002
dp = [[0] * 1002 for i in range(1002)]

while 1:
	n = int(input())
	if n == 0: break
	for r in range(n): table[r] = input()
	ans = 0
	
	for r in range(n):
		for c in range(n):
			if table[r][c] == '*': dp[r][c] = 0
			else :
				t = dp[r-1][c-1]
				if dp[r  ][c-1] < t: t = dp[r  ][c-1];
				if dp[r-1][c  ] < t: t = dp[r-1][c  ];
				t += 1
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)


Measured memory_bytes: 32164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7,d1[200005],d2[200005],n,k,ans;
ll qpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return res%mod;
}
int main(){
    cin>>n>>k;
    d1[0]=1;d2[0]=1;
    ll t=n,x=1;
    for(int i=1;i<n;i++){
        d1[i]=(d1[i-1]%mod*t%mod*qpow(x,mod-2)%mod)%mod;
        d2[i]=(d2[i-1]%mod*(t-1)%mod*qpow(x,mod-2)%mod)%mod;
        t--;x++;
    }
    for(int i=0;i<=min(k,n-1);i++){
        ans=(ans%mod+d1[i]%mod*d2[i]%mod)%mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  sort(begin(s), end(s));
  cout << (s[0] == s[1] and s[1] != s[2] and s[2] == s[3] ? "Yes" : "No") << '\n';
}

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

int main()
{

#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif


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

    map<int,int> mp[2];

    for (int i = 0; i < n; ++i)
    {
        static int a;
        scanf("%d", &a);
        ++mp[i & 1][a];
    }

    vector< pair<int,int> > v[2];
    for (int r = 0; r < 2; ++r)
    {
        for (auto p : mp[r])
            v[r].push_back({p.second, p.first});

        sort(v[r].begin(), v[r].end());
        reverse(v[r].begin(), v[r].end());

        for (int i = 0; i < v[r].size(); ++i)
            swap(v[r][i].first, v[r][i].second);
    }

    if (v[0].size() == 1)
    {
        if (v[1].size() == 1)
        {
            if (v[0][0].first == v[1][0].first)
                printf("%d", n / 2);
            else
                printf("0");
        }
        else
        {
            if (v[1][0].first == v[0][0].first)
                printf("%d", n /2 - v[1][1].second);
            else
                printf("%d", n / 2 - v[1][0].second);
        }
    }
    else
    {
        if (v[1].size() == 1)
        {
            if (v[1][0].first == v[0][0].first)
                printf("%d", n /2 - v[0][1].second);
            else
                printf("%d", n / 2 - v[0][0].second);
        }
        else
        {
            if (v[0][0].first == v[1][0].first)
                printf("%d", min(n - v[0][0].second - v[1][1].second, n - v[0][1].second - v[1][0].second));
            else
                printf("%d", n - v[0][0].second - v[1][0].second);
        }
    }


}


Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
ll get_digent(ll);


int main(){
  often();
  string s;
  cin >> s;
  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll get_digent(ll x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    while(b <= a) b *= 2, k--;
    while(c <= b) c *= 2, k--;

    cout << ((k >= 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3632
import numpy
n = int(input())
ans = 0
u = list(map(int,input().split()))
d = list(map(int,input().split()))
d.reverse()
u = numpy.cumsum(u)
d = numpy.cumsum(d)
for i in range(n):
    cnt = u[i] + d[n-i-1]
    ans = max(ans,cnt)
print(ans)


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

  const int MOD = 1000000007;
  const int INF = 1e9;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
  #define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
  #define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

  //最大公約数 
  ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b,a%b);
  }

  //最小公倍数
  ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
      a = b;
      b = r;
    }
    return b;
  } 


  //  int X[8]={-1, 0, 1, -1, 1, -1, 0, 1};
  //  int Y[8]={1, 1, 1, 0, 0, -1, -1, -1};




int main() {
 int N;
 cin >> N;
 set<ll> st;
 REP(i, N){
   int a;
   cin >> a;
   if(st.count(a)) st.erase(a);
   else st.insert(a);

 }
   print(st.size());
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    string a, b;
    cin >> a >> b;

    int n = stoi(a + b);

    for (int i = 1; i <= sqrt(100100); ++i) {
        if(i * i == n){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()

# 各X xor Aiについて
# 各桁について
# Xにフラグ立つ + Aiにフラグ立たない
# Xにフラグ立たない + Aiにフラグ立つ　の時 2 ** iだけxorの値が増える
# Aの各要素の2 ** iのフラグの合計がn本の時
# Xの2 ** iのフラグを立てるとN - n * 2 ** i、立てないとn * 2 ** i　f(x)の値が増える

# 各桁のフラグが合計何本あるか
flag = [0] * 61
def splitbit(n):
    for i in range(61):
        if n & (1 << i):
            flag[i] += 1
for i in range(N):
    splitbit(A[i])

x = 0
ans = 0
for i in range(60, -1, -1):
    # flag[i] < N - flag[i]ならフラグを立てるほうがお得
    # だがKの制限があり立てたくても立てられないことがある
    # Xの2 ** iのフラグを立ててもXがKを超えないか
    if flag[i] < N - flag[i] and x + 2 ** i <= K:
        # Xにフラグを立てる
        x += 2 ** i
        # f(x)の値が増える
        ans += 2 ** i * (N - flag[i])
    # flag[i] < N - flag[i]だがフラグを立てられない場合 +
    # flag[i] >= N - flag[i]の時
    else:
        ans += 2 ** i * flag[i]

print(ans)

Measured memory_bytes: 101060
import itertools


def main():
    A = int(input()) + 1
    B = int(input()) + 1
    C = int(input()) + 1
    X = int(input())

    cnt = 0
    for n_500, n_100, n_50 in itertools.product(range(A), range(B), range(C)):
        y = 500 * n_500 + 100 * n_100 + 50 * n_50
        if y == X:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1), b(N + 1), c(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
  }
  vector<vector<int>> cost(N + 1, vector<int>(3, 1000000001));
  cost.at(0).at(0) = 0;
  cost.at(0).at(1) = 0;
  cost.at(0).at(2) = 0;
  for (int i = 1; i <= N; i++) {
      cost.at(i).at(0) 
          = max((cost.at(i - 1).at(1) + a.at(i)), (cost.at(i - 1).at(2) + a.at(i)));
      cost.at(i).at(1) 
          = max((cost.at(i - 1).at(0) + b.at(i)), (cost.at(i - 1).at(2) + b.at(i)));
      cost.at(i).at(2) 
          = max((cost.at(i - 1).at(0) + c.at(i)), (cost.at(i - 1).at(1) + c.at(i)));      
  }
  int C = max(cost.at(N).at(0), cost.at(N).at(1));
  C = max(cost.at(N).at(2), C);
  cout << C << endl;
}
    

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

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int ll
using ll = long long;
using ull = unsigned long long;

int h,w,n;
int is[100010];
int js[100010];

set<int> s;
map<int,int> cnt;

int enc(int i, int j){
    return i*w + j;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> h >> w >> n && h){
        s.clear();
        cnt.clear();
        rep(i,n){
            int a,b;
            cin >> a >> b;
            --a; --b;
            is[i] = a; js[i] = b;
            s.emplace(enc(a,b));
        }
        rep(i,n){
            //cout << 'a' << endl;
            for(int ci = is[i]-2; ci <= is[i]; ++ci){
                for(int cj = js[i]-2; cj <= js[i]; ++cj){
                    if(ci < 0 || cj < 0) continue;
                    if(ci >= h-2 || cj >= w-2) continue;
                    cnt[enc(ci,cj)]++;
                    //cout << ci << ' ' << cj << endl;
                }
            }
        }

        ll ans[10] = {};
        ans[0] = (h-2LL)*(w-2);
        for(auto &box : cnt){
            ++ans[box.second];
            --ans[0];
        }
        rep(i,10) cout << ans[i] << endl;
    }
}


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    long double A; cin >> A;
    a[i] = (A * 1e9 + 0.5);
  }

  auto dp = make_vec<int>(60, 60);
  fill(dp, 0);
  int ans = 0;
  for(int i = 0; i < n; i++){
    int cnt2 = 0, cnt5 = 0, t = a[i];
    while(t % 2 == 0){
      t /= 2;
      cnt2++;
    }
    while(t % 5 == 0){
      t /= 5;
      cnt5++;
    }
    for(int j = 0; j < 60; j++){
      for(int k = 0; k < 60; k++){
        if(cnt2 + j >= 18 && cnt5 + k >= 18){
          ans += dp[j][k];
        }
      }
    }
    dp[cnt2][cnt5]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4920
// AOJ 2525: Change
// 2017.10.6 bal4u@uu

#include <stdio.h>

int main()
{
	int rd, rr;
    long long m, cd, cr, s, t;
 
	scanf("%lld%d%d%lld%lld", &m, &rd, &rr, &cd, &cr);
    s = cd * 100 / rd;
    if (cd * 100 % rd) s++;
    t = cr * 100 / rr;
    if (cr * 100 % rr) t++;
    if (m-s-t < 0) puts("-1");
	else printf("%lld\n", m-s-t);
    return 0;
}

Measured memory_bytes: 1820
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
    l=[]
    l1=[]
    li=list(map(int,input().split()))
    for i in range(n+1):
        if x-i not in li:
            l.append(x-i)
        if x+i not in li:
            l1.append(x+i)
    a=max(l)
    b=min(l1)
    if(abs(a-x)>abs(b-x)):
        print(b)
    else:
        print(a)

Measured memory_bytes: 9208
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int in_num[101];
int tmp_depth;
vector<int> G[101],GROUP[101];

int boss[101],height[101];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}


void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}

void init(){
	for(int i = 1; i <= 100; i++){
		boss[i] = i;
		height[i] = 0;
	}
}

void recursive(bool visited[101],int node_id,int depth,int group_id){
	tmp_depth = max(tmp_depth,depth);

	for(int i = 0; i < G[node_id].size(); i++){
		if(visited[G[node_id][i]])continue;

		bool next_visited[101];
		for(int k = 0; k < GROUP[group_id].size(); k++)next_visited[GROUP[group_id][k]] = visited[GROUP[group_id][k]];
		next_visited[G[node_id][i]] = true;
		recursive(next_visited,G[node_id][i],depth+1,group_id);
	}
}


void func(){

	for(int i = 1; i <= 100; i++){
		in_num[i] = 0;
		G[i].clear();
		GROUP[i].clear();
	}

	init();

	int from,to;
	for(int loop = 0; loop < N; loop++){
		scanf("%d %d",&from,&to);
		G[from].push_back(to);
		G[to].push_back(from);
		in_num[to]++;
		in_num[from]++;
		unite(from,to);
	}

	for(int i = 1; i <= 100; i++){
		if(in_num[i] == 0)continue;
		GROUP[get_boss(i)].push_back(i);
	}

	int max_depth = 1,min_in_num;
	bool visited[101];
	for(int i = 1; i <= 100; i++){
		if(GROUP[i].size() == 0 || GROUP[i].size() <= max_depth)continue;

		min_in_num = BIG_NUM;
		for(int k = 0; k < GROUP[i].size(); k++){
			min_in_num = min(min_in_num,in_num[GROUP[i][k]]);
		}

		for(int k = 0; k < GROUP[i].size(); k++){
			if(in_num[GROUP[i][k]] == min_in_num){
				for(int p = 0; p < GROUP[i].size(); p++)visited[GROUP[i][p]] = false;
				visited[GROUP[i][k]] = true;
				tmp_depth = 0;
				recursive(visited,GROUP[i][k],1,i);
				max_depth = max(max_depth,tmp_depth);
				if(max_depth == GROUP[i].size()){
					break;
				}
			}
		}
	}
	printf("%d\n",max_depth);
}


int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long; using ull = unsigned long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>;
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

signed main() {
    ll n1, n0, nm1, k;
    cin>>n1>>n0>>nm1>>k;
    if(k <= n1) {
        cout<<k;
        return 0;
    }
    k -= n1;
    if(k <= n0) {
        cout<<n1;
        return 0;
    }
    k -= n0;
    cout<< (n1-k);
    return 0;
}

Measured memory_bytes: 3624
INF = 10 ** 20

def update_state(state, newx):
  tmp = list(state)
  tmp[newx] = 1
  return tuple(tmp)

def get_co(x, y):
  dc = do = 0
  score = mp[y][x]
  if score < 0:
    dc = -score
  else:
    do = score
  return dc, do

def minimum_cost(x, y, state, ox, goal, dic, w, m):
  if (x, y, state, ox) in dic:
    return dic[(x, y, state, ox)]
  if y == goal:
    return 0
  if ox <= 1:
    return INF
  
  ret = INF
  
  if x >= 1:
    if state[x - 1] == 0:
      dc, do = get_co(x - 1, y)
      ret = min(ret, minimum_cost(x - 1, y, update_state(state, x - 1), min(ox + do - 1, m), goal, dic, w, m) + dc)
    else:
      ret = min(ret, minimum_cost(x - 1, y, state, ox - 1, goal, dic, w, m))
  
  if x < w - 1:
    if state[x + 1] == 0:
      dc, do = get_co(x + 1, y)
      ret = min(ret, minimum_cost(x + 1, y, update_state(state, x + 1), min(ox + do - 1, m), goal, dic, w, m) + dc)
    else:
      ret = min(ret, minimum_cost(x + 1, y, state, ox - 1, goal, dic, w, m))
 
 
  dc, do = get_co(x, y + 1)
  ret = min(ret, minimum_cost(x, y + 1, tuple((1 if i == x else 0 for i in range(w))), min(ox + do - 1, m), goal, dic, w, m) + dc)
  dic[(x, y, state, ox)] = ret
  return ret

while True:
  w, h = map(int, input().split())
  if w == 0:
    break
  f, m, o = map(int, input().split())
  mp = [list(map(int, input().split())) for _ in range(h)]
  if o <= 1:
    print("NA")
    continue
  dic = {}
  ans = INF
  for i in range(w):
    dc, do = get_co(i, 0)
    state = tuple(1 if i == j else 0 for j in range(w))
    ans = min(ans, minimum_cost(i, 0, state, min(o + do - 1, m), h - 1, dic, w, m) + dc)
  if ans > f:
    print("NA")
  else:
    print(ans)


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

using namespace std;

int N, K, R, S, P;

int64_t get_score(char c) {
  switch (c) {
    case 'r':
      return P;
    case 's':
      return R;
    case 'p':
      return S;
  }
  assert(false);
}

void solve() {
  string T;
  cin >> N >> K >> R >> S >> P >> T;

  vector<int64_t> won(N);
  vector<int64_t> not_won(N);

  for (int i = 0; i < K; ++i) {
    won[i] = get_score(T[i]);
  }

  for (int i = K; i < N; ++i) {
    auto prev_won = won[i - K];
    auto prev_not_won = not_won[i - K];
    not_won[i] = max(prev_won, prev_not_won);
    auto score = get_score(T[i]);
    won[i] = (T[i] == T[i - K] ? prev_not_won : not_won[i]) + score;
  }

  int64_t score = 0;
  for (int i = 0; i < K; ++i) {
    auto idx = N - 1 - i;
    score += max(not_won[idx], won[idx]);
  }
  cout << score << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = INF;
const int MAX = 1 << 25;
int depth[200005];
int ans[200005];
vector<int> g[200005];
void dfs(int u, int p = -1)
{
	for(auto v : g[u])
	{
		if(v == p)
			continue;
		depth[v] = depth[u] ^ 1;
		dfs(v , u);
	}
}
void put(vector<int> &a , int val)
{
	ans[a.back()] = val;
	a.pop_back();
}
void solve(vector<int> &y , int a , int b , int c)
{
	if(c){
	do {
		put(y , c * 3);
		c--;
	}while(c);
	}
	if(b){
	do {
		put(y , b * 3 - 1);
		b--;
	}while(b);
	}
	if(a) {
	do {
		put(y , a * 3 - 2);
		a--;
	}while(a);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i = 1; i < n; i++)
	{
		int u , v; 
		cin >> u >> v;
		u--;v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0);
	vector<int> A , B;
	for(int i = 0; i < n; i++)
	{
		if(depth[i] == 0)
			A.pb(i);
		else
			B.pb(i);
	}
	if(sz(A) > sz(B))
		swap(A , B);
	int x = sz(A) , y = sz(B);
	int a = (n + 2) / 3 , b = (n + 1) / 3 , c = n / 3;
	if(x <= c)
	{
		for(int i = 0; i < x; i++)
		{
			put(A , c * 3);
			c--;
		}
		solve(B , a , b , c);
		for(int i = 0; i < n; i++)
			cout << ans[i] << " ";
		return 0;
	}
	if(x >= a && y >= b)
	{
		do
		{
			put(A , a * 3 - 2);
			a--;
		}while(a);
		do
		{
			put(B , b * 3 - 1);
			b--;
		}while(b);
		if(A.size())
		{
			do
			{
				put(A , c * 3);
				c--;
			}while(A.size());
		}
		if(B.size())
		{
			do
			{
				put(B , c * 3);
				c--;
			}while(B.size());
		}
		for(int i = 0; i < n; i++)
			cout << ans[i] << " ";
		return 0;
	}
	
	assert(false);
}


Measured memory_bytes: 20084
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	set<int> s;
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		int x;
		cin>>x;
		s.insert(x);
	}
	
	cout<<YN(s.size() == N)<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c || b+c==a || c+a==b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


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

def ans(n):
    count = 0
    for i in range(1, n+1):
        if n%i == 0:
            count += 1
    if count == 8 and n%2 == 1:
        return True
    else:
        return False

ans(105)
res = 0
for i in range(n+1):
    if ans(i):
        res += 1
        
print(res)

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

int main(){
    int a,b;
    cin >> a >> b;

    int ans;
    if(a == 1) {
        if (b == 2){
            ans = 3;
        }
        if(b == 3){
            ans = 2;
        }
    }
    if(a == 2){
        if(b == 1){
            ans = 3;
        }
        if(b == 3){
            ans = 1;
        }
    }
    if(a == 3){
        if(b == 1){
            ans = 2;
        }
        if(b == 2){
            ans = 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256