akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

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

    vector<int> a(n-1);
    rep(i,n-1) cin >> a[i];
    rep(i,n-1) a[i]--;

    vector<int> count(n,0);

    rep(i,n-1){
        count[a[i]]++;
    }

    rep(i,n){
        cout << count[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4844
#include<stdio.h>
#define n 5

int main(void)
{
	int a[n],i,j,t;

	for(i=0;i<n;i++)
	  scanf("%d",&a[i]);

	for( i = 1; i < n; ++i )
	{
		t = a[i];
		for( j = i; j > 0 && a[j-1] > t; --j )
		{
			a[j] = a[j-1];
		}
		a[j] = t;
	}
	printf("%d",a[n-1]);
	for(i=n-2;i>-1;i--)
		printf(" %d",a[i]);
	printf("\n");
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N,M; cin>>N>>M;
  ll x = 0;
  REP(count,M){
    ll a; cin>>a;
    x += a;
  }
  ll ans = N-x;
  if(ans<0){ ans = -1; }
  cout << ans << "\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int D;
vi c(26);
vvi s;

void calc(vi &t) {
  vi last(26,-1);
  ll res=0;
  rep(i,D) {
    last[t[i]]=i;
    res += s[i][t[i]];
    rep(j,26) {
      res -= c[j]*(i-last[j]);
    }
    cout << res << endl;
  }
}
  
int main() {
  cin >> D;
  rep(i,26) {
    cin >> c[i];
  }
  s.assign(D,vi(26));
  rep(i,D) {
    rep(j,26) {
      cin >> s[i][j];
    }
  }
  vi t(D);
  rep(i,D) {
    cin >> t[i];
    t[i]--;
  }
  
  calc(t);
  return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<math.h>

char primes[1000010];
int b[1000010];
int main(){
  int price[30],m,n,i,bud,j,max,count;
  n=sqrt(1000000);
  for(i=2;i<n;i++){
    if(primes[i]==0){
      m=1000000/i+1;
      for(j=2;j<m;j++) primes[j*i]=1;
    }
  }
  count=0;
  do{
    scanf("%d %d",&n,&bud);
    if(!n&&!bud) break;
    count++;
    for(i=0,max=0;i<n;i++){
      scanf("%d",price+i);
      if(max<price[i]) max=price[i];
    }
    for(i=0,b[0]=count;i<bud;i++){
      if(b[i]==count){
	for(j=0;j<n;j++){
	  if(price[j]+i<=bud)
	    b[i+price[j]]=count;
	}
      }
    }
    b[0]=0;
    for(i=bud;i>-1;i--){
      if(!primes[i]&&b[i]==count){
	printf("%d\n",i);
	break;
      }
    }
    if(i==-1){
      printf("NA\n");
    }
  }while(1);
  return 0;
}

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

using namespace std;
typedef long long ll;

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

  vector<int> x(n), y(n);
  vector<int> xary, yary;

  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xary.push_back(x[i]);
    yary.push_back(y[i]);
  }

  sort(xary.begin(), xary.end());
  sort(yary.begin(), yary.end());

  ll ans = 1LL * (xary[n - 1] - xary[0]) * (yary[n - 1] - yary[0]);

  for (int xi = 0; xi < n; xi++) {
    for (int xj = xi + 1; xj < n; xj++) {
      for (int yi = 0; yi < n; yi++) {
        for (int yj = yi + 1; yj < n; yj++) {
          int num = 0;
          ll lx = xary[xi], rx = xary[xj];
          ll by = yary[yi], uy = yary[yj];

          for (int i = 0; i < n; i++) {
            if (lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy) {
              num++;
            }
          }

          if (num >= k) {
            ans = min(ans, 1LL * (rx - lx) * (uy - by));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, k;
	cin >> n >> k;
	int h[n];
	for(int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int dp[n];
	memset(dp, 63, sizeof(dp));
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 1; j <= k; j++) {
			if(i + j < n) {
				dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
			}
		}
	}
	cout << dp[n - 1];

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    sort(a.rbegin(), a.rend());
    priority_queue<pair<ll, ll> > pq;
    pq.push(make_pair(a[0], a[0]));
    for (int i = 1; i < n; i++) {
        pair<ll, ll> p = pq.top();
        pq.pop();
        ans += p.first;
        pq.push(make_pair(a[i], p.first));
        pq.push(make_pair(a[i], p.second));
    }
    cout << ans << endl;
}


Measured memory_bytes: 9020
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

int main() {
  int N;
  cin >> N;
  string s;
  unordered_map<string, bool> map;
  int e = 0;
  while (N--) {
    cin >> s;
    if (!map.count(s)) {
      map[s] = true;
      ++e;
    }
  }

  cout << e << "\n";
}

Measured memory_bytes: 17156
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll MOD = 1e9+7;
 
int main(){
 
    int A,B,Q;
    cin >> A >> B >> Q;
 
    vector<ll> s(A+2,0);
    vector<ll> t(B+2,0);
 
    s[0] = -30000000001;
    t[0] = -30000000001;
    s[A+1] = 30000000000;
    t[B+1] = 30000000000;
 
    rep(i,0,A){
        cin >> s[i+1];
    }
    rep(i,0,B){
        cin >> t[i+1];
    }
 
    ll x;
    int si,ti;
    ll ls,lt,rs,rt;
    rep(loop,0,Q){
 
        cin >> x;
        si = distance(s.begin(),lower_bound(s.begin(),s.end(),x));
        ti = distance(t.begin(),lower_bound(t.begin(),t.end(),x));
        ls = x - s[si-1];
        lt = x - t[ti-1];
        rs = s[si]-x;
        rt = t[ti]-x;
 
        cout << min({ max(ls,lt) , max(rs,rt) , min(ls,rt) * 2 + max(ls,rt) , min(lt,rs) * 2 + max(lt,rs) }) << endl;
    }
 
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int INF = 1e12 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int ans = INF;
    for(int i = 1;i*i<=n;i++){
    	if(n % i == 0){
    		int temp = abs(1 - i) + abs(1 - (n/i));
    		ans = min(ans, temp);
    	}
    }    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
h_li = gets.split.map(&:to_i)
ans = 0
tmp_ans = 0
(h_li.length - 1).times do |i|
  if h_li[i+1] <= h_li[i]
    tmp_ans += 1
  else
    ans = tmp_ans if tmp_ans > ans
    tmp_ans = 0
  end
end
ans > tmp_ans ? puts(ans) : puts(tmp_ans)


Measured memory_bytes: 8580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

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

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

    int maxi = 0;
    ll ans = 0;

    for (int i = 0; i < n; ++i) {
        if (a[i] <= maxi) continue;

        if (a[i] == maxi + 1) {
            maxi = maxi + 1;
            continue;
        }

        int m = (a[i] - 1) / (maxi + 1);

        ans += m;

        if (i == 0) {
            maxi = 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N){
        cin >> A[i] >> B[i];
    }

    ll ans = 0;
    for (int i = N-1; i >= 0; i--){
        ll a = A[i] + ans;
        ll x = B[i] - (a % B[i]);
        if(x == B[i])x = 0;
        ans += x;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a[]={0,2,0,1,0,1,0,0,1,0,1,0};
    int x,y;
    cin>>x>>y;
    if(a[x-1]==a[y-1]){
    cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC51 C
sx,sy,tx,ty = map(int,input().split())

ans = ''
for _ in range(ty-sy):
    ans += 'U'
for _ in range(tx-sx):
    ans += 'R'
for _ in range(ty-sy):
    ans += 'D'
for _ in range(tx-sx+1):
    ans += 'L'
for _ in range(ty-sy+1):
    ans += 'U'
for _ in range(tx-sx+1):
    ans += 'R'
ans += 'D'
ans += 'R'
for _ in range(ty-sy+1):
    ans += 'D'
for _ in range(tx-sx+1):
    ans += 'L'
ans += 'U'
print(ans)


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

using namespace std;

using ll = long long;

ll nCr(ll n,ll r){
    if ( r > n ) return 0;
    if ( r * 2 > n ) r = n - r;
    if ( r == 0 ) return 1;

    ll result = n;
    for (ll i = 2; i <= r; ++i ) {
        result *= (n - i + 1);
        result /= i;
    }
    return result;
}

int main(void){
    ll n,a,b;
    ll sum = 0;

    double avg;
    ll cnt = 0;

    cin >> n >> a >> b;

    vector<ll> v(n,0);
    map<ll, ll> num_cnt;

    for(ll i=0; i<n; i++){
        cin >> v[i];
        num_cnt[v[i]]++;
    }
    
    sort(v.rbegin(), v.rend());

    ll cnt_last = 0;
    for(int i=0; i<a; i++){
        sum += v[i];
    }
    avg = (double)sum / a;

    ll ans = 0;

    int prev_cnt = 0;
    for(int i=0; v[i]>v[a-1]; i++){
        i += num_cnt[v[i]]-1;
        prev_cnt += num_cnt[v[i]];
    }

    if(b-prev_cnt > num_cnt[v[a-1]])
        b = num_cnt[v[a-1]] + prev_cnt;

    if(v[0] != v[a-1])
        b = a;
    
    for(ll i=a-prev_cnt; i<=b-prev_cnt; i++){
        ans += nCr(num_cnt[v[a-1]], i);
        //cout <<  nCr(num_cnt[v[a-1]], i) << ":" << num_cnt[v[a-1]] << "C" << i << endl;
    }

    printf("%lf\n%lld\n", avg, ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
ll mod = 998244353;
vector<ll> m;

int main() {
	fastio;
	ll n,a,b;
	cin>>n>>a>>b;
	m.resize(n);
	for(ll i=0;i<n;i++){
		cin>>m[i];
	}
	ll lo = 1, hi = 1e9;
	ll ans = hi;
	while(lo<=hi){
		ll mid = (hi+lo)/2;
		ll c = 0;
		for(ll i=0;i<n;i++){
			if(mid*b<m[i]){
				ll r = m[i]-mid*b;
				c += (r+a-b-1)/(a-b);
			}
		}
		
		if(c<=mid){
			ans = mid;
			hi = mid-1;
		}
		else{
			lo = mid+1;
		}
		
	}
	
	cout<<ans<<"\n";
	
}






Measured memory_bytes: 1024
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		s := io.NextLine()
		if s == "." {
			break
		}
		t := io.NextLine()
		if s == t {
			io.Println("IDENTICAL")
			continue
		}
		ss := strings.Split(s, "\"")
		tt := strings.Split(t, "\"")
		if len(ss) != len(tt) {
			io.Println("DIFFERENT")
			continue
		}
		cnt := 0
		for i := 0; i < len(ss); i++ {
			if i%2 == 0 {
				if ss[i] != tt[i] {
					cnt = -1
					break
				}
			} else {
				if ss[i] != tt[i] {
					cnt++
				}
			}
		}
		if cnt > 1 || cnt == -1 {
			io.Println("DIFFERENT")
		} else {
			io.Println("CLOSE")
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

ll solve(ll n, ll m) {
    if (n >= 2 and m >= 2) {
        return (n-2) * (m-2);
    }
    if (n == 1 and m >= 2) {
        return m-2;
    }
    if (m == 1 and n >= 2) {
        return n-2;
    }
    if (n == 1 and m == 1) {
        return 1;
    }
    return 0;
}

int main() {
    ll n, m;
    cin >> n >> m;
    cout << solve(n, m) << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF (long long)1 << 61
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
typedef vector<LL> LV;

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

LL gcd(LL a, LL b){    return b != 0 ? gcd(b, a % b) : a;} 

LL lcm(LL number1,LL number2){	return number1 * number2 / gcd(number1,number2);}


int main(){
    int n;cin >>n;
    LV a(n);REP(i,n) cin >> a[i];
    LV b;copy(a.begin(),a.end(),back_inserter(b));
    VSORT(b);
    REP(i,n){
        cout << (a[i]==b[n-1]?b[n-2]:b[n-1]) << endl;
    }

    return 0;

}




Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    ll length[3];
    bool flag = false;
    rep(i, 3) {
        cin >> length[i];
        if(length[i]%2==0)
            flag = true;
    }
    sort(length, length + 3);
    if(flag)
        cout << 0 << endl;
    else
        cout << length[0] * length[1] << endl;
    return 0;
}

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

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

int N,W;
int v[110],w[110];
int dp[110][10010]; // i???????????§?????¢?????????????????£??? W??\?????§?????§?????????

int main(){

  cin >> N >> W; //??\???
  v[0] = w[0] = 0;
  rep(i,N){
    cin >> v[i+1] >> w[i+1];
  }

  rep(j,W){
    dp[0][j] = 0;
  }

  for(int i = 1; i < N+1 ;i++){
    for(int j = 0; j < W+1 ;j++){
      if(w[i] <= j){
	dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i]] + v[i]);
      }
      else dp[i][j] = dp[i-1][j];
    }
  }

  cout << dp[N][W] << endl; 

  return 0;
}

Measured memory_bytes: 5252
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    int X, N; cin >> X >> N;
    vector<int> d(102);
    rep(i, N) {
        int p;
        cin >> p;
        d[p] = 1;
    }

    P ans(99999, -1);

    rrep(i, 0, 101) {
        if (d[i] == 1) continue;
        int diff = abs(X - i);
        ans = min(ans, P(diff, i));
    }

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


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

#define MOD (1.0e9 + 7)

using namespace std;

int main(void)
{
    int n;
    int c2 = 0,c4 = 0;

    cin>>n;

    for(int i = 0;i < n;i++)
    {
	int temp;
	cin>>temp;

	if(temp % 2 == 0 && temp % 4 != 0)
	    c2++;
	else if(temp % 4 == 0)
	    c4++;
    }

    if((n / 2) <= c2/2+c4)
	cout<<"Yes"<<endl;
    else
	cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    int A, B;
    cin >> A >> B;

    int ans = 0;
    if(A > B){
        ans += A;
        A--;
        if(A > B){
            ans+= A;
        }else{
            ans+= B;
        }
    }else{

           ans += B;
           B--;
        if(A < B){
            ans+= B;
        }else{
            ans+= A;
        }     
    }

    cout << ans << endl;



} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000000
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
int getbit(int s, int i)
{ return (s >> i) & 1; }
int cntbit(int s)
{ return __builtin_popcountll(s); }
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
     string s;
    cin>>s;
    if(s=="ABC")
     cout<<"ARC";
    else
     cout<<"ABC";



}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
  int n[5];
  for(int i = 0; i < 5; i++)
    cin >> n[i];
  sort(n, n + 5, greater<int>());
  cout << n[0];
  for(int i = 1; i < 5; i++)
    cout << ' ' << n[i];
  cout << endl;
}

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

int main()
{
	string s;
	cin >> s;
	long long n;
	cin >> n;

	char ret;
	long long count = 0;
	for (auto& i : s) {
		if (i == '1') {
			++count;
			if (count == n) {
				ret = '1';
				break;
			}
		}
		else {
			ret = i;
			break;
		}
	}

	cout << ret << endl;

	return 0;
}


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

int n;
vector<int> ans;

void search(){
    for(int x=1;;++x){
        if(x*x>n) break;
        for(int y=1;;++y){
            if(x*x+y*y+x*y>n) break;
            for(int z=1;;++z){
                int t=x*x+y*y+z*z+x*y+y*z+z*x;
                if(t>n) break;
                ++ans[t];
            }
        }
    }
}

int main(){
    cin>>n;
    ans.assign(n+100,0);
    
    search();

    for(int i=0;i<n;++i) cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 3552
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int s;
	
	scanf("%d", &s);
	
	int L=s/100, R=s%100;
	
	if(1<=L&&L<=12){
		if(1<=R&&R<=12)printf("AMBIGUOUS\n");
		else printf("MMYY\n");
	}else{
		if(1<=R&&R<=12)printf("YYMM\n");
		else printf("NA\n");
	}
	
return 0;
}

Measured memory_bytes: 128
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    H, W = map(int,input().split())
    visited = [[False]*W for _ in range(H)]
    q = []
    for y in range(H):
        S = input().rstrip()
        for x, s in enumerate(S):
            if s == "#":
                q.append((y, x))
                visited[y][x] = True

    ans = -1
    while q:
        ans += 1
        nq = []
        for y, x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 106724
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

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

Node root;

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key){
      u = u->left;
    }
    else{
      u = u->right;
    }
  }
  return u;
}

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

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

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d", u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);
  }
}

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

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

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

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

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

  }
  return 0;
}

Measured memory_bytes: 24040
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll d[1000];
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)d[s[i]]++;
	ll ans=(ll)(s.size())*(ll)(s.size()-1)/2+1;
	for(int i='a';i<='z';i++)ans-=d[i]*(d[i]-1)/2;
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
def get_prime_factorized(N):
    R = []
    b, e = 2, 0
    while b ** 2 <= N:
        while N % b == 0:
            N  = N // b
            e += 1
        if e > 0:
            R.append([b, e])
        b, e = b + 1, 0
    if N > 1:
        R.append([N, 1])
    return R

def get_list_divisor(N, reverse=True):
    try:
        F = get_prime_factorized(N)
        L = re_func_divisior(F)
        R = []
        for l in L:
            for i, x in enumerate(l):
                if i == 0:
                    r = x
                else:
                    r *= x
            R.append(r)
        R.sort()
        if reverse == True:
            R.reverse()
    except:
        if N == 1:
            R = [1]
        else:
            R = [N]
    return R

def re_func_divisior(F):
    b, e = F.pop()
    P = re_func_divisior(F) if F else [[]]
    Q = [[b ** k] for k in range(e + 1)]
    return [p + q for p in P for q in Q]


A, B, K = map(int, input().split())

R = set(get_list_divisor(A)) & set(get_list_divisor(B))
R = list(R)

R.sort()

print(R[-1*K])


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main() {

    int N; cin >> N;
    int p[N+1];
    for (int i = 1; i <= N; ++i) cin >> p[i];
    int ans = 0;
    int no = 0;
    for (int i = 1; i <= N; ++i) {
        if (p[i] == i) {
            ++no;
        }
        if (p[i] != i || i == N) {
            ans += no / 2 + no % 2;
            no = 0;
        }
    }
    out(ans);

    return 0;
}






Measured memory_bytes: 640
import java.util.Scanner;

class Main {
    private static boolean[] calcPrimeTable(int n) {
        boolean[] table = new boolean[n + 1];
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (!table[i]) {
                for (int j = i + i; j <= n; j += i) {
                    table[j] = true;
                }
            }
        }
        return table;
    }

    private static void solve() {
        boolean[] table = calcPrimeTable(50000);
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            int counter = 0;
            if (n == 0) {
                break;
            }
            for (int i = 2; i <= n / 2; i++) {
                if (!table[i] && !table[n - i]) {
                    counter++;
                }
            }
            System.out.println(counter);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 13000
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	vll h(n) ;
	for(auto &i:h) cin >> i ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<m;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).emplace_back(b) ;
		g.at(b).emplace_back(a) ;
	}
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		bool ok = true ;
		for(int j=0;j<g.at(i).size();j++){
			if(h.at(i)<=h.at(g.at(i).at(j))){
				ok = false ;
				break ;
			}
		}
		ans += ok ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 9856
/**
*    author:  yuya1234
*    created: 22.08.2020 21:07:08
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  ll n;
  cin>>n;

  ll a[n];
  REP(i,n)cin>>a[i];

  ll sum=0;
  ll num=a[0];
  REP(i,n)
  {
    if(a[i]>num)num=a[i];
    else if(a[i]<num)sum+=num-a[i];
  }

  cout<<sum<<endl;



  return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
double a,b,h,m;
cin>>a>>b>>h>>m;

double kaku=abs((h*360)/12+(m*30)/60-(m*360)/60);
/*if(kaku>M_PI){
  kaku=2*M_PI-kaku;
}*/

//cout<<(h*360)/12<<endl;
//out<<(m*360)/60<<endl;
//cout<<kaku<<endl;
cout<<fixed<<setprecision(20)<<sqrt((a*a)+(b*b)-(2*a*b*cos(M_PI*kaku/180)))<<endl;

  return 0;
}


Measured memory_bytes: 4228
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n, k;
	scanf("%d", &n);
	char res[500];
	int pos = 0;
	long product = 1;
	if (n == 0) {
		printf("0");
		return 0;
	}
	long sum = 0;
	while (n!=0) {
		product *= (-2);
		if ((n / product) * product != n) {
			res[pos] = '1';
			sum += (product/(-2));
			n -=(product/(-2));
		}
		else {
			res[pos] = '0';
		}
		if (sum == n) break; 
		pos++;
	}
	for (int i = pos-1; i >= 0; i--) {
		printf("%c", res[i]);
	}
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n;
int main()
{
	cin>>n;
	cout<<n*180-360;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,i;
    cin >> n;
    long long a = 0;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            a+=i;
        }
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> ma(N);
  for(int i=0;i<N;i++) cin >> H.at(i);
  for(int i=0;i<N;i++) ma.at(i) = 0;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    ma.at(a) = max(ma.at(a),H.at(b));
    ma.at(b) = max(ma.at(b),H.at(a));
  }
  int ans=0;
  for(int i=0;i<N;i++){
    //printf("ma.at(%d) = %d\n",i,ma.at(i));
    if(ma.at(i) < H.at(i)) {
      ans++;
      
    }
  }
  cout  << ans << endl;
}


Measured memory_bytes: 4024
# pylint: disable=invalid-name
# pylint: disable=missing-docstring


def main():
    N, K = map(int, input().split())
    H = [0] + [int(x) for x in input().split()]
    DP = [[-1 for _ in range(K + 1)] for _ in range(N + 1)]
    DP[0] = [0 for _ in range(K + 1)]
    for i in range(1, N + 1):
        for j in range(K + 1):
            for k in range(max(i - j - 1, 0), i):
                previous = DP[k][j - (i - k - 1)]
                if previous == -1:
                    continue

                if DP[i][j] == -1 or previous + max(H[i] - H[k], 0) < DP[i][j]:
                    DP[i][j] = previous + max(H[i] - H[k], 0)

                if j > 0 and DP[i][j - 1] != -1 and DP[i][j - 1] < DP[i][j]:
                    DP[i][j] = DP[i][j - 1]
                # print('i {} j {} k {} j - (i - k - 1) {} DP_targ {} DP {}'.
                #       format(i, j, k, j - (i - k - 1),
                #              previous + max(H[i] - H[k], 0), DP[i][j]))
    ans = -1
    for i in range(N + 1):
        if K < (N - i):
            continue
        if ans == -1 or DP[i][min(K - (N - i), K)] < ans:
            ans = DP[i][min(K - (N - i), K)]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// chctxdy
vll adj[200005], blc[200005];
ll col[200005];
bool acc[200005];
ll cc[200005];
void dfs(ll u, ll color){
	if (acc[u]) return;
	acc[u] = true; col[u] = color;
	for (ll i = 0; i<adj[u].size(); i++){
		ll v = adj[u][i]; dfs(v, color);
	}
}
int main(){
	ll n, m, k; cin >> n >> m >> k;
	for (ll i = 0; i<m; i++){
		ll u, v; cin >> u >> v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	for (ll i = 0; i<k; i++){
		ll u, v; cin >> u >> v; u--; v--;
		blc[u].pb(v); blc[v].pb(u);
	}
	ll cnt = 1;
	for (ll i = 0; i<n; i++){
		if (!acc[i]){
			dfs(i, cnt); cnt++;
		}
	}
	for (ll i = 0; i<n; i++) cc[col[i]]++;
	for (ll i = 0; i<n; i++){
		ll ans = cc[col[i]]; ans--;
		for (ll j = 0; j<adj[i].size(); j++) ans--;
		for (ll j = 0; j<blc[i].size(); j++){
			ll v = blc[i][j];
			if (col[v] == col[i]) ans--;
		}
		cout << ans << " ";
	}
}

Measured memory_bytes: 20096
/**
 *    author:  tourist
 *    created: 14.01.2020 00:23:34       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> p(n), w(n);
  for (int i = 1; i < n; i++) {
    cin >> p[i] >> w[i];
    --p[i];
  }
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    g[p[i]].push_back(i);
  }
  long long low = 0, high = (long long) 1e12;
  while (low < high) {
    long long mid = (low + high) >> 1;
    vector<vector<pair<long long, long long>>> f(n);
    for (int i = n - 1; i >= 0; i--) {
      if (g[i].empty()) {
        f[i].emplace_back(w[i], w[i]);
        continue;
      }
      int x = g[i][0];
      int y = g[i][1];
      if (f[x].size() > f[y].size()) {
        swap(x, y);
      }
      auto Add = [&](long long v0, long long v1) {
        if (v0 > v1) {
          swap(v0, v1);
        }
        f[i].emplace_back(v0 + w[i], v1 + w[i]);
      };
      for (int it = 0; it < (int) f[x].size(); it++) {
        for (long long val : {f[x][it].first, f[x][it].second}) {
          long long limit = mid - val;
          if (limit < 0) {
            continue;
          }
          {
            int L = -1, R = (int) f[y].size() - 1;
            while (L < R) {
              int M = (L + R + 1) >> 1;
              if (f[y][M].first <= limit) {
                L = M;
              } else {
                R = M - 1;
              }
            }
            if (L >= 0) {
              Add(f[x][it].first ^ f[x][it].second ^ val, f[y][L].second);
            }
          }
          {
            int L = 0, R = (int) f[y].size();
            while (L < R) {
              int M = (L + R) >> 1;
              if (f[y][M].second <= limit) {
                R = M;
              } else {
                L = M + 1;
              }
            }
            if (R < (int) f[y].size()) {
              Add(f[x][it].first ^ f[x][it].second ^ val, f[y][R].first);
            }
          }
        }
      }
      sort(f[i].begin(), f[i].end());
      int sz = 0;
      for (int j = 0; j < (int) f[i].size(); j++) {
        if (sz == 0 || f[i][j].second < f[i][sz - 1].second) {
          f[i][sz++] = f[i][j];
        }
      }
      f[i].resize(sz);
    }
    if (f[0].empty()) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << low << '\n';
  return 0;
}


Measured memory_bytes: 30008
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;

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

    ll k;
    cin>>k;
    if(k==1||k==7){
        cout<<1<<endl;
        return 0;
    }
    if(k==3){
        cout<<3<<endl;
        return 0;
    }
    if(k%2==0||k%5==0){
        cout<<-1<<endl;
        return 0;
    }

    vector<ll> amari(1000005);
    for(int i=1;i<1000005;i++){
        if(i==1){
            amari[i]=7%k;
            continue;
        } 
        amari[i]=(amari[i-1]*10)%k;
    }
    for(int i=2;i<1000005;i++){
        amari[i]+=amari[i-1];
        if(amari[i]%k==0){
            cout<<i<<endl;
            return 0;
        }
    }

    




}

Measured memory_bytes: 11088
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[88888888];
int ans=1e9+7;
int main()
{
  scanf("%s",&a);
  for(int i=0;i<strlen(a);i++)
  	if(a[i]!=a[i+1])  ans=min(ans,max(i+1,(int)strlen(a)-i-1));
  printf("%d",min(ans,(int)strlen(a)));
  return 0;
}

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

typedef long long int llint;

llint a[10001];

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

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

  int cnt = 0;
  for(int i = 0; i < n; i++) {

    if(a[i] % 2 == 1) continue;
    while(a[i] > 1 && a[i] % 2 == 0) {
      cnt++;
      a[i] /= 2;
    }
    
  }

  cout<< cnt <<endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int A[3001],d[3001],M=998244353,i,K,N,S,j,P;
int main(){
scanf("%d%d",&N,&S);
while(i++<N)scanf("%d",&A[i]);
while(--i){
    j=S+1;P=A[i];
    while(j--){
      if(j>=A[i])d[j]+=d[j-P]+(j==P);
      d[j]%=M;
    }
    K=(K+d[S])%M;d[0]++;
  }
  printf("%d\n",K);
}

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int sum = 0;
    for (char i : s)
    {
        int d = i - '0';
        sum = (sum + d) % 9;
    }
    if (sum != 0)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    int t=stoi(a+b);
    for(int i=0;i<=1000;i++){
        if(i*i==t){
            cout << "Yes" << endl;
            return 0;
        }
    }
cout << "No"  << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
  int n,i;
  double t,res=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> t;
    res+=1/t;
  }
  res=1/res;
  cout << setprecision(10) << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	ll MOD = pow(10, 9) + 7;
	int n;
	cin >> n;
	ll ans = 1;
	FOR(i, 1, n + 1) {
		ans = (ans * i) % MOD;
	}
	cout << ans << endl;
}



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

using namespace std;

int main(){
//int W,H,x,y,r;
    int a,b;
    cin>>a>>b;


    cout<<a/b<<" "<<a%b<<" ";   
  printf("%.5lf\n", (double)a/b);
  
  return 0;
}


Measured memory_bytes: 3224
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            long[] y = new long[N];
            long y1 = 0;
            int f = 1;
            for (int i = 0; i < N; i++)
            {
                y[i] = long.Parse(s[i]);
                y1 += f * y[i];
                f *= -1;
            }

            y1 /= 2;

            for (int i = 0; i < N; i++)
            {
                Console.Write("{0} ", y1 * 2);
                y1 = y[i] - y1;
            }

            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 29140
h, w = map(int, input().split())
grid = []
ignore_i = []
ignore_j = []
for i in range(h):
    l = list(input())
    grid.append(l)
    
    if  not("#" in l):
        ignore_i.append(i)

for j in range(w):
    white = True
    for i in range(h): 
        if grid[i][j] == "#":
            white = False
            break
    if white:
        ignore_j.append(j)

# print(ignore_i)
# print(ignore_j)

for i in range(h):
    if i in ignore_i:
        continue

    for j in range(w):
        if j in ignore_j:
            continue
        print(grid[i][j], end="")
    print("\n")

Measured memory_bytes: 4596
import java.util.Scanner

fun main(args: Array<String>){
	val s = Scanner(System.`in`).nextLine()
	val sarr = s.split(" ")

	val N = Integer.parseInt(sarr[0])
	val K = Integer.parseInt(sarr[1])

	if(N%K == 0) println(0)
	else println(1)
}

Measured memory_bytes: 34040
Lists = [1, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
x = int(input())
print(Lists[x])

Measured memory_bytes: 3060