akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(void)
{
    int a, b, h, m;

    scanf("%d %d %d %d", &a, &b, &h, &m);
    double radm = (60 - m) % 60 / 60.0 * acos(-1) * 2 + acos(-1) / 2;
    double mx = b * cos(radm), my = b * sin(radm);

    double radh = (720 - h * 60 - m) % 720 / 720.0 * acos(-1) * 2 + acos(-1) / 2;
    double hx = a * cos(radh), hy = a * sin(radh);

    // printf("min (%f,%f), hor (%f,%f)", mx, my, hx, hy);

    printf("%.10f\n", sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my)));

    return 0;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
using namespace std;
using ii = pair<int, int>;
using ll = long long int;


int arr[200'005];

int main (){
	FASTIO;

   // freopen("input.txt", "r", stdin);
	int n; cin >> n;



	rep(i, 1, n + 1) cin >> arr[i];
	sort(arr + 1, arr + n + 1);
	
	ll ans = 0;

    rep(i, n / 2 + 1, n + 1) ans += arr[i];
    rep(i, n / 2 + 1, n ) ans += arr[i];
    if(n % 2 == 1) ans -= arr[n / 2 + 1];
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cerr<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;


void solve_old(long long N, std::string S){
    vector<int> cntW(N,0);
    vector<int> cntE(N,0);
    // int cntW=0, cntE=0;
    for (ll i = 1; i < N; i++) {
        if(S[i-1]=='W') {
            cntW[i]=cntW[i-1]+1;
        } else {
            cntW[i]=cntW[i-1];
        }
        if(S[N-1-i+1]=='E') {
            cntE[N-1-i]=cntE[N-1-i+1]+1;
        } else {
            cntE[N-1-i]=cntE[N-1-i+1];
        }
    }
    int val = cntW[0]+cntE[0];
    for (ll i = 0; i < N; i++) {
        val = min(val, cntW[i]+cntE[i]);
    }
    cout << val << "\n";
    // vout(cntW);
    // vout(cntE);
}

void solve(long long N, std::string S){
    vector<int> W(N,0);
    vector<int> E(N,0);
    for (ll i = 1; i < N; i++) W[i]=W[i-1]+(S[i-1]=='W');
    for (ll i = N-2; i >= 0; i--) E[i]=E[i+1]+(S[i+1]=='E');
    int val = W[0]+E[0];
    for (ll i = 0; i < N; i++) val = min(val, W[i]+E[i]);
    cout << val << "\n";
    // vout(W);
    // vout(E);
}


int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3332
#include <stdio.h>
int main(void)

{
	int n,a[1000],b[1000],c[1000],ans[1000],i;
	scanf("%d",&n);
	for (i=0 ; i<n ; i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		if(a[i]*a[i]+b[i]*b[i]==c[i]*c[i] || a[i]*a[i]+c[i]*c[i]==b[i]*b[i] || c[i]*c[i]+b[i]*b[i]==a[i]*a[i]){
			ans[i]=1;
		}
		else{
			ans[i]=0;
		}
	}
	for (i=0 ; i<n ; i++){
		if(ans[i]==1){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1760
import Data.List

main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  ns <- map (read :: String -> Int) . words <$> getLine
  print $ solve ns n

solve :: [Int] -> Int -> Int
solve ns n = if n `mod` 2 == 0
             then evenFold
             else oddFold
  where
    evenFold = foldl f 1  ans
    oddFold = foldl1 f ans
    ans = map length $ group $ sort ns
    f a b = if b /= 2 then 0
            else a * b `mod` 1000000007


Measured memory_bytes: 30844
#include<stdio.h>
#include<string.h>
int main(){
  char a[10],b[10],c[10];
  scanf("%s %s %s",&a,&b,&c);
  int d,e,f;
  d=strlen(a);
  e=strlen(b);
  f=strlen(c);
  if(a[d-1]==b[0]&&b[e-1]==c[0])
    printf("YES");
  else 
    printf("NO");
  
  return 0;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=103;
int N, M, k;
int arr[MX];
string s[MX];
bool cmp(string &a, string &b)
{
    return a+b <= b+a;
}
int main()
{
    int a, b;
    cin>>a>>b;
    if(a > b) swap(a, b);
    if(a == 0 || b == 0)
    {
        cout<<"Zero\n";
        return 0;
    }
    if(a < 0 && b < 0)
    {
        int num=b-a;
        num+=1;
        if(num%2 == 0)
        {
            cout<<"Positive\n";
        }
        else
            
        {
             cout<<"Negative\n";
        }
        return 0;
    }
    if(a > 0 && b > 0)
    {
       cout<<"Positive\n";
       return 0;
    }
    if( a <= 0 && b >= 0)
    {
         cout<<"Zero\n";
        return 0;
    }
    
    
//    
//    if(a <= 0 && b >= 0) {
//        
//    }
//    else if(a < 0 && b < 0)
//    {
//        if((b-a)%2) cout<<"Positive\n";
//        return 0;
//    }
//    cout<<"Negative\n";
    return 0;
}



Measured memory_bytes: 256
/* ex5_3
  bonbonc */

#include<stdio.h>

int main(void){
	
	int height,width,i,j;/*H,Wを受け取る変数とforループで使う変数*/
	char matrix[100][100];/*a_ijを受け取る二次元配列*/
	int blackrow[100]={0};/*黒いマスを含む行を記録する0,1配列*/
	int blackcol[100]={0};/*黒いマスを含む列を記録する0,1配列*/

	scanf("%d %d",&height,&width);/*H,Wを入力*/

	for(i = 0;i<height;i++){
		for(j = 0;j<width;j++){
			scanf(" %c",&matrix[i][j]);/*各マスの文字を入力*/
		}
	}

	for(i=0;i<height;i++){
		for(j=0;j<width;j++){
			if(matrix[i][j]=='#'){
				blackrow[i]=1;/*i行目に一つでも黒いマスがあればblackrow[i]を1にする*/
				blackcol[j]=1;/*j列目に一つでも黒いマスがあればblackcol[i]を1にする*/
			}
		}
	}
	for(i=0;i<height;i++){
		for(j=0;j<width;j++){
			if(blackrow[i]==1 && blackcol[j]==1){
				printf("%c",matrix[i][j]);/*i行目に黒いマスがある、なおかつj列目に黒いマスがある場合は(i,j)マスの文字を出力*/
			}
		}
		if(blackrow[i]==1){
			printf("\n");/*i行目を出力した場合は改行する*/
		}
		
	}

	return 0;
}



Measured memory_bytes: 128
// https://atcoder.jp/contests/abc173/tasks/abc173_a

#include <cstdio>

using namespace std;

const int N_MAX = 10000;

int N;

void solve() {
  int ans = 0;
  int surplus = N % 1000;
  if(surplus != 0){
    ans = 1000 - surplus;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
}

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


Measured memory_bytes: 1732
#include<stdio.h>
#include<string.h>
int main(){
  int k,i;
  char s[100];
  scanf("%d%s",&k,s);
  if(strlen(s)>k){
    s[k]='\0';
    printf("%s...\n",s);
  }else{
  	printf("%s\n",s);
  }
  return 0;
}

Measured memory_bytes: 1732
import sys
input = sys.stdin.readline
def main():
    N, M = map( int, input().split())
    d = dict()
    for i in range(M):
        a, b, c = map( int, input().split())
        a, b = a-1, b-1
        d[(a,b)] = c
    V = [[1000000]*N for _ in range(N)]
    for i in range(N):
        V[i][i] = 0
    for (s,t), c in d.items():
        V[s][t] = V[t][s] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if V[i][k] + V[k][j] < V[i][j]:
                    V[i][j] = V[i][k] + V[k][j]
    ans = 0
    for (s,t), c in d.items():
        check = False
        for k in range(N**2):
            i = k//N
            j = k%N
            if V[i][s] + c + V[t][j] == V[i][j]:
                check = True
                break
        if check == False:
            ans += 1

    print(ans)
                
if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
//#define LOCAL
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
#include<map>
#include<random>
#include<stack>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
using piii = pair<pii, pii>;
using pdii = pair<int, pii>;
int n, m;
int a[200009];
int b[410009];
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	while (t--) {
		scanf("%d", &n);
		m = 2 * n + 10;
		for (i = 0; i < n; i++) {
			scanf("%d", &a[i]);
			if (i - a[i] > 0 && i - a[i] < m)b[i - a[i]]++;
		}
		lld res = 0;
		for (i = 0; i < n; i++) {
			if (i + a[i] > 0 && i + a[i] < m) {
				res += b[i + a[i]];
			}
			if (i - a[i] > 0 && i - a[i] < m)b[i - a[i]]--;
		}
		printf("%lld\n", res);

	}
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1,-1};
signed main() {
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(i < B) {
                if(j < A) {
                    cout << 1;
                }
                else {
                    cout << 0;
                }
            }
            else {
                if(j < A) {
                    cout << 0;
                }
                else {
                    cout << 1;
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = sz(s);
    vll la(n+1, 0), rc(n+1, 0);
    rep(i, n) la[i+1] = la[i] + (s[i] == 'A');
    for (int i = n-1; i >= 0; --i) rc[i] = rc[i+1] + (s[i] == 'C');
    ll aq = 0;
    rep(i, n) if (s[i] == '?') aq++;
    ll lq = 0;
    ll rq = aq;
    mint ans = 0;
    rep(i, n) {
        if (s[i] == 'B') {
            ans += mint(la[i]) * mint(rc[i]) * mint(3).pow(aq);
            if (aq - 1 >= 0) ans += mint(lq) * mint(rc[i]) * mint(3).pow(aq-1);
            if (aq - 1 >= 0) ans += mint(la[i]) * mint(rq) * mint(3).pow(aq-1);
            if (aq - 2 >= 0) ans += mint(lq) * mint(rq) * mint(3).pow(aq-2);
        } else if (s[i] == '?') {
            rq--;
            aq--;
            ans += mint(la[i]) * mint(rc[i]) * mint(3).pow(aq);
            if (aq - 1 >= 0) ans += mint(lq) * mint(rc[i]) * mint(3).pow(aq-1);
            if (aq - 1 >= 0) ans += mint(la[i]) * mint(rq) * mint(3).pow(aq-1);
            if (aq - 2 >= 0) ans += mint(lq) * mint(rq) * mint(3).pow(aq-2);
            aq++;
            lq++;
        }
    }
    cout << ans << endl;
}

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

#define PI 3.1415926535

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double ans;
  
  if (2 * x >= a * a * b) {
    ans = atan(2 * b / a - 2 * x / (a*a*a)) * 180 / PI;
  } else {
    ans = atan(a * b * b / (2 * x)) * 180 / PI;
  }
  
  
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;

namespace atc
{
    class Program
    {
        static void Main(string[] args)
        {
            long num = long.Parse(Console.ReadLine());
            long[] p = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long count = 0;
            for (int iii = 0; iii < num - 1; iii++)
            {

                if (p[iii] <= p[iii + 1])
                {
                    // nanim
                }
                else
                {
                    long temp = p[iii] - p[iii + 1];
                    p[iii + 1] = p[iii];
                    count += temp;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 47476
n=int(input())
a= input()
l=[]
x=[]
y=[]
if n%2!=0:
    print('No')
else:
    for i in range(len(a)):
        l.append(a[i])
    for i in range(n//2):
        x.append(a[i])
    for j in range(n//2,n):
        y.append(a[j])
    if x==y:
        print('Yes')
    else:
        print('No')

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000
vector<string> v = {"dream", "dreamer", "erase", "eraser"};

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;

    int i = s.size() - 1;
    bool ok = true;
    while (s.size() > 0) {
        string tmp1 = " ", tmp2 = " ";
        if (s[i] == 'r') {
            if (s.size() > 5) {
                tmp1 = s.substr(i - 5, 6);
            }
            if (s.size() > 6) {
                tmp2 = s.substr(i - 6, 7);
            }
            if (tmp1 == v[3]) {
                i -= 6;
                s = s.substr(0, i + 1);
            } else if (tmp2 == v[1]) {
                i -= 7;
                s = s.substr(0, i + 1);
            } else {
                ok = false;
                break;
            }
        } else if (s[i] == 'e') {
            if (s.size() > 4) {
                tmp1 = s.substr(i - 4, 5);
            }
            if (tmp1 == v[2]) {
                i -= 5;
                s = s.substr(0, i + 1);
            } else {
                ok = false;
                break;
            }
        } else if (s[i] == 'm') {
            if (s.size() > 4) {
                tmp1 = s.substr(i - 4, 5);
            }
            if (tmp1 == v[0]) {
                i -= 5;
                s = s.substr(0, i + 1);
            } else {
                ok = false;
                break;
            }
        } else {
            ok = false;
            break;
        }
    }

    cout << ((ok) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 620
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;


const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=3e5+5;
const int MOD=1e9+7;
const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
//inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
inline int mul(int x,int y){return 1LL*x*y%MOD;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

int m,ans,ge;
int x[20],y[20],s[20][2];
bool used[20];
inline bool check(int i,int j){
    int p=s[i][0],q=s[i][1],r=s[j][0],t=s[j][1];
    int sx=x[p]-x[q],sy=y[p]-y[q],ex=x[r]-x[t],ey=y[r]-y[t];
    return (sx*ey==sy*ex);
}
void dfs(int dep){
    if(dep>=m){
        int cnt=0;
        for(int i=0;i<ge;i++){
            for(int j=i+1;j<ge;j++){
                if(check(i,j))++cnt;
            }
        }
        ans=max(ans,cnt);
        return;
    }
    if(used[dep]){dfs(dep+1);return;}
    for(int i=dep+1;i<m;i++)if(!used[i]){
        s[ge][0]=dep,s[ge][1]=i;++ge;
        used[i]=used[dep]=1;
        dfs(dep+1);--ge;
        used[i]=used[dep]=0;
    }
}
int main()
{
    read(m);
    for(int i=0;i<m;i++)read(x[i]),read(y[i]);
    dfs(0);
    printf("%d\n",ans);
    return 0;
}
/*

*/



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
long n;
vector <long> a;
vector <long> b;
vector <vector<long>> node;
vector <long> colorNumber;
long rootIndex = 0;
long depth = 0;
void dfs(long index){
    //cout << index;
    long rootColor = 0;
    if(index!=rootIndex){
        rootColor = colorNumber[index];
    }
    depth++;
    long tmp = 0;
    for(long i = 0; i < node[index].size(); i++){
        tmp++;
        if(tmp==rootColor){
            //cout << "rootColor: " << rootColor << endl; 
            tmp++;
        }
        //cout << tmp << " ";
        colorNumber[node[index][i]]=tmp;
    }
    //cout << endl;
    for(long i = 0; i < node[index].size(); i++){
        dfs(node[index][i]);
        depth--;
    }
    //cout << endl;
}
int main(){
    cin >> n;
    a = vector<long>(n);
    b = vector<long>(n);
    node = vector<vector<long>>(n);
    colorNumber = vector<long>(n,0);
    vector <long> pairent;
    vector <long> child;
    for(long i = 0; i < n-1; i++){
        cin >> a[i];
        cin >> b[i];
        a[i]--;
        b[i]--;
        node[a[i]].push_back(b[i]);
        pairent.push_back(a[i]);
        child.push_back(b[i]);
    }
    sort(pairent.begin(),pairent.end());
    pairent.erase(unique(pairent.begin(),pairent.end()),pairent.end());
    sort(child.begin(),child.end());
    child.erase(unique(child.begin(),child.end()),child.end());
    for(int i = 0; i < pairent.size(); i++){
        bool isFound = false;
        for(int j = 0; j < child.size(); j++){
            if(pairent[i]==child[j]){
                isFound=true;
                break;
            }
        }
        if(isFound==false){
            rootIndex=pairent[i];
        }
    }

    dfs(rootIndex);
    depth--;
    // cout << colorNumber[b[0]] << endl;
    // cout << colorNumber[b[1]] << endl;
    // cout << colorNumber[b[2]] << endl;
    // cout << colorNumber[b[3]] << endl;

    long ans = 0;
    for(int i = 0; i < n; i++){
        ans=max(ans,colorNumber[i]);
    }
    cout << ans << endl;
    for(long i = 0; i < n-1; i++){
        cout << colorNumber[b[i]] << endl;;
    }
    return 0;
}

Measured memory_bytes: 11108
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;

int arr[N];

int main() {
    // freopen("in.txt", "rt", stdin);
    int n, k;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", arr + i);
        arr[i] -= i;
    }
    sort(arr + 1, arr + n + 1);
    int b = arr[(n + 1) / 2];
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += abs(arr[i] - b);
    }
    printf("%lld", ans);
}

Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b ,c,d= map(int, readline().split())

ac = a*c
ad = a * d
bc = b * c
bd = b * d
l = [ac, ad, bc, bd]
l.sort()
print(l[-1])


Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    ll n, k;
    cin >> n >> k;
    vector<ll> sunuke(n,0);
    vector<vector<ll>> wh(k);
    REP(i, k) { 
        int d;
        cin >> d;
        REP(j,d){
            int a;
            cin >> a;
            sunuke[a - 1]++;
        }
    }

    ll ans = 0;
    REP(i, n) {
        if(sunuke[i] == 0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int n;
int x[100];
ll dp[21][100];

int main(){
	cin >> n;
	rep(i,n) cin >> x[i];
	dp[x[0]][0] = 1;
	for(int i = 1; i < n-1; i++){
		for(int j = x[i]; j < 21; j++) dp[j-x[i]][i] += dp[j][i-1];
		for(int j = 0; j < 21-x[i]; j++) dp[j+x[i]][i] += dp[j][i-1];
	}
	cout << dp[x[n-1]][n-2] << endl;
}

Measured memory_bytes: 1172
n,m = map(int,input().split())
mod = 10**9+7
a = set()
for i in range(m):
  s = int(input())
  a.add(s)
  
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
  if i in a:
    continue
  dp[i] = (dp[i-1] + dp[i-2]) % mod
  
print(dp[-1])

Measured memory_bytes: 17176
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll min(ll a, ll b) {
	if (a < b)
		return a;


	return b;
}


ll max(ll a, ll b) {
	if (a < b)
		return b;

	return a;
}



char a[500][500], blue[500][500], red[500][500];

int main() {
	ll H, W;
	cin >> H >> W;
	
	ll lindex = inf, rindex = -10000000;
	rep(i, H) {
		rep(j, W) {

			cin >> a[i][j];
			if (a[i][j] == '#') {
				lindex = min(lindex, j);
				rindex = max(rindex, j);
			}
			blue[i][j] = red[i][j] = a[i][j];
		}

	}

	rep(i, H){
		blue[i][0] = '#';
		red[i][W-1] = '#';

		if (i % 2 == 0) {
			for (int j = 0; j < W-1; j++) {
				blue[i][j] = '#';
			}

		}
		else {
			for(int j = 1; j < W; j++){
				red[i][j] = '#';
			}
		}
	}


	rep(i, H) {
		rep(j, W)
			cout << blue[i][j];


		cout << endl;
	}

	cout << "\n" << endl;
	
	rep(i, H) {
		rep(j, W) {
			cout << red[i][j];

		}

		cout << endl;
	}





	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
  int A,B;

  scanf("%d %d",&A,&B);

  if(A<B)
    {
       printf("a < b\n");
    }
  else  if(A>B)
    {
       printf("a > b\n");
    }
  else 
    {
        printf("a == b\n");
    }

  return 0;
    }

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> sv(h+2);
  string dd = "";
  for (int i = 0;i<w+2;i++){
    dd += ".";
  }
  sv.at(0) = dd;
  for(int i = 1;i<h+1;i++){
    string sd = ".";
    string s;
    cin >> s;
    sv.at(i) = "." + s + ".";
    //cout << s << endl;
  }
  sv.at(h+1) = dd;
  
  //for(int i = 0; i< h+2;i++){
  //  cout << sv.at(i) << endl;
  //}
  
  vector<string> ans(h);
  for(int i = 1; i< h +1;i++){
    string st_u = sv.at(i-1);
    string st = sv.at(i);
    string st_d = sv.at(i+1);
    string ans_st = "";
    for(int j = 1; j < w+1; j++){
      if (st.at(j) == '#') {
        ans_st += "#";
        continue;
      }
      
      int count = 0;
      if(st_u.at(j-1) == '#')
        count++;
      if(st_u.at(j) == '#')
        count++;
      if(st_u.at(j+1) == '#')
        count++;
      
      if(st.at(j-1) == '#')
        count++;
      if(st.at(j+1) == '#')
        count++;
      
      if(st_d.at(j-1) == '#')
        count++;
      if(st_d.at(j) == '#')
        count++;
      if(st_d.at(j+1) == '#')
        count++;
      ans_st += std::to_string(count);
    }
    ans.at(i-1) = ans_st;
  }
  
  for(int i = 0; i< h;i++){
    cout << ans.at(i) << endl;
  }
  
}


Measured memory_bytes: 256
S = input()
if S[0] != "A":
    print("WA")
    exit()

if S[2:-1].count("C") != 1:
    print("WA")
    exit()

C_index = None
for i, s in enumerate(S[2:-1], 2):
    if s == "C":
        C_index = i
        break

for i, s in enumerate(S[1:], 1):
    if i == C_index:
        continue

    if s.isupper():
        print("WA")
        exit()
print("AC")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF (1<<29)
using namespace std;
typedef long long ll;
int main(){
      string s;
      int f1[26],f2[10];
      for(int i=0;i<26;i++)f1[i]=0;
      for(int i=0;i<10;i++)f2[i]=0;
      cin>>s;
      for(int i=0;i<s.size();i++){
            if('a'<=s[i]&&s[i]<='z')f1[s[i]-'a']++;
            else f2[s[i]-'0']++;
      }
      bool update=true;
      int ans=0;
      while(update){
            update=false;
            for(int i=0;i<26;i++){
                  if(f1[i]>0){
                        int b=i;
                        while(f1[i]>0)i++;
                        if(i-b>3){
                              //cout<<i<<endl;
                              ans+=3;
                              for(int j=b;j<i;j++){
                                    f1[j]--;
                              }
                              update=true;
                        }
                  }
            }
            for(int i=0;i<10;i++){
                  if(f2[i]>0){
                        int b=i;
                        while(f2[i]>0)i++;
                        if(i-b>3){
                              ans+=3;
                              for(int j=b;j<i;j++){
                                    f2[j]--;
                              }
                              update=true;
                        }
                  }
            }
      }
      for(int i=0;i<26;i++)ans+=f1[i];
      for(int i=0;i<10;i++)ans+=f2[i];
      cout<<ans<<endl;
}

Measured memory_bytes: 1184
N,K = map(int,input().split())
V = list(map(int,input().split()))
V_r = list(reversed(V))

ans = 0
for take in range(min(N+1,K+1)):
	for left in range(take+1):
		right = take - left
		jewel = V[:left] + V_r[:right]
		rest = K - take
		jewel.sort()
		tmp = sum(jewel)
		for i in range(min(take,rest)):
			if jewel[i] < 0:
				tmp -= jewel[i]
		ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3064
import sys

def GetColumnName(index):
	return chr(index+ord('A'))

H, W = map(int, input().split())

matrix = []
for i in range(H):
	row = sys.stdin.readline()
	matrix.append(row.split())

for i in range(H):
	for j in range(W):
		if matrix[i][j] == "snuke":
			print(GetColumnName(j)+str(i+1))
			sys.exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    int maxx = -101,miny = 101;
    int tmp;
    for(int i = 0;i < N;i++)
    {
        cin >> tmp;
        maxx = max(maxx,tmp);
    }
    
    for(int i = 0;i < M;i++)
    {
        cin >> tmp;
        miny = min(miny,tmp);
    }

    bool is = false;
    for(int i = X + 1;i <= Y;i++)
    {
        if(maxx < i && i <= miny)
            is = true;
    }
    cout << (is ? "No War\n" : "War\n");
}



Measured memory_bytes: 256
n,m=map(int,input().split())
b=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
  x,y=map(int,input().split())
  x,y=x-1,y-1
  if not b[x]:
    continue
  b[y]+=1
  if red[x]:
    red[y]=True
  
  b[x]-=1
  if b[x]==0:
    red[x]=False
    
print(red.count(True))


Measured memory_bytes: 4596
import java.util.*;

class Main {
	static int N;
	static int[] low, high;
	static boolean[] f, s;
	static int[] pow = new int[8];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		pow[0] = 1;
		for (int i = 1; i < pow.length; ++i) {
			pow[i] = pow[i - 1] * 10;
		}
		while (true) {
			int maxLen = 0;
			N = sc.nextInt();
			if (N == 0)
				break;
			low = new int[N];
			high = new int[N];
			for (int i = 0; i < N; ++i) {
				low[i] = sc.nextInt();
				high[i] = sc.nextInt();
				if (high[i] >= 10)
					maxLen += 2;
				else
					maxLen += 1;
			}
			f = new boolean[pow[6]];
			s = new boolean[pow[6]];
			dfs(0, N / 2, f, 0);
			dfs(N / 2, N, s, 0);
			long ans = 0;
			for (int L = N; L <= maxLen; ++L) {
				ans += solve(L);
			}
			System.out.println(ans);
		}
	}

	static long solve(int length) {
		int fFix = Math.max(length - (N - N / 2) * 2, N / 2);
		int sFix = Math.max(length - N / 2 * 2, N - N / 2);
		int middleLen = length - fFix - sFix;
		if (middleLen == 0) {
			long sc = 0, fc = 0;
			for (int i = pow[fFix - 1]; i < pow[fFix]; ++i) {
				if (f[i])
					++sc;
			}
			for (int i = pow[sFix - 1]; i < pow[sFix]; ++i) {
				if (s[i])
					++fc;
			}
			return fc * sc;

		} else {
			long ret = 0;
			for (int middle = 0; middle < pow[middleLen]; ++middle) {
				boolean[][] fok = new boolean[middleLen + 1][pow[fFix]];
				boolean[][] sok = new boolean[middleLen + 1][pow[sFix]];
				for (int i = 0; i <= middleLen; ++i) {
					int add = pow[i];
					int res = middle / pow[middleLen - i];
					for (int cur = res + pow[fFix + i - 1]; cur < pow[fFix + i]; cur += add) {
						if (f[cur])
							fok[i][cur / pow[i]] = true;
					}
				}
				for (int i = 0; i <= middleLen; ++i) {
					if (i > 0 && (middle % pow[i] / pow[i - 1] == 0)) {// leading0
						continue;
					}
					int res = middle % pow[i] * pow[sFix];
					for (int cur = res + (i == 0 ? pow[sFix - 1] : 0); cur < res + pow[sFix]; cur++) {
						if (s[cur])
							sok[middleLen - i][cur % pow[sFix]] = true;
					}
				}
				for (int i = 1; i < (1 << (middleLen + 1)); ++i) {
					long fc = 0;
					long sc = 0;
					out1: for (int j = pow[fFix - 1]; j < pow[fFix]; ++j) {
						for (int k = 0; k < (1 + middleLen); ++k) {
							if ((i & (1 << k)) > 0 && !fok[k][j]) {
								continue out1;
							}
						}
						++fc;
					}
					out2: for (int j = 0; j < pow[sFix]; ++j) {
						for (int k = 0; k < (1 + middleLen); ++k) {
							if ((i & (1 << k)) > 0 && !sok[k][j]) {
								continue out2;
							}
						}
						++sc;
					}
					ret += fc * sc * (Integer.bitCount(i) % 2 == 1 ? 1 : -1);
				}
			}
			return ret;
		}
	}

	static void dfs(int curIdx, int endIdx, boolean[] arr, int sum) {
		if (curIdx == endIdx) {
			arr[sum] = true;
			return;
		}
		for (int i = low[curIdx]; i <= Math.min(9, high[curIdx]); ++i) {
			dfs(curIdx + 1, endIdx, arr, sum * 10 + i);
		}
		for (int i = Math.max(10, low[curIdx]); i <= high[curIdx]; ++i) {
			dfs(curIdx + 1, endIdx, arr, sum * 100 + i);
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 159224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int n, ans = inf;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		int sub = 0;
		while (a[i]%2== 0) {
			a[i] /= 2;
			sub++;
		}
		ans = min(ans, sub);
	}
	cout << ans << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#include <random>

using namespace std;

typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cout << "ACL";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << endl;
	}
}

Measured memory_bytes: 3592
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;

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

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> Pol;

const D INF = 1e40;
const D EPS = 1e-8;
const D PI = acos(-1);

int sig(D r) {return (r < -EPS) ? -1 : (r > EPS) ? 1: 0;}
bool eq(D a, D b) {return abs(a - b) < EPS;}
bool near(P a, P b) {return abs(b - a) < EPS;}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D cross(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.second - a.first;}

// 線分abに対する点xの位置
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
int ccw(L s, P p) {
  P a = vec(s);
  p -= s.first;
  D cr = cross(a, p);
  if (eq(cr, 0)) {
    if (sig(dot(a, p)) < 0) return BACK;
    if (sig(norm(a) - norm(p)) < 0) return FRONT;
    return ON;
  }
  return (cr > 0) ? LEFT : RIGHT;
}

int main() {
  P a, b, c, p;
  while (cin >> a.X >> a.Y >> b.X >> b.Y >> c.X >> c.Y >> p.X >> p.Y) {
    int bit = ccw(L(a, b), p) | ccw(L(b, c), p) | ccw(L(c, a), p);
    if (bit == LEFT || bit == RIGHT) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n)
    {
        vi v;
        s=0;
        rep(i,n)
        {
            cin>>x;
            if(i%2==0&&x%2)s++;
        }
        cout<<s<<en;
    }

}




Measured memory_bytes: 3628
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



char buf[105];

int main(){

	ll L,N;
	scanf("%lld %lld",&L,&N);

	scanf("%s",buf);

	ll num_o = 0,num_x = 0,num_seq = 0;

	for(int i = 0; i < L; i++){
		if(buf[i] == 'x'){

			num_x++;
		}else{

			num_o++;
			if(i > 0 && buf[i-1] == 'o'){
				num_seq++;
			}
		}
	}

	for(int loop = 0; loop < N; loop++){

		num_x += num_seq;
		num_o += num_seq*2;
		num_seq *= 2;
	}

	printf("%lld\n",num_o+num_x);

	return 0;
}



Measured memory_bytes: 3208
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e17)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int a,b,x; cin>>a>>b>>x;
	cout<<(b/x-a/x+(a%x==0?1:0))<<"\n";
	return 0;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())


p = list(map(int, input().split()))
d = list(map(int, input().split()))


a = list(itertools.permutations(range(1,n+1)))

b = []
for i in range(1,len(a)+1):
    b.append(i)

it = itertools.zip_longest(b, a)

pcount = 0
dcount = 0

for i in it:
    if p != d:
        if p == list(i[1]):
            pcount = int(i[0])
        if d == list(i[1]):
            dcount = int(i[0])


print(abs(pcount-dcount))


Measured memory_bytes: 9568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
};


using p3=pair<ll,pint>;
ll a[202020],d;

ll dist(int x,int y){
    return d*(ll)abs(x-y)+a[x]+a[y];
}
void dfs(int l,int r,vector<p3> &v){
    vector<p3> ret;
    ret.push_back({longinf,{0,0}});
    if(l+1>=r){
        v.push_back({longinf,{0,0}});
        return;
    }
    ll mini=longinf,idx=-1;
    int m=(l+r)/2;
    for(int i=l;i<m;++i){
        if(dist(i,m)<mini)mini=dist(i,m),idx=i;
    }
    for(int i=m;i<r;++i){
        ret.push_back({dist(idx,i),{idx,i}});
    }
    mini=longinf;idx=-1;
    for(int i=m;i<r;++i){
        if(dist(i,l)<mini)mini=dist(i,l),idx=i;
    }
    for(int i=l;i<m;++i){
        ret.push_back({dist(idx,i),{idx,i}});
    }
    sort(ret.begin(),ret.end());
    vector<p3> vl,vr;
    dfs(l,m,vl);
    dfs(m,r,vr);
    int il=0,im=0,ir=0,sl=vl.size(),sm=ret.size(),sr=vr.size();
    while(il<sl&&im<sm&&ir<sr){
        if(vl[il]<ret[im]&&vl[il]<vr[ir])v.push_back(vl[il++]);
        else if(ret[im]<vr[ir])v.push_back(ret[im++]);
        else v.push_back(vr[ir++]);
    }
}
int main(){
    int n;cin>>n>>d;
    rep(i,n)cin>>a[i];
    vector<p3> edges;
    dfs(0,n,edges);
    UnionFind uf(n);
    ll ans=0;
    for(auto e:edges){
        if(uf.unite(e.second.first,e.second.second))ans+=e.first;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 128340
#include <iostream>
#include <string>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
    vector<int> A(3);
    for (int i = 0; i <3;++i){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    int count = 0;

    if (A[0]%2 == A[1]%2){
        count += ((A[1]-A[0])/2);
        count+=(A[2]-A[1]);
    }
    else{
        //dai to tyuu guuki onaji
        if(A[2]%2 == A[1]%2){
            count+=1;
            A[2]+=1;A[1]+=1;

            count += ((A[1]-A[0])/2);
            count+=(A[2]-A[1]);
        }
        else{
            count+=1;
            A[2]+=1;A[0]+=1;

            count += ((A[1]-A[0])/2);
            count+=(A[2]-A[1]);

        }
    }

    cout<<count<<endl;

}


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

int main() {
    int H,N;
    cin >> H >> N;
    int A[N];
    for(int i = 0; i < N; ++i) cin >> A[i];

    sort(A, A+N, greater<>());
    int Atks = 0;

    for(int i = 0; i < N; ++i){
        Atks += A[i];
    }

    if(Atks >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
// ABC075_C
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>  // std::swap()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define pll pair<ll, ll>
#define F first
#define S second

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M, a, b;
    cin >> N >> M;
    vector<pll> vec(M);
    REP(i, M) {
        cin >> a >> b; --a, --b;
        vec[i].F = a;
        vec[i].S = b;
    }

    // calculation
    UnionFind uf(N);
    ll res = 0;
    REP(i, M) {
        uf.init(N);
        REP(j, M) {
            if (j == i) continue;
            uf.merge(vec[j].F, vec[j].S);
        }
        if (uf.size(0) < N) res++;
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stack>
#include<cstdio>
using namespace std;
int main(){
stack<int> s;
int n;
while((scanf("%d",&n))!=EOF){
if(n!=0){
s.push(n);
}else{
printf("%d\n",s.top());
s.pop();
}
}
return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define MAX_N 1000000
#define INF 1000000

int main() {

  // ---------------------
  // Input
  
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int L;
  cin >> L;

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

  double x,y;
  double l = double(L);
  
  // 微分
  // x == y
  // x = L/3

  double V = (l/3.0) * (l/3.0) * ( l - 2.0*l/3.0);
  //cout << V << endl;

  printf("%.12f\n", V);
  
  return 0;
  
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max()

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n+1, vector<int>(0));
	for(int i=1; i<=m; i++) {
		int a, b;
		cin >> a >> b; 
		g[a].push_back(b);
		g[b].push_back(a);
	}

	queue<int> q;
	vector<int> w(n+1, 0);
	q.push(1);
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for(int i=0; i<g[x].size(); i++) {
			if (w[g[x][i]] == 0) {
				w[g[x][i]] = x; 
				q.push(g[x][i]);
			}
		}
	}
	bool vf = 1;
	for(int i=2; i<=n; i++) {
		if (w[i] == 0) vf = 0;
	}
	if (!vf) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		for(int i=2; i<=n; i++) {
			cout << w[i] << endl; 
		}
	}
}



Measured memory_bytes: 9696