akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll memo[111][111];
int n, a[111], b[111];
ll rec(int l, int r){
    if(memo[l][r] != 1e9) return memo[l][r];
    if(l == r) return memo[l][r] = 0;
    ll ret = 1e9;
    FOR(m, l, r){
      ret = min(ret, rec(l, m) + rec(m + 1, r) + a[l] * b[m] * b[r]);
    }
    return memo[l][r] = ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  FOR(i,0,n) cin >> a[i] >> b[i];
  FOR(i,0,111)FOR(j,0,111)memo[i][j]=1e9;
  cout << rec(0,n-1) << endl;
}


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

int main(){

  int n, m, ans;

  cin>>n>>m;
  ans=m;
  for(int i=0;i<n;i++){
    int a, b;
    cin>>a>>b;
    m=m+a-b;
    if(m<0){
      ans=0;
      break;
    }
    ans=max(ans, m);
  }

  cout<<ans<<endl;

  return 0;
}

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

int main(){
  int n,ans=0;
  string s;
  cin>>n>>s;
  for(int a=0;a<s.size();a++){
    int Z[s.size()-a];
    Z[0]=s.size()-a;
    int i=1,j=0;
    while(i+a<s.size()){
      while(i+j+a<s.size() && s[a+j]==s[a+i+j])j++;
      Z[i]=j;
      ans=max(ans,min(i,Z[i]));
      if(j==0){
        i++;
        continue;
      }
      int k=1;
      while(k<j && k+Z[k]<j){
        Z[i+k]=Z[k];
        ans=max(ans,min(i+k,Z[i+k]));
        k++;
      }
      i += k;
      j -= k;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    bool ans = true;
    //一文字のときに注意
    if(S.size() == 1 or S.size()%2 != 0)ans = false;

    for(int i=0;i<N/2;i++){
        if(S[i] != S[i+N/2]){
            ans = false;
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
D = [[] for i in range(N)]
for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく
ans = [None]*M
for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入
print(*ans, sep = '\n') 
#普通にprint(ans)とするとリストが出力される
#print(*ans)とすると，リストの要素がスペース区切りで出力される
#printのオプションsepで，文字の区切りをスペース出なく，改行に指定

Measured memory_bytes: 37480
$numAry = Array.new()

def readNum()
    # Count
    str = STDIN.gets.split()
    
    # Read 
    str.each{|val|
        $numAry.push(val.to_i)
    }
    
    $numAry.sort!
end

# Main
readNum()
sum = $numAry[0] + $numAry[1]

puts sum

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    ll asum=0, bsum=0;
    rep(i,n) asum+=a[i];
    rep(i,n) bsum+=b[i];
    if (asum<bsum){
        cout<<"-1\n";
        return 0;
    }
    vll c;
    rep(i,n)if(a[i]>=b[i]) c.pb(a[i]-b[i]);
    sort(all(c));
    int m=c.size();
    int l=-1, r=n;
    while(r-l>1){
        int mid = (l+r)/2;
        if (mid<n-m){
            l=mid;
        }else{
            ll sum=asum-bsum;
            rep(i,n-mid) sum-=c[i];
            if (sum<0) l=mid;
            else r=mid;
        }
    }
    cout<<r<<"\n";
    return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){
    string s,t,u;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    cin >> u;
    if(s == u) a--;
    else if(t == u) b--;
    cout << a << ' ' << b << endl;

}


Measured memory_bytes: 256
s=input()
t=input()
s=list(s)
t=list(t)

size = len(t)
ms = []
for i in range(len(s)-size+1):
    # print(s[i:i+size])
    m = sum([a==b for a,b in zip(s[i:i+size], t)])
    ms.append(m)

print(size - max(ms))

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll a,b;
    cin>>a>>b;
    cout<<6-a-b,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		boolean[] arr = new boolean[101];
		for (int i = 1; i <= 9; i++) {
			for (int j = i; j <= 9; j++) {
				arr[i * j] = true;
			}
		}
		if (arr[scanner.nextInt()]) {
			System.out.println("Yes");
		} else
			System.out.println("No");
	}
}

Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main() {
   string S; cin >> S;
   for (int i = 0; i < 3; i++)
   {
        if (S[i] == S[i + 1]) {
            printf("%s\n", "Bad");
            return 0;
        }
   }
    printf("%s\n", "Good");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a*b)%2==0)
    ou("No");
  else ou("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/
int weight[100],value[100];

int dp[100][100001];

using namespace std;
int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;tc++){
        int n,w;
        cin>>n>>w;
        for(int i=0;i<n;i++){
            cin>>weight[i]>>value[i];
        }
        for(int i=0;i<100;i++){
            for(int j=0;j<=100000;j++){
                dp[i][j]=INT_MAX;
            }
        }
        dp[0][0]=0;
        dp[0][value[0]]=weight[0];
        for(int i=1;i<n;i++){
            dp[i][0]=0;
            for(int j=1;j<=100000;j++){
                dp[i][j]=dp[i-1][j];
                if(j>=value[i]){
                    dp[i][j]=min(dp[i][j],weight[i]+dp[i-1][j-value[i]]);
                }
            }
        }
        int ans;
        for(int i=100000;i>=0;i--){
            if(dp[n-1][i]<=w){
                ans=i;
                break;
            }
        }
        cout<<ans<<'\n';

    }
    
    
    
    
    
    return 0;
    
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int x; cin>>x;
	for(int n = x; ; n++){
		bool flg = true;
		for(int i = 2; i*i <= n; i++){
			if(n%i == 0){
				flg = false;
				break;
			}
		}
		if(flg){
			cout<<n<<endl;
			exit(0);
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <cassert>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>

using Point = std::complex<double>;
using Line = std::vector<Point>;

Point get_ipoint(const Line &l1, const Line &l2) {
  double x1=l1[0].real(), x2=l1[1].real();
  double x3=l2[0].real(), x4=l2[1].real();
  double y1=l1[0].imag(), y2=l1[1].imag();
  double y3=l2[0].imag(), y4=l2[1].imag();

  double x=(y4-y3)*(x4-x1)-(x4-x3)*(y4-y1);
  double d=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1);

  return Point(x1, y1) + (x/d)*Point(x2-x1, y2-y1);
}

double dot_prod(const Point &p1, const Point &p2) {
  return (conj(p1)*p2).real();
}

class PointOrLine {
  bool is_line() const {
    return points.size() == 2;
  }

public:
  std::vector<Point> points;

  PointOrLine(double x, double y): points{Point(x, y)} {}
  PointOrLine(Point z): points{z} {}
  PointOrLine(Point z, Point w): points{z, w} {}

  PointOrLine operator |(const PointOrLine &oth) const {
    if (is_line() && oth.is_line()) {
      return get_ipoint(points, oth.points);
    } else if (is_line()) {
      Point p1=points[0], p2=points[1];
      Point p=oth.points[0];
      Point e(p2.real()-p1.real(), p2.imag()-p1.imag());
      e /= abs(e);

      double r=dot_prod(p-p1, e);
      Point h=p1+r*e;
      return p+2.0*(h-p);
    } else if (oth.is_line()) {
      return oth | *this;
    } else {
      return PointOrLine(points[0], oth.points[0]);
    }
  }

  Point point() const {
    assert(!is_line());
    return points[0];
  }
};

PointOrLine parse(const std::string &s, size_t &i, size_t preced=0) {
  if (preced == 1) {
    if (s[i] == '(') {
      PointOrLine res=parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (isdigit(s[i]) || s[i] == '-') {
      bool xneg=false, yneg=false;
      if (s[i] == '-') {
        xneg = true;
        ++i;
      }
      double x=s[i]-'0';
      while (s[++i] != ',') x = x*10+s[i]-'0';
      if (xneg) x = -x;

      ++i;
      if (s[i] == '-') {
        yneg = true;
        ++i;
      }

      double y=s[i]-'0';
      while (s[++i] != ')') y = y*10+s[i]-'0';
      if (yneg) y = -y;

      return PointOrLine(x, y);
    }
    assert(false);
  }

  PointOrLine res=parse(s, i, 1);
  while (i < s.length()) {
    char op=s[i];
    if (op != '@') break;
    PointOrLine tmp=parse(s, ++i, 1);
    res = res|tmp;
  }
  return res;
}

int testcase_ends() {
  char buf[128];
  scanf("%s", buf);
  std::string s=buf;
  if (s == "#") return 1;
  size_t i=0;
  Point point=parse(s, i).point();
  printf("%.12f %.12f\n", point.real(), point.imag());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2760
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll r, D, x;
    cin >> r >> D >> x;
    rep(i,10)
    {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3128
// Date: 2020-03-07

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

vector<char> pre, suf;
int main() {
    FIO;
    string s;
    cin >> s;
    int rev = 0;
    int q; cin >> q;
    while(q--) {
        int t; cin >> t;
        if(t == 1) rev ^= 1;
        else {
            int f; char c;
            cin >> f >> c;
            if(f == 1) {
                if(rev) suf.pb(c);
                else pre.pb(c);
            } else {
                if(rev) pre.pb(c);
                else suf.pb(c);
            }
        }
    }
    string tp;
    for(int i = pre.size()-1; i >= 0; --i) tp += pre[i];
    s = tp + s;
    for(auto c : suf) s += c;
    if(rev) reverse(all(s));
    cout << s;

    return 0;
}

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

using namespace std;

int main(){
  string s, ans;
  cin >> s;
  int N = s.size();
  ans = "";
  for(int i = 0; i < N; i++){
    if( s.at(i) != 'B'){
      ans = ans + s.at(i);
    }
    else if(ans.size() > 1 && s.at(i) == 'B'){
      int a = ans.size();
      string X = "";
      for(int j=0; j<a-1; j++){
        X = X + ans.at(j);
      }
      ans = X;
    }
    else{
      ans = "";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  ll l,r;
  cin >> l >> r;
  r=min(r,l+2020);
  ll ans=2020;
  for(ll i=l;i<r;i++) {
    for(ll j=i+1;j<=r;j++) {
      if((i*j)%2019==0) {
        ans=0;
        break;
      }
      ans=min(ans,(i*j)%2019);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

int main()
{
int n,max=0,sum=0;
scanf("%d",&n);
int a[2][n];
for(int i=0;i<2;i++)
for(int j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(int i=0;i<n;i++)
{
sum=0;
for(int j=0;j<=i;j++)
sum+=a[0][j];
for(int k=i;k<n;k++)
sum+=a[1][k];
if(sum>max)
max=sum;
}
printf("%d",max);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using P = pair<int,int>;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<vector<int>> f(N);
  for(int i=0; i<M; i++){
    cin >> A.at(i) >> B.at(i);
    int a = A.at(i)-1;
    int b = B.at(i)-1;
    f[a].push_back(b);
    f[b].push_back(a);
  }
  int ans = 0;
  vector<bool> seen(N,false);
  for(int i=0; i<N; i++){
    if(seen.at(i)) continue;
    seen.at(i) = true;
    int num = 1;
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      int j = q.front();
      q.pop();
      for(auto v : f[j]){
        if(seen.at(v)) continue;
        seen.at(v) = true;
        q.push(v);
        num++;
      }
    }
    ans = max(ans, num);
  }  
  cout << ans;
  return 0;
}

Measured memory_bytes: 16392
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int r, c;
	int all = 0;
	int num[101][101];
	int x[100] = { 0 }, y[100] = { 0 };
	cin >> r >> c;
	for (int i = 1; i <= r; i++){
		for (int j = 1; j <= c; j++){
			cin >> num[i][j];
			all += num[i][j];
		}
	}
	for (int k = 1; k <= r; k++){
		for (int l = 1; l <= c; l++){
			cout << num[k][l] << " ";
			x[k] += num[k][l];
		}
		cout << x[k] << endl;
	}
	for (int n = 1; n <= r; n++){
		for (int m = 1; m <= c; m++){
			y[m] += num[n][m];
		}
	}
	for (int o = 1; o < c + 1;o++){
		cout << y[o] << " ";
	}
	cout << all << endl;
	return 0;
	}


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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(a);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<long long> vi;
const int mod=1e9+7;

int main(){
	int n,nw;cin>>n>>nw;
	vi w(n+1),v(n+1);
	trv(i,1,n+1) cin>>w[i]>>v[i];
	vector<vi> dp(n+1,vi(nw+1));
	trv(i,1,n+1){
		trv(j,1,nw+1){
			dp[i][j] = dp[i-1][j];
			if(j-w[i]>=0){
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
		}
	}
	cout<<dp[n][nw];
}


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

int val(string ca){
    return (int)ca.at(1);
}

bool isStable(vector<string> in, vector<string> out, int n){
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = 0; k < n; k++){
                for(int l = k + 1; l < n; l++){
                    if(val(in.at(i)) == val(in.at(j)) && in.at(i) == out.at(l) && in.at(j) == out.at(k)) return false;
                }
            }
        }
    }
    return true;
} 

int main(){
   int n;
   int minj = 0;
   bool isSelectionSortStable = true;
   cin >> n;
   vector<string> a(n);
   for(int i = 0; i < n; i++) cin >> a.at(i);
   vector<string> b(n);
   b = a;
   vector<string> tmp_vector(n);
   tmp_vector = a;
   for(int i = 0; i < n; i++){
       for(int j = n-1; j > i; j--){
           if(val(a.at(j)) < val(a.at(j-1))){
               swap(a.at(j),a.at(j-1));
           }
       }
   }

   for(int i = 0; i < n; i++){
       minj = i;
       for(int j = i; j < n; j++){
           if(val(b.at(j)) < val(b.at(minj))){
               minj = j;
           }
       }
       swap(b.at(i),b.at(minj));
   }

   for(int i = 0; i < n; i++){
       if(i > 0) cout << " ";
       cout << a.at(i);
   }
   cout << endl << "Stable" << endl;

   for(int i = 0; i < n; i++){
       if(i > 0) cout << " ";
       cout << b.at(i);
   }
   if(isStable(tmp_vector,b,n)) cout << endl << "Stable" << endl;
   else cout << endl << "Not stable" << endl;

}


Measured memory_bytes: 3236
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <boost/math/common_factor.hpp>
#include <algorithm>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include<chrono>
 
using namespace std;
//using namespace std::chrono;
 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vl int64_t

int main()
{
     ll a,b;
     cin>>a>>b;
     ll prod=a*b;
     //ll hcf=_gcd(a,b);
     //ll final=prod/hcf;
     cout<<boost::math::lcm(a,b);
     
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, 3 * N);

	sort(all(a));
	reverse(all(a));

	int ret = 0;
	rep(i, N) {
		ret += a[2 * i + 1];
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 2688
from sys import *
from math import *
from collections import deque
input = stdin.readline
lmi = lambda: list(map(float, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

s = si()

def p(x):
    return x == x[::-1]

if p(s) and p(s[:(len(s)-1)//2]) and p(s[(len(s)+3)//2-1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 28396
#include<iostream>
int main(){
	int n;
	int a[100];
	int key;
	int i,j,k;

	std::cin >> n;
	for(i=0;i<n;i++){
		std::cin >> a[i];
	}
	for(i=0;i<n;i++){
		if(i>0){
			std::cout << " ";
		}
		std::cout << a[i];
	}
	std::cout << "\n";

	for(i=1;i<n;i++){
		key = a[i];
		j=i-1;
		while(j>=0 && a[j] > key){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = key;
		for(k=0;k<n;k++){
			if(k>0){
				std::cout << " ";
			}
			std::cout << a[k];
		}
		std::cout << "\n";
	}
	return (0);
}

Measured memory_bytes: 3080
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;



int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vi a(x), b(y), c(z);
    rep(i, x) {
        cin >> a[i];
    }
    rep(i, y) {
        cin >> b[i];
    }
    rep(i, z) {
        cin >> c[i];
    }

    sort(rall(a));
    sort(rall(b));
    sort(rall(c));
    priority_queue<tuple<ll, int, int, int> > Q;
    Q.push(make_tuple(a[0]+b[0]+c[0], 0, 0, 0)); 
    vector<vector<vector<bool> > > check(x, vector<vector<bool> >(y, vector<bool>(z, false)));
    check[0][0][0] = true;

    rep(i, k) {
        auto qq = Q.top();
        Q.pop();
        ll m_;
        int a_, b_, c_;
        tie(m_, a_, b_, c_) = qq;

        cout << m_ << endl;
        if(a_ != x-1 && !check[a_+1][b_][c_]) {
            check[a_+1][b_][c_] = true;
            Q.push(make_tuple(a[a_+1]+b[b_]+c[c_], a_+1, b_, c_));
        }
        if(b_ != y-1 && !check[a_][b_+1][c_]) {
            check[a_][b_+1][c_] = true;
            Q.push(make_tuple(a[a_]+b[b_+1]+c[c_], a_, b_+1, c_));
        }
        if(c_ != z-1 && !check[a_][b_][c_+1]) {
            check[a_][b_][c_+1] = true;
            Q.push(make_tuple(a[a_]+b[b_]+c[c_+1], a_, b_, c_+1));
        }
    }
}

Measured memory_bytes: 180352
import java.util.Scanner;

public class Main {
	/*
	*1 軒のホテルがあります。 このホテルの宿泊費は、次のようになっています。
	*
	*最初の K 泊までは、1 泊あたり X 円
	*K+1 泊目以降は、1 泊あたり Y 円
	*高橋君は、このホテルに N 泊連続で宿泊することにしました。
	* 高橋君の宿泊費は合計で何円になるか求めてください。
	*/
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int X=sc.nextInt();
		int Y=sc.nextInt();
		int result=0;
		for(int i=0;i<N;i++){
			if(i<K){
				result=result+X;
			}else{
				result=result+Y;
			}
		}
		System.out.println(result);
	}

}

Measured memory_bytes: 9684
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

mint f(int n){ 
  if(n == 0)return 1;
  mint x = f(n / 2); 
  x *= x; 
  if(n % 2 == 1)x *= 2;
  return x;
}

mint choose(int n, int a){
  mint x = 1, y = 1;
  for(int i = 0; i < a; ++i){
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

mint d[100100];
mint d2[100100];

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

  for(int i = 1; i <= k; ++i){
  	mint tmp = k / i;
  	d2[i] = tmp.pow(n);
  }


  for(int i = k; i >= 1; --i){
  	d[i] = d2[i];
  	for(int j = 2 * i; j <= k; j += i){
  		d[i] -= d[j];
  	}
  }

  mint ans = 0;
  for(int i = 1; i <= k; ++i){
  	ans += d[i] * i;
  }

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


Measured memory_bytes: 5212
program allgreen
implicit none
integer :: D, G, I, J, K
integer :: co, su
integer, allocatable, dimension(:) :: P, PP, C, counter, sum

read(*,*) D, G

allocate(P(D))
allocate(PP(D))
allocate(C(D))
allocate(counter(2**D))
allocate(sum(2**D))

do I = 1, D
read(*,*) P(I), C(I)
end do

do I = 1, 2**D
counter(I) = 10000
sum(I) = 10000
end do
do I = 1, 2**D
su = 0
co = 0
 do J = 1, D
 PP(J) = P(J)
 end do
 do J = 1, D
  if (btest(I-1,J-1)) then
  su = su + PP(J)*100*J + C(J)
  co = co + PP(J)
  PP(J) = 0
  end if
 end do
! write(*,*) su, co
 if (su>=G) then
 sum(I) = su
 counter(I) = co
 cycle
 end if
 do J = D, 1, -1
  if (PP(J)/=0) then
   do K = 1, (PP(J)-1)
   su = su + 100*J
   co = co + 1
!   write(*,*) su, co
    if (su>=G) then
    sum(I) = su
    counter(I) = co
    exit
    end if
   end do
  end if
 if (su>=G) exit
 end do
end do

write(*,*) minval(counter)

end program

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

A_c = Counter(A)

ans = 0
for k, v in zip(A_c.keys(), A_c.values()):
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)


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

#define int long long
int N , X , arr[100003] , mn[100003];

signed main(){
	cin >> N >> X;
	for(int i = 0 ; i < N ; ++i){cin >> arr[i]; arr[i + N] = arr[i];}
	int ans = 1e18; memset(mn , 0x3f , sizeof(mn));
	for(int i = 0 ; i <= N ; ++i){
		for(int j = 0 ; j < N ; ++j)
			mn[(i + j) % N] = min(mn[(i + j) % N] , arr[j]);
		int sum = i * X; for(int j = 0 ; j < N ; ++j) sum += mn[j];
		ans = min(ans , sum);
	}
	cout << ans; return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) = ripPro0408b()

fun ripPro0408b() {
    val n = readLine()!!.toInt()
    val vList = readLine()!!.split(' ').map { it.toDouble() }

    val answer = vList.sorted().reduce { acc, i -> (acc + i) / 2 }

    println(answer)
}


Measured memory_bytes: 38036
# S = input()
# print('Heisei' if S <= '2019/04/30' else 'TBD')

n,m,c=map(int,input().split())
b=list(map(int,input().split()))
e = [[int(i) for i in input().split()] for i in range(n)]

total=0
count=0


for j in range(0,n):
	total=0
	for k in range(0,m):
		total+=e[j][k]*b[k]
	if total+c>0:
		count+=1

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  vector<int> A(26,0);
  int mzint=0;
  for(int i=0;i<D;i++){
    int mzi=mzint,mzin=0,k;
    for(int j=0;j<26;j++)
      mzi-=(i+1-A[j])*c[j];
    for(int j=0;j<26;j++){
      int l=mzi+s[i][j]-(i+1-A[j])*c[j];
      if(l>mzin){
        k=j;
        mzin=l;
      }
    }
    A[k]=i+1;
    mzint=mzin;
    t[i]=k+1;
  }
  int M=4000000,ans=mzint;
  while(M--){
    vector<pair<int,int>> AAA={make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26)};
    vector<int> BBB={t[AAA[0].first],t[AAA[1].first],t[AAA[2].first]};
    int ans2=ans;
    for(int aaa=0;aaa<3;aaa++){
    int d=AAA[aaa].first,q=AAA[aaa].second;
    ans+=s[d][q]-s[d][t[d]-1];
    int mae=-1,ato=D;
    for(int i=d-1;i>=0;i--){
      if(t[i]==t[d]){
        mae=i;
        break;
      }
    }
    for(int i=d+1;i<D;i++){
      if(t[i]==t[d]){
        ato=i;
        break;
      }
    }
    ans-=(ato-d)*(d-mae)*c[t[d]-1];
    mae=-1,ato=D;
    for(int i=d;i>=0;i--){
      if(t[i]==q+1){
        mae=i;
        break;
      }
    }
    for(int i=d;i<D;i++){
      if(t[i]==q+1){
        ato=i;
        break;
      }
    }
    ans+=(ato-d)*(d-mae)*c[q];
    t[d]=q+1;
    }
    if(ans2>ans){
      ans=ans2;
      t[AAA[0].first]=BBB[0];
      t[AAA[1].first]=BBB[1];
      t[AAA[2].first]=BBB[2];
    }
  }
  for(int i:t)
    cout<<i<<endl;
}

Measured memory_bytes: 3704
n=int(input())
tree=[[]for _ in range(n+1)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])
d=[-1]*(n+1)
d[1]=0
q=[1]
while q:
    now=q.pop()
    for n_i,n_l in tree[now]:
        if d[n_i]==-1:
            d[n_i]=d[now]+n_l
            q.append(n_i)
for l in d[1:]:
    print(l%2)

Measured memory_bytes: 49836
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a=0,b=0;
    for(int i=0;i<n;i++) {
        string s,p;
        cin >> s >> p;
        if(strcmp(s.c_str(),p.c_str()) > 0)
            a+=3;
        else if(strcmp(s.c_str(),p.c_str()) == 0) {
            a++;
            b++;
        }
        else
            b+=3;
    }
    cout << a << " " << b << endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << setprecision(15);
    auto unit_r = 180.0 / M_PI;

    int64_t n;
    string s;
    
    cin >> n;
    cin >> s;

    int nn[n];
    for (ll i = 0; i < n; ++i) {
        nn[i] = s[i] - '0';
    }

    vector<unordered_set<int>> s1(n);
    vector<unordered_set<int>> s2(n);
    unordered_set<int> s3;
    
    for (ll i = 0; i < n; ++i) {
        if (i > 0) {
            for (auto iter = s1[i-1].begin(); iter != s1[i-1].end(); ++iter) {
                s1[i].insert(*iter);
            }
        }
        s1[i].insert(nn[i] * 100 + 1000);
    }
    // cerr << "iter 1" << endl;
    // for (ll i = 0; i < n; ++i) {
    //     cerr << "s1[" << i << "]: ";
    //     for (auto iter = s1[i].begin(); iter != s1[i].end(); ++iter) {
    //         cerr << *iter << ",";
    //     }
    //     cerr << endl;
    // }
    for (ll i = 1; i < n; ++i) {
        if (i > 1) {
            for (auto iter = s2[i-1].begin(); iter != s2[i-1].end(); ++iter) {
                s2[i].insert(*iter);
            }
        }
        for (auto iter = s1[i-1].begin(); iter != s1[i-1].end(); ++iter) {
            s2[i].insert(*iter + 10*nn[i]);
        }
    }
    //cerr << "iter 2" << endl;
    //for (ll i = 0; i < n; ++i) {
    //    cerr << "s2[" << i << "]: ";
    //    for (auto iter = s2[i].begin(); iter != s2[i].end(); ++iter) {
    //        cerr << *iter << ",";
    //    }
    //    cerr << endl;
    //}
    //cerr << "iter 3" << endl;
    for (ll i = 2; i < n; ++i) {
        for (auto iter = s2[i-1].begin(); iter != s2[i-1].end(); ++iter) {
            s3.insert(*iter + nn[i]);
        }
    }
    cout << s3.size() << endl;
}




Measured memory_bytes: 156928
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#define ll long long 
#define pb push_back
#include<string>
#include<cctype>
using namespace std;
	
int main()
{
	 ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll a[100001];
	int count=0;
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	if(a[i]==0)
	count++;
}
if(count>=1)
{
cout<<0<<endl;
return 0;	
}
	ll sum=1;
for(int i=0;i<n;i++){
if(a[i]<=1000000000000000000/sum){
sum*=a[i];
}
else{
cout<<-1<<endl;
return 0;
}
}
	cout<<sum<<endl;


}


Measured memory_bytes: 4392
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = input()
    li = map(int, raw_input().split())

    print [li[li[i - 1] - 1] == i for i in range(1, n + 1)].count(True) / 2

if __name__ == '__main__':
    main()


Measured memory_bytes: 11328
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= 1

used = [False]*N
path = []
now = 0
while not used[now]:
    path.append(now)
    used[now] = True
    now = A[now]
# print(now)
# print(path)

# ループがpath(0-indexed)に格納されてループの始点がnow
start_idx = path.index(now)
# print(start_idx)
loop_len = len(path) - start_idx
if K < start_idx:
    print(path[K] + 1)
else:
    print(path[(K-start_idx)%loop_len + start_idx] + 1)

Measured memory_bytes: 95008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,n;
    set<int>s;
    cin>>n;
    int m=n;
    while(n--)
    {
        cin>>a;
        s.insert(a);
    }
    int l=s.size();
    if(l==m)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct edge { int to,nxt; } e[N<<1];
int tot=1,h[N];
void adde(int u,int v) {
    e[++tot]=(edge){v,h[u]};h[u]=tot;
    e[++tot]=(edge){u,h[v]};h[v]=tot;
}
int n,ans=0,f[N][30];
void dfs(int u,int fa) {
    for(int i=h[u];i;i=e[i].nxt) {
        int v=e[i].to; if(v==fa) continue;
        dfs(v,u);
        for(int j=20;j>=0;j--) f[u][j]+=f[v][j];
    }
    int p=0;
    for(int i=20;i>=0;i--)
        if(f[u][i]>1) { p=i+1;break; }
    while(f[u][p]) p++;
    f[u][p]++;
    for(int j=0;j<p;j++) f[u][j]=0;
    ans=max(ans,p);
}
int main() {
    cin>>n;
    for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),adde(u,v);
    dfs(1,0);printf("%d\n",ans);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

namespace std {
template <typename A, typename B> struct hash<pair<A, B>> {
  size_t operator()(const pair<A, B> &p) const {
    const static size_t rand_seed = random_device()() + 0x9e3779b9;
    size_t seed = rand_seed;
    seed ^= hash<A>()(p.first) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    seed ^= hash<B>()(p.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    return seed;
  }
};
}

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.clear(), graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

void dfs(Graph &g, int v, int p, int prev_col, unordered_map<pair<int, int>, int> &cmap) {
  int col = 0;
  for (const auto &e : g[v]) {
    if (e.dst == p) continue;
    ++col;
    if (col == prev_col) ++col;
    cmap[{ v, e.dst }] = col;
    dfs(g, e.dst, v, col, cmap);
  }
}

void bfs(Graph &g, unordered_map<pair<int, int>, int> &cmap) {
  queue<tuple<int, int, int>> que;
  que.push(make_tuple(0, -1, 0));
  while (!que.empty()) {
    int v = get<0>(que.front()), p = get<1>(que.front()), pc = get<2>(que.front());
    que.pop();
    int col = 1;
    for (const auto &e : g[v]) {
      if (e.dst == p) continue;
      if (col == pc) ++col;
      cmap[{ v, e.dst }] = col;
      que.push(make_tuple(e.dst, v, col));
      ++col;
    }
  }
}

Graph graph;
int main(void) {
  int n;
  cin >> n;
  Edges edges(n - 1);
  rep (i, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i] = {--a, --b, 0};
  }
  edges_to_graph(graph, edges, n, false);
  int maxi = 0;
  rep (i, n) maxi = max(maxi, (int)graph[i].size());
  unordered_map<pair<int, int>, int> cmap;
  // dfs(graph, 0, -1, 0, cmap);
  bfs(graph, cmap);
  cout << maxi << "\n";
  rep (i, n - 1) cout << cmap[{ edges[i].src, edges[i].dst }] << "\n";
  return 0;
}

Measured memory_bytes: 13988
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines.shift()),
      _splitNum2 = _slicedToArray(_splitNum, 1),
      D = _splitNum2[0];

  switch (D) {
    case 25:
      console.log('Christmas');
      return;

    case 24:
      console.log('Christmas Eve');
      return;

    case 23:
      console.log('Christmas Eve Eve');
      return;

    case 22:
      console.log('Christmas Eve Eve Eve');
      return;
  }
}

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

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 22964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int X;
    cin >> X;
    rep(i,pow(10,4)){
        bool prime = true;
        int x = X + i;
        repX(j,pow(x,0.5),2){
            if(x%j==0){
                prime = false;
                break;
            }
        }
        if(prime){
            cout << X+i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
typedef pair<int,int> P;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
	in >> p.first >> p.second;
	return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD = 1000000007;
	string s,t;
	cin>>s>>t;
	if(t.substr(0,s.size())==s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define fab(i,a,b) for(long int i = a ; i < b; i++)
#define testcase ll tt; cin >> tt; while(tt--)
#define vll vector<ll>
#define ll long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F first
#define S second
using namespace std;


#include <bits/stdc++.h> 
  
using namespace std; 
  
vector<pair<ll,ll>> dp;

pair<ll,ll> helper(string s, int i){
    if(i>=s.size()) return {0,1};
    if(dp[i].F != -1) return dp[i];
    ll n_ways = 0;
    ll ans = 0;
    for(int k = i+1 ; k <= s.size() ; k++){
        auto add = helper(s,k);
        n_ways += add.S;
        ans += stol(s.substr(i,k-i))*add.S + add.first;
    }
    return {ans,n_ways};
} 
 
int main(){
    string s;
    cin>>s;
    dp.resize(s.size(),{-1,-1});
    cout<<helper(s,0).F;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b;

    if(a > b)
    {
        c = a;
        a--;
    }
    else
    {
        c = b;
        b--;
    }

    if(a > b)
    {
        c += a;
        a--;
    }
    else
    {
        c += b;
        b--;
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;
	if (x < 1 || x >100 || y < 1 || y >100) {
		cout << "error" << endl;
		return 0;
	}
	for (int i = 0; i <= x; i++)
	{
		if (i * 2 + (x - i) * 4 == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3648