akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll M,T,P,R; cin >> M >> T >> P >> R;
        if(!M && !T && !P && !R) break;
        ll solve[55][15] = {};
        ll pena[55][15] = {};
        while(R--){
            ll m,t,p,b; cin >> m >> t >> p >> b; t--; p--;
            if(!b){
                solve[t][p] = 1;
                pena[t][p] -= m;
            }else{
                pena[t][p] -= 20;
            }
        }
        vector<tapu> ans(T);
        rep(i,T){
            ll a=0, b=0, c=0;
            rep(j,P){
                a += solve[i][j];
                if(solve[i][j]) b += pena[i][j];
            }
            c = i+1;
            ans[i] = tie(a,b,c);
        }
        sort(rall(ans));
        rep(i,T){
            ll a,b,c;
            tie(a,b,c) = ans[i];
            cout << c;
            if(i<T-1){
                ll d,e,f; tie(d,e,f) = ans[i+1];
                if(a==d && b==e) cout << '=';
                else cout << ",";
            }
        }
        cout << endl;
        rep(i,T) rep(j,P) solve[i][j] = 0, pena[i][j] = 0;
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000005
#define MOD 1000000007
#define LOG 20
#define EPS 0.000000001
#define M 305
using namespace std;

int n,k;
int h[N];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>h[i];
	sort(h+1,h+1+n);
	ll sum=0;
	for(int i=1;i<=n-k;i++) sum+=h[i];
	cout<<sum;

}

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

int main() {
  string S;
  cin >> S;
  int k= S.size();
  int a=0;
  for(int i=0;i<k;i++){
    if(S.at(i)=='o'){
      a++;
    }
  }
  if((8-a)<=15-k){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


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

int N;
void input()
{
    cin>>N;
}

void solve()
{
    if(N%1000==0) cout<<0<<endl;
    else cout<<1000-(N%1000)<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	string s; cin >> s;
	map<char,ll> mp;
	rep(i,4) mp[s[i]]++;
	if(mp.size()!=2) puts("No");
	else{
		for(auto i : mp){
			if(i.second != 2){
				puts("No");
				return 0;
			}
		}
		puts("Yes");
	}
}

Measured memory_bytes: 256
let flip f x y = f y x

let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d %d %d" @@ fun a b k ->
  let g = gcd a b in
  Printf.printf "%d\n" @@
  flip List.nth (k - 1) @@
  List.filter (fun d -> g mod d = 0) @@
  List.rev @@ Array.to_list @@ Array.init g succ



Measured memory_bytes: 384
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a_num = bisect.bisect_left(A, b)
    c_num = N - bisect.bisect_right(C, b)
    ans += a_num * c_num

print(ans)


Measured memory_bytes: 23092
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }
        if(n <= k) {
            System.out.println(0);
            return;
        }
        Collections.sort(a);
        for (int i = 0; i < k; i++) {
            a.remove(a.size() - 1);
        }
        long ans = 0l;
        for (Integer i : a) {
            ans += i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 64936
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair < int,int> pii;
typedef pair < ll, ll > pll;

const int N = 1e5 + 500;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int BASE = 31337;
const int INF = 0x3f3f3f3f;

ll n,a[N],lo[N],hi[N];

int main(){
    scanf("%lld",&n);
    for(int i = 0;i<n;i++)
        scanf("%lld",a+i);
    lo[n] = 2;
    hi[n] = 2;
    for(int i = n - 1;i>=0;i--){
        if(lo[i + 1] % a[i])
            lo[i] = (lo[i + 1] - lo[i + 1] % a[i] + a[i]);
        else
            lo[i] = lo[i + 1];
        hi[i] = (hi[i + 1] - hi[i + 1] % a[i]) + a[i] - 1;
        if(lo[i] > hi[i]) {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld %lld\n",lo[0],hi[0]);
    return 0;
}


Measured memory_bytes: 2560
/*
Chase excellence, rating will come automatically.
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans;
    ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

    if (a <= 0 and b >= 0)
        ans = max(ans, 0LL);
    else if (c <= 0 and d >= 0)
        ans = max(ans, 0LL);

    cout << ans << "\n";

}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int p[15][15];

int main() {

    ios_base::sync_with_stdio(false);cin.tie(0);

    int n,d;
    cin>>n>>d;

    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>p[i][j];
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int s = 0;
            for(int k=0;k<d;k++){
                s+=(p[i][k]-p[j][k])*(p[i][k]-p[j][k]);
            }
            for(int k=1;k<=s/2+1;k++){
                if(k*k==s){
                    ans++ ;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using std::sort;
main(){
    int x[10],i;
    for(i=0;i<10;i++)
    scanf("%d",&x[i]);
    sort(x,x+10);
    printf("%d\n%d\n%d\n",x[9],x[8],x[7]);
}

Measured memory_bytes: 1044
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] >= 'a' && str[i] <= 'z')
			{
				str[i] -= 32;
			}
			cout << str[i];
		}
		cout << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  deque<ll> dq;
  bool hasMinus = false, hasPlus = false;
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  REP(i, n) {
    if(a[i] < 0) hasMinus = true;
    if(a[i] > 0) hasPlus = true;
    dq.push_back(a[i]);
  }

  vector<string> ans_s;
  ll val = 0LL;
  if(hasPlus && hasMinus) {
    ll fv = dq.front(); dq.pop_front();
    ll bv = dq.back(); dq.pop_back();     
    //cerr << "current fv:" << fv << " bv:" << bv << endl;
    while(!dq.empty()) {
      ll fvv = dq.front(); dq.pop_front();
      ll tmp;
      if(fvv < 0) {
        tmp = bv;        
        bv += abs(fvv);
      } else {
        tmp = fv;
        fv -= abs(fvv);
      }
      ans_s.push_back(to_string(tmp)+" "+to_string(fvv));
    }
    ans_s.push_back(to_string(bv)+" "+to_string(fv));
    val = bv-fv;
  } else if(hasMinus) {
    ll fv = dq.front(); dq.pop_front();
    ll bv = dq.back(); dq.pop_back();  
    while(!dq.empty()) {
      ll fvv = dq.front(); dq.pop_front();
      ll tmp = bv;        
      bv -= fvv;     
      ans_s.push_back(to_string(tmp)+" "+to_string(fvv));
    }
    ans_s.push_back(to_string(bv)+" "+to_string(fv));
    val = bv-fv;  
  } else {
    ll fv = dq.front(); dq.pop_front();
    ll bv = dq.back(); dq.pop_back();  
    while(!dq.empty()) {
      ll fvv = dq.front(); dq.pop_front();
      ll tmp = fv;
      fv -= fvv;
      ans_s.push_back(to_string(tmp)+" "+to_string(fvv));
    }
    ans_s.push_back(to_string(bv)+" "+to_string(fv));
    val = bv-fv;      
  }
  cout << val << endl;
  for(auto &e: ans_s) cout << e << endl;

  return 0;
}


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

using namespace std;
#define ll long long int


int main()
{
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    for(auto& w:a) cin >> w;
    int ans = k-(a[0]+k-a[n-1]);
    for(int i=1;i<n;i++){
        ans = min(ans, k-(a[i]-a[i-1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True


def main():
    N, K = MI()
    H = LI()
    H = sorted(H, reverse=True)
    ans = 0

    if len(H) <= K:
        print(0)
        return

    for h in H[K:]:
        ans += h

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84760
n=int(input())
a=list(map(int,input().split()))
s=0
j=0
if 1 not in a:
  print(-1)
  exit()
for k in range(n):
  for i in range(j,n):
    if a[i]==k+1:
      s=s+i-j
      j=i+1
      break
  else:
    print(s+(n-j))
    exit()
print(s)
  
  

Measured memory_bytes: 26140
#include <iostream>
#include <string>
using namespace std;
int main(void){
    long N;
    cin >> N;
    long sum=0;
    
    for(long i=0;i<=N;i++){
        if(i % 5 !=0 && i % 3 != 0){
            sum+=i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3636
s=input()

tuki=['01','02','03','04','05','06','07','08','09','10','11','12']

a=str(s[0])+str(s[1])
b=str(s[2])+str(s[3])

flag=[1,2,3]

if a not in tuki:
    flag.remove(1)
    flag.remove(3)
if b not in tuki:
    flag.remove(2)
    if 3 in flag:
        flag.remove(3)

if flag==[]:
    print('NA')
elif flag[-1]==3:
    print('AMBIGUOUS')
elif flag[-1]==2:
    print('YYMM')
elif flag[-1]==1:
    print('MMYY')

Measured memory_bytes: 3064
for i in range(int(input())):
    x = int(input())
    print("Case " + str(i+1) + ":")
    for _ in range(10):
        x = str(int(x)**2)
        if len(x) < 8 : x = (8-len(x))*"0" + x
        x = x[2:6]
        print(int(x))

Measured memory_bytes: 7592
#include <iostream>

using namespace std;

int main()
{
	const int M = 8;
	int N, a;
	bool is_contains[M];
	int min, max;
	min = max = 0;
	cin >> N;

	for (int i = 0; i < M; i++)
		is_contains[i] = false;

	for (int i = 0; i < N; i++)
	{
		cin >> a;

		if (a >= 3200)
			max++;
		else
		{
			if (!is_contains[a / 400])
			{
				min++;
				max++;
				is_contains[a / 400] = true;
			}
		}
	}

	cout << (min == 0 ? 1 : min) << " " << max << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N,K;
  cin>>N>>K;
  vector<ll> H(N);
  for(ll i=0;i<N;i++) {
cin>>H[i];
  }
  sort(all(H));
  reverse(all(H));
  
  ll ans=0;
  for(ll i=K;i<N;i++) {
ans+=H[i];
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 4704
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    int n, m;
    cin >> n >> m;
    if(m % 2 == 0) {
        // split the tourneys in the middle
        int low1 = 1;
        int high1 = m + 1;
        for(int i = 0; i < m / 2; i++) {
            cout << low1 << " " << high1 << endl;
            low1++;
            high1--;
        }
        low1 = m + 2;
        high1 = 2*m+1;
        for(int i = 0; i < m / 2; i++) {
            cout << low1 << " " << high1 << endl;
            low1++;
            high1--;
        }
    } else {
        int low1 = 1;
        int high1 = m;
        for(int i = 0; i < m / 2; i++) {
            cout << low1 << " " << high1 << endl;
            low1++;
            high1--;
        }
        low1 = m + 1;
        high1 = 2*m+1; 
        for(int i = 0; i < (m + 1) / 2; i++) {
            cout << low1 << " " << high1 << endl;
            low1++;
            high1--;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
package main

import "fmt"

func main() {
	for {
		var H, W int
		var col string
		fmt.Scan(&H, &W)
		if H == 0 {
			break
		}
		for i := 0; i < W; i++ {
			col += "#"
		}
		for i := 0; i < H; i++ {
			fmt.Println(col)
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1120
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <utility>

using namespace std;

typedef pair<vector<int>, int> P;

int zeroPosition( vector<int> a ) {
    for ( int i = 0; i < 9; i++ ) {
	if ( a[i] == 0 ) return i;
    }

    return -1;
}

vector<int> swapDigit( vector<int> v, int a, int b ) {
    vector<int> ret = v;
    int x = v[a];
    int y = v[b];
    ret[a] = y;
    ret[b] = x;

    return ret;
}

bool isSame( vector<int> a, vector<int> b ) {
    for ( int i = 0; i < 9; i++ ) {
	if ( a[i] != b[i] ) return false;
    }

    return true;
}

int convert( vector<int> a ) {
    int ret = 0;
    for ( int i = 0; i < 9; i++ ) {
	ret *= 10;
	ret += a[i];
    }

    return ret;
}

int main()
{
    set<int> S;
    queue<P> Q;
    vector<int> start;
    vector<int> goal;		// 123456780
    for ( int i = 0; i < 9; i++ ) {
	goal.push_back( (i + 1) % 9 );
    }

    for ( int i = 0; i < 9; i++ ) {
	int d;
	scanf("%d", &d);
	start.push_back( d );
    }

    S.insert( convert(start) );
    Q.push( make_pair( start, 0 ) );
    int ans = 0;

    while ( !Q.empty() ) {
	P p = Q.front(); Q.pop();
	if ( isSame( p.first, goal) ) {
	    ans = p.second;
	    break;
	}
	int pos = zeroPosition( p.first );
	
	if ( ( pos % 3 ) != 0 ) { // ???????§???????
	    vector<int> v = swapDigit( p.first, pos, pos - 1 );
	    if ( S.find( convert(v) ) == S.end() ) {
		Q.push( make_pair( v, p.second + 1 ) );
		S.insert( convert(v) );
	    }
	}

	if ( ( pos % 3 ) != 2 ) { // ???????§???????
	    vector<int> v = swapDigit( p.first, pos, pos + 1 );	    
	    if ( S.find( convert(v) ) == S.end() ) {
		Q.push( make_pair( v, p.second + 1 ) );
		S.insert( convert(v) );
	    }
	}

	if ( pos > 2 ) { // ???????§???????
	    vector<int> v = swapDigit( p.first, pos, pos - 3 );	    	    
	    if ( S.find( convert(v) ) == S.end() ) {
		Q.push( make_pair( v, p.second + 1 ) );
		S.insert( convert(v) );
	    }
	}

	if ( pos < 6 ) { // ???????§???????
	    vector<int> v = swapDigit( p.first, pos, pos + 3 );	    	    
	    if ( S.find( convert(v) ) == S.end() ) {
		Q.push( make_pair( v, p.second + 1 ) );
		S.insert( convert(v) );
	    }
	}
    }

    printf("%d\n", ans);

    return 0;
}

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

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

constexpr int MAX_N = 200000;
constexpr int64 INF = 1LL << 60;

vector<int> tree[MAX_N];
int64 as[MAX_N], dp[MAX_N + 1];
int ans[MAX_N];

void DFS(int u, int p) {
    int i = lower_bound(begin(dp), end(dp), as[u]) - begin(dp);
    int64 old = dp[i];
    dp[i] = as[u];

    ans[u] = lower_bound(begin(dp), end(dp), INF) - begin(dp);
    for (int c : tree[u]) {
        if (c == p) continue;
        DFS(c, u);
    }
    dp[i] = old;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

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

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    fill(begin(dp), end(dp), INF);
    DFS(0, -1);

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

    return 0;
}



Measured memory_bytes: 32856
N = list(map(int,input().split()))
k = int(input())

for i in range(k):
  if N[1] <= N[0]:
    N[1] = N[1] * 2
  elif N[2] <= N[1]:
    N[2] = N[2] * 2
  
if N[1] > N[0] and N[2] > N[1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9004
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

long double a, b, c, d; int n;

long double calc(long double pos) {
	return a * pos * pos * pos + b * pos * pos + c * pos + d;
}

long double find_answer(long double L, long double R, bool ok) {
	long double p1 = calc(L), p2 = calc(R); if (p1 > p2) swap(p1, p2);
	if (!(p1 <= 1e-14 && -1e-14 <= p2)) return -1e9;

	long double M;
	for (int i = 0; i < 100; i++) {
		M = (L + R) / 2;
		long double ret = calc(M);
		bool res = false; if (ret > 0) res = true;

		if ((ok ^ res) == false) R = M;
		else L = M;
	}
	return M;
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b >> c >> d;
		d /= a; c /= a; b /= a; a = 1;

		long double A = 3.0 * a, B = 2.0 * b, C = c;
		vector<tuple<long double, long double, bool>> T;
		if (B * B - 4.0 * A * C < -1e-5) {
			T.push_back(make_tuple(-10000, 10000, true));
		}
		else {
			long double V = sqrtl(B * B - 4.0 * A * C);
			long double W1 = (-B - V) / (2.0 * A);
			long double W2 = (-B + V) / (2.0 * A);
			T.push_back(make_tuple(-10000, W1, true));
			T.push_back(make_tuple(W1, W2, false));
			T.push_back(make_tuple(W2, 10000, true));
		}
		vector<long double>U;
		for (int j = 0; j < T.size(); j++) {
			long double V = find_answer(get<0>(T[j]), get<1>(T[j]), get<2>(T[j]));
			if (V >= -1e8) U.push_back(V);
		}
		sort(U.begin(), U.end());

		int t1 = 0, t2 = 0;
		for (int j = 0; j < U.size(); j++) {
			if (U[j] < -1e-5) t1++;
			else t2++;
		}
		if (fabs(d) < 1e-10) t2--;
		if (fabs(c) < 1e-10 && fabs(d) < 1e-10) t2--;
		if (fabs(b) < 1e-10 && fabs(c) < 1e-10 && fabs(d) < 1e-10) t2--;
		cout << t2 << " " << t1 << endl;
	}
	return 0;
}


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

int main() {
  
  int N;
  cin>>N;
  vector<string> vec(N);
  vector<int> vec2(4);
  for(int i=0; i<N; i++){
    cin>>vec.at(i);
  }
  for(int i=0; i<N; i++){
    if (vec.at(i)=="AC"){
      vec2.at(0)++;
    }
    else if (vec.at(i)=="WA"){
      vec2.at(1)++;
    }
    else if (vec.at(i)=="TLE"){
      vec2.at(2)++;
    }
    else{
      vec2.at(3)++;
    }
  }
  cout<<"AC"<<" "<<"x"<<" "<<vec2.at(0)<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<vec2.at(1)<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<vec2.at(2)<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<vec2.at(3)<<endl;
}


Measured memory_bytes: 6424
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var X = Sarray()[0];
            var max = 1L;
            for (var i = 2; i * i <= X; ++i)
            {
                var t = i * i;
                while (t * i <= X)
                    t *= i;
                max = Max(max, t);
            }
            WriteLine(max);
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28036
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(auto& i: L) cin >> i;
  sort(begin(L), end(L));
  auto ans = 0;
  for(auto a=0; a<N; ++a) for(auto b=a+1; b<N; ++b) {
    auto c = lower_bound(begin(L)+b+1, end(L), L[a]+L[b]) - begin(L);
    ans += c - b - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
K,N = map(int,input().split())
A = []
A = list(map(int,input().split()))
last = 0
maxd = 0
x = 0
for i in range(N):
  now = A[i]
  d = now - last
  if(maxd < d):
    maxd = d
    x = i
  last = now
if(maxd < (A[0] + K - A[N-1])):
  print(A[N-1] - A[0])
else:
  print(K - A[x] + A[x-1])

Measured memory_bytes: 26444
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 100001;

vi g[N];
int G[N];

int dfs(int c, int p) {
  rep(i,0,g[c].size()) {
    int u = g[c][i];
    if(u != p) {
      G[c] ^= 1 + dfs(u, c);
    }
  }
  return G[c];
}

int main() {
  int n;
  S(n);
  rep(i,0,n-1) {
    int u,v;
    S2(u,v);
    g[u].pb(v);
    g[v].pb(u);
  }
  int x = dfs(1, -1);
  if(x) {
    printf("Alice\n");
  } else {
    printf("Bob\n");
  }
  return 0;
}


Measured memory_bytes: 12416
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

struct UnionFind
{
  vector<int> num;
  UnionFind(int n)
  {
    num.assign(n, -1);
  }
  int root(int x)
  {
    if (num[x] < 0)
      return x;
    return num[x] = root(num[x]);
  }
  bool unite(int x, int y)
  {
    x = root(x), y = root(y);
    if (x == y)
      return false;
    if (-num[x] < -num[y])
      swap(x, y);
    num[x] += num[y];
    num[y] = x;
    return true;
  }
  int size(int x)
  {
    return -num[root(x)];
  }
};

int main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long K;
  scanf("%lld", &K);
  UnionFind uf(N);
  vector<set<int>> tomo(N), block(N);
  for (int i = 0; i < M; i++)
  {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    uf.unite(A, B);
    tomo[A].insert(B);
    tomo[B].insert(A);
  }
  for (int i = 0; i < K; i++)
  {
    int C, D;
    cin >> C >> D;
    C--;
    D--;
    if (uf.root(C) == uf.root(D))
    {
      block[C].insert(D);
      block[D].insert(C);
    }
  }
  for (int i = 0; i < N; ++i)
  {
    cout << uf.size(i) - tomo[i].size() - block[i].size() - 1 << " \n"[i == N - 1];
  }

  return 0;
}


Measured memory_bytes: 29312
#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 treeMinimum(Node x){ 
//
// }
//
// Node treeSearch(Node u, int k){
//
//
// }
//
// Node treeSuccessor(Node x){
//
//
// }
//
// void treeDelete(Node z){
//   Node y; // node to be deleted
//   Node x; // child of y
//
//
//
// }

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

    // node生成
    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;

    // yよりzが小さければ左の子に
    else if(z->key < y->key) y->left = z;

    // yより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);
           Node t = treeSearch(root, x);
           if ( t != NIL ) printf("yes\n");
           else printf("no\n");
           } */

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

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

        /* else if ( com[0] == 'd' ){
           scanf("%d", &x);
           treeDelete(treeSearch(root, x));
           } */
    }

    return 0;
}

Measured memory_bytes: 24036
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    int ans = 0;
    int mn = 200005;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a < mn) {
            ans++;
            mn = a;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
fun main(args: Array<String>){
    val input = readLine()!!.split(' ')
                            .map  { it.toInt() }
    val result = D1015B(
                    numberOfBall  = input[0]
                   ,numberOfPaint = input[1]
                 ).judge()
    println(result)
}
 
class D1015B(
  val numberOfBall:  Int
 ,val numberOfPaint: Int
){
    fun judge(): Int{
        return numberOfPaint * 
               Math.pow(numberOfPaint - 1.toDouble(), numberOfBall-1.toDouble())
                   .toInt()
    }
}

Measured memory_bytes: 38136
import math

x = int(input())

def is_prime(n: int) -> bool:
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(x):
        break
    x += 1
print(x)


Measured memory_bytes: 2940
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+9;
const ll MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    int N;
    cin >> N;
    string S1,S2;
    cin >> S1 >> S2;
    ll ans=0;

    REP(i,N){
        if(i==0){
            if(S1[i]==S2[i]){
                ans=3;
            }else{
                ans=6;
                i++;
            }
        }else{
            if(S1[i]==S2[i]){
                if(S1[i-1]==S2[i-1]){
                    ans*=2;
                    ans%=MOD;
                }
            }else{
                if(S1[i-1]==S2[i-1]){
                    ans*=2;
                }else{
                    ans*=3;
                }
                
                ans%=MOD;
                i++;
            }
        }   
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

using ll = long long;
int N, M;
vector<int> Sh, St;
int sumH;
int sumT;

bool solve()
{
    for (int i = 0; i < M; ++i)
    {
        int xH = sumH - Sh[i];
        for (int j = 0; j < N; ++j)
        {
            int xT = sumT - St[j] + Sh[i];
            xH += St[j];
            if (xH == xT)
            {
                cout << St[j] << " " << Sh[i] << endl;
                return true;
            }
            xH -= St[j];
            
        }
    }
    return false;
}
int main(void)
{
    while (1)
    {
        cin >> N >> M;
        if (N == 0 && M == 0)
            break;
        St.resize(N);
        Sh.resize(M);

        for (int i = 0; i < N; ++i)
        {
            cin >> St[i];
        }
        for (int i = 0; i < M; ++i)
        {
            cin >> Sh[i];
        }
        sumH = accumulate(Sh.begin(), Sh.end(), 0);
        sumT = accumulate(St.begin(), St.end(), 0);
        if (!solve())
        {
            cout << "-1" << endl;
        }
    }

    return 0;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;
const int logn = 45;

class Shop{
public:
	int a, b;
	bool operator < (const Shop &oth)const{
		if(!a && !oth.a)
			return b < oth.b;
		return 1ll * a * (oth.b + 1) > 1ll * oth.a * (b + 1);
	}
}s[maxn];

int n, T, ans;
int sum[maxn];
int dp[maxn][logn];

inline int go(int t, Shop cur){
	ll ret = min(1ll * T + 1, t + 1 + 1ll * cur.a * (t + 1) + cur.b);
	return ret;
}

int main(){
	scanf("%d%d", &n, &T);
	FOR(i, 0, n){
		scanf("%d%d", &s[i].a, &s[i].b);
	}
	sort(s, s + n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	FOR(i, 0, n){
		if(!s[i].a){
			FOR(j, i, n)
				sum[j] = min(T + 1, (j == i ? 0 : sum[j - 1]) + 1 + s[j].b);
			FOR(j, 0, logn) if(dp[i][j] <= T){
				int pos = upper_bound(sum + i, sum + n, T - dp[i][j]) - sum - i;
				ans = max(ans, j + pos);
			}
			break;
		}
		FOR(j, 0, logn) if(dp[i][j] <= T){
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			if(go(dp[i][j], s[i]) <= T)
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], go(dp[i][j], s[i]));
		}
	}
	if(s[n - 1].a){
		FOR(j, 0, logn) if(dp[n][j] <= T)
			ans = j;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 37760
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
const double EPS = 1e-8, INF = 1e12, PI = 2 * acos(0.0);
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














double A, B, X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> X;

	double half = A * A * B / 2;
	double ans;

	if (X < half) ans = atan(A * B * B / (2.0 * X));
	else ans = atan((2.0 * B - 2.0 * X / (A * A)) / A);

	ans = ans / PI * 180;

	printf("%.10f\n", ans);
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll signed long long int
#define MAXX 1000005
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
 
ll a[MAXX], b[MAXX];
 
signed main()
{
	FAST;
	ll n, m = 0;
	cin >> n;
	for(ll i = 1; i <= n; i++){
		if(i %3 != 0 && i%5 != 0){
			m += i;
		}
	}
	cout << m;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
// void c_p_c()
// {
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// // #ifndef  ONLINE_JUDGE
// // 	freopen("input.txt", "r", stdin);
// // 	freopen("output.txt", "w", stdout);
// // #endif
// }
int32_t main()
{
	//c_p_c();
	int n, h, w;
	cin >> n >> h >> w;
	int c = 0;
	while (n--)
	{
		int x, y;
		cin >> x >> y;

		if (x >= h && y >= w)
			c++;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
import math

# A:時針の長さ
# B:分針の長さ
# H:時間
# M:分
A, B, H, M = map(int, input().split())

# 時針のなす角
H_angle = H * 30 + (M / 60 * 30)
# 分針のなす角
M_angle = M * 6

# 針のなす角
H_M_angle = abs(H_angle - M_angle)

cosHM = math.cos(math.radians(H_M_angle))

C2 = A**2 + B**2 - 2*A*B*cosHM

print(math.sqrt(C2))


Measured memory_bytes: 9400
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int A;
        int B;
        Scanner sc = new Scanner(System.in);
        A=sc.nextInt();
        B=sc.nextInt();
        int ans=A+B;
        if(ans<A-B){
            ans=A-B;
        }
        if(ans<A*B){
            ans=A*B;
        }
        System.out.println(ans);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
    }
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

/***** MAIN *****/
signed main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  map<int,int> mp;
  int bridge = y - x;
  for(int i = 0; i < n; ++i) {
    for(int j = i+1; j < n; ++j) {
      int tmp = min(j-i, abs(x-i)+1+abs(j-y));
      ++mp[tmp];
    }
  }
  REP(i,n-1) {
    cout << mp[i+1] << endl;
  }
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 384
#include <stdio.h>
int main ()
{

  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  
  if(a<b&&b<c){
    printf("Yes\n");
  }
  
  if(a>=b||b>=c){
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
pair<int,int>a[214514];
signed main(){
	ic(n) 
	c(3*n*n)
}	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>

using namespace std;

int main()
{
    
	long long int a, b, c;
	cin >> a >> b >> c;
	
	int ans = 0;

	if (a == b && b == c) {
		if (a % 2 == 1) {
			ans = 0;
		}
		else {
			ans = -1;
		}
	}
	else {

		while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			long long int wk_a, wk_b, wk_c;

			wk_a = b / 2 + c / 2;
			wk_b = c / 2 + a / 2;
			wk_c = a / 2 + b / 2;
			
			a = wk_a;
			b = wk_b;
			c = wk_c;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;

}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s,t;
    cin >> s >> t;
    // dp[i][j]: s[i], t[j]までみた時のLCS
    vector<vector<int>> dp(s.length()+1, vector<int>(t.length()+1));
    vector<vector<pair<int, int>>> history(s.length()+1, vector<pair<int, int>>(t.length()+1));
    for(int i=0; i<=s.length(); i++) dp[i][0] = 0;
    for(int i=0; i<=t.length(); i++) dp[0][i] = 0;

    int max_length = 0;
    int max_i = 0;
    int max_j = 0;
    for(int i=1; i<=s.length(); i++)
        for(int j=1; j<=t.length(); j++) {
            if(s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
                if(dp[i][j] > max_length) {
                    max_length = dp[i][j];
                    max_i = i;
                    max_j = j;
                }
                history[i][j] = make_pair(i-1, j-1);
            } else {
                if(dp[i-1][j] > dp[i][j-1]) {
                    history[i][j] = make_pair(i-1, j);
                    dp[i][j] = dp[i-1][j];
                } else {
                    history[i][j] = make_pair(i, j-1);
                    dp[i][j] = dp[i][j-1];
                }
            }
        }

    // cout << "dp" << endl;
    // for(int i=0; i<=s.length(); i++) {
    //     for(int j=0; j<=t.length(); j++) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    // cout << "history" << endl;
    // for(int i=0; i<=s.length(); i++) {
    //     for(int j=0; j<=t.length(); j++) cout << "(" << history[i][j].first << ", " << history[i][j].second << ")" << " ";
    //     cout << endl;
    // }

    int i=max_i;
    int j=max_j;
    string ans = "";
    while(i>=1 && j>=1) {
        if(s[i-1]==t[j-1])
            ans = s[i-1] + ans;
        pair<int, int> tmp = history[i][j];
        i = tmp.first;
        j = tmp.second;
    }

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

Measured memory_bytes: 106112
#include<stdio.h>

int main()
{
  int n,i,j;
  scanf("%d",&n);
  int a[n+1];
  for(i=1;i<=n;i++)
  {
    scanf("%d",&a[i]);
  } 
  long long int sum=0;
  for(i=1;i<=n;i++)
          {
            for(j=i+1;j<=n;j++)
            {
              sum=sum+a[i]*a[j];
            }
          }
          printf("%lld\n",sum);
          
          return 0;
          }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, m;
string s;
const int maxN = 2 * (int)1e5 + 10;
vector < int > g[maxN];
int deg[maxN][2];
set < pair < int, int > > all;
bool used[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    cin >> s;
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        deg[x][s[y - 1] - 'A']++;
        g[x].push_back(y);
        if (x != y) deg[y][s[x - 1] - 'A']++;
        if (y != x) g[y].push_back(x);
    }
    for (int i = 1; i <= n; i++) {
        all.insert(make_pair(min(deg[i][0], deg[i][1]), i));
    }
    while (1) {
        if (all.empty()) break;
        auto it = all.begin();
        if (it -> first != 0) break;
        int v = (*it).second;
        all.erase(it);
        used[v] = true;
        for (int to : g[v]) {
            if (used[to]) continue;
            all.erase(make_pair(min(deg[to][0], deg[to][1]), to));
            deg[to][s[v - 1] - 'A']--;
            all.insert(make_pair(min(deg[to][0], deg[to][1]), to));
        }
    }
    if (!all.empty()) cout << "Yes";
    else cout << "No";
    return 0;
}

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

using namespace std;

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

  if (a <= c && c <= b) {
    cout << min(b - c, d - c) << endl;
  } else if (c <= a && a <= d) {
    cout << min(b - a, d - a) << endl;
  } else {
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf")] * N
dp[0] = 0
for i in range(N):
  if i + 1 < N: dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
  if i + 2 < N: dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[-1])

Measured memory_bytes: 52668
public class Main {
	public static void main(String[] args) {
		java.util.Scanner in = new java.util.Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] cost = new int[n][2];
		int[] std = new int[m];
		for (int i=0; i<n; i++)
			cost[i][0] = in.nextInt();
	    for (int i=0; i<m; i++) 
	    	std[i] = in.nextInt();
	    java.util.Arrays.sort(std);
	    for (int i=0; i<m; i++) {
	    	for (int j=0; j<n; j++) {
	    		if (cost[j][0] <= std[i]) {
	    			cost[j][1] += 1;
	    			break;
	    		}
	    	}
	    }
	    int tmp = cost[0][1];
	    int ans = 1;
	    for (int i=0; i<n; i++) {
	    	if (tmp <cost[i][1]) {
	    		tmp = cost[i][1];
	    		ans = i+1;
	    	}
	    }
	    System.out.println(ans);
	}
}

Measured memory_bytes: 25116
import sys
  
total = 0
quantity = 0
count = 0

for s in sys.stdin:
    p, q = map(int, s.split(','))
    total += p * q
    quantity += q
    count += 1

avg_f = quantity / count
avg = int(avg_f)+1 if avg_f*10%10 >= 5 else int(avg_f)

print(total)
print(avg)      


Measured memory_bytes: 5600