akhauriyash/Code-Regression huggingface dataset:
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=405;
int N;
int t[MX];
int memo[MX][MX];
int pref[MX];

int solve(int l, int r){
	if(l==r) return 0;
	if(memo[l][r]!=-1) return memo[l][r];
	int ans=INF;
	for(int i=l; i<r; i++) ans=min(ans,solve(l,i)+solve(i+1,r)+pref[r+1]-pref[l]);

	return memo[l][r]=ans;
}

int32_t main(){
   boost;
   IO();
	
	memset(memo,-1,sizeof(memo));
	cin>>N;
	pref[0]=0;
	for(int i=0; i<N; i++){
		cin>>t[i];
		pref[i+1]=t[i]; pref[i+1]+=pref[i];
	}
	cout << solve(0,N-1) << endl;

   return 0;
}



Measured memory_bytes: 4868
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

S = list(s())
print(S.count('+')-S.count('-'))

Measured memory_bytes: 77484
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, a, b;
    cin >> n >> a >> b;

    lli loop = a + b;
    lli ans = a * (n / loop);
    n %= loop;
    if(n >= a) ans += a;
    else ans += n;

    cout << ans << endl;
}

Measured memory_bytes: 256
import math
a,b,C = map(int,input().split())
print(a*b*math.sin(math.radians(C))/2)
print(a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**(1/2))
print(b*math.sin(math.radians(C)))


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

/*If you are going to try,keep going until the end ,or don't even try to start*/

/* Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!*/

using namespace std;

#define ll long long
#define nada "\n"
#define st string
#define S  second
#define F  first
#define pb push_back
#define MP make_pair
#define isnttriangle(a,b,c)  (a+b<c||a+c<b||b+c<a)
#define todegree(rad) rad*(180.0/pi)
#define rrp(i, a, b)  for(ll i = a; i >= b; i--)
#define repp(i,a,b)   for (int i = int(a); i <=int(b); i++)
#define rep(i, n)     for (int i = 0; i <n; i++)
#define rep1(i,n)     for (int i = 1; i <=n; i++)
#define allr(v)       ((v).rbegin()), ((v).rend())
#define all(v)        ((v).begin()),((v).end())
#define fx(n)         cout<<fixed<<setprecision(n);
#define sz(v)         ((int)(v).size())
#define Test          ll t;cin>>t;while(t--)
#define mod           1000000009LL


const double ME = 2.71828;
const int    N  = 3e5 + 20;
const int   inf = 0x3f3f3f3f;
const double pi = 3.141592653;




void LOSER()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void file()
{
    freopen("records.in", "r", stdin);
    //freopen("text.out", "w", stdout);
}

ll gcd(ll a, ll b)
{
    //Eculidean Algorthim
    return (!b) ? a : gcd(b, a % b);
    //complixty=log(ab);
}

ll lcm(ll a,ll b)
{
    return a / gcd(a, b) * b;
}

ll Fib_recur(ll n)
{
    vector<ll>v(n+5,0);
    //BaseCase
    v[1]=0;
    v[2]=1;
    repp(i,3,n)v[i]=v[i-1]+v[i-2];
    return v[n];
}

bool isprime(int n)
{
    for(int i = 2; i <= sqrt(n); i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

void Solve()
{

  int n,AC=0,WA=0,TLE=0,RE=0;
  st s;
  cin>>n;
  while(n--)
  {
      cin>>s;
      if(s=="AC")AC++;
      if(s=="WA")WA++;
       if(s=="TLE")TLE++;
        if(s=="RE")RE++;
  }
  cout<<"AC"<<" x "<<AC<<nada;
  cout<<"WA"<<" x "<<WA<<nada;
  cout<<"TLE"<<" x "<<TLE<<nada;
  cout<<"RE"<<" x "<<RE<<nada;
}





int main()
{
    // fx(7)
    //file();
    LOSER();
    //Test

    Solve();







}

Measured memory_bytes: 3712
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll MOD=1e+9+7;
ll dp[101][99900];
ll sdp[99900];
ll num[99900];
int main(){
	int N,K;
	scan(N>>K);
	ll ans=0;
	int iter=0;
	for(int i=1;i<=N;){
		int j=N/i;
		if(i<=j){
			num[iter]=1;
			i++;
		}
		else{
			num[iter]=N/j-i+1;
			i=N/j+1;
		}
		iter++;
	}
	dp[0][0]=1;
	rep(k,K){
		fill(sdp,sdp+iter,0);
		rep(j,iter){
			sdp[j+1]=(sdp[j]+dp[k][j])%MOD;
		}
		rep(j,iter){
			dp[k+1][j]=sdp[iter-j]*num[j]%MOD;
		}
	}
	rep(i,iter+1){
		ans+=dp[K][i];
		ans%=MOD;
	}
	prin(ans);
	return 0;
}


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

int main()
{
	int abc[4];
	int tmp;
	
	cin>>abc[0]>>abc[1]>>abc[2];
	for( int i=0; i<2; i++ ) {
		for( int j=i+1; j<3; j++ ) {
			if( abc[j] < abc[i] ) {
				tmp=abc[i];
				abc[i]=abc[j];
				abc[j]=tmp;		
			}
		}
	}

	cout <<abc[0]<<" "<<abc[1]<<" "<<abc[2]<<endl;
	 
    return 0;
}

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

int main (){
    int K, A, B;

    cin >> K >> A >> B;


    int p = A / K;

    int x = ((p+1)*K);
    
    if((p*K)== A){
        cout << "OK" << endl;
    }

    else if(x <= B){
        cout << "OK" << endl;
    }

    else{
        cout << "NG" <<endl;
    }
    }

Measured memory_bytes: 3636
def inductive_inference(animal, statement, other):
    if animal == 'S':
        if statement == 'o':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]
    else:
        if statement == 'x':
            return other
        else:
            return {'S': 'W', 'W': 'S'}[other]

N = int(input())
S = input()
for a1, a2 in ['SS', 'SW', 'WS', 'WW']:
    assumption = inductive_inference(a1, S[0], a2)  # the animal numbered N
    a, b = a1, a2
    animals = [assumption, a, b]
    for c in S[1:]:
        a, b = b, inductive_inference(b, c, a)
        animals.append(b)
    if animals[1] == animals[-1] and animals[0] == animals[N]:
        print(''.join(animals[1:-1]))
        exit()
print(-1)

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  ll N; cin >> N;
  ll result = LLINF;
  rep(i,N) {
    ll A, B; cin >> A >> B;
    result = min(result, A+B);
  }
  cout << result << endl;
  return 0;
}

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

int main() {
    int n;
    string s;
    cin>>n>>s;
    int ans=0,cnt;
    for (int i=1; i<n; i++) {
        cnt=0;
        for (char c='a'; c<='z'; c++) {
            bool left=false,right=false;

            for (int j=0; j<i; j++) {
                if (s[j]==c) left=true;
            }
            for (int j=i; j<n; j++) {
                if (s[j]==c) right=true;
            }
            if (left&&right) cnt++;
        }
        if (ans<cnt) ans=cnt;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int answer = 0;
  cin >> S;
  for (int i = 0; 2*i < S.length(); i++) {
    answer += S[i] != S[S.length()-1-i];
  }
  cout << answer;
}    

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a = 0;
    int b = 0;

    cin >> a;
    cin >> b;

    int c = 0;

    for (int x = a; x <= b; ++x) {
        int t = x;
        int r = 0;
        while (t != 0) {
            int d = t % 10;
            r = r * 10 + d;
            t /= 10;
        }

        if (x == r) {
            c++;
        }
    }

    cout << c << endl;

    return 0;
}

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

int main() {
  string S;
  cin >> S;

  if (S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(3)){
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(2) && S.at(1) == S.at(3) && S.at(0) != S.at(3)){
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(3) && S.at(1) == S.at(2) && S.at(1) != S.at(3)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3608
#include <stdio.h>

int picture_size;
int picture[100][100];
int kirehasi_size;
int kirehasi[50][50];

void rotate(int left,int size) {
	int i;
	int temp;
	if(size<=1)return;
	size--;
	for(i=0;i<size;i++) {
		temp=kirehasi[left+i][left];
		kirehasi[left+i][left]=kirehasi[left][left+size-i];
		kirehasi[left][left+size-i]=kirehasi[left+size-i][left+size];
		kirehasi[left+size-i][left+size]=kirehasi[left+size][left+i];
		kirehasi[left+size][left+i]=temp;
	}
	rotate(left+1,size-1);
}

void ryoiki_search(int* x,int* y) {
	int i,j;
	for(i=0;i<kirehasi_size;i++) {
		for(j=0;j<kirehasi_size;j++) {
			if(kirehasi[i][j]!=-1) {
				*y=i;
				*x=j;
				return;
			}
		}
	}
}

int is_match(int x,int y) {
	int i,j;
	if(x+kirehasi_size>picture_size || y+kirehasi_size>picture_size) {
		return 0;
	}
	for(i=0;i<kirehasi_size;i++) {
		for(j=0;j<kirehasi_size;j++) {
			if(kirehasi[i][j]!=-1 && picture[y+i][x+j]!=kirehasi[i][j]) {
				return 0;
			}
		}
	}
	return 1;
}

int main(void) {
	int i,j,k;
	int rx,ry,nx,ny;
	while(1) {
		scanf("%d%d",&picture_size,&kirehasi_size);
		if(picture_size==0 || kirehasi_size==0)break;
		for(i=0;i<picture_size;i++) {
			for(j=0;j<picture_size;j++) {
				scanf("%d",&picture[i][j]);
			}
		}
		for(i=0;i<kirehasi_size;i++) {
			for(j=0;j<kirehasi_size;j++) {
				scanf("%d",&kirehasi[i][j]);
			}
		}
		rx=ry=picture_size;
		ryoiki_search(&nx,&ny);
		for(i=0;i<picture_size;i++) {
			for(j=0;j<picture_size;j++) {
				if(is_match(j,i)) {
					i+=ny;j+=nx;
					if(i<ry || (i==ry && j<rx)) {
						rx=j;
						ry=i;
					}
					i=picture_size;
					break;
				}
			}
		}
		for(k=0;k<3;k++) {
			rotate(0,kirehasi_size);
			ryoiki_search(&nx,&ny);
			for(i=0;i<picture_size;i++) {
				for(j=0;j<picture_size;j++) {
					if(is_match(j,i)) {
						i+=ny;j+=nx;
						if(i<ry || (i==ry && j<rx)) {
							rx=j;
							ry=i;
						}
						i=picture_size;
						break;
					}
				}
			}
		}
		if(rx==picture_size && ry==picture_size)puts("NA");
		else printf("%d %d\n",rx+1,ry+1);
	}
	return 0;
}

Measured memory_bytes: 460
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=10000000;

int dp[11][200001];

const int lim=100000;

int main(){
    int D,G;
    cin >> D >> G;
    G/=100;
    int p[D],c[D];
    for(int i=0;i<D;i++){
        cin >> p[i] >> c[i];
        c[i]/=100;
    }
    for(int i=0;i<=D;i++){
        for(int j=0;j<200001;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<D;i++){
        for(int k=0;k<=lim;k++) dp[i+1][k]=dp[i][k];
        int tp=p[i];
        for(int j=0;tp>0;j++){
            int key=min(tp,1<<j);
            tp-=key;
            for(int k=lim;k>=0;k--){
                dp[i+1][k+(i+1)*key]=min(dp[i+1][k+(i+1)*key],dp[i+1][k]+key);
            }
        }
        for(int k=0;k<lim;k++){
            dp[i+1][k+p[i]*(i+1)+c[i]]=min(dp[i+1][k+p[i]*(i+1)+c[i]],dp[i][k]+p[i]);
        }
    }
    int ans=INF;
    for(int k=G;k<2*lim;k++) ans=min(ans,dp[D][k]);
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    sort(x, x+3);

    int d1 = x[2] - x[1];
    int d0 = x[2] - x[0];
    if(d1 % 2 == 0 && d0 % 2 == 0) {
        printf("%d\n", d1/2 + d0/2);
    }
    else if(d1 % 2 == 1 && d0 % 2 == 1) {
        printf("%d\n", d1/2 + d0/2 + 1);
    }
    else if (d1 % 2 == 1 && d0 % 2 == 0) {
        printf("%d\n", d1/2 + 1 + d0/2 + 1);
    }
    else if (d1 % 2 == 0 && d0 % 2 == 1) {
        printf("%d\n", d1/2 + d0/2 + 1 + 1);
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int val[N][N],b[N][N],S[N],n,u[N][N],l[N],r[N];
char A[N][N];
bool flag[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9',b[i][j]=A[i][j]-'0';
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=x?b[x][j]:0);
		for (register int j=n+1;j;--j){
			if (flag[x][j]){
				l[j]=j-1;
				r[j]=max(r[j+1],j);
				val[x][j]+=(S[r[j]]-S[l[j]]-b[x][j]);
			}
			else l[j]=1e9,r[j]=-1;
		}
		for (register int i=x-1;i;--i){
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=i?b[x][j]:0);
			for (register int j=n+1;j;--j){
				if (flag[i][j]){
					l[j]=min(l[j+1],l[j]);
					r[j]=max(r[j+1],r[j]);
					if (l[j]<=r[j])val[i][j]+=(S[r[j]]-S[l[j]]);
				}
				else l[j]=1e9,r[j]=-1;
			}
		}
	}
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)ans+=val[i][j]*b[i][j];
	printf("%lld\n",ans);
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n, d;
    cin >> n >> d;
    VL x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];
    ll ans = 0;
    rep(i, 0, n) {
        ll r = x[i] * x[i] + y[i] * y[i];
        if(r <= d*d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6428
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

signed main() {
    string s;
    int q;
    cin >> s >> q;

    deque<char> deq;
    for (auto c: s) deq.push_back(c);

    bool is_reversed = false;

    repeat(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            is_reversed = !is_reversed;
        } else if (t == 2) {
            int f; char c;
            cin >> f >> c;

            if ((f == 1) ^ is_reversed) {
                deq.push_front(c);
            } else {
                deq.push_back(c);
            }
        }
    }

    if (is_reversed) reverse(all(deq));
    for (auto c: deq) cout << c;

    return 0;
}

Measured memory_bytes: 3336
from collections import Counter

def solve():
    N = int(input())
    
    counter = Counter(input())
    for _ in range(N-1):
        counter_ = Counter(input())
        counter = {k:min(counter[k],counter_[k]) for k in counter_.keys() & counter.keys()}
        
    print(''.join([k*v for k,v in sorted(counter.items())]))
    
solve()

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int p = 1;
    REP(i, 1, N) p = (p * i) % mod;
    cout << p << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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;}

signed main() {
  INIT;
  VAR(int,n);
  VEC(int,b,n-1);

  vector<int> a(n,INF);
  REP(i,n-1){
    // 0-indexed
    a[i] = min(a[i], b[i]);
    a[i+1] = min(a[i+1], b[i]);
  }

  int ans = 0;
  REP(i,n){
    ans += a[i];
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  float N,T,A;
  cin >> N >> T >> A;
  float H[100010]={0};
  for(int i=1;i<=N;i++){
    cin >> H[i];
  }
  int ans=1;
  float tmp=0;
  for(int i=2;i<=N;i++){
    tmp=T-0.006*H[i];
    if(abs(A-tmp)<abs(A-T+0.006*H[ans])){
      ans=i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;



int main(){
    int n ,m;
    cin >> n >> m ;
    vector<vector<int> > list(n,vector<int>(0)) ;
    int a,b ;
    //部屋番号は-1して記録し、出力時に1足す
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b ;
        list.at(a-1).push_back(b-1) ;
        list.at(b-1).push_back(a-1) ;
    }
    queue<pair<int,int> > wait ;
    vector<bool> seen(n,0) ;
    vector<int> ans(n) ;
    for (size_t i = 0; i < list.at(0).size(); i++)
    {
        wait.push(make_pair(list.at(0).at(i),0) ) ;
        seen.at(list.at(0).at(i)) = 1;
    }
    while (wait.empty()==0)
    {
        pair<int,int> now = wait.front() ;
        wait.pop() ;
        ans.at(now.first) = now.second ;
        for (int i = 0; i < list.at(now.first).size(); i++)
        {
            int next = list.at(now.first).at(i) ;
            if (seen.at(next) == 0)
            {
                wait.push(make_pair(next,now.first)) ;
                seen.at(next) = 1 ;
            }
            
        }
        
    }
    
    //1足す！！！
    cout << "Yes" << endl ;
    for (int i = 1; i < n; i++)
    {
        cout << ans.at(i) + 1 << endl ;
    }
    
    
}

Measured memory_bytes: 10572
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long N = sc.nextLong();
		long X = 0;
		if( B-1<=N ){
			X = B-1;
		}else{
			X = N;
		}
		System.out.println( A*X/B - A*(X/B) );
	}
}

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

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	
	if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))

ans = 0

for i in range(N):
    ans += min(A[i], B[i])
    if B[i] > A[i]:
        carry = (B[i] - A[i])
        if A[i+1] > carry:
            ans += carry
            A[i+1] -= carry
        else:
            ans += A[i+1]
            A[i+1] = 0


print(ans)

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, x;
    cin >> N >> x;

    if (x <= 1 || x >= N*2-1) {
        cout << "No" << endl;
        return 0;
    }

    vector<int> res(2 * N - 1, -1);

    res[N-2] = 1;
    res[N-1] = x;
    res[N] = 2 * N - 1;

    int iter = 0;
    for (int v = 2; v < 2 * N - 1; ++v) {
        if (v == x) continue;
        while (res[iter] != -1){
            ++iter;
        }
        res[iter] = v;
    }

    cout << "Yes" << endl;
    for (auto v : res){
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, tr, ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> tr;
		while (tr % 2 == 0) {
			tr /= 2;
			++ans;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N, K;
  cin >> N >> K;
  
  // 計算をしていく
  int x = 0;
  int sumKyori = 0;
  rep(i, N) {
    cin >> x;
    
    if (x < K - x) {
      sumKyori += x * 2;
    }
    else {
      sumKyori += (K - x) * 2;
    }
  }
 
  // 計算結果を出力
  cout << sumKyori << endl;
}

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

int main(){
    int r,c;cin>>r>>c;
    vector<vector<vector<long long>>> dp(r+2,vector<vector<long long>>(c+2,vector<long long>(4)));
    vector<vector<long long>> a(r+1,vector<long long>(c+1));
    int xx;cin>>xx;
    for(int i=0;i<xx;i++){
        int R,C,V;cin>>R>>C>>V;
        a[R][C]=V;
    }

    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            for(int k=2;k>=0;k--){
                dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
            }
            for(int k=0;k<4;k++){
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
            }
        }
    }
    for(int k=1;k<4;k++){
        dp[r][c][k]=max(dp[r][c][k],dp[r][c][k-1]);
    }
    cout<<dp[r][c][3]<<endl;

    return 0;
}

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

int main(){
  int n;
  int iro[9] = {0,0,0,0,0,0,0,0,0};
  cin >> n;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    iro[(a/400<9)?a/400:8]++;
  }
  int syurui=0;
  for(int i=0;i<8;i++){
    if(iro[i]) syurui++;
  }
  cout << ((syurui!=0)?syurui:1) << " " << syurui+iro[8] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=405,INF=1e9;
int dp[maxn+100][maxn+100]; // i个a j个b最小的消耗
int a[maxn],b[maxn],c[maxn];
int main() {
	int n,A,B;
	cin>>n>>A>>B;
	for(int i=1; i<=n; i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=0; i<=400; i++)
		for(int j=0; j<=400; j++)
			dp[i][j]=INF;
	dp[0][0]=0;
	for(int x=1; x<=n; x++) {
		for(int i=400; i>=0; i--)
			for(int j=400; j>=0; j--)
				if(dp[i][j]!=INF)
					dp[i+a[x]][j+b[x]]=min(dp[i+a[x]][j+b[x]],dp[i][j]+c[x]);
	}
	int ans=INF;
	for(int i=1; i<=400; i++) {
		for(int j=1; j<=400; j++)
			if(dp[i][j]!=INF && i*B==A*j)
				ans=min(ans,dp[i][j]);
	}
	printf("%d\n",ans==INF?-1:ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    ll n,k;
    cin >> n >> k;
    pair<int,int> p[n];
    rep(i,0,n){
	int a,b;
	cin >> a >> b;
	p[i] = {a,b};
    }
    sort(p,p+n);

    ll c = 0;
    rep(i,0,n){
	c += p[i].sd;
	if(c >= k){
	    P(p[i].ft);
	    break;
	}
    }

    
    return  0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    ll n, a, b;
    while(cin>>n>>a>>b){
        ll ans=n/(a+b)*a;
        ans+=min(a, n%(a+b));
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256
n, k = input().split()


def base_10_to_n(X, n):
    if int(X / n):
        return base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


x = base_10_to_n(int(n), int(k))
print(len(x))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

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

    ll ans1 = 0,ans2 = 0;//ans1 -start
    ll tmp = a[0];
    if(tmp <= 0){
        ans1 += abs(1 - tmp);
        tmp = 1;
    }
    for(int i = 1;i < n;i++){
        tmp += a[i];
        if(i%2 ==1){
            if(tmp >= 0){
                ans1 += abs(-1 - tmp);
                tmp = -1;
            }
        }
        else{
            if(tmp <= 0){
                ans1 += abs(1 - tmp);
                tmp = 1;
            }
        }
    }
    tmp = a[0];
    if(tmp >= 0){
        ans2 += abs(-1 - tmp);
        tmp = -1;
    }
    for(int i = 1;i < n;i++){
        tmp  += a[i];
        if(i%2 == 1){
            if(tmp <= 0){
                ans2 += abs(1 - tmp);
                tmp = 1;
            }
        }
        else{
            if(tmp >= 0){
                ans2 += abs(-1 - tmp);
                tmp = -1;
            }
        }
    }

    cout << min(ans1,ans2) << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n;
	cin>>n;

	double arr[1000000];
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	double sum = 0.0;

	for(int i=0; i<n; i++)
	{
		sum += 1/(arr[i]);
	}

	cout<< 1/(sum)<<endl;
	
	return 0;
}
	


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

int main(){
  int n, m, a, b;
  int bridge[51]= {0};
  cin >> n >> m;
  
  for ( int i = 0; i < m; i ++ ){
    cin >> a >> b;
    bridge[a - 1]++;
    bridge[b - 1]++;
  }
  for ( int i = 0; i < n; i++ ){
    cout << bridge[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	string s,t; cin>>s>>t;
	int ns=s.length(),nt=t.length();

	bool judge=false;
	for(int i=ns-nt;i>=0;i--){
		if(s[i]==t[0] or s[i]=='?'){
			bool flag=true;
			rep(j,nt){
				if(s[i+j]!=t[j]){
					if(s[i+j]=='?') continue;
					else flag=false;
				}
			}
			if(flag){
				rep(j,nt) s[i+j]=t[j];
				rep(j,ns){
					if(s[j]=='?') s[j]='a';
				}
				judge=true; break;
			}
		}
	}
	if(judge) cout<<s<<endl;
	else cout<<"UNRESTORABLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
N = int(input())
S = input()

T = [[0 for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(i + 1, N):
    if S[i] == S[j]:
      T[i][j] += T[i - 1][j - 1] + 1

answer = 0
for i in range(N):
  for j in range(N):
    if T[i][j] and j - i >= T[i][j]:
      answer = max(answer, T[i][j])
print(answer)


Measured memory_bytes: 245768
import sys
import heapq


input = sys.stdin.readline
N = int(input())
lst_A = [int(input()) for _ in range(N)]


hq = []
for val in lst_A:
    val *= -1
    heapq.heappush(hq, val)
m1 = -(heapq.heappop(hq))
m2 = -(heapq.heappop(hq))


for v in lst_A:
    print(m2 if v == m1 else m1)

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

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

  vector<vector<int>> inputs(m, vector<int>(2));
  map<int, vector<int>> edge;

  for (int i = 0; i < m; ++i) {
    cin >> inputs[i][0] >> inputs[i][1];
    edge[inputs[i][0]].push_back(inputs[i][1]);
    edge[inputs[i][1]].push_back(inputs[i][0]);
  }

  int cnt = m;
  for (int i = 0; i < m; ++i) {
    int start = inputs[i][0];
    int goal = inputs[i][1];
    
    queue<int> que;
    que.push(start);
    unordered_set<int> visited;
    visited.insert(start);
    
    while (!que.empty()) {
      int curr = que.front();
      que.pop();
      if (curr == goal) {
        --cnt;
        break;
      }
      for (int next : edge[curr]) {
        if (curr == start and next == goal) continue;
        if (visited.find(next) != visited.end()) continue;
        que.push(next);
        visited.insert(next);
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    int c[510];
    int s[510];
    int f[510];
    for(int i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    for(int i=0;i<n-1;i++){
        int sum=c[i]+s[i];
        for(int j=i+1;j<n-1;j++){
            if(sum>s[j]){
            sum=s[j]+f[j]*((sum-s[j]+f[j]-1)/f[j])+c[j];
            }
            else{
                sum=s[j]+c[j];
            }
        }
        cout<<sum<<endl;

    }
    cout<<0<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int num,a,b,c;
  cin>>num;
  a = num/100;
  b = (num%100)/10;
  c = num%10;
  if(a==1){
    a = 9;
  }
  else if(a==9){
    a =1;
  }
  
  if(b==1){
    b = 9;
  }
  else if(b==9){
    b =1;
  }
  if(c==1){
    c = 9;
  }
  else if(c==9){
    c =1;
  }
  
  cout<< 100*a + 10*b +c<<endl;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  998244353
#define mod1 1000000009
#define var    int n,m,i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

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

int n,m,a[200005],b[200005],p[200005],sz[200005];
vector<pair<int,pii> > inc,dec;

priority_queue<pii> pq;

int ans[200005];

int Gets(int u)
{
    if(u==p[u])return u;
    else return p[u] = Gets(p[u]);
}

void Union(int u,int v)
{
    u = Gets(u);
    v = Gets(v);

    if(u==v)return;

    p[u] = v;
    sz[v] += sz[u];
}
int main()
{
    int t;
    sf(n);
    int x,y;
    for(int i=1;i<=n;i++)
    {
        p[i] = i;
        sf(x);sf(y);
        inc.pb({x,{y,i}});
        sz[i]=1;
    }
    sort(inc.begin(),inc.end());

    for(int i=n-1;i>=0;i--)
    {
        if(pq.empty()==0 && pq.top().xx>inc[i].yy.xx)
        {
            x = pq.top().xx,y=pq.top().yy;
            while(pq.empty()==0 && pq.top().xx>inc[i].yy.xx)
            {
                Union(pq.top().yy,inc[i].yy.yy);
                pq.pop();
            }
            pq.push({x,y});
        }
        pq.push({inc[i].yy.xx,inc[i].yy.yy});
    }

    for(int i=1;i<=n;i++)
    {
        ans[i] = sz[Gets(i)];
        pf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 11136
#include<stdio.h>
int main(void){
    int a;
    int i;
    int f;
    scanf("%d",&a);
    int b;
    for(i=1;i<=a;i++){
        if(i%3==0){
            f=1;
        }
        for(b=i;b>=3;b+=0){
            if(b%10==3){
                f=1;
            }
            b = b/10;
        }
        if(f==1){
            printf(" %d",i);
            f=0;
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
require "prime"
Q=gets.to_i
A=Hash.new{|h,k|h[k-1]}
A[0]=0
A[1]=0
A[3]=1
5.step(10**5, 4){|x|
    if x.prime? && ((x+1)/2).prime?
        A[x]=A[x-1]+1
    else
        A[x]=A[x-1]
    end
}
#warn A.inspect
Q.times{
    l,r=gets.split.map(&:to_i)
    puts A[r]-A[l-1]
}


Measured memory_bytes: 15432
def C():
    X, K, D = map(int, input().split())
    X = abs(X)
    if X//D >= K:
        return X - K*D

    pos1 = abs(X - (X//D)*D)
    pos2 = abs(X - (X//D+1)*D)

    if pos1 > pos2:
        K -= X//D+1
    else:
        K -= X//D
    
    if K % 2 == 0:
        return min(pos1, pos2)
    else:
        return abs(min(pos1, pos2) - D)

print(C())

Measured memory_bytes: 8956
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[-2] = abs(h[-1] - h[-2])

for i in range(0, n-2)[::-1]:
    dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])

print(dp[0])


Measured memory_bytes: 13928
x, y = map(int, input().split())

c = (4*x-y)/2
t = (y-2*x)/2

if  c>= 0 and  t>= 0:
	if c >= 1 or t >= 1:
		if c.is_integer() == 1 and t.is_integer() == 1:
			print('Yes')
		else:
			print('No')
	else:
		print('No')
else:
	print('No')

Measured memory_bytes: 9188
import math

n = int(input())
lL = sorted(list(map(int, input().split(" "))))

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if len(set([lL[i], lL[j], lL[k]])) != 3:
                continue
            sm, no, lo = sorted([lL[i], lL[j], lL[k]])
            if lo < no + sm:
                ans += 1

print(ans)

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

ll n, a[1010],ans;
int main(){
  cin >> n;
  ans = 1;
  rep(i,2,n+1){
    int div = i;
    rep(j,2,div+1){
      while(div%j==0){
        div /= j;
        a[j]++;//a[2]->素因数2をどれくらい所持しているか
      }
    }
  }
  rep(i,1,n+1){
    ans = (ans*(a[i]+1)%(INTMAX+7));
    // cout << ans << endl;
  }
  cout << ans <<  endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	}while(isdigit(ch));
	return res * sign;
}
int a;
int main()
{
	cin >> a;
	cout << a * a * a << endl;
	return 0;
}
//A

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

max_values = [-1, -1]
max_indices = [-1, -1]
for i in range(N):
  a = int(input())
  if a>max_values[0]:
    max_values[0] = a
    max_indices[0] = i
  elif a>max_values[1]:
    max_values[1] = a
    max_indices[1] = i

for i in range(N):
  if max_indices[0] != i:
    print(max_values[0])
  else:
    print(max_values[1])

Measured memory_bytes: 4540
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;

int main(){
    int N;cin>>N;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(),A.end());
    int ans=0;
    long long sum=0;
    REP(i,N-1){
        sum+=A[i];
        if(A[i+1]<=2*sum) ans++;
        else ans=0;
    }
    ans++;
    cout<<ans<<endl;
}

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

#define LENGTH ((100))
void Trace(int a[], int n)
{
    int i;
    for (int i = 0; i < n; i++) {
        if (i > 0) { 
            printf(" ");
        }
        printf("%d", a[i]);
    }
    printf("\n");
}

void InsertSort(int a[], int n)
{
    int i, j, v;
    for (int i = 1; i < n; i++) {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        Trace(a, n);
    }
}

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

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

    return 0;
}


Measured memory_bytes: 2096
while True:
    n = int(input())
    if not n:
        break
    s = input().strip()

    while n:
        prev, cnt, new = s[0], 1, ''
        for c in s[1:]:
            if c == prev:
                cnt += 1
            else:
                new += str(cnt) + prev
                prev, cnt = c, 1
        new += str(cnt) + prev
        s = new
        n -= 1
    print(s)

Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    while (cin >> n >> k) {
        vector<ll>a(n),b(n);
        for (auto &i : a) {
            cin >> i;
        }
        for (auto &i : b) {
            cin >> i;
        }
        sort(all(a));
        sort(all(b));
        reverse(all(b));
        ll l = -1, r = 1e12;
        while (r - l > 1) {
            ll mid = (l + r) >> 1;
            ll sum = 0;
            for (int i = 0 ; i < n ; i++) {
                ll mx = mid / b[i];
                sum += max(0LL,a[i] - mx);
            }
            if (sum <= k) {
                r = mid;
            }
            else {
                l = mid;
            }
        }
        cout << r << endl;
    }
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<27);

using namespace std;

typedef long long ll;
typedef long double ld;

int n, m, p, q, r;
int C[101][101], V[101][101];

void floyd() {
  rep(k,m) {
    rep(i,m) {
      rep(j,m) {
        C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
        V[i][j] = min(V[i][j], V[i][k] + V[k][j]);
      }
    }
  }
}

int main() {
  while(cin >> n >> m, n) {
    rep(i, m) rep(j, m) {
      C[i][j] = ((i==j)?0:INFTY);
      V[i][j] = ((i==j)?0:INFTY);
    }
    
    rep(i, n) {
      int tmp_i, tmp_j, ti, co;
      cin >> tmp_i >> tmp_j >> co >> ti;
      C[tmp_i-1][tmp_j-1] = co;
      C[tmp_j-1][tmp_i-1] = co;
      V[tmp_i-1][tmp_j-1] = ti;
      V[tmp_j-1][tmp_i-1] = ti;      
    }

    floyd();

    int k;
    cin >> k;

    rep(i,k) {
      cin >> p >> q >> r;
      if(r == 0)
        cout << C[p-1][q-1] << endl;
      else
        cout << V[p-1][q-1] << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1240
c = [[0 for j in range(3)] for i in range(3)]

for i in range(3):
    c[i] = [int(i) for i in input().split()]

for i in range(3):
    if not c[i % 3][0] - c[(i + 1) % 3][0] == \
                    c[i % 3][1] - c[(i + 1) % 3][1] == \
                    c[i % 3][2] - c[(i + 1) % 3][2]:
        print("No")
        exit()
for i in range(3):
    if not c[0][i % 3] - c[0][(i + 1) % 3] == \
                    c[1][i % 3] - c[1][(i + 1) % 3] == \
                    c[2][i % 3] - c[2][(i + 1) % 3]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3064
#include<stdlib.h>
#define R(i,a,n)for(int i=a;i<n;i++)
#define m(x,y)(x<y?x:y)
n,x,y,a[2000];
main(){
	scanf("%d%d%d",&n,&x,&y);
	R(i,1,n)R(j,i+1,n+1)a[m(abs(x-i)+abs(y-j)+1,m(abs(y-i)+abs(x-j)+1,j-i))]++;
	R(i,1,n)printf("%d\n",a[i]);}

Measured memory_bytes: 128